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

MAKE                 = @MAKE@

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@
MPE_CFLAGS           = @MPE_CFLAGS@
MPE_FFLAGS           = @MPE_FFLAGS@
MPE_INCDIR           = @includebuild_dir@
MPE_LIBDIR           = @libbuild_dir@
LOG_LIBS             = -L$(MPE_LIBDIR) @LOG_LIBS@ $(MPI_LIBS)
TRACE_LIBS           = -L$(MPE_LIBDIR) @TRACE_LIBS@ $(MPI_LIBS)
F2CMPI_LIBS          = @F2CMPI_LIBS@
FLIB_PATH            = @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@
RM                   = @RM@

### End User configurable options ###

@VPATH@

srcdir        = @srcdir@

CFLAGS        = $(MPE_CFLAGS) $(C_INCS) 
FFLAGS        = $(MPE_FFLAGS) $(F_INCS)
CC_LDFLAGS    = $(LDFLAGS) $(MPE_CFLAGS)
FC_LDFLAGS    = $(LDFLAGS) $(MPE_FFLAGS)
EXECS         = cpilog srtest


.c.o:
	$(MPI_CC) $(CFLAGS) -c $<
.f.o:
	$(MPI_F77) $(FFLAGS) -c $<

default: $(EXECS)
	-if [ "$(MPE_BUILD_FORTRAN2C)" = "yes" ] ; then \
	     $(MAKE) fpilog ; \
	 fi

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

cpi_trace: cpi.o
	$(MPI_CLINKER) $(CC_LDFLAGS) -o $@ $? $(TRACE_LIBS) $(DEBUG_LIBS) -lm

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

fpilog: fpilog.o
	$(MPI_FLINKER) $(FC_LDFLAGS) -o $@ $? $(FLIB_PATH) $(DEBUG_LIBS) -lm

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

linktest: linktest_C

linktest_C: 
	@-echo ; \
	echo "** Testing if C application can be linked with logging library" ; \
	$(RM) -f cpi_log ; \
	$(MAKE) cpi_log ; \
	if test -x cpi_log ; then \
	    echo "** C application can be linked with logging library" ; \
	    $(RM) -f cpi_log ; \
	else \
	    echo "** C application CANNOT be linked with logging library" ; \
	fi 
	@-echo ; \
	echo "** Testing if C application can be linked with tracing library" ; \
	$(RM) -f cpi_trace ; \
	$(MAKE) cpi_trace ; \
	if test -x cpi_trace ; then \
	    echo "** C application can be linked with tracing library" ; \
	    $(RM) -f cpi_trace ; \
	else \
	    echo "** C application CANNOT be linked with tracing library" ; \
	fi 
	@-echo ; \
	echo "** Testing if C application can use both automatic and manual logging together" ; \
	$(RM) -f cpilog ; \
	$(MAKE) cpilog ; \
	if test -x cpilog ; then \
	    echo "** C application can use both automatic and manual logging together" ; \
	    $(RM) -f cpilog ; \
	else \
	    echo "** C application CANNOT use both automatic and manual logging together" ; \
	fi ; \
	echo
	@-$(MAKE) clean

linktest_F77: 
	@-if [ "$(MPE_BUILD_FORTRAN2C)" = "yes" ] ; then \
	    echo ; \
	    echo "** Testing if Fortran77 application can be linked with logging library" ; \
	    $(RM) -f fpilog ; \
	    $(MAKE) fpilog ; \
	    if test -x fpilog ; then \
	        echo "** Fortran77 application can be linked with logging library" ; \
	        $(RM) -f fpilog ; \
	    else \
	        echo "** Fortran77 application CANNOT be linked with logging library" ; \
	    fi ; \
	    echo ; \
	    $(MAKE) clean ; \
	  fi

clean:
	@-$(RM) -f work.pc work.pcl
	@-$(RM) -f *.o *~ PI* $(EXECS) cpi_log cpi_trace cpilog fpilog srtest
	@-$(RM) -f *.clog2 *.slog2

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