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

MAKE                 = @MAKE@

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@
F2CMPI_LIBS          = @F2CMPI_LIBS@
COLLCHK_LIBS         = -L$(MPE_LIBDIR) @COLLCHK_LIBS@ $(MPI_LIBS)
COLLCHK_FLIBS        = @FLIB_PATH_LEADER@$(MPE_LIBDIR) \
                       $(F2CMPI_LIBS) @COLLCHK_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@

@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)

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

C_SRC         = wrong_composite.c wrong_scatterv.c \
                wrong_int_byte.c wrong_root.c \
                composite.c scatterv.c \
                time_bcast.c time_allreduce.c \
                time_alltoallv.c time_alltoallv0.c
F_SRC         = wrong_reals.f
C_OBJS        = $(C_SRC:.c=.@OBJEXT@)
F_OBJS        = $(F_SRC:.f=.@OBJEXT@)
C_EXECS       = $(C_OBJS:.o=)

OPT_C_EXECS   = time_bcast_nochk@EXEEXT@ time_allreduce_nochk@EXEEXT@ \
                time_alltoallv0_nochk@EXEEXT@ time_alltoallv_nochk@EXEEXT@

OPT_F_EXECS   = wrong_reals@EXEEXT@ wrong_reals_nochk@EXEEXT@

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

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

.@OBJEXT@@EXEEXT@:
	$(MPE_CLINKER)mpicheck $(MPICC_LDFLAGS) -o $@ $<
#	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $< $(COLLCHK_LIBS)

time_bcast_nochk@EXEEXT@: time_bcast.@OBJEXT@
	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(MPI_LIBS)

time_allreduce_nochk@EXEEXT@: time_allreduce.@OBJEXT@
	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(MPI_LIBS)

time_alltoallv_nochk@EXEEXT@: time_alltoallv.@OBJEXT@
	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(MPI_LIBS)

time_alltoallv0_nochk@EXEEXT@: time_alltoallv0.@OBJEXT@
	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(MPI_LIBS)

wrong_int_byte@EXEEXT@: wrong_int_byte.@OBJEXT@
	$(MPE_CLINKER)mpicheck $(MPICC_LDFLAGS) -o $@ $?
#	$(MPI_CLINKER) $(MPICC_LDFLAGS) -o $@ $? $(COLLCHK_LIBS)

wrong_reals@EXEEXT@: wrong_reals.@OBJEXT@
	$(MPE_FLINKER)mpicheck $(MPIFC_LDFLAGS) -o $@ $?
#	$(MPI_FLINKER) $(MPIFC_LDFLAGS) -o $@ $? $(COLLCHK_FLIBS)

wrong_reals_nochk@EXEEXT@: wrong_reals.@OBJEXT@
	$(MPE_FLINKER)mpicheck $(MPIFC_LDFLAGS) -o $@ $?
#	$(MPI_FLINKER) $(MPIFC_LDFLAGS) -o $@ $? $(MPI_LIBS)

default: $(C_OBJS) $(C_EXECS) $(OPT_C_EXECS)

linktest: linktest_C

linktest_C:
	@-$(MPE_SBINDIR)/mpetestlink wrong_int_byte@EXEEXT@ \
	  "*** Link C program with the MPI collective/datatype checking library ....."
	@-echo ; $(MAKE) clean

linktest_F77:
	@-if [ "$(MPE_BUILD_FORTRAN2C)" = "yes" ] ; then \
	    $(MPE_SBINDIR)/mpetestlink wrong_reals@EXEEXT@ \
	    "*** Link F77 program with the MPI collective/datatype checking library ..." ; \
	    $(MAKE) clean ; \
	    echo ; \
	  fi


runtest_C:
	@-$(MPE_SBINDIR)/mpetestexec wrong_int_byte@EXEEXT@ \
	  "*** Test C program with the MPI collective/datatype checking library ....."
	@-echo ; $(MAKE) clean

runtest_F77:
	@-if [ "$(MPE_BUILD_FORTRAN2C)" = "yes" ] ; then \
	    $(MPE_SBINDIR)/mpetestexec wrong_reals@EXEEXT@ \
	    "*** Test F77 program with the MPI collective/datatype checking library ..." ; \
	    $(MAKE) clean ; \
	    echo ; \
	  fi

clean:
	@-$(RM) -f $(C_OBJS) $(F_OBJS) *.@OBJEXT@
	@-$(RM) -f $(C_EXECS) $(OPT_C_EXECS) $(OPT_F_EXECS)

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