root/mpich2/trunk/src/env/mpif90.in @ 4856

Revision 4856, 12.1 KB (checked in by balaji, 5 months ago)

Added a new set of environment variables (MPICH2_MPICC_FLAGS, etc.),
that will be appended to mpicc and friends, but do not affect MPICH2's
compilation itself. The README has also be updated appropriately to
explain all the available flags correctly.

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