root/mpich2/trunk/src/env/mpicxx.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#! /bin/sh
2#
3# (C) 2006 by Argonne National Laboratory.
4#     See COPYRIGHT in top-level directory.
5#
6# mpicxx
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#    CXX                - C compiler
14#    WRAPPER_CXXFLAGS      - Any special flags needed to compile
15#    WRAPPER_LDFLAGS       - Any special flags needed to link
16#    MPILIBNAME         - Name of the MPI library
17#    MPICXXLIBNAME      - Name of the C++ binding part of the MPI library
18#    MPI_OTHERLIBS      - Other libraries needed in order to link
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
31prefix=@prefix@
32exec_prefix=@exec_prefix@
33sysconfdir=@sysconfdir@
34includedir=@includedir@
35libdir=@libdir@
36opalibdir=@libdir@
37#
38# Default settings for compiler, flags, and libraries
39CXX="@CXX@"
40CXX_LINKPATH_SHL="@CXX_LINKPATH_SHL@"
41WRAPPER_CXXFLAGS="@WRAPPER_CXXFLAGS@"
42WRAPPER_LDFLAGS="@WRAPPER_LDFLAGS@"
43MPILIBNAME="@MPILIBNAME@"
44PMPILIBNAME="@PMPILIBNAME@"
45MPICXXLIBNAME="@MPICXXLIBNAME@"
46MPI_OTHERLIBS="@LIBS@"
47NEEDSPLIB="@NEEDSPLIB@"
48# MPIVERSION is the version of the MPICH2 library that mpicxx is intended for
49MPIVERSION="@VERSION@"
50#
51# Internal variables
52# Show is set to echo to cause the compilation command to be echoed instead
53# of executed.
54Show=eval
55#
56# End of initialization of variables
57#---------------------------------------------------------------------
58# Environment Variables.
59# The environment variables MPICH_CXX may be used to override the
60# default choices.
61# In addition, if there is a file $sysconfdir/mpicxx-$CXXname.conf,
62# where CXXname is the name of the compiler with all spaces replaced by hyphens
63# (e.g., "CC -64" becomes "CC--64", that file is sources, allowing other
64# changes to the compilation environment.  See the variables used by the
65# script (defined above)
66if [ -n "$MPICH_CXX" ] ; then
67    CXX="$MPICH_CXX"
68    CXXname=`echo $CXX | sed 's/ /-/g'`
69    if [ -s $sysconfdir/mpicxx-$CXXname.conf ] ; then
70        . $sysconfdir/mpicxx-$CXXname.conf
71    fi
72fi
73# Allow a profiling option to be selected through an environment variable
74if [ -n "$MPICXX_PROFILE" ] ; then
75    profConf=$MPICXX_PROFILE
76fi
77#
78# ------------------------------------------------------------------------
79# Argument processing.
80# This is somewhat awkward because of the handling of arguments within
81# the shell.  We want to handle arguments that include spaces without
82# loosing the spacing (an alternative would be to use a more powerful
83# scripting language that would allow us to retain the array of values,
84# which the basic (rather than enhanced) Bourne shell does not. 
85#
86# Look through the arguments for arguments that indicate compile only.
87# If these are *not* found, add the library options
88
89linking=yes
90allargs=""
91for arg in "$@" ; do
92    # Set addarg to no if this arg should be ignored by the C compiler
93    addarg=yes
94    qarg=$arg
95    case $arg in
96        # ----------------------------------------------------------------
97        # Compiler options that affect whether we are linking or no
98    -c|-S|-E|-M|-MM)
99    # The compiler links by default
100    linking=no
101    ;;
102        # ----------------------------------------------------------------
103        # Options that control how we use mpicxx (e.g., -show,
104        # -cxx=* -config=*
105    -echo)
106    addarg=no
107    set -x
108    ;;
109    -cxx=*)
110    CXX=`echo A$arg | sed -e 's/A-cxx=//g'`
111    addarg=no
112    ;;
113    # Backwards compatibility for MPICH1 - scripts
114    -CC=*)
115    CXX=`echo A$arg | sed -e 's/A-CC=//g'`
116    addarg=no
117    ;;
118    -show)
119    addarg=no
120    Show=echo
121    ;;
122    -config=*)
123    addarg=no
124    CXXname=`echo A$arg | sed -e 's/A-config=//g'`
125    if [ -s "$sysconfdir/mpicxx-$CXXname.conf" ] ; then
126        . "$sysconfdir/mpicxx-$CXXname.conf"
127    else
128        echo "Configuration file mpicxx-$CXXname.conf not found"
129    fi
130    ;;
131    -compile-info|-compile_info)
132    # -compile_info included for backward compatibility
133    Show=echo
134    addarg=no
135    ;;
136    -link-info|-link_info)
137    # -link_info included for backward compatibility
138    Show=echo
139    addarg=no
140    ;;
141    -v)
142    # Pass this argument to the compiler as well.
143    echo "mpicxx for $MPIVERSION"
144    # if there is only 1 argument, it must be -v.
145    if [ "$#" -eq "1" ] ; then
146        linking=no
147    fi
148    ;;
149    -profile=*)
150    # Pass the name of a profiling configuration.  As
151    # a special case, lib<name>.so or lib<name>.la may be used
152    # if the library is in $libdir
153    profConf=`echo A$arg | sed -e 's/A-profile=//g'`
154    addarg=no
155    # Loading the profConf file is handled below
156    ;;
157    -mpe=*)
158    # Pass the name of a profiling configuration; this is a special
159    # case for the MPE libs.  See -profile
160    profConf=`echo A$arg | sed -e 's/A-mpe=//g'`
161    profConf="mpe_$profConf"
162    addarg=no
163    # Loading the profConf file is handled below
164    ;;
165    -help)
166    NC=`echo "$CXX" | sed 's%\/% %g' | awk '{print $NF}' -`
167    if [ -f "$sysconfdir/mpixxx_opts.conf" ] ; then
168        . $sysconfdir/mpixxx_opts.conf
169        echo "    -cxx=xxx      - Reset the native compiler to xxx."
170    else
171        if [ -f "./mpixxx_opts.conf" ] ; then
172            . ./mpixxx_opts.conf
173            echo "    -cxx=xxx      - Reset the native compiler to xxx."
174        fi
175    fi
176    exit 0
177    ;;
178        # -----------------------------------------------------------------
179        # Other arguments.  We are careful to handle arguments with
180        # quotes (we try to quote all arguments in case they include
181        # any spaces)
182    *\"*)
183    qarg="'"$arg"'"
184    ;;
185    *\'*)
186    qarg='\"'"$arg"'\"'
187    ;;
188    *)
189    qarg="'$arg'"
190    ;;
191
192    esac
193    if [ $addarg = yes ] ; then
194        allargs="$allargs $qarg"
195    fi
196done
197
198if [ $# -eq 0 ] ; then
199    echo "Error: Command line argument is needed!"
200    "$0" -help
201    exit 1
202fi
203
204# -----------------------------------------------------------------------
205# Derived variables.  These are assembled from variables set from the
206# default, environment, configuration file (if any) and command-line
207# options (if any)
208if [ "$NEEDSPLIB" = yes ] ; then
209    mpilibs="-l$PMPILIBNAME -l$MPILIBNAME -lopa"
210else
211    mpilibs="-l$MPILIBNAME -lopa"
212fi
213cxxlibs=
214if [ "$MPICXXLIBNAME" != "$MPILIBNAME" ] ; then
215    cxxlibs="-l$MPICXXLIBNAME"
216fi
217#
218# Init with the ones needed by MPI
219CXXFLAGS="$WRAPPER_CXXFLAGS"
220LDFLAGS="$WRAPPER_LDFLAGS"
221#
222#
223# Handle the case of a profile switch
224if [ -n "$profConf" ] ; then
225    profConffile=
226    if [ -s "$libdir/lib$profConf.a" -o -s "$libdir/lib$profConf.so" ] ; then
227        mpilibs="-l$profConf $mpilibs"
228    elif [ -s "$sysconfdir/$profConf.conf" ] ; then
229        profConffile="$sysconfdir/$profConf.conf"
230    elif [ -s "$profConf.conf" ] ; then
231        profConffile="$profConf.conf"
232    else
233        echo "Profiling configuration file $profConf.conf not found in $sysconfdir"
234    fi
235    if [ -n "$profConffile" -a -s "$profConffile" ] ; then
236        . $profConffile
237        if [ -n "$PROFILE_INCPATHS" ] ; then
238            CXXFLAGS="$PROFILE_INCPATHS $CXXFLAGS"
239        fi
240        if [ -n "$PROFILE_PRELIB" ] ; then
241            mpilibs="$PROFILE_PRELIB $mpilibs"
242        fi
243        if [ -n "$PROFILE_POSTLIB" ] ; then
244            mpilibs="$mpilibs $PROFILE_POSTLIB"
245        fi
246    fi
247fi
248# A temporary statement to invoke the compiler
249# Place the -L before any args incase there are any mpi libraries in there.
250# Eventually, we'll want to move this after any non-MPI implementation
251# libraries
252if [ "$linking" = yes ] ; then
253    if [ -n "$CXX_LINKPATH_SHL" ] ; then
254        # Prepend the path for the shared libraries to the library list
255        shllibpath="$CXX_LINKPATH_SHL$libdir"
256    fi
257    $Show $CXX $CXXFLAGS $LDFLAGS $allargs -I$includedir -L$libdir -L$opalibdir $shllibpath $cxxlibs $mpilibs $MPI_OTHERLIBS
258    rc=$?
259else
260    $Show $CXX $CXXFLAGS $allargs -I$includedir
261    rc=$?
262fi
263
264exit $rc
Note: See TracBrowser for help on using the browser.