smvar_do_dependencies = ignore
smvar_do_sharedlibs   = 0

MOD              = @F90MODEXT@
MPIMOD           = @MPIMODNAME@
MPICONSTMOD      = @MPICONSTMODNAME@
MPISIZEOFMOD     = @MPISIZEOFMODNAME@
F90INCFLAG       = @F90INCFLAG@
F90EXT           = @F90EXT@
F90_COMPILE_MODS = $(F90_COMPILE) 
# We need to tell some compilers (e.g., Solaris f90) to look in the current 
# directory when the source file is not in the working directory (i.e.,
# in a VPATH build)
F90INCLUDES = @F90INCFLAG@.

lib${MPILIBNAME}f90_a_SOURCES = mpi.o mpi_constants.o mpi_sizeofs.o
all-preamble: $(MPIMOD).$(MOD)

# Thes copy line in this step makes the F90 modules available to 
# the mpif90 script before an install takes place
# The if handles the Intel F90 compiler, which has an unusual interface
# (The mpimod.pcl file should contain only a local mpimod.pc name; if
# it contains a file name in another directory and that file does not 
# exist, the compiler may refuse to compile the file)
#
# 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)
$(MPIMOD).$(MOD): $(MPICONSTMOD).$(MOD) $(MPISIZEOFMOD).$(MOD) \
		  $(srcdir)/mpi.f90 mpifnoext.h
	@if [ -n "@F90_WORK_FILES_ARG@" ] ; then \
	    rm -f mpimod.pc mpimod.pcl ; \
	    echo "mpimod.pc" > mpimod.pcl ; \
	    echo $(F90_COMPILE_MODS) @F90_WORK_FILES_ARG@ -c $(srcdir)/mpi.f90 ; \
	    $(F90_COMPILE_MODS) @F90_WORK_FILES_ARG@ -c $(srcdir)/mpi.f90 ; \
	    cp mpimod.pc ../../../src/include/mpimod.pc ; \
	    cp mpimod.pcl ../../../src/include/mpimod.pcl ; \
	else \
	    if [ "$(F90EXT)" != "f90" ] ; then \
	        ln -sf mpi.f90 mpi.$(F90EXT) ; \
	    fi ; \
	    echo $(F90_COMPILE_MODS) -c $(srcdir)/mpi.$(F90EXT) ; \
	    $(F90_COMPILE_MODS) -c $(srcdir)/mpi.$(F90EXT) ; \
	    if [ "$(F90EXT)" != "f90" ] ; then \
	        rm -f mpi.$(F90EXT) ; \
	    fi ; \
	fi

$(MPICONSTMOD).$(MOD): $(srcdir)/mpi_constants.f90 mpifnoext.h
	@if [ -n "@F90_WORK_FILES_ARG@" ] ; then \
	    rm -f mpimod.pc mpimod.pcl ; \
	    echo "mpimod.pc" > mpimod.pcl ; \
	    echo $(F90_COMPILE_MODS) @F90_WORK_FILES_ARG@ -c $(srcdir)/mpi_constants.f90 ; \
	    $(F90_COMPILE_MODS) @F90_WORK_FILES_ARG@ -c $(srcdir)/mpi.f90 ; \
	    cp mpimod.pc ../../../src/include/mpimod.pc ; \
	    cp mpimod.pcl ../../../src/include/mpimod.pcl ; \
	else \
	    if [ "$(F90EXT)" != "f90" ] ; then \
	        ln -sf mpi_constants.f90 mpi_constants.$(F90EXT) ; \
	    fi ; \
	    echo $(F90_COMPILE_MODS) -c $(srcdir)/mpi_constants.$(F90EXT) ; \
	    $(F90_COMPILE_MODS) -c $(srcdir)/mpi_constants.$(F90EXT) ; \
	    if [ "$(F90EXT)" != "f90" ] ; then \
	        rm -f mpi_constants.$(F90EXT) ; \
	    fi ; \
	fi

$(MPISIZEOFMOD).$(MOD): mpi_sizeofs.f90 mpifnoext.h
	@if [ -n "@F90_WORK_FILES_ARG@" ] ; then \
	    rm -f mpimod.pc mpimod.pcl ; \
	    echo "mpimod.pc" > mpimod.pcl ; \
	    echo $(F90_COMPILE_MODS) @F90_WORK_FILES_ARG@ -c mpi_sizeofs.f90 ; \
	    $(F90_COMPILE_MODS) @F90_WORK_FILES_ARG@ -c mpi_sizeofs.f90 ; \
	    cp mpimod.pc ../../../src/include/mpimod.pc ; \
	    cp mpimod.pcl ../../../src/include/mpimod.pcl ; \
	else \
	    if [ "$(F90EXT)" != "f90" ] ; then \
	        ln -sf mpi_sizeofs.f90 mpi_sizeofs.$(F90EXT) ; \
	    fi ; \
	    echo $(F90_COMPILE_MODS) -c mpi_sizeofs.$(F90EXT) ; \
	    $(F90_COMPILE_MODS) -c mpi_sizeofs.$(F90EXT) ; \
	    if [ "$(F90EXT)" != "f90" ] ; then \
	        rm -f mpi_sizeofs.$(F90EXT) ; \
	    fi ; \
	fi

# We need a free-format version of mpif.h with no external commands
mpifnoext.h: ../f77/mpif.h
	rm -f mpifnoext.h
	sed -e 's/^C/\!/g' -e '/EXTERNAL/d' \
		-e '/DOUBLE PRECISION/d' ../f77/mpif.h > mpifnoext.h

# To ensure that f90 can be used before a make-install step, we copy
# the library to the build directory (just like we do with the module files)
all-postamble:
	if [ -s lib${MPILIBNAME}f90.a ] ; then \
	   cp -p lib${MPILIBNAME}f90.a ../../../lib ; fi

clean-local:
	rm -f *.$(MOD)

install_INCLUDE = $(MPIMOD).$(MOD) $(MPISIZEOFMOD).$(MOD)
optinstall_INCLUDE = mpimod.pcl mpimod.pc
install_LIB     = lib${MPILIBNAME}f90.a

# Documentation sources
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}

distclean-local:
	rm -f lib${MPILIBNAME}f90.a
	rm -f ../../../bin/mpif90
	rm -f ../../../src/include/$(MPIMOD).$(MOD)
	rm -f ../../../lib/lib${MPILIBNAME}f90.a
	rm -f mpifnoext.h
