
##### User configurable options #####

MAKE                 = @MAKE@

CPP                  = @CPP@
CC                   = @CC@
CLINKER              = @CLINKER@
MPI_CC               = @MPI_CC@
MPI_F77              = @MPI_F77@
MPI_CLINKER          = $(MPI_CC)
MPI_FLINKER          = $(MPI_F77)
MPE_CLINKER          = @MPE_CLINKER@
MPE_FLINKER          = @MPE_FLINKER@
#
DEBUG_LIBS           = @DEBUG_LIBS@
MPI_CFLAGS           = @MPI_CFLAGS@
MPI_FFLAGS           = @MPI_FFLAGS@
MPI_LIBS             = @MPI_LIBS@
CFLAGS               = @CFLAGS@
FFLAGS               = @FFLAGS@
MPE_INCDIR           = @includebuild_dir@
MPE_LIBDIR           = @libbuild_dir@
MPE_SBINDIR          = @sbinbuild_dir@
PROF_LIBS            = -L$(MPE_LIBDIR) @PROF_LIBS@ $(MPI_LIBS)
LOG_LIBS             = -L$(MPE_LIBDIR) @LOG_LIBS@ $(MPI_LIBS)
TRACE_LIBS           = -L$(MPE_LIBDIR) @TRACE_LIBS@ $(MPI_LIBS)
F2CMPI_LIBS          = @F2CMPI_LIBS@
PROF_FLIBS           = @FLIB_PATH_LEADER@$(MPE_LIBDIR) \
                       $(F2CMPI_LIBS) @PROF_LIBS@ \
                       $(MPI_LIBS)
LOG_FLIBS            = @FLIB_PATH_LEADER@$(MPE_LIBDIR) \
                       $(F2CMPI_LIBS) @LOG_LIBS@ \
                       $(MPI_LIBS)
#
C_INCS               = -I$(MPE_INCDIR)
F_INCS               = @FINC_PATH_LEADER@$(MPE_INCDIR)
LDFLAGS              = @LDFLAGS@
MPE_BUILD_FORTRAN2C  = @MPE_BUILD_FORTRAN2C@

### End User configurable options ###

SHELL         = @SHELL@
RM            = @RM@
MV            = @MV@
CP            = @CPRP@

@VPATH@

srcdir        = @srcdir@

CC_FLAGS      = $(C_INCS) $(CFLAGS) $(MPE_COPTS)
FC_FLAGS      = $(F_INCS) $(FFLAGS) $(MPE_FOPTS)
CC_LDFLAGS    = $(LDFLAGS) $(CFLAGS) $(MPE_LDOPTS)
FC_LDFLAGS    = $(LDFLAGS) $(FFLAGS) $(MPE_LDOPTS)
# MPE include path, x_INCS, goes in front of MPI include path, MPI_xFLAGS,
# in case MPI include path is in MPI_xFLAGS containing old MPE include path.
MPICC_FLAGS   = $(C_INCS) $(MPI_CFLAGS) $(MPE_COPTS)
MPIFC_FLAGS   = $(F_INCS) $(MPI_FFLAGS) $(MPE_FOPTS)
MPICC_LDFLAGS = $(LDFLAGS) $(MPI_CFLAGS) $(MPE_LDOPTS)
MPIFC_LDFLAGS = $(LDFLAGS) $(MPI_FFLAGS) $(MPE_LDOPTS)

C_EXECS       = cpilog@EXEEXT@ cpilog_pack@EXEEXT@ srtest@EXEEXT@ comm1_isr@EXEEXT@
EXTRA_C_EXECS = cpi_trace@EXEEXT@ cpi_log@EXEEXT@ ncpilog@EXEEXT@ ncpilog_pack@EXEEXT@ iotest@EXEEXT@ comm1_isr_loop@EXEEXT@ log_cost@EXEEXT@
F_EXECS       = fpilog@EXEEXT@ fpilog_pack@EXEEXT@ fcomm1_isr@EXEEXT@
EXTRA_F_EXECS = nfpilog_pack@EXEEXT@

.SUFFIXES: .c .f .n@OBJEXT@ .@OBJEXT@ @EXEEXT@

.c.@OBJEXT@:
	$(MPI_CC) $(MPICC_FLAGS) -c $<

.f.@OBJEXT@:
	$(MPI_F77) $(MPIFC_FLAGS) -c $<

.c.n@OBJEXT@:
	$(MPI_CC) -DNO_MPI_LOGGING $(MPICC_FLAGS) -c $<
	$(MV) -f $*.@OBJEXT@ $*.n@OBJEXT@

.F.@OBJEXT@:
	$(RM) -f mpe2tmp.f mpe2tmp.@OBJEXT@
	$(CPP) $< > mpe2tmp.f && \
	$(MPI_F77) $(MPIFC_FLAGS) -c mpe2tmp.f
	$(MV) -f mpe2tmp.@OBJEXT@ $*.@OBJEXT@

.F.n@OBJEXT@:
	$(RM) -f mpe2tmp.f mpe2tmp.@OBJEXT@
	$(CPP) -DNO_MPI_LOGGING $< > mpe2tmp.f && \
	$(MPI_F77) $(MPIFC_FLAGS) -c mpe2tmp.f
	$(MV) -f mpe2tmp.@OBJEXT@ $*.n@OBJEXT@

default: $(C_EXECS)
	@-if [ "$(MPE_BUILD_FORTRAN2C)" = "yes" ] ; then \
	      for pgm in $(F_EXECS) ; do \
	          $(MAKE) $$pgm ; \
	      done ; \
	  fi

all: default $(EXTRA_C_EXECS)
	@-if [ "$(MPE_BUILD_FORTRAN2C)" = "yes" ] ; then \
	      for pgm in $(EXTRA_F_EXECS) ; do \
	          $(MAKE) $$pgm ; \
	      done ; \
	  fi

cpi_trace@EXEEXT@: cpi.@OBJEXT@
	$(MPE_CLINKER)mpitrace $(MPICC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(TRACE_LIBS) $(DEBUG_LIBS) -lm

cpi_log@EXEEXT@: cpi.@OBJEXT@
	$(MPE_CLINKER)mpilog $(MPICC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

cpilog@EXEEXT@: cpilog.@OBJEXT@
	$(MPE_CLINKER)mpilog $(MPICC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm 
#	$(MPI_CLINKER) $(MPICC_LDFLAGS)  -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm 

cpilog_pack@EXEEXT@: cpilog_pack.@OBJEXT@
	$(MPE_CLINKER)mpilog $(MPICC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm 
#	$(MPI_CLINKER) $(MPICC_LDFLAGS)  -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm 

ncpilog@EXEEXT@: cpilog.n@OBJEXT@
	$(CP) -f $? mpe2tmp.@OBJEXT@
	$(MPE_CLINKER)log $(MPICC_LDFLAGS) -o $@ mpe2tmp.@OBJEXT@ $(DEBUG_LIBS) -lm 
	@-$(RM) -f mpe2tmp.@OBJEXT@
#	$(MPI_CLINKER) $(MPICC_LDFLAGS)  -o $@ $? $(PROF_LIBS) $(DEBUG_LIBS) -lm 

ncpilog_pack@EXEEXT@: cpilog_pack.n@OBJEXT@
	$(CP) -f $? mpe2tmp.@OBJEXT@
	$(MPE_CLINKER)log $(MPICC_LDFLAGS)  -o $@ mpe2tmp.@OBJEXT@ $(DEBUG_LIBS) -lm 
	@-$(RM) -f mpe2tmp.@OBJEXT@
#	$(MPI_CLINKER) $(MPICC_LDFLAGS)  -o $@ $? $(PROF_LIBS) $(DEBUG_LIBS) -lm 

fpilog@EXEEXT@: fpilog.@OBJEXT@
	$(MPE_FLINKER)mpilog $(MPIFC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_FLINKER) $(MPIFC_LDFLAGS) -o $@ $? $(LOG_FLIBS) $(DEBUG_LIBS) -lm

fpilog_pack@EXEEXT@: fpilog_pack.@OBJEXT@
	$(MPE_FLINKER)mpilog $(MPIFC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_FLINKER) $(MPIFC_LDFLAGS) -o $@ $? $(LOG_FLIBS) $(DEBUG_LIBS) -lm

nfpilog_pack@EXEEXT@: fpilog_pack.n@OBJEXT@
	$(CP) -f $? mpe2tmp.@OBJEXT@
	$(MPE_FLINKER)log $(MPIFC_LDFLAGS) -o $@ mpe2tmp.@OBJEXT@ $(DEBUG_LIBS) -lm
	@-$(RM) -f mpe2tmp.@OBJEXT@
#	$(MPI_FLINKER) $(MPIFC_LDFLAGS) -o $@ $? $(PROF_FLIBS) $(DEBUG_LIBS) -lm

srtest@EXEEXT@: srtest.@OBJEXT@
	$(MPE_CLINKER)mpilog $(MPICC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

pthread_sendrecv@EXEEXT@: pthread_sendrecv.@OBJEXT@
	$(MPE_CLINKER)mpilog $(MPICC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

pthread_allreduce@EXEEXT@: pthread_allreduce.@OBJEXT@
	$(MPE_CLINKER)mpilog $(MPICC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

iotest@EXEEXT@: iotest.@OBJEXT@
	$(MPE_CLINKER)mpilog $(MPICC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

openmp_mpilog@EXEEXT@: openmp_mpilog.@OBJEXT@
	$(MPE_FLINKER)mpilog $(MPIFC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_FLINKER) $(MPIFC_LDFLAGS) -o $@ $? $(LOG_FLIBS) $(DEBUG_LIBS) -lm

comm1_isr@EXEEXT@: comm1_isr.@OBJEXT@
	$(MPE_CLINKER)mpilog $(MPICC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

comm1_isr_loop@EXEEXT@: comm1_isr_loop.@OBJEXT@
	$(MPE_CLINKER)mpilog $(MPICC_LDFLAGS)  -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

fcomm1_isr@EXEEXT@: fcomm1_isr.@OBJEXT@
	$(MPE_FLINKER)mpilog $(MPIFC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_FLINKER) $(MPIFC_LDFLAGS) -o $@ $? $(LOG_FLIBS) $(DEBUG_LIBS) -lm

comm2_connect_accept@EXEEXT@: comm2_connect_accept.@OBJEXT@
	$(MPE_CLINKER)mpilog $(MPICC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

comm2_spawn_parent@EXEEXT@: comm2_spawn_parent.@OBJEXT@
	$(MPE_CLINKER)mpilog $(MPICC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

comm2_spawn_child@EXEEXT@: comm2_spawn_child.@OBJEXT@
	$(MPE_CLINKER)mpilog $(MPICC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

comm2_join@EXEEXT@: comm2_join.@OBJEXT@
	$(MPE_CLINKER)mpilog $(MPICC_LDFLAGS) -o $@ $? $(DEBUG_LIBS) -lm
#	$(MPI_CLINKER) $(CC_LDFLAGS) -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

log_cost@EXEEXT@: log_cost.c
	$(CC) $(CC_FLAGS) -DCLOG_NOMPI -c $?
	$(CLINKER) $(CC_LDFLAGS) -DCLOG_NOMPI -o $@ log_cost.@OBJEXT@ -L$(MPE_LIBDIR) -lmpe_nompi

linktest: linktest_C

linktest_C: 
	@-$(MPE_SBINDIR)/mpetestlink cpi_trace@EXEEXT@ \
	  "*** Link C program with the MPI tracing library .........................."
	@-$(MPE_SBINDIR)/mpetestlink cpi_log@EXEEXT@ \
	  "*** Link C program with the MPI logging library .........................."
	@-$(MPE_SBINDIR)/mpetestlink cpilog@EXEEXT@ \
	  "*** Link C program with the MPI and manual logging libraries ............."
	@-echo ; $(MAKE) clean

linktest_F77: 
	@-if [ "$(MPE_BUILD_FORTRAN2C)" = "yes" ] ; then \
	    $(MPE_SBINDIR)/mpetestlink fpilog@EXEEXT@ \
	    "*** Link F77 program with the MPI and manual logging libraries ..........." ; \
	    $(MAKE) clean ; \
	    echo ; \
	  fi


runtest_C: 
	@-$(MPE_SBINDIR)/mpetestexec cpi_trace@EXEEXT@ \
	  "*** Test C program with the MPI tracing library .........................."
	@-$(MPE_SBINDIR)/mpetestexeclog cpi_log@EXEEXT@ \
	  "*** Test C program with the MPI logging library .........................."
	@-$(MPE_SBINDIR)/mpetestexeclog cpilog@EXEEXT@ \
	  "*** Test C program with the MPI and manual logging libraries ............."
	@-echo ; $(MAKE) clean

runtest_F77: 
	@-if [ "$(MPE_BUILD_FORTRAN2C)" = "yes" ] ; then \
	      $(MPE_SBINDIR)/mpetestexeclog fpilog@EXEEXT@ \
	      "*** Test F77 program with the MPI and manual logging libraries ..........." ; \
	      $(MAKE) clean ; \
	      echo ; \
	  fi

clean:
	@-$(RM) -f work.pc work.pcl
	@-$(RM) -f *.@OBJEXT@ *.n@OBJEXT@ *~ PI*
	@-$(RM) -f mpe2tmp.f
	@-$(RM) -f $(C_EXECS) $(F_EXECS)
	@-$(RM) -f $(EXTRA_C_EXECS) $(EXTRA_F_EXECS)
	@-$(RM) -f *.clog2 *.slog2

distclean: clean
	@-$(RM) -f Makefile
