Blame src/env/mpicxx.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
# mpicxx
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
#    CXX                - C compiler
Packit Service c5cf8c
#    WRAPPER_CXXFLAGS      - 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
#    
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
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
CXX="@CXX@"
Packit Service c5cf8c
MPICH_VERSION="@MPICH_VERSION@"
Packit Service c5cf8c
Packit Service c5cf8c
enable_wrapper_rpath="@enable_wrapper_rpath@"
Packit Service c5cf8c
@cxx_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_CXX may be used to override the 
Packit Service c5cf8c
# default choices.
Packit Service c5cf8c
# In addition, if there is a file $sysconfdir/mpicxx-$CXXname.conf, 
Packit Service c5cf8c
# where CXXname is the name of the compiler with all spaces replaced by hyphens
Packit Service c5cf8c
# (e.g., "CC -64" becomes "CC--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_CXX_OLD, MPICH_CXX can be used to prefix CXX
Packit Service c5cf8c
# with external utility, e.g. setenv MPICH_CXX 'eval linkcache $MPICH_CXX_OLD'
Packit Service c5cf8c
if [ -n "$MPICH_CXX" ] ; then
Packit Service c5cf8c
    MPICH_CXX_OLD="$CXX"
Packit Service c5cf8c
    CXX="$MPICH_CXX"
Packit Service c5cf8c
    CXXname=`echo $CXX | sed 's/ /-/g'`
Packit Service c5cf8c
    if [ -s $sysconfdir/mpicxx-$CXXname.conf ] ; then
Packit Service c5cf8c
        . $sysconfdir/mpicxx-$CXXname.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 "$MPICXX_PROFILE" ] ; then
Packit Service c5cf8c
    profConf=$MPICXX_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
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 mpicxx (e.g., -show, 
Packit Service c5cf8c
	# -cxx=* -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
    -cxx=*)
Packit Service c5cf8c
    CXX=`echo A$arg | sed -e 's/A-cxx=//g'`
Packit Service c5cf8c
    addarg=no
Packit Service c5cf8c
    ;;
Packit Service c5cf8c
    # Backwards compatibility for MPICH1 - scripts
Packit Service c5cf8c
    -CC=*)
Packit Service c5cf8c
    CXX=`echo A$arg | sed -e 's/A-CC=//g'`
Packit Service c5cf8c
    addarg=no
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
    CXXname=`echo A$arg | sed -e 's/A-config=//g'`
Packit Service c5cf8c
    if [ -s "$sysconfdir/mpicxx-$CXXname.conf" ] ; then
Packit Service c5cf8c
        . "$sysconfdir/mpicxx-$CXXname.conf"
Packit Service c5cf8c
    else
Packit Service c5cf8c
	echo "Configuration file mpicxx-$CXXname.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 "mpicxx 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 "$CXX" | 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 "    -cxx=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 "    -cxx=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
    *)
Packit Service c5cf8c
    ;;
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
cxxlibs=
Packit Service c5cf8c
if [ "@MPICXXLIBNAME@" != "@MPILIBNAME@" ] ; then
Packit Service c5cf8c
    cxxlibs="-l@MPICXXLIBNAME@"
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_cxxflags="@MPICH_MPICXX_CXXFLAGS@ "
Packit Service 3f36f5
final_cppflags="@MPICH_MPICXX_CPPFLAGS@ "
Packit Service 3f36f5
final_ldflags="@MPICH_MPICXX_LDFLAGS@ "
Packit Service c5cf8c
final_libs="@MPICH_MPICXX_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
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 $CXX ${final_cppflags} $PROFILE_INCPATHS ${final_cxxflags} ${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 $CXX ${final_cppflags} $PROFILE_INCPATHS ${final_cxxflags} ${final_ldflags} "${allargs[@]}" -I$includedir -L$libdir $cxxlibs $PROFILE_PRELIB $PROFILE_FOO $rpath_flags -l@MPILIBNAME@ @LPMPILIBNAME@ $PROFILE_POSTLIB ${final_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 $CXX ${final_cppflags} $PROFILE_INCPATHS ${final_cxxflags} ${final_ldflags} "${allargs[@]}" -I$includedir -L$libdir $cxxlibs $PROFILE_PRELIB $PROFILE_FOO $rpath_flags $libdir/libmpi.a @LPMPILIBNAME@ $PROFILE_POSTLIB ${final_libs} ${fabric_dep}
Packit Service c5cf8c
      fi
Packit Service c5cf8c
        rc=$?
Packit Service c5cf8c
    fi
Packit Service c5cf8c
else
Packit Service c5cf8c
    $Show $CXX ${final_cppflags} $PROFILE_INCPATHS ${final_cxxflags} "${allargs[@]}" -I$includedir
Packit Service c5cf8c
    rc=$?
Packit Service c5cf8c
fi
Packit Service c5cf8c
Packit Service c5cf8c
exit $rc