# DPRSim makefile
CC = g++
CFLAGS = -g -Wall -I . -L ode-0.5/lib -I ode-0.5/include -L sqlite/.libs -I sqlite -L /usr/local/lib -I /usr/local/include -I ./CodeModules -I ./CodeModules/Debugging -I/usr/X11R6/include -I/usr/include/boost
LIB = -lpthread -lode sqlite/.libs/libsqlite3.a #-lnewmat
MAC = -I/usr/local/include/boost-1_33_1/ -I/usr/X11R6/include

GHEADERS = GlobalConstants.hxx 
UNSRCS = CatomCode.cxx

SIMSRCS = CatomWorld.cxx CatomSim.cxx CodeModule.cxx \
          SmartYield.cxx Catom.cxx Primitives.cxx \
          LatticeFunctions.cxx Util.cxx \
          Historian.cxx StatsManager.cxx \
          VisManager.cxx VisDataTransform.cxx VisDataTransforms.cxx \
	  DCondParse.cxx DCondManager.cxx

FMNW = Network.o FeatureMap.o FeatureMapIterator.o

HSRCS = $(SIMSRCS)
SRCS  = $(HSRCS) $(UNSRCS)

OBJS =  $(SRCS:cxx=o)

HDRS =  $(HSRCS:cxx=hxx)

# uncomment below to force threaded --- only way to build threaded version right now!!!  Oracles only work with treaded version!!!!!
#CFLAGS += -D__THREADED__ 

all: rmexecutables dprsim dprsimgr # dprsimthr dprsimthrgr  # the -thr versions don't work anyway -- see above option instead

rmexecutables:
	rm -f dprsim dprsimthr dprsimgr dprsimthrgr

dprsim: $(OBJS) $(HDRS) $(GHEADERS) DPRSim.o libfmnw.a CodeModules
	(cd CodeModules; make)
	(cd StateFile; make lib; cp libstatefile.a ..)
	$(CC) $(CFLAGS) -o dprsim $(OBJS) DPRSim.o CodeModules/*.o  CodeModules/Debugging/*.o $(LIB) libfmnw.a libstatefile.a

dprsimthr: $(OBJS) $(HDRS) $(GHEADERS) DPRSim.o libfmnw.a
	(cd CodeModules; make)
	(cd StateFile; make lib; cp libstatefile.a ..)
	$(CC) $(CFLAGS) -D__THREADED__ -o dprsimthr $(OBJS) DPRSim.o CodeModules/*.o  CodeModules/Debugging/*.o $(LIB) libfmnw.a libstatefile.a

DPRSimGr.o: DPRSim.cxx
	$(CC) $(CFLAGS) -D__USE_DRAWSTUFF__ DPRSim.cxx -c -o DPRSimGr.o

dprsimgr: dprsim DPRSimGr.o
	(cd graphics; make; cp libdprsimgr.a ..)
	$(CC) $(CFLAGS) -D__USE_DRAWSTUFF__ -o dprsimgr $(OBJS) DPRSimGr.o CodeModules/*.o CodeModules/Debugging/*.o Modeler.cxx WorldBuilder.cxx $(LIB) libfmnw.a libstatefile.a libdprsimgr.a -lGL -lGLU -lfreetype $(shell pkg-config gtk+-2.0 --libs) -lgthread-2.0 -lpthread

dprsimthrgr: dprsimthr DPRSimGr.o
	(cd graphics; make; cp libdprsimgr.a ..)
	$(CC) $(CFLAGS) -D__THREADED__ -D__USE_DRAWSTUFF__ -o dprsimthrgr $(OBJS) DPRSimGr.o CodeModules/*.o CodeModules/Debugging/*.o Modeler.cxx WorldBuilder.cxx $(LIB) libfmnw.a libstatefile.a libdprsimgr.a -lGL -lGLU -lfreetype $(shell pkg-config gtk+-2.0 --libs) -lgthread-2.0 -lpthread

%.o : %.cxx
	@rm -f $*.o
	$(CC) $(CFLAGS) $*.cxx -c

clean:
	rm -f *.o  *~ *.dat *.idx *.a a.out
	(cd CodeModules; make clean)
	(cd StateFile; make clean)
	(cd graphics; make clean)

lib: libfmnw.a

libfmnw.a: $(FMNW)
	ar rcs libfmnw.a $(FMNW)
