# 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=-O#-DCMK_OPTIMIZE=1 -DCMK_MEMCHECKS_OFF=1

CHARMBASE=../../../
CHARMBIN=$(CHARMBASE)/bin
CHARMINC=$(CHARMBASE)/include

CHARMC=$(CHARMBIN)/charmc -I$(CHARMINC)/pose $(OPTS)

# 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:	$(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."

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

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

$(PGM).comm:	$(SIM_OBJECTS) 
	$(CHARMC) $(SIM_OBJECTS) $(OTHER) $(LIBS) -o $(PGM).comm \
	-lpose -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++ -lpose -purify

$(PGM).proj:	$(SIM_OBJECTS) $(POSE_ROOT)/libpose.a
	$(CHARMC) $(SIM_OBJECTS) $(OTHER) $(LIBS) -L$(POSE_ROOT) -o $(PGM).proj \
	-language charm++ -lpose -tracemode projections

$(PGM).summary:	$(SIM_OBJECTS) $(POSE_ROOT)/libpose.a
	$(CHARMC) $(SIM_OBJECTS) -L$(POSE_ROOT) -o $(PGM).summary \
	-language charm++ -lpose -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 
	$(CHARMBIN)/etrans.pl TCsim

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
	$(CHARMBIN)/etrans.pl NetSim


test:
	./pgm 100 8 10
