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

MAKE                 = @MAKE@

CPP                  = @CPP@
MPI_CC               = @MPI_CC@
MPI_F77              = @MPI_F77@
MPI_CLINKER          = $(MPI_CC)
MPI_FLINKER          = $(MPI_F77)
#
DEBUG_LIBS           = @DEBUG_LIBS@
MPI_INC              = @MPI_INC@
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) $(MPI_INC)
F_INCS               = @FINC_PATH_LEADER@$(MPE_INCDIR) $(MPI_INC)
LDFLAGS              = @LDFLAGS@
MPE_BUILD_FORTRAN2C  = @MPE_BUILD_FORTRAN2C@

### End User configurable options ###

SHELL         = @SHELL@
RM            = @RM@

@VPATH@

srcdir        = @srcdir@

CC_FLAGS      = $(CFLAGS) $(C_INCS) $(MPE_COPTS)
FC_FLAGS      = $(FFLAGS) $(F_INCS) $(MPE_FOPTS)
CC_LDFLAGS    = $(LDFLAGS) $(CFLAGS) $(MPE_LDOPTS)
FC_LDFLAGS    = $(LDFLAGS) $(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@ 
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) $(CC_FLAGS) -c $<

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

.c.n@OBJEXT@:
	$(MPI_CC) -DNO_MPI_LOGGING $(CC_FLAGS) -c $<
	mv -f $*.@OBJEXT@ $*.n@OBJEXT@

.F.@OBJEXT@:
	rm -f mpe2tmp.f mpe2tmp.@OBJEXT@
	$(CPP) $< > mpe2tmp.f && \
	$(MPI_F77) $(FC_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) $(FC_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@
	$(MPI_CLINKER) $(CC_LDFLAGS) -o $@ $? $(TRACE_LIBS) $(DEBUG_LIBS) -lm

cpi_log@EXEEXT@: cpi.@OBJEXT@
	$(MPI_CLINKER) $(CC_LDFLAGS) -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

cpilog@EXEEXT@: cpilog.@OBJEXT@
	$(MPI_CLINKER) $(CC_LDFLAGS)  -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm 

cpilog_pack@EXEEXT@: cpilog_pack.@OBJEXT@
	$(MPI_CLINKER) $(CC_LDFLAGS)  -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm 

ncpilog@EXEEXT@: cpilog.n@OBJEXT@
	$(MPI_CLINKER) $(CC_LDFLAGS)  -o $@ $? $(PROF_LIBS) $(DEBUG_LIBS) -lm 

ncpilog_pack@EXEEXT@: cpilog_pack.n@OBJEXT@
	$(MPI_CLINKER) $(CC_LDFLAGS)  -o $@ $? $(PROF_LIBS) $(DEBUG_LIBS) -lm 

fpilog@EXEEXT@: fpilog.@OBJEXT@
	$(MPI_FLINKER) $(FC_LDFLAGS) -o $@ $? $(LOG_FLIBS) $(DEBUG_LIBS) -lm

fpilog_pack@EXEEXT@: fpilog_pack.@OBJEXT@
	$(MPI_FLINKER) $(FC_LDFLAGS) -o $@ $? $(LOG_FLIBS) $(DEBUG_LIBS) -lm

nfpilog_pack@EXEEXT@: fpilog_pack.n@OBJEXT@
	$(MPI_FLINKER) $(FC_LDFLAGS) -o $@ $? $(PROF_FLIBS) $(DEBUG_LIBS) -lm

srtest@EXEEXT@: srtest.@OBJEXT@
	$(MPI_CLINKER) $(CC_LDFLAGS)  -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

iotest@EXEEXT@: iotest.@OBJEXT@
	$(MPI_CLINKER) $(CC_LDFLAGS)  -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

comm1_isr@EXEEXT@: comm1_isr.@OBJEXT@
	$(MPI_CLINKER) $(CC_LDFLAGS)  -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

comm1_isr_loop@EXEEXT@: comm1_isr_loop.@OBJEXT@
	$(MPI_CLINKER) $(CC_LDFLAGS)  -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

fcomm1_isr@EXEEXT@: fcomm1_isr.@OBJEXT@
	$(MPI_FLINKER) $(FC_LDFLAGS) -o $@ $? $(LOG_FLIBS) $(DEBUG_LIBS) -lm

comm2_connect_accept@EXEEXT@: comm2_connect_accept.@OBJEXT@
	$(MPI_CLINKER) $(CC_LDFLAGS)  -o $@ $? $(LOG_LIBS) $(DEBUG_LIBS) -lm

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

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
