root/mpich2/trunk/src/env/mpif77.bash.in @ 4856

Revision 4856, 10.0 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#! @BASH_SHELL@
2#
3# (C) 2006 by Argonne National Laboratory.
4#     See COPYRIGHT in top-level directory.
5#
6# mpif77
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#    FC                 - Fortran 77 compiler
14#    WRAPPER_FFLAGS        - 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#    F77_OTHER_LIBS     - Yet more libraries, needed just with F77
19#   
20#   
21# We assume that (a) the C compiler can both compile and link programs
22#
23# Handling of command-line options:
24#   This is a little tricky because some options may contain blanks.
25#
26# Special issues with shared libraries - todo
27#
28# --------------------------------------------------------------------------
29# Set the default values of all variables.
30#
31# Directory locations: Fixed for any MPI implementation.
32# Set from the directory arguments to configure (e.g., --prefix=/usr/local)
33prefix=@prefix@
34exec_prefix=@exec_prefix@
35sysconfdir=@sysconfdir@
36includedir=@includedir@
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)
43FC="@FC@"
44FC_LINKPATH_SHL="@FC_LINKPATH_SHL@"
45F77CPP="@F77CPP@"
46WRAPPER_FFLAGS="@WRAPPER_FFLAGS@"
47WRAPPER_LDFLAGS="@WRAPPER_LDFLAGS@"
48MPILIBNAME="@MPILIBNAME@"
49PMPILIBNAME="@PMPILIBNAME@"
50MPI_OTHERLIBS="@LIBS@ @F77_OTHER_LIBS@"
51NEEDSPLIB="@NEEDSPLIB@"
52#
53# MPIVERSION is the version of the MPICH2 library for which mpif77 is intended
54MPIVERSION="@VERSION@"
55#
56# Internal variables
57# Show is set to echo to cause the compilation command to be echoed instead
58# of executed.
59Show=
60#
61# End of initialization of variables
62#---------------------------------------------------------------------
63# Environment Variables.
64# The environment variables MPICH_F77 may be used to override the
65# default choices.
66# In addition, if there is a file $sysconfdir/mpif77-$F77name.conf,
67# where F77name is the name of the compiler with all spaces replaced by hyphens
68# (e.g., "f77 -64" becomes "f77--64", that file is sources, allowing other
69# changes to the compilation environment.  See the variables used by the
70# script (defined above)
71if [ -n "$MPICH_F77" ] ; then
72    FC="$MPICH_F77"
73    F77name=`echo $FC | sed 's/ /-/g'`
74    if [ -s $sysconfdir/mpif77-$F77name.conf ] ; then
75        . $sysconfdir/mpif77-$F77name.conf
76    fi
77fi
78# Allow a profiling option to be selected through an environment variable
79if [ -n "$MPIF77_PROFILE" ] ; then
80    profConf=$MPIF77_PROFILE
81fi
82#
83# ------------------------------------------------------------------------
84# Argument processing.
85# This is somewhat awkward because of the handling of arguments within
86# the shell.  We want to handle arguments that include spaces without
87# loosing the spacing (an alternative would be to use a more powerful
88# scripting language that would allow us to retain the array of values,
89# which the basic (rather than enhanced) Bourne shell does not. 
90#
91# Look through the arguments for arguments that indicate compile only.
92# If these are *not* found, add the library options
93
94linking=yes
95allargs=("$@")
96argno=0
97cppflags=()
98for arg in "$@" ; do
99    # Set addarg to no if this arg should be ignored by the C compiler
100    addarg=yes
101    case "$arg" in
102        # ----------------------------------------------------------------
103        # Compiler options that affect whether we are linking or no
104    -c|-S|-E|-M|-MM)
105    # The compiler links by default
106    linking=no
107    ;;
108        # ----------------------------------------------------------------
109        # Options that control how we use mpif77 (e.g., -show,
110        # -f77=* -config=*
111    -echo)
112    addarg=no
113    set -x
114    ;;
115
116    -f77=*)
117    FC=`echo A$arg | sed -e 's/A-f77=//g'`
118    addarg=no
119    ;;
120    -fc=*)
121    FC=`echo A$arg | sed -e 's/A-fc=//g'`
122    addarg=no
123    ;;
124
125    -show)
126    addarg=no
127    Show=echo
128    ;;
129    -config=*)
130    addarg=no
131    F77name=`echo A$arg | sed -e 's/A-config=//g'`
132    if [ -s "$sysconfdir/mpif77-$F77name.conf" ] ; then
133        . "$sysconfdir/mpif77-$F77name.conf"
134    else
135        echo "Configuration file mpif77-$F77name.conf not found"
136    fi
137    ;;
138    -compile-info|-compile_info)
139    # -compile_info included for backward compatibility
140    Show=echo
141    addarg=no
142    ;;
143    -link-info|-link_info)
144    # -link_info included for backward compatibility
145    Show=echo
146    addarg=no
147    ;;
148    -v)
149    # Pass this argument to the compiler as well.
150    echo "mpif77 for $MPIVERSION"
151    # if there is only 1 argument, it must be -v.
152    if [ "$#" -eq "1" ] ; then
153        linking=no
154    fi
155    ;;
156    -profile=*)
157    # Pass the name of a profiling configuration.  As
158    # a special case, lib<name>.so or lib<name>.la may be used
159    # if the library is in $libdir
160    profConf=`echo A$arg | sed -e 's/A-profile=//g'`
161    addarg=no
162    # Loading the profConf file is handled below
163    ;;
164    -mpe=*)
165    # Pass the name of a profiling configuration; this is a special
166    # case for the MPE libs.  See -profile
167    profConf=`echo A$arg | sed -e 's/A-mpe=//g'`
168    profConf="mpe_$profConf"
169    addarg=no
170    # Loading the profConf file is handled below
171    ;;
172    -help)
173    NC=`echo "$FC" | sed 's%\/% %g' | awk '{print $NF}' -`
174    if [ -f "$sysconfdir/mpixxx_opts.conf" ] ; then
175        . $sysconfdir/mpixxx_opts.conf
176        echo "    -f77=xxx      - Reset the native compiler to xxx."
177        echo "    -fc=xxx       - Reset the native compiler to xxx."
178    else
179        if [ -f "./mpixxx_opts.conf" ] ; then
180            . ./mpixxx_opts.conf
181            echo "    -f77=xxx      - Reset the native compiler to xxx."
182            echo "    -fc=xxx       - Reset the native compiler to xxx."
183        fi
184    fi
185    exit 0
186    ;;
187    # The following are special args used to handle .F files when the
188    # Fortran compiler itself does not handle these options
189    -I*)
190    cppflags[${#cppflags}]="$arg"
191    ;;
192    -D*)
193    cppflags[${#cppflags}]="$arg"
194    ;;
195    *.F|*.F90|*.fpp|*.FPP)
196# If F77CPP is not empty, then we need to do the following:
197#    If any input files have the .F or .F90 extension, then   
198#        If F77CPP = false, then
199#            generate an error message and exit
200#        Use F77CPP to convert the file from .F to .f, using
201#            $TMPDIR/f$$-$count.f as the output file name
202#            Replace the input file with this name in the args
203# This is needed only for very broken systems
204#     
205    if [ -n "$F77CPP" ] ; then
206        if [ "$F77CPP" = "false" ] ; then
207            echo "This Fortran compiler does not accept .F or .F90 files"
208            exit 1
209        fi
210        addarg=no
211        # Remove and directory names and extension
212        $ext=`expr "$arg" : '.*\(\..*\)'`
213        bfile=`basename $arg $ext`
214        #
215        TMPDIR=${TMPDIR:-/tmp}
216        tmpfile=$TMPDIR/f$$-$bfile.f
217        if $F77CPP "${cppflags[@]}" $arg > $tmpfile ; then
218            # Add this file to the commandline list
219            count=`expr $count + 1`
220            allargs[${#allargs}]="$tmpfile"
221            rmfiles="$rmfiles $tmpfile"
222        else
223            echo "Aborting compilation because of failure in preprocessing step"
224            echo "for file $arg ."
225            exit 1
226        fi
227    fi
228    # Otherwise, just accept the argument
229    ;;
230    # - end of special handling for .F files
231   
232    esac
233    if [ $addarg = no ] ; then
234        unset allargs[$argno]
235    fi
236    # Some versions of bash do not accept ((argno++))
237    argno=`expr $argno + 1`
238done
239
240if [ $# -eq 0 ] ; then
241    echo "Error: Command line argument is needed!"
242    "$0" -help
243    exit 1
244fi
245
246# -----------------------------------------------------------------------
247# Derived variables.  These are assembled from variables set from the
248# default, environment, configuration file (if any) and command-line
249# options (if any)
250if [ "$NEEDSPLIB" = yes ] ; then
251    mpilibs="-l$PMPILIBNAME -l$MPILIBNAME -lopa"
252else
253    mpilibs="-l$MPILIBNAME -lopa"
254fi
255#
256# Init with the ones needed by MPI
257FFLAGS="$WRAPPER_FFLAGS"
258LDFLAGS="$WRAPPER_LDFLAGS"
259#
260# Handle the case of a profile switch
261if [ -n "$profConf" ] ; then
262    profConffile=
263    if [ -s "$libdir/lib$profConf.a" -o -s "$libdir/lib$profConf.so" ] ; then
264        mpilibs="-l$profConf $mpilibs"
265    elif [ -s "$sysconfdir/$profConf.conf" ] ; then
266        profConffile="$sysconfdir/$profConf.conf"
267    elif [ -s "$profConf.conf" ] ; then
268        profConffile="$profConf.conf"
269    else
270        echo "Profiling configuration file $profConf.conf not found in $sysconfdir"
271    fi
272    if [ -n "$profConffile" -a -s "$profConffile" ] ; then
273        . $profConffile
274        if [ -n "$PROFILE_INCPATHS" ] ; then
275            FFLAGS="$PROFILE_INCPATHS $FFLAGS"
276        fi
277        if [ -n "$PROFILE_PRELIB" ] ; then
278            mpilibs="$PROFILE_PRELIB $mpilibs -lopa"
279        fi
280        if [ -n "$PROFILE_POSTLIB" ] ; then
281            mpilibs="$mpilibs $PROFILE_POSTLIB -lopa"
282        fi
283    fi
284fi
285#
286# A temporary statement to invoke the compiler
287# Place the -L before any args incase there are any mpi libraries in there.
288# Eventually, we'll want to move this after any non-MPI implementation
289# libraries
290#
291if [ "$linking" = yes ] ; then
292    if [ -n "$FC_LINKPATH_SHL" ] ; then
293        # Prepend the path for the shared libraries to the library list
294        mpilibs="$FC_LINKPATH_SHL$libdir $mpilibs"
295    fi
296    $Show $FC $MPICH2_MPIF77_FLAGS $FFLAGS $LDFLAGS "${allargs[@]}" -I$includedir -L$libdir -L$opalibdir $MPICH2_LDFLAGS $mpilibs $MPI_OTHERLIBS
297    rc=$?
298else
299    $Show $FC $MPICH2_MPIF77_FLAGS $FFLAGS "${allargs[@]}" -I$includedir
300    rc=$?
301fi
302if [ -n "$rmfiles" ] ; then
303    for file in $rmfiles ; do
304        objfile=`basename $file .f`
305        if [ -s "${objfile}.o" ] ; then
306            # Rename
307            destfile=`echo $objfile | sed -e "s/.*$$-//"`
308            mv -f ${objfile}.o ${destfile}.o
309        fi
310        rm -f $file
311    done
312    rm -f $rmfiles
313fi
314exit $rc
Note: See TracBrowser for help on using the browser.