##### JEROME  PLEASE PUT SOME COMMENTS HERE ABOUT WHAT THIS IS #############
##### All the mbari source files:

SRCDIR             	:= src/
OBJDIR				:= obj/
BINDIR				:= bin/
CC              	:= gcc
CXX             	:= g++
CXXFLAGS        	:= -Wall -g -w -O3 -Wno-non-virtual-dtor -march=i686 -fpic 
ADDDEF				:= 
DEFS            	:= -DPACKAGE_STRING=\"Monterey\ Bay\ Aquarium\ Research\ Institute\" -DINST_BYTE=1 -DINST_FLOAT=1 $(ADDDEF)
CPPFLAGS			:= -I$(SRCDIR)  -I$(SALIENCYROOT)/src -include config.h
LDFLAGS         	:= -L$(SALIENCYROOT)/build/obj -L/usr/lib/qt-3.3/lib -Wl,-rpath,/usr/lib/qt-3.3/lib -lxerces-c -lz -lbz2 -lX11 -lpng -ljpeg -lXext -lpthread -lavutil -lavcodec -lavformat -ldc1394_control -lraw1394 -lSDL -lz
DEPFILE				:= alldepends
COMPILE1       	    := @echo 
COMPILE2            := @
COMPILE3            := 
CDEPS				:= $(BINDIR)cdeps

all: $(CDEPS) $(BINDIR)avedclassifier $(BINDIR)BuildDataBase $(BINDIR)AddImagesToDataBase $(BINDIR)MatchImages2DataBase 

# make an executable from shared libraries
$(BINDIR)%:
	$(COMPILE1) "Linking executable program" $@
	$(COMPILE2) $(CXX) $(CXXFLAGS) $(LDFLAGS)  \
	  $(addprefix $(PWD)/,$(filter-out /%, $+)) \
	  $(filter /%, $+)  \
	  -o $@
	  $(COMPILE3)

# make an object file from a C++ source file
$(OBJDIR)%.o: $(SRCDIR)%.C
	@mkdir -p $(dir $@)
	$(COMPILE1) "Compiling C++ file        " $<
	$(COMPILE2) $(CXX) $(DEFS) $(CPPFLAGS) $(CXXFLAGS) \
		-c $< \
		-o $@
	$(COMPILE3)

##### Rule to build the dependency-computing program:
$(CDEPS): cdeps.cc
	$(COMPILE1) Compiling source dependencies calculator
	$(COMPILE2) $(CXX) -O2 -Wall $^ -o $@ 

#################################################################
##### Rule to build the source file dependencies ####
#### To add a new executable, add the line --execformat, 
#### e.g. to add a new test file build from the source test.C
#### --exeformat "$(SRCDIR)test.C : $(BINDIR)test
#################################################################
$(DEPFILE):$(CDEPS) 
	$(COMPILE1) Computing source file dependencies
	$(COMPILE2) $(CDEPS) \
	   --srcdir "$(SRCDIR)" \
	   --includedir "$(SRCDIR)" \
   	   --includedir "$(SALIENCYROOT)/src" \
	   --objdir "$(OBJDIR)" \
	   --objext ".o" \
	   --literal .I \
	   --exeformat "$(SRCDIR)Sift.C : $(BINDIR)avedclassifier" \
	   --exeformat "$(SRCDIR)BuildDataBase.C : $(BINDIR)BuildDataBase" \
	   --exeformat "$(SRCDIR)AddImagesToDataBase.C : $(BINDIR)AddImagesToDataBase" \
	   --exeformat "$(SRCDIR)MatchImages2DataBase.C : $(BINDIR)MatchImages2DataBase" \
	   --linkformat "$(SRCDIR) : $(OBJDIR)*.o" \
	   --linkformat "$(SALIENCYROOT)/src/ : $(SALIENCYROOT)/build/obj/*.o" \
	   --options-file depoptions \
	   --output-link-deps \
	   --output-compile-deps \
	   --sources-variable SOURCES \
	   --headers-variable HEADERS \
           > $(@)

.PHONY: clean allclean

clean	:
	@-rm -rf $(BINDIR)*	
	@-rm -rf $(OBJDIR)

depclean:
	@-rm -f $(DEPFILE) 

allclean: clean depclean

-include $(DEPFILE)
