root/mpich2/trunk/src/env/mpif77.in @ 4441

Revision 4441, 10.3 KB (checked in by goodell, 7 months ago)

Remove MPIDU_Atomic_ primitives code and use OPA_ instead.

Reviewed by buntinas@.

Line 
1#! /bin/sh
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=eval
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=""
96for arg in "$@" ; do
97    # Set addarg to no if this arg should be ignored by the C compiler
98    addarg=yes
99    qarg=$arg
100    case $arg in
101        # ----------------------------------------------------------------
102        # Compiler options that affect whether we are linking or no
103    -c|-S|-E|-M|-MM)
104    # The compiler links by default
105    linking=no
106    ;;
107        # ----------------------------------------------------------------
108        # Options that control how we use mpif77 (e.g., -show,
109        # -f77=* -config=*
110    -echo)
111    addarg=no
112    set -x
113    ;;
114
115    -f77=*)
116    FC=`echo A$arg | sed -e 's/A-f77=//g'`
117    addarg=no
118    ;;
119    -fc=*)
120    FC=`echo A$arg | sed -e 's/A-fc=//g'`
121    addarg=no
122    ;;
123
124    -show)
125    addarg=no
126    Show=echo
127    ;;
128    -config=*)
129    addarg=no
130    F77name=`echo A$arg | sed -e 's/A-config=//g'`
131    if [ -s "$sysconfdir/mpif77-$F77name.conf" ] ; then
132        . "$sysconfdir/mpif77-$F77name.conf"
133    else
134        echo "Configuration file mpif77-$F77name.conf not found"
135    fi
136    ;;
137    -compile-info|-compile_info)
138    # -compile_info included for backward compatibility
139    Show=echo
140    addarg=no
141    ;;
142    -link-info|-link_info)
143    # -link_info included for backward compatibility
144    Show=echo
145    addarg=no
146    ;;
147    -v)
148    # Pass this argument to the compiler as well.
149    echo "mpif77 for $MPIVERSION"
150    # if there is only 1 argument, it must be -v.
151    if [ "$#" -eq "1" ] ; then
152        linking=no
153    fi
154    ;;
155    -profile=*)
156    # Pass the name of a profiling configuration.  As
157    # a special case, lib<name>.so or lib<name>.la may be used
158    # if the library is in $libdir
159    profConf=`echo A$arg | sed -e 's/A-profile=//g'`
160    addarg=no
161    # Loading the profConf file is handled below
162    ;;
163    -mpe=*)
164    # Pass the name of a profiling configuration; this is a special
165    # case for the MPE libs.  See -profile
166    profConf=`echo A$arg | sed -e 's/A-mpe=//g'`
167    profConf="mpe_$profConf"
168    addarg=no
169    # Loading the profConf file is handled below
170    ;;
171    -help)
172    NC=`echo "$FC" | sed 's%\/% %g' | awk '{print $NF}' -`
173    if [ -f "$sysconfdir/mpixxx_opts.conf" ] ; then
174        . $sysconfdir/mpixxx_opts.conf
175        echo "    -f77=xxx      - Reset the native compiler to xxx."
176        echo "    -fc=xxx       - Reset the native compiler to xxx."
177    else
178        if [ -f "./mpixxx_opts.conf" ] ; then
179            . ./mpixxx_opts.conf
180            echo "    -f77=xxx      - Reset the native compiler to xxx."
181            echo "    -fc=xxx       - Reset the native compiler to xxx."
182        fi
183    fi
184    exit 0
185    ;;
186        # -----------------------------------------------------------------
187        # Other arguments.  We are careful to handle arguments with
188        # quotes (we try to quote all arguments in case they include
189        # any spaces)
190    *\"*)
191    qarg="'"$arg"'"
192    case $arg in
193       -D*)
194       cppflags="$cppflags $qarg"
195       ;;
196    esac
197    ;;
198    *\'*)
199    qarg='\"'"$arg"'\"'
200    case $arg in
201       -D*)
202       cppflags="$cppflags $qarg"
203       ;;
204    esac
205    ;;
206
207    # The following are special args used to handle .F files when the
208    # Fortran compiler itself does not handle these options
209    -I*)
210    cppflags="$cppflags $arg"
211    ;;
212    -D*)
213    cppflags="$cppflags $arg"
214    ;;
215    *.F|*.F90|*.fpp|*.FPP)
216# If F77CPP is not empty, then we need to do the following:
217#    If any input files have the .F or .F90 extension, then   
218#        If F77CPP = false, then
219#            generate an error message and exit
220#        Use F77CPP to convert the file from .F to .f, using
221#            $TMPDIR/f$$-$count.f as the output file name
222#            Replace the input file with this name in the args
223# This is needed only for very broken systems
224#     
225    if [ -n "$F77CPP" ] ; then
226        if [ "$F77CPP" = "false" ] ; then
227            echo "This Fortran compiler does not accept .F or .F90 files"
228            exit 1
229        fi
230        addarg=no
231        # Remove and directory names and extension
232        $ext=`expr "$arg" : '.*\(\..*\)'`
233        bfile=`basename $arg $ext`
234        #
235        TMPDIR=${TMPDIR:-/tmp}
236        tmpfile=$TMPDIR/f$$-$bfile.f
237        if $F77CPP $cppflags $arg > $tmpfile ; then
238            # Add this file to the commandline list
239            count=`expr $count + 1`
240            allargs="$allargs $tmpfile"
241            rmfiles="$rmfiles $tmpfile"
242        else
243            echo "Aborting compilation because of failure in preprocessing step"
244            echo "for file $arg ."
245            exit 1
246        fi
247    fi
248    # Otherwise, just accept the argument
249    ;;
250    # - end of special handling for .F files
251   
252    *)
253    qarg="'$arg'"
254    ;;
255
256    esac
257    if [ $addarg = yes ] ; then
258        allargs="$allargs $qarg"
259    fi
260done
261
262if [ $# -eq 0 ] ; then
263    echo "Error: Command line argument is needed!"
264    "$0" -help
265    exit 1
266fi
267
268# -----------------------------------------------------------------------
269# Derived variables.  These are assembled from variables set from the
270# default, environment, configuration file (if any) and command-line
271# options (if any)
272if [ "$NEEDSPLIB" = yes ] ; then
273    mpilibs="-l$PMPILIBNAME -l$MPILIBNAME -lopa"
274else
275    mpilibs="-l$MPILIBNAME -lopa"
276fi
277#
278# Init with the ones needed by MPI
279FFLAGS="$WRAPPER_FFLAGS"
280LDFLAGS="$WRAPPER_LDFLAGS"
281#
282# Handle the case of a profile switch
283if [ -n "$profConf" ] ; then
284    profConffile=
285    if [ -s "$libdir/lib$profConf.a" -o -s "$libdir/lib$profConf.so" ] ; then
286        mpilibs="-l$profConf $mpilibs"
287    elif [ -s "$sysconfdir/$profConf.conf" ] ; then
288        profConffile="$sysconfdir/$profConf.conf"
289    elif [ -s "$profConf.conf" ] ; then
290        profConffile="$profConf.conf"
291    else
292        echo "Profiling configuration file $profConf.conf not found in $sysconfdir"
293    fi
294    if [ -n "$profConffile" -a -s "$profConffile" ] ; then
295        . $profConffile
296        if [ -n "$PROFILE_INCPATHS" ] ; then
297            FFLAGS="$PROFILE_INCPATHS $FFLAGS"
298        fi
299        if [ -n "$PROFILE_PRELIB" ] ; then
300            mpilibs="$PROFILE_PRELIB $mpilibs"
301        fi
302        if [ -n "$PROFILE_POSTLIB" ] ; then
303            mpilibs="$mpilibs $PROFILE_POSTLIB"
304        fi
305    fi
306fi
307#
308# A temporary statement to invoke the compiler
309# Place the -L before any args incase there are any mpi libraries in there.
310# Eventually, we'll want to move this after any non-MPI implementation
311# libraries
312#
313if [ "$linking" = yes ] ; then
314    if [ -n "$FC_LINKPATH_SHL" ] ; then
315        # Prepend the path for the shared libraries to the library list
316        mpilibs="$FC_LINKPATH_SHL$libdir $mpilibs"
317    fi
318    $Show $FC $FFLAGS $LDFLAGS $allargs -I$includedir -L$libdir -L$opalibdir $mpilibs $MPI_OTHERLIBS
319    rc=$?
320else
321    $Show $FC $FFLAGS $allargs -I$includedir
322    rc=$?
323fi
324if [ -n "$rmfiles" ] ; then
325    for file in $rmfiles ; do
326        objfile=`basename $file .f`
327        if [ -s "${objfile}.o" ] ; then
328            # Rename
329            destfile=`echo $objfile | sed -e "s/.*$$-//"`
330            mv -f ${objfile}.o ${destfile}.o
331        fi
332        rm -f $file
333    done
334    rm -f $rmfiles
335fi
336exit $rc
Note: See TracBrowser for help on using the browser.