# DPRSim/CodeModules
CC = g++
CFLAGS = -g -Wall -I . -I/usr/local/include -I /usr0/local/include -I .. -I ../ode-0.5/include -I../sqlite/ -L /usr/local/lib -L ../ode-0.5/lib -L ../sqlite/ -I ./Debugging -I/usr/include/newmat
LIB = -lpthread -lsqlite
MAC = -I/usr/local/include/boost-1_33_1/

GHEADERS = ../GlobalConstants.hxx

COMOSRCS = Hierarchy.cxx \
           SpeculationManager.cxx \
           DPRHierarchy.cxx GradientHierarchy.cxx \
           DPRHierarchy-HotBackups.cxx \
           Flicker.cxx \
	   RemoteFeatureTest.cxx \
	   TestAggregationUtils.cxx \
	   Life.cxx Color.cxx \
	   HexRotate.cxx Ellipsis.cxx \
	   CatomStick.cxx Localize.cxx \
	   XYMelt.cxx Sculpture.cxx \
	   BoundingBox.cxx \
	   SandCast.cxx Brownian.cxx ShiftInit.cxx \
	   Sprinkle.cxx Sprinkle2D.cxx Snowflake.cxx \
	   MagicMoveTest.cxx CubicCA.cxx \
	   CatomCamera.cxx TestDPRLine.cxx GradientField.cxx \
	   DConsensus.cxx ShapeMotion.cxx SoftwareTimer.cxx \
	   AntennaSim.cxx \
	   InterContactTest.cxx \
	   LockInfo.cxx RandomValue.cxx \
           FailureSimulator.cxx RPCHoleMotion.cxx \
	   modular.cxx P2CatomBase.cxx Point.cxx cyclecount.cxx \
	   DCondition.cxx pathsupport.cxx DcPlanner.cxx DcSnake.cxx DcAggregate.cxx  DcStoy.cxx DcPlanner2.cxx


HSRCS = $(COMOSRCS) $(COMOHELP)
SRCS  = $(HSRCS) $(UNSRCS) 

OBJS =  $(SRCS:cxx=o) TestAggregationDPR.o TestAggregationGradient.o TestAggregationHBTrad.o TestAggregationHB.o

HDRS =  $(HSRCS:cxx=hxx)

XFILES = $(SRCS:.cxx=-Instrumented.cxx)

all: codemodules

codemodules: $(OBJS) $(HDRS) $(GHEADERS)
	(cd Debugging; make)
	@echo "compiled"

TestAggregationDPR.o : TestAggregation.cxx TestAggregation.hxx
	@rm -f TestAggregationDPR.o
	./Debugging/InstrumentCXX.rb TestAggregation.cxx TestAggregation-Instrumented.cxx
	$(CC) $(CFLAGS) -c -g TestAggregation-Instrumented.cxx -o TestAggregationDPR.o
	@rm -f TestAggregation-Instrumented.cxx

TestAggregationGradient.o : TestAggregation.cxx TestAggregation.hxx
	@rm -f TestAggregationGradient.o
	./Debugging/InstrumentCXX.rb TestAggregation.cxx TestAggregation-Instrumented.cxx
	$(CC) $(CFLAGS) -DUSEGRADIENTHCHY -c -g TestAggregation-Instrumented.cxx -o TestAggregationGradient.o
	@rm -f TestAggregation-Instrumented.cxx

TestAggregationHBTrad.o : TestAggregationHB.cxx TestAggregationHB.hxx
	@rm -f TestAggregationHBTrad.o
	./Debugging/InstrumentCXX.rb TestAggregationHB.cxx TestAggregationHB-Instrumented.cxx
	$(CC) $(CFLAGS) -DUSETRADHCHY -c -g TestAggregationHB-Instrumented.cxx -o TestAggregationHBTrad.o
	@rm -f TestAggregationHB-Instrumented.cxx

TestAggregationHB.o : TestAggregationHB.cxx TestAggregationHB.hxx
	@rm -f TestAggregationHB.o
	./Debugging/InstrumentCXX.rb TestAggregationHB.cxx TestAggregationHB-Instrumented.cxx
	$(CC) $(CFLAGS) -c -g TestAggregationHB-Instrumented.cxx -o TestAggregationHB.o
	@rm -f TestAggregationHB-Instrumented.cxx

%.o : %.cxx %.hxx
	@rm -f $*.o
	./Debugging/InstrumentCXX.rb $*.cxx $*-Instrumented.cxx
	$(CC) $(CFLAGS) -c -g $*-Instrumented.cxx -o $*.o
#	@rm -f $*-Instrumented.cxx

%.cxx : %.meld
	sml @SMLload=compiler.x86-linux $*.meld $*

%.hxx : %.meld
	sml @SMLload=compiler.x86-linux $*.meld $*

clean:
	(cd Debugging; make clean)
	rm -f $(XFILES) *.o  *~ *.dat *.idx *.a a.out

depend:	$(SRCS)
	$(CC) $(CFLAGS) -M $(SRCS) > Makefile.deps

Makefile.deps:	depend
include Makefile.deps
