ALL: default
##### User configurable options #####

MPIR_HOME   = @MPIR_HOME@
CC          = @MPICC@
CLINKER     = @MPICC@
CCC         = @MPICPLUSPLUS@
CCLINKER    = $(CCC)
F77         = @MPIF77@
FLINKER     = @MPIF77@
OPTFLAGS    = @OPTFLAGS@

### End User configurable options ###

SHELL = /bin/sh

PROFLIB =
CFLAGS  = $(OPTFLAGS) 
CCFLAGS = $(CFLAGS)
FFLAGS = $(OPTFLAGS)
# Use LIBS to add any special libraries for C programs
LIBS = 
# Use FLIBS to add any special libraries for Fortran programs
FLIBS = 
EXECS = cart cart2 graphtest cartmap cartorder

default: $(EXECS)

#
# Note that runtests builds the executables as required
testing: 
	-./runtests $(TESTARGS)

linktest: default clean

all: testing

fortran_tests: cartf twod cart1f cart2f

cart: cart.o test.o
	$(CLINKER) $(OPTFLAGS) -o cart cart.o test.o $(LIBS)

cartmap: cartmap.o
	$(CLINKER) $(OPTFLAGS) -o cartmap cartmap.o $(LIBS)

cartorder: cartorder.o test.o
	$(CLINKER) $(OPTFLAGS) -o cartorder cartorder.o test.o $(LIBS)

cart2: cart2.o test.o
	$(CLINKER) $(OPTFLAGS) -o cart2 cart2.o test.o $(LIBS)

graphtest: graphtest.o
	$(CLINKER) $(OPTFLAGS) -o graphtest graphtest.o $(LIBS)

cartf: mpif.h cartf.o
	$(FLINKER) $(OPTFLAGS) -o cartf cartf.o $(FLIBS)

cart1f: mpif.h cart1f.o
	$(FLINKER) $(OPTFLAGS) -o cart1f cart1f.o $(FLIBS)

cart2f: mpif.h cart2f.o
	$(FLINKER) $(OPTFLAGS) -o cart2f cart2f.o $(FLIBS)

twod: mpif.h twod.o
	$(FLINKER) $(OPTFLAGS) -o twod twod.o $(FLIBS)

#
# Some systems have no test for a symbolic link and return false for
# a link that exists
mpif.h: $(MPIR_HOME)/include/mpif.h
	if test \! -f mpif.h ; then \
	    /bin/rm -f mpif.h ; \
	    ln -s $(MPIR_HOME)/include/mpif.h . ; \
	fi
clean:
	/bin/rm -f *.o *~ core PI* $(EXECS) cartf twod cart1f cart2f topol.diff

.c.o:
	$(CC) $(CFLAGS) -c $*.c
.f.o:
	$(F77) $(FFLAGS) -c $*.f
