##########################################################################
# Copyright 2002 MBARI                                             
##########################################################################
# Summary  : Makefile for Cluster
# Filename : Makefile
# Author   : Frederic Py
# Project  : 
# Version  : Version 1.0
# Created  : 12/01/2006
# Archived :
##########################################################################
# Modification History:
#
##########################################################################

DMEM = NO
DEBUG = NO

include Init.make

INCLUDES    = -I.  \
	      -I$(AUV_HOME)/stlport \
	      -I$(AUV_HOME)/utils \
	      -I$(AUV_HOME)/framework \
	      -I$(AUV_HOME)/system \
	      -I$(AUV_HOME)/taskIF \
	      -I$(AUV_HOME)/DataLog \
	      -I/usr/include

LDFLAGS	    = $(DFLAG)
LIBPATH	    = /usr/lib:$(AUV_HOME)/lib

LIBS        =   $(AUV_HOME)/utils/utils.lib \
		$(AUV_HOME)/taskIF/taskInterfaces.lib \
		$(AUV_HOME)/framework/auvFramework.lib \
		$(AUV_HOME)/DataLog/dataLog.lib

ifeq ($(DMEM), YES)
MY_LIBS     =   dmem/dmem.lib
LIBS        = $(LIBS) $(MY_LIBS)
else
MY_LIBS     =
endif

UTILS_OBJS = utils/Symbol.o utils/ArgList.o \
             utils/ConfParser.o utils/ConfLexer.o utils/Random.o

DEVICE_IMPL = $(wildcard devices/impl/*.cc)
DEVICE_OBJS = devices/ValDB.o devices/DevicesManager.o \
	$(DEVICE_IMPL:.cc=.o)

CLASSIF_IMPL = $(wildcard classifiers/impl/*.cc)
CLASSIF_OBJS = classifiers/StateVector.o classifiers/StateMetrics.o \
	       classifiers/ClusterOutput.o classifiers/DeviceClassifier.o \
	       classifiers/ClusterLoader.o classifiers/NormalizedBase.o \
	       $(CLASSIF_IMPL:.cc=.o)

CLUSTER_OBJS = ClusterLogger.o Cluster.o _cluster.o \
	       $(CLASSIF_OBJS) $(DEVICE_OBJS) $(UTILS_OBJS) $(DMEM_OBJS)
SERVER_OBJS = ClusterServer.o _clusterServer.o classifiers/ClusterOutput.o \
	      $(UTILS_OBJS) $(DMEM_OBJS)

TARGETS =	cluster clusterServer

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


all: $(TARGETS)

cluster: $(CLUSTER_OBJS) $(LIBS)
	$(LD) $(LDFLAGS) $(CLUSTER_OBJS) $(MY_LIBS) $(LIBS) -o $@

clusterServer: $(SERVER_OBJS) $(MY_LIBS) $(LIBS)
	$(LD) $(LDFLAGS) $(SERVER_OBJS) $(MY_LIBS) $(LIBS) -o $@

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

install_cfg: 
	cp -f cluster.cfg $(AUV_CONFIG_DIR)

install_hmm_cfg:
	cp -f cluster.hmm.cfg $(AUV_CONFIG_DIR)

install_sim_cfg:
	cp -f cluster.sim.cfg $(AUV_CONFIG_DIR)/cluster.cfg

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

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

dmem/dmem.lib: my_libs

my_libs: 
	( cd dmem ; $(MAKE) ) 

utils/ConfParser.cc: utils/ConfParser.yy
	yacc -b ConfParser -d -v utils/ConfParser.yy
	cat ConfParser.tab.c | sed 's/yy/ConfParser/g' > $@
	rm ConfParser.tab.c
	cat ConfParser.tab.h | sed 's/yy/ConfParser/g' > utils/ConfParser_tab.hh
	rm ConfParser.tab.h

utils/ConfLexer.cc: utils/ConfParser.cc utils/ConfLexer.ll
	lex utils/ConfLexer.ll
	cat lex.yy.c | sed 's/yy/ConfParser/g' > $@
	rm lex.yy.c

utils/ConfParser_tab.hh: utils/ConfParser.cc

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

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

DEST	    = .

MAKEFILE    = Makefile

include       $(CLUSTER_OBJS:.o=.d)
include       $(SERVER_OBJS:.o=.d)

depend:	

clean:
	rm -f core $(CLUSTER_OBJS) $(CLUSTER_OBJS:.o=.d) $(SERVER_OBJS) \
	$(SERVER_OBJS:.o=.d) utils/ConfParser.cc utils/ConfParser_tab.hh \
	utils/ConfLexer.cc $(TARGETS) *~
	( cd dmem ; $(MAKE) clean )

update:
	cvs update $(CC_SRCS) $MAKEFILE

commit:
	cvs commit $(CC_SRCS) $MAKEFILE

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









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