all:

# Flush suffixes
.SUFFIXES: .xxXxXxXXX

# All module subdirectories.
DIRS := GraphicsLib MathLib IOLib 
DIRS += GLViewers GetSysInfo 
DIRS += OccupancyMaps

# Those subdirectories that implement libraries.
LIBDIRS := GraphicsLib MathLib IOLib Main


###
###  Do not modify below this line.
###


# All source files (computer or human generated)
#  Organized based on any speciaal includes or flags needed.
GL_SRC := # OpenGL source:  Empty, added in submakefiles.
FL_SRC := # FLTK source:  Empty, added in submakefiles.
WX_SRC := # WXGTK source:  Empty, added in submakefiles.
O_SRC :=  # Other source (no flags): Empty, added in submakefiles.

PROGRAMS := # Empty, added in submakefiles.
LIBRARIES := # Empty, added in submakefiles.

# All object files.
OBJ := # Empty, added to automatically.

CLEANFILES := # Empty, added to automatically and manually.
DEPS := # Empty, added to automatically.




# look for include files in
#   each of the modules
C++ := g++
CC  := gcc

CLIBS := -lnana
CINC  := -I. $(patsubst %,-I%,$(LIBDIRS)) -Wall # BUGGO '-Wall' superflouis.
CFLAGS := -g -Wall ${CINC} -march=pentiumpro -O -Wuninitialized
#CFLAGS += -O3 -fomit-frame-pointer -funroll-loops 

# extra libraries if required
O_LIBS := $(CLIBS) 
O_INC  := 
O_CFLAGS := ${CFLAGS}

GL_LIBS := -lGL  -lglut -lGLU -lXmu $(CLIBS) 
GL_INC  := -L/usr/X11R6/lib/ 
GL_CFLAGS := ${GL_INC} ${CFLAGS}

FL_LIBS := -lfltk -lGL  -lglut -lGLU -lXmu $(CLIBS) 
FL_INC  := -L/usr/X11R6/lib/ 
FL_CFLAGS := ${FL_INC} ${CFLAGS}

WX_LIBS := -lwx_gtk -lwx_gtk_gl -lGL  -lglut -lGLU -lXmu $(CLIBS) 
WX_INC  := -L/usr/X11R6/lib/ 
WX_CFLAGS := ${WX_INC} ${CFLAGS}
# each module will add to this

# include the description for each module
include $(patsubst %,%/Makefile.dir,$(DIRS))

SRC := ${O_SRC} ${GL_SRC} ${WX_SRC} ${FL_SRC}

O_COBJS  := $(patsubst %.c,%.o,$(filter %.c,$(O_SRC)))
O_C++OBJS  := $(patsubst %.cpp,%.o,$(filter %.cpp,$(O_SRC)))
GL_C++OBJS := $(patsubst %.cpp,%.o,$(filter %.cpp,$(GL_SRC)))
FL_C++OBJS := $(patsubst %.cpp,%.o,$(filter %.cpp,$(FL_SRC)))
WX_C++OBJS := $(patsubst %.cpp,%.o,$(filter %.cpp,$(WX_SRC)))

OBJS := ${O_COBJS} ${O_C++OBJS} ${GL_C++OBJS} ${WX_C++OBJS} ${FL_C++OBJS}
CPPFLAGS := ${CINC}

DEPS := $(patsubst %.o,%.d,$(OBJS))
CLEANFILES += ${OBJS} ${DEPS}

$(patsubst %.c,%.d,$(filter %.c,$(SRC))) : %.d: %.c
	@echo "***** Doing dependencies for $<"
#	@echo "$(CC) -MM $(CPPFLAGS) $<"
	@set -e; b=`basename $* .c` ; d=`dirname $*` ; \
                $(CC) -MM $(CPPFLAGS) $< \
		| sed "s%\\($$b\\)\\.o[ :]*%$${d}/\\1.o $${d}/\\1.d : %g" > $@; \
		[ -s $@ ] || rm -f $@

$(patsubst %.cpp,%.d,$(filter %.cpp,$(SRC))) : %.d: %.cpp
	@echo "***** Doing dependencies for $<"
#	@echo "$(C++) -MM $(CPPFLAGS) $<"
	@set -e; b=`basename $* .cpp` ; d=`dirname $*` ; \
                $(C++) -MM $(CPPFLAGS) $< \
		| sed "s%\\($$b\\)\\.o[ :]*%$${d}/\\1.o $${d}/\\1.d : %g" > $@; \
		[ -s $@ ] || rm -f $@


${O_COBJS}: %.o : %.c %.d
	$(CC) ${CFLAGS} -o $@ -c $< 

$(GL_COBJS): %.o : %.c %.d
	$(CC) ${GL_CFLAGS} -o $@ -c $< 


${O_C++OBJS}: %.o : %.cpp %.d
	$(C++) ${O_CFLAGS} -o $@ -c $< 

$(FL_C++OBJS): %.o : %.cpp %.d
	$(C++) ${FL_CFLAGS} -o $@ -c $< 

$(GL_C++OBJS): %.o : %.cpp %.d
	$(C++) ${GL_CFLAGS} -o $@ -c $< 

$(WX_C++OBJS): %.o : %.cpp %.d
	$(C++) ${WX_CFLAGS} -o $@ -c $< 


all: bin lib
bin: ${PROGRAMS}
lib: $(LIBRARIES)
obj: ${OBJS}
dep: $(DEPS)


cleandep:
	rm -f $(DEPS)

cleanobj:
	rm -f ${OBJS}

cleanlib:
	rm -f ${LIBRARIES}

cleanbin:
	rm -f $(PROGRAMS)

cleansome: cleanbin cleanobj 

clean: cleanobj cleanbin cleanlib

# Clean everything.
cleanclean: clean cleandep
# Build everything, even if it is not used.
allall: all obj



include ${DEPS}


#
#  Special code for verifying dependencies for binaries.
#     clean out each compile codebase, then attempt to build the binary.
#   If it fails, we missed some dependency on a *.o or a lib. 
#   If it succeeds, then our dependency works perfect.
TESTdeps:
	make cleanclean
	make bin
	for i in ${PROGRAMS} ; do make cleanobj ; make $$i ; done

#routine to list all source files that have no programs depending on them:
#   make bin
# Then, anything which this builds has no dependency.
#   make allall


