CC=gcc
#  With TAU
TAU=${HOME}/tau2/x86_64/lib

CWD=`pwd`

TAU_MAKEFILE=${TAU}/Makefile.tau-pdt
include ${TAU_MAKEFILE}
TAUOP='-optCompile=-I$(CWD)/hdfwrapper/hdf5_wrapper -optLinking="-L$(CWD)/hdfwrapper/hdf5_wrapper/ -lhdf5_wrap" '

CC_INST = tau_cc.sh -tau_options=$(TAUOP)  
CC_UNINST = gcc


HDF5DIR=/usr/local/packages/hdf5-1.6.5
CFLAGS=-I$(HDF5DIR)/include
LIBS=-L$(HDF5DIR)/lib -lhdf5 -lm

all: build run analyze

build: checkhdf wrap

checkhdf: wrap checkhdf.c 
	@echo "Step 6: Building the uninstrumented application..."
	$(CC_UNINST) $(CFLAGS) checkhdf.c -o checkhdf $(LIBS)
	@echo "Done! "
	@echo " "
wrap:
	@echo "Building the wrapper ...: Step 1.: Copy the header interfaces to a wrapper directory"
	mkdir -p hdfwrapper; cp -r $(HDF5DIR)/include/* hdfwrapper
	@echo " "
	@echo "Building the wrapper ...: Step 2.: Copy the optional selective instrumentation file to the wrapper directory"
	cp select.tau hdfwrapper
	@echo " "
	@echo "Building the wrapper ...: Step 3.: Parse the header file containing the external package interfaces"
	cd hdfwrapper; $(PDTDIR)/$(PDTARCHDIR)/bin/cparse hdf5.h; 
	@echo " "
	@echo "Building the wrapper ...: Step 4.: Invoke tau_wrap and specify the PDB file, the header file and the wrapper library sources. "
	@echo "Building the wrapper ...:        : Optionally specify the selective instrumentation file and a group (hdf5)."
	@echo "Building the wrapper ...:        : Specify the runtime library to be pre-loaded using the -r <libname> option."
	cd hdfwrapper; tau_wrap hdf5.h.pdb hdf5.h -o hdf5.inst.c -f select.tau -g hdf5 -r libhdf5.so
	@echo " "
	@echo "Building the wrapper ...: Step 5 : Build the wrapper library using the source generated by the tau_wrap tool."
	cd hdfwrapper/hdf5_wrapper; gmake  TAU_MAKEFILE=$(TAU_MAKEFILE) AR='$(TAU_AR)'
	@echo " "

run: checkhdf wrap
	LD_LIBRARY_PATH=${HDF5DIR}/lib:${LD_LIBRARY_PATH}; \
	tau_exec -T serial -loadlib=`pwd`/hdfwrapper/hdf5_wrapper/libhdf5_wrap.so ./checkhdf
	@echo " "

analyze: run
	pprof

clean:
	/bin/rm -rf checkhdf.o checkhdf profile.* *.trc *.edf MULT* hdfwrapper SDS.h5
