Blame src/env/mpif77.bash.in

Packit Service c5cf8c
#! @BASH_SHELL@
Packit Service c5cf8c
#
Packit Service c5cf8c
# (C) 2006 by Argonne National Laboratory.
Packit Service c5cf8c
#     See COPYRIGHT in top-level directory.
Packit Service c5cf8c
#
Packit Service c5cf8c
# mpif77
Packit Service c5cf8c
# Simple script to compile and/or link MPI programs.
Packit Service c5cf8c
# This script knows the default flags and libraries, and can handle
Packit Service c5cf8c
# alternative C compilers and the associated flags and libraries.
Packit Service c5cf8c
# The important terms are:
Packit Service c5cf8c
#    includedir, libdir - Directories containing an *installed* mpich
Packit Service c5cf8c
#    prefix, execprefix - Often used to define includedir and libdir
Packit Service c5cf8c
#    F77                - Fortran 77 compiler
Packit Service c5cf8c
#    WRAPPER_FFLAGS     - Any special flags needed to compile 
Packit Service c5cf8c
#    WRAPPER_LDFLAGS    - Any special flags needed to link
Packit Service c5cf8c
#    WRAPPER_LIBS       - Any special libraries needed in order to link
Packit Service c5cf8c
#    F77_OTHER_LIBS     - Yet more libraries, needed just with F77
Packit Service c5cf8c
#    
Packit Service c5cf8c
#    
Packit Service c5cf8c
# We assume that (a) the C compiler can both compile and link programs
Packit Service c5cf8c
#
Packit Service c5cf8c
# Handling of command-line options:
Packit Service c5cf8c
#   This is a little tricky because some options may contain blanks.
Packit Service c5cf8c
#
Packit Service c5cf8c
# Special issues with shared libraries - todo
Packit Service c5cf8c
#
Packit Service c5cf8c
# --------------------------------------------------------------------------
Packit Service c5cf8c
# Set the default values of all variables.
Packit Service c5cf8c
#
Packit Service c5cf8c
# Directory locations: Fixed for any MPI implementation.
Packit Service c5cf8c
# Set from the directory arguments to configure (e.g., --prefix=/usr/local)
Packit Service c5cf8c
prefix=__PREFIX_TO_BE_FILLED_AT_INSTALL_TIME__
Packit Service c5cf8c
exec_prefix=__EXEC_PREFIX_TO_BE_FILLED_AT_INSTALL_TIME__
Packit Service c5cf8c
sysconfdir=__SYSCONFDIR_TO_BE_FILLED_AT_INSTALL_TIME__
Packit Service c5cf8c
includedir=__INCLUDEDIR_TO_BE_FILLED_AT_INSTALL_TIME__
Packit Service c5cf8c
libdir=__LIBDIR_TO_BE_FILLED_AT_INSTALL_TIME__
Packit Service c5cf8c
Packit Service c5cf8c
# Default settings for compiler, flags, and libraries
Packit Service c5cf8c
# Determined by a combination of environment variables and tests within
Packit Service c5cf8c
# configure (e.g., determining whehter -lsocket is needee)
Packit Service c5cf8c
F77="@F77@"
Packit Service c5cf8c
F77CPP="@F77CPP@"
Packit Service c5cf8c
MPICH_VERSION="@MPICH_VERSION@"
Packit Service c5cf8c
Packit Service c5cf8c
enable_wrapper_rpath="@enable_wrapper_rpath@"
Packit Service c5cf8c
@f77_shlib_conf@
Packit Service c5cf8c
Packit Service c5cf8c
# Internal variables
Packit Service c5cf8c
# Show is set to echo to cause the compilation command to be echoed instead 
Packit Service c5cf8c
# of executed.
Packit Service c5cf8c
Show=
Packit Service c5cf8c
#
Packit Service c5cf8c
# End of initialization of variables
Packit Service c5cf8c
#---------------------------------------------------------------------
Packit Service c5cf8c
# Environment Variables.
Packit Service c5cf8c
# The environment variables MPICH_F77 may be used to override the 
Packit Service c5cf8c
# default choices.
Packit Service c5cf8c
# In addition, if there is a file $sysconfdir/mpif77-$F77name.conf, 
Packit Service c5cf8c
# where F77name is the name of the compiler with all spaces replaced by hyphens
Packit Service c5cf8c
# (e.g., "f77 -64" becomes "f77--64", that file is sources, allowing other
Packit Service c5cf8c
# changes to the compilation environment.  See the variables used by the 
Packit Service c5cf8c
# script (defined above)
Packit Service c5cf8c
# Added MPICH_F77_OLD, MPICH_F77 can be used to prefix F77
Packit Service c5cf8c
# with external utility, e.g. setenv MPICH_F77 'eval linkcache $MPICH_F77_OLD'
Packit Service c5cf8c
if [ -n "$MPICH_F77" ] ; then
Packit Service c5cf8c
    MPICH_F77_OLD="$F77"
Packit Service c5cf8c
    F77="$MPICH_F77"
Packit Service c5cf8c
    F77name=`echo $F77 | sed 's/ /-/g'`
Packit Service c5cf8c
    if [ -s $sysconfdir/mpif77-$F77name.conf ] ; then
Packit Service c5cf8c
        . $sysconfdir/mpif77-$F77name.conf
Packit Service c5cf8c
    fi
Packit Service c5cf8c
fi
Packit Service c5cf8c
# Allow a profiling option to be selected through an environment variable
Packit Service c5cf8c
if [ -n "$MPIF77_PROFILE" ] ; then
Packit Service c5cf8c
    profConf=$MPIF77_PROFILE
Packit Service c5cf8c
fi
Packit Service c5cf8c
#
Packit Service c5cf8c
# ------------------------------------------------------------------------
Packit Service c5cf8c
# Argument processing.
Packit Service c5cf8c
# This is somewhat awkward because of the handling of arguments within
Packit Service c5cf8c
# the shell.  We want to handle arguments that include spaces without 
Packit Service c5cf8c
# loosing the spacing (an alternative would be to use a more powerful
Packit Service c5cf8c
# scripting language that would allow us to retain the array of values, 
Packit Service c5cf8c
# which the basic (rather than enhanced) Bourne shell does not.  
Packit Service c5cf8c
#
Packit Service c5cf8c
# Look through the arguments for arguments that indicate compile only.
Packit Service c5cf8c
# If these are *not* found, add the library options
Packit Service c5cf8c
Packit Service c5cf8c
linking=yes
Packit Service c5cf8c
allargs=("$@")
Packit Service c5cf8c
argno=0
Packit Service c5cf8c
cppflags=()
Packit Service c5cf8c
interlib_deps=yes
Packit Service c5cf8c
static_mpi=no
Packit Service c5cf8c
for arg in "$@" ; do
Packit Service c5cf8c
    # Set addarg to no if this arg should be ignored by the C compiler
Packit Service c5cf8c
    addarg=yes
Packit Service c5cf8c
    case "$arg" in 
Packit Service c5cf8c
 	# ----------------------------------------------------------------
Packit Service c5cf8c
	# Compiler options that affect whether we are linking or no
Packit Service c5cf8c
    -c|-S|-E|-M|-MM)
Packit Service c5cf8c
    # The compiler links by default
Packit Service c5cf8c
    linking=no
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
	# ----------------------------------------------------------------
Packit Service c5cf8c
	# Options that control how we use mpif77 (e.g., -show, 
Packit Service c5cf8c
	# -f77=* -config=*
Packit Service c5cf8c
    -static)
Packit Service c5cf8c
    interlib_deps=no
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    -static-mpi)
Packit Service c5cf8c
    interlib_deps=no
Packit Service c5cf8c
    static_mpi=yes
Packit Service c5cf8c
    addarg=no
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    -echo)
Packit Service c5cf8c
    addarg=no
Packit Service c5cf8c
    set -x
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
Packit Service c5cf8c
    -f77=*)
Packit Service c5cf8c
    F77=`echo A$arg | sed -e 's/A-f77=//g'`
Packit Service c5cf8c
    addarg=no
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    -fc=*)
Packit Service c5cf8c
    F77=`echo A$arg | sed -e 's/A-fc=//g'`
Packit Service c5cf8c
    addarg=no
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
Packit Service c5cf8c
    -show)
Packit Service c5cf8c
    addarg=no
Packit Service c5cf8c
    Show=echo
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    -config=*)
Packit Service c5cf8c
    addarg=no
Packit Service c5cf8c
    F77name=`echo A$arg | sed -e 's/A-config=//g'`
Packit Service c5cf8c
    if [ -s "$sysconfdir/mpif77-$F77name.conf" ] ; then
Packit Service c5cf8c
        . "$sysconfdir/mpif77-$F77name.conf"
Packit Service c5cf8c
    else
Packit Service c5cf8c
	echo "Configuration file mpif77-$F77name.conf not found"
Packit Service c5cf8c
    fi
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    -compile-info|-compile_info)
Packit Service c5cf8c
    # -compile_info included for backward compatibility
Packit Service c5cf8c
    Show=echo
Packit Service c5cf8c
    addarg=no
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    -link-info|-link_info)
Packit Service c5cf8c
    # -link_info included for backward compatibility
Packit Service c5cf8c
    Show=echo
Packit Service c5cf8c
    addarg=no
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    -v)
Packit Service c5cf8c
    # Pass this argument to the compiler as well.
Packit Service c5cf8c
    echo "mpif77 for MPICH version $MPICH_VERSION"
Packit Service c5cf8c
    # if there is only 1 argument, it must be -v.
Packit Service c5cf8c
    if [ "$#" -eq "1" ] ; then
Packit Service c5cf8c
        linking=no
Packit Service c5cf8c
    fi
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    -profile=*)
Packit Service c5cf8c
    # Pass the name of a profiling configuration.  As
Packit Service c5cf8c
    # a special case, lib<name>.so or lib<name>.la may be used
Packit Service c5cf8c
    # if the library is in $libdir
Packit Service c5cf8c
    profConf=`echo A$arg | sed -e 's/A-profile=//g'`
Packit Service c5cf8c
    addarg=no
Packit Service c5cf8c
    # Loading the profConf file is handled below
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    -nativelinking)
Packit Service c5cf8c
    # Internal option to use native compiler for linking without MPI libraries
Packit Service c5cf8c
    nativelinking=yes
Packit Service c5cf8c
    addarg=no
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    -help)
Packit Service c5cf8c
    NC=`echo "$F77" | sed 's%\/% %g' | awk '{print $NF}' -`
Packit Service c5cf8c
    if [ -f "$sysconfdir/mpixxx_opts.conf" ] ; then
Packit Service c5cf8c
        . $sysconfdir/mpixxx_opts.conf
Packit Service c5cf8c
        echo "    -f77=xxx      - Reset the native compiler to xxx."
Packit Service c5cf8c
        echo "    -fc=xxx       - Reset the native compiler to xxx."
Packit Service c5cf8c
    else
Packit Service c5cf8c
        if [ -f "./mpixxx_opts.conf" ] ; then
Packit Service c5cf8c
            . ./mpixxx_opts.conf
Packit Service c5cf8c
            echo "    -f77=xxx      - Reset the native compiler to xxx."
Packit Service c5cf8c
            echo "    -fc=xxx       - Reset the native compiler to xxx."
Packit Service c5cf8c
        fi
Packit Service c5cf8c
    fi
Packit Service c5cf8c
    exit 0
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    # The following are special args used to handle .F files when the
Packit Service c5cf8c
    # Fortran compiler itself does not handle these options
Packit Service c5cf8c
    -I*)
Packit Service c5cf8c
    cppflags[${#cppflags}]="$arg"
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    -D*)
Packit Service c5cf8c
    cppflags[${#cppflags}]="$arg"
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    *.F|*.F90|*.fpp|*.FPP)
Packit Service c5cf8c
# If F77CPP is not empty, then we need to do the following:
Packit Service c5cf8c
#    If any input files have the .F or .F90 extension, then    
Packit Service c5cf8c
#        If F77CPP = false, then
Packit Service c5cf8c
#            generate an error message and exit
Packit Service c5cf8c
#        Use F77CPP to convert the file from .F to .f, using 
Packit Service c5cf8c
#            $TMPDIR/f$$-$count.f as the output file name
Packit Service c5cf8c
#            Replace the input file with this name in the args
Packit Service c5cf8c
# This is needed only for very broken systems
Packit Service c5cf8c
#     
Packit Service c5cf8c
    if [ -n "$F77CPP" ] ; then
Packit Service c5cf8c
        if [ "$F77CPP" = "false" ] ; then
Packit Service c5cf8c
            echo "This Fortran compiler does not accept .F or .F90 files"
Packit Service c5cf8c
	    exit 1
Packit Service c5cf8c
        fi
Packit Service c5cf8c
        addarg=no
Packit Service c5cf8c
	# Remove and directory names and extension
Packit Service c5cf8c
	$ext=`expr "$arg" : '.*\(\..*\)'`
Packit Service c5cf8c
        bfile=`basename $arg $ext`
Packit Service c5cf8c
	# 
Packit Service c5cf8c
	TMPDIR=${TMPDIR:-/tmp}
Packit Service c5cf8c
        tmpfile=$TMPDIR/f$$-$bfile.f
Packit Service c5cf8c
        if $F77CPP "${cppflags[@]}" $arg > $tmpfile ; then
Packit Service c5cf8c
            # Add this file to the commandline list
Packit Service c5cf8c
	    count=`expr $count + 1`
Packit Service c5cf8c
	    allargs[${#allargs}]="$tmpfile"
Packit Service c5cf8c
	    rmfiles="$rmfiles $tmpfile"
Packit Service c5cf8c
        else
Packit Service c5cf8c
	    echo "Aborting compilation because of failure in preprocessing step"
Packit Service c5cf8c
	    echo "for file $arg ."
Packit Service c5cf8c
	    exit 1
Packit Service c5cf8c
        fi
Packit Service c5cf8c
    fi
Packit Service c5cf8c
    # Otherwise, just accept the argument
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    # - end of special handling for .F files
Packit Service c5cf8c
    
Packit Service c5cf8c
    esac
Packit Service c5cf8c
    if [ $addarg = no ] ; then
Packit Service c5cf8c
        unset allargs[$argno]
Packit Service c5cf8c
    fi
Packit Service c5cf8c
    # Some versions of bash do not accept ((argno++))
Packit Service c5cf8c
    argno=`expr $argno + 1`
Packit Service c5cf8c
done
Packit Service c5cf8c
Packit Service c5cf8c
if [ $# -eq 0 ] ; then
Packit Service c5cf8c
    echo "Error: Command line argument is needed!"
Packit Service c5cf8c
    "$0" -help
Packit Service c5cf8c
    exit 1
Packit Service c5cf8c
fi
Packit Service c5cf8c
Packit Service c5cf8c
# -----------------------------------------------------------------------
Packit Service c5cf8c
# Derived variables.  These are assembled from variables set from the
Packit Service c5cf8c
# default, environment, configuration file (if any) and command-line
Packit Service c5cf8c
# options (if any)
Packit Service c5cf8c
f77libs=
Packit Service c5cf8c
if [ "@MPIFCLIBNAME@" != "@MPILIBNAME@" ] ; then
Packit Service c5cf8c
    f77libs="-l@MPIFCLIBNAME@"
Packit Service c5cf8c
fi
Packit Service c5cf8c
Packit Service c5cf8c
PROFILE_FOO=
Packit Service c5cf8c
# Handle the case of a profile switch
Packit Service c5cf8c
if [ -n "$profConf" ] ; then
Packit Service c5cf8c
    profConffile=
Packit Service c5cf8c
    if [ -s "$libdir/lib$profConf.a" -o -s "$libdir/lib$profConf.so" ] ; then
Packit Service c5cf8c
	PROFILE_FOO="-l$profConf"
Packit Service c5cf8c
    elif [ -s "$sysconfdir/$profConf.conf" ] ; then
Packit Service c5cf8c
	profConffile="$sysconfdir/$profConf.conf"
Packit Service c5cf8c
    elif [ -s "$profConf.conf" ] ; then
Packit Service c5cf8c
        profConffile="$profConf.conf"
Packit Service c5cf8c
    else
Packit Service c5cf8c
        echo "Profiling configuration file $profConf.conf not found in $sysconfdir"
Packit Service c5cf8c
    fi
Packit Service c5cf8c
    if [ -n "$profConffile" -a -s "$profConffile" ] ; then
Packit Service c5cf8c
	. $profConffile
Packit Service c5cf8c
    fi
Packit Service c5cf8c
fi
Packit Service c5cf8c
Packit Service 3f36f5
final_fflags="@MPICH_MPIF77_FFLAGS@ "
Packit Service 3f36f5
final_ldflags="@MPICH_MPIF77_LDFLAGS@ "
Packit Service c5cf8c
final_libs="@MPICH_MPIF77_LIBS@"
Packit Service c5cf8c
if test "@INTERLIB_DEPS@" = "no" -o "${interlib_deps}" = "no" ; then
Packit Service c5cf8c
    final_ldflags="${final_ldflags} @LDFLAGS@"
Packit Service 3f36f5
    final_libs="${final_libs} @LIBS@ "
Packit Service c5cf8c
fi
Packit Service c5cf8c
Packit Service c5cf8c
# A temporary statement to invoke the compiler
Packit Service c5cf8c
# Place the -L before any args incase there are any mpi libraries in there.
Packit Service c5cf8c
# Eventually, we'll want to move this after any non-MPI implementation 
Packit Service c5cf8c
# libraries
Packit Service c5cf8c
#
Packit Service c5cf8c
if [ "$linking" = yes ] ; then
Packit Service c5cf8c
    # Attempt to encode rpath info into the executable if the user has not
Packit Service c5cf8c
    # disabled rpath usage and some flavor of rpath makes sense on this
Packit Service c5cf8c
    # platform.
Packit Service c5cf8c
    # TODO configure and config.rpath are computing more sophisticated rpath
Packit Service c5cf8c
    # schemes than this simple one.  Consider updating this logic accordingly.
Packit Service c5cf8c
    if test "X$enable_wrapper_rpath" = "Xyes" ; then
Packit Service c5cf8c
        eval rpath_flags=\"${hardcode_libdir_flag_spec}\"
Packit Service c5cf8c
    else
Packit Service c5cf8c
	rpath_flags=""
Packit Service c5cf8c
    fi
Packit Service c5cf8c
Packit Service c5cf8c
    if [ "$nativelinking" = yes ] ; then
Packit Service c5cf8c
        $Show $F77 $PROFILE_INCPATHS ${final_fflags} ${final_ldflags} "${allargs[@]}" -I$includedir
Packit Service c5cf8c
        rc=$?
Packit Service c5cf8c
    else
Packit Service c5cf8c
        if [ "$static_mpi" = no ] ; then
Packit Service c5cf8c
          $Show $F77 $PROFILE_INCPATHS ${final_fflags} ${final_ldflags} "${allargs[@]}" -I$includedir -L$libdir $f77libs $PROFILE_PRELIB $PROFILE_FOO $rpath_flags -l@MPILIBNAME@ @LPMPILIBNAME@ $PROFILE_POSTLIB ${final_libs} @F77_OTHER_LIBS@
Packit Service c5cf8c
        else
Packit Service c5cf8c
          fabric_dep=""
Packit Service c5cf8c
          if [ "@ofi_embedded@" = yes ] ; then
Packit Service c5cf8c
              fabric_dep=`pkg-config --static --libs $libdir/pkgconfig/libfabric.pc`
Packit Service c5cf8c
              fabric_dep=`echo $fabric_dep | sed 's/-lfabric//'`
Packit Service c5cf8c
          elif [ -f @with_libfabric@/lib/pkgconfig/libfabric.pc ] ; then
Packit Service c5cf8c
              fabric_dep=`pkg-config --static --libs @with_libfabric@/lib/pkgconfig/libfabric.pc`
Packit Service c5cf8c
          else
Packit Service c5cf8c
              fabric_dep=`pkg-config --static --libs libfabric`
Packit Service c5cf8c
          fi
Packit Service c5cf8c
          $Show $F77 $PROFILE_INCPATHS ${final_fflags} ${final_ldflags} "${allargs[@]}" -I$includedir -L$libdir $f77libs $PROFILE_PRELIB $PROFILE_FOO $rpath_flags $libdir/libmpi.a @LPMPILIBNAME@ $PROFILE_POSTLIB ${final_libs} @F77_OTHER_LIBS@ ${fabric_dep}
Packit Service c5cf8c
        fi
Packit Service c5cf8c
        rc=$?
Packit Service c5cf8c
    fi
Packit Service c5cf8c
else
Packit Service c5cf8c
    $Show $F77 $PROFILE_INCPATHS ${final_fflags} "${allargs[@]}" -I$includedir
Packit Service c5cf8c
    rc=$?
Packit Service c5cf8c
fi
Packit Service c5cf8c
if [ -n "$rmfiles" ] ; then
Packit Service c5cf8c
    for file in $rmfiles ; do
Packit Service c5cf8c
        objfile=`basename $file .f`
Packit Service c5cf8c
	if [ -s "${objfile}.o" ] ; then
Packit Service c5cf8c
	    # Rename 
Packit Service c5cf8c
	    destfile=`echo $objfile | sed -e "s/.*$$-//"`
Packit Service c5cf8c
	    mv -f ${objfile}.o ${destfile}.o
Packit Service c5cf8c
	fi
Packit Service c5cf8c
        rm -f $file
Packit Service c5cf8c
    done
Packit Service c5cf8c
    rm -f $rmfiles
Packit Service c5cf8c
fi
Packit Service c5cf8c
exit $rc