Blame src/env/mpicxx.bash.in

Packit 0848f5
#! @BASH_SHELL@
Packit 0848f5
# 
Packit 0848f5
# (C) 2006 by Argonne National Laboratory.
Packit 0848f5
#     See COPYRIGHT in top-level directory.
Packit 0848f5
#
Packit 0848f5
# mpicxx
Packit 0848f5
# Simple script to compile and/or link MPI programs.
Packit 0848f5
# This script knows the default flags and libraries, and can handle
Packit 0848f5
# alternative C++ compilers and the associated flags and libraries.
Packit 0848f5
# The important terms are:
Packit 0848f5
#    includedir, libdir - Directories containing an *installed* mpich
Packit 0848f5
#    prefix, execprefix - Often used to define includedir and libdir
Packit 0848f5
#    CXX                - C compiler
Packit 0848f5
#    WRAPPER_CXXFLAGS      - Any special flags needed to compile 
Packit 0848f5
#    WRAPPER_LDFLAGS       - Any special flags needed to link
Packit 0848f5
#    WRAPPER_LIBS          - Any special libraries needed in order to link
Packit 0848f5
#    
Packit 0848f5
# We assume that (a) the C++ compiler can both compile and link programs
Packit 0848f5
#
Packit 0848f5
# Handling of command-line options:
Packit 0848f5
#   This is a little tricky because some options may contain blanks.
Packit 0848f5
#
Packit 0848f5
# Special issues with shared libraries - todo
Packit 0848f5
#
Packit 0848f5
# --------------------------------------------------------------------------
Packit 0848f5
# Set the default values of all variables.
Packit 0848f5
#
Packit 0848f5
# Directory locations: Fixed for any MPI implementation
Packit 0848f5
prefix=__PREFIX_TO_BE_FILLED_AT_INSTALL_TIME__
Packit 0848f5
exec_prefix=__EXEC_PREFIX_TO_BE_FILLED_AT_INSTALL_TIME__
Packit 0848f5
sysconfdir=__SYSCONFDIR_TO_BE_FILLED_AT_INSTALL_TIME__
Packit 0848f5
includedir=__INCLUDEDIR_TO_BE_FILLED_AT_INSTALL_TIME__
Packit 0848f5
libdir=__LIBDIR_TO_BE_FILLED_AT_INSTALL_TIME__
Packit 0848f5
Packit 0848f5
# Default settings for compiler, flags, and libraries
Packit 0848f5
CXX="@CXX@"
Packit 0848f5
MPICH_VERSION="@MPICH_VERSION@"
Packit 0848f5
Packit 0848f5
enable_wrapper_rpath="@enable_wrapper_rpath@"
Packit 0848f5
@cxx_shlib_conf@
Packit 0848f5
Packit 0848f5
# Internal variables
Packit 0848f5
# Show is set to echo to cause the compilation command to be echoed instead 
Packit 0848f5
# of executed.
Packit 0848f5
Show=
Packit 0848f5
#
Packit 0848f5
# End of initialization of variables
Packit 0848f5
#---------------------------------------------------------------------
Packit 0848f5
# Environment Variables.
Packit 0848f5
# The environment variables MPICH_CXX may be used to override the 
Packit 0848f5
# default choices.
Packit 0848f5
# In addition, if there is a file $sysconfdir/mpicxx-$CXXname.conf, 
Packit 0848f5
# where CXXname is the name of the compiler with all spaces replaced by hyphens
Packit 0848f5
# (e.g., "CC -64" becomes "CC--64", that file is sources, allowing other
Packit 0848f5
# changes to the compilation environment.  See the variables used by the 
Packit 0848f5
# script (defined above)
Packit 0848f5
# Added MPICH_CXX_OLD, MPICH_CXX can be used to prefix CXX
Packit 0848f5
# with external utility, e.g. setenv MPICH_CXX 'eval linkcache $MPICH_CXX_OLD'
Packit 0848f5
if [ -n "$MPICH_CXX" ] ; then
Packit 0848f5
    MPICH_CXX_OLD="$CXX"
Packit 0848f5
    CXX="$MPICH_CXX"
Packit 0848f5
    CXXname=`echo $CXX | sed 's/ /-/g'`
Packit 0848f5
    if [ -s $sysconfdir/mpicxx-$CXXname.conf ] ; then
Packit 0848f5
        . $sysconfdir/mpicxx-$CXXname.conf
Packit 0848f5
    fi
Packit 0848f5
fi
Packit 0848f5
# Allow a profiling option to be selected through an environment variable
Packit 0848f5
if [ -n "$MPICXX_PROFILE" ] ; then
Packit 0848f5
    profConf=$MPICXX_PROFILE
Packit 0848f5
fi
Packit 0848f5
#
Packit 0848f5
# ------------------------------------------------------------------------
Packit 0848f5
# Argument processing.
Packit 0848f5
# This is somewhat awkward because of the handling of arguments within
Packit 0848f5
# the shell.  We want to handle arguments that include spaces without 
Packit 0848f5
# loosing the spacing (an alternative would be to use a more powerful
Packit 0848f5
# scripting language that would allow us to retain the array of values, 
Packit 0848f5
# which the basic (rather than enhanced) Bourne shell does not.  
Packit 0848f5
#
Packit 0848f5
# Look through the arguments for arguments that indicate compile only.
Packit 0848f5
# If these are *not* found, add the library options
Packit 0848f5
Packit 0848f5
linking=yes
Packit 0848f5
allargs=("$@")
Packit 0848f5
argno=0
Packit 0848f5
interlib_deps=yes
Packit 0848f5
for arg in "$@" ; do
Packit 0848f5
    # Set addarg to no if this arg should be ignored by the C compiler
Packit 0848f5
    addarg=yes
Packit 0848f5
    case "$arg" in 
Packit 0848f5
 	# ----------------------------------------------------------------
Packit 0848f5
	# Compiler options that affect whether we are linking or no
Packit 0848f5
    -c|-S|-E|-M|-MM)
Packit 0848f5
    # The compiler links by default
Packit 0848f5
    linking=no
Packit 0848f5
    ;;
Packit 0848f5
	# ----------------------------------------------------------------
Packit 0848f5
	# Options that control how we use mpicxx (e.g., -show, 
Packit 0848f5
	# -cxx=* -config=*
Packit 0848f5
    -static)
Packit 0848f5
    interlib_deps=no
Packit 0848f5
    ;;
Packit 0848f5
    -echo)
Packit 0848f5
    addarg=no
Packit 0848f5
    set -x
Packit 0848f5
    ;;
Packit 0848f5
    -cxx=*)
Packit 0848f5
    CXX=`echo A$arg | sed -e 's/A-cxx=//g'`
Packit 0848f5
    addarg=no
Packit 0848f5
    ;;
Packit 0848f5
    # Backwards compatibility for MPICH1 - scripts
Packit 0848f5
    -CC=*)
Packit 0848f5
    CXX=`echo A$arg | sed -e 's/A-CC=//g'`
Packit 0848f5
    addarg=no
Packit 0848f5
    ;;
Packit 0848f5
    -show)
Packit 0848f5
    addarg=no
Packit 0848f5
    Show=echo
Packit 0848f5
    ;;
Packit 0848f5
    -config=*)
Packit 0848f5
    addarg=no
Packit 0848f5
    CXXname=`echo A$arg | sed -e 's/A-config=//g'`
Packit 0848f5
    if [ -s "$sysconfdir/mpicxx-$CXXname.conf" ] ; then
Packit 0848f5
        . "$sysconfdir/mpicxx-$CXXname.conf"
Packit 0848f5
    else
Packit 0848f5
	echo "Configuration file mpicxx-$CXXname.conf not found"
Packit 0848f5
    fi
Packit 0848f5
    ;;
Packit 0848f5
    -compile-info|-compile_info)
Packit 0848f5
    # -compile_info included for backward compatibility
Packit 0848f5
    Show=echo
Packit 0848f5
    addarg=no
Packit 0848f5
    ;;
Packit 0848f5
    -link-info|-link_info)
Packit 0848f5
    # -link_info included for backward compatibility
Packit 0848f5
    Show=echo
Packit 0848f5
    addarg=no
Packit 0848f5
    ;;
Packit 0848f5
    -v)
Packit 0848f5
    # Pass this argument to the compiler as well.
Packit 0848f5
    echo "mpicxx for MPICH version $MPICH_VERSION"
Packit 0848f5
    # if there is only 1 argument, it must be -v.
Packit 0848f5
    if [ "$#" -eq "1" ] ; then
Packit 0848f5
        linking=no
Packit 0848f5
    fi
Packit 0848f5
    ;;
Packit 0848f5
    -profile=*)
Packit 0848f5
    # Pass the name of a profiling configuration.  As
Packit 0848f5
    # a special case, lib<name>.so or lib<name>.la may be used
Packit 0848f5
    # if the library is in $libdir
Packit 0848f5
    profConf=`echo A$arg | sed -e 's/A-profile=//g'`
Packit 0848f5
    addarg=no
Packit 0848f5
    # Loading the profConf file is handled below
Packit 0848f5
    ;;
Packit 0848f5
    -nativelinking)
Packit 0848f5
    # Internal option to use native compiler for linking without MPI libraries
Packit 0848f5
    nativelinking=yes
Packit 0848f5
    addarg=no
Packit 0848f5
    ;;
Packit 0848f5
    -help)
Packit 0848f5
    NC=`echo "$CXX" | sed 's%\/% %g' | awk '{print $NF}' -`
Packit 0848f5
    if [ -f "$sysconfdir/mpixxx_opts.conf" ] ; then
Packit 0848f5
        . $sysconfdir/mpixxx_opts.conf
Packit 0848f5
        echo "    -cxx=xxx      - Reset the native compiler to xxx."
Packit 0848f5
    else
Packit 0848f5
        if [ -f "./mpixxx_opts.conf" ] ; then
Packit 0848f5
            . ./mpixxx_opts.conf
Packit 0848f5
            echo "    -cxx=xxx      - Reset the native compiler to xxx."
Packit 0848f5
        fi
Packit 0848f5
    fi
Packit 0848f5
    exit 0
Packit 0848f5
    ;;
Packit 0848f5
    *)
Packit 0848f5
    ;;
Packit 0848f5
Packit 0848f5
    esac
Packit 0848f5
    if [ $addarg = no ] ; then
Packit 0848f5
	unset allargs[$argno]
Packit 0848f5
    fi
Packit 0848f5
    # Some versions of bash do not accept ((argno++))
Packit 0848f5
    argno=`expr $argno + 1`
Packit 0848f5
done
Packit 0848f5
Packit 0848f5
if [ $# -eq 0 ] ; then
Packit 0848f5
    echo "Error: Command line argument is needed!"
Packit 0848f5
    "$0" -help
Packit 0848f5
    exit 1
Packit 0848f5
fi
Packit 0848f5
Packit 0848f5
# -----------------------------------------------------------------------
Packit 0848f5
# Derived variables.  These are assembled from variables set from the
Packit 0848f5
# default, environment, configuration file (if any) and command-line
Packit 0848f5
# options (if any)
Packit 0848f5
cxxlibs=
Packit 0848f5
if [ "@MPICXXLIBNAME@" != "@MPILIBNAME@" ] ; then
Packit 0848f5
    cxxlibs="-l@MPICXXLIBNAME@"
Packit 0848f5
fi
Packit 0848f5
Packit 0848f5
PROFILE_FOO=
Packit 0848f5
# Handle the case of a profile switch
Packit 0848f5
if [ -n "$profConf" ] ; then
Packit 0848f5
    profConffile=
Packit 0848f5
    if [ -s "$libdir/lib$profConf.a" -o -s "$libdir/lib$profConf.so" ] ; then
Packit 0848f5
	PROFILE_FOO="-l$profConf"
Packit 0848f5
    elif [ -s "$sysconfdir/$profConf.conf" ] ; then
Packit 0848f5
	profConffile="$sysconfdir/$profConf.conf"
Packit 0848f5
    elif [ -s "$profConf.conf" ] ; then
Packit 0848f5
        profConffile="$profConf.conf"
Packit 0848f5
    else
Packit 0848f5
        echo "Profiling configuration file $profConf.conf not found in $sysconfdir"
Packit 0848f5
    fi
Packit 0848f5
    if [ -n "$profConffile" -a -s "$profConffile" ] ; then
Packit 0848f5
	. $profConffile
Packit 0848f5
    fi
Packit 0848f5
fi
Packit 0848f5
Packit 0848f5
final_cxxflags="@MPICH_MPICXX_CXXFLAGS@ @WRAPPER_CXXFLAGS@"
Packit 0848f5
final_cppflags="@MPICH_MPICXX_CPPFLAGS@ @WRAPPER_CPPFLAGS@"
Packit 0848f5
final_ldflags="@MPICH_MPICXX_LDFLAGS@ @WRAPPER_LDFLAGS@"
Packit 0848f5
final_libs="@MPICH_MPICXX_LIBS@"
Packit 0848f5
if test "@INTERLIB_DEPS@" = "no" -o "${interlib_deps}" = "no" ; then
Packit 0848f5
    final_ldflags="${final_ldflags} @LDFLAGS@"
Packit 0848f5
    final_libs="${final_libs} @LIBS@ @WRAPPER_LIBS@"
Packit 0848f5
fi
Packit 0848f5
Packit 0848f5
# A temporary statement to invoke the compiler
Packit 0848f5
# Place the -L before any args incase there are any mpi libraries in there.
Packit 0848f5
# Eventually, we'll want to move this after any non-MPI implementation 
Packit 0848f5
# libraries
Packit 0848f5
if [ "$linking" = yes ] ; then
Packit 0848f5
    # Attempt to encode rpath info into the executable if the user has not
Packit 0848f5
    # disabled rpath usage and some flavor of rpath makes sense on this
Packit 0848f5
    # platform.
Packit 0848f5
    # TODO configure and config.rpath are computing more sophisticated rpath
Packit 0848f5
    # schemes than this simple one.  Consider updating this logic accordingly.
Packit 0848f5
    if test "X$enable_wrapper_rpath" = "Xyes" ; then
Packit 0848f5
        eval rpath_flags=\"${hardcode_libdir_flag_spec}\"
Packit 0848f5
    else
Packit 0848f5
	rpath_flags=""
Packit 0848f5
    fi
Packit 0848f5
Packit 0848f5
    if [ "$nativelinking" = yes ] ; then
Packit 0848f5
        $Show $CXX ${final_cppflags} $PROFILE_INCPATHS ${final_cxxflags} ${final_ldflags} "${allargs[@]}" -I$includedir
Packit 0848f5
        rc=$?
Packit 0848f5
    else
Packit 0848f5
        $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 0848f5
        rc=$?
Packit 0848f5
    fi
Packit 0848f5
else
Packit 0848f5
    $Show $CXX ${final_cppflags} $PROFILE_INCPATHS ${final_cxxflags} "${allargs[@]}" -I$includedir
Packit 0848f5
    rc=$?
Packit 0848f5
fi
Packit 0848f5
Packit 0848f5
exit $rc
Packit 0848f5