| 1 | #! @BASH_SHELL@ |
|---|
| 2 | # |
|---|
| 3 | # (C) 2006 by Argonne National Laboratory. |
|---|
| 4 | # See COPYRIGHT in top-level directory. |
|---|
| 5 | # |
|---|
| 6 | # mpicxx |
|---|
| 7 | # Simple script to compile and/or link MPI programs. |
|---|
| 8 | # This script knows the default flags and libraries, and can handle |
|---|
| 9 | # alternative C++ compilers and the associated flags and libraries. |
|---|
| 10 | # The important terms are: |
|---|
| 11 | # includedir, libdir - Directories containing an *installed* mpich2 |
|---|
| 12 | # prefix, execprefix - Often used to define includedir and libdir |
|---|
| 13 | # CXX - C compiler |
|---|
| 14 | # WRAPPER_CXXFLAGS - Any special flags needed to compile |
|---|
| 15 | # WRAPPER_LDFLAGS - Any special flags needed to link |
|---|
| 16 | # MPILIBNAME - Name of the MPI library |
|---|
| 17 | # MPICXXLIBNAME - Name of the C++ binding part of the MPI library |
|---|
| 18 | # MPI_OTHERLIBS - Other libraries needed in order to link |
|---|
| 19 | # |
|---|
| 20 | # We assume that (a) the C++ compiler can both compile and link programs |
|---|
| 21 | # |
|---|
| 22 | # Handling of command-line options: |
|---|
| 23 | # This is a little tricky because some options may contain blanks. |
|---|
| 24 | # |
|---|
| 25 | # Special issues with shared libraries - todo |
|---|
| 26 | # |
|---|
| 27 | # -------------------------------------------------------------------------- |
|---|
| 28 | # Set the default values of all variables. |
|---|
| 29 | # |
|---|
| 30 | # Directory locations: Fixed for any MPI implementation |
|---|
| 31 | prefix=@prefix@ |
|---|
| 32 | exec_prefix=@exec_prefix@ |
|---|
| 33 | sysconfdir=@sysconfdir@ |
|---|
| 34 | includedir=@includedir@ |
|---|
| 35 | libdir=@libdir@ |
|---|
| 36 | opalibdir=@libdir@ |
|---|
| 37 | # |
|---|
| 38 | # Default settings for compiler, flags, and libraries |
|---|
| 39 | CXX="@CXX@" |
|---|
| 40 | CXX_LINKPATH_SHL="@CXX_LINKPATH_SHL@" |
|---|
| 41 | WRAPPER_CXXFLAGS="@WRAPPER_CXXFLAGS@" |
|---|
| 42 | WRAPPER_LDFLAGS="@WRAPPER_LDFLAGS@" |
|---|
| 43 | MPILIBNAME="@MPILIBNAME@" |
|---|
| 44 | PMPILIBNAME="@PMPILIBNAME@" |
|---|
| 45 | MPICXXLIBNAME="@MPICXXLIBNAME@" |
|---|
| 46 | MPI_OTHERLIBS="@LIBS@" |
|---|
| 47 | NEEDSPLIB="@NEEDSPLIB@" |
|---|
| 48 | # MPIVERSION is the version of the MPICH2 library that mpicxx is intended for |
|---|
| 49 | MPIVERSION="@VERSION@" |
|---|
| 50 | # |
|---|
| 51 | # Internal variables |
|---|
| 52 | # Show is set to echo to cause the compilation command to be echoed instead |
|---|
| 53 | # of executed. |
|---|
| 54 | Show= |
|---|
| 55 | # |
|---|
| 56 | # End of initialization of variables |
|---|
| 57 | #--------------------------------------------------------------------- |
|---|
| 58 | # Environment Variables. |
|---|
| 59 | # The environment variables MPICH_CXX may be used to override the |
|---|
| 60 | # default choices. |
|---|
| 61 | # In addition, if there is a file $sysconfdir/mpicxx-$CXXname.conf, |
|---|
| 62 | # where CXXname is the name of the compiler with all spaces replaced by hyphens |
|---|
| 63 | # (e.g., "CC -64" becomes "CC--64", that file is sources, allowing other |
|---|
| 64 | # changes to the compilation environment. See the variables used by the |
|---|
| 65 | # script (defined above) |
|---|
| 66 | if [ -n "$MPICH_CXX" ] ; then |
|---|
| 67 | CXX="$MPICH_CXX" |
|---|
| 68 | CXXname=`echo $CXX | sed 's/ /-/g'` |
|---|
| 69 | if [ -s $sysconfdir/mpicxx-$CXXname.conf ] ; then |
|---|
| 70 | . $sysconfdir/mpicxx-$CXXname.conf |
|---|
| 71 | fi |
|---|
| 72 | fi |
|---|
| 73 | # Allow a profiling option to be selected through an environment variable |
|---|
| 74 | if [ -n "$MPICXX_PROFILE" ] ; then |
|---|
| 75 | profConf=$MPICXX_PROFILE |
|---|
| 76 | fi |
|---|
| 77 | # |
|---|
| 78 | # ------------------------------------------------------------------------ |
|---|
| 79 | # Argument processing. |
|---|
| 80 | # This is somewhat awkward because of the handling of arguments within |
|---|
| 81 | # the shell. We want to handle arguments that include spaces without |
|---|
| 82 | # loosing the spacing (an alternative would be to use a more powerful |
|---|
| 83 | # scripting language that would allow us to retain the array of values, |
|---|
| 84 | # which the basic (rather than enhanced) Bourne shell does not. |
|---|
| 85 | # |
|---|
| 86 | # Look through the arguments for arguments that indicate compile only. |
|---|
| 87 | # If these are *not* found, add the library options |
|---|
| 88 | |
|---|
| 89 | linking=yes |
|---|
| 90 | allargs=("$@") |
|---|
| 91 | argno=0 |
|---|
| 92 | for arg in "$@" ; do |
|---|
| 93 | # Set addarg to no if this arg should be ignored by the C compiler |
|---|
| 94 | addarg=yes |
|---|
| 95 | case "$arg" in |
|---|
| 96 | # ---------------------------------------------------------------- |
|---|
| 97 | # Compiler options that affect whether we are linking or no |
|---|
| 98 | -c|-S|-E|-M|-MM) |
|---|
| 99 | # The compiler links by default |
|---|
| 100 | linking=no |
|---|
| 101 | ;; |
|---|
| 102 | # ---------------------------------------------------------------- |
|---|
| 103 | # Options that control how we use mpicxx (e.g., -show, |
|---|
| 104 | # -cxx=* -config=* |
|---|
| 105 | -echo) |
|---|
| 106 | addarg=no |
|---|
| 107 | set -x |
|---|
| 108 | ;; |
|---|
| 109 | -cxx=*) |
|---|
| 110 | CXX=`echo A$arg | sed -e 's/A-cxx=//g'` |
|---|
| 111 | addarg=no |
|---|
| 112 | ;; |
|---|
| 113 | # Backwards compatibility for MPICH1 - scripts |
|---|
| 114 | -CC=*) |
|---|
| 115 | CXX=`echo A$arg | sed -e 's/A-CC=//g'` |
|---|
| 116 | addarg=no |
|---|
| 117 | ;; |
|---|
| 118 | -show) |
|---|
| 119 | addarg=no |
|---|
| 120 | Show=echo |
|---|
| 121 | ;; |
|---|
| 122 | -config=*) |
|---|
| 123 | addarg=no |
|---|
| 124 | CXXname=`echo A$arg | sed -e 's/A-config=//g'` |
|---|
| 125 | if [ -s "$sysconfdir/mpicxx-$CXXname.conf" ] ; then |
|---|
| 126 | . "$sysconfdir/mpicxx-$CXXname.conf" |
|---|
| 127 | else |
|---|
| 128 | echo "Configuration file mpicxx-$CXXname.conf not found" |
|---|
| 129 | fi |
|---|
| 130 | ;; |
|---|
| 131 | -compile-info|-compile_info) |
|---|
| 132 | # -compile_info included for backward compatibility |
|---|
| 133 | Show=echo |
|---|
| 134 | addarg=no |
|---|
| 135 | ;; |
|---|
| 136 | -link-info|-link_info) |
|---|
| 137 | # -link_info included for backward compatibility |
|---|
| 138 | Show=echo |
|---|
| 139 | addarg=no |
|---|
| 140 | ;; |
|---|
| 141 | -v) |
|---|
| 142 | # Pass this argument to the compiler as well. |
|---|
| 143 | echo "mpicxx for $MPIVERSION" |
|---|
| 144 | # if there is only 1 argument, it must be -v. |
|---|
| 145 | if [ "$#" -eq "1" ] ; then |
|---|
| 146 | linking=no |
|---|
| 147 | fi |
|---|
| 148 | ;; |
|---|
| 149 | -profile=*) |
|---|
| 150 | # Pass the name of a profiling configuration. As |
|---|
| 151 | # a special case, lib<name>.so or lib<name>.la may be used |
|---|
| 152 | # if the library is in $libdir |
|---|
| 153 | profConf=`echo A$arg | sed -e 's/A-profile=//g'` |
|---|
| 154 | addarg=no |
|---|
| 155 | # Loading the profConf file is handled below |
|---|
| 156 | ;; |
|---|
| 157 | -mpe=*) |
|---|
| 158 | # Pass the name of a profiling configuration; this is a special |
|---|
| 159 | # case for the MPE libs. See -profile |
|---|
| 160 | profConf=`echo A$arg | sed -e 's/A-mpe=//g'` |
|---|
| 161 | profConf="mpe_$profConf" |
|---|
| 162 | addarg=no |
|---|
| 163 | # Loading the profConf file is handled below |
|---|
| 164 | ;; |
|---|
| 165 | -help) |
|---|
| 166 | NC=`echo "$CXX" | sed 's%\/% %g' | awk '{print $NF}' -` |
|---|
| 167 | if [ -f "$sysconfdir/mpixxx_opts.conf" ] ; then |
|---|
| 168 | . $sysconfdir/mpixxx_opts.conf |
|---|
| 169 | echo " -cxx=xxx - Reset the native compiler to xxx." |
|---|
| 170 | else |
|---|
| 171 | if [ -f "./mpixxx_opts.conf" ] ; then |
|---|
| 172 | . ./mpixxx_opts.conf |
|---|
| 173 | echo " -cxx=xxx - Reset the native compiler to xxx." |
|---|
| 174 | fi |
|---|
| 175 | fi |
|---|
| 176 | exit 0 |
|---|
| 177 | ;; |
|---|
| 178 | *) |
|---|
| 179 | ;; |
|---|
| 180 | |
|---|
| 181 | esac |
|---|
| 182 | if [ $addarg = no ] ; then |
|---|
| 183 | unset allargs[$argno] |
|---|
| 184 | fi |
|---|
| 185 | # Some versions of bash do not accept ((argno++)) |
|---|
| 186 | argno=`expr $argno + 1` |
|---|
| 187 | done |
|---|
| 188 | |
|---|
| 189 | if [ $# -eq 0 ] ; then |
|---|
| 190 | echo "Error: Command line argument is needed!" |
|---|
| 191 | "$0" -help |
|---|
| 192 | exit 1 |
|---|
| 193 | fi |
|---|
| 194 | |
|---|
| 195 | # ----------------------------------------------------------------------- |
|---|
| 196 | # Derived variables. These are assembled from variables set from the |
|---|
| 197 | # default, environment, configuration file (if any) and command-line |
|---|
| 198 | # options (if any) |
|---|
| 199 | if [ "$NEEDSPLIB" = yes ] ; then |
|---|
| 200 | mpilibs="-l$PMPILIBNAME -l$MPILIBNAME -lopa" |
|---|
| 201 | else |
|---|
| 202 | mpilibs="-l$MPILIBNAME -lopa" |
|---|
| 203 | fi |
|---|
| 204 | cxxlibs= |
|---|
| 205 | if [ "$MPICXXLIBNAME" != "$MPILIBNAME" ] ; then |
|---|
| 206 | cxxlibs="-l$MPICXXLIBNAME" |
|---|
| 207 | fi |
|---|
| 208 | # |
|---|
| 209 | # Init with the ones needed by MPI |
|---|
| 210 | CXXFLAGS="$WRAPPER_CXXFLAGS" |
|---|
| 211 | LDFLAGS="$WRAPPER_LDFLAGS" |
|---|
| 212 | # |
|---|
| 213 | # |
|---|
| 214 | # Handle the case of a profile switch |
|---|
| 215 | if [ -n "$profConf" ] ; then |
|---|
| 216 | profConffile= |
|---|
| 217 | if [ -s "$libdir/lib$profConf.a" -o -s "$libdir/lib$profConf.so" ] ; then |
|---|
| 218 | mpilibs="-l$profConf $mpilibs" |
|---|
| 219 | elif [ -s "$sysconfdir/$profConf.conf" ] ; then |
|---|
| 220 | profConffile="$sysconfdir/$profConf.conf" |
|---|
| 221 | elif [ -s "$profConf.conf" ] ; then |
|---|
| 222 | profConffile="$profConf.conf" |
|---|
| 223 | else |
|---|
| 224 | echo "Profiling configuration file $profConf.conf not found in $sysconfdir" |
|---|
| 225 | fi |
|---|
| 226 | if [ -n "$profConffile" -a -s "$profConffile" ] ; then |
|---|
| 227 | . $profConffile |
|---|
| 228 | if [ -n "$PROFILE_INCPATHS" ] ; then |
|---|
| 229 | CXXFLAGS="$PROFILE_INCPATHS $CXXFLAGS" |
|---|
| 230 | fi |
|---|
| 231 | if [ -n "$PROFILE_PRELIB" ] ; then |
|---|
| 232 | mpilibs="$PROFILE_PRELIB $mpilibs" |
|---|
| 233 | fi |
|---|
| 234 | if [ -n "$PROFILE_POSTLIB" ] ; then |
|---|
| 235 | mpilibs="$mpilibs $PROFILE_POSTLIB" |
|---|
| 236 | fi |
|---|
| 237 | fi |
|---|
| 238 | fi |
|---|
| 239 | # A temporary statement to invoke the compiler |
|---|
| 240 | # Place the -L before any args incase there are any mpi libraries in there. |
|---|
| 241 | # Eventually, we'll want to move this after any non-MPI implementation |
|---|
| 242 | # libraries |
|---|
| 243 | if [ "$linking" = yes ] ; then |
|---|
| 244 | if [ -n "$CXX_LINKPATH_SHL" ] ; then |
|---|
| 245 | # Prepend the path for the shared libraries to the library list |
|---|
| 246 | shllibpath="$CXX_LINKPATH_SHL$libdir" |
|---|
| 247 | fi |
|---|
| 248 | $Show $CXX $CXXFLAGS $LDFLAGS "${allargs[@]}" -I$includedir -L$libdir -L$opalibdir $shllibpath $cxxlibs $mpilibs $MPI_OTHERLIBS |
|---|
| 249 | rc=$? |
|---|
| 250 | else |
|---|
| 251 | $Show $CXX $CXXFLAGS "${allargs[@]}" -I$includedir |
|---|
| 252 | rc=$? |
|---|
| 253 | fi |
|---|
| 254 | |
|---|
| 255 | exit $rc |
|---|