root/mpich2/trunk/src/env/mpicc.bash.in @ 4441

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

Remove MPIDU_Atomic_ primitives code and use OPA_ instead.

Reviewed by buntinas@.

Line 
1#! @BASH_SHELL@
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)
31prefix=@prefix@
32exec_prefix=@exec_prefix@
33sysconfdir=@sysconfdir@
34includedir=@includedir@
35libdir=@libdir@
36opalibdir=@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)
41CC="@CC@"
42C_LINKPATH_SHL="@C_LINKPATH_SHL@"
43WRAPPER_CFLAGS="@WRAPPER_CFLAGS@"
44WRAPPER_LDFLAGS="@WRAPPER_LDFLAGS@"
45MPILIBNAME="@MPILIBNAME@"
46PMPILIBNAME="@PMPILIBNAME@"
47MPI_OTHERLIBS="@LIBS@"
48NEEDSPLIB="@NEEDSPLIB@"
49# MPIVERSION is the version of the MPICH2 library that mpicc is intended for
50MPIVERSION="@VERSION@"
51#
52# Internal variables
53# Show is set to echo to cause the compilation command to be echoed instead
54# of executed.
55Show=
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)
67if [ -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
73fi
74# Allow a profiling option to be selected through an environment variable
75if [ -n "$MPICC_PROFILE" ] ; then
76    profConf=$MPICC_PROFILE
77fi
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
90linking=yes
91allargs=("$@")
92argno=0
93for arg in "$@" ; do
94    # Set addarg to no if this arg should be ignored by the C compiler
95    addarg=yes
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    ;;
176
177    esac
178    if [ $addarg = no ] ; then
179        unset allargs[$argno]
180    fi
181    # Some versions of bash do not accept ((argno++))
182    argno=`expr $argno + 1`
183done
184
185if [ $# -eq 0 ] ; then
186    echo "Error: Command line argument is needed!"
187    "$0" -help
188    exit 1
189fi
190
191# -----------------------------------------------------------------------
192# Derived variables.  These are assembled from variables set from the
193# default, environment, configuration file (if any) and command-line
194# options (if any)
195if [ "$NEEDSPLIB" = yes ] ; then
196    mpilibs="-l$PMPILIBNAME -l$MPILIBNAME -lopa"
197else
198    mpilibs="-l$MPILIBNAME -lopa"
199fi
200#
201# Init with the ones needed by MPI
202CFLAGS="$WRAPPER_CFLAGS"
203LDFLAGS="$WRAPPER_LDFLAGS"
204#
205# Handle the case of a profile switch
206if [ -n "$profConf" ] ; then
207    profConffile=
208    if [ -s "$libdir/lib$profConf.a" -o -s "$libdir/lib$profConf.so" ] ; then
209        mpilibs="-l$profConf $mpilibs"
210    elif [ -s "$sysconfdir/$profConf.conf" ] ; then
211        profConffile="$sysconfdir/$profConf.conf"
212    elif [ -s "$profConf.conf" ] ; then
213        profConffile="$profConf.conf"
214    else
215        echo "Profiling configuration file $profConf.conf not found in $sysconfdir"
216    fi
217    if [ -n "$profConffile" -a -s "$profConffile" ] ; then
218        . $profConffile
219        if [ -n "$PROFILE_INCPATHS" ] ; then
220            CFLAGS="$PROFILE_INCPATHS $CFLAGS"
221        fi
222        if [ -n "$PROFILE_PRELIB" ] ; then
223            mpilibs="$PROFILE_PRELIB $mpilibs"
224        fi
225        if [ -n "$PROFILE_POSTLIB" ] ; then
226            mpilibs="$mpilibs $PROFILE_POSTLIB"
227        fi
228    fi
229fi
230
231# -----------------------------------------------------------------------
232#
233# A temporary statement to invoke the compiler
234# Place the -L before any args incase there are any mpi libraries in there.
235# Eventually, we'll want to move this after any non-MPI implementation
236# libraries.
237# We use a single invocation of the compiler.  This will be adequate until
238# we run into a system that uses a separate linking command.  With any luck,
239# such archaic systems are no longer with us.  This also lets us
240# accept any argument; we don't need to know if we've seen a source
241# file or an object file.  Instead, we just check for an option that
242# suppressing linking, such as -c or -M.
243if [ "$linking" = yes ] ; then
244    if [ -n "$C_LINKPATH_SHL" ] ; then
245        # prepend the path for the shared libraries to the library list
246        mpilibs="$C_LINKPATH_SHL$libdir $mpilibs"
247    fi
248    $Show $CC $CFLAGS $LDFLAGS "${allargs[@]}" -I$includedir -L$libdir -L$opalibdir $mpilibs $MPI_OTHERLIBS
249    rc=$?
250else
251    $Show $CC $CFLAGS "${allargs[@]}" -I$includedir
252    rc=$?
253fi
254
255exit $rc
Note: See TracBrowser for help on using the browser.