| 1 | #! @BASH_SHELL@ |
|---|
| 2 | # |
|---|
| 3 | # (C) 2006 by Argonne National Laboratory. |
|---|
| 4 | # See COPYRIGHT in top-level directory. |
|---|
| 5 | # |
|---|
| 6 | # mpif90 |
|---|
| 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 | # F90 - Fortran 90 compiler |
|---|
| 14 | # WRAPPER_F90FLAGS - 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 | # F90_OTHER_LIBS - Yet more libraries, needed just with F90 |
|---|
| 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 | # Set from the directory arguments to configure (e.g., --prefix=/usr/local) |
|---|
| 32 | prefix=@prefix@ |
|---|
| 33 | exec_prefix=@exec_prefix@ |
|---|
| 34 | sysconfdir=@sysconfdir@ |
|---|
| 35 | includedir=@includedir@ |
|---|
| 36 | modincdir=@modincdir@ |
|---|
| 37 | libdir=@libdir@ |
|---|
| 38 | opalibdir=@libdir@ |
|---|
| 39 | # |
|---|
| 40 | # Default settings for compiler, flags, and libraries |
|---|
| 41 | # Determined by a combination of environment variables and tests within |
|---|
| 42 | # configure (e.g., determining whehter -lsocket is needee) |
|---|
| 43 | F90="@F90@" |
|---|
| 44 | F90_LINKPATH_SHL="@F90_LINKPATH_SHL@" |
|---|
| 45 | F90CPP="@F90CPP@" |
|---|
| 46 | # |
|---|
| 47 | # Fortran 90 Compiler characteristics |
|---|
| 48 | F90INC="@F90INC@" |
|---|
| 49 | # f90modinc specifies how to add a directory to the search path for modules. |
|---|
| 50 | # Some compilers (Intel ifc version 5) do not support this concept, and |
|---|
| 51 | # instead need |
|---|
| 52 | # a specific list of files that contain module names and directories. |
|---|
| 53 | # The F90MODINCSPEC is a more general approach that uses <dir> and <file> |
|---|
| 54 | # for the directory and file respectively. |
|---|
| 55 | F90MODINC="@F90MODINCFLAG@" |
|---|
| 56 | F90MODINCSPEC="@F90MODINCSPEC@" |
|---|
| 57 | F90EXT="@F90EXT@" |
|---|
| 58 | # |
|---|
| 59 | WRAPPER_F90FLAGS="@WRAPPER_F90FLAGS@" |
|---|
| 60 | WRAPPER_LDFLAGS="@WRAPPER_LDFLAGS@" |
|---|
| 61 | MPILIBNAME="@MPILIBNAME@" |
|---|
| 62 | PMPILIBNAME="@PMPILIBNAME@" |
|---|
| 63 | MPI_OTHERLIBS="@LIBS@ @F90_OTHER_LIBS@" |
|---|
| 64 | NEEDSPLIB="@NEEDSPLIB@" |
|---|
| 65 | # MPIVERSION is the version of the MPICH2 library for which mpif90 is intended |
|---|
| 66 | MPIVERSION="@VERSION@" |
|---|
| 67 | # |
|---|
| 68 | # |
|---|
| 69 | # Internal variables |
|---|
| 70 | # Show is set to echo to cause the compilation command to be echoed instead |
|---|
| 71 | # of executed. |
|---|
| 72 | Show= |
|---|
| 73 | # |
|---|
| 74 | # End of initialization of variables |
|---|
| 75 | #--------------------------------------------------------------------- |
|---|
| 76 | # Environment Variables. |
|---|
| 77 | # The environment variables MPICH_F90 may be used to override the |
|---|
| 78 | # default choices. |
|---|
| 79 | # In addition, if there is a file $sysconfdir/mpif90-$F90name.conf, |
|---|
| 80 | # where F90name is the name of the compiler with all spaces replaced by hyphens |
|---|
| 81 | # (e.g., "f90 -64" becomes "f90--64", that file is sources, allowing other |
|---|
| 82 | # changes to the compilation environment. See the variables used by the |
|---|
| 83 | # script (defined above) |
|---|
| 84 | if [ -n "$MPICH_F90" ] ; then |
|---|
| 85 | F90="$MPICH_F90" |
|---|
| 86 | F90name=`echo $F90 | sed 's/ /-/g'` |
|---|
| 87 | if [ -s $sysconfdir/mpif90-$F90name.conf ] ; then |
|---|
| 88 | . $sysconfdir/mpif90-$F90name.conf |
|---|
| 89 | fi |
|---|
| 90 | fi |
|---|
| 91 | # Allow a profiling option to be selected through an environment variable |
|---|
| 92 | if [ -n "$MPIF90_PROFILE" ] ; then |
|---|
| 93 | profConf=$MPIF90_PROFILE |
|---|
| 94 | fi |
|---|
| 95 | # |
|---|
| 96 | # ------------------------------------------------------------------------ |
|---|
| 97 | # Argument processing. |
|---|
| 98 | # This is somewhat awkward because of the handling of arguments within |
|---|
| 99 | # the shell. We want to handle arguments that include spaces without |
|---|
| 100 | # loosing the spacing (an alternative would be to use a more powerful |
|---|
| 101 | # scripting language that would allow us to retain the array of values, |
|---|
| 102 | # which the basic (rather than enhanced) Bourne shell does not. |
|---|
| 103 | # |
|---|
| 104 | # Look through the arguments for arguments that indicate compile only. |
|---|
| 105 | # If these are *not* found, add the library options |
|---|
| 106 | |
|---|
| 107 | linking=yes |
|---|
| 108 | allargs=("$@") |
|---|
| 109 | argno=0 |
|---|
| 110 | cppflags=() |
|---|
| 111 | for arg in "$@" ; do |
|---|
| 112 | # Set addarg to no if this arg should be ignored by the C compiler |
|---|
| 113 | addarg=yes |
|---|
| 114 | case "$arg" in |
|---|
| 115 | # ---------------------------------------------------------------- |
|---|
| 116 | # Compiler options that affect whether we are linking or no |
|---|
| 117 | -c|-S|-E|-M|-MM) |
|---|
| 118 | # The compiler links by default |
|---|
| 119 | linking=no |
|---|
| 120 | ;; |
|---|
| 121 | # ---------------------------------------------------------------- |
|---|
| 122 | # Options that control how we use mpif90 (e.g., -show, |
|---|
| 123 | # -f90=* -config=* |
|---|
| 124 | -echo) |
|---|
| 125 | addarg=no |
|---|
| 126 | set -x |
|---|
| 127 | ;; |
|---|
| 128 | -f90=*) |
|---|
| 129 | F90=`echo A$arg | sed -e 's/A-f90=//g'` |
|---|
| 130 | addarg=no |
|---|
| 131 | ;; |
|---|
| 132 | -show) |
|---|
| 133 | addarg=no |
|---|
| 134 | Show=echo |
|---|
| 135 | ;; |
|---|
| 136 | -config=*) |
|---|
| 137 | addarg=no |
|---|
| 138 | F90name=`echo A$arg | sed -e 's/A-config=//g'` |
|---|
| 139 | if [ -s "$sysconfdir/mpif90-$F90name.conf" ] ; then |
|---|
| 140 | . "$sysconfdir/mpif90-$F90name.conf" |
|---|
| 141 | else |
|---|
| 142 | echo "Configuration file mpif90-$F90name.conf not found" |
|---|
| 143 | fi |
|---|
| 144 | ;; |
|---|
| 145 | -compile-info|-compile_info) |
|---|
| 146 | # -compile_info included for backward compatibility |
|---|
| 147 | Show=echo |
|---|
| 148 | addarg=no |
|---|
| 149 | ;; |
|---|
| 150 | -link-info|-link_info) |
|---|
| 151 | # -link_info included for backward compatibility |
|---|
| 152 | Show=echo |
|---|
| 153 | addarg=no |
|---|
| 154 | ;; |
|---|
| 155 | -v) |
|---|
| 156 | # Pass this argument to the compiler as well. |
|---|
| 157 | echo "mpif90 for $MPIVERSION" |
|---|
| 158 | # if there is only 1 argument, it must be -v. |
|---|
| 159 | if [ "$#" -eq "1" ] ; then |
|---|
| 160 | linking=no |
|---|
| 161 | fi |
|---|
| 162 | ;; |
|---|
| 163 | -profile=*) |
|---|
| 164 | # Pass the name of a profiling configuration. As |
|---|
| 165 | # a special case, lib<name>.so or lib<name>.la may be used |
|---|
| 166 | # if the library is in $libdir |
|---|
| 167 | profConf=`echo A$arg | sed -e 's/A-profile=//g'` |
|---|
| 168 | addarg=no |
|---|
| 169 | # Loading the profConf file is handled below |
|---|
| 170 | ;; |
|---|
| 171 | -mpe=*) |
|---|
| 172 | # Pass the name of a profiling configuration; this is a special |
|---|
| 173 | # case for the MPE libs. See -profile |
|---|
| 174 | profConf=`echo A$arg | sed -e 's/A-mpe=//g'` |
|---|
| 175 | profConf="mpe_$profConf" |
|---|
| 176 | addarg=no |
|---|
| 177 | # Loading the profConf file is handled below |
|---|
| 178 | ;; |
|---|
| 179 | -help) |
|---|
| 180 | NC=`echo "$F90" | sed 's%\/% %g' | awk '{print $NF}' -` |
|---|
| 181 | if [ -f "$sysconfdir/mpixxx_opts.conf" ] ; then |
|---|
| 182 | . $sysconfdir/mpixxx_opts.conf |
|---|
| 183 | echo " -f90=xxx - Reset the native compiler to xxx." |
|---|
| 184 | else |
|---|
| 185 | if [ -f "./mpixxx_opts.conf" ] ; then |
|---|
| 186 | . ./mpixxx_opts.conf |
|---|
| 187 | echo " -f90=xxx - Reset the native compiler to xxx." |
|---|
| 188 | fi |
|---|
| 189 | fi |
|---|
| 190 | exit 0 |
|---|
| 191 | ;; |
|---|
| 192 | # The following are special args used to handle .F files when the |
|---|
| 193 | # Fortran compiler itself does not handle these options |
|---|
| 194 | -I*) |
|---|
| 195 | cppflags[${#cppflags}]="$arg" |
|---|
| 196 | ;; |
|---|
| 197 | -D*) |
|---|
| 198 | cppflags[${#cppflags}]="$arg" |
|---|
| 199 | ;; |
|---|
| 200 | *.F|*.F90|.fpp|.FPP) |
|---|
| 201 | # If F90CPP is not empty, then we need to do the following: |
|---|
| 202 | # If any input files have the .F or .F90 extension, then |
|---|
| 203 | # If F90CPP = false, then |
|---|
| 204 | # generate an error message and exit |
|---|
| 205 | # Use F90CPP to convert the file from .F to .f, using |
|---|
| 206 | # $TMPDIR/f$$-$count.f as the output file name |
|---|
| 207 | # Replace the input file with this name in the args |
|---|
| 208 | # This is needed only for very broken systems |
|---|
| 209 | # |
|---|
| 210 | if [ -n "$F90CPP" ] ; then |
|---|
| 211 | if [ "$F90CPP" = "false" ] ; then |
|---|
| 212 | echo "This Fortran compiler does not accept .F or .F90 files" |
|---|
| 213 | exit 1 |
|---|
| 214 | fi |
|---|
| 215 | addarg=no |
|---|
| 216 | # Remove and directory names and extension |
|---|
| 217 | $ext=`expr "$arg" : '.*\(\..*\)'` |
|---|
| 218 | bfile=`basename $arg $ext` |
|---|
| 219 | # |
|---|
| 220 | TMPDIR=${TMPDIR:-/tmp} |
|---|
| 221 | # Make sure that we use a valid extension for the temp file. |
|---|
| 222 | tmpfile=$TMPDIR/f$$-$bfile.$F90EXT |
|---|
| 223 | if $F90CPP "${cppflags[@]}" $arg > $tmpfile ; then |
|---|
| 224 | # Add this file to the commandline list |
|---|
| 225 | count=`expr $count + 1` |
|---|
| 226 | allargs[${#allargs}]="$tmpfile" |
|---|
| 227 | rmfiles="$rmfiles $tmpfile" |
|---|
| 228 | else |
|---|
| 229 | echo "Aborting compilation because of failure in preprocessing step" |
|---|
| 230 | echo "for file $arg ." |
|---|
| 231 | exit 1 |
|---|
| 232 | fi |
|---|
| 233 | fi |
|---|
| 234 | # Otherwise, just accept the argument |
|---|
| 235 | ;; |
|---|
| 236 | # - end of special handling for .F files |
|---|
| 237 | |
|---|
| 238 | esac |
|---|
| 239 | if [ $addarg = no ] ; then |
|---|
| 240 | unset allargs[$argno] |
|---|
| 241 | fi |
|---|
| 242 | # Some versions of bash do not accept ((argno++)) |
|---|
| 243 | argno=`expr $argno + 1` |
|---|
| 244 | done |
|---|
| 245 | |
|---|
| 246 | if [ $# -eq 0 ] ; then |
|---|
| 247 | echo "Error: Command line argument is needed!" |
|---|
| 248 | "$0" -help |
|---|
| 249 | exit 1 |
|---|
| 250 | fi |
|---|
| 251 | |
|---|
| 252 | # ----------------------------------------------------------------------- |
|---|
| 253 | # Derived variables. These are assembled from variables set from the |
|---|
| 254 | # default, environment, configuration file (if any) and command-line |
|---|
| 255 | # options (if any) |
|---|
| 256 | |
|---|
| 257 | # |
|---|
| 258 | # The library lib${MPILIBNAME}f90 contains the f90-specific features, |
|---|
| 259 | # such as the module objects and the routines defined by them |
|---|
| 260 | # (MPI_SIZEOF is handled in lib${MPILIBNAME)f90, for example). |
|---|
| 261 | if [ "$NEEDSPLIB" = yes ] ; then |
|---|
| 262 | mpilibs="-l${MPILIBNAME}f90 -l$PMPILIBNAME -l$MPILIBNAME -lopa" |
|---|
| 263 | else |
|---|
| 264 | mpilibs="-l${MPILIBNAME}f90 -l$MPILIBNAME -lopa" |
|---|
| 265 | fi |
|---|
| 266 | # |
|---|
| 267 | # Init with the ones needed by MPI |
|---|
| 268 | F90FLAGS="$WRAPPER_F90FLAGS" |
|---|
| 269 | LDFLAGS="$WRAPPER_LDFLAGS" |
|---|
| 270 | # |
|---|
| 271 | # Handle the case of a profile switch |
|---|
| 272 | if [ -n "$profConf" ] ; then |
|---|
| 273 | profConffile= |
|---|
| 274 | if [ -s "$libdir/lib$profConf.a" -o -s "$libdir/lib$profConf.so" ] ; then |
|---|
| 275 | mpilibs="-l$profConf $mpilibs" |
|---|
| 276 | elif [ -s "$sysconfdir/$profConf.conf" ] ; then |
|---|
| 277 | profConffile="$sysconfdir/$profConf.conf" |
|---|
| 278 | elif [ -s "$profConf.conf" ] ; then |
|---|
| 279 | profConffile="$profConf.conf" |
|---|
| 280 | else |
|---|
| 281 | echo "Profiling configuration file $profConf.conf not found in $sysconfdir" |
|---|
| 282 | fi |
|---|
| 283 | if [ -n "$profConffile" -a -s "$profConffile" ] ; then |
|---|
| 284 | . $profConffile |
|---|
| 285 | if [ -n "$PROFILE_INCPATHS" ] ; then |
|---|
| 286 | F90FLAGS="$PROFILE_INCPATHS $F90FLAGS" |
|---|
| 287 | fi |
|---|
| 288 | if [ -n "$PROFILE_PRELIB" ] ; then |
|---|
| 289 | mpilibs="$PROFILE_PRELIB $mpilibs" |
|---|
| 290 | fi |
|---|
| 291 | if [ -n "$PROFILE_POSTLIB" ] ; then |
|---|
| 292 | mpilibs="$mpilibs $PROFILE_POSTLIB" |
|---|
| 293 | fi |
|---|
| 294 | fi |
|---|
| 295 | fi |
|---|
| 296 | |
|---|
| 297 | # Construct the line to add the include directory (not all compilers |
|---|
| 298 | # use -I, unfortunately) |
|---|
| 299 | if [ -z "${F90INC}" ] ; then |
|---|
| 300 | # If there is no path, add a link to the mpif.h file. |
|---|
| 301 | # There *must* be a way to provide the path the any modules (there |
|---|
| 302 | # may be too many to link) |
|---|
| 303 | if [ ! -r mpif.h ] ; then |
|---|
| 304 | #echo "Adding a symbolic link for mpif.h" |
|---|
| 305 | trap "$Show rm -f mpif.h" 0 |
|---|
| 306 | # This should really be the (related) f77includedir (see mpif77). |
|---|
| 307 | $Show ln -s ${includedir}/mpif.h mpif.h |
|---|
| 308 | # Remember to remove this file |
|---|
| 309 | rmfiles="$rmfiles mpif.h" |
|---|
| 310 | fi |
|---|
| 311 | F90INCDIRS= |
|---|
| 312 | else |
|---|
| 313 | # Normally, F90INC is just -I, but some compilers have used different |
|---|
| 314 | # command line arguments |
|---|
| 315 | F90INCDIRS=${F90INC}${includedir} |
|---|
| 316 | fi |
|---|
| 317 | |
|---|
| 318 | # Handle the specification of the directory containing the modules |
|---|
| 319 | # For now, these are in the includedir (no choice argument supported) |
|---|
| 320 | moduledir=$modincdir |
|---|
| 321 | modulelib=${MPILIBNAME}f90 |
|---|
| 322 | if [ -n "$F90MODINCSPEC" ] ; then |
|---|
| 323 | newarg=`echo A"$F90MODINCSPEC" | \ |
|---|
| 324 | sed -e 's/^A//' -e 's%<dir>%'"$moduledir%g" -e 's/<file>/mpi/g'` |
|---|
| 325 | F90MODDIRS="$newarg" |
|---|
| 326 | F90MODLIBS="-l$modulelib" |
|---|
| 327 | elif [ -n "$F90MODINC" ] ; then |
|---|
| 328 | F90MODDIRS="${F90MODINC}$moduledir" |
|---|
| 329 | F90MODLIBS="-l$modulelib" |
|---|
| 330 | fi |
|---|
| 331 | |
|---|
| 332 | # |
|---|
| 333 | # A temporary statement to invoke the compiler |
|---|
| 334 | # Place the -L before any args incase there are any mpi libraries in there. |
|---|
| 335 | # Eventually, we'll want to move this after any non-MPI implementation |
|---|
| 336 | # libraries |
|---|
| 337 | |
|---|
| 338 | if [ "$linking" = yes ] ; then |
|---|
| 339 | if [ -n "$F90_LINKPATH_SHL" ] ; then |
|---|
| 340 | # Prepend the path for the shared libraries to the library list |
|---|
| 341 | mpilibs="$F90_LINKPATH_SHL$libdir $mpilibs" |
|---|
| 342 | fi |
|---|
| 343 | $Show $F90 $MPICH2_MPIF90_FLAGS $F90FLAGS $LDFLAGS "${allargs[@]}" $F90INCDIRS $F90MODDIRS -L$libdir -L$opalibdir $MPICH2_LDFLAGS $F90MODLIBS $mpilibs $MPI_OTHERLIBS |
|---|
| 344 | rc=$? |
|---|
| 345 | else |
|---|
| 346 | $Show $F90 $MPICH2_MPIF90_FLAGS $F90FLAGS "${allargs[@]}" $F90INCDIRS $F90MODDIRS |
|---|
| 347 | rc=$? |
|---|
| 348 | fi |
|---|
| 349 | if [ -n "$rmfiles" ] ; then |
|---|
| 350 | for file in $rmfiles ; do |
|---|
| 351 | objfile=`basename $file .f` |
|---|
| 352 | if [ -s "${objfile}.o" ] ; then |
|---|
| 353 | # Rename |
|---|
| 354 | destfile=`echo $objfile | sed -e "s/.*$$-//"` |
|---|
| 355 | mv -f ${objfile}.o ${destfile}.o |
|---|
| 356 | fi |
|---|
| 357 | rm -f $file |
|---|
| 358 | done |
|---|
| 359 | rm -f $rmfiles |
|---|
| 360 | fi |
|---|
| 361 | exit $rc |
|---|