include ../../makefile.dep

LIBDIR= ../../lib/$(HOST)
BINDIR= ../../bin/$(HOST)

INCLUDES      = -I../cal -I../include  -I../../include

TARGETS = edfix lst_btrk nav2dir putnav ref2mat refabs sm2mat\
		smoothr ubprint nmea_gps

all:	$(TARGETS)

LIBS1	      =  \
		$(LIBDIR)/vstat$(LIB) \
		$(LIBDIR)/use_adcp$(LIB) \
		$(LIBDIR)/matlab$(LIB) \
      $(LIBDIR)/use_db$(LIB) \
		$(LIBDIR)/dbsource$(LIB) \
		$(LIBDIR)/ioserv$(LIB)


LIBS2	      = $(LIBDIR)/ioserv$(LIB) \
		$(LIBDIR)/matlab$(LIB)
# Not all the targets really need the full list; but
# it does not take much time to check the whole list,
# and using a single list simplifies the makefile!

edfix	: $(BINDIR)/edfix$(EXE)
edfixOBJECTS = edfix$(OBJ) $(LIBDIR)/main_cnt$(OBJ)
$(BINDIR)/edfix$(EXE): $(edfixOBJECTS) $(LIBDIR)/main_cnt$(OBJ)
	$(CCLINK) -o $@ $(edfixOBJECTS) $(LIBS1) $(LDLIBS)
	$(CHMOD) $(BIN_PERMISSION) $@

lst_btrk   : $(BINDIR)/lst_btrk$(EXE)
lst_btrkOBJECTS = lst_btrk$(OBJ) $(LIBDIR)/main_cnt$(OBJ)
$(BINDIR)/lst_btrk$(EXE): $(lst_btrkOBJECTS)
	$(CCLINK) -o $@ $(lst_btrkOBJECTS) $(LIBS1) $(LDLIBS)
	$(CHMOD) $(BIN_PERMISSION) $@

nav2dir   : $(BINDIR)/nav2dir$(EXE)
nav2dirOBJECTS = nav2dir$(OBJ)	$(LIBDIR)/main_cnt$(OBJ)
$(BINDIR)/nav2dir$(EXE): $(nav2dirOBJECTS)
	$(CCLINK) -o $@ $(nav2dirOBJECTS) $(LIBS1) $(LDLIBS)
	$(CHMOD) $(BIN_PERMISSION) $@

putnav	 : $(BINDIR)/putnav$(EXE)
putnavOBJECTS = putnav$(OBJ) $(LIBDIR)/main_cnt$(OBJ)
$(BINDIR)/putnav$(EXE): $(putnavOBJECTS)
	$(CCLINK) -o $@ $(putnavOBJECTS) $(LIBS1) $(LDLIBS)
	$(CHMOD) $(BIN_PERMISSION) $@

ref2mat   : $(BINDIR)/ref2mat$(EXE)
ref2matOBJECTS = ref2mat$(OBJ)
$(BINDIR)/ref2mat$(EXE): $(ref2matOBJECTS)
	$(CCLINK) -o $@ $(ref2matOBJECTS) $(LIBS2) $(LDLIBS)
	$(CHMOD) $(BIN_PERMISSION) $@

refabs	 : $(BINDIR)/refabs$(EXE)
refabs.c : ../cal/refabinc.c
	touch $@
fix2vel.c  : ../cal/fix2vel.c
	touch $@
read_ref.c : ../cal/read_ref.c
	touch $@
refabsOBJECTS = refabs$(OBJ) \
		fix2vel$(OBJ) \
		read_ref$(OBJ) \
		$(LIBDIR)/main_cnt$(OBJ)
$(BINDIR)/refabs$(EXE): $(refabsOBJECTS)
	$(CCLINK) -o $@ $(refabsOBJECTS) $(LIBS1) $(LDLIBS)
	$(CHMOD) $(BIN_PERMISSION) $@

sm2mat	 : $(BINDIR)/sm2mat$(EXE)
sm2matOBJECTS = sm2mat$(OBJ)
$(BINDIR)/sm2mat$(EXE): $(sm2matOBJECTS)
	$(CCLINK) -o $@ $(sm2matOBJECTS) $(LIBS2) $(LDLIBS)
	$(CHMOD) $(BIN_PERMISSION) $@

smoothr   : $(BINDIR)/smoothr$(EXE)
smoothrOBJECTS = smoothr$(OBJ) optpos$(OBJ) $(LIBDIR)/main_cnt$(OBJ)
$(BINDIR)/smoothr$(EXE): $(smoothrOBJECTS)
	$(CCLINK) -o $@ $(smoothrOBJECTS) $(LIBS1) $(LDLIBS)
	$(CHMOD) $(BIN_PERMISSION) $@

ubprint   : $(BINDIR)/ubprint$(EXE)
ubprintOBJECTS = ubprint$(OBJ) ubwrite$(OBJ) $(LIBDIR)/main_cnt$(OBJ)
$(BINDIR)/ubprint$(EXE): $(ubprintOBJECTS)
	$(CCLINK) -o $@ $(ubprintOBJECTS) $(LIBS1) $(LDLIBS)
	$(CHMOD) $(BIN_PERMISSION) $@

nmea_gps   : $(BINDIR)/nmea_gps$(EXE)
nmea_gpsOBJECTS = nmea_gps$(OBJ) $(LIBDIR)/main_cnt$(OBJ)
$(BINDIR)/nmea_gps$(EXE): $(nmea_gpsOBJECTS)
	$(CCLINK) -o $@ $(nmea_gpsOBJECTS) $(LIBS1) $(LDLIBS)
	$(CHMOD) $(BIN_PERMISSION) $@

clean:
	$(RM) $(DIRT)
#
