# NOTE: This is the basic Makefile template that includes the additional
#       Makefile.simulation makefile that is found in the location of the
#       current installation of POSE.
#
#	The Makefile.simulation set of rules allows the compilation of
#       a SINGLE simulation module. If multiple simulation modules are
#	desired, some "surgery" of Makefile.simulation (and this file)
#	will be required. 
#
# ***********************************************************************

# Default charmc options
# - changes here will be exported to upper level makefile
# *******************************************************
OPTS=-g -pg #-DCMK_OPTIMIZE=1 -DCMK_MEMCHECKS_OFF=1

CHARMBASE=../../../
#CHARMBASE=/expand8/home/gzheng/old/charm-6-8/net-linux/
CHARMBIN=$(CHARMBASE)/bin
CHARMINC=$(CHARMBASE)/include

ifeq ($(SEQUENTIAL),1)
CHARMC=$(CHARMBIN)/charmc -I$(CHARMINC)/pose $(OPTS) -DSEQUENTIAL_POSE=1
else
CHARMC=$(CHARMBIN)/charmc -I$(CHARMINC)/pose $(OPTS)
endif

# Default Location variables
# **************************
#POSE_ROOT=$(HOME)/charm/net-linux/lib

# Default module names
# - MAKE MODIFICATIONS HERE
# *************************
PGM_MODULE=Pgm
PGM=pgm
OTHER=-lconv-bluegene-logs
LIBS=-Lstdc++ -lm
#LIBS=/expand8/home/guna/charm/src/langs/bluegene/blue_seq.o


# Simulation object definitions 
# *****************************
SIM_OBJECTS=NetSim_sim.o TCsim_sim.o $(PGM).o 

# EXECUTABLE GENERATION RULES 
# - DO NOT MODIFY
#****************************

base:	sqtest $(PGM)
	@echo "Simulation compiled."

pure:   $(PGM).pure
	@echo "Simulation (w purify) compiled."

proj:   $(PGM).proj
	@echo "Simulation (w projections log traces) compiled."

summary:    $(PGM).summary
	@echo "Simulation (w summary log traces) compiled."

sqtest:
ifeq ($(SEQUENTIAL),1)
	cp  $(CHARMBASE)/lib/libmoduleseqpose.a $(CHARMBASE)/lib/libmodulepose.a
	cp  $(CHARMBASE)/lib_so/libmoduleseqpose.so $(CHARMBASE)/lib_so/libmodulepose.so
else
	cp  $(CHARMBASE)/lib/libmoduleorigpose.a $(CHARMBASE)/lib/libmodulepose.a
	cp  $(CHARMBASE)/lib_so/libmoduleorigpose.so $(CHARMBASE)/lib_so/libmodulepose.so
endif


$(PGM):	$(SIM_OBJECTS) 
	$(CHARMC) $(SIM_OBJECTS) $(OTHER) $(LIBS) -o $(PGM) \
	-module pose -ltrace-projections -language charm++ 

$(PGM).lb:	$(SIM_OBJECTS)
	$(CHARMC) $(SIM_OBJECTS) -o $(PGM).lb \
	-language charm++ -module pose

$(PGM).comm:	$(SIM_OBJECTS) 
	$(CHARMC) $(SIM_OBJECTS) $(OTHER) $(LIBS) -o $(PGM).comm \
	-module pose -ltrace-projections -language charm++ -module commlib

$(PGM).pure:	$(SIM_OBJECTS) $(POSE_ROOT)/libpose.a
	$(CHARMC) $(SIM_OBJECTS) -L$(POSE_ROOT) -o $(PGM).pure \
	-language charm++ -module pose -purify

$(PGM).proj:	$(SIM_OBJECTS) 
	$(CHARMC) $(SIM_OBJECTS) $(OTHER) $(LIBS) -o $(PGM).proj \
	-module pose -ltrace-projections -language charm++ -tracemode projections

$(PGM).summary:	$(SIM_OBJECTS) $(POSE_ROOT)/libpose.a
	$(CHARMC) $(SIM_OBJECTS) -L$(POSE_ROOT) -o $(PGM).summary \
	-language charm++ -module pose -tracemode summary

# HOUSE-KEEPING RULES
# - DO NOT MODIFY
#********************

# clean removes everything
clean:	clear rm_logs ;

# clear removes only binaries and generated files
clear:
	rm -f charmrun conv-host *.o
	rm -f *.def.h *.decl.h
	rm -f $(PGM) $(PGM).pure $(PGM).proj $(PGM).summary
	rm -f gmon.out #*#
	rm -f core *~
	rm -f TAGS *.headers
	rm -f *_sim.*

# rm_logs removes projections/summary log traces
rm_logs:
	rm -f [^j]*.log *.sum [^j]*.sts
	rm -f *-bg.*.log *-bg.sts

# SIMULATION COMPILATION RULES
# - DO NOT MODIFY 
#*****************************
$(PGM).o : 	$(PGM).C $(PGM).h $(PGM_MODULE).def.h $(PGM_MODULE).decl.h
	$(CHARMC) -c -I$(CHARMINC) $(INCLUDES) $(LIBS) $(PGM).C
 
$(PGM_MODULE).def.h $(PGM_MODULE).decl.h : $(PGM).ci
	$(CHARMC) $(INCLUDES) $(LIBS) $(PGM).ci
 
TCsim_sim.o :	NetSim.def.h TCsim_sim.C TCsim_sim.h \
			TCsim.def.h TCsim.decl.h
	$(CHARMC) -c $(LIBS) $(INCLUDES) -I$(CHARMINC) TCsim_sim.C
 
TCsim.def.h TCsim.decl.h : TCsim_sim.ci
	$(CHARMC) $(INCLUDES) $(LIBS) TCsim_sim.ci
 
TCsim_sim.C TCsim_sim.h TCsim_sim.ci: TCsim.C \
		TCsim.h TCsim.ci 
ifeq ($(SEQUENTIAL),1)
	$(CHARMBIN)/etrans.pl -s TCsim
else
	$(CHARMBIN)/etrans.pl  TCsim
endif

NetSim_sim.o :	TCsim.def.h NetSim_sim.C NetSim_sim.h \
			NetSim.def.h NetSim.decl.h
	$(CHARMC) -c $(LIBS) $(INCLUDES) -I$(CHARMINC) NetSim_sim.C
 
NetSim.def.h NetSim.decl.h : NetSim_sim.ci
	$(CHARMC) $(INCLUDES) $(LIBS) NetSim_sim.ci
 
NetSim_sim.C NetSim_sim.h NetSim_sim.ci: NetSim.C \
		NetSim.h NetSim.ci
ifeq ($(SEQUENTIAL),1)
	$(CHARMBIN)/etrans.pl -s NetSim
else
	$(CHARMBIN)/etrans.pl NetSim
endif


test:
	./pgm 100 8 10
