ALL: all

MAKE   = @MAKE@
SHELL  = @SHELL@
MKDIR  = @MKDIR@
RM     = @RM@
CP     = @CPRP@

top_srcdir        = @top_srcdir@
srcdir            = @srcdir@

# Build directories
includebuild_dir  = @includebuild_dir@
libbuild_dir      = @libbuild_dir@
binbuild_dir      = @binbuild_dir@
etcbuild_dir      = @etcbuild_dir@
sbinbuild_dir     = @sbinbuild_dir@

# Building Fortran to C interface
MPE_BUILD_FORTRAN2C  = @MPE_BUILD_FORTRAN2C@
# MPI implementation: used to turn on/off of certain feature
MPI_IMPL             = @MPI_IMPL@
# MPE header files that are needed by endusers
MPE_HEADERS          = ""

all: build_include build_lib_bin build_etc linktest_all

#######  Building from the source
build_include:
	@-if [ -n "$(includebuild_dir)" ] ; then \
	      if [ ! -d $(includebuild_dir) ] ; then \
	          $(MKDIR) -p $(includebuild_dir) ; \
	      fi ; \
	      for file in $(MPE_HEADERS) ; do \
	          if [ -f $(top_srcdir)/include/$$file ] ; then \
	              $(CP) -f $(top_srcdir)/include/$$file \
	                       $(includebuild_dir) ; \
	          fi ; \
	      done ; \
	  fi

build_lib_bin:
	@( cd src && $(MAKE) )

build_etc:
	@-for file in ./etc/*.conf ; do \
	      $(CP) -f $$file $(etcbuild_dir) ; \
	  done

########  Linkage Tests
linktest_all: linktest_C linktest_F77

linktest_C:
	@if [ "$(MPI_IMPL)" != "MPICH" -a "$(MPI_IMPL)" != "MPICH2" ] ; then \
	     ( cd test && $(MAKE) linktest_C ) ; \
	 fi

linktest_F77:
	@if [ "$(MPE_BUILD_FORTRAN2C)" = "yes" ] ; then \
	     if [    "$(MPI_IMPL)" != "MPICH" \
	          -a "$(MPI_IMPL)" != "MPICH2" ] ; then \
	         ( cd test && $(MAKE) linktest_F77 ) ; \
	     fi ; \
	 fi
	@echo

########  Cleaning
# This is always a VPATH build, cleaning up the MPE_HEADERS
clean_include:
	@-cd $(includebuild_dir) && \
	  for file in $(MPE_HEADERS) ; do \
	      $(RM) -f $$file ; \
	  done

clean_lib:

clean_bin:

clean_etc:
	@-$(RM) -f ./etc/*.conf

clean: clean_bin clean_lib
	@( cd src && $(MAKE) clean )

distclean: clean_include clean_bin clean_lib clean_etc
	@-( cd src && $(MAKE) distclean )
	@-$(RM) -f mpe_collchk_conf.h
	@-$(RM) -f Makefile test/Makefile
	@-$(RM) -f config.log config.status
	@-$(RM) -rf autom4te*.cache

maintainer-clean: distclean
	@-$(RM) -f mpe_collchk_conf.h.in

owner-clean: maintainer-clean
	@-$(RM) -f configure
