| 1 | #! /bin/sh |
|---|
| 2 | # |
|---|
| 3 | # (C) 2006 by Argonne National Laboratory. |
|---|
| 4 | # See COPYRIGHT in top-level directory. |
|---|
| 5 | # |
|---|
| 6 | # mpicc |
|---|
| 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, opalibdir - Directories containing an *installed* mpich2 |
|---|
| 12 | # prefix, execprefix - Often used to define includedir and libdir |
|---|
| 13 | # CC - C compiler |
|---|
| 14 | # WRAPPER_CFLAGS - Any special flags needed to compile |
|---|
| 15 | # WRAPPER_LDFLAGS - Any special flags needed to link |
|---|
| 16 | # MPILIBNAME - Name of the MPI library |
|---|
| 17 | # MPI_OTHERLIBS - Other libraries needed in order to link |
|---|
| 18 | # |
|---|
| 19 | # We assume that (a) the C compiler can both compile and link programs |
|---|
| 20 | # |
|---|
| 21 | # Handling of command-line options: |
|---|
| 22 | # This is a little tricky because some options may contain blanks. |
|---|
| 23 | # |
|---|
| 24 | # Special issues with shared libraries - todo |
|---|
| 25 | # |
|---|
| 26 | # -------------------------------------------------------------------------- |
|---|
| 27 | # Set the default values of all variables. |
|---|
| 28 | # |
|---|
| 29 | # Directory locations: Fixed for any MPI implementation. |
|---|
| 30 | # Set from the directory arguments to configure (e.g., --prefix=/usr/local) |
|---|
| 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 | # Determined by a combination of environment variables and tests within |
|---|
| 40 | # configure (e.g., determining whehter -lsocket is needee) |
|---|
| 41 | CC="@CC@" |
|---|
| 42 | C_LINKPATH_SHL="@C_LINKPATH_SHL@" |
|---|
| 43 | WRAPPER_CFLAGS="@WRAPPER_CFLAGS@" |
|---|
| 44 | WRAPPER_LDFLAGS="@WRAPPER_LDFLAGS@" |
|---|
| 45 | MPILIBNAME="@MPILIBNAME@" |
|---|
| 46 | PMPILIBNAME="@PMPILIBNAME@" |
|---|
| 47 | MPI_OTHERLIBS="@LIBS@" |
|---|
| 48 | NEEDSPLIB="@NEEDSPLIB@" |
|---|
| 49 | # MPIVERSION is the version of the MPICH2 library that mpicc is intended for |
|---|
| 50 | MPIVERSION="@VERSION@" |
|---|
| 51 | # |
|---|
| 52 | # Internal variables |
|---|
| 53 | # Show is set to echo to cause the compilation command to be echoed instead |
|---|
| 54 | # of executed. |
|---|
| 55 | Show=eval |
|---|
| 56 | # |
|---|
| 57 | # End of initialization of variables |
|---|
| 58 | #--------------------------------------------------------------------- |
|---|
| 59 | # Environment Variables. |
|---|
| 60 | # The environment variables MPICH_CC may be used to override the |
|---|
| 61 | # default choices. |
|---|
| 62 | # In addition, if there is a file $sysconfdir/mpicc-$CCname.conf, |
|---|
| 63 | # where CCname is the name of the compiler with all spaces replaced by hyphens |
|---|
| 64 | # (e.g., "cc -64" becomes "cc--64", that file is sources, allowing other |
|---|
| 65 | # changes to the compilation environment. See the variables used by the |
|---|
| 66 | # script (defined above) |
|---|
| 67 | if [ -n "$MPICH_CC" ] ; then |
|---|
| 68 | CC="$MPICH_CC" |
|---|
| 69 | CCname=`echo $CC | sed 's/ /-/g'` |
|---|
| 70 | if [ -s $sysconfdir/mpicc-$CCname.conf ] ; then |
|---|
| 71 | . $sysconfdir/mpicc-$CCname.conf |
|---|
| 72 | fi |
|---|
| 73 | fi |
|---|
| 74 | # Allow a profiling option to be selected through an environment variable |
|---|
| 75 | if [ -n "$MPICC_PROFILE" ] ; then |
|---|
| 76 | profConf=$MPICC_PROFILE |
|---|
| 77 | fi |
|---|
| 78 | # |
|---|
| 79 | # ------------------------------------------------------------------------ |
|---|
| 80 | # Argument processing. |
|---|
| 81 | # This is somewhat awkward because of the handling of arguments within |
|---|
| 82 | # the shell. We want to handle arguments that include spaces without |
|---|
| 83 | # loosing the spacing (an alternative would be to use a more powerful |
|---|
| 84 | # scripting language that would allow us to retain the array of values, |
|---|
| 85 | # which the basic (rather than enhanced) Bourne shell does not. |
|---|
| 86 | # |
|---|
| 87 | # Look through the arguments for arguments that indicate compile only. |
|---|
| 88 | # If these are *not* found, add the library options |
|---|
| 89 | |
|---|
| 90 | linking=yes |
|---|
| 91 | allargs="" |
|---|
| 92 | for arg in "$@" ; do |
|---|
| 93 | # Set addarg to no if this arg should be ignored by the C compiler |
|---|
| 94 | addarg=yes |
|---|
| 95 | qarg=$arg |
|---|
| 96 | case $arg in |
|---|
| 97 | # ---------------------------------------------------------------- |
|---|
| 98 | # Compiler options that affect whether we are linking or no |
|---|
| 99 | -c|-S|-E|-M|-MM) |
|---|
| 100 | # The compiler links by default |
|---|
| 101 | linking=no |
|---|
| 102 | ;; |
|---|
| 103 | # ---------------------------------------------------------------- |
|---|
| 104 | # Options that control how we use mpicc (e.g., -show, |
|---|
| 105 | # -cc=* -config=* |
|---|
| 106 | -echo) |
|---|
| 107 | addarg=no |
|---|
| 108 | set -x |
|---|
| 109 | ;; |
|---|
| 110 | -cc=*) |
|---|
| 111 | CC=`echo A$arg | sed -e 's/A-cc=//g'` |
|---|
| 112 | addarg=no |
|---|
| 113 | ;; |
|---|
| 114 | -show) |
|---|
| 115 | addarg=no |
|---|
| 116 | Show=echo |
|---|
| 117 | ;; |
|---|
| 118 | -config=*) |
|---|
| 119 | addarg=no |
|---|
| 120 | CCname=`echo A$arg | sed -e 's/A-config=//g'` |
|---|
| 121 | if [ -s "$sysconfdir/mpicc-$CCname.conf" ] ; then |
|---|
| 122 | . "$sysconfdir/mpicc-$CCname.conf" |
|---|
| 123 | else |
|---|
| 124 | echo "Configuration file mpicc-$CCname.conf not found" |
|---|
| 125 | fi |
|---|
| 126 | ;; |
|---|
| 127 | -compile-info|-compile_info) |
|---|
| 128 | # -compile_info included for backward compatibility |
|---|
| 129 | Show=echo |
|---|
| 130 | addarg=no |
|---|
| 131 | ;; |
|---|
| 132 | -link-info|-link_info) |
|---|
| 133 | # -link_info included for backward compatibility |
|---|
| 134 | Show=echo |
|---|
| 135 | addarg=no |
|---|
| 136 | ;; |
|---|
| 137 | -v) |
|---|
| 138 | # Pass this argument to the compiler as well. |
|---|
| 139 | echo "mpicc for $MPIVERSION" |
|---|
| 140 | # if there is only 1 argument, it must be -v. |
|---|
| 141 | if [ "$#" -eq "1" ] ; then |
|---|
| 142 | linking=no |
|---|
| 143 | fi |
|---|
| 144 | ;; |
|---|
| 145 | -profile=*) |
|---|
| 146 | # Pass the name of a profiling configuration. As |
|---|
| 147 | # a special case, lib<name>.so or lib<name>.la may be used |
|---|
| 148 | # if the library is in $libdir |
|---|
| 149 | profConf=`echo A$arg | sed -e 's/A-profile=//g'` |
|---|
| 150 | addarg=no |
|---|
| 151 | # Loading the profConf file is handled below |
|---|
| 152 | ;; |
|---|
| 153 | -mpe=*) |
|---|
| 154 | # Pass the name of a profiling configuration; this is a special |
|---|
| 155 | # case for the MPE libs. See -profile |
|---|
| 156 | profConf=`echo A$arg | sed -e 's/A-mpe=//g'` |
|---|
| 157 | profConf="mpe_$profConf" |
|---|
| 158 | addarg=no |
|---|
| 159 | # Loading the profConf file is handled below |
|---|
| 160 | ;; |
|---|
| 161 | -help) |
|---|
| 162 | NC=`echo "$CC" | sed 's%\/% %g' | awk '{print $NF}' -` |
|---|
| 163 | if [ -f "$sysconfdir/mpixxx_opts.conf" ] ; then |
|---|
| 164 | . $sysconfdir/mpixxx_opts.conf |
|---|
| 165 | echo " -cc=xxx - Reset the native compiler to xxx." |
|---|
| 166 | else |
|---|
| 167 | if [ -f "./mpixxx_opts.conf" ] ; then |
|---|
| 168 | . ./mpixxx_opts.conf |
|---|
| 169 | echo " -cc=xxx - Reset the native compiler to xxx." |
|---|
| 170 | fi |
|---|
| 171 | fi |
|---|
| 172 | exit 0 |
|---|
| 173 | ;; |
|---|
| 174 | # ----------------------------------------------------------------- |
|---|
| 175 | # Other arguments. We are careful to handle arguments with |
|---|
| 176 | # quotes (we try to quote all arguments in case they include |
|---|
| 177 | # any spaces) |
|---|
| 178 | *\"*) |
|---|
| 179 | qarg="'"$arg"'" |
|---|
| 180 | ;; |
|---|
| 181 | *\'*) |
|---|
| 182 | qarg='\"'"$arg"'\"' |
|---|
| 183 | ;; |
|---|
| 184 | *) |
|---|
| 185 | qarg="'$arg'" |
|---|
| 186 | ;; |
|---|
| 187 | |
|---|
| 188 | esac |
|---|
| 189 | if [ $addarg = yes ] ; then |
|---|
| 190 | allargs="$allargs $qarg" |
|---|
| 191 | fi |
|---|
| 192 | done |
|---|
| 193 | |
|---|
| 194 | if [ $# -eq 0 ] ; then |
|---|
| 195 | echo "Error: Command line argument is needed!" |
|---|
| 196 | "$0" -help |
|---|
| 197 | exit 1 |
|---|
| 198 | fi |
|---|
| 199 | |
|---|
| 200 | # ----------------------------------------------------------------------- |
|---|
| 201 | # Derived variables. These are assembled from variables set from the |
|---|
| 202 | # default, environment, configuration file (if any) and command-line |
|---|
| 203 | # options (if any) |
|---|
| 204 | if [ "$NEEDSPLIB" = yes ] ; then |
|---|
| 205 | mpilibs="-l$PMPILIBNAME -l$MPILIBNAME -lopa" |
|---|
| 206 | else |
|---|
| 207 | mpilibs="-l$MPILIBNAME -lopa" |
|---|
| 208 | fi |
|---|
| 209 | # |
|---|
| 210 | # Init with the ones needed by MPI |
|---|
| 211 | CFLAGS="$WRAPPER_CFLAGS" |
|---|
| 212 | LDFLAGS="$WRAPPER_LDFLAGS" |
|---|
| 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 | CFLAGS="$PROFILE_INCPATHS $CFLAGS" |
|---|
| 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 | |
|---|
| 240 | # ----------------------------------------------------------------------- |
|---|
| 241 | # |
|---|
| 242 | # A temporary statement to invoke the compiler |
|---|
| 243 | # Place the -L before any args incase there are any mpi libraries in there. |
|---|
| 244 | # Eventually, we'll want to move this after any non-MPI implementation |
|---|
| 245 | # libraries. |
|---|
| 246 | # We use a single invocation of the compiler. This will be adequate until |
|---|
| 247 | # we run into a system that uses a separate linking command. With any luck, |
|---|
| 248 | # such archaic systems are no longer with us. This also lets us |
|---|
| 249 | # accept any argument; we don't need to know if we've seen a source |
|---|
| 250 | # file or an object file. Instead, we just check for an option that |
|---|
| 251 | # suppressing linking, such as -c or -M. |
|---|
| 252 | if [ "$linking" = yes ] ; then |
|---|
| 253 | if [ -n "$C_LINKPATH_SHL" ] ; then |
|---|
| 254 | # prepend the path for the shared libraries to the library list |
|---|
| 255 | mpilibs="$C_LINKPATH_SHL$libdir $mpilibs" |
|---|
| 256 | fi |
|---|
| 257 | $Show $CC $CFLAGS $LDFLAGS $allargs -I$includedir -L$libdir -L$opalibdir $mpilibs $MPI_OTHERLIBS |
|---|
| 258 | rc=$? |
|---|
| 259 | else |
|---|
| 260 | $Show $CC $CFLAGS $allargs -I$includedir |
|---|
| 261 | rc=$? |
|---|
| 262 | fi |
|---|
| 263 | |
|---|
| 264 | exit $rc |
|---|