
##### 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@
ANIM_LIBS            = -L$(MPE_LIBDIR) @ANIM_LIBS@ $(MPI_LIBS)
C_XGRAPH_LIBS        = -L$(MPE_LIBDIR) @XGRAPH_LIBS@ $(MPI_LIBS)
F_XGRAPH_LIBS        = @FLIB_PATH_LEADER@$(MPE_LIBDIR) @XGRAPH_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         = cpi_anim cxgraphics


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

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

cpi_anim: cpi.o
	$(MPI_CLINKER) $(CC_LDFLAGS) -o $@ $? $(ANIM_LIBS) $(DEBUG_LIBS) -lm 

cxgraphics: cxgraphics.o
	$(MPI_CLINKER) $(CC_LDFLAGS) -o $@ $? $(C_XGRAPH_LIBS) $(DEBUG_LIBS) -lm

fxgraphics: fxgraphics.o
	$(MPI_FLINKER) $(FC_LDFLAGS) -o $@ $? $(F_XGRAPH_LIBS) $(DEBUG_LIBS) -lm

linktest: linktest_C

linktest_C: 
	@-echo ; \
	echo "** Testing if C application can be linked with animation library" ; \
	$(RM) -f cpi_anim ; \
	$(MAKE) cpi_anim ; \
	if test -x cpi_anim ; then \
	    echo "** C application can be linked with animation library" ; \
	    $(RM) -f cpi_anim ; \
	else \
	    echo "** C application CANNOT be linked with animation library" ; \
	fi
	@-echo ; \
	echo "** Testing if C application can be linked with graphics library" ; \
	$(RM) -f cxgraphics ; \
	$(MAKE) cxgraphics ; \
	if test -x cxgraphics ; then \
	    echo "** C application can be linked with graphics library" ; \
	    $(RM) -f cxgraphics ; \
	else \
	    echo "** C application CANNOT be linked with graphics library" ; \
	fi
	echo
	@-$(MAKE) clean

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

clean:
	@-$(RM) -f work.pc work.pcl
	@-$(RM) -f *.o *~ PI* $(EXECS) cpi_anim cxgraphics fxgraphics

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