## DO NOT EDIT
## This file created by buildiface 
##
## vim: set ft=automake :

MOD              = @FCMODEXT@
MPIMOD           = @MPIMODNAME@
MPICONSTMOD      = @MPICONSTMODNAME@
MPISIZEOFMOD     = @MPISIZEOFMODNAME@
MPIBASEMOD       = @MPIBASEMODNAME@
FC_COMPILE_MODS  = $(LTFCCOMPILE)

# ensure that the buildiface script ends up in the release tarball
EXTRA_DIST += src/binding/f90/buildiface

# additional perl files that are "require"d by f90/buildiface and
# f77/buildiface, respectively
EXTRA_DIST += src/binding/f90/binding.sub src/binding/f90/cf90tdefs

# FIXME need to add proper rules to rebuild the fortran sources generated by
# buildiface when buildiface is updated
if MAINTAINER_MODE
$(top_srcdir)/src/binding/f90/Makefile.mk: src/binding/f90/buildiface-stamp

src/binding/f90/buildiface-stamp: $(top_srcdir)/src/binding/f90/buildiface $(top_srcdir)/src/include/mpi.h.in
	( cd $(top_srcdir)/src/binding/f90 && ./buildiface )
endif MAINTAINER_MODE

# variables for custom "silent-rules" for F90 modules
mod_verbose = $(mod_verbose_$(V))
mod_verbose_ = $(mod_verbose_$(AM_DEFAULT_VERBOSITY))
mod_verbose_0 = @echo "  MOD     " $@;

if BUILD_F90_LIB

# We need to tell some compilers (e.g., Solaris f90) to look for modules in the
# current directory when the source file is not in the working directory (i.e.,
# in a VPATH build)
AM_FCFLAGS += @FCINCFLAG@src/binding/f90

lib_LTLIBRARIES += lib/lib@MPILIBNAME@f90.la

# C source that implements both the C and the Fortran bindings for the type
# creation routines.  These go into libmpich.la and will be built a second time
# for inclusion in libpmpich.la on platforms that do not support weak symbols.
# If shared libraries are enabled then the compilation space doubles again.
mpi_f90_c_sources = \
    src/binding/f90/create_f90_int.c \
    src/binding/f90/create_f90_real.c \
    src/binding/f90/create_f90_complex.c \
    src/binding/f90/typef90cmplxf.c \
    src/binding/f90/typef90realf.c \
    src/binding/f90/typef90intf.c

mpi_sources += $(mpi_f90_c_sources)

# utility code that has no PMPI equivalent
lib_lib@MPILIBNAME@_la_SOURCES += src/binding/f90/create_f90_util.c
AM_CPPFLAGS += -Isrc/binding/f90
noinst_HEADERS +=                     \
    src/binding/f90/create_f90_util.h \
    src/binding/f90/cf90t.h           \
    src/binding/f90/mpif90type.h      \
    src/binding/f90/mpifnoext.h

nodist_noinst_HEADERS += \
    src/binding/f90/mpif90model.h

# actual f90 code that also gets compiled into modules
lib_lib@MPILIBNAME@f90_la_LDFLAGS = $(ABIVERSIONFLAGS)

# cause any .$(MOD) files to be output in the f90 bindings directory instead of
# the current directory
AM_FCFLAGS += $(FCMODOUTFLAG)src/binding/f90

# we "manually" build the f90 sources and add them with LIBADD
lib_lib@MPILIBNAME@f90_la_SOURCES =
lib_lib@MPILIBNAME@f90_la_LIBADD = \
    src/binding/f90/mpi.lo \
    src/binding/f90/mpi_constants.lo \
    src/binding/f90/mpi_sizeofs.lo \
    src/binding/f90/mpi_base.lo

# now force libtool FC rules/variables to be generated and cause FC linking to
# be selected for lib/lib@MPILIBNAME@f90.la
EXTRA_lib_lib@MPILIBNAME@f90_la_SOURCES = \
    src/binding/f90/mpi.f90 \
    src/binding/f90/mpi_constants.f90

nodist_EXTRA_lib_lib@MPILIBNAME@f90_la_SOURCES = \
    src/binding/f90/mpi_sizeofs.f90 \
    src/binding/f90/mpi_base.f90

# FIXME: We may want to edit the mpif.h to convert Fortran77-specific
# items (such as an integer*8 used for file offsets) into the 
# corresponding Fortran 90 KIND type, to accomodate compilers that
# reject non-standard features such as integer*8 (such as the Intel
# Fortran compiler with -std95).
# We need the MPI constants in a separate module for some of the
# interface definitions (the ones that need MPI_ADDRESS_KIND or
# MPI_OFFSET_KIND)
src/binding/f90/mpi.$(MOD)-stamp: src/binding/f90/$(MPICONSTMOD).$(MOD) src/binding/f90/$(MPISIZEOFMOD).$(MOD) src/binding/f90/$(MPIBASEMOD).$(MOD) $(srcdir)/src/binding/f90/mpi.f90 src/binding/f90/mpifnoext.h
	@rm -f src/binding/f90/mpi-tmp
	@touch src/binding/f90/mpi-tmp
	@( cd src/binding/f90 && \
	   if [ "$(FCEXT)" != "f90" ] || [ ! -f mpi.$(FCEXT) ] ; then \
	       rm -f mpi.$(FCEXT) ; \
	       $(LN_S) $(abs_top_srcdir)/src/binding/f90/mpi.f90 mpi.$(FCEXT) ; \
	   fi )
	$(mod_verbose)$(FC_COMPILE_MODS) -c src/binding/f90/mpi.$(FCEXT) -o src/binding/f90/mpi.lo
	@( cd src/binding/f90 && \
	   if [ "$(FCEXT)" != "f90" ] || [ ! -f mpi.$(FCEXT) ] ; then \
	       rm -f mpi.$(FCEXT) ; \
	   fi )
	@mv src/binding/f90/mpi-tmp src/binding/f90/mpi.$(MOD)-stamp

src/binding/f90/mpi.lo src/binding/f90/$(MPIMOD).$(MOD): src/binding/f90/mpi.$(MOD)-stamp
## Recover from the removal of $@
	@if test -f $@; then :; else \
	  trap 'rm -rf src/binding/f90/mpi-lock src/binding/f90/mpi.$(MOD)-stamp' 1 2 13 15; \
	  if mkdir src/binding/f90/mpi-lock 2>/dev/null; then \
## This code is being executed by the first process.
	    rm -f src/binding/f90/mpi.$(MOD)-stamp; \
	    $(MAKE) $(AM_MAKEFLAGS) src/binding/f90/mpi.$(MOD)-stamp; \
	    rmdir src/binding/f90/mpi-lock; \
	  else \
## This code is being executed by the follower processes.
## Wait until the first process is done.
	    while test -d src/binding/f90/mpi-lock; do sleep 1; done; \
## Succeed if and only if the first process succeeded.
	    test -f src/binding/f90/mpi.$(MOD)-stamp; exit $$?; \
	  fi; \
	fi

CLEANFILES += src/binding/f90/mpi.$(MOD)-stamp src/binding/f90/$(MPIMOD).$(MOD) src/binding/f90/mpi.lo src/binding/f90/mpi-tmp


src/binding/f90/mpi_constants.$(MOD)-stamp: src/binding/f90/mpi_constants.f90 src/binding/f90/mpifnoext.h
	@rm -f src/binding/f90/mpi_constants-tmp
	@touch src/binding/f90/mpi_constants-tmp
	@( cd src/binding/f90 && \
	   if [ "$(FCEXT)" != "f90" ] || [ ! -f mpi_constants.$(FCEXT) ] ; then \
	       rm -f mpi_constants.$(FCEXT) ; \
	       $(LN_S) $(abs_top_srcdir)/src/binding/f90/mpi_constants.f90 mpi_constants.$(FCEXT) ; \
	   fi )
	$(mod_verbose)$(FC_COMPILE_MODS) -c src/binding/f90/mpi_constants.$(FCEXT) -o src/binding/f90/mpi_constants.lo
	@( cd src/binding/f90 && \
	   if [ "$(FCEXT)" != "f90" ] || [ ! -f mpi_constants.$(FCEXT) ] ; then \
	       rm -f mpi_constants.$(FCEXT) ; \
	   fi )
	@mv src/binding/f90/mpi_constants-tmp src/binding/f90/mpi_constants.$(MOD)-stamp

src/binding/f90/mpi_constants.lo src/binding/f90/$(MPICONSTMOD).$(MOD): src/binding/f90/mpi_constants.$(MOD)-stamp
## Recover from the removal of $@
	@if test -f $@; then :; else \
	  trap 'rm -rf src/binding/f90/mpi_constants-lock src/binding/f90/mpi_constants.$(MOD)-stamp' 1 2 13 15; \
	  if mkdir src/binding/f90/mpi_constants-lock 2>/dev/null; then \
## This code is being executed by the first process.
	    rm -f src/binding/f90/mpi_constants.$(MOD)-stamp; \
	    $(MAKE) $(AM_MAKEFLAGS) src/binding/f90/mpi_constants.$(MOD)-stamp; \
	    rmdir src/binding/f90/mpi_constants-lock; \
	  else \
## This code is being executed by the follower processes.
## Wait until the first process is done.
	    while test -d src/binding/f90/mpi_constants-lock; do sleep 1; done; \
## Succeed if and only if the first process succeeded.
	    test -f src/binding/f90/mpi_constants.$(MOD)-stamp; exit $$?; \
	  fi; \
	fi

CLEANFILES += src/binding/f90/mpi_constants.$(MOD)-stamp src/binding/f90/$(MPICONSTMOD).$(MOD) src/binding/f90/mpi_constants.lo src/binding/f90/mpi_constants-tmp


src/binding/f90/mpi_sizeofs.$(MOD)-stamp: src/binding/f90/mpi_sizeofs.f90 src/binding/f90/mpifnoext.h
	@rm -f src/binding/f90/mpi_sizeofs-tmp
	@touch src/binding/f90/mpi_sizeofs-tmp
	@( cd src/binding/f90 && \
	   if [ "$(FCEXT)" != "f90" ] ; then \
	       rm -f mpi_sizeofs.$(FCEXT) ; \
	       $(LN_S) mpi_sizeofs.f90 mpi_sizeofs.$(FCEXT) ; \
	   fi )
	$(mod_verbose)$(FC_COMPILE_MODS) -c src/binding/f90/mpi_sizeofs.$(FCEXT) -o src/binding/f90/mpi_sizeofs.lo
	@( cd src/binding/f90 && \
	   if [ "$(FCEXT)" != "f90" ] ; then \
	       rm -f mpi_sizeofs.$(FCEXT) ; \
	   fi )
	@mv src/binding/f90/mpi_sizeofs-tmp src/binding/f90/mpi_sizeofs.$(MOD)-stamp

src/binding/f90/mpi_sizeofs.lo src/binding/f90/$(MPISIZEOFMOD).$(MOD): src/binding/f90/mpi_sizeofs.$(MOD)-stamp
## Recover from the removal of $@
	@if test -f $@; then :; else \
	  trap 'rm -rf src/binding/f90/mpi_sizeofs-lock src/binding/f90/mpi_sizeofs.$(MOD)-stamp' 1 2 13 15; \
	  if mkdir src/binding/f90/mpi_sizeofs-lock 2>/dev/null; then \
## This code is being executed by the first process.
	    rm -f src/binding/f90/mpi_sizeofs.$(MOD)-stamp; \
	    $(MAKE) $(AM_MAKEFLAGS) src/binding/f90/mpi_sizeofs.$(MOD)-stamp; \
	    rmdir src/binding/f90/mpi_sizeofs-lock; \
	  else \
## This code is being executed by the follower processes.
## Wait until the first process is done.
	    while test -d src/binding/f90/mpi_sizeofs-lock; do sleep 1; done; \
## Succeed if and only if the first process succeeded.
	    test -f src/binding/f90/mpi_sizeofs.$(MOD)-stamp; exit $$?; \
	  fi; \
	fi

CLEANFILES += src/binding/f90/mpi_sizeofs.$(MOD)-stamp src/binding/f90/$(MPISIZEOFMOD).$(MOD) src/binding/f90/mpi_sizeofs.lo src/binding/f90/mpi_sizeofs-tmp


src/binding/f90/mpi_base.$(MOD)-stamp: src/binding/f90/mpi_base.f90 src/binding/f90/$(MPICONSTMOD).$(MOD)
	@rm -f src/binding/f90/mpi_base-tmp
	@touch src/binding/f90/mpi_base-tmp
	@( cd src/binding/f90 && \
	   if [ "$(FCEXT)" != "f90" ] ; then \
	       rm -f mpi_base.$(FCEXT) ; \
	       $(LN_S) mpi_base.f90 mpi_base.$(FCEXT) ; \
	   fi )
	$(mod_verbose)$(FC_COMPILE_MODS) -c src/binding/f90/mpi_base.$(FCEXT) -o src/binding/f90/mpi_base.lo
	@( cd src/binding/f90 && \
	   if [ "$(FCEXT)" != "f90" ] ; then \
	       rm -f mpi_base.$(FCEXT) ; \
	   fi )
	@mv src/binding/f90/mpi_base-tmp src/binding/f90/mpi_base.$(MOD)-stamp

src/binding/f90/mpi_base.lo src/binding/f90/$(MPIBASEMOD).$(MOD): src/binding/f90/mpi_base.$(MOD)-stamp
## Recover from the removal of $@
	@if test -f $@; then :; else \
	  trap 'rm -rf src/binding/f90/mpi_base-lock src/binding/f90/mpi_base.$(MOD)-stamp' 1 2 13 15; \
	  if mkdir src/binding/f90/mpi_base-lock 2>/dev/null; then \
## This code is being executed by the first process.
	    rm -f src/binding/f90/mpi_base.$(MOD)-stamp; \
	    $(MAKE) $(AM_MAKEFLAGS) src/binding/f90/mpi_base.$(MOD)-stamp; \
	    rmdir src/binding/f90/mpi_base-lock; \
	  else \
## This code is being executed by the follower processes.
## Wait until the first process is done.
	    while test -d src/binding/f90/mpi_base-lock; do sleep 1; done; \
## Succeed if and only if the first process succeeded.
	    test -f src/binding/f90/mpi_base.$(MOD)-stamp; exit $$?; \
	  fi; \
	fi

CLEANFILES += src/binding/f90/mpi_base.$(MOD)-stamp src/binding/f90/$(MPIBASEMOD).$(MOD) src/binding/f90/mpi_base.lo src/binding/f90/mpi_base-tmp



mpi_f90_modules = \
    src/binding/f90/$(MPIMOD).$(MOD) \
    src/binding/f90/$(MPISIZEOFMOD).$(MOD) \
    src/binding/f90/$(MPICONSTMOD).$(MOD) \
    src/binding/f90/$(MPIBASEMOD).$(MOD)

# the modules are effectively precompiled headers for Fortran programs
include_HEADERS += $(mpi_f90_modules)

# We need a free-format version of mpif.h with no external commands,
# including no wtime/wtick (removing MPI_WTICK also removes MPI_WTIME, 
# but leave MPI_WTIME_IS_GLOBAL).
# Also allow REAL*8 or DOUBLE PRECISION for the MPI_WTIME/MPI_WTICK 
# declarations
src/binding/f90/mpifnoext.h: src/binding/f77/mpif.h
	rm -f $@
	sed -e 's/^C/\!/g' -e '/EXTERNAL/d' \
		-e '/REAL\*8/d' \
		-e '/DOUBLE PRECISION/d' \
		-e '/MPI_WTICK/d' src/binding/f77/mpif.h > $@

CLEANFILES += src/binding/f90/mpifnoext.h

MAINTAINERCLEANFILES += $(mpi_sources) fproto.h
CLEANFILES += $(mpi_f90_modules)

# Documentation sources
# FIXME disabled for now until we sort out how to handle docs correctly in the
# new build system
#doc_sources =
#DOCDESTDIRS = html:www/www1,man:man/man1,latex:doc/refman
#doc_HTML_SOURCES  = ${doc_sources}
#doc_MAN_SOURCES   = ${doc_sources}
#doc_LATEX_SOURCES = ${doc_sources}

endif BUILD_F90_LIB
