include Makefile.defs


# -- NO instrumentation
PREP      =
PREP_POMP =
PREP_TAU  =


# -- Automatic instrumentation (Only for some compilers, see USAGE document)
PREP      = scalasca -instrument

# -- Manual POMP instrumentation (disables automatic instrumentation)
PREP_POMP = $(PREP) -pomp

# -- Automatic TAU instrumentation (needs PDToolkit)
PREP_TAU  = $(PREP) -tau

# -- Support for manual instrumentation
ECONFFLAG  = -DEPIK
VCONFFLAG  = -DVT_INST
CONFLIB   = `kconfig --mpi --$(PREC) --libs`
FECONFFLAG = $(FDOPT)EPIK
FVCONFFLAG = $(FDOPT)VT_INST
FCONFLIB  = `kconfig --for --mpi --$(PREC) --libs`


# -- MPI test cases
MCC       = $(MPICC) $(PFLAG)
MF90      = $(MPIF90) $(PFLAG) $(FPP)
MCPROGS   = ctest-mpi ftest-mpi
MPPROGS   = ctest-pomp-mpi ftest-pomp-mpi
MEPROGS   = ctest-epik-mpi ftest-epik-mpi
MOPROGS   = ctest-elg-mpi ftest-elg-mpi
MTPROGS   = ctest-tau-mpi ftest-tau-mpi
MVPROGS   = ctest-vt-mpi ftest-vt-mpi
MXPROGS   = ctest-xt-mpi ftest-xt-mpi

# -- Hybrid test cases (MPI/OpenMP)
HCC       = $(HYBCC) $(PFLAG) $(OMPFLAG) -DOPENMP
HF90      = $(HYBF90) $(PFLAG) $(OMPFLAG) $(FPP) $(FDOPT)OPENMP
HCPROGS   = ctest-hyb ftest-hyb
HPPROGS   = ctest-pomp-hyb ftest-pomp-hyb
#HEPROGS   = ctest-epik-hyb ftest-epik-hyb
#HOPROGS   = ctest-elg-hyb ftest-elg-hyb
HTPROGS   = ctest-tau-hyb ftest-tau-hyb
#HVPROGS   = ctest-vt-hyb ftest-vt-hyb
HXPROGS   = ctest-xt-hyb ftest-xt-hyb

# -- Required with and without instrumentation
CONFINC   = `kconfig --$(PREC) --cflags`
FCONFINC  = `kconfig --for --$(PREC) --cflags`


# -- Rules --
all: auto-progs pomp-progs epik-progs tau-progs

clean:
	rm -rf core a.* *.o
	rm -f *.inc *.mod.* opari.* *.tau.* *.pdb
	rm -f $(MCPROGS) $(MPPROGS) $(MEPROGS) $(MOPROGS) $(MVPROGS) \
              $(MXPROGS) $(MTPROGS)
	rm -f $(HCPROGS) $(HPPROGS) $(HEPROGS) $(HOPROGS) $(HVPROGS) \
              $(HXPROGS) $(HTPROGS)

auto-progs:
	$(MAKE) $(MCPROGS)
	@if test "$(OMPFLAG)" = "-OpenMPnotAvailable"; then \
		echo "INFO: Skipping hybrid auto-progs"; \
	else \
		echo $(MAKE) $(HCPROGS); \
		eval $(MAKE) $(HCPROGS); \
	fi
pomp-progs:
	$(MAKE) $(MPPROGS)
	@if test "$(OMPFLAG)" = "-OpenMPnotAvailable"; then \
		echo "INFO: Skipping hybrid pomp-progs"; \
	else \
		echo $(MAKE) $(HPPROGS); \
		eval $(MAKE) $(HPPROGS); \
	fi
epik-progs:
	$(MAKE) $(MEPROGS)
# Skip hybrid, since no EPIK instrumentation in OpenMP part
	@echo "INFO: Skipping hybrid epik-progs"
elg-progs:
	$(MAKE) $(MOPROGS)
# Skip hybrid, since no ELG instrumentation in OpenMP part
	@echo "INFO: Skipping hybrid elg-progs"
vt-progs:
	$(MAKE) $(MVPROGS)
# Skip hybrid, since no VT instrumentation in OpenMP part
	@echo "INFO: Skipping hybrid vt-progs"
xt-progs:
	$(MAKE) $(MXPROGS)
	@if test "$(OMPFLAG)" = "-OpenMPnotAvailable"; then \
		echo "INFO: Skipping hybrid xt-progs"; \
	else \
		echo $(MAKE) $(HXPROGS); \
		eval $(MAKE) $(HXPROGS); \
	fi
tau-progs:
	@if test "$(PDTDIR)" = ""; then \
		echo "INFO: Skipping tau-progs"; \
	else \
		$(MAKE) real-tau-progs; \
	fi
real-tau-progs:
	$(MAKE) $(MTPROGS)
	@if test "$(OMPFLAG)" = "-OpenMPnotAvailable"; then \
		echo "INFO: Skipping hybrid tau-progs"; \
	else \
		echo $(MAKE) $(HTPROGS); \
		eval $(MAKE) $(HTPROGS); \
	fi


# -- Build rules / Automatic compiler instrumentation --
ctest-mpi: ctest.c
	$(PREP) $(MCC) ctest.c -o ctest-mpi $(MPILIB)

ftest-mpi: ftest.F90
	$(PREP) $(MF90) ftest.F90 -o ftest-mpi $(MPILIB)

ctest-hyb: ctest.c
	rm -f opari.rc
	$(PREP) $(HCC) ctest.c -o ctest-hyb $(MPILIB)

ftest-hyb: ftest.F90
	rm -f opari.rc
	$(PREP) $(HF90) ftest.F90 -o ftest-hyb $(MPILIB)


# -- Build rules / Automatic compiler instrumentation --
# -- (separate compile and link) --
ctest-xt-mpi: ctest.c
	$(PREP) $(MCC) ctest.c -c
	$(PREP) $(MCC) ctest.o -o ctest-xt-mpi $(MPILIB)

ftest-xt-mpi: ftest.F90
	$(PREP) $(MF90) ftest.F90 -c
	$(PREP) $(MF90) ftest.o -o ftest-xt-mpi $(MPILIB)

ctest-xt-hyb: ctest.c
	rm -f opari.rc
	$(PREP) $(HCC) ctest.c -c
	$(PREP) $(HCC) ctest.o -o ctest-xt-hyb $(MPILIB)

ftest-xt-hyb: ftest.F90
	rm -f opari.rc
	$(PREP) $(HF90) ftest.F90 -c
	$(PREP) $(HF90) ftest.o -o ftest-xt-hyb $(MPILIB)


# -- Build rules / Manual POMP instrumentation --
ctest-pomp-mpi: ctest-pomp.c
	rm -f opari.rc
	$(PREP_POMP) $(MCC) ctest-pomp.c -o ctest-pomp-mpi $(MPILIB)

ftest-pomp-mpi: ftest-pomp.F90
	rm -f opari.rc
	$(PREP_POMP) $(MF90) ftest-pomp.F90 -o ftest-pomp-mpi $(MPILIB)

ctest-pomp-hyb: ctest-pomp.c
	rm -f opari.rc
	$(PREP_POMP) $(HCC) ctest-pomp.c -o ctest-pomp-hyb $(MPILIB)

ftest-pomp-hyb: ftest-pomp.F90
	rm -f opari.rc
	$(PREP_POMP) $(HF90) ftest-pomp.F90 -o ftest-pomp-hyb $(MPILIB)


# -- Build rules / Manual EPIK instrumentation --
ctest-epik-mpi: ctest-epik.c
	$(MCC) $(ECONFFLAG) $(CONFINC) ctest-epik.c \
		-o ctest-epik-mpi $(CONFLIB) $(MPILIB)

ftest-epik-mpi: ftest-epik.F90
	$(MF90) $(FECONFFLAG) $(FCONFINC) ftest-epik.F90 \
		-o ftest-epik-mpi $(FCONFLIB) $(MPILIB)

# -- Build rules / Manual ELG instrumentation --
ctest-elg-mpi: ctest-elg.c
	$(MCC) $(ECONFFLAG) $(CONFINC) ctest-elg.c \
		-o ctest-elg-mpi $(CONFLIB) $(MPILIB)

ftest-elg-mpi: ftest-elg.F90
	$(MF90) $(FECONFFLAG) $(FCONFINC) ftest-elg.F90 \
		-o ftest-elg-mpi $(FCONFLIB) $(MPILIB)

# -- Build rules / VampirTrace instrumentation --
ctest-vt-mpi: ctest-vt.c
	$(MCC) $(VCONFFLAG) $(CONFINC) ctest-vt.c \
		-o ctest-vt-mpi $(CONFLIB) $(MPILIB)

ftest-vt-mpi: ftest-vt.F90
	$(MF90) $(FVCONFFLAG) $(FCONFINC) ftest-vt.F90 \
		-o ftest-vt-mpi $(FCONFLIB) $(MPILIB)

# -- Build rules / TAU instrumentation --
ctest-tau-mpi: ctest.c
	rm -f opari.rc
	$(PREP_TAU) $(MCC) ctest.c -c
	$(PREP_TAU) $(MCC) ctest.o -o ctest-tau-mpi $(MPILIB)

ftest-tau-mpi: ftest.F90
	rm -f opari.rc
	$(PREP_TAU) $(MF90) ftest.F90 -c
	$(PREP_TAU) $(MF90) ftest.o -o ftest-tau-mpi $(MPILIB)

ctest-tau-hyb: ctest.c
	rm -f opari.rc
	$(PREP_TAU) $(HCC) ctest.c -o ctest-tau-hyb $(MPILIB)

ftest-tau-hyb: ftest.F90
	rm -f opari.rc
	$(PREP_TAU) $(HF90) ftest.F90 -o ftest-tau-hyb $(MPILIB)


