root/mpich2/trunk/configure.in @ 4819

Revision 4819, 244.4 KB (checked in by balaji, 5 months ago)

The symbolic link for mpic++ was incorrectly setup. This should fix
ticket #467.

Line 
1AC_PREREQ(2.62)
2#
3# (C) 2006 by Argonne National Laboratory.
4#     See COPYRIGHT in top-level directory.
5#
6dnl Process this file with autoconf to produce a configure script.
7dnl
8dnl aclocal_cache.m4, included by sowing/confdb/aclocal.m4, fixes
9dnl bugs in autoconf caching.
10dnl
11dnl This is a large configure script and it is important to keep it
12dnl clearly organized.  In addition, this script must coordinate with
13dnl the other modules that can be used to construct MPICH2, such as
14dnl the communication device and the process manager.  Each of these
15dnl may have special features or limitations that other modules or
16dnl this configure may need to take into account.  To handle this, there
17dnl are xx major steps in this configure script:
18dnl
19dnl 1. Identify major modules and source any prerequisite scripts
20dnl 2. Determine compiler characteristics
21dnl 3. Setup and configure the other modules
22dnl 4. Determine MPI features and characteristics (such as datatype values)
23dnl
24dnl Each of these is described in more detail below.
25dnl
26dnl 1. Identify the modules (most are specified by
27dnl --with-<modulename>=instance,
28dnl for example, --with-pm=mpd or --with-device=ch3:nemesis).
29dnl For each module, source the file mpich2prereq if present (in the
30dnl module's top-level directory).  This
31dnl must be a bourne (sh) shell script; it can access any of the variables
32dnl in the configure script.  In addition, there are a few variables that
33dnl are defined and provided to allow the modules to communicate their
34dnl needs or limitations to the other modules.  These are:
35dnl    MPID_MAX_THREAD_LEVEL - thread level supported by device.
36dnl                            if unset, is MPI_THREAD_FUNNELED
37dnl    MPID_NO_LONG_LONG     - if yes, the device does not support the
38dnl                            long long integer type
39dnl    MPID_NO_LONG_DOUBLE   - if yes, the device does not support the
40dnl                            long double type
41dnl    MPID_PM_NAMESERVER    - if set, provides the name of the nameserver
42dnl                            that the process manager supports.
43dnl                            This name server will be used if the
44dnl                            default name server is selected.
45dnl    MPID_NO_PM            - If yes, the device does not require any
46dnl                            PM implementation. 
47dnl    MPID_NO_PMI           - If yes, the device does not require any
48dnl                            PMI implementation.
49dnl    EXTRA_STATUS_DECL     - Any extra declarations that the device
50dnl                            needs added to the definition of MPI_Status.
51dnl    MPID_MAX_PROCESSOR_NAME - The maximum number of character in a processor
52dnl                            name.  If not set, 128 will be used.
53dnl    PMI_REQUIRES_READABLE_TOKENS - if yes, define the C-preprocessor
54dnl                            value USE_HUMAN_READABLE_TOKENS, which is
55dnl                            used in src/include/mpimem.h to define token
56dnl                            separators used in src/util/mem/argstr.c
57dnl    PM_REQUIRES_PMI       - if set, provides the name of the PMI
58dnl                            interface implementation.  If not set,
59dnl                            the "simple" PMI implementation is used.
60dnl                            A process manager that needs a particular
61dnl                            process manager should check that this is
62dnl                            not set to an incompatible value.
63dnl    MPID_NO_SPAWN         - if yes, the device does not support the
64dnl                            dynamic process routines (spawn, connect
65dnl                            attach, join, plus port and publish
66dnl                            routines).  The major effect of this
67dnl                            is to let the test codes know that
68dnl                            spawn is not implemented.
69dnl    MPID_NO_RMA           - if yes, the device does not support the
70dnl                            MPI RMA routines (MPI_Win_create and
71dnl                            MPI_Put etc.).  The major effect of this
72dnl                            is to let the test codes know that
73dnl                            RMA is not implemented.
74dnl
75dnl Note that the meanings of these variables are defined so that an
76dnl undefined value gives the default.  This makes it easy to expand
77dnl the set of such variables, since only modules that need the new
78dnl variable will need to be changed.
79dnl
80dnl 2. Determine compiler characteristics
81dnl Here is where features of the compilers are determined, including
82dnl support for shared libraries and sizes of the basic datatype types.
83dnl
84dnl 3. Setup and configure the other modules
85dnl Before each module configure is executed, the script setup_<module>
86dnl is run if present.  This is a bourne (sh) shell script and may
87dnl access configure variables.  It should not make any changes to the
88dnl compiler name or flags (e.g., do not add -D_XOPEN_SOURCE to CFLAGS here,
89dnl because that may invalidate the determination of the compiler
90dnl characteristics in the prior step).
91dnl
92dnl 4. Determine MPI features
93dnl   
94dnl
95dnl Special environment variables
96dnl To let other scripts and in particular the configure in test/mpi
97dnl know that they are being invoked from within the MPICH2 configure,
98dnl the following environment variables are set and exported:
99dnl    FROM_MPICH2
100dnl    MPICH2_ENABLE_F77
101dnl    MPICH2_ENABLE_F90
102dnl    MPICH2_ENABLE_CXX
103dnl
104dnl The file name here refers to a file in the source being configured
105dnl In later versions of autoconf, the binding of AC_INIT changed (!!!)
106dnl The original version was AC_INIT(a source file)
107dnl The later version is AC_INIT(package,version,[bug-report],[tarname])
108dnl Here we use the original version
109dnl AC_INIT(src/include/mpiimpl.h)
110dnl
111dnl Note that no executable statements are allowed (and any are silently
112dnl dropped) before AC_INIT.
113dnl
114dnl AC_INIT requires an explicit version number
115dnl Args are package name, version, bug report, and tar file name
116dnl All must be literals
117dnl Note that AC_PACKAGE_STRING is not a command but must be defined(!)
118dnl Unfortunately, setting the PACKAGE names is not compatible with
119dnl AC_CONFIG_SUBDIRS, since the resulting values in the generated
120dnl conf file will not be consistent.
121dnl define([AC_PACKAGE_STRING],[MPICH2 1.0.6])
122dnl AC_INIT(mpich2,1.0.6,mpich2-maint@mcs.anl.gov,mpich2-1.0.6)
123dnl Use the oldstyle AC_INIT instead
124
125AC_INIT(src/include/mpichconf.h.in)
126
127CONFIGURE_ARGS_CLEAN=`echo $* | tr '"' ' '`
128AC_SUBST(CONFIGURE_ARGS_CLEAN)
129
130# Try to find the release date
131if test -s "$srcdir/maint/ReleaseDate" ; then
132    RELEASE_DATE="`cat $srcdir/maint/ReleaseDate`"
133else
134    RELEASE_DATE="Unknown, built on `date`"
135fi
136AC_SUBST(RELEASE_DATE)
137
138# Try to find the version
139if test -s "$srcdir/maint/Version" ; then
140    VERSION="`cat $srcdir/maint/Version`"
141else
142    AC_MSG_ERROR([Version information not found. Configuration aborted.])
143fi
144
145# Produce a numeric version assuming the following format:
146# Version: [MAJ].[MIN].[REV][EXT][EXT_NUMBER]
147# Example: 1.0.7rc1 has
148#          MAJ = 1
149#          MIN = 0
150#          REV = 7
151#          EXT = rc
152#          EXT_NUMBER = 1
153#
154# Converting to numeric version will convert EXT to a format number:
155#          ALPHA (a) = 0
156#          BETA (b)  = 1
157#          RC (rc)   = 2
158#          PATCH (p) = 3
159# Regular releases are treated as patch 0
160#
161# Numeric version will have 1 digit for MAJ, 2 digits for MIN,
162# 2 digits for REV, 1 digit for EXT and 2 digits for EXT_NUMBER.
163changequote(<<,>>)
164V1=`expr $VERSION : '\([0-9]*\)\.[0-9]*[\.]*[0-9]*[a-zA-Z]*[0-9]*'`
165V2=`expr $VERSION : '[0-9]*\.\([0-9]*\)[\.]*[0-9]*[a-zA-Z]*[0-9]*'`
166V3=`expr $VERSION : '[0-9]*\.[0-9]*[\.]*\([0-9]*\)[a-zA-Z]*[0-9]*'`
167V4=`expr $VERSION : '[0-9]*\.[0-9]*[\.]*[0-9]*\([a-zA-Z]*\)[0-9]*'`
168V5=`expr $VERSION : '[0-9]*\.[0-9]*[\.]*[0-9]*[a-zA-Z]*\([0-9]*\)'`
169changequote([,])
170
171if test "$V2" -le 9 ; then V2=0$V2 ; fi
172if test "$V3" = "" ; then V3=0; fi
173if test "$V3" -le 9 ; then V3=0$V3 ; fi
174if test "$V4" = "a" ; then
175    V4=0
176elif test "$V4" = "b" ; then
177    V4=1
178elif test "$V4" = "rc" ; then
179    V4=2
180elif test "$V4" = "" ; then
181    V4=3
182    V5=0
183elif test "$V4" = "p" ; then
184    V4=3
185fi
186if test "$V5" -le 9 ; then V5=0$V5 ; fi
187
188NUMVERSION=$V1$V2$V3$V4$V5
189AC_SUBST(NUMVERSION)
190AC_SUBST(VERSION)
191
192#
193# ABIVERSION is incremented when there are changes in the ABI.  This is
194# used to let a shared library describe how compatible it is with executables
195# that were linked against it.  In our use, the version number is x:y, where
196#  x changes when the ABI changes
197#  y changes when major behavior of the routines, without changing the ABI;
198#    reset y to one when x changes.  Some systems don't like a 0 subversion,
199#    so we always use one as the smallest version number.
200# The ABIVERSION is not the same as the VERSION. It is used principly in the
201# Makefile.sm to pass the ABIVERSION to the createshlib script.
202# We use libtool-style version numbers (see --version-info in the
203# libtool manual)
204ABIVERSION="1:1"
205AC_SUBST(ABIVERSION)
206dnl
207CONFIGURE_ARGUMENTS="$ac_configure_args"
208AC_SUBST(CONFIGURE_ARGUMENTS)
209if test -n "$ac_configure_args" ; then
210    echo "Configuring MPICH2 version $VERSION with $ac_configure_args"
211else
212    echo "Configuring MPICH2 version $VERSION"
213fi
214# Add the information on the system:
215echo "Running on system: `uname -a`"
216dnl
217dnl Definitions will be placed in this file rather than in the DEFS variable
218AC_CONFIG_HEADER(src/include/mpichconf.h)
219AH_TOP([/* -*- Mode: C; c-basic-offset:4 ; -*- */
220/* 
221 *  (C) 2001 by Argonne National Laboratory.
222 *      See COPYRIGHT in top-level directory.
223 */
224#ifndef MPICHCONF_H_INCLUDED
225#define MPICHCONF_H_INCLUDED
226])
227AH_BOTTOM([#endif])
228
229dnl
230dnl Set the directory that contains support scripts such as install-sh and
231dnl config.guess
232AC_CONFIG_AUX_DIR(confdb)
233dnl
234dnl Use AC_ARG_ENABLE to look for --enable-feature and AC_ARG_WITH to look for
235dnl --with-capability
236dnl
237dnl Enable better caching control
238PAC_ARG_CACHING
239dnl
240AC_ARG_ENABLE(echo,
241[--enable-echo  - Turn on strong echoing. The default is enable=no.] ,set -x)
242dnl
243dnl
244AC_ARG_ENABLE(coverage,
245[--enable-coverage - Turn on coverage analysis using gcc and gcov],,
246enable_coverage=no)
247dnl
248AC_ARG_ENABLE(dynamiclibs,
249[--enable-dynamiclibs - Enable the use of dynamic libraries by the devices that support them],,enable_dynamiclibs=no)
250dnl
251AC_ARG_ENABLE(error-checking,
252[--enable-error-checking=level - Control the amount of error checking. 
253level may be
254    no        - no error checking
255    runtime   - error checking controllable at runtime through environment
256                variables
257    all       - error checking always enabled],,enable_error_checking=all)
258dnl
259AC_ARG_ENABLE(error-messages,
260[--enable-error-messages=level - Control the amount of detail in error
261  messages.  Level may be
262    all       - Maximum amount of information
263    generic   - Only generic messages (no information about the specific
264                instance)
265    class     - One message per MPI error class
266    none      - No messages],,enable_error_messages=all)
267dnl
268AC_ARG_ENABLE(timing,
269[--enable-timing=level - Control the amount of timing information
270collected by the MPICH implementation.  level may be
271    none    - Collect no data
272    all     - Collect lots of data
273    runtime - Runtime control of data collected
274The default is none.],,enable_timing=default)
275dnl
276AC_ARG_ENABLE(g,
277[--enable-g=option - Control the level of debugging support in the MPICH
278implementation.  option is a list of comma separated names including
279    none     - No debugging
280    handle   - Trace handle operations
281    handlealloc - Trace hancle allocations
282    dbg      - Add compiler flag, -g, to CFLAGS, CXXFLAGS FFLAGS and F90FLAGS.
283    debug    - Synonym for dbg
284    log      - Enable debug event logging
285    mem      - Memory usage tracing
286    meminit  - Preinitialize memory associated structures and unions to
287               eliminate access warnings from programs like valgrind
288    memarena - Check for overwrite errors in memory allocation arena
289    mutex    - Enable error checking on pthread mutexes
290    mutexnesting - Check for non-nesting of mutexes
291    nesting  - Check for proper nesting values
292    fine-grain-nesting - Perform a fine-grain nesting check on exit
293   
294    all      - All of the above choices],,enable_g=none)
295dnl
296dnl We may want to force MPI_Aint to be the same size as MPI_Offset,
297dnl particularly on 32 bit systems with large (64 bit) file systems.
298AC_ARG_WITH(aint-size,
299[--with-aint-size - Override the size of MPI_AINT],,with_aint_size=0)
300dnl
301dnl
302dnl --enable-sharedlibs=kind is set with the PAC_ARG_SHAREDLIBS macro
303dnl
304dnl AC_ARG_ENABLE(internat,
305dnl [--enable-internat - Enable internationalization of messages.
306dnl  Not yet supported])
307dnl
308dnl --enable-fast
309AC_ARG_ENABLE(fast,
310[--enable-fast=option - Control the level of fast execution in the MPICH
311implementation.   option is a list of comma separated names including
312    O<n>     - Appends default optimization flags, -O<n>, to all internal
313               compiler flags, i.e. MPICH2LIB_CFLAGS, MPICH2LIB_CXXFLAGS,
314               MPICH2LIB_FFLAGS, and MPICH2LIB_F90FLAGS.
315    defopt   - Default compiler optimization -O2 for all language bindings,
316               i.e. --enable-fast=O2, when neither --enable-fast
317               nor --disable-fast is specified.
318    nochkmsg - No error checking, i.e. --disable-error-checking
319    notiming - No timing collection, i.e. --disable-timing.
320    ndebug   - Appends -DNDEBUG to internal CFLAGS, i.e. MPICH2LIB_CFLAGS.
321    all|yes  - "defopt", "nochkmsg", "notiming" and "ndebug" are enabled
322               when --enable-fast is specified without any option.
323    none     - None of above options, i.e. --disable-fast.
324],,enable_fast=defopt)
325
326AC_ARG_ENABLE(check-compiler-flags,
327[--enable-check-compiler-flags -- enable the checks for all compiler options,
328xxxFLAGS, MPICH2_xxxFLAGS.  Default is on.],,enable_check_compiler_flags=yes)
329
330dnl
331dnl We enable f77 and f90 if we can find compilers for them.
332dnl In addition, we check whether f77 and f90 can work together.
333dnl
334AC_ARG_ENABLE(f77,
335[--enable-f77 - Enable Fortran 77 bindings],,
336enable_f77=default; enable_f77_wasdefault=yes)
337AC_ARG_ENABLE(f90,
338[--enable-f90 - Enable Fortran 90 bindings],,enable_f90=default)
339AC_ARG_ENABLE(cxx,
340[--enable-cxx - Enable C++ bindings],,enable_cxx=default)
341AC_ARG_ENABLE(romio,
342[--enable-romio - Enable ROMIO MPI I/O implementation],
343,enable_romio=yes)
344dnl
345AC_ARG_ENABLE(debuginfo,
346[--enable-debuginfo - Enable support for debuggers],,enable_debuginfo=no)
347
348AC_ARG_ENABLE(smpcoll,
349        [--enable-smpcoll - Enable support for SMP/multi-core aware collectives],
350        smpcoll=$enableval,
351        smpcoll=yes)
352
353if test $smpcoll = "yes" ; then
354   AC_DEFINE(USE_SMP_COLLECTIVES,1,[define to enable SMP/multi-core aware collectives])
355fi
356
357dnl Check for pipelined collectives
358AC_ARG_ENABLE(pipecoll,
359        [--enable-pipecoll - Enable support for pipelined collectives],
360        pipecoll=$enableval,
361        pipecoll=yes)
362
363if test $pipecoll = "yes" ; then
364   AC_DEFINE(USE_PIPE_COLLECTIVES,1,[define to enable pipelined collectives])
365fi
366
367dnl
368dnl The environment variable MPICH_DEBUGLIBNAME may be used to override the
369dnl default name of the library that the debugger will load to access the
370dnl MPICH2 internal data structures.
371dnl
372AC_ARG_ENABLE(nmpi-as-mpi,
373[--enable-nmpi-as-mpi - Use MPI rather than PMPI routines for MPI routines,
374 such as the collectives, that may be implemented in terms of other MPI
375 routines],,enable_nmpi_as_mpi=no)
376dnl
377dnl With options
378dnl "default" is a special device that allows MPICH to choose one based on
379dnl the environment.
380AC_ARG_WITH(device,
381[--with-device=name - Specify the communication device for MPICH.],,
382with_device=default)
383dnl
384AC_ARG_WITH(pmi, [--with-pmi=name - Specify the pmi interface for MPICH.],,
385with_pmi=default)
386dnl
387AC_ARG_WITH(pm, [--with-pm=name - Specify the process manager for MPICH.
388      Multiple process managers may be specified as long as they all use
389      the same pmi interface by separating them with colons.  The
390      mpiexec for the first named process manager will be installed.
391      Example: --with-pm=gforker:mpd:remshell builds the three process
392      managers gforker, mpd, and remshell; only the mpiexec from gforker
393      is installed into the bin directory.],,
394with_pm=default)
395dnl
396AC_ARG_WITH(logging,
397[--with-logging=name - Specify the logging library for MPICH.],
398[if test -z "$withval" ; then with_logging=rlog ; fi],
399with_logging=none)
400dnl
401dnl both --without-mpe and --disable-mpe are supported
402dnl AC_ARG_ENABLE(mpe) is used only when --with(out)-mpe is not used.
403AC_ARG_WITH(mpe,
404[--with-mpe - Build the MPE (MPI Parallel Environment) routines],,
405with_mpe=default)
406if test "$with_mpe" = "default" ; then
407    AC_ARG_ENABLE(mpe,
408    [--enable-mpe - Build the MPE (MPI Parallel Environment) routines],
409    with_mpe=$enableval,with_mpe=default)
410fi
411dnl
412AC_ARG_ENABLE(threads,
413[--enable-threads=level - Control the level of thread support in the
414MPICH implementation.  The following levels are supported.
415    single - No threads (MPI_THREAD_SINGLE)
416    funneled - Only the main thread calls MPI (MPI_THREAD_FUNNELED)
417    serialized - User serializes calls to MPI (MPI_THREAD_SERIALIZED)
418    multiple(:impl) - Fully multi-threaded (MPI_THREAD_MULTIPLE)
419The following implementations are supported.
420    global_mutex - a single global lock guards access to all MPI functions.
421The default implementation is global_mutex.
422For the ch3:sock channel, a separate build is no longer needed for thread-multiple.
423It is compiled by default and is selectable at run time with MPI_Init_thread.
424If MPI_Init_thread is not called, the default is funneled .
425For other channels, the --enable-threads option is not supported currently, and
426the default is funneled.],,
427enable_threads=default)
428dnl
429AC_ARG_ENABLE(thread-cs,
430[--enable-thread-cs=type - Choose the method used for critical sections and
431 other atomic updates when multiple threads are present.  Values may be
432 global (default), brief-global, per-object, lock-free],,
433 enable_thread_cs=global)
434AC_ARG_ENABLE(refcount,
435[--enable-refcount=type - Choose the method for ensuring atomic updates to
436the reference counts for MPI objects.  Values may be lock, lock-free, none.
437The default depends on the thread-cs choice; for global it is none (because
438none is required), for brief-global and per-object it is lock, and for
439lock-free it is lock-free],,enable_refcount=default)
440AC_ARG_ENABLE(mutex-timing, [--enable-mutex-timing - calculate the
441                            time spent waiting on mutexes.  For best
442                            results, use with
443                            --enable-timer-type=linux86_cycle],
444              AC_DEFINE(MPIU_MUTEX_WAIT_TIME,1,[Define to enable timing mutexes])
445              )
446AC_ARG_ENABLE(handle-allocation,
447              [--enable-handle-allocation=type - Choose the method used for
448              allocating MPI object handles.  Values may be 'tls' for
449              thread-local storage or 'mutex' for simple locking.  'mutex' is
450              the default.],
451              ,
452              enable_handle_allocation=default)
453
454dnl
455dnl
456AC_ARG_ENABLE(weak-symbols,
457[--enable-weak-symbols - Use weak symbols to implement PMPI routines (default)],,
458enable_weak_symbols=yes)
459dnl
460dnl
461dnl
462AC_ARG_WITH(cross,
463[--with-cross=file - Specify the values of variables that configure cannot
464determine in a cross-compilation environment],,with_cross=no)
465dnl
466AC_ARG_WITH(namepublisher,
467[--with-namepublisher=name - Choose the system that will support
468                             MPI_PUBLISH_NAME and MPI_LOOKUP_NAME.  Options
469                             include
470                               no (no service available)
471                               mpd
472                               file[:directory] (optional directory)
473                               ],,
474with_namepublisher=default)
475dnl
476dnl AC_ARG_WITH(cxxlibname,
477dnl [--with-cxxlibname=name  - Specify name of library containing C++ interface
478dnl routines],[MPICXXLIBNAME=$withval;set_MPICXXLIBNAME="yes"],MPICXXLIBNAME=)
479
480dnl flibname complicates the handling of MPIR_F_TRUE and MPIR_F_FALSE,
481dnl particularly when using IBM/MS-style shared libraries.  Withdraw this
482dnl option and see if anyone misses it.
483dnl
484dnl AC_ARG_WITH(flibname,
485dnl [--with-flibname=name  - Specify name of library containing Fortran interface
486dnl routines],[MPIFLIBNAME=$withval;set_MPIFLIBNAME="yes"],MPIFLIBNAME=)
487AC_SUBST(MPIFLIBNAME)
488AC_SUBST(PMPIFLIBNAME)
489dnl
490dnl The default is a special wrapper library
491AC_ARG_WITH(fwrapname,
492[--with-fwrapname=name  - Specify name of library containing Fortran interface
493routines],[FWRAPNAME=$withval;set_FWRAPNAME="yes"],FWRAPNAME=fmpich)
494AC_SUBST(FWRAPNAME)
495dnl
496#
497# Save a copy of CFLAGS, CXXFLAGS, FFLAGS, F90FLAGS, LDFLAGS as WRAPPER_*
498# before any of these flags are being modified by configure tests.
499#
500# WRAPPER_xFLAGS are used by mpicc and friends.
501# Don't modify WRAPPER_xFLAGS
502WRAPPER_CFLAGS=$CFLAGS
503WRAPPER_CXXFLAGS=$CXXFLAGS
504WRAPPER_FFLAGS=$FFLAGS
505WRAPPER_F90FLAGS=$F90FLAGS
506WRAPPER_LDFLAGS=$LDFLAGS
507export WRAPPER_CFLAGS
508export WRAPPER_CXXFLAGS
509export WRAPPER_FFLAGS
510export WRAPPER_F90FLAGS
511export WRAPPER_LDFLAGS
512
513# -----------------------------------------------------------------------------
514# First check that we have a clean build if we are doing a VPATH build
515PAC_VPATH_CHECK(src/include/mpi.h src/env/mpicc src/env/mpicc.conf,lib)
516
517# ----------------------------------------------------------------------------
518# This test is complicated by the fact that top_srcdir is not set until
519# the very end of configure.  Instead, we get it ourselves
520if test -z "$top_srcdir" ; then
521   use_top_srcdir=$srcdir   
522else
523   use_top_srcdir=$top_srcdir
524fi
525if test -z "$master_top_srcdir" ; then
526    # This needs to be an absolute pathname
527    case "$use_top_srcdir" in
528    /*) ;;
529    *)
530        use_top_srcdir=`(cd $use_top_srcdir && pwd)`
531        ;;     
532    esac
533    master_top_srcdir=$use_top_srcdir
534fi
535# Get the directory that we're running in...
536if test -z "$master_top_builddir" ; then
537   master_top_builddir="`pwd`"
538fi
539AC_SUBST(master_top_builddir)
540AC_SUBST(master_top_srcdir)
541export master_top_builddir
542export master_top_srcdir
543# ----------------------------------------------------------------------------
544# We create this file to allow other configures to find the "master"
545# top builddir
546rm -f .mpich2
547date > .mpich2
548# ----------------------------------------------------------------------------
549# with-device
550if test "$with_device" = "default" ; then
551    # Pick the device.  For now, always choose ch3
552    with_device=ch3
553fi
554# Extract the device name from any options
555# Allow the device to specify a directory; if no directory, use the
556# included directories
557#
558DEVICE=$with_device
559AC_SUBST(DEVICE)
560
561device_name=`echo $with_device | sed -e 's/:.*$//'`
562changequote(<<,>>)
563device_args=`echo $with_device | sed -e 's/^[^:]*//' -e 's/^://'`
564changequote([,])
565
566devicedir=$use_top_srcdir/src/mpid/$device_name
567devicereldir=src/mpid/$device_name
568case "$device_name" in
569     /*)
570     devicedir=$DEVICE
571     # Get the name from the leaf
572     device_name=`echo $device_name ~ sed -e 's%.*/%%'`
573     # FIXME: should the devicereldir be different (perhaps not -
574     # this allows use to build within our tree, even when other data
575     # is outside of the tree)
576     ;;
577     *)
578     ;;
579esac
580export device_name
581export device_args
582export devicedir
583# Make the device base name and args available to generated files
584DEVICE_NAME=$device_name
585AC_SUBST(DEVICE_NAME)
586DEVICE_ARGS=$device_args
587AC_SUBST(DEVICE_ARGS)
588#
589# Give the device an opportunity to include a header file in mpi.h.  The
590# default value of INCLUDE_MPIDDEFS_H is set prior to the inclusion of the
591# device's mpich2prereq script.  The device's script may override the value
592# if needed.
593INCLUDE_MPIDDEFS_H='/* ... no device specific definitions ... */'
594AC_SUBST(INCLUDE_MPIDDEFS_H)
595
596#
597# See if the device wants to say something about the compilers (for example,
598# the globus device may need to do this)
599if test -f $devicedir/mpich2prereq ; then
600    . $devicedir/mpich2prereq
601fi
602
603# ----------------------------------------------------------------------------
604# Set default library names if names haven't already been provided
605MPILIBNAME=${MPILIBNAME:-"mpich"}
606PMPILIBNAME_set=no
607if test -n "$PMPILIBNAME" ; then
608   PMPILIBNAME_set=yes
609fi
610PMPILIBNAME=${PMPILIBNAME:-"p$MPILIBNAME"}
611# Note that the name for this library may be updated after we check for
612# enable_shmem
613# Fortran names are set later.
614# We use a different library for the C++ wrappers to avoid problems when
615# creating shared libraries
616if test -z "$MPICXXLIBNAME" ; then MPICXXLIBNAME="${MPILIBNAME}cxx" ; fi
617export MPIFLIBNAME
618export PMPIFLIBNAME
619export MPICXXLIBNAME
620AC_SUBST(MPICXXLIBNAME)
621
622# We'll set FORTRAN_BINDING to 1 if we support Fortran
623FORTRAN_BINDING=0
624
625# Set up default compiler optimization
626MPI_DEFAULT_COPTS="-O2"
627MPI_DEFAULT_CXXOPTS="-O2"
628MPI_DEFAULT_FOPTS="-O2"
629MPI_DEFAULT_F90OPTS="-O2"
630
631# enable-fast
632# strip off multiple options, separated by commas
633save_IFS="$IFS"
634IFS=","
635for option in $enable_fast ; do
636    case "$option" in
637        defopt)
638        enable_default_optimize=yes
639        ;;
640        nochkmsg)
641        enable_fast_nochkmsg=yes
642        ;;
643        notiming)
644        enable_timing=no
645        ;;
646        ndebug)
647        enable_append_ndebug=yes
648        ;;
649#
650# [BRT] removed the reseting of enable_g so that --with-enable=dbg,meminit
651# can be specified with -enable-fast.  This change was largely made for the
652# PETSc folks who want to use --enable-fast to eliminate parameter checking
653# overhead, but also wish to use meminit to eliminate initialization
654# warnings from valgrind.
655#
656        all|yes)
657        enable_default_optimize=yes
658        enable_fast_nochkmsg=yes
659        # Disable timing/logging stuffs
660        enable_timing=no
661        enable_append_ndebug=yes
662        ;;
663        O*)
664        # Allows O<n> where <n> can be [0-9] or ' '.
665        opt_flags=`echo $option | sed -e 's%\(O[0-9] \)%\1%g'`
666        if test -n "$opt_flags" ; then
667            enable_default_optimize=yes
668            MPI_DEFAULT_COPTS="-$option"
669            MPI_DEFAULT_CXXOPTS="-$option"
670            MPI_DEFAULT_FOPTS="-$option"
671            MPI_DEFAULT_F90OPTS="-$option"
672        else
673            AC_MSG_WARN([Unknown value $option for --enable-fast])
674        fi
675        ;;
676        none|no)
677        enable_default_optimize=no
678        enable_fast_nochkmsg=no
679        # Reset timing/logging stuffs to when --enable-timing isn't specified.
680        enable_timing=default
681        enable_append_ndebug=no
682        ;;
683        *)
684        AC_MSG_WARN([Unknown value $option for --enable-fast])
685        ;;
686    esac
687done
688IFS="$save_IFS"
689
690# ----------------------------------------------------------------------------
691# Process any enable or with values
692# We must do enable-fast first, because it changes the other enable values
693if test "$enable_fast_nochkmsg" = "yes" ; then
694    enable_error_checking=no
695    # Export a variable that will allow the test suite to detect that
696    # MPICH has no error testing
697    MPICH_FAST=yes
698    export MPICH_FAST
699fi
700
701# error-checking
702case "$enable_error_checking" in
703    no)
704    # if error checking has been diabled, then automatically diable the error
705    # checking tests in the test suite
706    ac_configure_args="${ac_configure_args} --disable-checkerrors"
707    ;;
708    all|yes|runtime)
709    error_checking_kind=`echo $enable_error_checking | \
710    tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
711    error_checking_kind=MPID_ERROR_LEVEL_$error_checking_kind
712    AC_DEFINE_UNQUOTED(HAVE_ERROR_CHECKING,$error_checking_kind,[Define to enable error checking])
713    ;;
714    *)
715    AC_MSG_WARN([Unknown value $enable_error_checking for enable-error-checking])
716    ;;
717esac
718
719# error-messages
720case "$enable_error_messages" in
721    no|none)
722        error_message_kind="MPICH_ERROR_MSG_NONE"
723    ;;
724    all|yes)
725        error_message_kind="MPICH_ERROR_MSG_ALL"
726    ;;
727    generic)
728        error_message_kind="MPICH_ERROR_MSG_GENERIC"
729    ;;
730    class)
731        error_message_kind="MPICH_ERROR_MSG_CLASS"
732    ;;
733    *)
734    AC_MSG_WARN([Unknown value $enable_error_messages for enable-error-messages])
735    ;;
736esac
737AC_DEFINE_UNQUOTED(MPICH_ERROR_MSG_LEVEL,$error_message_kind,[define to enable error messages])
738
739# ----------------------------------------------------------------------------
740#
741# enable-timing and with-logging
742#
743# Still to do: add subsets: e.g., class=pt2pt,class=coll.  See mpich2 doc
744#
745# Logging and timing are intertwined.  If you select logging, you
746# may also need to select a timing level.  If no timing is selected
747# but logging with rlog is selected, make "all" the default timing level.
748#
749# FIXME: make timing and logging options work more cleanly together,
750# particularly when other logging options are selected (e.g., logging is not
751# rlog).
752# ----------------------------------------------------------------------------
753collect_stats=false
754logging_required=false
755if test "$enable_timing" = "default" ; then
756    if test "$with_logging" = "rlog" ; then
757        enable_timing=all
758    fi
759fi
760timing_name=$enable_timing
761case "$enable_timing" in
762    no)
763    timing_name=none
764    ;;
765    time)
766    collect_stats=true
767    ;;
768    log|log_detailed)
769    logging_required=true
770    ;;
771    yes)
772    timing_name=all
773    collect_stats=true
774    logging_required=true
775    ;;
776    all|runtime)
777    collect_stats=true
778    logging_required=true
779    ;;
780    none|default)
781    timing_name=none
782    ;;
783    *)
784    AC_MSG_WARN([Unknown value $enable_timing for enable-timing])
785    enable_timing=no
786    timing_name=none
787    ;;
788esac
789#
790# The default logging package is rlog; you can get it by
791# specifying --with-logging or --with-logging=rlog
792#
793case $with_logging in
794    yes)
795    logging_name=rlog
796    ;;
797    no|none)
798    logging_name=none
799    ;;
800    default)
801    if test "$logging_required" = "true" ; then
802        logging_name=rlog
803    else
804        logging_name=none
805    fi
806    ;;
807    *)
808    logging_name=$with_logging
809    ;;
810esac
811#
812# Include the selected logging subsystem
813#
814# Choices:
815# 1) A subdir of src/util/logging
816#     This directory must contain a configure which will be executed
817#     to build the
818# 2) An external directory
819#     This directory must contain
820#          a mpilogging.h file
821#     It may contain
822#          a setup_logging script
823#          a configure
824#     
825#   
826logging_subsystems=
827if test "$logging_name" != "none" ; then
828    # Check for an external name (directory containing a /)
829    hasSlash=`echo A$logging_name | sed -e 's%[[^/]]%%g'`
830    if test -n "$hasSlash" ; then
831        # Check that the external logging system is complete.
832        # Any failure will cause configure to abort
833        if test ! -d $logging_name ; then
834            AC_MSG_ERROR([External logging directory $logging_name not found.  Configure aborted])
835            logging_name=none
836        elif test ! -s $logging_name/mpilogging.h ; then
837            AC_MSG_ERROR([External logging header $logging_name/mpilogging.h not found.  Configure aborted])
838            logging_name=none
839        fi
840
841        logdir=$logging_name
842        # Force the logdir to be absolute
843        logdir=`cd $logdir && pwd`
844        # Switch name to "external" because that is how the MPICH2
845        # code will know it
846        logging_name=external
847        # Add the dir to the include paths
848        #CPPFLAGS="$CPPFLAGS -I$logdir"
849        MPICH2_INCLUDE_FLAGS="$MPICH2_INCLUDE_FLAGS -I$logdir"
850        EXTERNAL_SRC_DIRS="$EXTERNAL_SRC_DIRS $logdir"
851        # Add to the list of external modules to setup
852        if test -x $logdir/setup_logging ; then
853             EXTERNAL_SETUPS="$EXTERNAL_SETUPS $logdir/setup_logging"
854        fi
855    else
856        logdir=$srcdir/src/util/logging
857        logreldir=src/util/logging/$logging_name
858        logging_subsystems="$logging_subsystems $logreldir"
859        logging_subdirs=$logging_name
860        for dir in $logging_subdirs ; do
861            if test ! -d $logdir/$dir ; then
862                AC_MSG_ERROR([$logdir/$dir does not exist.  Configure aborted])
863                logging_name=none
864            fi
865        done
866        for dir in $logging_subsystems ; do
867            if test ! -x $srcdir/$dir/configure ; then
868                AC_MSG_ERROR([$logdir/$dir has no configure (required).  Configure aborted])
869                logging_name=none
870            fi
871            other_install_dirs="${other_install_dirs} $logreldir"
872        done
873    fi
874fi
875#
876# FIXME: Logging doesn't necessarily require timing (e.g., simply logging the
877# sequence of routines). 
878if test "$logging_name" != "none" ; then
879    if test "$enable_timing" != "no" ; then
880        if test "$enable_timing" = "default" -o "$enable_timing" = "none" ; then
881            enable_timing=log
882            timing_name=log
883        fi
884        logging_dir=logging
885        subsystems="$subsystems $logging_subsystems"
886    else
887        AC_MSG_WARN([Timing was disabled.  Logging has been disabled as well.])
888        with_logging=no
889        logging_name=none
890        logging_dir=
891        logging_subdirs=
892    fi
893else
894    if test "$logging_required" = "true" ; then
895        AC_MSG_WARN([Timing was enabled with log option but no logging library is available.  Timing has been disabled.])
896        enable_timing=no
897        timing_name=none
898    fi
899    logging_dir=
900    logging_subdirs=
901fi
902if test "$timing_name" != "none" ; then
903    timing_kind=`echo $timing_name | \
904       tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
905    timing_kind=MPID_TIMING_KIND_$timing_kind
906    AC_DEFINE_UNQUOTED(HAVE_TIMING,$timing_kind,[define to enable timing collection])
907    if test "$collect_stats" = "true" ; then
908        AC_DEFINE(COLLECT_STATS,1,[define to enable collection of statistics])
909    fi
910fi
911#
912AC_SUBST(logging_dir)
913AC_SUBST(logging_name)
914AC_SUBST(logging_subdirs)
915use_logging_variable="MPID_LOGGING_`echo $logging_name | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
916AC_DEFINE_UNQUOTED(USE_LOGGING,$use_logging_variable,[define to choose logging library])
917# ----------------------------------------------------------------------------
918# End of logging tests
919# ----------------------------------------------------------------------------
920
921# ----------------------------------------------------------------------------
922# Check to see if the device does not support spawn. 
923# FIXME: This should provide the option of not building the dynamic
924# process routines.  It could also allow us to specialize support
925# for all processes are members of MPI_COMM_WORLD (only one comm_world).
926# ----------------------------------------------------------------------------
927if test "$MPID_NO_SPAWN" = yes ; then
928    AC_MSG_WARN([The device $with_device does not support MPI dynamic process routines])   
929fi
930
931
932# ----------------------------------------------------------------------------
933# atomic operations
934# ----------------------------------------------------------------------------
935# FIXME TODO eventually delete the src/mpid/common/locks directory
936subsystems="$subsystems src/mpid/common/locks"
937
938opadir="${use_top_srcdir}/src/openpa"
939if test -e "$opadir" ; then
940    EXTERNAL_SRC_DIRS="$EXTERNAL_SRC_DIRS src/openpa"
941    # this must go in CPPFLAGS intead of MPICH2_INCLUDE_FLAGS because we need it
942    # to be available to lower-level configure scripts
943    CPPFLAGS="$CPPFLAGS -I${use_top_srcdir}/src/openpa/src -I${master_top_builddir}/src/openpa/src"
944    # openpa needs to go at the front of the devsubsystems because it needs to
945    # be configured before the device itself (e.g. nemesis).
946    devsubsystems="src/openpa $devsubsystems"
947    other_install_dirs="$other_install_dirs src/openpa"
948fi
949
950# ----------------------------------------------------------------------------
951# Threads
952# ----------------------------------------------------------------------------
953#
954# Threads must be supported by the device.  First, set the default to
955# be the highest supported by the device
956if test "$enable_threads" = default ; then
957    if test -n "$MPID_MAX_THREAD_LEVEL" ; then
958        case $MPID_MAX_THREAD_LEVEL in
959            MPI_THREAD_SINGLE)     enable_threads=single ;;
960            MPI_THREAD_FUNNELED)   enable_threads=funneled ;;
961            MPI_THREAD_SERIALIZED) enable_threads=serialized ;;
962            MPI_THREAD_MULTIPLE)   enable_threads=runtime ;;
963            *) AC_MSG_ERROR([Unrecognized thread level from device $MPID_MAX_THREAD_LEVEL])
964            ;;
965        esac
966    else
967        enable_threads=single
968    fi
969fi
970
971if test "$enable_threads" = "yes" ; then
972    enable_threads=multiple
973elif test "$enable_threads" = "no" ; then
974    enable_threads=single
975elif test "$enable_threads" = "default"; then
976    if test "$with_device" = "default" -o "$with_device" = "ch3:sock" ; then
977        enable_threads=runtime
978    fi
979fi
980# Runtime is an alias for multiple with an additional value
981if test "$enable_threads" = "runtime" ; then
982    AC_DEFINE(HAVE_RUNTIME_THREADCHECK,1,[Define if MPI supports MPI_THREAD_MULTIPLE with a runtime check for thread level])
983    enable_threads=multiple
984    # FIXME: This doesn't support runtime:thread-impl (as in multiple:thread-impl)
985fi
986
987MPICH_THREAD_LEVEL=MPI_THREAD_FUNNELED
988case "$enable_threads" in
989    single)
990    thread_pkg_required=no
991    thread_impl=none
992    MPICH_THREAD_LEVEL=MPI_THREAD_SINGLE
993    ;;
994    funneled)
995    thread_pkg_required=no
996    thread_impl=none
997    MPICH_THREAD_LEVEL=MPI_THREAD_FUNNELED
998    ;;
999    serialized)
1000    # FIXME: Why does serialized require a thread package?
1001    thread_pkg_required=yes
1002    thread_impl=none
1003    MPICH_THREAD_LEVEL=MPI_THREAD_SERIALIZED
1004    ;;
1005    multiple)
1006    thread_pkg_required=yes
1007    thread_impl=global_mutex
1008    MPICH_THREAD_LEVEL=MPI_THREAD_MULTIPLE
1009    ;;
1010    multiple:*)
1011    thread_pkg_required=yes
1012    thread_impl="`echo $enable_threads | sed -e 's/.*://'`"
1013    MPICH_THREAD_LEVEL=MPI_THREAD_MULTIPLE
1014    case "$thread_impl" in
1015        global_mutex)
1016        ;;
1017        # global_monitor)
1018        # ;;
1019        *)
1020        AC_MSG_ERROR(["$thread_impl" is not a valid multi-thread implementation for MPICH2])     
1021        ;;
1022    esac
1023    ;;
1024    *)
1025    AC_MSG_ERROR(["$enable_threads" is not a valid value for --enable-threads])     
1026    ;;
1027esac
1028# Check that the requested thread level is available.
1029threadLevelOK=yes
1030if test -z "$MPID_MAX_THREAD_LEVEL" ; then
1031    if test "$MPICH_THREAD_LEVEL" = "MPI_THREAD_MULTIPLE" -o "$MPICH_THREAD_LEVEL" = "MPI_THREAD_SERIALIZED" ; then
1032        threadLevelOK=no
1033    fi
1034else
1035    # Check that MPID_MAX_THREAD_LEVEL is at least as large as the
1036    # selected MPICH_THREAD_LEVEL
1037    case $MPICH_THREAD_LEVEL in
1038        MPI_THREAD_MULTIPLE)
1039        if test "$MPID_MAX_THREAD_LEVEL" != "MPI_THREAD_MULTIPLE" ; then
1040            threadLevelOK=no
1041        fi
1042        ;;
1043        MPI_THREAD_SERIALIZED)
1044        if test "$MPID_MAX_THREAD_LEVEL" != "MPI_THREAD_MULTIPLE" -a \
1045                "$MPID_MAX_THREAD_LEVEL" != "MPI_THREAD_SERIALIZED" ; then
1046            threadLevelOK=no
1047        fi
1048        ;;
1049        MPI_THREAD_FUNNELED)
1050        if test "$MPID_MAX_THREAD_LEVEL" = "MPI_THREAD_SINGLE" ; then
1051            threadLevelOK=no
1052        fi
1053        ;;
1054        MPI_THREAD_SINGLE)
1055        ;;
1056    esac
1057fi
1058if test "$threadLevelOK" != yes ; then
1059   AC_MSG_ERROR([The device $with_device does not support $MPICH_THREAD_LEVEL])
1060fi
1061
1062export MPICH_THREAD_LEVEL
1063AC_DEFINE_UNQUOTED(MPICH_THREAD_LEVEL,$MPICH_THREAD_LEVEL,[Level of thread support selected at compile time])
1064
1065MPICH_THREAD_IMPL="MPICH_THREAD_IMPL_`echo $thread_impl | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
1066export MPICH_THREAD_IMPL
1067AC_DEFINE_UNQUOTED(USE_THREAD_IMPL,$MPICH_THREAD_IMPL,[Multi-threaded implementation selected at compile time])
1068
1069if test "$thread_pkg_required" = "no" ; then
1070    MPE_THREAD_DEFAULT=${MPE_THREAD_DEFAULT:-none}
1071fi
1072export MPE_THREAD_DEFAULT
1073
1074# Check for value thread_cs choice; set the refcount default if necessary
1075thread_granularity=0
1076thread_refcount=0
1077if test "$enable_threads" = "multiple" ; then
1078    case $enable_thread_cs in
1079    global)
1080    thread_granularity=MPIU_THREAD_GRANULARITY_GLOBAL
1081    if test "$enable_refcount" = "default" ; then enable_refcount=none ; fi
1082    ;;
1083    brief-global|brief_global)
1084    thread_granularity=MPIU_THREAD_GRANULARITY_BRIEF_GLOBAL
1085    if test "$enable_refcount" = "default" ; then enable_refcount=lock ; fi
1086    ;;
1087    per-object|per_object)
1088    thread_granularity=MPIU_THREAD_GRANULARITY_PER_OBJECT
1089    if test "$enable_refcount" = "default" ; then enable_refcount=lock ; fi
1090    ;;
1091    lock-free|lock_free|lockfree)
1092    thread_granularity=MPIU_THREAD_GRANULARITY_LOCK_FREE
1093    if test "$enable_refcount" = "default" ; then enable_refcount=lock-free ; fi
1094    ;;
1095    *)
1096    AC_MSG_ERROR([Unrecognized value $enable_thread_cs for --enable-thread-cs])
1097    ;;
1098    esac
1099
1100    case $enable_refcount in
1101    lock)
1102    thread_refcount=MPIU_REFCOUNT_LOCK
1103    ;;
1104    lock-free|lock_free|lockfree)
1105    thread_refcount=MPIU_REFCOUNT_LOCKFREE
1106    ;;
1107    none)
1108    thread_refcount=MPIU_REFCOUNT_NONE
1109    ;;
1110    *)
1111    AC_MSG_ERROR([Unrecognized value $enable_refcount for --enable-refcount])
1112    ;;
1113    esac
1114fi
1115AC_DEFINE_UNQUOTED([MPIU_THREAD_GRANULARITY],$thread_granularity,[Method used to implement atomic updates and access])
1116
1117case $enable_handle_allocation in
1118    mutex|default)
1119        handle_allocation_method=MPIU_HANDLE_ALLOCATION_MUTEX
1120    ;;
1121    tls)
1122        handle_allocation_method=MPIU_HANDLE_ALLOCATION_THREAD_LOCAL
1123    ;;
1124    *)
1125        AC_MSG_ERROR([Unrecognized value $enable_handle_allocation for --enable-handle-allocation])
1126    ;;
1127esac
1128AC_DEFINE_UNQUOTED([MPIU_HANDLE_ALLOCATION_METHOD],$handle_allocation_method,[Method used to allocate MPI object handles])
1129
1130
1131AC_DEFINE_UNQUOTED([MPIU_THREAD_REFCOUNT],$thread_refcount,[Method used to implement refcount updates])
1132
1133# enable-g
1134# strip off multiple options, separated by commas
1135save_IFS="$IFS"
1136IFS=","
1137for option in $enable_g ; do
1138    case "$option" in
1139        debug|dbg)
1140        enable_append_g=yes
1141        ;;
1142        no|none)
1143        ;;
1144        handlealloc)
1145        perform_handlealloc=yes
1146        ;;
1147        handle)
1148        AC_DEFINE(MPICH_DEBUG_HANDLES,1,[Define to enable handle checking])
1149        ;;
1150        meminit)
1151        perform_meminit=yes
1152        ;;
1153        memarena)
1154        perform_memarena=yes
1155        perform_memtracing=yes
1156        ;;
1157        nesting)
1158        perform_nesttesting=yes
1159        ;;     
1160        fine-grain-nesting|fg-nesting)
1161        perform_fg_nesttesting=yes
1162        ;;     
1163        mem)
1164        perform_memtracing=yes
1165        ;;
1166        log)
1167        perform_dbglog=yes
1168        ;;
1169        mutex)
1170        perform_dbgmutex=yes
1171        ;;
1172        mutexnesting)
1173        perform_mutexnesting=yes
1174        ;;
1175        all|yes)
1176        perform_memtracing=yes
1177        perform_nesttesting=yes
1178        perform_dbglog=yes
1179        enable_append_g=yes
1180        perform_meminit=yes
1181        perform_dbgmutex=yes
1182        perform_mutexnesting=yes
1183        perform_handlealloc=yes
1184        ;;
1185        *)
1186        AC_MSG_WARN([Unknown value $enable_g for enable-g])
1187        ;;
1188    esac
1189done
1190IFS="$save_IFS"
1191
1192# MPICH2_EXTRA_xFLAGS contains MPICH2LIB_xFLAGS and
1193# all the extra compiler flags added by MPICH2.
1194# Initial all MPICH2_EXTRA_xFLAGS to empty string.
1195MPICH2_EXTRA_CFLAGS=""
1196MPICH2_EXTRA_CXXFLAGS=""
1197MPICH2_EXTRA_FFLAGS=""
1198MPICH2_EXTRA_F90FLAGS=""
1199
1200if test "$enable_append_g" = "yes" ; then
1201    CFLAGS="$CFLAGS -g"
1202    CXXFLAGS="$CXXFLAGS -g"
1203    FFLAGS="$FFLAGS -g"
1204    F90FLAGS="$F90FLAGS -g"
1205    MPICH2_EXTRA_CFLAGS="$MPICH2_EXTRA_CFLAGS -g"
1206    MPICH2_EXTRA_CXXFLAGS="$MPICH2_EXTRA_CXXFLAGS -g"
1207    MPICH2_EXTRA_FFLAGS="$MPICH2_EXTRA_FFLAGS -g"
1208    MPICH2_EXTRA_F90FLAGS="$MPICH2_EXTRA_F90FLAGS -g"
1209fi
1210if test "$enable_append_ndebug" = "yes" ; then
1211    CFLAGS="$CFLAGS -DNDEBUG"
1212    CXXFLAGS="$CXXFLAGS -DNDEBUG"
1213    FFLAGS="$FFLAGS -DNDEBUG"
1214    F90FLAGS="$F90FLAGS -DNDEBUG"
1215    MPICH2_EXTRA_CFLAGS="$MPICH2_EXTRA_CFLAGS -DNDEBUG"
1216    MPICH2_EXTRA_CXXFLAGS="$MPICH2_EXTRA_CXXFLAGS -DNDEBUG"
1217    MPICH2_EXTRA_FFLAGS="$MPICH2_EXTRA_FFLAGS -DNDEBUG"
1218    MPICH2_EXTRA_F90FLAGS="$MPICH2_EXTRA_F90FLAGS -DNDEBUG"
1219fi
1220if test -n "$perform_meminit" ; then
1221    AC_DEFINE(MPICH_DEBUG_MEMINIT,1,[Define to enable preinitialization of memory used by structures and unions])
1222fi
1223if test "$perform_handlealloc" = yes ; then
1224   AC_DEFINE(MPICH_DEBUG_HANDLEALLOC,1,[Define to enable checking of handles still allocated at MPI_Finalize])
1225fi
1226
1227if test -n "$perform_memtracing" ; then
1228    enable_g_mem=yes
1229    AC_DEFINE(USE_MEMORY_TRACING,1,[Define to enable memory tracing])
1230    if test -n "$perform_memarena" ; then
1231        AC_DEFINE(MPICH_DEBUG_MEMARENA,1,[Define if each function exit should confirm memory arena correctness])
1232    fi
1233fi
1234if test -n "$perform_nesttesting" ; then
1235    AC_DEFINE(MPICH_DEBUG_NESTING,1,[Define to check nesting level on exit])
1236fi
1237if test -n "$perform_mutexnesting" ; then
1238    AC_DEFINE(MPICH_DEBUG_MUTEXNESTING,1,[Define to check nesting in mutexes])
1239fi
1240if test -n "$perform_fg_nesttesting" ; then
1241    AC_DEFINE(MPICH_DEBUG_FINE_GRAIN_NESTING,1,[Define to perform a fine-grain nesting level check on exit])
1242fi
1243if test -n "$perform_dbglog" ; then
1244   if test "$with_logging" != "none" ; then
1245       AC_MSG_WARN([--with-logging overrides --enable-g=log])
1246   else
1247       AC_DEFINE(USE_DBG_LOGGING,1,[Define to enable logging macros])
1248   fi
1249fi
1250
1251if test -n "$perform_dbgmutex" ; then
1252   AC_DEFINE(MPICH_DEBUG_MUTEX,1,[Define to enable mutex debugging])
1253fi
1254
1255pac_cross_compiling=no
1256if test "$with_cross" != "no" ; then
1257    if test -s "$with_cross" ; then
1258        AC_MSG_RESULT([Reading values from cross-compilation file $with_cross])
1259        . $with_cross
1260        # Autoconf 2.52 no longer sets cross_compiling except with the
1261        # awkward "targethost" options.
1262        pac_cross_compiling=yes
1263        cross_compiling=yes
1264        ac_cv_prog_cc_cross=yes
1265        ac_cv_prog_f77_cross=yes
1266        ac_cv_prog_f90_cross=yes
1267        ac_cv_prog_cxx_cross=yes
1268        export cross_compiling
1269        # Export all cross variables.  Any subsidiary configure should also
1270        # export CROSS_xxx
1271        rm -f confcross
1272        (set) 2>&1 | grep CROSS_ | \
1273              sed -e 's/^/export /g' -e 's/=.*//g' > confcross
1274        . confcross
1275        rm -f confcross     
1276    fi
1277fi
1278
1279if test "$enable_nmpi_as_mpi" = yes ; then
1280   AC_DEFINE(USE_MPI_FOR_NMPI,1,[Define if the NMPI names should use MPI instead of PMPI])
1281fi
1282
1283# This goes here because we need the top_srcdir
1284FROM_MPICH2=yes
1285export FROM_MPICH2
1286if test "$enable_romio" = "yes" ; then
1287   if test -d $use_top_srcdir/src/mpi/romio ; then
1288       subsystems="$subsystems src/mpi/romio"
1289       AC_DEFINE(HAVE_ROMIO,1,[Define if ROMIO is enabled])
1290       # Set environment variables that the romio configure expects
1291       romio_dir=romio
1292       AC_SUBST(romio_dir)
1293       export use_top_srcdir
1294       top_build_dir=`pwd`
1295       export top_build_dir
1296       # if there is no $top_build_dir/lib, romio puts lib in wrong place
1297       # This test used -e under Linux, but not all test programs understand
1298       # -e
1299       if test ! -d lib ; then mkdir lib ; fi
1300       # tell mpi.h to include mpio.h
1301       PAC_HAVE_ROMIO
1302   else
1303       AC_MSG_WARN([ROMIO src directory is not available])
1304   fi
1305fi
1306#
1307# FIXME: If an external device, don't necessarily complain (e.g.,
1308# if the device is already built)
1309if test ! -d $devicedir ; then
1310dnl     WAIT UNTIL WE INCLUDE A DEVICE
1311dnl     AC_MSG_ERROR([Device $device_name is unknown)]
1312    AC_MSG_WARN([Device $device_name is unknown])
1313elif test ! -x $devicedir/configure ; then
1314    if test -s $devicedir/configure ; then
1315        AC_MSG_WARN([The configure in $devicedir exists but is not executable])
1316    else
1317        AC_MSG_WARN([Device $device_name has no configure])
1318    fi
1319    device_name=""
1320else
1321    # Add the device to the configure list
1322    devsubsystems="$devsubsystems $devicereldir"
1323    # Make device_name available to subdirs
1324fi
1325#
1326# Allow the device to request that the install step invoke the install
1327# target in the device's Makefile.
1328if test -n "$device_name" -a "$INSTALL_FROM_DEVICE" = yes ; then
1329    other_install_dirs="${other_install_dirs} $devicereldir"
1330fi
1331AC_SUBST(device_name)
1332#
1333# with-pm
1334if test "$MPID_NO_PM" = yes ; then
1335    if test "$with_pm" != "default" -a "$with_pm" != no ; then
1336        AC_MSG_ERROR([The PM chosen ($with_pm) is is not valid for the selected device ($with_device)])
1337    fi
1338    # This is used to change with_pm=default to with_pm=no in the case
1339    # where the device does not want a PM
1340    with_pm=no
1341fi
1342if test -z "$with_pm" ; then
1343    with_pm="no"
1344fi
1345if test "$with_pmi" = "uni" -a "$with_pm" = "default" ; then
1346    with_pm="no"
1347fi
1348if test "$with_pm" = "default" -o "$with_pm" = "yes" ; then
1349    with_pm=mpd,hydra,gforker
1350fi
1351
1352# We allow multiple pm names, separated by : or ,
1353# If multiple PMs are provided, we set the value MANY_PM to yes
1354MANY_PM=no
1355AC_SUBST(MANY_PM)
1356if test "$with_pm" != "no" ; then
1357    pm_names="`echo $with_pm | sed -e 's/:/ /g' -e 's/,/ /g'`"
1358else
1359    pm_names=""
1360fi
1361#
1362hasError=no
1363# We need to be careful about PM's that have either conflicting
1364# requirements (e.g., different PMI implementations) or different
1365# optional features (e.g., MPID_PM_NAMESERVER).
1366# In addition, we need to interleave the setup of the PMI and PM
1367# modules.  The order is as follows:
1368#
1369# For each PM, execute the mpich2prereq script for that pm (if present). 
1370# This script provides information about the PM, including which PMI
1371# implementations are supported.
1372#
1373# Then, for the selected PMI, the setup script (if any) is run.  This is
1374# necessary because the setup of the PM may require information discovered
1375# or provided duing the PMI setup step (e.g., smpd requires this)
1376#
1377# Finally, for each PM, the setup script is executed.
1378#
1379# Step 1: invoke the mpich2prereq for each PM
1380for pm_name in $pm_names ; do
1381    if test -z "$first_pm_name" ; then
1382       first_pm_name=$pm_name
1383    else
1384       # Only add to other_pm_names if the directory exists,
1385       # since the Makefile in src/pm/Makefile will try to cd to
1386       # that directory
1387       if test -d $use_top_srcdir/src/pm/$pm_name ; then
1388           other_pm_names="$other_pm_names $pm_name"
1389       fi
1390    fi
1391    if test ! -d $use_top_srcdir/src/pm/$pm_name ; then
1392        AC_MSG_WARN([$use_top_srcdir/src/pm/$pm_name does not exist. PM is unknown])
1393        hasError=yes
1394    elif test ! -x $use_top_srcdir/src/pm/$pm_name/configure ; then
1395        if test -s $use_top_srcdir/src/pm/$pm_name/configure ; then
1396            AC_MSG_WARN([The configure in $use_top_srcdir/src/pm/$pm_name exists but is not executable])
1397        else
1398            AC_MSG_WARN([pm $pm_name has no configure])
1399        fi
1400        pm_name=""
1401        hasError=yes
1402    else
1403        nameserver=$MPID_PM_NAMESERVER
1404        if test -f $use_top_srcdir/src/pm/$pm_name/mpich2prereq ; then
1405            echo sourcing $use_top_srcdir/src/pm/$pm_name/mpich2prereq
1406            . $use_top_srcdir/src/pm/$pm_name/mpich2prereq
1407        fi
1408        # Check for a change; if found, we'll take the default
1409        if test "$MPID_PM_NAMESERVER" != "$nameserver" ; then
1410            if test "$first_pm_name" != "$pm_name" ; then
1411                # Reject suggestion (use the default, common mode)
1412                MPID_PM_NAMESERVER=""
1413            fi
1414        fi
1415    fi
1416done
1417if test "$hasError" != no ; then
1418    AC_MSG_ERROR([Aborting configure because an error was seen in the selection of process managers])
1419fi
1420#
1421# pm_name is the *primary* pm
1422pm_name=$first_pm_name
1423AC_SUBST(pm_name)
1424AC_SUBST(other_pm_names)
1425
1426# Some versions of PM and PMI require a special definition (currently, only
1427# smpd requires this)
1428if test "$PMI_REQUIRES_READABLE_TOKENS" = "yes" ; then
1429    AC_DEFINE(USE_HUMAN_READABLE_TOKENS,1,[Define to use ='s and spaces in the string utilities.])
1430fi
1431
1432if test -n "$first_pm_name" ; then
1433    other_install_dirs="${other_install_dirs} src/pm/$first_pm_name"
1434fi
1435# Step 2:
1436# Once we've selected the process manager (or managers), we can
1437# check that we have a compatible PMI implemenatation.
1438# with-pmi
1439if test "$MPID_NO_PMI" = yes ; then
1440    if test "$with_pmi" != "default" -a "$with_pmi" != no ; then
1441        AC_MSG_ERROR([The PMI chosen ($with_pmi) is is not valid for the selected device ($with_device)])
1442    fi
1443    # This is used to change with_pmi=default to with_pmi=no in the case
1444    # where the device does not want a PMI
1445    with_pmi=no
1446elif test "$with_pmi" != "no" ; then
1447    if test "$with_pmi" = "default" -o "$with_pmi" = "yes" ; then
1448        if test -n "$PM_REQUIRES_PMI" ; then
1449            with_pmi=$PM_REQUIRES_PMI
1450        else
1451            with_pmi=simple
1452        fi
1453    elif test -n "$PM_REQUIRES_PMI" ; then
1454        # Test for compatibility between pm and pmi choices
1455        if test "$PM_REQUIRES_PMI" != "$with_pmi" ; then
1456            AC_MSG_ERROR([The PM chosen ($with_pm) requires the PMI implementation $PM_REQUIRES_PMI but $with_pmi was selected as the PMI implementation.])
1457        fi
1458    fi
1459    pmi_name=$with_pmi
1460   
1461    if test ! -d $use_top_srcdir/src/pmi/$pmi_name ; then
1462        AC_MSG_WARN([$use_top_srcdir/src/pmi/$pmi_name does not exist. PMI is unknown])
1463    elif test ! -x $use_top_srcdir/src/pmi/$pmi_name/configure ; then
1464        AC_MSG_WARN([pmi $pmi_name has no configure or Makefile])
1465        pmi_name=""
1466    else
1467        subsystems="$subsystems src/pmi/$pmi_name"
1468    fi
1469else
1470    AC_MSG_ERROR([A PMI implementation must be selected or the default used.])
1471fi
1472AC_SUBST(pmi_name)
1473
1474# Step 3: complete pm setup.
1475# Note that checks for errors have already been performed, so this
1476# loop does not need to perform any extra error checks.
1477# Note that this uses this_pm_name because pm_name must be the *first*
1478# of the PM names
1479for this_pm_name in $pm_names ; do
1480    subsystems="$subsystems src/pm/$this_pm_name"
1481    if test -f $use_top_srcdir/src/pm/$this_pm_name/setup_pm ; then
1482        echo sourcing $use_top_srcdir/src/pm/$this_pm_name/setup_pm
1483        . $use_top_srcdir/src/pm/$this_pm_name/setup_pm
1484    fi
1485done
1486
1487# ----------------------------------------------------------------------------
1488if test $with_mpe != no ; then
1489    if test ! -d $use_top_srcdir/src/mpe2 ; then
1490        if test $with_mpe = yes ; then
1491            # No warning message on the default
1492            AC_MSG_WARN([No MPE directory available])
1493        fi
1494    elif test ! -x $use_top_srcdir/src/mpe2/configure ; then
1495        if test $with_mpe = yes ; then
1496            # No warning message on the default
1497            AC_MSG_WARN([No configure available for MPE])
1498        fi
1499    else
1500        subsystems="$subsystems src/mpe2"
1501        other_install_dirs="$other_install_dirs src/mpe2"
1502        mpe_dir=mpe2
1503        # Make sure that MPE knows that we're building from MPICH
1504        # (similar to ROMIO)
1505        FROM_MPICH2=yes
1506        export FROM_MPICH2
1507        # Temporarily replace the default NONE value for exec_prefix
1508        # and prefix with the actual, default values.
1509        savePrefix=$prefix
1510        saveExecprefix=$exec_prefix
1511        test "x$prefix" = xNONE && prefix=$ac_default_prefix
1512        test "x$exec_prefix" = xNONE && exec_prefix=$prefix
1513        eval actualbindir=$bindir
1514        # MPI_CC and MPIF77 must use the local (build) bin dir, not
1515        # the installation bin dir
1516        #MPI_CC=$actualbindir/mpicc
1517        #MPI_F77=$actualbindir/mpif77
1518        #eval actuallibdir=$libdir
1519        #MPI_LIBS="-L$actuallibdir -lmpich -lpmpich"
1520        buildbindir=`pwd`/bin
1521        MPI_CC=$buildbindir/mpicc
1522        MPI_F77=$buildbindir/mpif77
1523        prefix=$savePrefix
1524        exec_prefix=$saveExecprefix
1525        # NOTE: You must append LIBS to MPI_LIBS before invoking the mpe
1526        # configure
1527        export MPI_CC
1528        export MPI_F77
1529        #export MPI_LIBS
1530        export use_top_srcdir
1531        top_build_dir=`pwd`
1532        export top_build_dir
1533    fi
1534fi
1535AC_SUBST(mpe_dir)
1536AC_SUBST(other_install_dirs)
1537
1538dnl
1539dnl The recommended order for items in a configure.in file is
1540dnl     check for programs
1541dnl     check for libraries
1542dnl     check for header files
1543dnl     check for typedefs
1544dnl     check for structures
1545dnl     check for compiler characteristics
1546dnl     check for library functions
1547dnl     check for system services
1548dnl
1549dnl We actually check for compilers first, then roughly follow this order,
1550dnl though logical subsystems (like Fortran support) my use this order
1551dnl within their part of the configure.
1552dnl
1553#
1554#
1555# Find a C compiler (choose gcc first).
1556# We also need to do this before the F77 and F90 test to ensure that we
1557# find the C preprocessor reliably.
1558saveCFLAGS=$CFLAGS
1559AC_PROG_CC
1560AC_PROG_CPP
1561# Bug in autoconf.  Restore cross settings
1562if test "$pac_cross_compiling" = "yes" -a "$ac_cv_prog_cc_cross" = "no" ; then
1563    AC_MSG_RESULT([Resetting cross compilation to yes])
1564    cross_compiling=yes
1565    ac_cv_prog_cc_cross=yes
1566    ac_cv_prog_f77_cross=yes
1567    ac_cv_prog_f90_cross=yes
1568    ac_cv_prog_cxx_cross=yes
1569fi
1570# Misfeature in autoconf.  When using gcc, PROG_CC insists on setting
1571# CFLAGS to -g -O2 if CFLAGS is not set.  This may be appropriate for
1572# many tools built with configure and gcc, but not always.  In particular,
1573# there seems to be no way to get gcc to use no extra flags if that is desired.
1574if test -z "$saveCFLAGS" -a -n "$CFLAGS" ; then
1575    # restore CFLAGS
1576    # Note: This may not be correct if PROG_CC decided to add other
1577    # flags to CFLAGS to enforce some behavior (such as ANSI/ISO C),
1578    # But we haven't seen that in practice.  It would be better
1579    # if the CFLAGS were decomposed into flags-that-change-the-language
1580    # that the compiler accepts from optimizations
1581    CFLAGS=$saveCFLAGS
1582fi
1583
1584# Check whether shared libraries are enabled.  We need to know this
1585# before we start chosing the Fortran, Fortran 90, and C++ compilers
1586ENABLE_SHLIB=$enable_sharedlibs
1587if test -z "$ENABLE_SHLIB" -o "$ENABLE_SHLIB" = "no" ; then
1588    ENABLE_SHLIB=none
1589    # Also turn off the libtool tests
1590    enable_shared=no
1591fi
1592# We need the script that is used to create shared libraries if either
1593# we are creating shared libraries for MPICH2 or we are creating the
1594# dynamically loadable library for the debugger interface
1595CREATESHLIB=false
1596if test "$ENABLE_SHLIB" != "none" -o "$enable_debuginfo" != "no" ; then
1597   CREATESHLIB=`pwd`/src/util/createshlib
1598fi
1599AC_SUBST(CREATESHLIB)
1600# ---------------------------------------------------------------------------
1601# Basic properties of the C compiler; some are needed for the language
1602# bindings tests.
1603# Set CFLAGS for enable strict if necessary.  Do this *first* because
1604# it may influence the output of the other tests
1605AC_ARG_ENABLE(strict,[--enable-strict - Turn on strict debugging with gcc],,enable_strict=no)
1606PAC_CC_STRICT($enable_strict)
1607if test -n "$pac_cc_strict_flags" ; then
1608    MPICH2_EXTRA_CFLAGS="$MPICH2_EXTRA_CFLAGS $pac_cc_strict_flags"
1609fi
1610# Check for whether the compiler defines a symbol that contains the
1611# function name.  The MPICH2 code, for greater portability, defines
1612# its own symbols, FCNAME (a string) and FUNCNAME (a token that is not a
1613# string).  Code should use these symbols where possible.  However,
1614# some debugging macros may want to use a compiler-provided symbol
1615# for the function name, and this check makes it possible to
1616# define such macros in a way that is always correct.
1617PAC_CC_FUNCTION_NAME_SYMBOL
1618
1619# Check if $MPI_DEFAULT_COPTS is valid with $CC
1620if test "$enable_default_optimize" = "yes" \
1621     -a -n "$MPI_DEFAULT_COPTS" ; then
1622    if test "$enable_check_compiler_flags" = "yes" ; then
1623        PAC_C_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_COPTS], [
1624        CFLAGS="$CFLAGS $MPI_DEFAULT_COPTS"
1625        MPICH2_EXTRA_CFLAGS="$MPICH2_EXTRA_CFLAGS $MPI_DEFAULT_COPTS"
1626                                   ] )
1627    else
1628        CFLAGS="$CFLAGS $MPI_DEFAULT_COPTS"
1629        MPICH2_EXTRA_CFLAGS="$MPICH2_EXTRA_CFLAGS $MPI_DEFAULT_COPTS"
1630    fi
1631fi
1632# Up till here, MPICH2_EXTRA_CFLAGS contains only flags added by MPICH2.
1633# Check with "grep -n MPICH2_EXTRA_CFLAGS configure.in"
1634# Remove duplicated flags from MPICH2_EXTRA_CFLAGS.
1635PAC_MAKE_UNIQ_STRING([MPICH2_EXTRA_CFLAGS])
1636# Check if $MPICH2LIB_CFLAGS is valid with $CC
1637if test -n "$MPICH2LIB_CFLAGS" ; then
1638    if test "$enable_check_compiler_flags" = "yes" ; then
1639        PAC_C_CHECK_COMPILER_OPTION( [$MPICH2LIB_CFLAGS], [
1640        CFLAGS="$CFLAGS $MPICH2LIB_CFLAGS"
1641        MPICH2_EXTRA_CFLAGS="$MPICH2_EXTRA_CFLAGS $MPICH2LIB_CFLAGS"
1642                                   ] )
1643    else
1644        CFLAGS="$CFLAGS $MPICH2LIB_CFLAGS"
1645        MPICH2_EXTRA_CFLAGS="$MPICH2_EXTRA_CFLAGS $MPICH2LIB_CFLAGS"
1646    fi
1647fi
1648
1649# Check for support for weak symbols.  If not found, set NO_WEAK_SYM
1650# to the Make target name understood by simplemake.
1651# Set NEEDSPLIB to yes if link commands need both -l$MPILIBNAME
1652# and -lp$MPILIBNAME.
1653NEEDSPLIB=yes
1654NO_WEAK_SYM_TARGET=build_proflib
1655if test $enable_weak_symbols = yes ; then
1656    # Turn off weak symbols if they aren't available
1657    PAC_PROG_C_WEAK_SYMBOLS(,enable_weak_symbols=no)
1658fi
1659if test $enable_weak_symbols = "yes" ; then
1660    AC_DEFINE(USE_WEAK_SYMBOLS,1,[Define if weak symbols should be used])
1661    NEEDSPLIB=no
1662    # Check for the ability to support multiple weak symbols
1663    if test "$pac_cv_prog_c_weak_symbols" = "pragma weak" ; then
1664       PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS(AC_DEFINE(HAVE_MULTIPLE_PRAGMA_WEAK,1,[Define if multiple weak symbols may be defined]))
1665    fi
1666else
1667    NO_WEAK_SYM=build_proflib
1668    PROFILE_DEF_MPI="-DMPICH_MPI_FROM_PMPI"
1669fi
1670export NEEDSPLIB
1671export NO_WEAK_SYM
1672export NO_WEAK_SYM_TARGET
1673export PROFILE_DEF_MPI
1674AC_SUBST(NEEDSPLIB)
1675AC_SUBST(NO_WEAK_SYM)
1676AC_SUBST(NO_WEAK_SYM_TARGET)
1677AC_SUBST(PROFILE_DEF_MPI)
1678
1679# ---------------------------------------------------------------------------
1680# Support for the language bindings: Fortran 77, Fortran 90, and C++
1681#
1682# First, we handle the case of no explicit enable/disable option.  In that
1683# case, we look for a usable compiler.  We cannot use the ac macros for this
1684# because they abort the configure step if they fail to find a compiler
1685# (earlier versions of autoconf did not have this behavior!).
1686#
1687# Second, we perform the langugage-specific tests, if necessary.  This may
1688# be relatively simple (C++) or complex (Fortran 77, including formation of
1689# the encoded MPI handles).
1690#
1691# Note that the bindings support needs to know some of the properties of
1692# the C compiler, so those tests (particularly for weak symbols)
1693# must come first.
1694# ----------------------------------------------------------------------------
1695
1696#
1697# First, determine whether we are/can support the language bindings
1698#
1699# Handle the case that the user set FC but not F77 before we run the
1700# PROG_F77 command
1701if test -n "$F77" -a -n "$FC" -a "$F77" != "$FC" ; then
1702    AC_MSG_ERROR([The values of the environment variables F77 (=$F77) and FC (=$FC) are not the same.  Unset one or both and rerun configure])
1703fi
1704if test -z "$F77" -a -n "$FC" ; then F77="$FC" ; fi
1705if test -z "$FC" -a -n "$F77" ; then FC="$F77" ; fi
1706# ----------------------------------------------------------------------------
1707# Handle default choices for the Fortran compilers
1708if test "$enable_f77" = "default" ; then
1709    enable_f77=no
1710    # Check for a Fortran compiler
1711    # Warning: the PROG_F77 command aborts if it fails to
1712    # find a compiler.  We should first try to find a compiler, then
1713    # check to see if it works (which the PROG_F77 command does as well)
1714    # It also prefers g77 to f77, and doesn't know about other compilers
1715    # Also handle the bug that autoconf sets FFLAGS for you
1716    saveFFLAGS=$FFLAGS
1717    AC_PROG_F77
1718    FFLAGS=$saveFFLAGS
1719    if test -n "$F77" ; then
1720        enable_f77_wasdefault=yes
1721        enable_f77=yes
1722    fi
1723elif test "$enable_f77" = "yes" ; then
1724    saveFFLAGS=$FFLAGS
1725    AC_PROG_F77
1726    FFLAGS=$saveFFLAGS
1727fi
1728
1729if test "$enable_f77" = yes ; then
1730    # Check if $MPI_DEFAULT_FOPTS is valid with $F77
1731    if test "$enable_default_optimize" = "yes" \
1732         -a -n "$MPI_DEFAULT_FOPTS" ; then
1733        if test "$enable_check_compiler_flags" = "yes" ; then
1734            PAC_F77_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_FOPTS], [
1735            FFLAGS="$FFLAGS $MPI_DEFAULT_FOPTS"
1736            MPICH2_EXTRA_FFLAGS="$MPICH2_EXTRA_FFLAGS $MPI_DEFAULT_FOPTS"
1737                                         ] )
1738        else
1739            FFLAGS="$FFLAGS $MPI_DEFAULT_FOPTS"
1740            MPICH2_EXTRA_FFLAGS="$MPICH2_EXTRA_FFLAGS $MPI_DEFAULT_FOPTS"
1741        fi
1742    fi
1743    # Up till here, MPICH2_EXTRA_FFLAGS contains only flags added by MPICH2.
1744    # Check with "grep -n MPICH2_EXTRA_FFLAGS configure.in"
1745    # Remove duplicated flags from MPICH2_EXTRA_FFLAGS.
1746    PAC_MAKE_UNIQ_STRING([MPICH2_EXTRA_FFLAGS])
1747    # Check if $MPICH2LIB_FFLAGS is valid with $F77
1748    if test -n "$MPICH2LIB_FFLAGS" ; then
1749        if test "$enable_check_compiler_flags" = "yes" ; then
1750            PAC_F77_CHECK_COMPILER_OPTION( [$MPICH2LIB_FFLAGS], [
1751            FFLAGS="$FFLAGS $MPICH2LIB_FFLAGS"
1752            MPICH2_EXTRA_FFLAGS="$MPICH2_EXTRA_FFLAGS $MPICH2LIB_FFLAGS"
1753                                         ] )
1754        else
1755            FFLAGS="$FFLAGS $MPICH2LIB_FFLAGS"
1756            MPICH2_EXTRA_FFLAGS="$MPICH2_EXTRA_FFLAGS $MPICH2LIB_FFLAGS"
1757        fi
1758    fi
1759fi
1760
1761#
1762# We need to know the name mangling for Fortran before testing for F90
1763# compatibility (we need this because of the way we decide to generate
1764# the Fortran 77 bindings)
1765if test "$enable_f77" = yes ; then
1766    FLIBS_save="$FLIBS"
1767    FLIBS=""
1768    AC_F77_LIBRARY_LDFLAGS
1769    # The autoconf macro for finding FLIBS sometimes makes mistakes
1770    # (particularly with the Fujitsu frt compiler).  This next step
1771    # first sees if the FLIBS is valid with the Fortran compiler
1772    PAC_PROG_F77_FLIBS_VALID
1773    # Now see if FLIBS works with the C compiler
1774    PAC_PROG_F77_CHECK_FLIBS
1775
1776    PAC_PROG_F77_LINKER_WITH_C
1777    PAC_PROG_F77_OBJ_LINKS_WITH_C
1778    # For name mangle, we need the library flags
1779    PAC_PROG_F77_NAME_MANGLE
1780    # Check whether additional libraries are needed when linking with C
1781    PAC_PROG_F77_AND_C_STDIO_LIBS
1782    AC_SUBST(F77_OTHER_LIBS)
1783
1784    # Warn about mixed name mangling, since many of the tests will fail
1785    if test "$pac_cv_prog_f77_name_mangle" = "mixed" ; then
1786        AC_MSG_WARN([The compiler $F77 uses mixed case names.  Fortran is monocase
1787and many Fortran programs may use either upper or lower case names for MPI
1788calls.  Consider specifying a particular parameter to your Fortran compiler
1789to select either upper or lower case names.  For the Absoft compiler,
1790-f selects lower case and -N109 selects upper case (if you use -f, also use
1791-B108 to enable the iargc and getarg routines, which are needed for some
1792tests and by many user programs).  Specify new command
1793line options by setting the environment variable FFLAGS to include
1794the options (e.g., setenv FFLAGS "-f -B108").  In addition, make sure that your
1795Fortran 90 compiler uses a compatible naming choice.  For the
1796Absoft Fortran 90, -YALL_NAMES=LCS selects lower case names and -B108
1797adds underscores to names, as required for iargc and getarg.  Pass this
1798information to configure with the F90FLAGS environment variable.])
1799        # If Fortran implicitly enabled, disable it now.  Otherwise,
1800        # abort the configure since warning messages are often lost in
1801        # the output.
1802        if test "$enable_f77_wasdefault" = yes ; then
1803            AC_MSG_WARN([Turning off Fortran support because of mixed case names])
1804            enable_f77=no
1805            enable_f90=no
1806        else
1807            AC_MSG_ERROR([Aborting configure because of mixed case names in Fortran.  Either select --disable-f77 or set FFLAGS to force the compiler to select monocase names])
1808        fi
1809    fi
1810
1811    # The MPI standard requires that MPI_Init in any language initialize
1812    # MPI in all languages.  This can be a problem when objects produced
1813    # by the Fortran compiler require symbols from the Fortran runtime
1814    # (making linking C-only programs unnecessarily difficult).  What we test
1815    # here is whether the much more restricted needs of the Fortran
1816    # initialize can be met with no special use of the Fortran runtime
1817    pac_f_init_works_with_c=unknown
1818    AC_MSG_CHECKING([whether Fortran init will work with C])
1819    rm -f conftest*
1820    cat > conftestc.c <<EOF
1821#include <stdio.h>
1822#include "confdefs.h"
1823#ifdef F77_NAME_UPPER
1824#define minit_ MINIT
1825#elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
1826#define minit_ minit
1827#endif
1828int main( int argc, char *argv )
1829{
1830    minit_();
1831    return 0;
1832}
1833char *v1 = 0;
1834char *vc2 = 0;
1835int  v2 = 0;
1836minitc_( char *dv1, int d, char *dv2, int d2, int dv3 )
1837{
1838v1 = dv1;
1839v2 = dv3;
1840vc2 = dv2;
1841*vc2 = ' ';
1842}
1843EOF
1844    cat > conftestf.f <<EOF
1845       subroutine minit()
1846       common /m1/ vc, vc2
1847       character *1 vc(1,1), vc2(1)
1848       common /m2/ vd
1849       integer vd
1850       save /m1/, /m2/
1851       call minitc( vc, vc2, vd )
1852       end
1853EOF
1854   myfcompile='${F77-f77} -c $FFLAGS conftestf.f 1>&AC_FD_CC'
1855   myccompile='${CC-cc} -c $CFLAGS conftestc.c 1>&AC_FD_CC'
1856   if AC_TRY_EVAL(myfcompile) && test -s conftestf.o ; then
1857       :
1858   else
1859        echo "configure: failed program was:" >&AC_FD_CC
1860        cat conftestf.f >&AC_FD_CC
1861   fi
1862   if AC_TRY_EVAL(myccompile) && test -s conftestc.o ; then
1863       :
1864   else
1865        echo "configure: failed program was:" >&AC_FD_CC
1866        cat conftestc.c >&AC_FD_CC
1867   fi
1868   # Now try the link step
1869   myclink='${CC-cc} $CFLAGS -o conftest conftestc.o conftestf.o $LDFLAGS >conftest.out 2>&1'
1870   if AC_TRY_EVAL(myclink) && test -x conftest${ac_exeext} ; then
1871      pac_f_init_works_with_c=yes
1872   else
1873      pac_f_init_works_with_c=no
1874   fi
1875   AC_MSG_RESULT($pac_f_init_works_with_c)
1876   if test "$pac_f_init_works_with_c" = "yes" ; then
1877       AC_DEFINE(HAVE_MPI_F_INIT_WORKS_WITH_C,1,[Define if the Fortran init code for MPI works from C programs without special libraries])
1878   fi
1879fi
1880
1881# F90 requires F77 as well.  If the user disabled f77, do not run the
1882# next test; instead, drop into the warning message
1883# Set a default value for f90 works with f77.  This value is
1884# set to no *only* if f90 was selected but was not compatible with f77
1885f90_with_f77=yes
1886if test "$enable_f90" = "default" -a "$enable_f77" = yes ; then
1887    enable_f90=no
1888    # Check for a Fortran compiler.  Work around bug in autoconf that
1889    # adds -g to F90FLAGS
1890    saveF90FLAGS="$F90FLAGS"
1891    PAC_PROG_F90
1892    F90FLAGS=$saveF90FLAGS
1893    if test -n "$F90" ; then
1894        if test -z "$F77" ; then
1895            saveFFLAGS=$FFLAGS
1896            AC_PROG_F77
1897            FFLAGS=$saveFFLAGS
1898        fi
1899        #
1900        # If we allow multiple weak symbols, we should test a name
1901        # that does not contain an underscore.  The Fortran binding uses
1902        # this rule for enabling multiple weak symbols:
1903        # if defined(USE_WEAK_SYMBOLS) && !defined(USE_ONLY_MPI_NAMES) &&
1904        #    defined(HAVE_MULTIPLE_PRAGMA_WEAK) &&
1905        #    defined(F77_NAME_LOWER_2USCORE)
1906        #
1907        testRoutine="t1_2"
1908        if test "$pac_cv_prog_c_multiple_weak_symbols" = "yes" -a \
1909               "$enable_weak_symbols" = "yes" -a \
1910               "$pac_cv_prog_f77_name_mangle" = "lower doubleunderscore" ; then
1911            testRoutine="t12"
1912        fi
1913        PAC_F90_AND_F77_COMPATIBLE(f90_with_f77=yes,f90_with_f77=no,$testRoutine)
1914        if test "$f90_with_f77" != yes ; then
1915            enable_f90=no
1916            AC_MSG_WARN([The selected Fortran 90 compiler $F90 does not work with the selected Fortran 77 compiler $F77.  Use the environment variables F90 and F77 respectively to select compatible Fortran compilers.  The check here tests to see if a main program compiled with the Fortran 90 compiler can link with a subroutine compiled with the Fortran 77 compiler.])
1917        elif test "$f90_with_f77" = "yes" ; then
1918            # If we got here, there is a Fortran 90 compiler that we can use
1919            enable_f90=yes
1920        fi
1921    elif test "$pac_cv_prog_f90_works" = no; then
1922        AC_MSG_WARN([Use --disable-f90 to keep configure from searching for a Fortran 90 compiler])
1923    fi
1924fi
1925if test "$enable_f90" = "yes" -a "$enable_f77" != "yes" ; then
1926   # Fortran 90 support requires compatible Fortran 77 support
1927   AC_MSG_WARN([Fortran 90 support requires compatible Fortran 77 support.  To force the use of the Fortran 90 compiler for Fortran 77, set the environment variable F77 to the name of the Fortran 90 compiler.])
1928   # We should probably do the compatibility test as well
1929   enable_f77=yes
1930fi
1931
1932# ----------------------------------------------------------------------------
1933# Now test for Fortran compiler characteristics
1934# ----------------------------------------------------------------------------
1935if test "$enable_f77" = "yes" ; then
1936    AC_LANG_FORTRAN77
1937    PAC_PROG_F77_EXCLAIM_COMMENTS(has_exclaim="yes",has_exclaim="no")
1938dnl    The following can be used to check whether len=* or (*) form
1939dnl    should be used for character declarations
1940dnl    PAC_PROG_F77_NEW_CHAR_DECL(CHARDECL="(LEN=*)",CHARDECL="*(*)")
1941dnl    AC_SUBST(CHARDECL)
1942    PAC_PROG_F77_HAS_INCDIR(src)
1943    if test -n "$F77_INCDIR" ; then
1944        # For building the Fortran files, add the directory where we are building
1945        # the object to the include list.  This is needed for g77, which makes
1946        # includes relative to the source directory of the file, not the
1947        # directory that the command is executed in
1948        FINCLUDES="$F77_INCDIR`pwd`/src"
1949    fi
1950    AC_SUBST(FINCLUDES)
1951    #
1952    PAC_PROG_F77_LIBRARY_DIR_FLAG
1953
1954    AC_SUBST(MPIFPMPI)
1955    if test "$MPI_WITH_PMPI" = "no" ; then
1956        # If the PMPI routines are not in the same library with the MPI
1957        # routines, we may need to remove the pmpi declarations
1958        PAC_PROG_F77_ALLOWS_UNUSED_EXTERNALS([MPIFPMPI=",PMPI_WTIME,PMPI_WTICK"],[
1959        MPIFPMPI="";
1960        AC_MSG_WARN([Removed PMPI_WTIME and PMPI_WTICK from mpif.h])])
1961    else
1962        MPIFPMPI=",PMPI_WTIME,PMPI_WTICK"
1963    fi
1964
1965    # Once we have name mangle, we can try to limit the number of needed libs
1966    PAC_PROG_F77_IN_C_LIBS
1967    AC_SUBST(F77_IN_C_LIBS)
1968
1969    # ------------------------------------------------
1970    # Shared library support
1971    # ------------------------------------------------
1972# Note that USE_GCC_G77_DECLS is not used anywhere within the code, so
1973# this check has been commented out.
1974dnl    # If both C and Fortran are gnu, define the following to simplify
1975dnl    # shared library support. 
1976dnl    AC_MSG_CHECKING([whether using gcc and g77 together])
1977dnl    if test "$ac_cv_prog_gcc" = "yes" -a "$ac_cv_prog_g77" = "yes" ; then
1978dnl        # FIXME: Who uses this definition?
1979dnl        AC_DEFINE(USE_GCC_G77_DECLS,1,[Define if using gcc and g77 together])
1980dnl        AC_MSG_RESULT(yes)
1981dnl    else
1982dnl        AC_MSG_RESULT(no)
1983dnl    fi
1984    AC_SUBST(FC_SHL)
1985    AC_SUBST(FC_LINKPATH_SHL)
1986    case "$ENABLE_SHLIB" in
1987         gcc-osx|osx-gcc)
1988         FC_SHL="$F77 -fPIC"
1989         FC_LINKPATH_SHL=""
1990         ;;
1991         gcc)
1992         # Assume that the compiler is g77 if gcc style shared libraries chosen
1993         # (unfortunately, the name may be g77 or f77)
1994         # To make this a little more robust, only add the -shared
1995         # if the compiler allows it (e.g., building with gcc but
1996         # a different Fortran compiler. Another option is to
1997         # *require* g77.
1998         AC_MSG_CHECKING([whether $F77 allows -shared -fpic])
1999         rm -f conftest.f
2000         cat > conftest.f <<EOF
2001       program main
2002       end
2003EOF
2004         if $F77 -shared -fpic -o conftest conftest.f >/dev/null 2>&1 ; then
2005             FC_SHL="$F77 -shared -fpic"
2006             AC_MSG_RESULT(yes)
2007         else
2008             AC_MSG_RESULT(no)
2009             AC_MSG_CHECKING([whether $F77 allows -fpic])
2010             if $F77 -fpic -o conftest conftest.f >/dev/null 2>&1 ; then
2011                 FC_SHL="$F77 -fpic"
2012                 AC_MSG_RESULT(yes)
2013             else
2014                 FC_SHL=false
2015                 AC_MSG_RESULT(no)
2016                 AC_MSG_WARN([Cannot build shared libraries for Fortran with this compiler])
2017             fi
2018         fi
2019         # This is needed for Mac OSX 10.5
2020         rm -rf conftest.dSYM
2021         rm -f conftest*
2022
2023         FC_LINKPATH_SHL="-Wl,-rpath -Wl,"
2024         ;;
2025         cygwin|cygwin-gcc)
2026         FC_SHL="$F77 -shared"
2027         FC_LINKPATH_SHL=""
2028         ;;
2029
2030         solaris|solaris-cc)
2031         FC_SHL="$F77 -xcode=pic32"
2032         FC_LINKPATH_SHL=-R
2033         ;;
2034
2035         # Do we need a solaris-64 with -xcode=pic64?
2036
2037         libtool)
2038         FC_SHL='${LIBTOOL} --mode=compile ${F77}'
2039         FC_LINKPATH_SHL="-rpath "
2040         ;;
2041
2042         *)
2043         FC_SHL=false
2044         ;;
2045    esac
2046    # ------------------------------------------------
2047
2048    #
2049    # Most systems allow the Fortran compiler to process .F and .F90 files
2050    # using the C preprocessor.  However, some systems either do not
2051    # allow this or have serious bugs (OSF Fortran compilers have a bug
2052    # that generates an error message from cpp).  The following test
2053    # checks to see if .F works, and if not, whether "cpp -P -C" can be used
2054    # This is needed for Mac OSX 10.5
2055    rm -rf conftest.dSYM
2056    rm -f conftest*
2057    AC_MSG_CHECKING([whether Fortran compiler processes .F files with C preprocessor])
2058    cat >conftest.F <<EOF
2059        program main
2060#define SIZE 10
2061        integer a(SIZE)
2062        end
2063EOF
2064    pac_cv_fort_accepts_F=no
2065    pac_Fcompile='${F77} -c $FFLAGS $CPPFLAGS conftest.F 1>&AC_FD_CC'
2066
2067    if AC_TRY_EVAL(pac_Fcompile) && test -s conftest.o ; then
2068        pac_cv_fort_accepts_F=yes
2069    else
2070        # Can we use cpp?
2071        pac_Fcpp='${CPP} -C -P $CPPFLAGS conftest.F >conftest.f 2>&AC_FD_CC'
2072        if AC_TRY_EVAL(pac_Fcpp) && test -s conftest.f ; then
2073            pac_fFcompile='${F77} -c $FFLAGS $CPPFLAGS conftest.f 1>&AC_FD_CC'
2074            if AC_TRY_EVAL(pac_fFcompile) && test -s conftest.o ; then
2075                pac_cv_fort_accepts_F="no, use cpp"
2076            fi
2077        fi
2078    fi
2079    rm -f conftest.*
2080    AC_MSG_RESULT($pac_cv_fort_accepts_F)
2081    case "$pac_cv_fort_accepts_F" in
2082        yes)
2083        F77CPP=""
2084        ;;
2085        "no, use cpp")
2086         F77CPP="$CPP -C -P"
2087        ;;
2088        no)
2089        F77CPP="false"
2090        ;;
2091    esac
2092    AC_SUBST(F77CPP)
2093
2094    bindings="$bindings f77"
2095    bindings_dirs="$bindings_dirs src/binding/f77"
2096    AC_DEFINE(HAVE_FORTRAN_BINDING,1,[Define if Fortran is supported])
2097    # Also define the name FORTRAN_BINDING for use in #if @FORTRAN_BINDING@..
2098    FORTRAN_BINDING=1
2099fi
2100
2101dnl By modifying mpif.h to use ! for comments, it can work with many f90
2102dnl compilers without creating a separate version. 
2103dnl Note that this is run AFTER the AC_OUTPUT actions
2104AC_OUTPUT_COMMANDS([if test "$enable_f77" = yes ; then
2105if test "$bashWorks" = yes ; then cp -f src/env/mpif77.bash src/env/mpif77 ; fi
2106chmod a+x src/env/mpif77
2107if test "$has_exclaim" = "yes" ; then
2108    sed -e 's/^C/\!/g' src/binding/f77/mpif.h > src/include/mpif.h
2109        cp src/include/mpif.h src/binding/f77/mpif.h
2110else
2111    cp src/binding/f77/mpif.h src/include
2112fi
2113if test "$has_fort_real8" = "yes" ; then
2114    sed -e 's/DOUBLE PRECISION/REAL*8/g' src/include/mpif.h > src/include/mpif.h.new
2115    mv src/include/mpif.h.new src/include/mpif.h
2116    cp src/include/mpif.h src/binding/f77/mpif.h
2117fi
2118# Save a copy of the original mpi_base.f90 file
2119if test "$enable_f90" = "yes" ; then
2120  if test ! -f "$master_top_srcdir/src/binding/f90/mpi_base.f90.orig" ; then
2121    cp $master_top_srcdir/src/binding/f90/mpi_base.f90 $master_top_srcdir/src/binding/f90/mpi_base.f90.orig
2122  fi
2123  if test "$has_fort90_real8" = "yes" ; then
2124    sed -e 's/DOUBLE PRECISION/REAL*8/g' $master_top_srcdir/src/binding/f90/mpi_base.f90 > $master_top_srcdir/src/binding/f90/mpi_base.f90.new
2125    mv -f $master_top_srcdir/src/binding/f90/mpi_base.f90.new $master_top_srcdir/src/binding/f90/mpi_base.f90
2126  else
2127    cp -f $master_top_srcdir/src/binding/f90/mpi_base.f90.orig $master_top_srcdir/src/binding/f90/mpi_base.f90
2128  fi
2129fi
2130
2131if test ! -d bin  ; then mkdir bin ; fi
2132sed -e 's%includedir=.*%includedir='$includebuild_dir% \
2133    -e 's%libdir=.*%libdir='$libbuild_dir% \
2134    -e 's%^opalibdir=.*%opalibdir='$opalibbuild_dir% \
2135    src/env/mpif77 > bin/mpif77 ;
2136chmod a+x bin/mpif77
2137else
2138    rm -f src/env/mpif77 src/env/mpif77.conf
2139fi],
2140master_top_srcdir=$master_top_srcdir
2141enable_f77=$enable_f77
2142enable_f90=$enable_f90
2143has_exclaim=$has_exclaim
2144has_fort_real8=$pac_cv_fort_real8
2145has_fort90_real8=$pac_cv_fort90_real8
2146includebuild_dir=$includebuild_dir
2147libbuild_dir=$libbuild_dir
2148bashWorks=$bashWorks)
2149
2150if test "$enable_f90" = "yes" ; then
2151    if test "$enable_f77" != "yes" ; then
2152        AC_MSG_WARN([Fortran 90 requires Fortran 77])
2153        enable_f90=no
2154    else
2155        bindingsubsystems="$bindingsubsystems src/binding/f90"
2156        bindings="$bindings f90"
2157        bindings_dirs="$bindings_dirs src/binding/f90"
2158    fi
2159fi
2160
2161# Set defaults for these values so that the Makefile in src/bindings/f90
2162# is valid even if f90 is not enabled (this is necessary for the
2163# distclean target)
2164MPIMODNAME=mpi
2165MPICONSTMODNAME=mpi_constants
2166MPISIZEOFMODNAME=mpi_sizeofs
2167MPIBASEMODNAME=mpi_base
2168if test "$enable_f90" = "yes" ; then
2169    # Determine characteristics of the Fortran 90 compiler
2170    # Find a Fortran 90 compiler.  Sets F90
2171    # Work around bug in autoconf that adds -g to F90FLAGS
2172    saveF90FLAGS="$F90FLAGS"
2173    PAC_PROG_F90
2174    PAC_PROG_F90_WORKS
2175    F90FLAGS=$saveF90FLAGS
2176    if test "$pac_cv_prog_f90_works" = no ; then
2177        # Reject this compiler
2178        if test -n "$F90" ; then
2179            f90_rejected=yes
2180            oldF90="$F90"
2181            F90=""
2182        fi
2183    fi
2184
2185    if test -z "$F90" ; then
2186        if test "$f90_rejected" = "yes" ; then
2187            AC_MSG_ERROR([Could not find a usable F90 compiler.  The compiler $oldF90 may be incompatible with the Fortran 77 compiler $F77; check the output of configure and consult the installation manuals])
2188        else
2189            AC_MSG_ERROR([Could not find a usable F90 compiler.])
2190        fi
2191    fi
2192
2193    # Find the extension that this compiler uses for modules.
2194    # Sets F90MODEXT (and adds it to the list substed)
2195    # Sets F90MODINCFLAG (and adds it to the list substed)
2196    PAC_F90_MODULE
2197    AC_SUBST(F90MODINCSPEC)
2198    if test "$pac_cv_f90_module_case" = "upper" ; then
2199        MPIMODNAME=MPI
2200        MPICONSTMODNAME=MPI_CONSTANTS
2201        MPISIZEOFMODNAME=MPI_SIZEOFS
2202        MPIBASEMODNAME=MPI_BASE
2203    else
2204        MPIMODNAME=mpi
2205        MPICONSTMODNAME=mpi_constants
2206        MPISIZEOFMODNAME=mpi_sizeofs
2207        MPIBASEMODNAME=mpi_base
2208    fi
2209    AC_SUBST(MPIMODNAME)
2210    AC_SUBST(MPICONSTMODNAME)
2211    AC_SUBST(MPISIZEOFMODNAME)
2212    AC_SUBST(MPIBASEMODNAME)
2213    if test -z "$modincdir" ; then
2214        # The default module include dir is the same as the include dir
2215        modincdir=$includedir
2216    fi
2217    AC_SUBST(modincdir)   
2218    #
2219    # For now, assume that all f90 compilers accept -I for include directories
2220    F90INC=-I
2221    AC_SUBST(F90INC)
2222    F90INCFLAG=-I
2223    AC_SUBST(F90INCFLAG)
2224
2225    #
2226    # Determine the extension for f90 files (it isn't always .f90)
2227    PAC_F90_EXT
2228    F90EXT=$pac_cv_f90_ext
2229    AC_SUBST(F90EXT)
2230
2231    # Check if $MPI_DEFAULT_F90OPTS is valid with $F90
2232    if test "$enable_default_optimize" = "yes" \
2233         -a -n "$MPI_DEFAULT_F90OPTS" ; then
2234        if test "$enable_check_compiler_flags" = "yes" ; then
2235            PAC_F90_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_F90OPTS], [
2236            F90FLAGS="$F90FLAGS $MPI_DEFAULT_F90OPTS"
2237            MPICH2_EXTRA_F90FLAGS="$MPICH2_EXTRA_F90FLAGS $MPI_DEFAULT_F90OPTS"
2238                                     ] )
2239        else
2240            F90FLAGS="$F90FLAGS $MPI_DEFAULT_F90OPTS"
2241            MPICH2_EXTRA_F90FLAGS="$MPICH2_EXTRA_F90FLAGS $MPI_DEFAULT_F90OPTS"
2242        fi
2243    fi
2244    # Up till here, MPICH2_EXTRA_F90FLAGS contains only flags added by MPICH2.
2245    # Check with "grep -n MPICH2_EXTRA_F90FLAGS configure.in"
2246    # Remove duplicated flags from MPICH2_EXTRA_F90FLAGS.
2247    PAC_MAKE_UNIQ_STRING([MPICH2_EXTRA_F90FLAGS])
2248    # Check if $MPICH2LIB_F90FLAGS works with $F90
2249    if test -n "$MPICH2LIB_F90FLAGS" ; then
2250        if test "$enable_check_compiler_flags" = "yes" ; then
2251            PAC_F90_CHECK_COMPILER_OPTION( [$MPICH2LIB_F90FLAGS], [
2252            F90FLAGS="$F90FLAGS $MPICH2LIB_F90FLAGS"
2253            MPICH2_EXTRA_F90FLAGS="$MPICH2_EXTRA_F90FLAGS $MPICH2LIB_F90FLAGS"
2254                                     ] )
2255        else
2256            F90FLAGS="$F90FLAGS $MPICH2LIB_F90FLAGS"
2257            MPICH2_EXTRA_F90FLAGS="$MPICH2_EXTRA_F90FLAGS $MPICH2LIB_F90FLAGS"
2258        fi
2259    fi
2260
2261    #
2262    # Most systems allow the Fortran compiler to process .F and .F90 files
2263    # using the C preprocessor.  However, some systems either do not
2264    # allow this or have serious bugs (OSF Fortran compilers have a bug
2265    # that generates an error message from cpp).  The following test
2266    # checks to see if .F works, and if not, whether "cpp -P -C" can be used
2267    # This is needed for Mac OSX 10.5
2268    rm -rf conftest.dSYM
2269    rm -f conftest*
2270    AC_MSG_CHECKING([whether Fortran 90 compiler processes .F90 files with C preprocessor])
2271    cat >conftest.F90 <<EOF
2272        program main
2273#define ASIZE 10
2274        integer a(ASIZE)
2275        end
2276EOF
2277    pac_cv_f90_accepts_F90=no
2278    pac_F90compile='${F90} -c $F90FLAGS $CPPFLAGS conftest.F90 1>&AC_FD_CC'
2279
2280    if AC_TRY_EVAL(pac_F90compile) && test -s conftest.o ; then
2281        pac_cv_f90_accepts_F90=yes
2282    else
2283        # Can we use cpp?
2284        pac_F90cpp='${CPP} -C -P $CPPFLAGS conftest.F90 >conftest.$pac_cv_f90_ext 2>&AC_FD_CC'
2285        if AC_TRY_EVAL(pac_F90cpp) && test -s conftest.$pac_cv_f90_ext ; then
2286            pac_fF90compile='${F90} -c $F90FLAGS $CPPFLAGS conftest.$pac_cv_f90_ext 1>&AC_FD_CC'
2287            if AC_TRY_EVAL(pac_fF90compile) && test -s conftest.o ; then
2288                pac_cv_f90_accepts_F90="no, use cpp"
2289            fi
2290        fi
2291    fi
2292    rm -f conftest.*
2293    AC_MSG_RESULT($pac_cv_f90_accepts_F90)
2294    case "$pac_cv_f90_accepts_F90" in
2295        yes)
2296        F90CPP=""
2297        ;;
2298        "no, use cpp")
2299        F90CPP="$CPP -C -P"
2300        ;;
2301        no)
2302        F90CPP="false"
2303        ;;
2304    esac
2305    AC_SUBST(F90CPP)
2306
2307    # Check whether additional libraries are needed when linking with C
2308    PAC_PROG_F90_AND_C_STDIO_LIBS
2309    AC_SUBST(F90_OTHER_LIBS)
2310
2311    # ------------------------------------------------
2312    # ------------------------------------------------
2313    # Here are the commands to substitute the compilers to be used to create
2314    # shared libraries.  The choices for the first two come down from the
2315    # top-level configure.  FC_SHL must be determined in this configure
2316    AC_SUBST(F90_SHL)
2317    AC_SUBST(F90_LINKPATH_SHL)
2318
2319    # Try to get a version string for the F90 compiler.  We may
2320    # need this to find likely command-line arguments for accessing
2321    # shared libraries
2322    AC_MSG_CHECKING([for f90 compiler vendor])
2323    # This is complicated by some compilers (such as the Intel 8.1 ifort)
2324    # that return a non-zero status even when they accept the -V option
2325    # (a zero status is returned only if there is a file).
2326    pac_cv_f90_vendor="unknown"
2327    for arg in --version -V -v ; do
2328        rm -f conftest.txt
2329        $F90 $arg </dev/null >conftest.txt 2>&1
2330        # Ignore the return code, because some compilers set the
2331        # return code to zero on invalid arguments and some to
2332        # non-zero on success (with no files to compile)
2333        if test -f conftest.txt ; then
2334            if grep 'Portland Group' conftest.txt >/dev/null 2>&1 ; then
2335                pac_cv_f90_vendor=pgi
2336            elif grep 'Sun Workshop' conftest.txt >/dev/null 2>&1 ; then
2337                pac_cv_f90_vendor=sun
2338            elif grep 'Absoft' conftest.txt >/dev/null 2>&1 ; then
2339                pac_cv_f90_vendor=absoft
2340            elif grep 'G95' conftest.txt >/dev/null 2>&1 ; then
2341                pac_cv_f90_vendor=gnu
2342            elif grep 'GNU Fortran' conftest.txt >/dev/null 2>&1 ; then
2343                # This is gfortran
2344                pac_cv_f90_vendor=gnu
2345            elif grep Intel conftest.txt >/dev/null 2>&1 ; then
2346                pac_cv_f90_vendor=intel
2347            fi
2348        fi
2349        if test "$pac_cv_f90_vendor" != "unknown" ; then break ; fi
2350    done
2351    if test "$pac_cv_f90_vendor" = "unknown" ; then
2352        # Try to use the compiler name
2353        if test "$F90" = "ifort" -o "$F90" = "ifc" ; then
2354            pac_cv_f90_vendor=intel
2355        elif test "$F90" = "pgf90" ; then
2356            pac_cv_f90_vendor=pgi
2357        elif test "$F90" = "xlf90" -o "$F90" = "xlf90_r" ; then
2358            pac_cv_f90_vendor=ibm
2359        fi
2360    fi
2361    AC_MSG_RESULT($pac_cv_f90_vendor)
2362    rm -f conftest.txt
2363    # End of checking for F90 compiler vendor
2364
2365    if test "$ENABLE_SHLIB" != none ; then
2366        AC_MSG_CHECKING([for how to build shared libraries for Fortran 90])
2367        case "$ENABLE_SHLIB" in
2368         gcc-osx|osx-gcc)
2369         F90_SHL="$F90 -fPIC"
2370         F90_LINKPATH_SHL=""
2371         ;;
2372         gcc)
2373         if test "$pac_cv_f90_vendor" = gnu -o "$F90" = "g95" ; then
2374            # If we have the GNU Fortran 95 compiler (untested)
2375            F90_SHL="$F90 -shared -fpic"
2376            F90_LINKPATH_SHL="-Wl,-rpath -Wl,"
2377         else
2378            case "$pac_cv_f90_vendor" in
2379                absoft)
2380                F90_SHL="$F90 -fpic"
2381                F90_LINKPATH_SHL="-X -rpath -X "
2382                ;;
2383
2384                intel)
2385                # Intel implements the GNU options
2386                F90_SHL="$F90 -shared -fpic"
2387                F90_LINKPATH_SHL="-Wl,-rpath -Wl,"
2388                ;;
2389
2390                pgi)
2391                # Portland Group implements the GNU options
2392                F90_SHL="$F90 -shared -fpic"
2393                F90_LINKPATH_SHL="-Wl,-rpath -Wl,"
2394                ;;
2395
2396                *)
2397                # Unknown, ignore
2398                ;;
2399            esac
2400            fi
2401            ;;
2402         solaris|solaris-cc)
2403            # Assume the Solaris F90 compiler, in 32-bit mode
2404            F90_SHL="$F90 -xcode=pic32"
2405            F90_LINKPATH_SHL=-R
2406         ;;
2407         *)
2408           # Unknown, ignore
2409         ;;
2410        esac
2411        if test -n "$F90_SHL" ; then
2412            AC_MSG_RESULT([Compile with $F90_SHL and link using path argument $F90_LINKPATH_SHL])
2413        else
2414            AC_MSG_WARN([Unable to determine how to link Fortran 90 compiler with shared libraries])
2415        fi
2416    fi
2417
2418dnl  Some systems don't require or accept linkpath arguments.
2419dnl    if test "$ENABLE_SHLIB" != "none" -a -z "$F90_LINKPATH_SHL" -a \
2420dnl        -n "$C_LINKPATH_SHL" ; then
2421dnl        AC_MSG_WARN([Unable to determine how to pass the shared-library link patth to the Fortran 90 compiler $F90.  Set the environment variable F90_LINKPATH_SHL and rerun configure (the corresponding value for the C compiler is $C_LINKPATH_SHL)])
2422dnl    fi
2423    # ------------------------------------------------
2424fi
2425
2426AC_OUTPUT_COMMANDS([if test $enable_f90 = yes ; then
2427if test "$bashWorks" = yes ; then cp -f src/env/mpif90.bash src/env/mpif90 ; fi
2428chmod a+x src/env/mpif90
2429if test ! -d bin  ; then mkdir bin ; fi
2430sed -e 's%includedir=.*%includedir='$includebuild_dir% \
2431    -e 's%modincdir=.*%modincdir='$modincbuild_dir% \
2432    -e 's%libdir=.*%libdir='$libbuild_dir% \
2433    -e 's%^opalibdir=.*%opalibdir='$opalibbuild_dir% \
2434    src/env/mpif90 > bin/mpif90 ;
2435chmod a+x bin/mpif90
2436else
2437    rm -f src/env/mpif90 src/env/mpif90.conf bin/mpif90
2438fi
2439],
2440enable_f90=$enable_f90
2441modincbuild_dir=$modincbuild_dir
2442includebuild_dir=$includebuild_dir
2443libbuild_dir=$libbuild_dir
2444bashWorks=$bashWorks)
2445
2446# ----------------------------------------------------------------------------
2447# By default, only build C++ if there is a C++ compiler (if we don't
2448# test here, the configure can fail if there is no C++ compiler available)
2449if test "$enable_cxx" = "default" ; then
2450    # This test uses the list from a recent PROG_CXX, but with the
2451    # addition of the Portland group, IBM, and Intel C++ compilers
2452    # (While the Intel icc compiler will compile C++ programs, it will
2453    # not *link* C++ object files unless there is at least one C++ source
2454    # file present on the command that performs the linking.  icpc is the
2455    # Intel C++ compiler that both compiles and links C++ programs)
2456    AC_CHECK_PROGS(CXX,$CCC c++ g++ gcc CC cxx cc++ cl pgCC xlC icpc pathCC)
2457    if test -n "$CXX" ; then
2458        enable_cxx=yes
2459    fi
2460fi
2461
2462if test "$enable_cxx" = "yes" ; then
2463    # Save the current CXXFLAGS (see below for the reason)
2464    saveCXXFLAGS=$CXXFLAGS
2465    # Misfeature in autoconf.  While the macro name is PROG_CXX, it
2466    # looks at the CCC environment variable, not CXX, even though it
2467    # *sets* CXX!!!!
2468    if test -z "$CCC" -a -n "$CXX" ; then
2469        CCC="$CXX"
2470    fi
2471    AC_PROG_CXX
2472    # Misfeature in autoconf.  When using gcc, PROG_CXX insists on setting
2473    # CXXFLAGS to -g -O2 if CXXFLAGS is not set.  This may be appropriate for
2474    # many tools built with configure and gcc, but not always.  In particular,
2475    # there seems to be no way to get gcc to use no extra flags if that is
2476    # desired.
2477    if test -z "$saveCXXFLAGS" -a -n "$CXXFLAGS" ; then
2478        # restore CXXFLAGS
2479        # Note: This may not be correct if PROG_CXX decided to add other
2480        # flags to CXXFLAGS to enforce some behavior (such as ANSI/ISO C++),
2481        # But we haven't seen that in practice.  It would be better
2482        # if the CXXFLAGS were decomposed into flags-that-change-the-language
2483        # that the compiler accepts from optimizations
2484        CXXFLAGS=$saveCXXFLAGS
2485    fi
2486    # Another bug in autoconf.  The checks for the C++ compiler do not
2487    # ensure that you can link a program that is built with the C++
2488    # compiler.  We've seen this error with gcc and icc, particularly
2489    # when those compilers accept C++ language elements but are unable
2490    # to link programs that are really C++.  For that reason,
2491    # we've added a test to see if the C++ compiler can produce
2492    # an executable.
2493    AC_CACHE_CHECK([whether the C++ compiler $CXX can build an executable],
2494    pac_cv_cxx_builds_exe,[
2495 AC_LANG_SAVE
2496 AC_LANG_CPLUSPLUS
2497 AC_TRY_LINK([
2498class mytest {
2499  int a;
2500public:
2501  mytest(void) : a(1) {}
2502  ~mytest(void) {}
2503};],[mytest a;],
2504 pac_cv_cxx_builds_exe=yes, ac_cv_builds_exe=no)
2505 AC_LANG_RESTORE
2506])
2507    if test "$pac_cv_cxx_builds_exe" != yes ; then
2508       AC_MSG_ERROR([Aborting because C++ compiler does not work.  If you do not need a C++ compiler, configure with --disable-cxx])
2509    fi
2510    # Recent failures have come when a standard header is loaded
2511    # The Intel icpc 10.x compiler fails with <string> if gcc 4.2 is installed.
2512    AC_CACHE_CHECK([whether C++ compiler works with string],pac_cv_cxx_compiles_string,[
2513    AC_LANG_SAVE
2514    AC_LANG_CPLUSPLUS
2515    AC_TRY_COMPILE([#include <string>],[return 0;],pac_cv_cxx_compiles_string=yes,pac_cv_cxx_compiles_string=no)
2516    AC_LANG_RESTORE
2517])
2518    if test "$pac_cv_cxx_compiles_string" != yes ; then
2519        AC_MSG_WARN([The C++ compiler $CXX cannot compile a program containing the <string> header - this may indicate a problem with the C++ installation.  Consider configuing with --disable-cxx])
2520    fi
2521
2522    AC_LANG_CPLUSPLUS
2523    AC_CXX_EXCEPTIONS
2524    AC_CXX_BOOL
2525    AC_CXX_NAMESPACES
2526    if test "$ac_cv_cxx_namespaces" != "yes" ; then
2527        AC_MSG_ERROR([Namespaces are required for the MPI C++ interface])
2528    fi
2529    HAVE_CXX_EXCEPTIONS=0
2530    AC_SUBST(HAVE_CXX_EXCEPTIONS)
2531    if test "$ac_cv_cxx_exceptions" = "yes" ; then
2532        HAVE_CXX_EXCEPTIONS=1
2533    fi
2534    # iostream and math are needed for examples/cxx/cxxpi.cxx
2535    AC_CACHE_CHECK([whether <iostream> available],pac_cv_cxx_has_iostream,[
2536    AC_TRY_COMPILE([
2537#include <iostream>
2538],[using namespace std;],pac_cv_cxx_has_iostream=yes,pac_cv_cxx_has_iostream=no)])
2539    if test "$pac_cv_cxx_has_iostream" = yes ; then
2540        CXX_DEFS="$CXX_DEFS -DHAVE_CXX_IOSTREAM"
2541    fi
2542    AC_CXX_NAMESPACE_STD
2543    if test "$ac_cv_cxx_namespace_std" = "yes" ; then
2544        CXX_DEFS="$CXX_DEFS -DHAVE_NAMESPACE_STD"
2545    fi
2546   
2547    AC_CACHE_CHECK([whether <math> available],pac_cv_cxx_has_math,[
2548    AC_TRY_COMPILE([
2549#include <math>
2550],[using namespace std;],pac_cv_cxx_has_math=yes,pac_cv_cxx_has_math=no)])
2551    if test "$pac_cv_cxx_has_math" = yes ; then
2552        CXX_DEFS="$CXX_DEFS -DHAVE_CXX_MATH"
2553    fi
2554    AC_SUBST(CXX_DEFS)
2555
2556    # Add support for shared libraries if possible
2557    AC_SUBST(CXX_SHL)
2558    AC_SUBST(CXX_LINKPATH_SHL)
2559    case "$ENABLE_SHLIB" in
2560        gcc-osx|osx-gcc)
2561        # Assume that the compiler is g++ if gcc style shared libraries chosen
2562        CXX_SHL="$CXX -fPIC"
2563        CXX_LINKPATH_SHL=""
2564        ;;
2565        gcc)
2566        # Assume that the compiler is g++ if gcc style shared libraries chosen
2567        CXX_SHL="$CXX -shared -fpic"
2568        CXX_LINKPATH_SHL="-Wl,-rpath -Wl,"
2569        ;;
2570        cygwin|cygwin-gcc)
2571        CXX_SHL="$CXX -shared"
2572        CXX_LINKPATH_SHL=""
2573        ;;
2574        solaris|solaris-cc)
2575        CXX_SHL="$CXX -xcode=pic32"
2576        CXX_LINKPATH_SHL=-R
2577        ;;
2578        libtool)
2579        CXX_SHL='${LIBTOOL} --mode=compile ${CXX}'
2580        CXX_LINKPATH_SHL="-rpath "
2581        ;;
2582        *)
2583        CXX_SHL=false
2584        ;;
2585    esac
2586    # GNU changed the calling conventions between minor releases (!!!)
2587    # This is too hard to detect, but we should be able to detect
2588    # the version mismatch.  By default, we set the GNU version to 0.
2589    # In a cross-compiling environment, these can be set with environment
2590    # variables, either directly or through the standard "CROSS" variable.
2591    if test -z "$GNUCXX_VERSION" ; then
2592        if test -n "$CROSS_GNUCXX_VERSION" ; then
2593             GNUCXX_VERSION=$CROSS_GNUCXX_VERSION
2594        else
2595             GNUCXX_VERSION=0
2596        fi
2597    fi
2598    if test -z "$GNUCXX_MINORVERSION" ; then
2599        if test -n "$CROSS_GNUCXX_MINORVERSION" ; then
2600             GNUCXX_MINORVERSION=$CROSS_GNUCXX_MINORVERSION
2601        else
2602             GNUCXX_MINORVERSION=0
2603        fi
2604    fi
2605    if test "$cross_compiling" = "no" -a "$ac_compiler_gnu" = "yes" -a \
2606       "$GNUCXX_VERSION" = 0 -a "$GNUCXX_MINORVERSION" = 0 ; then
2607         ac_vals=""
2608         AC_MSG_CHECKING([for GNU g++ version])
2609         AC_TRY_RUN([#include <stdio.h>
2610int main() {
2611    int v = -1, m = -1;
2612    FILE *fp = fopen("conftest.out","w");
2613#ifdef __GNUC_MINOR__
2614    m = __GNUC_MINOR__;
2615#endif
2616#ifdef __GNUC__
2617    v = __GNUC__;
2618#endif
2619    fprintf( fp, "v=%d, m=%d\n", v, m );
2620    fclose( fp );
2621    return 0;
2622}],ac_vals=`cat conftest.out`)
2623         if test -n "$ac_vals" ; then
2624             v=`echo "$ac_vals" | sed -e 's/v=\(.*\),.*/\1/'`
2625             m=`echo "$ac_vals" | sed -e 's/.*m=\(.*\)/\1/'`
2626             AC_MSG_RESULT([$v . $m])
2627             GNUCXX_VERSION=$v
2628             GNUCXX_MINORVERSION=$m
2629         else
2630             AC_MSG_RESULT([unknown])
2631         fi
2632    fi   
2633    AC_SUBST(GNUCXX_VERSION)
2634    AC_SUBST(GNUCXX_MINORVERSION)
2635
2636    bindings="$bindings cxx"
2637    bindings_dirs="$bindings_dirs src/binding/cxx"
2638    AC_DEFINE(HAVE_CXX_BINDING,1,[Define if C++ is supported])
2639    INCLUDE_MPICXX_H='#include "mpicxx.h"'
2640    AC_SUBST(INCLUDE_MPICXX_H)
2641
2642    # In order to support the Fortran datatypes within C++,
2643    #
2644    # FORTRAN_BINDING always has a CPP-time value of either 0 or 1,
2645    # so that it may be used in #if statements without adding to
2646    # the CPP name space
2647    AC_SUBST(FORTRAN_BINDING)
2648
2649    # Special C++ datatypes.  Set to DATATYPE NULL first; we'll
2650    # replace the ones that we have later, after we have determined
2651    # the C datatypes
2652    MPIR_CXX_BOOL=0x0c000000
2653    MPIR_CXX_COMPLEX=0x0c000000
2654    MPIR_CXX_DOUBLE_COMPLEX=0x0c000000
2655    MPIR_CXX_LONG_DOUBLE_COMPLEX=0x0c000000
2656    AC_SUBST(MPIR_CXX_BOOL)
2657    AC_SUBST(MPIR_CXX_COMPLEX)
2658    AC_SUBST(MPIR_CXX_DOUBLE_COMPLEX)
2659    AC_SUBST(MPIR_CXX_LONG_DOUBLE_COMPLEX)
2660
2661fi
2662
2663if test "$enable_cxx" = yes; then
2664    # Check if $MPI_DEFAULT_CXXOPTS is valid with $CXX
2665    if test "$enable_default_optimize" = "yes" \
2666         -a -n "$MPI_DEFAULT_CXXOPTS" ; then
2667        if test "$enable_check_compiler_flags" = "yes" ; then
2668            PAC_CXX_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_CXXOPTS], [
2669            CXXFLAGS="$CXXFLAGS $MPI_DEFAULT_CXXOPTS"
2670            MPICH2_EXTRA_CXXFLAGS="$MPICH2_EXTRA_CXXFLAGS $MPI_DEFAULT_CXXOPTS"
2671                                     ] )
2672        else
2673            CXXFLAGS="$CXXFLAGS $MPI_DEFAULT_CXXOPTS"
2674            MPICH2_EXTRA_CXXFLAGS="$MPICH2_EXTRA_CXXFLAGS $MPI_DEFAULT_CXXOPTS"
2675        fi
2676    fi
2677    # Up till here, MPICH2_EXTRA_CXXFLAGS contains only flags added by MPICH2.
2678    # Check with "grep -n MPICH2_EXTRA_CXXFLAGS configure.in"
2679    # Remove duplicated flags from MPICH2_EXTRA_CXXFLAGS.
2680    PAC_MAKE_UNIQ_STRING([MPICH2_EXTRA_CXXFLAGS])
2681    # Check if $MPICH2LIB_CXXFLAGS is valid with $CXX
2682    if test -n "$MPICH2LIB_CXXFLAGS" ; then
2683        if test "$enable_check_compiler_flags" = "yes" ; then
2684            PAC_CXX_CHECK_COMPILER_OPTION( [$MPICH2LIB_CXXFLAGS], [
2685            CXXFLAGS="$CXXFLAGS $MPICH2LIB_CXXFLAGS"
2686            MPICH2_EXTRA_CXXFLAGS="$MPICH2_EXTRA_CXXFLAGS $MPICH2LIB_CXXFLAGS"
2687                                     ] )
2688        else
2689            CXXFLAGS="$CXXFLAGS $MPICH2LIB_CXXFLAGS"
2690            MPICH2_EXTRA_CXXFLAGS="$MPICH2_EXTRA_CXXFLAGS $MPICH2LIB_CXXFLAGS"
2691        fi
2692    fi
2693fi
2694
2695export MPICH2_EXTRA_CFLAGS
2696export MPICH2_EXTRA_CXXFLAGS
2697export MPICH2_EXTRA_FFLAGS
2698export MPICH2_EXTRA_F90FLAGS
2699
2700# Copy the mpicxx.h file to the main include directory
2701# Move a working version of the mpicxx script to the bin directory
2702# Create an alias mpic++ for mpicxx (BOOST, at least, makes invalid assumptions
2703# about the name of the MPI C++ compilation script)
2704AC_OUTPUT_COMMANDS([if test $enable_cxx = yes ; then
2705if test "$bashWorks" = yes ; then cp -f src/env/mpicxx.bash src/env/mpicxx ; fi
2706chmod a+x src/env/mpicxx
2707cp src/binding/cxx/mpicxx.h src/include
2708if test ! -d bin  ; then mkdir bin ; fi
2709sed -e 's%includedir=.*%includedir='$includebuild_dir% \
2710    -e 's%libdir=.*%libdir='$libbuild_dir% \
2711    -e 's%^opalibdir=.*%opalibdir='$opalibbuild_dir% \
2712    src/env/mpicxx > bin/mpicxx ;
2713chmod a+x bin/mpicxx
2714ln -sf mpicxx bin/mpic++
2715else
2716    rm -f src/env/mpicxx src/env/mpicxx.conf
2717fi
2718],
2719enable_cxx=$enable_cxx
2720includebuild_dir=$includebuild_dir
2721libbuild_dir=$libbuild_dir
2722bashWorks=$bashWorks)
2723
2724AC_SUBST(bindings)
2725# Bindings dirs is used for the installation target
2726AC_SUBST(bindings_dirs)
2727#
2728# A few final exports
2729# Some users use FC, others F77 for the Fortran compiler.  The following
2730# tests makes us consistent
2731if test -z "$FC" -a -n "$F77" ; then FC="$F77" ; export FC ; fi
2732if test -z "$F77" -a -n "$FC" ; then F77="$FC" ; export F77 ; fi
2733AC_SUBST(FC)
2734# ----------------------------------------------------------------------------
2735# End of the bindings support
2736# ----------------------------------------------------------------------------
2737
2738AC_LANG_C
2739#
2740# ----------------------------------------------------------------------------
2741# Done with the basic argument processing and decisions about which
2742# subsystems to build
2743# ----------------------------------------------------------------------------
2744
2745# Look for perl.  Perl is used *only* in the tests of the commands such as
2746# mpiexec, mpicc, etc, in test/commands, and in some of the utility
2747# programs for processing log files .  If perl is not found,
2748# MPICH2 may still be built and used.
2749# We need the full path to perl since we'll use it as the interpreter for
2750# a shell script.
2751AC_PATH_PROG(PERL,perl)
2752# Look for ar.  If we fail, abort
2753AC_CHECK_PROGS(AR,ar)
2754if test -z "$AR" ; then
2755    AC_MSG_ERROR([The program ar is required for building MPICH2.  Make sure that your path includes ar])
2756fi
2757# Note that we set RANLIB to true if we don't find it (some systems neither
2758# need it nor provide it)
2759AC_CHECK_PROGS(RANLIB,ranlib,true)
2760
2761# Check for etags.  Note that different versions of etags take
2762# different arguments for specifying the language to use in parsing a
2763# file.  Older versions only accept -l c or --language c as a way to
2764# *change* the interpretation of the following files; newer versions
2765# allow --langmap=c:+.i to add a file extension to those that are C
2766# programs.  New versions might want --language-force=c.
2767AC_CHECK_PROGS(ETAGS,etags,true)
2768if test -n "$ETAGS" -a "$ETAGS" != true ; then
2769    # Check for the --langmap argument
2770    AC_MSG_CHECKING([for etags argument to specify language])
2771    cat >>conftest.c <<EOF
2772int footest = 0;
2773EOF
2774    if $ETAGS --langmap=c:+.i -o conftesttags conftest.c >/dev/null 2>&1 ; then
2775        ETAGSADD="--langmap=c:+.i"
2776    else
2777        if $ETAGS --language=c -o conftesttags conftest.c >/dev/null 2>&1 ; then
2778            ETAGSADD="--language=c"
2779        else
2780            if $ETAGS --language-force=c -o conftesttags conftest.c >/dev/null 2>&1 ; then
2781                ETAGSADD="--language-force=c"
2782            else
2783                ETAGS=true
2784                AC_MSG_WARN([Could not find working etags])
2785            fi
2786        fi
2787    fi
2788    if test -n "$ETAGSADD" ; then
2789        AC_MSG_RESULT($ETAGSADD)
2790    fi
2791     # This is needed for Mac OSX 10.5
2792    rm -rf conftest.dSYM
2793    rm -f conftest*
2794fi
2795AC_SUBST(ETAGS)
2796AC_SUBST(ETAGSADD)
2797export ETAGS
2798export ETAGSADD
2799
2800# Check for the killall program; this can be used in some of the tests
2801# in test/commands
2802AC_CHECK_PROGS(KILLALL,killall,true)
2803
2804# Does xargs need the -r option to handle the case where the input
2805# is empty (gnu utils do, Mac OSX does not accept -r)
2806xargs_out=`echo "" | xargs ls | wc -l | sed -e 's/ //g'`
2807if test "$xargs_out" != "0" ; then
2808    XARGS_NODATA_OPT=-r
2809fi
2810AC_SUBST(XARGS_NODATA_OPT)
2811
2812# Check for broken handling of common symbols.  There are two fixes:
2813# Force ranlib to handle correctly (ranlib -c on some BSD and MAC OS platforms)
2814# or force gcc to not generate common symbols if using gcc (-fno-common).
2815# This autoconf macro checks for this.
2816
2817# Note that if an option is added to CFLAGS, that option MUST NOT appear
2818# in WRAPPER_CFLAGS (i.e., the options used in mpicc)
2819
2820# Also note that it should not be necessary to use this option - it
2821# is almost always possible to avoid "common" symbols, and this approach
2822# is gcc-specific (if it needs to choose -fno-common), which we want to avoid.
2823dnl PAC_PROG_C_BROKEN_COMMON
2824#
2825AC_PROG_INSTALL
2826PAC_PROG_CHECK_INSTALL_WORKS
2827#
2828# On Mac OS/X, install breaks libraries unless used with the -p switch
2829PAC_PROG_INSTALL_BREAKS_LIBS
2830# We also need mkdir -p.
2831PAC_PROG_MKDIR_P
2832PAC_PROG_MAKE
2833
2834#
2835# Check for bash to allow more robust shell scripts
2836AC_PATH_PROG(BASH_SHELL,bash)
2837#
2838# Confirm that bash has working arrays.  We can use this to
2839# build more robust versions of the scripts (particularly the
2840# compliation scripts) by taking advantage of the array features in
2841# bash.
2842bashWorks=no
2843if test -x "$BASH_SHELL" ; then
2844changequote(%%,::)dnl
2845    cat >>conftest <<EOF
2846#! $BASH_SHELL
2847A[0]="b"
2848A[1]="c"
2849rc=1
2850if test \${A[1]} != "c" ; then rc=2 ; else rc=0 ; fi
2851exit \$rc
2852EOF
2853changequote([,])dnl
2854    AC_MSG_CHECKING([whether $BASH_SHELL supports arrays])
2855    chmod +x conftest
2856    if ./conftest 2>&1 >/dev/null ; then
2857        bashWorks=yes
2858    else
2859        bashWorks=no
2860    fi
2861    rm -f conftest*
2862    AC_MSG_RESULT($bashWorks)
2863fi
2864BUILD_BASH_SCRIPTS=no
2865if test "$bashWorks" = yes ; then
2866    BUILD_BASH_SCRIPTS=yes
2867fi
2868AC_SUBST(BUILD_BASH_SCRIPTS)
2869
2870# ----------------------------------------------------------------------------
2871# Check for the routines and libraries needed for accessing dynamically
2872# loaded libraries.
2873# This is very approximate for now; it is enough to allow use to experiment
2874# with this feature under Linux.
2875# ----------------------------------------------------------------------------
2876BUILD_DLLS=no
2877if test "$enable_dynamiclibs" = "yes" ; then
2878    AC_CHECK_HEADERS(dlfcn.h)
2879    AC_SEARCH_LIBS(dlopen,dl)
2880    AC_CHECK_FUNCS(dlopen dlsym)
2881    if test "$ac_cv_func_dlopen" = yes -a \
2882            "$ac_cv_func_dlsym"  = yes -a \
2883            "$ac_cv_header_dlfcn_h" = yes ; then
2884        AC_DEFINE(USE_DYNAMIC_LIBRARIES,1,[Define if dynamic libraries are available and should be used])
2885        if test "$enable_sharedlibs" = no -o "$enable_sharedlibs" = none -o \
2886           -z "$enable_sharedlibs" ; then
2887            AC_MSG_ERROR([You must specify --enable-sharedlibs=type when building with dynamic libraries])
2888dnl         # We still need to determine how to build shared libraries
2889dnl         AC_MSG_CHECKING([for how to build shared library for dynamically loaded libraries])
2890dnl         PAC_CC_SHAREDLIBS(,CC_SHL,C_LINK_SHL)
2891dnl         PAC_CC_SHLIB_EXT
2892dnl         if test "$SHLIB_EXT" = "unknown" ; then
2893dnl             # Guess that the extension is .so
2894dnl             SHLIB_EXT=so
2895dnl         fi
2896dnl         if test "$CC_SHL" = true ; then
2897dnl             AC_MSG_RESULT([none found])
2898dnl                 AC_MSG_WARN([Dynamic library support requires shared libraries])     
2899dnl         else
2900dnl             AC_MSG_RESULT($CC_SHL)
2901dnl             BUILD_DLLS=yes
2902dnl         fi
2903        fi
2904    fi
2905    AC_SUBST(BUILD_DLLS)
2906
2907    # Let the DLL code know where we plan to install the libraries.
2908    # This will make it easier for the user, who may not need
2909    # to set a search path for the library.
2910    savePrefix=$prefix
2911    saveExecprefix=$exec_prefix
2912    test "x$prefix" = xNONE && prefix=$ac_default_prefix
2913    test "x$exec_prefix" = xNONE && exec_prefix=$prefix
2914    eval MPICH2_LIBDIR=$libdir
2915    prefix=$savePrefix
2916    exec_prefix=$saveExecprefix
2917    MPICH2_LIBDIR='"'$MPICH2_LIBDIR'"'
2918    AC_DEFINE_UNQUOTED(MPICH2_LIBDIR,$MPICH2_LIBDIR,[Name of installation directory intended for MPICH2])
2919fi
2920
2921# ----------------------------------------------------------------------------
2922# Don't setup the shared libraries until we know which compiler we will be
2923# using
2924PAC_ARG_SHAREDLIBS
2925# We allow aliases for enable_sharedlibs, but after ARG_SHAREDLIBS,
2926# enable_sharedlibs contains the cannonical version
2927ENABLE_SHLIB="$enable_sharedlibs"
2928if test -z "$ENABLE_SHLIB" -o "$ENABLE_SHLIB" = "no" ; then
2929    ENABLE_SHLIB=none
2930fi
2931# Special restrictions for some shared libraries
2932# It is difficult to import/export symbols from some shared libraries, so
2933# in that case, we require PMPILIBNAME and MPILIBNAME be the same
2934case $ENABLE_SHLIB in
2935     cygwin-gcc)
2936        if test "$PMPILIBNAME_set" = "no" ; then
2937            # Rename PMPILIBNAME
2938            PMPILIBNAME=$MPILIBNAME
2939        else
2940            if test "$PMPILIBNAME" != "$MPILIBNAME" ; then
2941                AC_MSG_ERROR([The PMPI and MPI libraries must have the same name when building shared libraries of type $ENABLE_SHLIB])
2942            fi
2943        fi
2944    ;;
2945esac
2946AC_SUBST(ENABLE_SHLIB)
2947AC_SUBST(C_LINKPATH_SHL)
2948# Now that CC is defined, get these values
2949# eval C_LINK_SHL=$C_LINK_SHL
2950# eval CC_SHL=$CC_SHL
2951# Ensure that all subdir configures get the shared library items
2952export CC_SHL
2953export C_LINK_SHL
2954export C_LINKPATH_SHL
2955export SHLIB_EXT
2956export ENABLE_SHLIB
2957export LIBTOOL
2958
2959# ----------------------------------------------------------------------------
2960# At this point, we've finally settled on the value of PMPILIBNAME.  We
2961# can now set NEEDSPLIB.
2962if test "$NEEDSPLIB" = yes -a "$PMPILIBNAME" = "$MPILIBNAME" ; then
2963    NEEDSPLIB=no
2964fi
2965# Set the defaults for the Fortran libraries to be the same as the C libraries
2966if test -z "$MPIFLIBNAME" ; then
2967    MPIFLIBNAME=$MPILIBNAME
2968fi
2969if test -z "$PMPIFLIBNAME" ; then
2970    PMPIFLIBNAME=$PMPILIBNAME
2971fi
2972
2973# ----------------------------------------------------------------------------
2974#
2975# Add the steps for debugger support
2976BUILD_TVDLL=no
2977if test "$enable_debuginfo" = "yes" ; then
2978   # We can build the Totalview interface DLL only if we know how to build
2979   # shared libraries.  For now, require that enable_sharedlibs is not none
2980   # Also, we may want to put some of this into a configure in the debugger
2981   # directory
2982   if test "$ENABLE_SHLIB" != "none" ; then
2983        BUILD_TVDLL=yes
2984        CC_SHL_DBG="$CC_SHL"
2985        C_LINK_SHL_DBG="$C_LINK_SHL"
2986        DBG_SHLIB_TYPE=$ENABLE_SHLIB
2987   else
2988        # Try to determine how to build the tv shared library
2989        AC_MSG_RESULT([for how to build shared library for debugger interface])
2990        PAC_CC_SHAREDLIBS(,CC_SHL_DBG,C_LINK_SHL_DBG,DBG_SHLIB_TYPE)
2991        PAC_CC_SHLIB_EXT
2992        if test "$SHLIB_EXT" = "unknown" ; then
2993            # Guess that the extension is .so
2994            SHLIB_EXT=so
2995        fi
2996        if test "$CC_SHL_DBG" = true ; then
2997            AC_MSG_RESULT([none found])
2998            AC_MSG_WARN([Debugger support requires shared libraries])     
2999        else
3000            AC_MSG_RESULT([Use this to build the debugger shared library: $CC_SHL_DBG])
3001            BUILD_TVDLL=yes
3002        fi
3003   fi
3004   AC_SUBST(DBG_SHLIB_TYPE)
3005   # One more nasty problem.  Totalview relies on debugger symbols
3006   # being present in the executable.  Some experimental versions of
3007   # gcc (3.2 20020329 for ia64) do *not* include the object symbols
3008   # when debugging.  For HPUX, the necessary linking options are
3009   #    +noobjdebug
3010   # for C, Fortran, and C++.  We don't have a good test for this yet,
3011   # so we add a warning
3012   if test "$ac_cv_prog_gcc" = "yes" ; then
3013       AC_MSG_WARN([Some versions of gcc do not include debugging information
3014within the executable.  Totalview requires this information to detect
3015an MPICH code.  If you have trouble, try linking with the additional
3016option
3017    +noobjdebug
3018on all link lines (consider adding it to LDFLAGS)])
3019   fi
3020   AC_SUBST(BUILD_TVDLL)
3021   AC_SUBST(CC_SHL_DBG)
3022   AC_SUBST(C_LINK_SHL_DBG)
3023
3024    # The debugger library name cannot be set until we know the extension
3025    # of shared libraries - the name is so on most Unix system, dylib on OS X.
3026    debugger_dir=debugger
3027    AC_DEFINE(HAVE_DEBUGGER_SUPPORT,1,[Define if debugger support is included])
3028    # The debugger support requires a shared library.  This is handled
3029    # below, after we check for compiler support for shared libraries
3030    # Note: if libdir contains exec_prefix, handle the fact that the
3031    # default exec_prefix is NONE, which (much later in configure)
3032    # gets turned into the value of prefix
3033    ##ENVVAR: MPICH_DEBUGLIBNAME - Set this environment variable to
3034    ## override the default name of the debugger support library.
3035    ## The default name is libtvmpich2.$SHLIB_EXT (e.g., libtvmpich2.so for
3036    ## most Unix versions, libtvmpich2.dylib for Mac OSX).
3037    ##ENVVAR END:
3038    if test -z "$MPICH_DEBUGLIBNAME" ; then
3039        DEBUGLIBNAME=libtvmpich2.$SHLIB_EXT
3040    else
3041        DEBUGLIBNAME=$MPICH_DEBUGLIBNAME
3042    fi
3043    if test "x$exec_prefix" = xNONE ; then
3044        saveExecPrefix=$exec_prefix
3045        exec_prefix=$prefix
3046        eval dlldir=$libdir/$DEBUGLIBNAME
3047        exec_prefix=$saveExecPrefix
3048    else
3049        eval dlldir=$libdir/$DEBUGLIBNAME
3050    fi
3051    dlldir='"'$dlldir'"'
3052    AC_DEFINE_UNQUOTED(MPICH_INFODLL_LOC,$dlldir,[Define as the name of the debugger support library])
3053fi
3054AC_SUBST(debugger_dir)
3055
3056# ----------------------------------------------------------------------------
3057
3058nameserv_name=""
3059AC_SUBST(nameserv_name)
3060#
3061# Get the default nameserver, if no nameserver was selected.  A process
3062# manager may advertise a nameserver name by setting the variable
3063# MPID_PM_NAMESERVER.
3064if test "$with_namepublisher" = "default" ; then
3065   if test -n "$MPID_PM_NAMESERVER" ; then
3066       with_namepublisher=$MPID_PM_NAMESERVER
3067   else
3068       # The default is to use a file to communicate published names
3069       with_namepublisher=file
3070   fi
3071fi
3072
3073if test "$with_namepublisher" != no -a "$with_namepublisher" != "none" ; then
3074    case "$with_namepublisher" in
3075    none|no) ;;
3076    ldap*)
3077        subsystems="$subsystems src/nameserv/ldap"
3078        # The configure in the nameserv/ldap directory will look for
3079        # the ldap files.
3080        AC_DEFINE(USE_LDAP_FOR_NAMEPUB,1,[Define if ldap should be used for name publishing])
3081        nameserv_name="ldap"
3082    ;;
3083
3084    file*)
3085    # Note that we always build the Makefile for the file version because
3086    # this name publisher is really too simple to require a
3087    # separate configure, and we might as well include a basic
3088    # name publisher with any MPICH2 distribution
3089    # We DO need to extract the directory name that is used for writing
3090    # the files, with the User's home directory as the default
3091    nameserv_name="file"
3092    basedir=`echo $with_namepublisher | sed -e 's/file://'`
3093    if test "$basedir" = "$with_namepublisher" ; then
3094        # Reset since no directory was set.
3095        basedir='"."';
3096    fi
3097    AC_DEFINE_UNQUOTED(FILE_NAMEPUB_BASEDIR,$basedir,[Directory to use in namepub])
3098    AC_DEFINE(USE_FILE_FOR_NAMEPUB,1,[Define if file should be used for name publisher])
3099    ;;
3100
3101    mpd)
3102    nameserv_name="mpd"
3103    ;;
3104
3105    *)
3106    # Check for a new namepublisher
3107    dir=$with_namepublisher
3108    # If we later need args, here is where we can strip them off of the
3109    # with argument
3110    if test -d "$use_top_srcdir/src/nameserv/$dir" ; then
3111        if test -x "$use_top_srcdir/src/nameserv/$dir/configure" ; then
3112            # Run the configure in this directory if necessary
3113            subsystems="$subsystems src/nameserv/$dir"
3114        fi
3115        nameserv_name=$dir
3116    else
3117        AC_MSG_WARN([Unknown name publisher $with_namepublisher])
3118    fi
3119    ;;
3120    esac   
3121fi
3122if test -n "$nameserv_name" ; then
3123   AC_DEFINE(HAVE_NAMEPUB_SERVICE,1,[Define if a name publishing service is available])
3124fi
3125
3126# In case the documentation targets are used, find doctext and attempt to
3127# find the source for the doctext LaTeX style files.  Use "false" if
3128# doctext is not found
3129AC_PATH_PROG(DOCTEXT,doctext,false)
3130if test -n "$DOCTEXT" ; then
3131    if test -z "$DOCTEXTSYTLE" ; then
3132        AC_MSG_CHECKING([for location of doctext style files])
3133        dpath=`doctext -debug_paths 2>&1 | grep 'default path' | \
3134              sed -e 's%.*default path\(.*\),%\1:%g'`
3135        saveIFS="$IFS"
3136        IFS=": "
3137        for dir in $dpath ; do
3138            if test -s $dir/refman.sty ; then
3139               DOCTEXTSTYLE=$dir
3140               break
3141            fi
3142        done
3143        IFS="$saveIFS"
3144        if test -n "$DOCTEXTSTYLE" ; then
3145            AC_MSG_RESULT($DOCTEXTSTYLE)
3146        else
3147            AC_MSG_RESULT([unavailable])
3148        fi
3149    fi
3150fi
3151export DOCTEXT
3152export DOCTEXTSTYLE
3153AC_SUBST(DOCTEXT)
3154AC_SUBST(DOCTEXTSTYLE)
3155
3156# ----------------------------------------------------------------------------
3157# Check for C compiler characteristics
3158AC_C_CONST
3159PAC_C_VOLATILE
3160PAC_C_RESTRICT
3161AC_C_INLINE
3162PAC_C_GNU_ATTRIBUTE
3163# We need to check for the endianess in order to implement the
3164# "external32" representations.  This defines "WORDS_BIGENDIAN when
3165# the system is bigendian.
3166# As of autoconf 2.62, this macro takes an additional argument for systems
3167# that can produce object files for either endianess. 
3168# With the as-always-incompatible-with-every-version autoconf, the
3169# arguments for this macro *changed* in 2.62 to
3170# (if-bigendian,if-littleendian,unknown,universal)
3171# The fourth argument is new.
3172# Also note that the definition emitted by autoheader requires that gcc
3173# be used to compile the programs - other compilers may not define the
3174# non-standard __BIG_ENDIAN__ or __LITTLE_ENDIAN__ CPP names on which
3175# autoconf 2.62 now depends.
3176byteOrdering=unknown
3177AC_C_BIGENDIAN(byteOrdering=big,byteOrdering=little,,byteOrdering=universal)
3178case $byteOrdering in
3179    big)
3180    # Nothing to do - the c_bigendian macro takes care of it
3181    :
3182    ;;
3183    little)
3184    AC_DEFINE(WORDS_LITTLEENDIAN,1,[Define if words are little endian])
3185    ;;
3186    universal)
3187    AC_DEFINE(WORDS_UNIVERSAL_ENDIAN,1,[Define if configure will not tell us, for universal binaries])
3188    ;;
3189    unknown)
3190    AC_MSG_ERROR([Unable to determine endianess])
3191    ;;
3192esac
3193
3194# We only need this test if we are using Fortran
3195if test "$enable_f77" ; then
3196    PAC_PROG_C_UNALIGNED_DOUBLES(,
3197[AC_MSG_WARN(Your C compiler $CC does not support unaligned accesses
3198to doubles.  This is required for interoperation with
3199Fortran (the Fortran standard requires it).
3200You may need to specify an additional argument to your C compiler to
3201force it to allow unaligned accesses.)])
3202fi
3203# Check for __func__ (defined in C99) or __FUNCTION__ (defined in older GCC)
3204AC_CACHE_CHECK([whether $CC supports __func__],pac_cv_cc_has___func__,
3205[AC_TRY_COMPILE([],
3206 [const char *cp = __func__; ],pac_cv_cc_has___func__=yes,
3207pac_cv_cc_has___func__=no)])
3208if test "$pac_cv_cc_has___func__" != "yes" ; then
3209    AC_CACHE_CHECK([whether $CC supports __FUNCTION__],pac_cv_cc_has___FUNCTION__,
3210[AC_TRY_COMPILE([],
3211 [const char *cp = __FUNCTION__;],pac_cv_cc_has___FUNCTION__=yes,
3212pac_cv_cc_has___FUNCTION__=no)])
3213fi
3214
3215# ----------------------------------------------------------------------------
3216# Attempt to support dependency handling
3217# ----------------------------------------------------------------------------
3218# Set a default for MAKE_DEPEND_C
3219MAKE_DEPEND_C=true
3220AC_SUBST(MAKE_DEPEND_C)
3221AC_ARG_ENABLE(dependencies,[
3222--enable-dependencies - Generate dependencies for sourcefiles.  This
3223            requires that the Makefile.in files are also created
3224            to support dependencies (see maint/updatefiles)],,
3225enable_dependencies=default)
3226#
3227#
3228if test -z "$enable_dependencies" ; then
3229   enable_dependencies=default
3230fi
3231if test "$enable_dependencies" = "default" ; then
3232    # Try to use gcc if available
3233    enable_dependencies=no
3234    if test "$ac_cv_prog_gcc" != "yes" ; then
3235         # See if gcc is available
3236         AC_CHECK_PROGS(GCC,gcc)
3237         if test -n "$GCC" ; then
3238             enable_dependencies=gcc
3239         else
3240             # Try for another form, based on the stock compiler on the
3241             # given system
3242             ostype=`uname -s`
3243             case "$ostype" in
3244                 SunOS)
3245                 enable_dependencies=solaris
3246                 ;;
3247                 *)
3248                 # Unrecognized; ignore
3249                 ;;
3250             esac
3251         fi
3252    else
3253        enable_dependencies=gcc
3254    fi
3255    # We use this to indicate that we use gcc for dependencies,
3256    # even if a different compiler (e.g., pgcc) is selected for
3257    # compiling the code.  This will normally be adequate, even
3258    # if gcc points to different system header files, we're really
3259    # only interested in dependencies on the MPICH2 source files.
3260    if test "$enable_dependencies" = "gcc" ; then
3261        AC_MSG_RESULT([Using gcc to determine dependencies])
3262    fi
3263fi
3264if test "$enable_dependencies" != "no" ; then
3265   case "$enable_dependencies" in
3266   gcc|yes)
3267        # Ensure that the profiling libraries get their targets into
3268        # the files.  Use -MMD if you want the file in the build directory
3269        # instead of a subdirectory
3270        MAKE_DEPEND_C="gcc -MM"
3271    ;;
3272    solaris)
3273        # At least some Solaris SunPro compilers accept -xM1 -MT name, though
3274        # they ignore the -MT name argument.
3275        MAKE_DEPEND_C="cc -xM1"
3276    ;;
3277    *) 
3278        AC_MSG_RESULT([Using $enable_dependencies for MAKE_DEPEND_C])
3279        MAKE_DEPEND_C="$enable_dependencies"
3280    ;; 
3281    esac               
3282fi
3283export MAKE_DEPEND_C
3284# ----------------------------------------------------------------------------
3285# Check on support for long double and long long types.  Do this before the
3286# structure alignment test because it will test for including those
3287# types as well.  In addition, allow the device to suppress support for these
3288# optional C types by setting MPID_NO_LONG_DOUBLE and/or MPID_NO_LONG_LONG
3289# to yes.
3290if test "$MPID_NO_LONG_DOUBLE" != "yes" ; then
3291    AC_CACHE_CHECK([whether long double is supported],
3292    pac_cv_have_long_double,[
3293    AC_TRY_COMPILE(,[long double a;],
3294    pac_cv_have_long_double=yes,pac_cv_have_long_double=no)])
3295    if test "$pac_cv_have_long_double" = "yes" ; then
3296        AC_DEFINE(HAVE_LONG_DOUBLE,1,[Define if long double is supported])
3297    fi
3298fi
3299if test "$MPID_NO_LONG_LONG" != "yes" ; then
3300    AC_CACHE_CHECK([whether long long is supported],
3301    pac_cv_have_long_long,[
3302    AC_TRY_COMPILE(,[long long a;],
3303    pac_cv_have_long_long=yes,pac_cv_have_long_long=no)])
3304    if test "$pac_cv_have_long_long" = "yes" ; then
3305        AC_DEFINE(HAVE_LONG_LONG_INT,1,[Define if long long is supported])
3306    fi
3307fi
3308# ----------------------------------------------------------------------------
3309# Get default structure alignment for integers
3310dnl PAC_C_MAX_INTEGER_ALIGN places the default alignment into
3311dnl pac_cv_c_max_integer_align, with possible values including
3312dnl packed (byte), largest, two, four, eight (or other failure message).
3313PAC_C_MAX_INTEGER_ALIGN
3314
3315if test "$pac_cv_c_max_integer_align" = "packed" ; then
3316    pac_cv_c_struct_align_nr=1
3317elif test "$pac_cv_c_max_integer_align" = "two" ; then
3318    pac_cv_c_struct_align_nr=2
3319elif test "$pac_cv_c_max_integer_align" = "four" ; then
3320    pac_cv_c_struct_align_nr=4
3321elif test "$pac_cv_c_max_integer_align" = "eight" ; then
3322    pac_cv_c_struct_align_nr=8
3323elif test "$pac_cv_c_max_integer_align" = "largest" ; then
3324    AC_DEFINE(HAVE_LARGEST_STRUCT_ALIGNMENT,1,[Define when alignment of structures is based on largest component])
3325fi
3326
3327if test -n "$pac_cv_c_struct_align_nr" ; then
3328    AC_DEFINE_UNQUOTED(HAVE_MAX_INTEGER_ALIGNMENT,$pac_cv_c_struct_align_nr,[Controls byte alignment of integer structures (for MPI structs)])
3329    AC_DEFINE_UNQUOTED(HAVE_MAX_STRUCT_ALIGNMENT,$pac_cv_c_struct_align_nr,[Controls byte alignment of structures (for aligning allocated structures)])
3330fi
3331# Get default structure alignment for floating point types
3332dnl PAC_C_MAX_FP_ALIGN places the default alignment into
3333dnl pac_cv_c_max_fp_align, with possible values including
3334dnl packed (byte), largest, two, four, eight (or other failure message).
3335PAC_C_MAX_FP_ALIGN
3336
3337if test "$pac_cv_c_max_fp_align" = "packed" ; then
3338    pac_cv_c_fp_align_nr=1
3339elif test "$pac_cv_c_max_fp_align" = "two" ; then
3340    pac_cv_c_fp_align_nr=2
3341elif test "$pac_cv_c_max_fp_align" = "four" ; then
3342    pac_cv_c_fp_align_nr=4
3343elif test "$pac_cv_c_max_fp_align" = "eight" ; then
3344    pac_cv_c_fp_align_nr=8
3345elif test "$pac_cv_c_max_fp_align" = "sixteen" ; then
3346    pac_cv_c_fp_align_nr=16
3347elif test "$pac_cv_c_max_fp_align" = "largest" ; then
3348    AC_MSG_ERROR([Configure detected unsupported structure alignment rules.  Please email mpich2-maint@mcs.anl.gov with complete configure output and information on architecture.])
3349fi
3350
3351if test -n "$pac_cv_c_fp_align_nr" ; then
3352    AC_DEFINE_UNQUOTED(HAVE_MAX_FP_ALIGNMENT,$pac_cv_c_fp_align_nr,[Controls byte alignment of structures with floats, doubles, and long doubles (for MPI structs)])
3353fi
3354
3355# Test for the alignment of structs containing only long doubles.
3356if test "$pac_cv_have_long_double" = yes ; then
3357    # Check for alignment of just float and double (no long doubles)
3358    PAC_C_MAX_DOUBLE_FP_ALIGN
3359    PAC_C_MAX_LONGDOUBLE_FP_ALIGN
3360    # FIXME: If this alignment is not the same as that for all float types,
3361    # we need to do something else in the alignment rule code.
3362    if test "$pac_cv_c_max_fp_align" != "$pac_cv_c_max_longdouble_fp_align" -o \
3363            "$pac_cv_c_max_fp_align" != "$pac_cv_c_max_double_fp_align" ; then
3364        AC_MSG_WARN([Structures containing long doubles may be aligned differently from structures with floats or longs.  MPICH2 does not handle this case automatically and you should avoid assumed extents for structures containing float types.])
3365
3366        double_align=-1
3367        case $pac_cv_c_max_double_fp_align in
3368        packed) double_align=1 ;;
3369        two)    double_align=2 ;;
3370        four)   double_align=4 ;;
3371        eight)  double_align=8 ;;
3372        esac
3373        longdouble_align=-1
3374        case $pac_cv_c_max_longdouble_fp_align in
3375        packed) longdouble_align=1 ;;
3376        two)    longdouble_align=2 ;;
3377        four)   longdouble_align=4 ;;
3378        eight)  longdouble_align=8 ;;
3379        sixteen)longdouble_align=16 ;;
3380        esac
3381       
3382        AC_DEFINE_UNQUOTED(HAVE_MAX_DOUBLE_FP_ALIGNMENT,$double_align,[Controls byte alignment of structs with doubles])
3383        AC_DEFINE_UNQUOTED(HAVE_MAX_LONG_DOUBLE_FP_ALIGNMENT,$longdouble_align,[Controls byte alignment of structs with long doubles])
3384    fi
3385fi
3386
3387# Test for weird struct alignment rules that vary padding based on
3388# size of leading type only.
3389PAC_C_DOUBLE_POS_ALIGN
3390if test "$pac_cv_c_double_pos_align" = "yes" ; then
3391    AC_DEFINE_UNQUOTED(HAVE_DOUBLE_POS_ALIGNMENT,1,[Controls how alignment is applied based on position of doubles in the structure])
3392fi
3393
3394# Test for same weird issues with long long int.
3395PAC_C_LLINT_POS_ALIGN
3396if test "$pac_cv_c_llint_pos_align" = "yes" ; then
3397   AC_DEFINE_UNQUOTED(HAVE_LLINT_POS_ALIGNMENT,1,[Controls how alignment is applied based on position of long long ints in the structure])
3398fi
3399
3400# Test for double alignment not following all our other carefully constructed rules
3401PAC_C_DOUBLE_ALIGNMENT_EXCEPTION
3402if test "$pac_cv_c_double_alignment_exception" = "four" ; then
3403   AC_DEFINE_UNQUOTED(HAVE_DOUBLE_ALIGNMENT_EXCEPTION,4,[Controls how alignment of doubles is performed, separate from other FP values])
3404fi
3405
3406# Test whether pointers can be aligned on a int boundary or require
3407# a pointer boundary.
3408AC_MSG_CHECKING([for alignment restrictions on pointers])
3409AC_TRY_RUN(
3410changequote(<<,>>)
3411struct foo { int a; void *b; };
3412int main() {
3413    int buf[10];
3414    struct foo *p1;
3415    p1=(struct foo*)&buf[0];
3416    p1->b = (void *)0;
3417    p1=(struct foo*)&buf[1];
3418    p1->b = (void *)0;
3419    return 0;
3420changequote([,])
3421},pac_cv_pointers_have_int_alignment=yes,pac_cv_pointers_have_int_alignment=no,pac_cv_pointers_have_int_alignment=unknown)
3422
3423if test "$pac_cv_pointers_have_int_alignment" != "yes" ; then
3424   AC_DEFINE(NEEDS_POINTER_ALIGNMENT_ADJUST,1,[define if pointers must be aligned on pointer boundaries])
3425   AC_MSG_RESULT([pointer])
3426else
3427   AC_MSG_RESULT([int or better])
3428fi
3429
3430# There are further alignment checks after we test for int64_t etc. below.
3431
3432# Get the size of the C types for encoding in the basic datatypes and for
3433# the specific-sized integers
3434AC_CHECK_SIZEOF(char,$CROSS_SIZEOF_CHAR)
3435AC_CHECK_SIZEOF(unsigned char,$CROSS_SIZEOF_UCHAR)
3436AC_CHECK_SIZEOF(short,$CROSS_SIZEOF_SHORT)
3437AC_CHECK_SIZEOF(unsigned short,$CROSS_SIZEOF_USHORT)
3438AC_CHECK_SIZEOF(int,$CROSS_SIZEOF_INT)
3439AC_CHECK_SIZEOF(unsigned int,$CROSS_SIZEOF_UINT)
3440AC_CHECK_SIZEOF(long,$CROSS_SIZEOF_LONG)
3441AC_CHECK_SIZEOF(unsigned long,$CROSS_SIZEOF_ULONG)
3442AC_CHECK_SIZEOF(long long,$CROSS_SIZEOF_LONG_LONG)
3443AC_CHECK_SIZEOF(unsigned long long,$CROSS_SIZEOF_ULONG_LONG)
3444AC_CHECK_SIZEOF(float,$CROSS_SIZEOF_FLOAT)
3445AC_CHECK_SIZEOF(double,$CROSS_SIZEOF_DOUBLE)
3446AC_CHECK_SIZEOF(long double,$CROSS_SIZEOF_LONG_DOUBLE)
3447AC_CHECK_SIZEOF(wchar_t,$CROSS_SIZEOF_WCHAR_T)
3448# wchar_t is sometimes defined in stddef.h.  If we got a zero for its
3449# size, and we have stddef.h, try again with an explicit test
3450if test "$ac_cv_sizeof_wchar_t" = 0 ; then
3451    # See if we have stddef
3452    AC_CHECK_HEADERS(stddef.h)
3453    if test "$ac_cv_header_stddef_h" = yes ; then
3454        # Do not use cache check since we don't want to use
3455        # any cached value
3456        AC_MSG_CHECKING([for sizeof wchar_t])
3457        rm -f conftestval
3458        AC_TRY_RUN([#include <stdio.h>
3459#include <stddef.h>
3460main()
3461{
3462  wchar_t a;
3463  FILE *f=fopen("conftestval", "w");
3464  if (!f) exit(1);
3465  fprintf(f, "%d\n", sizeof(a));
3466  exit(0);
3467}],ac_cv_sizeof_wchar_t=`cat conftestval`,ac_cv_sizeof_wchar_t=0,ac_cv_sizeof_wchar_t=$CROSS_SIZEOF_WCHAR_T)
3468        AC_MSG_RESULT($ac_cv_sizeof_wchar_t)
3469        rm -f conftestval
3470    fi
3471fi
3472AC_CHECK_SIZEOF(void *,$CROSS_SIZEOF_VOID_P)
3473PAC_CHECK_SIZEOF_2TYPES(float int, float, int, $CROSS_SIZEOF_FLOAT_INT)
3474PAC_CHECK_SIZEOF_2TYPES(double int, double, int, $CROSS_SIZEOF_DOUBLE_INT)
3475PAC_CHECK_SIZEOF_2TYPES(long int, long, int, $CROSS_SIZEOF_LONG_INT)
3476PAC_CHECK_SIZEOF_2TYPES(short int, short, int, $CROSS_SIZEOF_SHORT_INT)
3477PAC_CHECK_SIZEOF_2TYPES(2 int, int, int, $CROSS_SIZEOF_2_INT)
3478PAC_CHECK_SIZEOF_2TYPES(long double int, long double, int, $CROSS_SIZEOF_LONG_DOUBLE_INT)
3479
3480dnl # The following code is correct for the EXTENT, but not the size,
3481dnl # of these types.
3482dnl PAC_CHECK_SIZEOF_DERIVED(float int,[struct { float a; int b; }],$CROSS_EXTENTOF_FLOAT_INT)
3483dnl PAC_CHECK_SIZEOF_DERIVED(double int,[struct { double a; int b; }],$CROSS_EXTENTOF_DOUBLE_INT)
3484dnl PAC_CHECK_SIZEOF_DERIVED(long int,[struct { long a; int b; }],$CROSS_EXTENTOF_LONG_INT)
3485dnl PAC_CHECK_SIZEOF_DERIVED(short int,[struct { short a; int b; }],$CROSS_EXTENTOF_SHORT_INT)
3486dnl PAC_CHECK_SIZEOF_DERIVED(2 int,[struct { int a; int b; }],$CROSS_EXTENTOF_2_INT)
3487dnl PAC_CHECK_SIZEOF_DERIVED(long double int,[struct { long double a; int b; }],$CROSS_EXTENTOF_LONG_DOUBLE_INT)
3488
3489# sys/bitypes.h defines the int16_t etc. on some systems (e.g., OSF1).
3490# Include it when testing for these types
3491AC_CHECK_HEADER(sys/bitypes.h,[use_bitypes="#include <sys/bitypes.h>"
3492AC_DEFINE(HAVE_SYS_BITYPES_H,1,[Define if sys/bitypes.h exists])])
3493# A C99 compliant compiler should have inttypes.h for fixed-size int types
3494AC_CHECK_HEADERS(inttypes.h stdint.h)
3495
3496# Check for types
3497AC_TYPE_INT8_T
3498AC_TYPE_INT16_T
3499AC_TYPE_INT32_T
3500AC_TYPE_INT64_T
3501
3502# Temporary backwards compatiblity for the pre autoconf 2.62 integer
3503# type checking
3504if test "$ac_cv_c_int8_t" != no ; then
3505    AC_DEFINE(HAVE_INT8_T,1,[Define if int8_t is supported by the C compiler])
3506fi
3507if test "$ac_cv_c_int16_t" != no ; then
3508    AC_DEFINE(HAVE_INT16_T,1,[Define if int16_t is supported by the C compiler])
3509fi
3510if test "$ac_cv_c_int32_t" != no ; then
3511    AC_DEFINE(HAVE_INT32_T,1,[Define if int32_t is supported by the C compiler])
3512fi
3513if test "$ac_cv_c_int64_t" != no ; then
3514    AC_DEFINE(HAVE_INT64_T,1,[Define if int64_t is supported by the C compiler])
3515fi
3516
3517# The following make these definitions:
3518#   define _UINT<n>_T 1
3519# if uint<n>_t is available.  E.g., define _UINT8_T as 1 if uint8_t is available
3520# if not available, define uint<n>_t as the related C type, e.g.,
3521#   define uint8_t unsigned char
3522#
3523AC_TYPE_UINT8_T
3524AC_TYPE_UINT16_T
3525AC_TYPE_UINT32_T
3526AC_TYPE_UINT64_T
3527
3528# Temporary backwards compatiblity for the pre autoconf 2.62 integer
3529# type checking
3530if test "$ac_cv_c_uint8_t" != no ; then
3531    AC_DEFINE(HAVE_UINT8_T,1,[Define if uint8_t is supported by the C compiler])
3532fi
3533if test "$ac_cv_c_uint16_t" != no ; then
3534    AC_DEFINE(HAVE_UINT16_T,1,[Define if uint16_t is supported by the C compiler])
3535fi
3536if test "$ac_cv_c_uint32_t" != no ; then
3537    AC_DEFINE(HAVE_UINT32_T,1,[Define if uint32_t is supported by the C compiler])
3538fi
3539if test "$ac_cv_c_uint64_t" != no ; then
3540    AC_DEFINE(HAVE_UINT64_T,1,[Define if uint64_t is supported by the C compiler])
3541fi
3542
3543# Generate a hex version of the size of each type
3544for type in short int long long_long float double long_double wchar_t \
3545    float_int double_int long_int short_int 2_int long_double_int ; do
3546    eval len=\$ac_cv_sizeof_$type
3547    if test -z "$len" ; then
3548       len=0
3549       # Check for sizes from the CHECK_SIZEOF_DERIVED macro
3550       eval pclen=\$pac_cv_sizeof_$type
3551       if test -n "$pclen" ; then
3552           len=$pclen
3553       else
3554           # check for a non-optional type
3555           if test $type != long_long -a $type != long_double -a \
3556                   $type != long_double_int ; then
3557               AC_MSG_ERROR([Configure was unable to determine the size of $type ; if cross compiling,
3558use the environment variables CROSS_SIZEOF_typename, e.g., CROSS_SIZEOF_SHORT,
3559or use the --with-cross=file configure option to specify a file containing
3560Bourne (sh) shell assignments to CROSS_SIZEOF_typename for all datatype
3561types.  The program maint/getcross.c can be compiled and run on the target
3562system; this program outputs an appropriate file for the --with-cross option])
3563           fi
3564       fi
3565    fi
3566    #
3567    # Take len and turn it into two hex digits (there are 8 bits available
3568    # in the built-in datatype handle for the length; see
3569    # src/mpid/common/datatype/mpid_datatype.h)
3570    if test "$len" -gt 255 ; then
3571         AC_MSG_ERROR([Type sizes greater than 255 bytes are not supported (type $type is $len bytes)])
3572    fi
3573    tmplen=$len
3574    hexlen=""
3575    while test $tmplen -gt 0 ; do
3576        lowdigit=`expr $tmplen - 16 \* \( $tmplen / 16 \)`
3577        case $lowdigit in
3578         10) char=a ;;
3579         11) char=b ;;
3580         12) char=c ;;
3581         13) char=d ;;
3582         14) char=e ;;
3583         15) char=f ;;
3584          *) char=$lowdigit ;;
3585        esac
3586        hexlen="$char$hexlen"
3587        tmplen=`expr $tmplen / 16`
3588    done
3589    if test $len -lt 16 ; then
3590        hexlen="0$hexlen"
3591    fi
3592    if test $len = 0 ; then
3593        # This sometimes happens for wchar_t
3594        hexlen="00";
3595    fi
3596    eval len_$type=$hexlen
3597done
3598# By definition, sizeof char is 1
3599MPI_CHAR="0x4c000101"
3600MPI_UNSIGNED_CHAR="0x4c000102"
3601MPI_SHORT="0x4c00${len_short}03"
3602MPI_UNSIGNED_SHORT="0x4c00${len_short}04"
3603MPI_INT="0x4c00${len_int}05"
3604MPI_UNSIGNED_INT="0x4c00${len_int}06"
3605MPI_LONG="0x4c00${len_long}07"
3606MPI_UNSIGNED_LONG="0x4c00${len_long}08"
3607if test "$len_long_long" != 0 -a "$MPID_NO_LONG_LONG" != yes ; then
3608    MPI_LONG_LONG="0x4c00${len_long_long}09"
3609else
3610    MPI_LONG_LONG=MPI_DATATYPE_NULL;
3611fi
3612MPI_FLOAT="0x4c00${len_float}0a"
3613MPI_DOUBLE="0x4c00${len_double}0b"
3614if test "$len_long_double" != 0 -a "$MPID_NO_LONG_DOUBLE" != yes ; then
3615    MPI_LONG_DOUBLE="0x4c00${len_long_double}0c"
3616else
3617    MPI_LONG_DOUBLE=MPI_DATATYPE_NULL
3618fi
3619# If you change MPI_BYTE, you must change it in src/binding/f77/buildiface
3620MPI_BYTE="0x4c00010d"
3621MPI_WCHAR="0x4c00${len_wchar_t}0e"
3622MPI_PACKED="0x4c00010f"
3623MPI_LB="0x4c000010"
3624MPI_UB="0x4c000011"
3625#
3626# These should define the mixed types *only* for contiguous data.
3627# For example, MPI_SHORT_INT may have a gap; it will need to be defined
3628# as a derived type instead.  For IA32, this only affects short_int.
3629MPI_2INT="0x4c00${len_2_int}16"
3630#
3631# For now we aren't being too clever about figuring out which of these
3632# are in fact contiguous, so these are all allocated as "real" types.
3633#
3634# These values correspond to direct types 0..5.
3635#
3636dnl MPI_FLOAT_INT="0x4c00${len_float_int}12"
3637dnl MPI_DOUBLE_INT="0x4c00${len_double_int}13"
3638dnl MPI_LONG_INT="0x4c00${len_long_int}14"
3639dnl MPI_SHORT_INT="0x4c00${len_short_int}15"
3640dnl MPI_LONG_DOUBLE_INT="0x4c00${len_long_double_int}17"
3641MPI_FLOAT_INT="0x8c000000"
3642MPI_DOUBLE_INT="0x8c000001"
3643MPI_LONG_INT="0x8c000002"
3644MPI_SHORT_INT="0x8c000003"
3645if test "$MPID_NO_LONG_DOUBLE" != yes ; then
3646    MPI_LONG_DOUBLE_INT="0x8c000004"
3647else
3648    MPI_LONG_DOUBLE_INT=MPI_DATATYPE_NULL
3649fi
3650
3651# 2 additional predefined types named in MPI-2
3652MPI_SIGNED_CHAR="0x4c000118"
3653if test "$len_long_long" != 0 -a "$MPID_NO_LONG_LONG" != yes ; then
3654    MPI_UNSIGNED_LONG_LONG="0x4c00${len_long_long}19"
3655else
3656    MPI_UNSIGNED_LONG_LONG=MPI_DATATYPE_NULL
3657fi
3658
3659AC_SUBST(MPI_CHAR)
3660AC_SUBST(MPI_UNSIGNED_CHAR)
3661AC_SUBST(MPI_SHORT)
3662AC_SUBST(MPI_UNSIGNED_SHORT)
3663AC_SUBST(MPI_INT)
3664AC_SUBST(MPI_UNSIGNED_INT)
3665AC_SUBST(MPI_LONG)
3666AC_SUBST(MPI_UNSIGNED_LONG)
3667AC_SUBST(MPI_LONG_LONG)
3668AC_SUBST(MPI_FLOAT)
3669AC_SUBST(MPI_DOUBLE)
3670AC_SUBST(MPI_LONG_DOUBLE)
3671AC_SUBST(MPI_BYTE)
3672AC_SUBST(MPI_WCHAR)
3673AC_SUBST(MPI_PACKED)
3674AC_SUBST(MPI_LB)
3675AC_SUBST(MPI_UB)
3676AC_SUBST(MPI_FLOAT_INT)
3677AC_SUBST(MPI_DOUBLE_INT)
3678AC_SUBST(MPI_LONG_INT)
3679AC_SUBST(MPI_SHORT_INT)
3680AC_SUBST(MPI_2INT)
3681AC_SUBST(MPI_LONG_DOUBLE_INT)
3682AC_SUBST(MPI_SIGNED_CHAR)
3683AC_SUBST(MPI_UNSIGNED_LONG_LONG)
3684#
3685# FIXME: Leftover from separate fortran system
3686## Export the basic C types so that the Fortran system can use them
3687#export MPI_CHAR
3688#export MPI_SHORT
3689#export MPI_INT
3690#export MPI_LONG
3691#export MPI_LONG_LONG
3692#export MPI_FLOAT
3693#export MPI_DOUBLE
3694#export MPI_LONG_DOUBLE
3695#
3696# Size-specific types.  Initialize as NULL
3697MPI_REAL4=MPI_DATATYPE_NULL
3698MPI_REAL8=MPI_DATATYPE_NULL
3699MPI_REAL16=MPI_DATATYPE_NULL
3700MPI_COMPLEX8=MPI_DATATYPE_NULL
3701MPI_COMPLEX16=MPI_DATATYPE_NULL
3702MPI_COMPLEX32=MPI_DATATYPE_NULL
3703MPI_INTEGER1=MPI_DATATYPE_NULL
3704MPI_INTEGER2=MPI_DATATYPE_NULL
3705MPI_INTEGER4=MPI_DATATYPE_NULL
3706MPI_INTEGER8=MPI_DATATYPE_NULL
3707MPI_INTEGER16=MPI_DATATYPE_NULL
3708AC_SUBST(MPI_REAL4)
3709AC_SUBST(MPI_REAL8)
3710AC_SUBST(MPI_REAL16)
3711AC_SUBST(MPI_COMPLEX8)
3712AC_SUBST(MPI_COMPLEX16)
3713AC_SUBST(MPI_COMPLEX32)
3714AC_SUBST(MPI_INTEGER1)
3715AC_SUBST(MPI_INTEGER2)
3716AC_SUBST(MPI_INTEGER4)
3717AC_SUBST(MPI_INTEGER8)
3718AC_SUBST(MPI_INTEGER16)
3719export MPI_REAL4
3720export MPI_REAL8
3721export MPI_REAL16
3722export MPI_COMPLEX8
3723export MPI_COMPLEX16
3724export MPI_COMPLEX32
3725export MPI_INTEGER1
3726export MPI_INTEGER2
3727export MPI_INTEGER4
3728export MPI_INTEGER8
3729export MPI_INTEGER16
3730#
3731# Try to find corresponding types for the size-specific types.
3732#
3733# Assume that the float/double/long double are simply spaced
3734# Datatypes used up through 26 in Fortran
3735# 27,28,29,2a,2b,2c
3736if test "$ac_cv_sizeof_float" = "4" ; then
3737    MPI_REAL4="0x4c000427"
3738    MPI_COMPLEX8="0x4c000828"
3739    MPIR_REAL4_CTYPE=float
3740fi
3741if test "$ac_cv_sizeof_double" = "8" ; then
3742    MPI_REAL8="0x4c000829"
3743    MPI_COMPLEX16="0x4c00102a"
3744    MPIR_REAL8_CTYPE=double
3745fi
3746if test "$ac_cv_sizeof_long_double" = "16" -a "$MPID_NO_LONG_DOUBLE" != yes ; then
3747    MPI_REAL16="0x4c00102b"
3748    MPI_COMPLEX32="0x4c00202c"
3749    MPIR_REAL16_CTYPE="long double"
3750fi
3751if test -n "$MPIR_REAL4_CTYPE" ; then
3752    AC_DEFINE_UNQUOTED(MPIR_REAL4_CTYPE,$MPIR_REAL4_CTYPE,[C type to use for MPI_REAL4])
3753fi
3754if test -n "$MPIR_REAL8_CTYPE" ; then
3755    AC_DEFINE_UNQUOTED(MPIR_REAL8_CTYPE,$MPIR_REAL8_CTYPE,[C type to use for MPI_REAL8])
3756fi
3757if test -n "$MPIR_REAL16_CTYPE" ; then
3758    AC_DEFINE_UNQUOTED(MPIR_REAL16_CTYPE,$MPIR_REAL16_CTYPE,[C type to use for MPI_REAL16])
3759fi
3760# For complex 8/16/32, we assume that these are 2 consequetive real4/8/16
3761#
3762# Search for the integer types
3763for type in char short int long long_long ; do
3764    # ctype is a valid C type which we can use to declare a C version of
3765    # this item
3766    ctype=`echo $type | sed 's/_/ /'`
3767    eval len=\$ac_cv_sizeof_$type
3768    if test -n "$len" ; then
3769    case $len in
3770    1) if test "$MPI_INTEGER1" = "MPI_DATATYPE_NULL" ; then
3771           MPI_INTEGER1="0x4c00012d"
3772           MPIR_INTEGER1_CTYPE="$ctype"
3773       fi
3774       ;;
3775    2) if test "$MPI_INTEGER2" = "MPI_DATATYPE_NULL" ; then
3776           MPI_INTEGER2="0x4c00022f"
3777           MPIR_INTEGER2_CTYPE="$ctype"
3778       fi
3779       ;;
3780    4) if test "$MPI_INTEGER4" = "MPI_DATATYPE_NULL" ; then
3781           MPI_INTEGER4="0x4c000430"
3782           MPIR_INTEGER4_CTYPE="$ctype"
3783       fi
3784       ;;
3785    8) if test "$MPI_INTEGER8" = "MPI_DATATYPE_NULL" ; then
3786           MPI_INTEGER8="0x4c000831"
3787           MPIR_INTEGER8_CTYPE="$ctype"
3788       fi
3789       ;;
3790    16) if test "$MPI_INTEGER16" = "MPI_DATATYPE_NULL" ; then
3791           MPI_INTEGER16="0x4c001032"
3792           MPIR_INTEGER16_CTYPE="$ctype"
3793       fi
3794       ;;
3795    *)
3796    ;;
3797    esac
3798    fi
3799done
3800#
3801# Add the definitions of these types
3802if test -n "$MPIR_INTEGER1_CTYPE" ; then
3803    AC_DEFINE_UNQUOTED(MPIR_INTEGER1_CTYPE,$MPIR_INTEGER1_CTYPE,[C type to use for MPI_INTEGER1])
3804fi
3805if test -n "$MPIR_INTEGER2_CTYPE" ; then
3806   AC_DEFINE_UNQUOTED(MPIR_INTEGER2_CTYPE,$MPIR_INTEGER2_CTYPE,[C type to use for MPI_INTEGER2])
3807fi
3808if test -n "$MPIR_INTEGER4_CTYPE" ; then
3809   AC_DEFINE_UNQUOTED(MPIR_INTEGER4_CTYPE,$MPIR_INTEGER4_CTYPE,[C type to use for MPI_INTEGER4])
3810fi
3811if test -n "$MPIR_INTEGER8_CTYPE" ; then
3812   AC_DEFINE_UNQUOTED(MPIR_INTEGER8_CTYPE,$MPIR_INTEGER8_CTYPE,[C type to use for MPI_INTEGER8])
3813fi
3814if test -n "$MPIR_INTEGER16_CTYPE" ; then
3815   AC_DEFINE_UNQUOTED(MPIR_INTEGER16_CTYPE,$MPIR_INTEGER16_CTYPE,[C type to use for MPI_INTEGER16])
3816fi
3817
3818# ----------------------------------------------------------------------------
3819# We can now create the Fortran versions of the datatype values, along with
3820# some of the other datatype-dependent sizes
3821
3822# There are two parts to handling the datatypes:
3823#    Convert the C datatype values to their Fortran equivalent.  This
3824#    involves converting the hex values for the C version into decimal
3825#    since standard Fortran does not have hex constants
3826#
3827#    Determine the existence of the Fortran 'sized' types and set those
3828#    values.
3829#
3830# In addition, we need to look at a few additional constants that depend
3831# on how the compiler sizes some datatypes.  These are:
3832#    STATIS_SIZE, ADDRESS_KIND, and OFFSET_KIND
3833#
3834# ----------------------------------------------------------------------------
3835if test "$enable_f77" = yes ; then
3836    # Up to size checking code in master configure.in (where it tries to
3837    # find the matching C sizes) as part of defining mpi_integer8 etc.
3838    # The results are available in pac_cv_sizeof_f77_<type>
3839    # Size is 0 if unknown or unavailable (or cross-compiling)
3840    # Due to limitations in autoconf, we cannot put these into a loop.
3841    # We also check integer to find the type of MPI_Fint
3842    #
3843    # Cross-compilation results can be included with the --with-cross=file
3844    # option.
3845    CROSS_F77_SIZEOF_INTEGER=${CROSS_F77_SIZEOF_INTEGER:-0}
3846    CROSS_F77_SIZEOF_REAL=${CROSS_F77_SIZEOF_REAL:-0}
3847    CROSS_F77_SIZEOF_DOUBLE_PRECISION=${CROSS_F77_SIZEOF_DOUBLE_PRECISION:-0}
3848    PAC_PROG_F77_CHECK_SIZEOF_EXT(integer,$CROSS_F77_SIZEOF_INTEGER)
3849    PAC_PROG_F77_CHECK_SIZEOF_EXT(real,$CROSS_F77_SIZEOF_REAL)
3850    PAC_PROG_F77_CHECK_SIZEOF_EXT(double precision,$CROSS_F77_SIZEOF_DOUBLE_PRECISION)
3851    AC_LANG_FORTRAN77
3852    # If we have sizes for real and double, we do not need to call
3853    # mpir_get_fsize at run time.
3854    # For the size-defined types (e.g., integer*2), we assume that if the
3855    # compiler allows it, it has the stated size.
3856    AC_CACHE_CHECK([whether integer*1 is supported],pac_cv_fort_integer1,[
3857    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*1 i])],
3858         pac_cv_fort_integer1=yes,
3859         pac_cv_fort_integer1=no)])
3860    AC_CACHE_CHECK([whether integer*2 is supported],pac_cv_fort_integer2,[
3861    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*2 i])],
3862        pac_cv_fort_integer2=yes,
3863        pac_cv_fort_integer2=no)])
3864    AC_CACHE_CHECK([whether integer*4 is supported],pac_cv_fort_integer4,[
3865    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*4 i])],
3866        pac_cv_fort_integer4=yes,
3867        pac_cv_fort_integer4=no)])
3868    AC_CACHE_CHECK([whether integer*8 is supported],pac_cv_fort_integer8,[
3869    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*8 i])],
3870        pac_cv_fort_integer8=yes,
3871        pac_cv_fort_integer8=no)])
3872    AC_CACHE_CHECK([whether integer*16 is supported],pac_cv_fort_integer16,[
3873    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*16 i])],
3874        pac_cv_fort_integer16=yes,
3875        pac_cv_fort_integer16=no)])
3876    AC_CACHE_CHECK([whether real*4 is supported],pac_cv_fort_real4,[
3877    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      real*4 a])],
3878        pac_cv_fort_real4=yes,
3879        pac_cv_fort_real4=no)])
3880    AC_CACHE_CHECK([whether real*8 is supported],pac_cv_fort_real8,[
3881    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      real*8 a])],
3882        pac_cv_fort_real8=yes,
3883        pac_cv_fort_real8=no)])
3884    AC_CACHE_CHECK([whether real*16 is supported],pac_cv_fort_real16,[
3885    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      real*16 a])],
3886        pac_cv_fort_real16=yes,
3887        pac_cv_fort_real16=no)])
3888
3889    # Create the default datatype names for the standard MPI Fortran types
3890    MPI_CHARACTER=0x4c00011a
3891    AC_SUBST(MPI_CHARACTER)
3892
3893    if test -z "$pac_cv_f77_sizeof_integer" ; then
3894        AC_MSG_ERROR([Unable to configure with Fortran support because configure could not determine the size of a Fortran INTEGER.  Consider setting CROSS_F77_SIZEOF_INTEGER to the length in bytes of a Fortran INTEGER])
3895    fi
3896    len_integer=$pac_cv_f77_sizeof_integer
3897    # Convert to two digit hex
3898    len=$len_integer
3899    #
3900    # Take len and turn it into two hex digits (there are 8 bits available
3901    # in the built-in datatype handle for the length; see
3902    # src/mpid/common/datatype/mpid_datatype.h).  This code is taken
3903    # from the code in mpich2/configure.in
3904    if test "$len" -gt 255 ; then
3905        AC_MSG_ERROR([Type sizes greater than 255 bytes are not supported (type INTEGER is $len bytes)])
3906    fi
3907    tmplen=$len
3908    hexlen=""
3909    while test $tmplen -gt 0 ; do
3910        lowdigit=`expr $tmplen - 16 \* \( $tmplen / 16 \)`
3911        case $lowdigit in
3912        10) char=a ;;
3913        11) char=b ;;
3914        12) char=c ;;
3915        13) char=d ;;
3916        14) char=e ;;
3917        15) char=f ;;
3918         *) char=$lowdigit ;;
3919        esac
3920        hexlen="$char$hexlen"
3921        tmplen=`expr $tmplen / 16`
3922    done
3923    if test $len -lt 16 ; then
3924        hexlen="0$hexlen"
3925    fi
3926    len_integer=$hexlen
3927    if test "$len_integer" = 0 ; then
3928        # We have a problem
3929        AC_MSG_WARN([Unable to determine size of an INTEGER type; using 4])
3930        # We make the length 4
3931        len_integer="04"
3932    fi
3933    MPI_INTEGER=0x4c00${len_integer}1b
3934    MPI_REAL=0x4c00${len_integer}1c
3935    MPI_LOGICAL=0x4c00${len_integer}1d
3936    AC_SUBST(MPI_INTEGER)
3937    AC_SUBST(MPI_REAL)
3938    AC_SUBST(MPI_LOGICAL)
3939
3940    if test -z "$pac_cv_f77_sizeof_double_precision" ; then
3941        AC_MSG_ERROR([Unable to configure with Fortran support because configure could not determine the size of a Fortran DOUBLE PRECISION.  Consider setting CROSS_F77_SIZEOF_DOUBLE_PRECISION to the length in bytes of a Fortran DOUBLE PRECISION])
3942    fi
3943    len_double=$pac_cv_f77_sizeof_double_precision
3944    # Convert to two digit hex
3945    len=$len_double
3946    #
3947    # Take len and turn it into two hex digits (there are 8 bits available
3948    # in the built-in datatype handle for the length; see
3949    # src/mpid/common/datatype/mpid_datatype.h).  This code is taken
3950    # from the code in mpich2/configure.in
3951    if test "$len" -gt 255 ; then
3952        AC_MSG_ERROR([Type sizes greater than 255 bytes are not supported (type DOUBLE is $len bytes)])
3953    fi
3954    tmplen=$len
3955    hexlen=""
3956    while test $tmplen -gt 0 ; do
3957        lowdigit=`expr $tmplen - 16 \* \( $tmplen / 16 \)`
3958        case $lowdigit in
3959        10) char=a ;;
3960        11) char=b ;;
3961        12) char=c ;;
3962        13) char=d ;;
3963        14) char=e ;;
3964        15) char=f ;;
3965         *) char=$lowdigit ;;
3966        esac
3967        hexlen="$char$hexlen"
3968        tmplen=`expr $tmplen / 16`
3969    done
3970    if test $len -lt 16 ; then
3971        hexlen="0$hexlen"
3972    fi
3973    len_double=$hexlen
3974    if test "$len_double" = 0 ; then
3975       # We have a problem
3976       AC_MSG_WARN([Unable to determine size of a DOUBLE PRECISION type; using 8])
3977       # We make the length 8
3978       len_double="08"
3979    fi
3980    MPI_COMPLEX=0x4c00${len_double}1e
3981    MPI_DOUBLE_PRECISION=0x4c00${len_double}1f
3982    MPI_2INTEGER=0x4c00${len_double}20
3983    MPI_2REAL=0x4c00${len_double}21
3984    AC_SUBST(MPI_COMPLEX)
3985    AC_SUBST(MPI_DOUBLE_PRECISION)
3986    AC_SUBST(MPI_2INTEGER)
3987    AC_SUBST(MPI_2REAL)
3988
3989    len_doublecplx=`expr $pac_cv_f77_sizeof_double_precision \* 2`
3990    if test "$len_doublecplx" = 0 ; then
3991        # We have a problem
3992        AC_MSG_WARN([Unable to determine size of a DOUBLE PRECISION type; using 8])
3993        # We make the length 8*2 (in hex)
3994        len_doublecplx="16"
3995    fi
3996    len=$len_doublecplx
3997    #
3998    # Take len and turn it into two hex digits (there are 8 bits available
3999    # in the built-in datatype handle for the length; see
4000    # src/mpid/common/datatype/mpid_datatype.h).  This code is taken
4001    # from the code in mpich2/configure.in
4002    if test "$len" -gt 255 ; then
4003        AC_MSG_ERROR([Type sizes greater than 255 bytes are not supported (type DOUBLE COMPLEX is $len bytes)])
4004    fi
4005    tmplen=$len
4006    hexlen=""
4007    while test $tmplen -gt 0 ; do
4008        lowdigit=`expr $tmplen - 16 \* \( $tmplen / 16 \)`
4009        case $lowdigit in
4010        10) char=a ;;
4011        11) char=b ;;
4012        12) char=c ;;
4013        13) char=d ;;
4014        14) char=e ;;
4015        15) char=f ;;
4016         *) char=$lowdigit ;;
4017        esac
4018        hexlen="$char$hexlen"
4019        tmplen=`expr $tmplen / 16`
4020    done
4021    if test $len -lt 16 ; then
4022        hexlen="0$hexlen"
4023    fi
4024    len_doublecplx=$hexlen
4025
4026    MPI_DOUBLE_COMPLEX=0x4c00${len_doublecplx}22
4027    MPI_2DOUBLE_PRECISION=0x4c00${len_doublecplx}23
4028    MPI_2COMPLEX=0x4c00${len_doublecplx}24
4029    AC_SUBST(MPI_DOUBLE_COMPLEX)
4030    AC_SUBST(MPI_2DOUBLE_PRECISION)
4031    AC_SUBST(MPI_2COMPLEX)
4032
4033    #
4034    # Temporary for the vast majority of systems that use 4 byte reals and
4035    # 8 byte doubles
4036    # Lengths at this point are in hex, hence "10" = 10 base 16 = 16 base 10.
4037    if test "$len_double" = "08" ; then
4038        F77_COMPLEX8=$MPI_COMPLEX
4039    fi
4040    if test "$len_doublecplx" = "10" ; then
4041        F77_COMPLEX16=$MPI_DOUBLE_COMPLEX
4042    fi
4043    if test "$len_long_double" = "10" -a "$MPID_NO_LONG_DOUBLE" != "yes" ; then
4044        F77_COMPLEX32="0x4c002025"
4045    else
4046        F77_COMPLEX32="MPI_DATATYPE_NULL"
4047    fi
4048
4049    len_2dc=`expr $pac_cv_f77_sizeof_double_precision \* 4`
4050    firstdigit=0
4051    seconddigit=0
4052    while test $len_2dc -ge 16 ; do
4053        firstdigit=`expr $firstdigit + 1`
4054        len_2dc=`expr $len_2dc - 16`   
4055    done
4056    case $len_2dc in
4057        10) seconddigit=a ;;
4058        11) seconddigit=b ;;
4059        12) seconddigit=c ;;
4060        13) seconddigit=d ;;
4061        14) seconddigit=e ;;
4062        15) seconddigit=f ;;
4063         *) seconddigit=$len_2dc ;;
4064    esac
4065    len_2dc="$firstdigit$seconddigit"
4066    #echo "2double complex = $len_2dc"
4067    MPI_2DOUBLE_COMPLEX=0x4c00${len_2dc}25
4068    AC_SUBST(MPI_2DOUBLE_COMPLEX)
4069    MPI_F77_PACKED=$MPI_PACKED
4070    MPI_F77_UB=$MPI_UB
4071    MPI_F77_LB=$MPI_LB
4072    MPI_F77_BYTE=$MPI_BYTE
4073    AC_SUBST(MPI_F77_PACKED)
4074    AC_SUBST(MPI_F77_UB)
4075    AC_SUBST(MPI_F77_LB)
4076    AC_SUBST(MPI_F77_BYTE)
4077    #
4078    # We must convert all hex values to decimal (!)
4079    # It would be nice to use expr to extract the next character rather than
4080    # the heavier-weight sed, but expr under Tru64 Unix discards leading zeros,
4081    # even when used only with the match (:) command.  Rather than have
4082    # configure figure out if expr works, we just use sed.  Sigh.
4083    for var in CHARACTER INTEGER REAL LOGICAL DOUBLE_PRECISION COMPLEX \
4084        DOUBLE_COMPLEX 2INTEGER 2REAL 2COMPLEX 2DOUBLE_PRECISION \
4085        2DOUBLE_COMPLEX F77_PACKED F77_UB F77_LB F77_BYTE; do 
4086        fullvar="MPI_$var"
4087        eval fullvarvalue=\$$fullvar
4088        #echo "$fullvar = $fullvarvalue"
4089        value=0
4090        fullvarvalue=`echo $fullvarvalue | sed -e 's/..\(.*\)/\1/'`
4091        for pos in 3 4 5 6 7 8 9 10 ; do
4092            # This works, even for Tru64, because only a single character
4093            # is extracted
4094            char=`expr $fullvarvalue : '\(.\)'`
4095            # FIXME: Tru64 Unix eliminates leading zeros (!)
4096            # How do we fix something that broken?
4097            fullvarvalue=`echo $fullvarvalue | sed -e 's/.\(.*\)/\1/'`
4098            case $char in
4099                a) char=10 ;;
4100                b) char=11 ;;
4101                c) char=12 ;;
4102                d) char=13 ;;
4103                e) char=14 ;;
4104                f) char=15 ;;
4105            esac
4106            value=`expr $value \* 16 + $char`
4107        done
4108        #echo "$fullvar = $value"
4109        eval $fullvar=$value
4110    done
4111    AC_LANG_C
4112
4113    # Now, handle the sized types
4114    #
4115    # Preload the C mpi types
4116    # THESE MUST MATCH THE DEFINITIONS IN MPI.H and MPIF.H
4117    # We use these to match the optional Fortran types
4118    char_mpi=${MPI_CHAR:-0}
4119    short_mpi=${MPI_SHORT:-0}
4120    int_mpi=${MPI_INT:-0}
4121    long_mpi=${MPI_LONG:-0}
4122    long_long_mpi=${MPI_LONG_LONG:-0}
4123    float_mpi=${MPI_FLOAT:-0}
4124    double_mpi=${MPI_DOUBLE:-0}
4125    long_double_mpi=${MPI_LONG_DOUBLE:-0}
4126
4127    #
4128    # The following code was correct for MPI-1, which allowed these datatypes
4129    # to be an alias for another MPI type.  MPI-2 requires these to
4130    # be distinct types, so these are enumerated
4131    if test "$use_alias_types" = yes ; then
4132        for len in 1 2 4 8 16 ; do
4133            eval F77_INTEGER$len=0
4134            #eval testval=\$"pac_cv_f77_sizeof_integer_$len"
4135            eval testval=\$"pac_cv_fort_integer$len"
4136            if test "$testval" = no ; then continue ; fi
4137            testval=$len
4138            noval="yes"
4139            AC_MSG_CHECKING([for C type matching Fortran integer*$len])
4140            for c_type in char short int long "long_long" ; do
4141                eval ctypelen=\$"ac_cv_sizeof_$c_type"
4142                if test "$testval" = "$ctypelen" -a "$ctypelen" -gt 0 ; then
4143                    AC_MSG_RESULT($c_type)
4144                    eval F77_INTEGER$len=\$"${c_type}_mpi"
4145                    noval="no"
4146                    break
4147                fi
4148            done
4149            if test "$noval" = "yes" ; then
4150                AC_MSG_RESULT([unavailable])
4151            fi
4152        done
4153
4154        # Complex is set separately above
4155        for len in 4 8 16 ; do
4156            len2=`expr $len + $len`
4157            eval F77_REAL$len=0
4158            #eval F77_COMPLEX$len2=0
4159            #eval testval=\$"pac_cv_f77_sizeof_real_$len"
4160            eval testval=\$"pac_cv_fort_real$len"
4161            if test "$testval" = no ; then continue ; fi
4162            testval=$len
4163            noval="yes"
4164            AC_MSG_CHECKING([for C type matching Fortran real*$len])
4165            for c_type in float double "long_double" ; do
4166                eval ctypelen=\$"ac_cv_sizeof_$c_type"
4167                if test "$testval" = "$ctypelen" -a "$ctypelen" -gt 0 ; then
4168                    AC_MSG_RESULT($c_type)
4169                    eval F77_REAL$len=\$"${c_type}_mpi"
4170                    #eval F77_COMPLEX$len2=\$"${c_type}_cplx_mpi"
4171                    noval="no"
4172                    break
4173                fi
4174            done
4175            if test "$noval" = "yes" ; then
4176                AC_MSG_RESULT([unavailable])
4177            fi
4178        done
4179    else
4180        # Simply determine which types exist.  These may have been set by the
4181        # toplevel configure
4182        for var in INTEGER1 INTEGER2 INTEGER4 INTEGER8 INTEGER16 \
4183            REAL4 REAL8 REAL16 COMPLEX8 COMPLEX16 COMPLEX32 ; do 
4184            eval varname=MPI_$var
4185            eval varvalue=\$$varname
4186            #echo "$varname = $varvalue"
4187            if test "$varvalue" = MPI_DATATYPE_NULL ; then
4188                eval F77_$var=0
4189            else
4190                eval F77_$var=\$$varname
4191            fi
4192       done
4193    fi
4194    # We must convert all hex values to decimal (!)
4195    for var in INTEGER1 INTEGER2 INTEGER4 INTEGER8 INTEGER16 \
4196        REAL4 REAL8 REAL16 COMPLEX8 COMPLEX16 COMPLEX32 ; do 
4197        fullvar="F77_$var"
4198        eval fullvarvalue=\$$fullvar
4199        if test "$fullvarvalue" = 0 -o -z "$fullvarvalue" ; then
4200            eval $fullvar=MPI_DATATYPE_NULL
4201            continue
4202        fi
4203        #echo "$fullvar = $fullvarvalue"
4204        value=0
4205        # See the comments above on why expr with : cannot be used here
4206        fullvarvalue=`echo $fullvarvalue | sed -e 's/..\(.*\)/\1/'`
4207        for pos in 3 4 5 6 7 8 9 10 ; do
4208            #char=`expr substr $fullvarvalue $pos 1`
4209            char=`expr $fullvarvalue : '\(.\)'`
4210            # We don't test for success of expr here because some expr's are
4211            # buggy and set the status to one on expressions like
4212            #    expr 00ccc : '\(.\)'
4213            # while both
4214            #    expr 00ccc : '\(..\)'
4215            # and
4216            #    expr 100cc : '\(.\)'
4217            # return a zero status.  So the status is set even on success,
4218            # if the result is a single character that is a zero (!)
4219            #rc=$?
4220            #if test "$rc" != 0 ; then
4221            dnl #    AC_MSG_WARN([Failure (status $rc) in extracting first char from $fullvarvalue])
4222            #    break
4223            #fi
4224            fullvarvalue=`echo $fullvarvalue | sed -e 's/.\(.*\)/\1/'`
4225            case $char in
4226                a) char=10 ;;
4227                b) char=11 ;;
4228                c) char=12 ;;
4229                d) char=13 ;;
4230                e) char=14 ;;
4231                f) char=15 ;;
4232            esac
4233            value=`expr $value \* 16 + $char`
4234            if test $? != 0 ; then
4235                AC_MSG_WARN([Failure to evaluate $value \* 16 + $char])
4236            fi
4237        done
4238        #echo "$fullvar = $value"
4239        eval $fullvar=$value
4240    done
4241    AC_SUBST(F77_INTEGER1)
4242    AC_SUBST(F77_INTEGER2)
4243    AC_SUBST(F77_INTEGER4)
4244    AC_SUBST(F77_INTEGER8)
4245    AC_SUBST(F77_INTEGER16)
4246    AC_SUBST(F77_REAL4)
4247    AC_SUBST(F77_REAL8)
4248    AC_SUBST(F77_REAL16)
4249    AC_SUBST(F77_COMPLEX8)
4250    AC_SUBST(F77_COMPLEX16)
4251    AC_SUBST(F77_COMPLEX32)
4252
4253    noval="yes"
4254    AC_MSG_CHECKING([for C type matching Fortran integer])
4255    for c_type in char short int long "long_long" ; do
4256        eval ctypelen=\$"ac_cv_sizeof_$c_type"
4257        if test "$pac_cv_f77_sizeof_integer" = "$ctypelen" -a \
4258          "$ctypelen" -gt 0 ; then
4259            c_type=`echo $c_type | sed -e 's/_/ /g'`
4260            AC_MSG_RESULT($c_type)
4261            MPI_FINT=$c_type
4262            noval="no"
4263            break
4264        fi
4265    done
4266    if test "$noval" = "yes" ; then
4267        # Set a default
4268        MPI_FINT="int"
4269        AC_MSG_RESULT([unavailable])
4270    fi
4271    # We also need to check the size of MPI_Aint vs MPI_Fint, and
4272    # define AINT_LARGER_THAN_FINT if aint is larger (this
4273    # affects code in MPI_Address)
4274    if test "$ac_cv_sizeof_void_p" != "0" -a \
4275        "$ac_cv_sizeof_void_p" -gt "$pac_cv_f77_sizeof_integer" ; then
4276        AC_DEFINE(HAVE_AINT_LARGER_THAN_FINT,1,[Define if addresses are larger than Fortran integers])
4277    fi
4278    # Include a defined value for Fint is int
4279    if test "$MPI_FINT" = "int" ; then
4280        AC_DEFINE(HAVE_FINT_IS_INT,1,[Define if Fortran integer are the same size as C ints])
4281    elif test "$SIZEOF_F77_INTEGER" != "$ac_cv_sizeof_int" ; then
4282        # Make this fatal because we do not want to build a broken fortran
4283        # interface
4284        AC_MSG_ERROR([Fortran integers and C ints are not the same size.  The current Fortran binding does not support this case.  Either force the Fortran compiler to use integers of $ac_cv_sizeof_int bytes, or use --disable-f77 on the configure line for MPICH2.])
4285    fi
4286
4287    #
4288    # Set size of MPI_Status.  We may need sizeof_int here as well
4289    #
4290
4291    #
4292    # The size of MPI_Status is needed for the Fortran interface.
4293    # This is not quite right unless the device setup script, executed above,
4294    # sets the EXTRA_STATUS_DECL that will be used in defining a status.
4295    # The default size assumes that there are 5 ints
4296    default_status_size=`expr 5 \* $ac_cv_sizeof_int`
4297    AC_CACHE_CHECK([for size of MPI_Status],pac_cv_sizeof_mpi_status,[
4298    AC_TRY_RUN([
4299#include "confdefs.h"
4300#include <stdio.h>
4301#ifdef HAVE_STDLIB_H
4302#include <stdlib.h>
4303#endif
4304typedef struct {
4305    int count;
4306    int cancelled;
4307    int MPI_SOURCE;
4308    int MPI_TAG;
4309    int MPI_ERROR;
4310    $EXTRA_STATUS_DECL
4311} MPI_Status;
4312int main( int argc, char **argv ){
4313  FILE *f=fopen("conftestval", "w");
4314  if (!f) exit(1);
4315  fprintf(f, "%d\n", sizeof(MPI_Status));
4316  exit(0);
4317}
4318],pac_cv_sizeof_mpi_status=`cat conftestval`,pac_cv_sizeof_mpi_status=$default_status_size,pac_cv_sizeof_mpi_status=$default_status_size)
4319])
4320    SIZEOF_MPI_STATUS=$pac_cv_sizeof_mpi_status
4321    export SIZEOF_MPI_STATUS
4322    AC_SUBST(SIZEOF_MPI_STATUS)
4323
4324    if test -z "$MPI_STATUS_SIZE" ; then
4325        if test -n "$SIZEOF_MPI_STATUS" ; then
4326            # compute from the C sizeof
4327            MPI_STATUS_SIZE=`expr $SIZEOF_MPI_STATUS / $ac_cv_sizeof_int`
4328            if test "$MPI_STATUS_SIZE" = "0" ; then
4329                 AC_MSG_WARN([Could not compute the size of MPI_Status])
4330                MPI_STATUS_SIZE=5
4331            fi
4332        else
4333            AC_MSG_WARN([MPI_STATUS_SIZE was not defined!])
4334            # The default size is 5.  See mpi.h.in
4335            MPI_STATUS_SIZE=5
4336        fi
4337    fi
4338    AC_SUBST(MPI_STATUS_SIZE)
4339
4340    #
4341    # We must convert all hex values to decimal (!).
4342    # This is for the C types so they are also available in Fortran
4343    for var in CHAR SIGNED_CHAR UNSIGNED_CHAR WCHAR SHORT \
4344                  UNSIGNED_SHORT INT UNSIGNED_INT LONG UNSIGNED_LONG \
4345                  FLOAT DOUBLE LONG_DOUBLE LONG_LONG_INT \
4346                  UNSIGNED_LONG_LONG LONG_LONG FLOAT_INT DOUBLE_INT \
4347                  LONG_INT SHORT_INT "2INT" LONG_DOUBLE_INT ; do
4348        fullvar="MPI_$var"
4349        fullf77var="MPI_F77_$var"
4350        eval fullvarvalue=\$$fullvar
4351        #echo "$fullvar = $fullvarvalue"
4352        if test "x$fullvarvalue" = "x" -o \
4353                "x$fullvarvalue" = "xMPI_DATATYPE_NULL" ; then
4354             eval $fullf77var="MPI_DATATYPE_NULL"
4355             continue
4356        fi
4357        value=0
4358        fullvarvalue=`echo $fullvarvalue | sed -e 's/..\(.*\)/\1/'`
4359        offset=0
4360        for pos in 3 4 5 6 7 8 9 10 ; do
4361            # This works, even for Tru64, because only a single character
4362            # is extracted
4363            char=`expr $fullvarvalue : '\(.\)'`
4364            # FIXME: Tru64 Unix eliminates leading zeros (!)
4365            # How do we fix something that broken?
4366            fullvarvalue=`echo $fullvarvalue | sed -e 's/.\(.*\)/\1/'`
4367            case $char in
4368                a) char=10 ;;
4369                b) char=11 ;;
4370                c) char=12 ;;
4371                d) char=13 ;;
4372                e) char=14 ;;
4373                f) char=15 ;;
4374            esac
4375            # For Fortran, if the value is too big for an unsigned int,
4376            # we need to make it a signed (negative) int. Currently, the
4377            # types in this class are the minloc/maxloc types.
4378            if test $pos = 3 -a $char -ge 8 ; then
4379                #echo "for $var in position $pos found a value >= 8"
4380                char=`expr $char - 8`
4381                offset=-2147483648
4382            fi
4383            value=`expr $value \* 16 + $char`
4384        done
4385        if test "$offset" != 0 ; then
4386            #echo "$fullf77var: $value, $offset"
4387            value=`expr $value + $offset`
4388        fi
4389        #echo "$fullf77var = $value"
4390        eval $fullf77var=$value
4391    done
4392    AC_SUBST(MPI_F77_CHAR)
4393    AC_SUBST(MPI_F77_SIGNED_CHAR)
4394    AC_SUBST(MPI_F77_UNSIGNED_CHAR)
4395    AC_SUBST(MPI_F77_WCHAR)
4396    AC_SUBST(MPI_F77_SHORT)
4397    AC_SUBST(MPI_F77_UNSIGNED_SHORT)
4398    MPI_F77_UNSIGNED=$MPI_F77_UNSIGNED_INT
4399    AC_SUBST(MPI_F77_UNSIGNED)
4400    AC_SUBST(MPI_F77_INT)
4401    AC_SUBST(MPI_F77_LONG)
4402    AC_SUBST(MPI_F77_UNSIGNED_LONG)
4403    AC_SUBST(MPI_F77_FLOAT)
4404    AC_SUBST(MPI_F77_DOUBLE)
4405    AC_SUBST(MPI_F77_LONG_DOUBLE)
4406    AC_SUBST(MPI_F77_UNSIGNED_LONG_LONG)
4407    MPI_F77_LONG_LONG_INT=$MPI_F77_LONG_LONG
4408    AC_SUBST(MPI_F77_LONG_LONG_INT)
4409    AC_SUBST(MPI_F77_LONG_LONG)
4410    AC_SUBST(MPI_F77_FLOAT_INT)
4411    AC_SUBST(MPI_F77_DOUBLE_INT)
4412    AC_SUBST(MPI_F77_LONG_INT)
4413    AC_SUBST(MPI_F77_SHORT_INT)
4414    AC_SUBST(MPI_F77_2INT)
4415    AC_SUBST(MPI_F77_LONG_DOUBLE_INT)
4416    # Try and compute the values of .true. and .false. in Fortran
4417    # This code has been removed because the Fortran binding code does
4418    # not yet support it. 
4419dnl    AC_ARG_ENABLE(runtimevalues,
4420dnl [--enable-runtimevalues - Determine various parameters of the Fortran
4421dnl                          environment at run time, such as the values for
4422dnl                          .TRUE. and .FALSE. .  This allows a single MPICH
4423dnl                          library to be used with multiple Fortran compilers],
4424dnl use_runtimevalues=$enableval,use_runtimevalues=false)
4425dnl     if test "$use_runtimevalues" = "yes" ; then
4426dnl         AC_DEFINE(F77_RUNTIME_VALUES,1,[Define if Fortran environment should be determined at runtime])
4427dnl     fi
4428
4429    if test "$cross_compiling" = "no" ; then
4430        AC_MSG_CHECKING([for values of Fortran logicals])
4431        # Use a Fortran main program.  This simplifies some steps,
4432        # since getting all of the Fortran libraries (including shared
4433        # libraries that are not in the default library search path) can
4434        # be tricky.  Specifically, The PROG_F77_RUN_PROC_FROM_C failed with
4435        # some installations of the Portland group compiler.
4436        AC_CACHE_VAL(pac_cv_prog_f77_true_false_value,[
4437        # Compile a C routine to print the values of true and false
4438        cat >conftestc.c <<EOF
4439#include <stdio.h>
4440#include "confdefs.h"
4441#ifdef HAVE_STDLIB_H
4442#include <stdlib.h>
4443#endif
4444#ifdef F77_NAME_UPPER
4445#define ftest_ FTEST
4446#elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
4447#define ftest_ ftest
4448#endif
4449void ftest_( $MPI_FINT *, $MPI_FINT *);
4450void ftest_( $MPI_FINT *itrue, $MPI_FINT *ifalse )
4451{
4452  FILE *f = fopen("conftestval","w");
4453  if (!f) exit(1);
4454  fprintf( f, "%d %d\n", *itrue, *ifalse );
4455  fclose(f);
4456}
4457EOF
4458        # Create the Fortran program
4459        cat >conftest.f <<EOF
4460       program main
4461       logical itrue, ifalse
4462       itrue = .TRUE.
4463       ifalse = .FALSE.
4464       call ftest( itrue, ifalse )
4465       end
4466EOF
4467        # Compile the two files
4468        pac_tmp_compile='$CC -c $CFLAGS $CPPFLAGS conftestc.c >&AC_FD_CC'
4469        if AC_TRY_EVAL(pac_tmp_compile) && test -s conftestc.o ; then
4470            AC_LANG_SAVE
4471            AC_LANG_FORTRAN77
4472            saveLIBS=$LIBS
4473            LIBS="conftestc.o $LIBS"
4474            if AC_TRY_EVAL(ac_link) && test -s conftest$ac_exeext ; then
4475                if ./conftest$ac_exeext ; then
4476                    # success
4477                    pac_cv_prog_f77_true_false_value=`cat conftestval`
4478                else
4479                    # failure
4480                    AC_MSG_WARN([Unable to run the program to determine the values of logicals])
4481                    echo "configure: failed program was:" >&AC_FD_CC
4482                    cat conftest.f >&AC_FD_CC
4483                fi
4484            else
4485                # failure
4486                AC_MSG_WARN([Unable to build program to determine values of logicals])
4487                echo "configure: failed program was:" >&AC_FD_CC
4488                cat conftest.f >&AC_FD_CC
4489            fi
4490            LIBS=$saveLIBS
4491            AC_LANG_RESTORE
4492        else
4493            AC_MSG_WARN([Unable to compile the C routine for finding the values of logicals])
4494            echo "configure: failed program was:" >&AC_FD_CC
4495            cat conftestc.c >&AC_FD_CC
4496        fi
4497])
4498        true_val="`echo $pac_cv_prog_f77_true_false_value | sed -e 's/ .*//g'`"
4499        false_val="`echo $pac_cv_prog_f77_true_false_value | sed -e 's/.*  *//g'`"
4500        if test -n "$true_val" -a -n "$false_val" ; then
4501            AC_MSG_RESULT([True is $true_val and False is $false_val])
4502        else
4503            AC_MSG_RESULT([could not determine])
4504        fi
4505    else
4506        # Cross-compiling.  Allow the user to set the values
4507        if test -n "$CROSS_F77_TRUE_VALUE" -a -n "$CROSS_F77_FALSE_VALUE" ; then
4508            true_val=$CROSS_F77_TRUE_VALUE
4509            false_val=$CROSS_F77_FALSE_VALUE
4510        fi     
4511    fi
4512    if test -n "$true_val" -a -n "$false_val" ; then
4513        AC_DEFINE(F77_TRUE_VALUE_SET,1,[Define if we know the value of Fortran true and false])
4514        AC_DEFINE_UNQUOTED(F77_TRUE_VALUE,$true_val,[The value of true in Fortran])
4515        AC_DEFINE_UNQUOTED(F77_FALSE_VALUE,$false_val,[The value of false in Fortran])
4516    fi
4517    #
4518    # We'd also like to check other values for .TRUE. and .FALSE. to see
4519    # if the compiler allows (or uses) more than one value (some DEC compilers,
4520    # for example, used the high (sign) bit to indicate true and false; the
4521    # rest of the bits were ignored.  For now, we'll assume that there are
4522    # unique true and false values.
4523
4524    # Get the ADDRESS_KIND and OFFSET_KIND if possible
4525    #
4526    # For Fortran 90, we'll also need MPI_ADDRESS_KIND and MPI_OFFSET_KIND
4527    # Since our compiler might BE a Fortran 90 compiler, try and determine the
4528    # values. 
4529    if test -z "$F90" ; then
4530        AC_CACHE_CHECK([whether Fortran compiler is a Fortran 90 compiler],
4531        pac_cv_prog_f77_is_f90,[
4532        pac_cv_prog_f77_is_f90=no
4533        cat >>conftest.f90 <<EOF
4534        program main
4535        integer, dimension(10) :: n
4536        integer k
4537        print *,  range(k)
4538        end
4539EOF
4540        if $F77 -o conftest $FFLAGS conftest.f90 >/dev/null 2>&1 ; then
4541            if test -x conftest ; then
4542                pac_cv_prog_f77_is_f90=yes
4543            fi
4544        fi
4545    ])
4546        if test "$pac_cv_prog_f77_is_f90" = yes ; then
4547            F90=$F77
4548            if test -z "$F90FLAGS" ; then
4549                F90FLAGS="$FFLAGS"
4550            fi
4551        fi
4552    fi
4553    if test -n "$F90" ; then
4554        PAC_LANG_PUSH_COMPILERS
4555        PAC_LANG_FORTRAN90
4556        # Offset kind should be for 8 bytes if possible (Romio prefers that)
4557        # address should be sizeof void *
4558        # FIXME: make offset kind match the length of MPI_Offset.
4559        testsize=$ac_cv_sizeof_void_p
4560        if test "$testsize" = 0 ; then
4561            # Set a default
4562            testsize=4
4563        fi 
4564        dnl Using the {} around testsize helps the comments work correctly
4565        PAC_PROG_F90_INT_KIND(ADDRESS_KIND,${testsize},$CROSS_F90_ADDRESS_KIND)
4566        if test "$ac_cv_sizeof_void_p" = 8 ; then
4567            OFFSET_KIND=$ADDRESS_KIND
4568        else
4569            PAC_PROG_F90_INT_KIND(OFFSET_KIND,8,$CROSS_F90_OFFSET_KIND)
4570        fi
4571        #
4572        # Some compilers won't allow a -1 kind (e.g., absoft).  In this case,
4573        # use a fallback (sizeof(int) kind)
4574        if test "$ADDRESS_KIND" = "-1" -o "$OFFSET_KIND" = "-1" ; then
4575            PAC_PROG_F90_INT_KIND(simpleintkind,${pac_cv_f77_sizeof_integer})
4576            if test "$simpleintkind" = "-1" ; then
4577                # Wild guess; probably means that Fortran 90 is not available
4578                AC_MSG_WARN([Unable to determine Fortran 90 KIND values for either address-sized integers or offset-sized integers.  Using 4 in that case.])
4579                simpleintkind=4
4580            fi
4581            if test "$ADDRESS_KIND" = "-1" ; then
4582                ADDRESS_KIND=$simpleintkind
4583            fi
4584            if test "$OFFSET_KIND" = "-1" ; then
4585                OFFSET_KIND=$simpleintkind
4586            fi
4587        fi
4588        AC_CACHE_CHECK([whether real*8 is supported in Fortran 90],pac_cv_fort90_real8,[
4589        AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      real*8 a])],
4590            pac_cv_fort90_real8=yes,
4591            pac_cv_fort90_real8=no)])
4592        PAC_LANG_POP_COMPILERS
4593    fi
4594    # Make sure that address kind and offset kind have values.
4595    if test -z "$ADDRESS_KIND" ; then
4596        ADDRESS_KIND=0
4597    fi
4598    if test -z "$OFFSET_KIND" ; then
4599        OFFSET_KIND=0
4600    fi
4601    # Note, however, that zero value are (in all practical case) invalid
4602    # for Fortran 90, and indicate a failure.  Test and fail if Fortran 90
4603    # enabled.
4604    if test "$enable_f90" = "yes" ; then
4605        if test "$ADDRESS_KIND" -le 0 -o "$OFFSET_KIND" -le 0 ; then
4606            AC_MSG_ERROR([Unable to determine Fortran integer kinds for MPI types.  If you do not need Fortran 90, add --disable-f90 to the configure options.  If you need Fortran 90, please send the output of configure and the file config.log to mpich2-maint@mcs.anl.gov .])
4607            # If the above is converted to a warning, you need to change
4608            # enable_f90 and remote f90 from the bindings
4609            enable_f90=no
4610        fi
4611    fi
4612    AC_SUBST(ADDRESS_KIND)
4613    AC_SUBST(OFFSET_KIND)
4614
4615    # Some compilers may require special directives to handle the common
4616    # block in a library.  In particular, directives are needed for Microsoft
4617    # Windows to support dynamic library import.  The following six
4618    # directives may be needed:
4619    #  CMS\$ATTRIBUTES DLLIMPORT::/MPIPRIV1/
4620    #  CMS\$ATTRIBUTES DLLIMPORT::/MPIPRIV2/
4621    #  CMS\$ATTRIBUTES DLLIMPORT::/MPIPRIVC/
4622    #  CDEC\$ATTRIBUTES DLLIMPORT::/MPIPRIV1/
4623    #  CDEC\$ATTRIBUTES DLLIMPORT::/MPIPRIV2/
4624    #  CDEC\$ATTRIBUTES DLLIMPORT::/MPIPRIVC/
4625    # CMS is for the Microsoft compiler,
4626    # CDEC is (we believe) for the DEC Fortran compiler. 
4627    # We need to make this a configure-time variable because some compilers
4628    # (in particular, a version of the Intel Fortran compiler for Linux)
4629    # will read directives for other compilers and then flag as fatal
4630    # errors directives that it does not support but does recognize.
4631
4632    DLLIMPORT=""
4633    AC_SUBST(DLLIMPORT)
4634
4635    # FIXME:
4636    # We also need to include
4637    # SIZEOF_F90_MPI_OFFSET
4638    # SIZEOF_F90_MPI_AINT
4639    #
4640    # If other "kinds" are supported, MPI_SIZEOF needs to identify
4641    # those as well.  This is very difficult to do in a general way.
4642
4643    # To start with, we use the sizes determined for the Fortran 77 values.
4644    # These must be the same as for the Fortran 90 values.
4645    CROSS_F90_SIZEOF_INTEGER=${CROSS_F90_SIZEOF_INTEGER:-0}
4646    CROSS_F90_SIZEOF_REAL=${CROSS_F90_SIZEOF_REAL:-0}
4647    CROSS_F90_SIZEOF_DOUBLE_PRECISION=${CROSS_F90_SIZEOF_DOUBLE_PRECISION:-0}
4648    SIZEOF_F90_INTEGER=$CROSS_F90_SIZEOF_INTEGER
4649    SIZEOF_F90_REAL=$CROSS_F90_SIZEOF_REAL
4650    SIZEOF_F90_CHARACTER=1
4651    SIZEOF_F90_DOUBLE_PRECISION=$CROSS_F90_SIZEOF_DOUBLE_PRECISION
4652    if test "$pac_cv_f77_sizeof_integer" -gt 0 -a \
4653            "$SIZEOF_F90_INTEGER" = "0" ; then
4654        SIZEOF_F90_INTEGER=$pac_cv_f77_sizeof_integer
4655    fi
4656    if test "$pac_cv_f77_sizeof_real" -gt 0 -a "$SIZEOF_F90_REAL" = "0" ; then
4657        SIZEOF_F90_REAL=$pac_cv_f77_sizeof_real
4658    fi
4659    if test "$pac_cv_f77_sizeof_double_precision" -gt 0 -a \
4660       "$SIZEOF_F90_DOUBLE_PRECISION" = "0" ; then
4661        SIZEOF_F90_DOUBLE_PRECISION=$pac_cv_f77_sizeof_double_precision
4662    fi
4663    AC_SUBST(SIZEOF_F90_INTEGER)
4664    AC_SUBST(SIZEOF_F90_REAL)
4665    AC_SUBST(SIZEOF_F90_DOUBLE_PRECISION)
4666    AC_SUBST(SIZEOF_F90_CHARACTER)
4667
4668    # REQD is short for "real equal double precision" and is set to the
4669    # Fortran 90 comment character if true.  This is necessary to
4670    # allow the mpi_sizeofs module to be built, since if this part of the
4671    # Fortran standard is violated by the compiler (unfortunately common,
4672    # as some applications are written to require this non-standard
4673    # version), the double precision versions of the MPI_SIZEOF routine
4674    # must be commented out of the module (!).
4675    REQD=
4676    if test "$SIZEOF_F90_REAL" = "$SIZEOF_F90_DOUBLE_PRECISION" ; then
4677        REQD="!"
4678    fi
4679    AC_SUBST(REQD)
4680    # Is integer*1 supported, and is it a different size than integer?
4681    REQI1="!"
4682    if test "$pac_cv_fort_integer1" = yes -a "$SIZEOF_F90_INTEGER" != 1 ; then
4683        REQI1=
4684    fi
4685    AC_SUBST(REQI1)
4686    # Is integer*2 supported, and is it a different size than integer?
4687    REQI2="!"
4688    if test "$pac_cv_fort_integer2" = yes -a "$SIZEOF_F90_INTEGER" != 2 ; then
4689        REQI2=
4690    fi
4691    AC_SUBST(REQI2)
4692    # Is integer*8 supported, and is it a different size than integer?
4693    REQI8="!"
4694    if test "$pac_cv_fort_integer8" = yes -a "$SIZEOF_F90_INTEGER" != 8 ; then
4695        REQI8=
4696    fi
4697    AC_SUBST(REQI8)
4698    #
4699
4700    AC_LANG_C
4701fi
4702# ----------------------------------------------------------------------------
4703# C++ types
4704if test "$enable_cxx" = "yes" ; then
4705    AC_LANG_CPLUSPLUS
4706    AC_CHECK_SIZEOF(bool)
4707    AC_CHECK_HEADER(complex)
4708    if test "$ac_cv_header_complex" = "yes" ; then
4709        # The C++ complex types are all templated.  We finagle this by
4710        # defining a standin name
4711        AC_CHECK_SIZEOF(Complex,0,[#include <stdio.h>
4712#include <complex>
4713using namespace std;
4714#define Complex complex<float>
4715])
4716        AC_CHECK_SIZEOF(DoubleComplex,0,[#include <stdio.h>
4717#include <complex>
4718using namespace std;
4719#define DoubleComplex complex<double>
4720])
4721        if test "$MPID_NO_LONG_DOUBLE" != yes ; then
4722             AC_CHECK_SIZEOF(LongDoubleComplex,0,[#include <stdio.h>
4723#include <complex>
4724using namespace std;
4725#define LongDoubleComplex complex<long double>
4726])
4727        fi
4728
4729        # Datatypes are given by
4730        # 0x4c00 <length in bytes> (1 byte) <unique num> (1 byte)   
4731        # where the unique nums are
4732        # 33,34,35,36
4733        case "$ac_cv_sizeof_bool" in
4734           1)    MPIR_CXX_BOOL=0x4c000133 ;;
4735           2)    MPIR_CXX_BOOL=0x4c000233 ;;
4736           4)    MPIR_CXX_BOOL=0x4c000433 ;;
4737           8)    MPIR_CXX_BOOL=0x4c000833 ;;
4738           *) ;;
4739        esac
4740        case "$ac_cv_sizeof_Complex" in
4741           8)    MPIR_CXX_COMPLEX=0x4c000834 ;;
4742           16)   MPIR_CXX_COMPLEX=0x4c001034 ;;
4743           *) ;;
4744        esac
4745        case "$ac_cv_sizeof_DoubleComplex" in
4746           8)    MPIR_CXX_DOUBLE_COMPLEX=0x4c000835 ;;
4747           16)   MPIR_CXX_DOUBLE_COMPLEX=0x4c001035 ;;
4748           32)   MPIR_CXX_DOUBLE_COMPLEX=0x4c002035 ;;
4749           *) ;;
4750        esac
4751        case "$ac_cv_sizeof_LongDoubleComplex" in
4752           8)    MPIR_CXX_LONG_DOUBLE_COMPLEX=0x4c000836 ;;
4753           16)   MPIR_CXX_LONG_DOUBLE_COMPLEX=0x4c001036 ;;
4754           24)   MPIR_CXX_LONG_DOUBLE_COMPLEX=0x4c001836 ;;
4755           32)   MPIR_CXX_LONG_DOUBLE_COMPLEX=0x4c002036 ;;
4756           *) ;;
4757        esac
4758    fi
4759    AC_LANG_C
4760
4761    # Make these available to the collective operations and other code
4762    AC_DEFINE_UNQUOTED(MPIR_CXX_COMPLEX_VALUE,$MPIR_CXX_COMPLEX,[Define as the MPI Datatype handle for MPI::COMPLEX])
4763    AC_DEFINE_UNQUOTED(MPIR_CXX_DOUBLE_COMPLEX_VALUE,$MPIR_CXX_DOUBLE_COMPLEX,[Define as the MPI Datatype handle for MPI::DOUBLE_COMPLEX])
4764    AC_DEFINE_UNQUOTED(MPIR_CXX_LONG_DOUBLE_COMPLEX_VALUE,$MPIR_CXX_LONG_DOUBLE_COMPLEX,[Define as the MPI Datatype handle for MPI::LONG_DOUBLE_COMPLEX])
4765   
4766    # If either complex or double complex have length 0, then mark
4767    # c++ complex as unavailable
4768    if test "$ac_cv_sizeof_Complex" != 0 -a \
4769            "$ac_cv_sizeof_DoubleComplex" != 0 ; then
4770        AC_DEFINE(HAVE_CXX_COMPLEX,1,[Define is C++ supports complex types])
4771    fi
4772fi
4773
4774# ----------------------------------------------------------------------------
4775
4776# Is char * the byte address?
4777AC_CACHE_CHECK([if char * pointers use byte addresses],
4778pac_cv_c_char_p_is_byte,[
4779AC_TRY_RUN([
4780int main(int argc, char **argv ){
4781char *a, buf;
4782a = &buf;
4783if ((long)(a-(char*)0) == (long)(a)) return 0; return 1;
4784}],pac_cv_c_char_p_is_byte=yes,pac_cv_char_p_is_byte=no,
4785pac_cv_char_p_is_byte=unknown)])
4786if test "$pac_cv_char_p_is_byte" = "yes" ; then
4787    AC_DEFINE(CHAR_PTR_IS_BYTE,1,[define if char * is byte pointer])
4788fi
4789# ----------------------------------------------------------------------------
4790#
4791# Check for the alignment rules moves with types int64_t etc.  These
4792# are used in the datatype code to perform pack and unpack operations. 
4793# These only determine if different alignments *work*, not whether they
4794# work efficiently.  The datatype pack code (should) allow the developer
4795# to include stricter alignment rules than are needed for correctness to
4796# get better performance.
4797if test "$ac_cv_c_int64_t" != "no" -o -n "$INT64_T" ; then
4798    default_int64_t_alignment=${CROSS_INT64_T_ALIGNMENT:-"unknown"}
4799    if test -z "$INT64_T" ; then
4800         if test "$ac_cv_c_int64_t" = yes ; then
4801             INT64_T="int64_t"
4802         else
4803             INT64_T="$ac_cv_int64_t"
4804         fi
4805    fi
4806    # We use the type that we're going use for int64.
4807    AC_CACHE_CHECK([for alignment restrictions on $MYINT64_T],pac_cv_int64_t_alignment,[
4808    AC_TRY_RUN([
4809#include <sys/types.h>
4810#include <stdlib.h>
4811int main(int argc, char **argv )
4812{
4813    $INT64_T *p1, v;
4814    char    *buf_p = (char *)malloc( 64 ), *bp;
4815    bp = buf_p;
4816    /* Make bp aligned on 4, not 8 bytes */
4817    if (!( (long)bp & 0x7 ) ) bp += 4;
4818    p1 = ($INT64_T *)bp;
4819    v = -1;
4820    *p1 = v;
4821    if (!( (long)bp & 0x3 ) ) bp += 2;
4822    p1 = ($INT64_T *)bp;
4823    *p1 = 1;
4824    if (!( (long)bp & 0x1 ) ) bp += 1;
4825    p1 = ($INT64_T *)bp;
4826    *p1 = 1;
4827    return 0;
4828}
4829],pac_cv_int64_t_alignment=no,pac_cv_int64_t_alignment=yes,pac_cv_int64_t_alignment=$default_int64_t_alignment)
4830])
4831    if test "$pac_cv_int64_t_alignment" = "no" ; then
4832         AC_DEFINE(HAVE_ANY_INT64_T_ALIGNMENT,1,[Define if int64_t works with any alignment])
4833    fi
4834fi
4835
4836if test "$ac_cv_int32_t" != "no" ; then
4837    default_int32_t_alignment=${CROSS_INT32_T_ALIGNMENT:-"unknown"}
4838    if test -z "$INT32_T" ; then
4839         if test "$ac_cv_c_int32_t" = yes ; then
4840             INT32_T="int32_t"
4841         else
4842             INT32_T="$ac_cv_int32_t"
4843         fi
4844    fi
4845   
4846    AC_CACHE_CHECK([for alignment restrictions on int32_t],pac_cv_int32_t_alignment,[
4847    AC_TRY_RUN([
4848#include <sys/types.h>
4849#include <stdlib.h>
4850int main(int argc, char **argv )
4851{
4852    $INT32_T *p1, v;
4853    char    *buf_p = (char *)malloc( 64 ), *bp;
4854    bp = buf_p;
4855    /* Make bp aligned on 4, not 8 bytes */
4856    if (!( (long)bp & 0x7 ) ) bp += 4;
4857    p1 = ($INT32_T *)bp;
4858    v = -1;
4859    *p1 = v;
4860    if (!( (long)bp & 0x3 ) ) bp += 2;
4861    p1 = ($INT32_T *)bp;
4862    *p1 = 1;
4863    if (!( (long)bp & 0x1 ) ) bp += 1;
4864    p1 = ($INT32_T *)bp;
4865    *p1 = 1;
4866    return 0;
4867}
4868],pac_cv_int32_t_alignment=no,pac_cv_int32_t_alignment=yes,pac_cv_int32_t_alignment=$default_int32_t_alignment)
4869])
4870    if test "$pac_cv_int32_t_alignment" = "no" ; then
4871         AC_DEFINE(HAVE_ANY_INT32_T_ALIGNMENT,1,[Define if int32_t works with any alignment])
4872    fi
4873fi
4874
4875# Get the size for the bsendoverhead
4876AC_CHECK_SIZEOF(MPIR_Bsend_data_t,128,[
4877#define MPI_Datatype int
4878#include "${master_top_srcdir}/src/include/mpibsend.h"]
4879)
4880BSEND_OVERHEAD=$ac_cv_sizeof_MPIR_Bsend_data_t
4881export BSEND_OVERHEAD
4882AC_SUBST(BSEND_OVERHEAD)
4883
4884# Check for special compile characteristics
4885# If we are either gcc or icc, see if we can use __asm__
4886# We test on prog_gcc to allow gcc by any name; if we are using
4887# icc, the value of CC must be icc for this test to pass
4888if test "$ac_cv_prog_gcc" = "yes" -o "$ac_cv_prog_CC" = "icc" ; then
4889AC_MSG_CHECKING([for gcc __asm__ and pentium cmpxchgl instruction])
4890AC_TRY_RUN([
4891int main(int argc, char *argv[])
4892{
4893long int compval = 10;
4894volatile long int *p = &compval;
4895long int oldval = 10;
4896long int newval = 20;
4897char ret;
4898long int readval;
4899__asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
4900        : "=q" (ret), "=m" (*p), "=a" (readval)
4901        : "r" (newval), "m" (*p), "a" (oldval) : "memory");
4902return (compval == 20) ? 0 : -1;
4903}
4904], AC_MSG_RESULT(yes)
4905   AC_DEFINE(HAVE_GCC_AND_PENTIUM_ASM, 1,[Define if using gcc on a system with an Intel Pentium class chip])
4906   lac_cv_use_atomic_updates="yes",
4907AC_MSG_RESULT(no), AC_MSG_RESULT(not checking when cross compiling))
4908fi
4909if test "$lac_cv_use_atomic_updates" = "yes" ; then
4910    AC_DEFINE(USE_ATOMIC_UPDATES,, [Define if assembly language atomic update macros should be used (if available)])
4911fi
4912
4913# check for x86_64
4914if test "$ac_cv_prog_gcc" = "yes" ; then
4915AC_MSG_CHECKING([for gcc __asm__ and AMD x86_64 cmpxchgq instruction])
4916AC_TRY_RUN([
4917int main(int argc, char *argv[])
4918{
4919long int compval = 10;
4920volatile long int *p = &compval;
4921long int oldval = 10;
4922long int newval = 20;
4923char ret;
4924long int readval;
4925__asm__ __volatile__ ("lock; cmpxchgq %3, %1; sete %0"
4926        : "=q" (ret), "=m" (*p), "=a" (readval)
4927        : "r" (newval), "m" (*p), "a" (oldval) : "memory");
4928return (compval == 20) ? 0 : -1;
4929}
4930], AC_MSG_RESULT(yes)
4931   AC_DEFINE(HAVE_GCC_AND_X86_64_ASM, 1,[Define if using gcc on a system with an AMD x86_64 class chip]),
4932AC_MSG_RESULT(no), AC_MSG_RESULT(not checking when cross compiling))
4933fi
4934dnl
4935dnl check for asm() format
4936dnl
4937dnl AC_MSG_CHECKING([for asm() and pentium cmpxchgl instruction])
4938dnl AC_TRY_RUN([
4939dnl int main(int argc, char *argv[])
4940dnl {
4941dnl long int compval = 10;
4942dnl volatile long int *p = &compval;
4943dnl long int oldval = 10;
4944dnl long int newval = 20;
4945dnl char ret;
4946dnl long int readval;
4947dnl asm("lock; cmpxchgl %3, %1; sete %0"
4948dnl     : "=q" (ret), "=m" (*p), "=a" (readval)
4949dnl     : "r" (newval), "m" (*p), "a" (oldval) : "memory");
4950dnl return (compval == 20) ? 0 : -1;
4951dnl }
4952dnl ], AC_MSG_RESULT(yes)
4953dnl    AC_DEFINE(HAVE_PENTIUM_ASM, 1,[Define if using asm() on a system with an Intel Pentium class chip]),
4954dnl AC_MSG_RESULT(no), AC_MSG_RESULT(not checking when cross compiling))
4955dnl
4956dnl
4957dnl check for IA64
4958dnl
4959if test "$ac_cv_prog_gcc" = "yes" ; then
4960AC_MSG_CHECKING([for gcc __asm__ and IA64 xchg4 instruction])
4961AC_TRY_RUN([
4962unsigned long _InterlockedExchange(volatile void *ptr, unsigned long x)
4963{
4964   unsigned long result;
4965   __asm__ __volatile ("xchg4 %0=[%1],%2" : "=r" (result)
4966       : "r" (ptr), "r" (x) : "memory");
4967   return result;
4968}
4969int main(int argc, char *argv[])
4970{
4971long val = 1;
4972volatile long *p = &val;
4973long oldval = _InterlockedExchange(p, (unsigned long)2);
4974return (oldval == 1 && val == 2) ? 0 : -1;
4975}
4976], AC_MSG_RESULT(yes)
4977   AC_DEFINE(HAVE_GCC_AND_IA64_ASM, 1,[Define if using gcc on a system with an IA64 class chip]),
4978AC_MSG_RESULT(no), AC_MSG_RESULT(not checking when cross compiling))
4979fi
4980# -----------------------------------------------------------------------------
4981# Check for support of enable-coverage.  Put this near the end of the tests
4982# because the coverage options may affect the other tests.
4983if test "$enable_coverage" = "yes" ; then
4984    if test "$ac_cv_prog_gcc" = "yes" ; then
4985        CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
4986        MPICH2_EXTRA_CFLAGS="$MPICH2_EXTRA_CFLAGS -fprofile-arcs -ftest-coverage"
4987    else
4988        AC_MSG_WARN([--enable-coverage only supported for GCC])
4989    fi
4990    if test "$enable_cxx" = "yes" ; then
4991        if test "$ac_cv_cxx_compiler_gnu" = "yes" ; then
4992            CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage"
4993            MPICH2_EXTRA_CXXFLAGS="$MPICH2_EXTRA_CXXFLAGS -fprofile-arcs -ftest-coverage"
4994        else
4995            AC_MSG_WARN([--enable-coverage only supported for GCC])
4996        fi
4997    fi
4998    # Add similar options for g77 so that the Fortran tests will also
4999    #
5000    if test "$enable_f77" = yes ; then
5001        if test "$ac_cv_f77_compiler_gnu" = "yes" ; then
5002             FFLAGS="$FFLAGS -fprofile-arcs -ftest-coverage"
5003             MPICH2_EXTRA_FFLAGS="$MPICH2_EXTRA_FFLAGS -fprofile-arcs -ftest-coverage"
5004        else
5005            AC_MSG_WARN([--enable-coverage only supported for G77/GFORTRAN])
5006        fi
5007    fi
5008    if test "$enable_f90" = yes ; then
5009        if test "$ac_cv_f90_compiler_gnu" = "yes" ; then
5010             F90FLAGS="$F90FLAGS -fprofile-arcs -ftest-coverage"
5011             MPICH2_EXTRA_F90FLAGS="$MPICH2_EXTRA_F90FLAGS -fprofile-arcs -ftest-coverage"
5012        else
5013            AC_MSG_WARN([--enable-coverage only supported for GFORTRAN])
5014        fi
5015    fi
5016    # On some platforms (e.g., Mac Darwin), we must also *link*
5017    # with the -fprofile-args -ftest-coverage option.
5018    # We cannot use TRY_LINK because that uses both the compilation and
5019    # the linking flags. 
5020    # This is needed for Mac OSX 10.5
5021    rm -rf conftest.dSYM
5022    rm -f conftest*
5023    cat >>conftest.c <<EOF
5024int main( int argc, char **argv ) { return 1; }
5025EOF
5026    #
5027    compile_only='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext'
5028    link_only='$CC -o conftest$ac_exeext $LDFLAGS conftest.$ac_objext $LIBS'
5029    #
5030    AC_MSG_CHECKING([whether compilation with coverage analysis enabled works])
5031    if AC_TRY_EVAL(compile_only) ; then
5032        AC_MSG_RESULT(yes)
5033        AC_MSG_CHECKING([if extra options needed to link when coverage analysis enabled])
5034        if AC_TRY_EVAL(link_only) ; then
5035            AC_MSG_RESULT(no)
5036        else
5037            LDFLAGSsave="$LDFLAGS"
5038            LDFLAGS="$LDFLAGS -ftest-coverage -fprofile-arcs"
5039            if AC_TRY_EVAL(link_only) ; then
5040                AC_MSG_RESULT([need -ftest-coverage -fprofile-arcs])
5041            else
5042                AC_MSG_RESULT([Unable to determine])
5043                AC_MSG_ERROR([Cannot link programs when coverage analysis enabled])
5044            fi
5045        fi
5046    else
5047        AC_MSG_RESULT(no)
5048        AC_MSG_ERROR([Unable to compile programs when coverage analysis enabled])
5049    fi
5050    # This is needed for Mac OSX 10.5
5051    rm -rf conftest.dSYM
5052    rm -f conftest*
5053   
5054    # Test for the routines that we need to use to ensure that the
5055    # data files are (usually) written out
5056    # FIXME: Some versions of Linux provide usleep, but it rounds times
5057    # up to the next second (!)
5058    AC_CHECK_FUNCS(usleep)
5059    AC_DEFINE(USE_COVERAGE,1,[Define if performing coverage tests])
5060fi
5061# -----------------------------------------------------------------------------
5062# Look for Standard headers
5063AC_HEADER_STDC
5064# Check for a specific header
5065# Grrr.  OS/X fails the test for sys/uio.h because uio *requires* sys/types.h
5066# to compile.  Thus, we'll make that a separate test
5067# stddef.h is sometimes needed for types like wchar_t
5068AC_CHECK_HEADERS(stdlib.h stdarg.h sys/types.h string.h inttypes.h limits.h stddef.h errno.h sys/socket.h sys/time.h unistd.h endian.h assert.h sys/param.h)
5069AC_CACHE_CHECK([for sys/uio.h],ac_cv_header_sys_uio_h,[
5070AC_TRY_COMPILE([
5071#include <sys/types.h>
5072#include <sys/uio.h>
5073],[int a;],ac_cv_header_sys_uio_h=yes,ac_cv_header_sys_uio_h=no)])
5074if test "$ac_cv_header_sys_uio_h" = yes ; then
5075    AC_DEFINE(HAVE_SYS_UIO_H,1,[Define if you have the <sys/uio.h> header file.])
5076fi
5077
5078# Check for special types
5079AC_TYPE_SIZE_T
5080
5081# These are used to support timeouts
5082AC_CHECK_FUNCS(setitimer alarm)
5083# These are used for error reporting
5084AC_CHECK_FUNCS(vsnprintf vsprintf)
5085if test "$ac_cv_func_vsnprintf" = "yes" ; then
5086    # vsnprintf may be declared in stdio.h and may need stdarg.h
5087    PAC_FUNC_NEEDS_DECL([#include <stdio.h>
5088#include <stdarg.h>],vsnprintf)
5089fi
5090# We would like to use strerror in the file namepublisher; it is also used