##########################################################################
# Copyright 1999 MBARI                                             
##########################################################################
# Summary  : Makefile for Navigation
# Filename : Makefile
# Author   : Andrew Pearce
# Project  : 
# Version  : Version 1.0
# Created  : 12/06/99
# Modified : 12/06/99
# Archived :
##########################################################################
# Modification History:
# $Header$
#
##########################################################################

CC	    = cc
CCPP	    = cc
LD	    = cc
AR 	    = wlib
DEPEND_TOOL = makedepend

DEBUG 	    = -g
EXCEPTION_HANDLING = -WC,-xs

## OPTIMIZE = -4 -Os
OPTIMIZE = 

## MAP_OUTPUT = -S -ms -M
MAP_OUTPUT =

AUV_BIN_DIR = ../bin

CFLAGS	    = -c $(DEBUG) $(MAP_OUTPUT) $(OPTIMIZE) -WC,-ei -DAUTONOMY -Wc,-ei -D_QNX -DUNIX  
CPPFLAGS    = -c $(DEBUG) $(MAP_OUTPUT) $(OPTIMIZE) -WC,-ei -DAUTONOMY -Wc,-ei -D_QNX -DUNIX \
	         $(EXCEPTION_HANDLING)

INCLUDES    = -I..  \
	      -I../utils \
	      -I../framework \
	      -I../compass \
	      -I../DataLog \
	      -I../DynamicControl \
	      -I../LayeredControl \
	      -I../Navigation \
	      -I../taskIF \
	      -I../gps \
	      -I../echoSounder \
	      -I../delta_t \
	      -I../bluefinBatt \
	      -I../hydroscat \
	      -I../gulper \
	      -I../isus \
	      -I../terrainAid \
	      -I../terrainNav \
	      -I../MbTrnRecv \
	      -I/usr/include \
	      -I/usr/local/include \
	      -I../stlport \
	      -I../newmat \
	      -IOctreeC++Qnx

LDFLAGS	    = -g -lmqueue
LIBPATH	    = /usr/lib:../lib 

LIBS        =   ../utils/utils.lib \
		../DataLog/dataLog.lib \
		../terrainAid/terrainAid.lib \
		../taskIF/taskInterfaces.lib \
		../LayeredControl/MissionClock.o \
		../framework/auvFramework.lib \
		../terrainAid/terrainAid.lib \
		../terrainNav/terrainNav.lib \
		/usr/local/lib/libnetcdf.a \
		../newmat/libnewmat.a \
		/usr/local/lib/gctpc/geolib.a

#		../sonardyne/SonardyneLog.o \
#               ../gps/GpsLog.o \
#		../gps/GpsUtils.o \


SIMOBJS	    =	SimulationLog.o \
		Simulator.o \
		Simulator2.o \
		SimulatorInput.o \
		SimulatorOutput.o \
		SimulatorServer.o \
		OctreeC++Qnx/OctreeSupport.o

OBJS	    = 	SimulatedAhrs.o \
		SimulatedCompass.o \
		SimulatedCrossbow.o \
		SimulatedCtd.o \
		SimulatedDepthSensor.o \
		SimulatedDevice.o \
		SimulatedGps.o \
		SimulatedInclinometer.o \
		SimulatedRangeFinder.o \
		SimulatedEchoSounder.o \
		SimulatedDeltaT.o \
		SimulatedTailCone.o \
		SimulatedLbl.o \
		SimulatedDvl.o \
		SimulatedDvlSide.o \
		SimulatedKearfott.o \
		SimulatedUsbl.o \
		SimulatedBluefinBatt.o \
		SimulatedHydroscat.o \
		SimulatedReson.o \
		SimulatedEdgetechFSDW.o \
		SimulatedBenthosModem.o \
		SimulatedTerrainAid.o \
		SimulatedCarl.o \
		SimulatedMbTrnRecv.o \
		$(SIMOBJS)

TARGETS = 	simulator simCrossbow simDepthSensor simKearfott \
		simAhrs simRangeFinder simTailCone simGps simLbl simDvl simDvlSide \
		simUsbl simEchoSounder simDeltaT simBluefinBatt simHydroscat \
		simGulper simIsus simCtd simReson simEdgetechFSDW simModem simTerrainAid \
		simCarl simCathx simMbTrnRecv

-include ../autonomy.make # this file contains the general
                       # modifications we want to apply to
                       # all the modules 

#
# Attempt to have make only install newer executables.
#INSTALLTARGETS =	$(addprefix $(AUV_BIN_DIR/), $(TARGETS))

all:		octree $(TARGETS)

octree:
	@echo " "
	@echo "Building octree executables"
	@echo " "
	@cd OctreeC++Qnx; \
	if \
	  make all; \
	then \
	  echo ""; \
	  echo "make succeeded"; \
	  echo ""; \
	else \
	  echo ""; \
	  echo "make failed";\
	  echo ""; \
	  exit; \
	fi; 

#simulator:  	 _simulator.o  ../bluefinBatt/BluefinBattOutput.o $(SIMOBJS) $(LIBS) 
#
# Note: I don't think the above line works in general because THIS makefile
# will try to remake BluefinBattOutput.o.  This makefile may not have the
# right include list.  So, the setup below does it, except that it can't
# explictly check to see if BluefinBattOutput.o is up to date.  That is, if
# simulator needs to be remade, it will check BluefinBattOutput.o and
# correctly make it first, if necessary. If simulator is up to date, and
# BluefinBattOutput.o isn't, this make file doesn't know it and doesn't do
# anything.  
#
# The above problem is corrected below:
#
simulator:  	 _simulator.o  \
        ../bluefinBatt/BluefinBattLog.o $(SIMOBJS) $(LIBS) 
	@echo " "
	@echo "Checking  ../bluefinBatt/BluefinBattLog.o"
	@echo " "
	@cd ../bluefinBatt; \
	if \
	  make all; \
	then \
	  make install; \
	  echo ""; \
	  echo "make succeeded"; \
	  echo ""; \
	else \
	  echo ""; \
	  echo "make failed";\
	  echo ""; \
	  exit; \
	fi; 
	$(LD) $(LDFLAGS) _simulator.o \
	../bluefinBatt/BluefinBattLog.o \
	$(SIMOBJS) $(LIBS) -o $@ 

simCtd: simCtd.o SimulatedCtd.o $(LIBS)
	$(LD) $(LDFLAGS) simCtd.o SimulatedCtd.o $(LIBS) -o $@

simCarl: simCarl.o SimulatedCarl.o $(LIBS)
	$(LD) $(LDFLAGS) simCarl.o SimulatedCarl.o $(LIBS) -o $@

simCathx: SimulatedCathx.o $(LIBS)
	$(LD) $(LDFLAGS) SimulatedCathx.o $(LIBS) -o $@

simCrossbow:  simCrossbow.o SimulatedCrossbow.o $(LIBS) 
	$(LD) $(LDFLAGS) simCrossbow.o SimulatedCrossbow.o $(LIBS) -o $@

simDepthSensor:  simDepthSensor.o SimulatedDepthSensor.o $(LIBS) 
	$(LD) $(LDFLAGS) simDepthSensor.o SimulatedDepthSensor.o $(LIBS) -o $@

simAhrs:  simAhrs.o SimulatedAhrs.o $(LIBS) 
	$(LD) $(LDFLAGS) simAhrs.o SimulatedAhrs.o $(LIBS) -o $@

simRangeFinder:  simRangeFinder.o SimulatedRangeFinder.o PSA916Log.o $(LIBS) 
	$(LD) $(LDFLAGS) simRangeFinder.o SimulatedRangeFinder.o PSA916Log.o \
        $(LIBS) -o $@

# This one uses the flight code version of EchoSounderLog.cc.  It doesn't
# require a mostly duplicated simulation version of the log object, under the
# same name, as does the PSA and the dvl.
simEchoSounder:  simEchoSounder.o SimulatedEchoSounder.o \
                 ../echoSounder/EchoSounderLog.o $(LIBS) 
	@echo " "
	@echo "Checking  ../echoSounder/EchoSounderLog.o"
	@echo " "
	@cd ../echoSounder; \
	if \
	  make all; \
	then \
	  make install; \
	  echo ""; \
	  echo "make succeeded";\
	  echo ""; \
	else \
	  echo ""; \
	  echo "make failed";\
	  echo ""; \
	  exit; \
	fi; 
	$(LD) $(LDFLAGS) simEchoSounder.o SimulatedEchoSounder.o \
	../echoSounder/EchoSounderLog.o \
        $(LIBS) -o $@

#
# Tricky!  The rule below overrides the suffix rule, preventing THIS makefile
# from trying to make EchoSounderLog.o, but letting us use it as a dependency
# above.  The commands immediately following the above dependencies then
# explictly remakes it using the correct makefile in ../echoSounder.
#
EchoSounderLog.o: EchoSounderLog.cc
	true

# This one uses the flight code version of DeltaTLog.cc.  It doesn't
# require a mostly duplicated simulation version of the log object, under the
# same name, as does the PSA and the dvl.
simDeltaT:  simDeltaT.o SimulatedDeltaT.o \
                 ../delta_t/DeltaTLog.o $(LIBS) 
	@echo " "
	@echo "Checking  ../delta_t/DeltaTLog.o"
	@echo " "
	@cd ../delta_t; \
	if \
	  make all; \
	then \
	  make install; \
	  echo ""; \
	  echo "make succeeded";\
	  echo ""; \
	else \
	  echo ""; \
	  echo "make failed";\
	  echo ""; \
	  exit; \
	fi; 
	$(LD) $(LDFLAGS) simDeltaT.o SimulatedDeltaT.o \
	../delta_t/DeltaTLog.o \
        $(LIBS) -o $@

#
# Tricky!  The rule below overrides the suffix rule, preventing THIS makefile
# from trying to make DeltaTLog.o, but letting us use it as a dependency
# above.  The commands immediately following the above dependencies then
# explictly remakes it using the correct makefile in ../echoSounder.
#
DeltaTLog.o: DeltaTLog.cc
	true



# This one uses the flight code version of DeltaTLog.cc.  It doesn't
# require a mostly duplicated simulation version of the log object, under the
# same name, as does the PSA and the dvl.
simMbTrnRecv:  simMbTrnRecv.o SimulatedMbTrnRecv.o \
		../MbTrnRecv/MbTrnRecvLog.o $(LIBS) 
	@echo " "
	@echo "Checking  ../MbTrnRecv/MbTrnRecvLog.o"
	@echo " "
	@cd ../MbTrnRecv; \
	if \
	  make all; \
	then \
	  make install; \
	  echo ""; \
	  echo "make succeeded";\
	  echo ""; \
	else \
	  echo ""; \
	  echo "make failed";\
	  echo ""; \
	  exit; \
	fi; 
	$(LD) $(LDFLAGS) simMbTrnRecv.o SimulatedMbTrnRecv.o \
	../MbTrnRecv/MbTrnRecvLog.o $(LIBS) -o $@
#
# Tricky!  The rule below overrides the suffix rule, preventing THIS makefile
# from trying to make DeltaTLog.o, but letting us use it as a dependency
# above.  The commands immediately following the above dependencies then
# explictly remakes it using the correct makefile in ../echoSounder.
#
MbTrnRecvLog.o: MvTrnRecvLog.cc
	true



simTailCone:  simTailCone.o SimulatedTailCone.o $(LIBS) 
	$(LD) $(LDFLAGS) simTailCone.o SimulatedTailCone.o $(LIBS) -o $@

simGps:  simGps.o SimulatedGps.o ../gps/GpsLog.o ../gps/GpsUtils.o $(LIBS)
	@echo " "
	@echo "Checking  ../gps/GpsLog.o"
	@echo "Checking  ../gps/GpsUtils.o"
	@echo " "
	@cd ../gps; \
	if \
	  make all; \
	then \
	  make install; \
	  echo ""; \
	  echo "make succeeded";\
	  echo ""; \
	else \
	  echo ""; \
	  echo "make failed";\
	  echo ""; \
	  exit; \
	fi; 
	$(LD) $(LDFLAGS) simGps.o SimulatedGps.o \
        ../gps/GpsLog.o ../gps/GpsUtils.o $(LIBS) -o $@

# Override the suffix rule and prevent THIS makefile from doing it.
GpsLog.o: GpsLog.cc
	true

# Override the suffix rule and prevent THIS makefile from doing it.
GpsUtils.o: GpsUtils.cc
	true

simLbl:  simLbl.o SimulatedLbl.o $(LIBS) 
	$(LD) $(LDFLAGS) simLbl.o SimulatedLbl.o $(LIBS) -o $@

simDvl:	simDvl.o SimulatedDvl.o DvlLog.o $(LIBS) 
	$(LD) $(LDFLAGS) simDvl.o SimulatedDvl.o DvlLog.o $(LIBS) -o $@

simDvlSide:	simDvlSide.o SimulatedDvlSide.o DvlSideLog.o $(LIBS) 
	$(LD) $(LDFLAGS) simDvlSide.o SimulatedDvlSide.o DvlSideLog.o $(LIBS) -o $@

simKearfott:	simKearfott.o SimulatedKearfott.o $(LIBS) 
	$(LD) $(LDFLAGS) simKearfott.o SimulatedKearfott.o $(LIBS) -o $@

simUsbl: simUsbl.o SimulatedUsbl.o \
         ../sonardyne/SonardyneLog.o $(LIBS) 
	@echo " "
	@echo "Checking  ../sonardyne/SonardyneLog.o"
	@echo " "
	@cd ../sonardyne; \
	if \
	  make all; \
	then \
	  make install; \
	  echo ""; \
	  echo "make succeeded";\
	  echo ""; \
	else \
	  echo ""; \
	  echo "make failed";\
	  echo ""; \
	  exit; \
	fi; 
	$(LD) $(LDFLAGS) simUsbl.o SimulatedUsbl.o ../sonardyne/SonardyneLog.o \
	$(LIBS) -o $@

# Override the suffix rule and prevent THIS makefile from doing it.
SonardyneLog.o: SonardyneLog.cc
	true

simBluefinBatt:	simBluefinBatt.o SimulatedBluefinBatt.o $(LIBS) 
	$(LD) $(LDFLAGS) simBluefinBatt.o SimulatedBluefinBatt.o $(LIBS) -o $@

simHydroscat:	simHydroscat.o SimulatedHydroscat.o $(LIBS) 
	$(LD) $(LDFLAGS) simHydroscat.o SimulatedHydroscat.o $(LIBS) -o $@

simReson:	simReson.o SimulatedReson.o $(LIBS) 
	$(LD) $(LDFLAGS) simReson.o SimulatedReson.o $(LIBS) -o $@

simEdgetechFSDW:	simEdgetechFSDW.o SimulatedEdgetechFSDW.o $(LIBS) 
	$(LD) $(LDFLAGS) simEdgetechFSDW.o SimulatedEdgetechFSDW.o $(LIBS) -o $@

simModem:	simModem.o SimulatedBenthosModem.o $(LIBS) 
	$(LD) $(LDFLAGS) simModem.o SimulatedBenthosModem.o $(LIBS) -o $@

simTerrainAid: simTerrainAid.o SimulatedTerrainAid.o $(LIBS)
	$(LD) $(LDFLAGS) $^ -o $@

simGulper:  simGulper.o SimulatedGulperServer.o \
		../gulper/GulperLog.o ../gulper/GulperOutput.o $(LIBS) 
	@echo " "
	@echo "Checking  ../gulper/GulperLog.o and ../gulper/GulperOutput.o"
	@echo " "
	@cd ../gulper; \
	if \
	  make all; \
	then \
	  make install; \
	  echo ""; \
	  echo "make succeeded";\
	  echo ""; \
	else \
	  echo ""; \
	  echo "make failed";\
	  echo ""; \
	  exit; \
	fi; 
	$(LD) $(LDFLAGS) simGulper.o SimulatedGulperServer.o \
	../gulper/GulperLog.o ../gulper/GulperOutput.o \
        $(LIBS) -o $@

# Removed the following from the above:
#                 ../gulper/GulperOutput.o 
#	@echo "Checking  ../gulper/GulperOutput.o"
#	../gulper/GulperOutput.o \

# Override the suffix rule and prevent THIS makefile from doing it.

GulperLog.o: GulperLog.cc
	true

GulperOutput.o: GulperOutput.cc
	true

simIsus:  simIsus.o SimulatedIsus.o \
                 ../isus/IsusLog.o $(LIBS) 
	@echo " "
	@echo "Checking  ../isus/IsusLog.o"
	@echo " "
	@cd ../isus; \
	if \
	  make all; \
	then \
	  make install; \
	  echo ""; \
	  echo "make succeeded";\
	  echo ""; \
	else \
	  echo ""; \
	  echo "make failed";\
	  echo ""; \
	  exit; \
	fi; 
	$(LD) $(LDFLAGS) simIsus.o SimulatedIsus.o \
	../isus/IsusLog.o \
        $(LIBS) -o $@

# Override the suffix rule and prevent THIS makefile from doing it.
IsusLog.o: IsusLog.cc
	true

install:	$(TARGETS)
		cp -fnv $(TARGETS) 	$(AUV_BIN_DIR)/. 


##########################################################################
# Do not modify anything below this line unless absolutely necessary

.SUFFIXES:
.SUFFIXES:	.o .c .cc .d .idl


%.d: %.c
	    @echo Generating dependencies for $?
	    $(DEPEND_TOOL) $(INCLUDES) $? -f $@.tmp
	    @mv $@.tmp $@

%.d: %.cc
	    @echo Generating dependencies for $?
	    $(DEPEND_TOOL) $(INCLUDES) $? -f $@.tmp
	    @mv $@.tmp $@

%.o: %.c 
	    $(CC) $(CFLAGS) $(INCLUDES) $< -o $@	
	    @echo
%.o: %.cc
	    $(CCPP) $(CPPFLAGS) $(INCLUDES) $< -o $@
	    @echo

# #generic command to build object files from source files
# %.o :%.cpp
# 	@echo compiling $<...
# 	$(CPP) $(CPPFLAGS) $(INCLUDES) -c $< -o $@
# 	@echo

#generic command to build dependency files from source files
%.d :%.cpp
	@echo generating dependency file for $<
	$(DEPEND_TOOL) $(INCLUDES) $? -f $@.tmp
	@mv $@.tmp $@
	@echo

#
# Attempt to have make only install newer executables.
#$(AUV_BIN_DIR)/%:% 
#	cp $@ $(AUV_BIN_DIR)/$@


DEST	    = .

MAKEFILE    = Makefile

include       $(OBJS:.o=.d)

depend:	

clean:
	rm -vf core *.o *.d *.lib *.yy *.tab.* $(TARGETS)
#	rm -f core *.o $(OBJS:.o=.d) *.lib *.yy *.tab.* $(TARGETS)

update:
	cvs update $(CC_SRCS) $MAKEFILE

commit:
	cvs commit $(CC_SRCS) $MAKEFILE

##########################################################################









# DO NOT DELETE THIS LINE -- make depend depends on it.
