# Makefile for the OIR C routines in EWS and MIA
#
# $Id: makec,v 1.4 2005/08/18 15:25:57 koehler Exp $
# Updated to include wvgoff (HP) w. jaffe 2003/12/03
#
# Last Change: Sun Aug 21 17:38:31 2005

# directories relative to the CVS tree
BINDIR = ../bin
OBJDIR = ../object
INCDIR = ../include
LIBDIR = ../lib

# location of CFITSIO
CFITSIO_BASE = ../../cfitsio
CFITSIO_INC  = $(CFITSIO_BASE)
CFITSIO_LIB  = $(CFITSIO_BASE)


# compiler
CC = gcc $(CCEXT)

# compilation options
INC_OPTS = -I$(CFITSIO_INC) -I$(INCDIR) 
LIB_OPTS = -L$(CFITSIO_LIB) -L$(LIBDIR) -L$(OBJDIR) 
ifeq ($(OSTYPE),solaris)
   LIB_OPTS = -L$(CFITSIO_LIB) -L$(LIBDIR) -L$(OBJDIR) -lsocket -lnsl 
endif
CC_OPT32= 	# unless overridden on cmd line
CC_OPTS = -W -pedantic $(CC_OPT32)

# libraries needed for all executables
BASELIBS = -lEWS -lcfitsio -lm 

# compilation pattern for executables
%: %.c
	$(CC) -o $(BINDIR)/$(notdir $@) $(CC_OPTS) $(INC_OPTS) $(LIB_OPTS) $< $(BASELIBS)

# compilation pattern for objects
%.o: %.c
	$(CC) -c -o $(OBJDIR)/$(notdir $@) $(CC_OPTS) $(INC_OPTS) $<
# Tell make file to search for exec sources in this directory
vpath %.c exec
vpath %.o $(OBJDIR)
vpath % $(BINDIR)
#sources
sources = $(wildcard *.c)
# executables
EXECUTABLES = oir1dCompressData oirGroupDelay oirAutoFlag oirAverageVis\
	      oirRedCal oirCalibrateVis oirFormFringes oirRotateGroupDelay\
	      oirChopPhotoImages oirChopPhotometry oirMakePhotoSpectra\
	      oirRotateInsOpd  oirMeanRMS midiChopimg\
	      oirChopJitterPhotoImages oirMakeJitterPhotoSpectra\
	      oirCrossCoeff oirSciPhotometry

all: lib exec
# utility library
$(LIBDIR)/libEWS.a: 
#ar rc $(LIBDIR)/$@ $(addprefix $(OBJDIR)/,$(notdir $^))
	ar rc $(LIBDIR)/$@ $(addprefix $(OBJDIR)/,$(notdir $^))
lib: sources
	ar rc $(LIBDIR)/libEWS.a $(OBJDIR)/*.o
	ranlib $(LIBDIR)/libEWS.a
sources: $(sources)
	$(CC) -c  $(CC_OPTS) $(INC_OPTS) $(sources)
	mkdir -p $(OBJDIR)
	mkdir -p $(LIBDIR)
	mkdir -p $(BINDIR)
	mv *.o $(OBJDIR)
exec: $(EXECUTABLES) 

# exception from the pattern def'ed above
midiChopimg: midiChopimg.o midiMultifile.o
	$(CC) -o $(BINDIR)/$(notdir $@) $(CC_OPTS) $(INC_OPTS) $(LIB_OPTS) $(OBJDIR)/midiChopimg.o $(OBJDIR)/midiMultifile.o $(BASELIBS)
#was:	$(CC) -o midiChopimg midiChopimg.o midiMultifile.o $(LIB) $(EXTRA_LIBS)

clean:
	rm -f $(OBJDIR)/*.o $(LIBDIR)/*.a $(BINDIR)/* || exit 0
