1AC_PREREQ(2.63)
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    MPID_MAX_ERROR_STRING - The maximum number of character in an error
54dnl                            string.  If not set, 1024 will be used.
55dnl    MPID_LIBTOOL_STATIC_FLAG - The static compilation flag to use
56dnl                               for the example executables within
57dnl                               mpich.  If not set, -static will be
58dnl                               used.
59dnl    PMI_REQUIRES_READABLE_TOKENS - if yes, define the C-preprocessor
60dnl                            value USE_HUMAN_READABLE_TOKENS, which is
61dnl                            used in src/include/mpimem.h to define token
62dnl                            separators used in src/util/mem/argstr.c
63dnl    PM_REQUIRES_PMI       - if set, provides the name of the PMI
64dnl                            interface implementation.  If not set,
65dnl                            the "simple" PMI implementation is used.
66dnl                            A process manager that needs a particular
67dnl                            process manager should check that this is
68dnl                            not set to an incompatible value.
69dnl    MPID_NO_SPAWN         - if yes, the device does not support the
70dnl                            dynamic process routines (spawn, connect
71dnl                            attach, join, plus port and publish
72dnl                            routines).  The major effect of this
73dnl                            is to let the test codes know that
74dnl                            spawn is not implemented.
75dnl    MPID_NO_RMA           - if yes, the device does not support the
76dnl                            MPI RMA routines (MPI_Win_create and
77dnl                            MPI_Put etc.).  The major effect of this
78dnl                            is to let the test codes know that
79dnl                            RMA is not implemented.
80dnl
81dnl Note that the meanings of these variables are defined so that an
82dnl undefined value gives the default.  This makes it easy to expand
83dnl the set of such variables, since only modules that need the new
84dnl variable will need to be changed.
85dnl
86dnl 2. Determine compiler characteristics
87dnl Here is where features of the compilers are determined, including
88dnl support for shared libraries and sizes of the basic datatype types.
89dnl
90dnl 3. Setup and configure the other modules
91dnl Before each module configure is executed, the script setup_<module>
92dnl is run if present.  This is a bourne (sh) shell script and may
93dnl access configure variables.  It should not make any changes to the
94dnl compiler name or flags (e.g., do not add -D_XOPEN_SOURCE to CFLAGS here,
95dnl because that may invalidate the determination of the compiler
96dnl characteristics in the prior step).
97dnl
98dnl 4. Determine MPI features
99dnl
100dnl
101dnl Special environment variables
102dnl To let other scripts and in particular the configure in test/mpi
103dnl know that they are being invoked from within the MPICH2 configure,
104dnl the following environment variables are set and exported:
105dnl    FROM_MPICH2
106dnl    MPICH2_ENABLE_F77
107dnl    MPICH2_ENABLE_FC
108dnl    MPICH2_ENABLE_CXX
109dnl
110dnl Note that no executable statements are allowed (and any are silently
111dnl dropped) before AC_INIT.
112
113m4_include([maint/version.m4])
114dnl 2nd arg is intentionally underquoted
115AC_INIT([MPICH2],
116        MPICH2_VERSION_m4,
117        [mpich-discuss@mcs.anl.gov],
118        [mpich2],
119        [http://www.mcs.anl.gov/research/projects/mpich2/])
120
121if test "x$prefix" != "xNONE" && test -d "$prefix"; then
122    if test "x`(cd \"$prefix\"; echo \"$PWD\")`" = "x`(cd \"$srcdir\"; echo \"$PWD\")`" ||\
123       test "x`(cd \"$prefix\"; echo \"$PWD\")`" = "x$PWD"  ; then
124        AC_MSG_ERROR([The install directory (--prefix=) cannot be the same as the build or src directory.])
125    fi
126fi
127
128CONFIGURE_ARGS_CLEAN=`echo $* | tr '"' ' '`
129AC_SUBST(CONFIGURE_ARGS_CLEAN)
130
131# these values come from the m4_include above
132MPICH2_VERSION=MPICH2_VERSION_m4
133AC_SUBST([MPICH2_VERSION])
134MPICH2_RELEASE_DATE="MPICH2_RELEASE_DATE_m4"
135AC_SUBST([MPICH2_RELEASE_DATE])
136libmpich_so_version="libmpich_so_version_m4"
137AC_SUBST([libmpich_so_version])
138
139
140if test -z "$MPICH2_VERSION" ; then
141    AC_MSG_ERROR([MPICH2_VERSION is empty, check maint/version.m4 for errors])
142fi
143# Produce a numeric version assuming the following format:
144# Version: [MAJ].[MIN].[REV][EXT][EXT_NUMBER]
145# Example: 1.0.7rc1 has
146#          MAJ = 1
147#          MIN = 0
148#          REV = 7
149#          EXT = rc
150#          EXT_NUMBER = 1
151#
152# Converting to numeric version will convert EXT to a format number:
153#          ALPHA (a) = 0
154#          BETA (b)  = 1
155#          RC (rc)   = 2
156#          PATCH (p) = 3
157# Regular releases are treated as patch 0
158#
159# Numeric version will have 1 digit for MAJ, 2 digits for MIN,
160# 2 digits for REV, 1 digit for EXT and 2 digits for EXT_NUMBER.
161changequote(<<,>>)
162V1=`expr $MPICH2_VERSION : '\([0-9]*\)\.[0-9]*\.*[0-9]*[a-zA-Z]*[0-9]*'`
163V2=`expr $MPICH2_VERSION : '[0-9]*\.\([0-9]*\)\.*[0-9]*[a-zA-Z]*[0-9]*'`
164V3=`expr $MPICH2_VERSION : '[0-9]*\.[0-9]*\.*\([0-9]*\)[a-zA-Z]*[0-9]*'`
165V4=`expr $MPICH2_VERSION : '[0-9]*\.[0-9]*\.*[0-9]*\([a-zA-Z]*\)[0-9]*'`
166V5=`expr $MPICH2_VERSION : '[0-9]*\.[0-9]*\.*[0-9]*[a-zA-Z]*\([0-9]*\)'`
167changequote([,])
168
169if test "$V2" -le 9 ; then V2=0$V2 ; fi
170if test "$V3" = "" ; then V3=0; fi
171if test "$V3" -le 9 ; then V3=0$V3 ; fi
172if test "$V4" = "a" ; then
173    V4=0
174elif test "$V4" = "b" ; then
175    V4=1
176elif test "$V4" = "rc" ; then
177    V4=2
178elif test "$V4" = "" ; then
179    V4=3
180    V5=0
181elif test "$V4" = "p" ; then
182    V4=3
183fi
184if test "$V5" -le 9 ; then V5=0$V5 ; fi
185
186MPICH2_NUMVERSION=`expr $V1$V2$V3$V4$V5 + 0`
187AC_SUBST(MPICH2_NUMVERSION)
188
189# ABIVERSION is the name used by simplemake, so we reassign the
190# libmpich_so_version number to it
191ABIVERSION=${libmpich_so_version}
192export ABIVERSION
193export libmpich_so_version
194AC_SUBST(ABIVERSION)
195
196# Print out the configure options
197CONFIGURE_ARGUMENTS="$ac_configure_args"
198AC_SUBST(CONFIGURE_ARGUMENTS)
199if test -n "$ac_configure_args" ; then
200    echo "Configuring MPICH2 version $MPICH2_VERSION with $ac_configure_args"
201else
202    echo "Configuring MPICH2 version $MPICH2_VERSION"
203fi
204
205# Add the information on the system:
206echo "Running on system: `uname -a`"
207
208dnl Definitions will be placed in this file rather than in the DEFS variable
209AC_CONFIG_HEADER(src/include/mpichconf.h)
210AH_TOP([/* -*- Mode: C; c-basic-offset:4 ; -*- */
211/*
212 *  (C) 2001 by Argonne National Laboratory.
213 *      See COPYRIGHT in top-level directory.
214 */
215#ifndef MPICHCONF_H_INCLUDED
216#define MPICHCONF_H_INCLUDED
217])
218
219# We use an #include strategy here because all of the alternative strategies for
220# quashing these variables have various drawbacks.  The alternatives are listed
221# here to avoid rediscovery of these problems by someone else in the future:
222#
223# 1) Strategy: Rewrite mpichconf.h.in with sed at autogen.sh time.
224#    Problem: Automatic remaking of config.status and friends will re-run
225#             autoheader and blow away our sed changes without an opportunity to
226#             patch the resulting file again.
227# 2) Strategy: Add literal "#undef PACKAGE" lines to the AH_BOTTOM text.
228#    Problem: These lines get rewritten by config.status to be "#define" lines,
229#             so the intended quashing never actually occurs.
230# 3) Strategy: Use AC_CONFIG_COMMANDS to run a sed rewrite command on
231#              mpichconf.h at config.status time.
232#    Problem: Causes mpichconf.h to always be rewritten, first by the normal
233#             config.status commands and then by sed.  This can cause
234#             unnecessary remaking of object files since nearly every C source
235#             file includes this header (see the Autoconf Manual, "Automatic
236#             Remaking")
237#
238# The only other plausible strategy would seem to be rewriting config.status
239# itself via AC_CONFIG_COMMANDS_POST, but that seems error prone.  The best
240# solution would be to stop all subconfigures from including config.h headers
241# from other packages.  Then all of this nonsense can be eliminated.
242# [goodell@ 2011-08-26]
243AH_BOTTOM([
244/* Include nopackage.h to undef autoconf-defined macros that cause conflicts in
245 * subpackages.  This should not be necessary, but some packages are too
246 * tightly intertwined right now (such as ROMIO and the MPICH2 core) */
247#include "nopackage.h"
248
249#endif /* !defined(MPICHCONF_H_INCLUDED) */
250])
251
252dnl Set the directory that contains support scripts such as install-sh and
253dnl config.guess
254AC_CONFIG_AUX_DIR(confdb)
255dnl our macro dir is the same as our aux dir
256AC_CONFIG_MACRO_DIR([confdb])
257
258# Set the FROM_MPICH2 variable to tell subconfigures that they are
259# built from within MPICH2
260FROM_MPICH2=yes
261export FROM_MPICH2
262AC_SUBST([FROM_MPICH2])
263
264# Save a copy of precious flags as USER_* before any of these flags
265# are being modified by configure tests.
266PAC_PREFIX_ALL_FLAGS(USER)
267
268# WRAPPER_xFLAGS are used by mpicc and friends.
269#
270# WRAPPER_CFLAGS and other compile flags are used for compile options
271# that are added by MPICH2, but should be used by applications (such
272# as include paths).
273#
274# All libraries that are detected by MPICH2 as needed for some of its
275# functionality (such as -lpthread) should be added to LIBS so
276# autoconf link tests can use them. Libraries that are built by MPICH2
277# at make time (and hence are not available for autoconf link tests to
278# use), such as OPA and MPL, should be added to WRAPPER_LIBS for
279# static builds. All libraries in LIBS are added to WRAPPER_LIBS
280# (similarly LDFLAGS are added to WRAPPER_LDFLAGS) as well, at the end
281# of configure.
282PAC_PREFIX_ALL_FLAGS(WRAPPER)
283WRAPPER_CFLAGS="$CFLAGS $MPICH2_MPICC_FLAGS"
284WRAPPER_CPPFLAGS="$CPPFLAGS $MPICH2_MPICPP_FLAGS"
285WRAPPER_CXXFLAGS="$CXXFLAGS $MPICH2_MPICXX_FLAGS"
286WRAPPER_FFLAGS="$FFLAGS $MPICH2_MPIF77_FLAGS"
287WRAPPER_FCFLAGS="$FCFLAGS $MPICH2_MPIFC_FLAGS"
288WRAPPER_LDFLAGS="$MPICH2_LDFLAGS"
289WRAPPER_LIBS="$MPICH2_LIBS"
290
291# Add MPICH2LIB_* to the appropriate flags
292AC_ARG_VAR(MPICH2LIB_CFLAGS,
293	[extra CFLAGS used in building MPICH2 libraries])
294AC_ARG_VAR(MPICH2LIB_CPPFLAGS,
295	[extra CPPFLAGS used in building MPICH2 libraries])
296AC_ARG_VAR(MPICH2LIB_CXXFLAGS,
297	[extra CXXFLAGS used in building MPICH2 libraries])
298AC_ARG_VAR(MPICH2LIB_FFLAGS,
299	[extra FFLAGS used in building MPICH2 libraries])
300AC_ARG_VAR(MPICH2LIB_FCFLAGS,
301	[extra FCFLAGS used in building MPICH2 libraries])
302AC_ARG_VAR(MPICH2LIB_LDFLAGS,
303	[extra LDFLAGS used in building MPICH2 libraries])
304AC_ARG_VAR(MPICH2LIB_LIBS,
305	[extra LIBS used in building MPICH2 libraries])
306CFLAGS="$CFLAGS $MPICH2LIB_CFLAGS"
307CPPFLAGS="$CPPFLAGS $MPICH2LIB_CPPFLAGS"
308CXXFLAGS="$CXXFLAGS $MPICH2LIB_CXXFLAGS"
309FFLAGS="$FFLAGS $MPICH2LIB_FFLAGS"
310FCFLAGS="$FCFLAGS $MPICH2LIB_FCFLAGS"
311LDFLAGS="$LDFLAGS $MPICH2LIB_LDFLAGS"
312LIBS="$LIBS $MPICH2LIB_LIBS"
313
314dnl include all subsystem m4 fragments now that the core autoconf functionality
315dnl has been setup.  No fragment should do anything except define
316dnl PAC_SUBCFG_{PREREQ,BODY} macros which will be expanded later as
317dnl appropriate
318# begin subsys includes
319m4_include([subsys_include.m4])
320# end subsys includes
321
322dnl ----------------------------------------------------------------------------
323dnl setup top-level argument handling
324AC_ARG_ENABLE(echo,
325	AC_HELP_STRING([--enable-echo], [Turn on strong echoing. The default is enable=no.]),
326	set -x)
327
328AC_ARG_ENABLE(error-checking,
329[  --enable-error-checking=level
330      Control the amount of error checking.
331        no        - no error checking
332        runtime   - error checking controllable at runtime through environment
333                    variables
334        all       - error checking always enabled (default)
335],,enable_error_checking=default)
336
337AC_ARG_ENABLE(error-messages,
338[  --enable-error-messages=level - Control the amount of detail in error messages.
339        all       - Maximum amount of information
340        generic   - Only generic messages (no information about the specific
341                    instance)
342        class     - One message per MPI error class
343        none      - No messages
344],,enable_error_messages=all)
345
346AC_ARG_ENABLE(timing,
347[  --enable-timing=level - Control the amount of timing information
348                           collected by the MPICH implementation.
349        none    - Collect no data (default)
350        all     - Collect lots of data
351        runtime - Runtime control of data collected
352],,enable_timing=default)
353
354AC_ARG_ENABLE(g,
355[  --enable-g=option - Control the level of debugging support in the
356                      MPICH implementation.  option is a list of comma
357                      separated names including
358        none     - No debugging
359        handle   - Trace handle operations
360        handlealloc - Trace handle allocations
361        dbg      - Add compiler flag, -g, to all internal
362                   compiler flags, i.e. MPICH2LIB_CFLAGS, MPICH2LIB_CXXFLAGS,
363                   MPICH2LIB_FFLAGS, and MPICH2LIB_FCFLAGS.
364        debug    - Synonym for dbg
365        instr    - Enable instrumentation
366        log      - Enable debug event logging
367        mem      - Memory usage tracing
368        meminit  - Preinitialize memory associated structures and unions to
369                   eliminate access warnings from programs like valgrind
370        memarena - Check for overwrite errors in memory allocation arena
371        mutex    - Enable error checking on pthread mutexes
372        mutexnesting - Check for non-nesting of mutexes
373        all      - All of the above choices
374],,enable_g=none)
375
376dnl We may want to force MPI_Aint to be the same size as MPI_Offset,
377dnl particularly on 32 bit systems with large (64 bit) file systems.
378AC_ARG_WITH(aint-size,
379	AC_HELP_STRING([--with-aint-size], [Override the size of MPI_AINT (in bytes)]),,
380	with_aint_size=0)
381
382AC_ARG_ENABLE(fast,
383[  --enable-fast=option - Control the level of fast execution in the
384                         MPICH implementation.  option is a list of
385                         comma separated names including
386        defopt   - Default compiler optimization -O2 for all language bindings,
387                   i.e. --enable-fast=O2, when neither --enable-fast
388                   nor --disable-fast is specified. (default)
389        O<n>     - Appends default optimization flags, -O<n>, to all internal
390                   compiler flags, i.e. MPICH2LIB_CFLAGS, MPICH2LIB_CXXFLAGS,
391                   MPICH2LIB_FFLAGS, and MPICH2LIB_FCFLAGS.
392        nochkmsg - No error checking, i.e. --disable-error-checking
393        notiming - No timing collection, i.e. --disable-timing.
394        ndebug   - Appends -DNDEBUG to MPICH2LIB_CFLAGS.
395        all|yes  - "defopt", "nochkmsg", "notiming" and "ndebug" are enabled
396                   when --enable-fast is specified without any option.
397        none     - None of above options, i.e. --disable-fast. Note that
398                   --enable-strict will add the -O2 option even if
399                   --enable-fast=none is given.
400],,enable_fast=defopt)
401
402AC_ARG_ENABLE(check-compiler-flags,
403	AC_HELP_STRING([--enable-check-compiler-flags], [enable the checks for all compiler
404                       options, xxxFLAGS, MPICH2_xxxFLAGS. Default is on.]),,
405		       enable_check_compiler_flags=yes)
406
407dnl We enable f77 and fc if we can find compilers for them.
408dnl In addition, we check whether f77 and fc can work together.
409AC_ARG_ENABLE(f77,
410	AC_HELP_STRING([--enable-f77], [Enable Fortran 77 bindings]),,enable_f77=yes)
411
412AC_ARG_ENABLE(fc,
413	AC_HELP_STRING([--enable-fc], [Enable Fortran 90 bindings]),,enable_fc=yes)
414
415AC_ARG_ENABLE(f90,
416	AC_HELP_STRING([--enable-f90],
417		[Obsolete option: Use --enable-fc or --disable-fc instead]),
418	[AC_MSG_ERROR([
419--enable-f90 and --disable-f90 are NO longer valid configure options,
420use --enable-fc or --disable-fc instead])]
421)
422
423AC_ARG_ENABLE(cxx,
424	AC_HELP_STRING([--enable-cxx], [Enable C++ bindings]),,enable_cxx=yes)
425
426AC_ARG_ENABLE(romio,
427	AC_HELP_STRING([--enable-romio], [Enable ROMIO MPI I/O implementation]),,
428	enable_romio=yes)
429
430AC_ARG_ENABLE(debuginfo,
431	AC_HELP_STRING([--enable-debuginfo], [Enable support for debuggers]),,
432	enable_debuginfo=no)
433
434AC_ARG_ENABLE(smpcoll,
435	AC_HELP_STRING([--enable-smpcoll],
436			[Enable support for SMP/multi-core aware collectives]),
437	smpcoll=$enableval,smpcoll=yes)
438if test $smpcoll = "yes" ; then
439   AC_DEFINE(USE_SMP_COLLECTIVES,1,[define to enable SMP/multi-core aware collectives])
440fi
441
442
443## Enable creation of libtool-style versioning or no versioning
444AC_ARG_ENABLE(versioning,
445        [AC_HELP_STRING([--enable-versioning],[Enable library versioning])],,
446        [enable_versioning=yes])
447
448if test "$enable_versioning" = "yes" ; then
449   ABIVERSIONFLAGS="-version-info \$(ABIVERSION)"
450else
451   ABIVERSIONFLAGS="-avoid-version"
452fi
453export ABIVERSIONFLAGS
454AC_SUBST(ABIVERSIONFLAGS)
455
456
457dnl The environment variable MPICH_DEBUGLIBNAME may be used to
458dnl override the default name of the library that the debugger will
459dnl load to access the MPICH2 internal data structures.
460
461dnl "default" is a special device that allows MPICH to choose one
462dnl based on the environment.
463AC_ARG_WITH(device,
464	AC_HELP_STRING([--with-device=name], [Specify the communication device for MPICH]),,
465	with_device=default)
466
467AC_ARG_WITH(pmi,
468	AC_HELP_STRING([--with-pmi=name], [Specify the pmi interface for MPICH]),,
469	with_pmi=default)
470
471AC_ARG_WITH(pm,
472	AC_HELP_STRING([--with-pm=name],
473		[Specify the process manager for MPICH.  "no" or "none" are
474                 valid values.  Multiple process managers may be specified as
475                 long as they all use the same pmi interface by separating them
476                 with colons.  The mpiexec for the first named process manager
477                 will be installed.  Example: "--with-pm=hydra:mpd:gforker"
478                 builds the three process managers hydra, mpd and gforker;
479                 only the mpiexec from hydra is installed into the bin
480                 directory.]),,with_pm=default)
481
482AC_ARG_WITH(logging,
483	AC_HELP_STRING([--with-logging=name], [Specify the logging library for MPICH]),
484	[if test -z "$withval" ; then with_logging=rlog ; fi],with_logging=none)
485
486dnl both --without-mpe and --disable-mpe are supported
487dnl AC_ARG_ENABLE(mpe) is used only when --with(out)-mpe is not used.
488AC_ARG_WITH(mpe,
489	AC_HELP_STRING([--with-mpe], [Build the MPE (MPI Parallel Environment) routines]),,
490	with_mpe=default)
491if test "$with_mpe" = "default" ; then
492    AC_ARG_ENABLE(mpe,
493	AC_HELP_STRING([--enable-mpe], [Build the MPE (MPI Parallel Environment) routines]),
494	with_mpe=$enableval,with_mpe=default)
495fi
496
497dnl
498dnl The default option needs to be defined in terms of a specific choice
499dnl (runtime in this case).  Note that the default choice is the same as
500dnl runtime only for certain devices - not for every device.
501AC_ARG_ENABLE(threads,
502[  --enable-threads=level - Control the level of thread support in the
503                           MPICH implementation.  The following levels
504                           are supported.
505        single          - No threads (MPI_THREAD_SINGLE)
506        funneled        - Only the main thread calls MPI (MPI_THREAD_FUNNELED)
507        serialized      - User serializes calls to MPI (MPI_THREAD_SERIALIZED)
508        runtime         - The level of thread support is determined by
509                          the arguments to MPI_Init_thread, with
510                          MPI_THREAD_MULTIPLE available.  The default option
511                          for many communication devices.
512        multiple        - Fully multi-threaded (MPI_THREAD_MULTIPLE) always.
513                          DO NOT select this option. The option runtime is more
514                          efficient and also supports thread_multiple.
515                          (multiple aliased to runtime now)
516        default         - Make a good choice depending on the communication
517                          device.  For ch3:nemesis, this is runtime.
518
519        See also the --enable-thread-cs option for controlling the granularity of
520        the concurrency inside of the library
521],,enable_threads=default)
522
523AC_ARG_ENABLE(thread-cs,
524	AC_HELP_STRING([--enable-thread-cs=type],
525			[Choose the method used for critical sections
526                         and other atomic updates when multiple
527                         threads are present.  Values may be global
528                         (default), per-object, lock-free]),,enable_thread_cs=global)
529
530AC_ARG_ENABLE(refcount,
531	AC_HELP_STRING([--enable-refcount=type],
532			[Choose the method for ensuring atomic updates
533                         to the reference counts for MPI objects.
534                         Values may be lock, lock-free, none.  The
535                         default depends on the thread-cs choice; for
536                         global it is none (because none is required),
537                         for per-object it is lock, and for lock-free
538                         it is lock-free]),,enable_refcount=default)
539
540AC_ARG_ENABLE(mutex-timing,
541	AC_HELP_STRING([--enable-mutex-timing], [calculate the time spent waiting on mutexes]),
542	AC_DEFINE(MPIU_MUTEX_WAIT_TIME,1,[Define to enable timing mutexes]))
543
544AC_ARG_ENABLE(handle-allocation,
545	AC_HELP_STRING([--enable-handle-allocation=type],
546			[Choose the method used for allocating MPI
547			 object handles.  Values may be 'tls' for
548			 thread-local storage or 'mutex' for simple
549			 locking.  'mutex' is the default.]),,enable_handle_allocation=default)
550
551AC_ARG_ENABLE([predefined-refcount],
552	AS_HELP_STRING([--enable-predefined-refcount],
553                       [control whether predefined objects like
554		       MPI_COMM_WORLD are reference counted (default
555		       depends on --enable-thread-cs choice)]),[],
556              [enable_predefined_refcount=default])
557
558AC_ARG_ENABLE(weak-symbols,
559	AC_HELP_STRING([--enable-weak-symbols],
560			[Use weak symbols to implement PMPI routines (default)]),,
561		enable_weak_symbols=yes)
562
563AC_ARG_ENABLE([two-level-namespace],
564              [AS_HELP_STRING([--enable-two-level-namespace],
565                              [(Darwin only) Build shared libraries and programs
566                               built with the mpicc/mpif77/etc. compiler
567                               wrappers with '-Wl,-commons,use_dylibs' and
568                               without '-Wl,-flat_namespace'.  This may make the
569                               MPICH2 installation and MPI programs more
570                               compatible with other libraries.  Only enable
571                               this option if you really know what these linker
572                               options imply.])],
573              [],
574              [enable_two_level_namespace=no])
575
576AC_ARG_ENABLE(multi-aliases,
577	AC_HELP_STRING([--enable-multi-aliases],
578		[Multiple aliasing to support multiple fortran compilers (default)]),,
579		enable_multi_aliases=yes)
580
581AC_ARG_ENABLE([wrapper-rpath],
582              [AC_HELP_STRING([--enable-wrapper-rpath],
583                              [Determine whether the rpath is set when programs
584                               are linked by mpicc compiler wrappers.  This only
585                               applies when shared libraries are built.  The
586                               default is yes; use --disable-wrapper-rpath to
587                               turn this feature off.  In that case, shared
588                               libraries will be found according to the rules
589                               for your system (e.g., in LD_LIBRARY_PATH)])],
590              [],[enable_wrapper_rpath=yes])
591AC_SUBST([enable_wrapper_rpath])
592
593AC_ARG_WITH(cross,
594	AC_HELP_STRING([--with-cross=file],
595		[Specify the values of variables that configure cannot
596                 determine in a cross-compilation environment]),,with_cross=no)
597
598AC_ARG_WITH(namepublisher,
599[  --with-namepublisher=name   Choose the system that will support
600                              MPI_PUBLISH_NAME and MPI_LOOKUP_NAME.  Options
601                              include
602                                   no (no service available)
603                                   mpd
604			           file[:directory] (optional directory)
605                                   pmi],,with_namepublisher=default)
606AC_ARG_WITH(name-publisher,
607    [],
608    with_namepublisher=$with_name_publisher,)
609
610AC_SUBST(MPIFLIBNAME)
611AC_SUBST(PMPIFLIBNAME)
612
613dnl The default is a special wrapper library
614AC_ARG_WITH(fwrapname,
615	AC_HELP_STRING([--with-fwrapname=name],
616		[Specify name of library containing Fortran interface routines]),
617	[FWRAPNAME=$withval;set_FWRAPNAME="yes"],FWRAPNAME=fmpich)
618AC_SUBST(FWRAPNAME)
619
620# Find a C compiler.
621# We also need to do this before the F77 and FC test to ensure that we
622# find the C preprocessor reliably.
623PAC_PROG_CC
624AM_PROG_CC_C_O dnl needed for automake "silent-rules"
625PAC_PUSH_FLAG([CFLAGS])
626AC_PROG_CPP
627# Bug in autoconf.  Restore cross settings
628if test "$pac_cross_compiling" = "yes" -a "$ac_cv_prog_cc_cross" = "no" ; then
629    AC_MSG_RESULT([Resetting cross compilation to yes])
630    cross_compiling=yes
631    ac_cv_prog_cc_cross=yes
632    ac_cv_prog_f77_cross=yes
633    ac_cv_prog_fc_cross=yes
634    ac_cv_prog_cxx_cross=yes
635fi
636PAC_POP_FLAG([CFLAGS])
637
638dnl now that autoconf and core compilers are setup, init automake and libtool
639dnl
640dnl We would like to pass -Werror, but we are cheating in the "examples/"
641dnl directory and overriding the user-flags like CFLAGS, which automake-1.12
642dnl warns about.  Long-term we may need to use a hand-written Makefile.in or
643dnl something else in this special dir.
644AM_INIT_AUTOMAKE([-Wall foreign 1.12.3 silent-rules subdir-objects])
645AM_MAINTAINER_MODE([enable])
646
647AM_PROG_AR
648
649LT_INIT([disable-shared])
650# Non-verbose make by default
651m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
652
653# Disable rpath in the compiler wrappers if shared libraries are disabled, since
654# rpath makes no sense in the context of static libraries.
655if test "X$enable_shared" = "Xno" ; then
656    enable_wrapper_rpath=no
657fi
658
659dnl AC_PROG_{CXX,F77,FC} must come early in configure.ac in order to avoid some
660dnl esoteric autoconf macro expansion errors
661dnl
662dnl Also, DO NOT attempt to place shell conditionals (either manually or via
663dnl AS_IF) around these macros in an effort to save configure time.  It will
664dnl lead to weird AM_CONDITIONAL errors and potentially other problems.
665
666# suppress default "-g -O2" from AC_PROG_CXX
667: ${CXXFLAGS=""}
668AC_PROG_CXX([PAC_CXX_SEARCH_LIST])
669
670# suppress default "-g -O2" from AC_PROG_F77
671: ${FFLAGS=""}
672AC_PROG_F77([PAC_F77_SEARCH_LIST])
673
674# suppress default "-g -O2" from AC_PROG_FC
675: ${FCFLAGS=""}
676AC_PROG_FC([PAC_FC_SEARCH_LIST])
677
678
679# compute canonical system types
680AC_CANONICAL_BUILD
681AC_CANONICAL_HOST
682# TARGET not needed, MPICH2 isn't a compiler
683
684# Enable better caching control
685PAC_ARG_CACHING
686
687# Set CFLAGS for enable strict if necessary.  Do this *first* because
688# it may influence the output of the other tests
689PAC_ARG_STRICT
690
691# -----------------------------------------------------------------------------
692# First check that we have a clean build if we are doing a VPATH build
693PAC_VPATH_CHECK(src/include/mpi.h src/env/mpicc src/env/mpicc.conf,lib)
694
695# ----------------------------------------------------------------------------
696# This test is complicated by the fact that top_srcdir is not set until
697# the very end of configure.  Instead, we get it ourselves
698if test -z "$top_srcdir" ; then
699   use_top_srcdir=$srcdir
700else
701   use_top_srcdir=$top_srcdir
702fi
703if test -z "$master_top_srcdir" ; then
704    # This needs to be an absolute pathname
705    case "$use_top_srcdir" in
706    /*) ;;
707    *)
708        use_top_srcdir=`(cd $use_top_srcdir && pwd)`
709	;;
710    esac
711    master_top_srcdir=$use_top_srcdir
712fi
713# Get the directory that we're running in...
714if test -z "$master_top_builddir" ; then
715   master_top_builddir="`pwd`"
716fi
717AC_SUBST(master_top_builddir)
718AC_SUBST(master_top_srcdir)
719export master_top_builddir
720export master_top_srcdir
721
722# ----------------------------------------------------------------------------
723# with-device
724if test "$with_device" = "default" ; then
725    # Pick the device.  For now, always choose ch3
726    with_device=ch3
727fi
728# Extract the device name from any options
729# Allow the device to specify a directory; if no directory, use the
730# included directories
731#
732DEVICE=$with_device
733AC_SUBST(DEVICE)
734
735device_name=`echo $with_device | sed -e 's/:.*$//'`
736changequote(<<,>>)
737device_args=`echo $with_device | sed -e 's/^[^:]*//' -e 's/^://'`
738changequote([,])
739
740devicedir=$use_top_srcdir/src/mpid/$device_name
741devicereldir=src/mpid/$device_name
742case "$device_name" in
743     /*)
744     devicedir=$DEVICE
745     # Get the name from the leaf
746     device_name=`echo $device_name ~ sed -e 's%.*/%%'`
747     # FIXME: should the devicereldir be different (perhaps not -
748     # this allows use to build within our tree, even when other data
749     # is outside of the tree)
750     ;;
751     *)
752     ;;
753esac
754export device_name
755export device_args
756export devicedir
757# Make the device base name and args available to generated files
758DEVICE_NAME=$device_name
759AC_SUBST(DEVICE_NAME)
760DEVICE_ARGS=$device_args
761AC_SUBST(DEVICE_ARGS)
762#
763# Give the device an opportunity to include a header file in mpi.h.  The
764# default value of INCLUDE_MPIDDEFS_H is set prior to the inclusion of the
765# device's mpich2prereq script.  The device's script may override the value
766# if needed.
767INCLUDE_MPIDDEFS_H='/* ... no device specific definitions ... */'
768AC_SUBST(INCLUDE_MPIDDEFS_H)
769
770# See if the device wants to say something about the compilers
771if test -f $devicedir/mpich2prereq ; then
772    . $devicedir/mpich2prereq
773fi
774
775# expand all of the prereq macros in the correct order
776m4_map([PAC_SUBCFG_DO_PREREQ], [PAC_SUBCFG_MODULE_LIST])
777
778# ----------------------------------------------------------------------------
779# Set default library names if names haven't already been provided
780AC_ARG_VAR([MPILIBNAME],[can be used to override the name of the MPI library (default: "mpich")])
781AC_ARG_VAR([PMPILIBNAME],[can be used to override the name of the MPI profiling library (default: "p$MPILIBNAME")])
782AC_ARG_VAR([MPICXXLIBNAME],[can be used to override the name of the MPI C++ library (default: "${MPILIBNAME}cxx")])
783MPILIBNAME=${MPILIBNAME:-"mpich"}
784PMPILIBNAME_set=no
785if test -n "$PMPILIBNAME" ; then
786   PMPILIBNAME_set=yes
787fi
788PMPILIBNAME=${PMPILIBNAME:-"p$MPILIBNAME"}
789# Note that the name for this library may be updated after we check for
790# enable_shmem
791# Fortran names are set later.
792# We use a different library for the C++ wrappers to avoid problems when
793# creating shared libraries
794if test -z "$MPICXXLIBNAME" ; then MPICXXLIBNAME="${MPILIBNAME}cxx" ; fi
795export MPIFLIBNAME
796export PMPIFLIBNAME
797export MPICXXLIBNAME
798AC_SUBST(MPICXXLIBNAME)
799
800# We'll set FORTRAN_BINDING to 1 if we support Fortran
801FORTRAN_BINDING=0
802
803# Set up default compiler optimization
804MPI_DEFAULT_COPTS="-O2"
805MPI_DEFAULT_CXXOPTS="-O2"
806MPI_DEFAULT_FOPTS="-O2"
807MPI_DEFAULT_FCOPTS="-O2"
808
809# enable-fast
810# strip off multiple options, separated by commas
811save_IFS="$IFS"
812IFS=","
813for option in $enable_fast ; do
814    case "$option" in
815        defopt)
816        enable_default_optimize=yes
817        ;;
818        nochkmsg)
819        enable_fast_nochkmsg=yes
820        ;;
821        notiming)
822        enable_timing=no
823        ;;
824        ndebug)
825        enable_append_ndebug=yes
826        ;;
827#
828# [BRT] removed the reseting of enable_g so that --with-enable=dbg,meminit
829# can be specified with -enable-fast.  This change was largely made for the
830# PETSc folks who want to use --enable-fast to eliminate parameter checking
831# overhead, but also wish to use meminit to eliminate initialization
832# warnings from valgrind.
833#
834        all|yes)
835        enable_default_optimize=yes
836        enable_fast_nochkmsg=yes
837        # Disable timing/logging stuffs
838        enable_timing=no
839        enable_append_ndebug=yes
840        ;;
841        O*)
842        # Allows O<n> where <n> can be [0-9] or ' '.
843        opt_flags=`echo $option | sed -e 's%\(O[0-9] \)%\1%g'`
844        if test -n "$opt_flags" ; then
845            enable_default_optimize=yes
846            MPI_DEFAULT_COPTS="-$option"
847            MPI_DEFAULT_CXXOPTS="-$option"
848            MPI_DEFAULT_FOPTS="-$option"
849            MPI_DEFAULT_FCOPTS="-$option"
850        else
851	    IFS="$save_IFS"
852            AC_MSG_WARN([Unknown value $option for --enable-fast])
853	    IFS=","
854        fi
855        ;;
856        none|no)
857        enable_default_optimize=no
858        enable_fast_nochkmsg=no
859        # Reset timing/logging stuffs to when --enable-timing isn't specified.
860        enable_timing=default
861        enable_append_ndebug=no
862        ;;
863        *)
864	IFS="$save_IFS"
865        AC_MSG_WARN([Unknown value $option for --enable-fast])
866	IFS=","
867        ;;
868    esac
869done
870IFS="$save_IFS"
871
872# ----------------------------------------------------------------------------
873# Process any enable or with values
874# We must do enable-fast first, because it changes the other enable values
875if test "$enable_fast_nochkmsg" = "yes" ; then
876    #
877    if test "$enable_error_checking" != "default" -a "$enable_error_checking" != "no" ; then
878        AC_MSG_ERROR([enable-fast overrides enable-error-checking; error-checking option $enable_error_checking ignored])
879    fi
880    enable_error_checking=no
881    # Export a variable that will allow the test suite to detect that
882    # MPICH has no error testing
883    MPICH_FAST=yes
884    export MPICH_FAST
885fi
886
887# error-checking
888# Change default into the specific value of the default
889if test "$enable_error_checking" = "default" ; then
890   enable_error_checking=all
891fi
892# glue_romio.h needs the variable HAVE_ERROR_CHECKING to have the value 0 or 1
893HAVE_ERROR_CHECKING=0
894case "$enable_error_checking" in
895    no)
896    # if error checking has been disabled, then automatically disable the error
897    # checking tests in the test suite
898    ac_configure_args="${ac_configure_args} --disable-checkerrors"
899    ;;
900    all|yes|runtime)
901    error_checking_kind=`echo $enable_error_checking | \
902    tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
903    error_checking_kind=MPID_ERROR_LEVEL_$error_checking_kind
904    AC_DEFINE_UNQUOTED(HAVE_ERROR_CHECKING,$error_checking_kind,[Define to enable error checking])
905    HAVE_ERROR_CHECKING=1
906    ;;
907    *)
908    AC_MSG_WARN([Unknown value $enable_error_checking for enable-error-checking])
909    ;;
910esac
911# permit @HAVE_ERROR_CHECKING@ substitution in glue_romio.h
912AC_SUBST([HAVE_ERROR_CHECKING])
913
914# error-messages
915case "$enable_error_messages" in
916    no|none)
917        error_message_kind="MPICH_ERROR_MSG_NONE"
918    ;;
919    all|yes)
920	error_message_kind="MPICH_ERROR_MSG_ALL"
921    ;;
922    generic)
923	error_message_kind="MPICH_ERROR_MSG_GENERIC"
924    ;;
925    class)
926	error_message_kind="MPICH_ERROR_MSG_CLASS"
927    ;;
928    *)
929    AC_MSG_WARN([Unknown value $enable_error_messages for enable-error-messages])
930    ;;
931esac
932AC_DEFINE_UNQUOTED(MPICH_ERROR_MSG_LEVEL,$error_message_kind,[define to enable error messages])
933
934# ----------------------------------------------------------------------------
935#
936# enable-timing and with-logging
937#
938# Still to do: add subsets: e.g., class=pt2pt,class=coll.  See mpich2 doc
939#
940# Logging and timing are intertwined.  If you select logging, you
941# may also need to select a timing level.  If no timing is selected
942# but logging with rlog is selected, make "all" the default timing level.
943#
944# FIXME: make timing and logging options work more cleanly together,
945# particularly when other logging options are selected (e.g., logging is not
946# rlog).
947# ----------------------------------------------------------------------------
948AM_CONDITIONAL([BUILD_LOGGING_RLOG],[test "X$with_logging" = "Xrlog"])
949collect_stats=false
950logging_required=false
951if test "$enable_timing" = "default" ; then
952    if test "$with_logging" = "rlog" ; then
953        enable_timing=all
954    fi
955fi
956timing_name=$enable_timing
957case "$enable_timing" in
958    no)
959    timing_name=none
960    ;;
961    time)
962    collect_stats=true
963    ;;
964    log|log_detailed)
965    logging_required=true
966    ;;
967    yes)
968    timing_name=all
969    collect_stats=true
970    logging_required=true
971    ;;
972    all|runtime)
973    collect_stats=true
974    logging_required=true
975    ;;
976    none|default)
977    timing_name=none
978    ;;
979    *)
980    AC_MSG_WARN([Unknown value $enable_timing for enable-timing])
981    enable_timing=no
982    timing_name=none
983    ;;
984esac
985#
986# The default logging package is rlog; you can get it by
987# specifying --with-logging or --with-logging=rlog
988#
989case $with_logging in
990    yes)
991    logging_name=rlog
992    ;;
993    no|none)
994    logging_name=none
995    ;;
996    default)
997    if test "$logging_required" = "true" ; then
998        logging_name=rlog
999    else
1000        logging_name=none
1001    fi
1002    ;;
1003    *)
1004    logging_name=$with_logging
1005    ;;
1006esac
1007#
1008# Include the selected logging subsystem
1009#
1010# Choices:
1011# 1) A subdir of src/util/logging
1012#     This directory must contain a configure which will be executed
1013#     to build the
1014# 2) An external directory
1015#     This directory must contain
1016#          a mpilogging.h file
1017#     It may contain
1018#          a setup_logging script
1019#          a configure
1020#
1021#
1022logging_subsystems=
1023if test "$logging_name" != "none" ; then
1024    # Check for an external name (directory containing a /)
1025    hasSlash=`echo A$logging_name | sed -e 's%[[^/]]%%g'`
1026    if test -n "$hasSlash" ; then
1027        # Check that the external logging system is complete.
1028	# Any failure will cause configure to abort
1029        if test ! -d $logging_name ; then
1030	    AC_MSG_ERROR([External logging directory $logging_name not found.  Configure aborted])
1031	    logging_name=none
1032        elif test ! -s $logging_name/mpilogging.h ; then
1033	    AC_MSG_ERROR([External logging header $logging_name/mpilogging.h not found.  Configure aborted])
1034	    logging_name=none
1035        fi
1036
1037        logdir=$logging_name
1038	# Force the logdir to be absolute
1039	logdir=`cd $logdir && pwd`
1040	# Switch name to "external" because that is how the MPICH2
1041	# code will know it
1042	logging_name=external
1043	# Add the dir to the include paths
1044	#CPPFLAGS="$CPPFLAGS -I$logdir"
1045	CPPFLAGS="$CPPFLAGS -I$logdir"
1046	EXTERNAL_SRC_DIRS="$EXTERNAL_SRC_DIRS $logdir"
1047	# Add to the list of external modules to setup
1048	if test -x $logdir/setup_logging ; then
1049	     EXTERNAL_SETUPS="$EXTERNAL_SETUPS $logdir/setup_logging"
1050	fi
1051    else
1052        logdir=$srcdir/src/util/logging
1053        logreldir=src/util/logging/$logging_name
1054        logging_subsystems="$logging_subsystems $logreldir"
1055        logging_subdirs=$logging_name
1056        for dir in $logging_subdirs ; do
1057            if test ! -d $logdir/$dir ; then
1058	        AC_MSG_ERROR([$logdir/$dir does not exist.  Configure aborted])
1059	        logging_name=none
1060            fi
1061        done
1062        for dir in $logging_subsystems ; do
1063            if test ! -x $srcdir/$dir/configure ; then
1064	        AC_MSG_ERROR([$srcdir/$dir has no configure (required).  Configure aborted])
1065	        logging_name=none
1066            fi
1067            other_install_dirs="${other_install_dirs} $logreldir"
1068        done
1069    fi
1070fi
1071#
1072# FIXME: Logging doesn't necessarily require timing (e.g., simply logging the
1073# sequence of routines).
1074if test "$logging_name" != "none" ; then
1075    if test "$enable_timing" != "no" ; then
1076	if test "$enable_timing" = "default" -o "$enable_timing" = "none" ; then
1077	    enable_timing=log
1078	    timing_name=log
1079    	fi
1080	logging_dir=logging
1081	subsystems="$subsystems $logging_subsystems"
1082    else
1083	AC_MSG_WARN([Timing was disabled.  Logging has been disabled as well.])
1084	with_logging=no
1085	logging_name=none
1086        logging_dir=
1087        logging_subdirs=
1088    fi
1089else
1090    if test "$logging_required" = "true" ; then
1091	AC_MSG_WARN([Timing was enabled with log option but no logging library is available.  Timing has been disabled.])
1092	enable_timing=no
1093	timing_name=none
1094    fi
1095    logging_dir=
1096    logging_subdirs=
1097fi
1098if test "$timing_name" != "none" ; then
1099    timing_kind=`echo $timing_name | \
1100       tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
1101    timing_kind=MPID_TIMING_KIND_$timing_kind
1102    AC_DEFINE_UNQUOTED(HAVE_TIMING,$timing_kind,[define to enable timing collection])
1103    if test "$collect_stats" = "true" ; then
1104        AC_DEFINE(COLLECT_STATS,1,[define to enable collection of statistics])
1105    fi
1106fi
1107#
1108AC_SUBST(logging_dir)
1109AC_SUBST(logging_name)
1110AC_SUBST(logging_subdirs)
1111use_logging_variable="MPID_LOGGING_`echo $logging_name | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
1112AC_DEFINE_UNQUOTED(USE_LOGGING,$use_logging_variable,[define to choose logging library])
1113# ----------------------------------------------------------------------------
1114# End of logging tests
1115# ----------------------------------------------------------------------------
1116
1117# ----------------------------------------------------------------------------
1118# Check to see if the device does not support spawn.
1119# FIXME: This should provide the option of not building the dynamic
1120# process routines.  It could also allow us to specialize support
1121# for all processes are members of MPI_COMM_WORLD (only one comm_world).
1122# ----------------------------------------------------------------------------
1123if test "$MPID_NO_SPAWN" = yes ; then
1124    AC_MSG_WARN([The device $with_device does not support MPI dynamic process routines])
1125fi
1126
1127# MPL
1128PAC_CONFIG_SUBDIR(src/mpl,,AC_MSG_ERROR(MPL configure failed))
1129PAC_PREPEND_FLAG([-lmpl], [WRAPPER_LIBS])
1130PAC_APPEND_FLAG([-I${master_top_builddir}/src/mpl/include], [CPPFLAGS])
1131PAC_APPEND_FLAG([-I${use_top_srcdir}/src/mpl/include], [CPPFLAGS])
1132EXTERNAL_SRC_DIRS="$EXTERNAL_SRC_DIRS src/mpl"
1133other_install_dirs="$other_install_dirs src/mpl"
1134
1135# OpenPA
1136AC_ARG_WITH([openpa-prefix],
1137            [AS_HELP_STRING([[--with-openpa-prefix[=DIR]]],
1138                            [use the OpenPA atomics library installed in DIR,
1139                             rather than the one included in src/openpa.  Pass
1140                             "embedded" to force usage of the OpenPA source
1141                             distributed with MPICH2.])],
1142            [],
1143            [# see if OPA is already installed on the system
1144             PAC_PUSH_FLAG([LIBS])
1145             PAC_PREPEND_FLAG([-lopa],[LIBS])
1146             AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
1147#include "opa_primitives.h"
1148],[
1149OPA_int_t i;
1150OPA_store_int(i,10);
1151OPA_fetch_and_incr_int(&i,5);
1152])dnl
1153                             ],
1154                            [with_openpa_prefix=system],[with_openpa_prefix=embedded])
1155             PAC_POP_FLAG([LIBS])
1156             ])
1157# @opadir@ is used in src/Makefile.sm to control whether or not the OPA in
1158# src/openpa is built and installed
1159opadir=""
1160AC_SUBST([opadir])
1161
1162if test "$with_openpa_prefix" = "embedded" ; then
1163    if test -e "${use_top_srcdir}/src/openpa" ; then
1164        opadir="openpa"
1165        EXTERNAL_SRC_DIRS="$EXTERNAL_SRC_DIRS src/openpa"
1166        PAC_APPEND_FLAG([-I${use_top_srcdir}/src/openpa/src],[CPPFLAGS])
1167        PAC_APPEND_FLAG([-I${master_top_builddir}/src/openpa/src],[CPPFLAGS])
1168
1169        # OPA defaults to "auto", but in MPICH2 we want "auto_allow_emulation" to
1170        # easily permit using channels like ch3:sock that don't care about atomics
1171        AC_ARG_WITH([atomic-primitives],
1172                    [AS_HELP_STRING([--with-atomic-primitives],
1173                                    [Force OPA to use a specific atomic primitives
1174                                     implementation.  See the src/openpa directory
1175                                     for more info.])],
1176                    [],[with_atomic_primitives=not_specified])
1177        opa_subdir_args=""
1178        if test "$with_atomic_primitives" = "not_specified" ; then
1179            opa_subdir_args="--with-atomic-primitives=auto_allow_emulation"
1180        fi
1181        PAC_CONFIG_SUBDIR_ARGS([src/openpa],[$opa_subdir_args],[],[AC_MSG_ERROR([OpenPA configure failed])])
1182        PAC_PREPEND_FLAG([-lopa],[WRAPPER_LIBS])
1183
1184        other_install_dirs="$other_install_dirs src/openpa"
1185    else
1186        AC_MSG_WARN([Attempted to use the embedded OpenPA source tree in "src/openpa", but it is missing.  Configuration or compilation may fail later.])
1187    fi
1188elif test "$with_openpa_prefix" = "system" ; then
1189    PAC_PREPEND_FLAG([-lopa],[WRAPPER_LIBS])
1190elif test "$with_openpa_prefix" = "no" ; then
1191    # The user doesn't want to use OPA.  This may or may not cause MPICH2 to
1192    # fail to configure/build, depending on many other factors.
1193    :
1194else
1195    # The user specified an already-installed OPA; just sanity check, don't
1196    # subconfigure it
1197    AS_IF([test -s "${with_openpa_prefix}/include/opa_primitives.h" -a -s "${with_openpa_prefix}/include/opa_config.h"],
1198          [:],[AC_MSG_ERROR([the OpenPA installation in "${with_openpa_prefix}" appears broken])])
1199    PAC_APPEND_FLAG([-I${with_openpa_prefix}/include],[CPPFLAGS])
1200    PAC_PREPEND_FLAG([-lopa],[WRAPPER_LIBS])
1201    if test -d ${with_openpa_prefix}/lib64 ; then
1202        PAC_APPEND_FLAG([-L${with_openpa_prefix}/lib64],[WRAPPER_LDFLAGS])
1203    fi
1204    PAC_APPEND_FLAG([-L${with_openpa_prefix}/lib],[WRAPPER_LDFLAGS])
1205fi
1206
1207# ----------------------------------------------------------------------------
1208# Threads
1209# ----------------------------------------------------------------------------
1210#
1211# Threads must be supported by the device.  First, set the default to
1212# be the highest supported by the device
1213if test "$enable_threads" = default ; then
1214    # XXX DJG bug is here, PREREQ is not being used right now
1215    if test -n "$MPID_MAX_THREAD_LEVEL" ; then
1216        case $MPID_MAX_THREAD_LEVEL in
1217            MPI_THREAD_SINGLE)     enable_threads=single ;;
1218            MPI_THREAD_FUNNELED)   enable_threads=funneled ;;
1219            MPI_THREAD_SERIALIZED) enable_threads=serialized ;;
1220            MPI_THREAD_MULTIPLE)   enable_threads=runtime ;;
1221            *) AC_MSG_ERROR([Unrecognized thread level from device $MPID_MAX_THREAD_LEVEL])
1222    	    ;;
1223        esac
1224    else
1225        enable_threads=single
1226    fi
1227fi
1228
1229if test "$enable_threads" = "yes" ; then
1230    enable_threads=multiple
1231elif test "$enable_threads" = "no" ; then
1232    enable_threads=single
1233elif test "$enable_threads" = "default"; then
1234    if test "$with_device" = "default" -o "$with_device" = "ch3:sock" ; then
1235        enable_threads=runtime
1236    fi
1237fi
1238
1239# Runtime is an alias for multiple with an additional value
1240if test "$enable_threads" = "runtime" ; then
1241    AC_DEFINE(HAVE_RUNTIME_THREADCHECK,1,[Define if MPI supports MPI_THREAD_MULTIPLE with a runtime check for thread level])
1242    enable_threads=multiple
1243fi
1244
1245MPICH_THREAD_LEVEL=MPI_THREAD_FUNNELED
1246case "$enable_threads" in
1247    single)
1248    thread_pkg_required=no
1249    MPICH_THREAD_LEVEL=MPI_THREAD_SINGLE
1250    ;;
1251    funneled)
1252    thread_pkg_required=no
1253    MPICH_THREAD_LEVEL=MPI_THREAD_FUNNELED
1254    ;;
1255    serialized)
1256    # FIXME: Why does serialized require a thread package?
1257    thread_pkg_required=yes
1258    MPICH_THREAD_LEVEL=MPI_THREAD_SERIALIZED
1259    ;;
1260    multiple)
1261    thread_pkg_required=yes
1262    MPICH_THREAD_LEVEL=MPI_THREAD_MULTIPLE
1263    ;;
1264    *)
1265    AC_MSG_ERROR(["$enable_threads" is not a valid value for --enable-threads])
1266    ;;
1267esac
1268# Check that the requested thread level is available.
1269threadLevelOK=yes
1270if test -z "$MPID_MAX_THREAD_LEVEL" ; then
1271    if test "$MPICH_THREAD_LEVEL" = "MPI_THREAD_MULTIPLE" -o "$MPICH_THREAD_LEVEL" = "MPI_THREAD_SERIALIZED" ; then
1272        threadLevelOK=no
1273    fi
1274else
1275    # Check that MPID_MAX_THREAD_LEVEL is at least as large as the
1276    # selected MPICH_THREAD_LEVEL
1277    case $MPICH_THREAD_LEVEL in
1278        MPI_THREAD_MULTIPLE)
1279	if test "$MPID_MAX_THREAD_LEVEL" != "MPI_THREAD_MULTIPLE" ; then
1280	    threadLevelOK=no
1281        fi
1282	;;
1283	MPI_THREAD_SERIALIZED)
1284	if test "$MPID_MAX_THREAD_LEVEL" != "MPI_THREAD_MULTIPLE" -a \
1285	        "$MPID_MAX_THREAD_LEVEL" != "MPI_THREAD_SERIALIZED" ; then
1286            threadLevelOK=no
1287        fi
1288	;;
1289	MPI_THREAD_FUNNELED)
1290        if test "$MPID_MAX_THREAD_LEVEL" = "MPI_THREAD_SINGLE" ; then
1291            threadLevelOK=no
1292        fi
1293	;;
1294	MPI_THREAD_SINGLE)
1295	;;
1296    esac
1297fi
1298if test "$threadLevelOK" != yes ; then
1299   AC_MSG_ERROR([The device $with_device does not support $MPICH_THREAD_LEVEL])
1300fi
1301
1302export MPICH_THREAD_LEVEL
1303AC_DEFINE_UNQUOTED(MPICH_THREAD_LEVEL,$MPICH_THREAD_LEVEL,[Level of thread support selected at compile time])
1304
1305if test "$thread_pkg_required" = "no" ; then
1306    MPIU_THREAD_DEFAULT=${MPIU_THREAD_DEFAULT:-none}
1307fi
1308export MPIU_THREAD_DEFAULT
1309
1310# Check for value thread_cs choice; set the refcount default if necessary
1311thread_granularity=MPIU_THREAD_GRANULARITY_SINGLE
1312thread_refcount=MPIU_REFCOUNT_NONE
1313if test "$enable_threads" = "multiple" ; then
1314    case $enable_thread_cs in
1315    global)
1316    thread_granularity=MPIU_THREAD_GRANULARITY_GLOBAL
1317    if test "$enable_refcount" = "default" ; then enable_refcount=none ; fi
1318    ;;
1319    brief-global|brief_global)
1320    AC_MSG_ERROR([--enable-thread-cs=brief-global is no longer supported, please select a different granularity])
1321    ;;
1322    per-object|per_object)
1323    thread_granularity=MPIU_THREAD_GRANULARITY_PER_OBJECT
1324    if test "$enable_refcount" = "default" ; then enable_refcount=lock ; fi
1325    ;;
1326    lock-free|lock_free|lockfree)
1327    thread_granularity=MPIU_THREAD_GRANULARITY_LOCK_FREE
1328    if test "$enable_refcount" = "default" ; then enable_refcount=lock-free ; fi
1329    if test "$enable_predefined_refcount" = "default" ; then enable_predefined_refcount=no ; fi
1330    ;;
1331    *)
1332    AC_MSG_ERROR([Unrecognized value $enable_thread_cs for --enable-thread-cs])
1333    ;;
1334    esac
1335
1336    case $enable_refcount in
1337    lock)
1338    thread_refcount=MPIU_REFCOUNT_LOCK
1339    ;;
1340    lock-free|lock_free|lockfree)
1341    thread_refcount=MPIU_REFCOUNT_LOCKFREE
1342    ;;
1343    none)
1344    thread_refcount=MPIU_REFCOUNT_NONE
1345    ;;
1346    *)
1347    AC_MSG_ERROR([Unrecognized value $enable_refcount for --enable-refcount])
1348    ;;
1349    esac
1350fi
1351AC_DEFINE_UNQUOTED([MPIU_THREAD_GRANULARITY],$thread_granularity,[Method used to implement atomic updates and access])
1352
1353if test "$enable_predefined_refcount" = "no" ; then
1354    AC_DEFINE([MPIU_THREAD_SUPPRESS_PREDEFINED_REFCOUNTS],[1],[define to disable reference counting predefined objects like MPI_COMM_WORLD])
1355fi
1356
1357case $enable_handle_allocation in
1358    mutex|default)
1359        handle_allocation_method=MPIU_HANDLE_ALLOCATION_MUTEX
1360    ;;
1361    tls)
1362        handle_allocation_method=MPIU_HANDLE_ALLOCATION_THREAD_LOCAL
1363    ;;
1364    *)
1365        AC_MSG_ERROR([Unrecognized value $enable_handle_allocation for --enable-handle-allocation])
1366    ;;
1367esac
1368AC_DEFINE_UNQUOTED([MPIU_HANDLE_ALLOCATION_METHOD],$handle_allocation_method,[Method used to allocate MPI object handles])
1369
1370
1371AC_DEFINE_UNQUOTED([MPIU_THREAD_REFCOUNT],$thread_refcount,[Method used to implement refcount updates])
1372
1373# enable-g
1374# strip off multiple options, separated by commas
1375save_IFS="$IFS"
1376IFS=","
1377for option in $enable_g ; do
1378    case "$option" in
1379        debug|dbg)
1380        enable_append_g=yes
1381	;;
1382        no|none)
1383	;;
1384	handlealloc)
1385	perform_handlealloc=yes
1386	;;
1387	handle)
1388	AC_DEFINE(MPICH_DEBUG_HANDLES,1,[Define to enable handle checking])
1389	;;
1390	instr)
1391	perform_instr=yes
1392	;;
1393	meminit)
1394	perform_meminit=yes
1395	;;
1396	memarena)
1397	perform_memarena=yes
1398	perform_memtracing=yes
1399	;;
1400	mem)
1401	perform_memtracing=yes
1402	;;
1403	log)
1404	perform_dbglog=yes
1405	;;
1406	mutex)
1407	perform_dbgmutex=yes
1408	;;
1409	mutexnesting)
1410	perform_mutexnesting=yes
1411	;;
1412	all|yes)
1413	perform_memtracing=yes
1414	perform_dbglog=yes
1415	enable_append_g=yes
1416	perform_meminit=yes
1417	perform_instr=yes
1418	perform_dbgmutex=yes
1419	perform_mutexnesting=yes
1420	perform_handlealloc=yes
1421	;;
1422	*)
1423	IFS=$save_IFS
1424	AC_MSG_WARN([Unknown value $option for enable-g])
1425	IFS=","
1426	;;
1427    esac
1428done
1429IFS="$save_IFS"
1430
1431if test "$enable_append_g" = "yes" ; then
1432    CFLAGS="$CFLAGS -g"
1433    CXXFLAGS="$CXXFLAGS -g"
1434    FFLAGS="$FFLAGS -g"
1435    FCFLAGS="$FCFLAGS -g"
1436fi
1437if test "$enable_append_ndebug" = "yes" ; then
1438    CFLAGS="$CFLAGS -DNDEBUG -DNVALGRIND"
1439    CXXFLAGS="$CXXFLAGS -DNDEBUG -DNVALGRIND"
1440    # MPICH2 does NOT assume any preprocessing support from the Fortran compiler,
1441    # so no Fortran files contain any preprocessing statements.
1442    # Don't set FFLAGS or FCFLAGS with any -D.
1443fi
1444if test -n "$perform_meminit" ; then
1445    AC_DEFINE(MPICH_DEBUG_MEMINIT,1,[Define to enable preinitialization of memory used by structures and unions])
1446fi
1447if test "$perform_handlealloc" = yes ; then
1448    AC_DEFINE(MPICH_DEBUG_HANDLEALLOC,1,[Define to enable checking of handles still allocated at MPI_Finalize])
1449fi
1450if test "$perform_instr" = yes ; then
1451    AC_DEFINE(USE_MPIU_INSTR,1,[Define this to enable internal instrumentation] )
1452fi
1453
1454if test -n "$perform_memtracing" ; then
1455    enable_g_mem=yes
1456    AC_DEFINE(USE_MEMORY_TRACING,1,[Define to enable memory tracing])
1457    if test -n "$perform_memarena" ; then
1458        AC_DEFINE(MPICH_DEBUG_MEMARENA,1,[Define if each function exit should confirm memory arena correctness])
1459    fi
1460fi
1461if test -n "$perform_mutexnesting" ; then
1462    AC_DEFINE(MPICH_DEBUG_MUTEXNESTING,1,[Define to check nesting in mutexes])
1463fi
1464USE_DBG_LOGGING=0
1465if test -n "$perform_dbglog" ; then
1466   if test "$with_logging" != "none" ; then
1467       AC_MSG_WARN([--with-logging overrides --enable-g=log])
1468   else
1469       AC_DEFINE(USE_DBG_LOGGING,1,[Define to enable logging macros])
1470       USE_DBG_LOGGING=1
1471   fi
1472fi
1473# allow @USE_DBG_LOGGING@ substitution in glue_romio.h
1474AC_SUBST([USE_DBG_LOGGING])
1475
1476if test -n "$perform_dbgmutex" ; then
1477   AC_DEFINE(MPICH_DEBUG_MUTEX,1,[Define to enable mutex debugging])
1478fi
1479
1480pac_cross_compiling=no
1481if test "$with_cross" != "no" ; then
1482    if test -s "$with_cross" ; then
1483        AC_MSG_RESULT([Reading values from cross-compilation file $with_cross])
1484        . $with_cross
1485	# Autoconf 2.52 no longer sets cross_compiling except with the
1486	# awkward "targethost" options.
1487	pac_cross_compiling=yes
1488	cross_compiling=yes
1489	ac_cv_prog_cc_cross=yes
1490	ac_cv_prog_f77_cross=yes
1491 	ac_cv_prog_fc_cross=yes
1492        ac_cv_prog_cxx_cross=yes
1493        export cross_compiling
1494	# Export all cross variables.  Any subsidiary configure should also
1495        # export CROSS_xxx
1496	rm -f confcross
1497	(set) 2>&1 | grep CROSS_ | \
1498	      sed -e 's/^/export /g' -e 's/=.*//g' > confcross
1499	. confcross
1500	rm -f confcross
1501    fi
1502fi
1503
1504# This goes here because we need the top_srcdir
1505if test "$enable_romio" = "yes" ; then
1506   if test -d $use_top_srcdir/src/mpi/romio ; then
1507       subsystems="$subsystems src/mpi/romio"
1508       AC_DEFINE(HAVE_ROMIO,1,[Define if ROMIO is enabled])
1509
1510       # make it possible to "#include" mpio.h at build time
1511       #
1512       # This ought to be sufficient, but there is also a symlink setup in
1513       # src/include to accomodate current mpicc and MPE2 limitations.  See
1514       # src/mpi/Makefile.mk for more info.
1515       PAC_APPEND_FLAG([-I${master_top_builddir}/src/mpi/romio/include],[CPPFLAGS])
1516
1517       # Set environment variables that the romio configure expects
1518       romio_dir=romio
1519       AC_SUBST(romio_dir)
1520       export use_top_srcdir
1521       top_build_dir=`pwd`
1522       export top_build_dir
1523       # if there is no $top_build_dir/lib, romio puts lib in wrong place
1524       # This test used -e under Linux, but not all test programs understand
1525       # -e
1526       if test ! -d lib ; then mkdir lib ; fi
1527       # tell mpi.h to include mpio.h
1528       PAC_HAVE_ROMIO
1529   else
1530       AC_MSG_WARN([ROMIO src directory is not available])
1531   fi
1532fi
1533
1534AM_CONDITIONAL([BUILD_ROMIO], [test x$enable_romio = xyes])
1535
1536#
1537# FIXME: If an external device, don't necessarily complain (e.g.,
1538# if the device is already built)
1539if test ! -d $devicedir ; then
1540    AC_MSG_ERROR([Device $device_name is unknown])
1541elif test -f $devicedir/subconfigure.m4 ; then
1542    # this is a new-style subconfigure device, don't add it as a subsystem
1543    :
1544elif test ! -x $devicedir/configure ; then
1545    if test -s $devicedir/configure ; then
1546        AC_MSG_WARN([The configure in $devicedir exists but is not executable])
1547    else
1548        AC_MSG_WARN([Device $device_name has no configure])
1549    fi
1550    device_name=""
1551else
1552    # Add the device to the configure list
1553    devsubsystems="$devsubsystems $devicereldir"
1554    # Make device_name available to subdirs
1555fi
1556#
1557# Allow the device to request that the install step invoke the install
1558# target in the device's Makefile.
1559if test -n "$device_name" -a "$INSTALL_FROM_DEVICE" = yes ; then
1560    other_install_dirs="${other_install_dirs} $devicereldir"
1561fi
1562AC_SUBST(device_name)
1563#
1564# with-pm
1565if test "$with_pm" = "none" ; then
1566    # add "none" as synonym for "no" to agree with older erroneous docs
1567    with_pm="no"
1568fi
1569if test "$MPID_NO_PM" = yes ; then
1570    if test "$with_pm" != "default" -a "$with_pm" != no ; then
1571        AC_MSG_ERROR([The PM chosen ($with_pm) is is not valid for the selected device ($with_device)])
1572    fi
1573    # This is used to change with_pm=default to with_pm=no in the case
1574    # where the device does not want a PM
1575    with_pm=no
1576fi
1577if test -z "$with_pm" ; then
1578    with_pm="no"
1579fi
1580if test "$with_pmi" = "uni" -a "$with_pm" = "default" ; then
1581    with_pm="no"
1582fi
1583if test "$with_pm" = "default" -o "$with_pm" = "yes" ; then
1584    with_pm=hydra
1585fi
1586
1587# We allow multiple pm names, separated by : or ,
1588# If multiple PMs are provided, we set the value MANY_PM to yes
1589MANY_PM=no
1590AC_SUBST(MANY_PM)
1591if test "$with_pm" != "no" ; then
1592    pm_names="`echo $with_pm | sed -e 's/:/ /g' -e 's/,/ /g'`"
1593else
1594    pm_names=""
1595fi
1596#
1597hasError=no
1598# We need to be careful about PM's that have either conflicting
1599# requirements (e.g., different PMI implementations) or different
1600# optional features (e.g., MPID_PM_NAMESERVER).
1601# In addition, we need to interleave the setup of the PMI and PM
1602# modules.  The order is as follows:
1603#
1604# For each PM, execute the mpich2prereq script for that pm (if present).
1605# This script provides information about the PM, including which PMI
1606# implementations are supported.
1607#
1608# Then, for the selected PMI, the setup script (if any) is run.  This is
1609# necessary because the setup of the PM may require information discovered
1610# or provided duing the PMI setup step (e.g., smpd requires this)
1611#
1612# Finally, for each PM, the setup script is executed.
1613#
1614# Step 1: invoke the mpich2prereq for each PM
1615for pm_name in $pm_names ; do
1616    if test -z "$first_pm_name" ; then
1617       first_pm_name=$pm_name
1618       export first_pm_name
1619    else
1620       # Only add to other_pm_names if the directory exists,
1621       # since the Makefile in src/pm/Makefile will try to cd to
1622       # that directory
1623       if test -d $use_top_srcdir/src/pm/$pm_name ; then
1624           other_pm_names="$other_pm_names $pm_name"
1625       fi
1626    fi
1627    if test ! -d $use_top_srcdir/src/pm/$pm_name ; then
1628        AC_MSG_WARN([$use_top_srcdir/src/pm/$pm_name does not exist. PM is unknown])
1629	hasError=yes
1630    elif test ! -x $use_top_srcdir/src/pm/$pm_name/configure -a \
1631              ! -f $use_top_srcdir/src/pm/$pm_name/subconfigure.m4 ; then
1632        if test -s $use_top_srcdir/src/pm/$pm_name/configure ; then
1633	    AC_MSG_WARN([The configure in $use_top_srcdir/src/pm/$pm_name exists but is not executable])
1634        else
1635            AC_MSG_WARN([pm $pm_name has no configure or subconfigure.m4])
1636        fi
1637        pm_name=""
1638	hasError=yes
1639    else
1640	nameserver=$MPID_PM_NAMESERVER
1641        if test -f $use_top_srcdir/src/pm/$pm_name/mpich2prereq ; then
1642	    echo sourcing $use_top_srcdir/src/pm/$pm_name/mpich2prereq
1643	    . $use_top_srcdir/src/pm/$pm_name/mpich2prereq
1644	fi
1645	# Check for a change; if found, we'll take the default
1646	if test "$MPID_PM_NAMESERVER" != "$nameserver" ; then
1647            if test "$first_pm_name" != "$pm_name" ; then
1648	        # Reject suggestion (use the default, common mode)
1649		MPID_PM_NAMESERVER=""
1650	    fi
1651	fi
1652    fi
1653done
1654if test "$hasError" != no ; then
1655    AC_MSG_ERROR([Aborting configure because an error was seen in the selection of process managers])
1656fi
1657#
1658# pm_name is the *primary* pm
1659pm_name=$first_pm_name
1660AC_SUBST(pm_name)
1661AC_SUBST(other_pm_names)
1662
1663# Some versions of PM and PMI require a special definition (currently, only
1664# smpd requires this)
1665if test "$PMI_REQUIRES_READABLE_TOKENS" = "yes" ; then
1666    AC_DEFINE(USE_HUMAN_READABLE_TOKENS,1,[Define to use ='s and spaces in the string utilities.])
1667fi
1668
1669if test -n "$first_pm_name" ; then
1670    other_install_dirs="${other_install_dirs} src/pm/$first_pm_name"
1671fi
1672# Step 2:
1673# Once we've selected the process manager (or managers), we can
1674# check that we have a compatible PMI implemenatation.
1675# with-pmi
1676if test "$MPID_NO_PMI" = yes ; then
1677    if test "$with_pmi" != "default" -a "$with_pmi" != no ; then
1678        AC_MSG_ERROR([The PMI chosen ($with_pmi) is is not valid for the selected device ($with_device)])
1679    fi
1680    # This is used to change with_pmi=default to with_pmi=no in the case
1681    # where the device does not want a PMI
1682    with_pmi=no
1683elif test "$with_pmi" != "no" ; then
1684    if test "$with_pmi" = "default" -o "$with_pmi" = "yes" ; then
1685        if test -n "$PM_REQUIRES_PMI" ; then
1686	    with_pmi=$PM_REQUIRES_PMI
1687        else
1688            with_pmi=simple
1689        fi
1690    elif test -n "$PM_REQUIRES_PMI" ; then
1691        # Test for compatibility between pm and pmi choices
1692        if test "$PM_REQUIRES_PMI" != "$with_pmi" ; then
1693	    AC_MSG_ERROR([The PM chosen ($with_pm) requires the PMI implementation $PM_REQUIRES_PMI but $with_pmi was selected as the PMI implementation.])
1694        fi
1695    fi
1696    pmi_name=$with_pmi
1697
1698    if test ! -d $use_top_srcdir/src/pmi/$pmi_name ; then
1699        AC_MSG_WARN([$use_top_srcdir/src/pmi/$pmi_name does not exist. PMI is unknown])
1700    elif test ! -x $use_top_srcdir/src/pmi/$pmi_name/configure ; then
1701        if test ! -f $use_top_srcdir/src/pmi/$pmi_name/subconfigure.m4 ; then
1702            AC_MSG_WARN([pmi $pmi_name has no configure or subconfigure.m4])
1703            pmi_name=""
1704        fi
1705    else
1706        # only add to subsystems if a full configure is present
1707        subsystems="$subsystems src/pmi/$pmi_name"
1708    fi
1709else
1710    AC_MSG_ERROR([A PMI implementation must be selected or the default used.])
1711fi
1712AC_SUBST(pmi_name)
1713
1714# Step 3: complete pm setup.
1715# Note that checks for errors have already been performed, so this
1716# loop does not need to perform any extra error checks.
1717# Note that this uses this_pm_name because pm_name must be the *first*
1718# of the PM names
1719for this_pm_name in $pm_names ; do
1720    # only add the PM to the subsystems if it has a full configure to be
1721    # executed
1722    if test -f $use_top_srcdir/src/pm/$this_pm_name/configure ; then
1723        subsystems="$subsystems src/pm/$this_pm_name"
1724    fi
1725    if test -f $use_top_srcdir/src/pm/$this_pm_name/setup_pm ; then
1726	echo sourcing $use_top_srcdir/src/pm/$this_pm_name/setup_pm
1727	. $use_top_srcdir/src/pm/$this_pm_name/setup_pm
1728    fi
1729done
1730
1731# ----------------------------------------------------------------------------
1732if test $with_mpe != no ; then
1733    if test ! -d $use_top_srcdir/src/mpe2 ; then
1734        if test $with_mpe = yes ; then
1735	    # No warning message on the default
1736            AC_MSG_WARN([No MPE directory available])
1737        fi
1738    elif test ! -x $use_top_srcdir/src/mpe2/configure ; then
1739        if test $with_mpe = yes ; then
1740	    # No warning message on the default
1741            AC_MSG_WARN([No configure available for MPE])
1742        fi
1743    else
1744        subsystems="$subsystems src/mpe2"
1745	other_install_dirs="$other_install_dirs src/mpe2"
1746	mpe_dir=mpe2
1747
1748        # for AM_CONDITIONAL
1749        build_src_mpe2=yes
1750
1751	# Temporarily replace the default NONE value for exec_prefix
1752	# and prefix with the actual, default values.
1753	savePrefix=$prefix
1754	saveExecprefix=$exec_prefix
1755	test "x$prefix" = xNONE && prefix=$ac_default_prefix
1756	test "x$exec_prefix" = xNONE && exec_prefix=$prefix
1757	eval actualbindir=$bindir
1758	# MPI_CC and MPIF77 must use the local (build) bin dir, not
1759	# the installation bin dir
1760	#MPI_CC=$actualbindir/mpicc
1761	#MPI_F77=$actualbindir/mpif77
1762	#eval actuallibdir=$libdir
1763	#MPI_LIBS="-L$actuallibdir -lmpich -lpmpich"
1764	buildbindir=`pwd`/bin
1765	#MPI_CC=$buildbindir/mpicc
1766	#MPI_F77=$buildbindir/mpif77
1767	prefix=$savePrefix
1768	exec_prefix=$saveExecprefix
1769	# NOTE: You must append LIBS to MPI_LIBS before invoking the mpe
1770	# configure
1771	#export MPI_CC
1772	#export MPI_F77
1773	#export MPI_LIBS
1774        export use_top_srcdir
1775        top_build_dir=`pwd`
1776        export top_build_dir
1777    fi
1778fi
1779AC_SUBST(mpe_dir)
1780AC_SUBST(other_install_dirs)
1781AM_CONDITIONAL([BUILD_SRC_MPE2],[test "X$build_src_mpe2" = "Xyes"])
1782
1783# Check for whether the compiler defines a symbol that contains the
1784# function name.  The MPICH2 code, for greater portability, defines
1785# its own symbols, FCNAME (a string) and FUNCNAME (a token that is not a
1786# string).  Code should use these symbols where possible.  However,
1787# some debugging macros may want to use a compiler-provided symbol
1788# for the function name, and this check makes it possible to
1789# define such macros in a way that is always correct.
1790PAC_CC_FUNCTION_NAME_SYMBOL
1791
1792# Check if $MPI_DEFAULT_COPTS is valid with $CC
1793if test "$enable_default_optimize" = "yes" \
1794     -a -n "$MPI_DEFAULT_COPTS" ; then
1795    if test "$enable_check_compiler_flags" = "yes" ; then
1796        PAC_C_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_COPTS], [
1797        CFLAGS="$CFLAGS $MPI_DEFAULT_COPTS"
1798                                   ] )
1799    else
1800        CFLAGS="$CFLAGS $MPI_DEFAULT_COPTS"
1801    fi
1802fi
1803
1804# Check for support for weak symbols.  If not found, set NO_WEAK_SYM
1805# to the Make target name understood by simplemake.
1806# Set NEEDSPLIB to yes if link commands need both -l$MPILIBNAME
1807# and -lp$MPILIBNAME.
1808NEEDSPLIB=yes
1809NO_WEAK_SYM_TARGET=build_proflib
1810if test $enable_weak_symbols = yes ; then
1811    # Turn off weak symbols if they aren't available
1812    PAC_PROG_C_WEAK_SYMBOLS(,enable_weak_symbols=no)
1813fi
1814if test $enable_weak_symbols = "yes" ; then
1815    AC_DEFINE(USE_WEAK_SYMBOLS,1,[Define if weak symbols should be used])
1816    NEEDSPLIB=no
1817    # Check for the ability to support multiple weak symbols
1818    if test "$pac_cv_prog_c_weak_symbols" = "pragma weak" ; then
1819       PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS(AC_DEFINE(HAVE_MULTIPLE_PRAGMA_WEAK,1,[Define if multiple weak symbols may be defined]))
1820    fi
1821else
1822    NO_WEAK_SYM=build_proflib
1823    PROFILE_DEF_MPI="-DMPICH_MPI_FROM_PMPI"
1824fi
1825export NEEDSPLIB
1826export NO_WEAK_SYM
1827export NO_WEAK_SYM_TARGET
1828export PROFILE_DEF_MPI
1829AC_SUBST(NEEDSPLIB)
1830AC_SUBST(NO_WEAK_SYM)
1831AC_SUBST(NO_WEAK_SYM_TARGET)
1832AC_SUBST(PROFILE_DEF_MPI)
1833
1834AM_CONDITIONAL([BUILD_PROFILING_LIB],[test "$NEEDSPLIB" = "yes"])
1835
1836# ---------------------------------------------------------------------------
1837# determine rpath and other shared library flags for CC
1838# src/env may not exist yet in a vpath build
1839$MKDIR_P src/env
1840cc_shlib_conf=src/env/cc_shlib.conf
1841PAC_COMPILER_SHLIB_FLAGS([CC],[$cc_shlib_conf])
1842AC_SUBST_FILE([cc_shlib_conf])
1843
1844# ---------------------------------------------------------------------------
1845# Support for the language bindings: Fortran 77, Fortran 90, and C++
1846#
1847# First, we handle the case of no explicit enable/disable option.  In that
1848# case, we look for a usable compiler.  We cannot use the ac macros for this
1849# because they abort the configure step if they fail to find a compiler
1850# (earlier versions of autoconf did not have this behavior!).
1851#
1852# Second, we perform the langugage-specific tests, if necessary.  This may
1853# be relatively simple (C++) or complex (Fortran 77, including formation of
1854# the encoded MPI handles).
1855#
1856# Note that the bindings support needs to know some of the properties of
1857# the C compiler, so those tests (particularly for weak symbols)
1858# must come first.
1859# ----------------------------------------------------------------------------
1860
1861#
1862# First, determine whether we are/can support the language bindings
1863#
1864# Since F90/F90FLAGS are replaced by FC/FCFLAGS, rather than silently
1865# substituting them, i.e. FC=$F90 and FCFLAGS=$F90FLAGS, we choose to emit
1866# an error message and abort to avoid any ambiguous/hidden bug in choosing
1867# Fortran90 compilers.
1868if test -n "$F90" -o -n "$F90FLAGS" ; then
1869    AC_MSG_ERROR([F90 and F90FLAGS are replaced by FC and FCFLAGS respectively in this configure, please unset F90/F90FLAGS and set FC/FCFLAGS instead and rerun configure again.])
1870fi
1871# ----------------------------------------------------------------------------
1872# Handle default choices for the Fortran compilers
1873if test "$enable_f77" = "yes" ; then
1874    # Check for a Fortran compiler
1875    # FIXME already done earlier
1876    dnl PAC_PROG_F77
1877    :
1878fi
1879
1880if test "$enable_f77" = "yes" -a "$F77" = "" ; then
1881   # No Fortran 77 compiler found; abort
1882   AC_MSG_ERROR([No Fortran 77 compiler found. If you don't need to
1883   build any Fortran programs, you can disable Fortran support using
1884   --disable-f77 and --disable-fc. If you do want to build Fortran
1885   programs, you need to install a Fortran compiler such as gfortran
1886   or ifort before you can proceed.])
1887fi
1888
1889if test "$enable_f77" = yes ; then
1890    # Check if $MPI_DEFAULT_FOPTS is valid with $F77
1891    if test "$enable_default_optimize" = "yes" \
1892         -a -n "$MPI_DEFAULT_FOPTS" ; then
1893        if test "$enable_check_compiler_flags" = "yes" ; then
1894            PAC_F77_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_FOPTS], [
1895            FFLAGS="$FFLAGS $MPI_DEFAULT_FOPTS"
1896                                         ] )
1897        else
1898            FFLAGS="$FFLAGS $MPI_DEFAULT_FOPTS"
1899        fi
1900    fi
1901fi
1902
1903#
1904# We need to know the name mangling for Fortran before testing for FC
1905# compatibility (we need this because of the way we decide to generate
1906# the Fortran 77 bindings)
1907if test "$enable_f77" = yes ; then
1908    FLIBS_save="$FLIBS"
1909    FLIBS=""
1910    AC_F77_LIBRARY_LDFLAGS
1911    # The autoconf macro for finding FLIBS sometimes makes mistakes
1912    # (particularly with the Fujitsu frt compiler).  This next step
1913    # first sees if the FLIBS is valid with the Fortran compiler
1914    PAC_PROG_F77_FLIBS_VALID
1915    # Now see if FLIBS works with the C compiler
1916    PAC_PROG_F77_CHECK_FLIBS
1917
1918    # Check F77+FLAGS is compatible with CC+CFLAGS before using F77+CC.
1919    PAC_PROG_F77_OBJ_LINKS_WITH_C
1920
1921    PAC_PROG_F77_LINKER_WITH_C
1922    # For name mangle, we need the library flags
1923    PAC_PROG_F77_NAME_MANGLE
1924    # Check whether additional libraries are needed when linking with C
1925    PAC_PROG_F77_AND_C_STDIO_LIBS
1926    AC_SUBST(F77_OTHER_LIBS)
1927
1928    # Warn about mixed name mangling, since many of the tests will fail
1929    if test "$pac_cv_prog_f77_name_mangle" = "mixed" ; then
1930        AC_MSG_WARN([The compiler $F77 uses mixed case names.  Fortran is monocase
1931and many Fortran programs may use either upper or lower case names for MPI
1932calls.  Consider specifying a particular parameter to your Fortran compiler
1933to select either upper or lower case names.  For the Absoft compiler,
1934-f selects lower case and -N109 selects upper case (if you use -f, also use
1935-B108 to enable the iargc and getarg routines, which are needed for some
1936tests and by many user programs).  Specify new command
1937line options by setting the environment variable FFLAGS to include
1938the options (e.g., setenv FFLAGS "-f -B108").  In addition, make sure that your
1939Fortran 90 compiler uses a compatible naming choice.  For the
1940Absoft Fortran 90, -YALL_NAMES=LCS selects lower case names and -B108
1941adds underscores to names, as required for iargc and getarg.  Pass this
1942information to configure with the FCFLAGS environment variable.])
1943        # If Fortran implicitly enabled, disable it now.  Otherwise,
1944	# abort the configure since warning messages are often lost in
1945	# the output.
1946	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])
1947    fi
1948
1949    # The MPI standard requires that MPI_Init in any language initialize
1950    # MPI in all languages.  This can be a problem when objects produced
1951    # by the Fortran compiler require symbols from the Fortran runtime
1952    # (making linking C-only programs unnecessarily difficult).  What we test
1953    # here is whether the much more restricted needs of the Fortran
1954    # initialize can be met with no special use of the Fortran runtime
1955   PAC_F77_INIT_WORKS_WITH_C
1956   if test "$pac_f_init_works_with_c" = "yes" ; then
1957       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])
1958   fi
1959
1960fi
1961
1962# FC requires F77 as well.  If the user disabled f77, do not run the
1963# next test; instead, drop into the warning message
1964# Set a default value for fc works with f77.  This value is
1965# set to no *only* if fc was selected but was not compatible with f77
1966fc_with_f77=yes
1967if test "$enable_fc" = "yes" -a "$enable_f77" = yes ; then
1968    enable_fc=no
1969    if test -n "$FC" ; then
1970	# If we allow multiple weak symbols, we should test a name
1971	# that does not contain an underscore.  The Fortran binding uses
1972	# this rule for enabling multiple weak symbols:
1973	# if defined(USE_WEAK_SYMBOLS) && !defined(USE_ONLY_MPI_NAMES) &&
1974	#    defined(HAVE_MULTIPLE_PRAGMA_WEAK) &&
1975	#    defined(F77_NAME_LOWER_2USCORE)
1976	#
1977	testRoutine="t1_2"
1978	if test "$pac_cv_prog_c_multiple_weak_symbols" = "yes" -a \
1979               "$enable_weak_symbols" = "yes" -a \
1980	       "$pac_cv_prog_f77_name_mangle" = "lower doubleunderscore" ; then
1981	    testRoutine="t12"
1982        fi
1983        PAC_FC_AND_F77_COMPATIBLE(fc_with_f77=yes,fc_with_f77=no,$testRoutine)
1984        if test "$fc_with_f77" != yes ; then
1985	    enable_fc=no
1986	    AC_MSG_ERROR([The selected Fortran 90 compiler $FC does not work with the selected Fortran 77 compiler $F77.  Use the environment variables FC 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.])
1987        elif test "$fc_with_f77" = "yes" ; then
1988            # If we got here, there is a Fortran 90 compiler that we can use
1989            enable_fc=yes
1990        fi
1991    elif test "$pac_cv_prog_fc_works" = no; then
1992        AC_MSG_WARN([Use --disable-fc to keep configure from searching for a Fortran 90 compiler])
1993    fi
1994
1995    if test "$enable_fc" = "yes" -a "$FC" = "" ; then
1996       # No Fortran 90 compiler found; abort
1997       AC_MSG_ERROR([No Fortran 90 compiler found. If you don't need
1998       to build any Fortran 90 programs, you can disable Fortran 90
1999       support using --disable-fc. If you do want to build Fortran 90
2000       programs, you need to install a Fortran 90 compiler such as
2001       gfortran or ifort before you can proceed.])
2002    fi
2003fi
2004
2005if test "$enable_fc" = "yes" -a "$enable_f77" != "yes" ; then
2006   # Fortran 90 support requires compatible Fortran 77 support
2007   AC_MSG_ERROR([
2008Fortran 90 support requires compatible Fortran 77 support.
2009To force the use of the Fortran 90 compiler for Fortran 77,
2010do not use configure option --disable-f77, and set the environment
2011variable F77 to the name of the Fortran 90 compiler, or \$FC.
2012If you do not want any Fortran support, use configure options
2013--disable-f77 and --disable-fc.])
2014   # We should probably do the compatibility test as well
2015   enable_f77=yes
2016fi
2017
2018# ----------------------------------------------------------------------------
2019# Now test for Fortran compiler characteristics
2020# ----------------------------------------------------------------------------
2021if test "$enable_f77" = "yes" ; then
2022    # determine rpath and other shared library flags for F77
2023    f77_shlib_conf=src/env/f77_shlib.conf
2024    PAC_COMPILER_SHLIB_FLAGS([F77],[$f77_shlib_conf])
2025    AC_SUBST_FILE([f77_shlib_conf])
2026
2027    AC_LANG_FORTRAN77
2028    PAC_PROG_F77_EXCLAIM_COMMENTS(has_exclaim="yes",has_exclaim="no")
2029    PAC_PROG_F77_HAS_INCDIR(src)
2030    if test -n "$F77_INCDIR" ; then
2031        # For building the Fortran files, add the directory where we are building
2032        # the object to the include list.  This is needed for g77, which makes
2033        # includes relative to the source directory of the file, not the
2034        # directory that the command is executed in
2035        FINCLUDES="$F77_INCDIR`pwd`/src"
2036    fi
2037    AC_SUBST(FINCLUDES)
2038    #
2039    PAC_PROG_F77_LIBRARY_DIR_FLAG
2040
2041    AC_SUBST(MPIFPMPI)
2042    if test "$MPI_WITH_PMPI" = "no" ; then
2043        # If the PMPI routines are not in the same library with the MPI
2044        # routines, we may need to remove the pmpi declarations
2045        PAC_PROG_F77_ALLOWS_UNUSED_EXTERNALS([MPIFPMPI=",PMPI_WTIME,PMPI_WTICK"],[
2046        MPIFPMPI="";
2047        AC_MSG_WARN([Removed PMPI_WTIME and PMPI_WTICK from mpif.h])])
2048    else
2049        MPIFPMPI=",PMPI_WTIME,PMPI_WTICK"
2050    fi
2051
2052    # Once we have name mangle, we can try to limit the number of needed libs
2053    dnl F77_IN_C_LIBS is not needed currently because mpirinitf_() in setbotf.f
2054    dnl is called in initthread.c only when FLIBS is not needed to initialize
2055    dnl Fortran constants from a C main, See PAC_F77_INIT_WORKS_WITH_C.
2056    dnl PAC_PROG_F77_IN_C_LIBS
2057    dnl AC_SUBST(F77_IN_C_LIBS)
2058
2059    # Most systems allow the Fortran compiler to process .F and .F90 files
2060    # using the C preprocessor.  However, some systems either do not
2061    # allow this or have serious bugs (OSF Fortran compilers have a bug
2062    # that generates an error message from cpp).  The following test
2063    # checks to see if .F works, and if not, whether "cpp -P -C" can be used
2064    # This is needed for Mac OSX 10.5
2065    PAC_F77_WORKS_WITH_CPP([F77CPP])
2066    AC_SUBST(F77CPP)
2067
2068    # Check that the Fortran compiler will allow us to pass arguments
2069    # of different types (e.g., for MPI_Send)
2070    PAC_PROG_F77_MISMATCHED_ARGS(addarg,yes)
2071    if test "X$addarg" != "X" ; then
2072        # We could add the names of all of the MPI routines that
2073        # accept different types.  Instead, we fail cleanly.
2074        # Some Fortran compilers allow you to turn off checking for
2075        # mismatched arguments for *all* routines.  Adding an argument
2076	# that turns off checking for *everything* is not something that
2077	# configure should do - if the user wants this, they can follow
2078	# the instructions in the following error message.
2079	AC_MSG_ERROR([The Fortran compiler $F77 does not accept programs that call the same routine with arguments of different types without the option $addarg.  Rerun configure with FFLAGS=$addarg])
2080    fi
2081
2082    bindings="$bindings f77"
2083    bindings_dirs="$bindings_dirs src/binding/f77"
2084    AC_DEFINE(HAVE_FORTRAN_BINDING,1,[Define if Fortran is supported])
2085    # Also define the name FORTRAN_BINDING for use in #if @FORTRAN_BINDING@..
2086    FORTRAN_BINDING=1
2087
2088fi
2089
2090dnl By modifying mpif.h to use ! for comments, it can work with many f90
2091dnl compilers without creating a separate version.
2092dnl Note that this is run AFTER the AC_OUTPUT actions
2093AC_OUTPUT_COMMANDS([if test "$enable_f77" = yes ; then
2094if test "$has_exclaim" = "yes" ; then
2095    sed -e 's/^C/\!/g' src/binding/f77/mpif.h > src/include/mpif.h
2096	cp src/include/mpif.h src/binding/f77/mpif.h
2097else
2098    cp src/binding/f77/mpif.h src/include
2099fi
2100if test "$has_fort_real8" = "yes" ; then
2101    sed -e 's/DOUBLE PRECISION/REAL*8/g' src/include/mpif.h > src/include/mpif.h.new
2102    mv src/include/mpif.h.new src/include/mpif.h
2103    cp src/include/mpif.h src/binding/f77/mpif.h
2104fi
2105fi],
2106master_top_srcdir=$master_top_srcdir
2107enable_f77=$enable_f77
2108enable_fc=$enable_fc
2109has_exclaim=$has_exclaim
2110has_fort_real8=$pac_cv_fort_real8
2111includebuild_dir=$includebuild_dir
2112libbuild_dir=$libbuild_dir
2113bashWorks=$bashWorks)
2114
2115if test "$enable_fc" = "yes" ; then
2116    if test "$enable_f77" != "yes" ; then
2117        AC_MSG_WARN([Fortran 90 requires Fortran 77])
2118        enable_fc=no
2119    else
2120        bindingsubsystems="$bindingsubsystems src/binding/f90"
2121        bindings="$bindings f90"
2122        bindings_dirs="$bindings_dirs src/binding/f90"
2123    fi
2124fi
2125
2126# Set defaults for these values so that the Makefile in src/bindings/f90
2127# is valid even if fc is not enabled (this is necessary for the
2128# distclean target)
2129MPIMODNAME=mpi
2130MPICONSTMODNAME=mpi_constants
2131MPISIZEOFMODNAME=mpi_sizeofs
2132MPIBASEMODNAME=mpi_base
2133if test "$enable_fc" = "yes" ; then
2134    # determine rpath and other shared library flags for FC
2135    fc_shlib_conf=src/env/fc_shlib.conf
2136    PAC_COMPILER_SHLIB_FLAGS([FC],[$fc_shlib_conf])
2137    AC_SUBST_FILE([fc_shlib_conf])
2138
2139    # Determine characteristics of the Fortran 90 compiler
2140    # Find a Fortran 90 compiler.  Sets FC
2141    # Work around bug in autoconf that adds -g to FCFLAGS
2142    saveFCFLAGS="$FCFLAGS"
2143    dnl FIXME XXX DJG this needs to be reconciled with our separate use of
2144    dnl AC_PROG_FC earlier
2145    dnl PAC_PROG_FC
2146    PAC_PROG_FC_WORKS
2147    FCFLAGS=$saveFCFLAGS
2148    if test "$pac_cv_prog_fc_works" = no ; then
2149        # Reject this compiler
2150        if test -n "$FC" ; then
2151            fc_rejected=yes
2152            oldFC="$FC"
2153            FC=""
2154        fi
2155    fi
2156
2157    # Determine the extension for Fortran 90 files (it isn't always .f90)
2158    FCEXT=$ac_fc_srcext
2159    AC_SUBST(FCEXT)
2160
2161    if test -z "$FC" ; then
2162        if test "$fc_rejected" = "yes" ; then
2163            AC_MSG_ERROR([Could not find a usable Fortran 90 compiler.  The compiler $oldFC may be incompatible with the Fortran 77 compiler $F77; check the output of configure and consult the installation manuals])
2164        else
2165            AC_MSG_ERROR([Could not find a usable Fortran 90 compiler.])
2166        fi
2167    fi
2168
2169    # Find the extension that this compiler uses for modules.
2170    # Sets FCMODEXT (and adds it to the list substed)
2171    # Sets FCMODINCFLAG (and adds it to the list substed)
2172    PAC_FC_MODULE
2173    AC_SUBST(FCMODINCSPEC)
2174    if test -z "$FCMODOUTFLAG" ; then
2175        AC_MSG_ERROR([FCMODOUTFLAG could not be determined but is critical for the current Fortran build system])
2176    fi
2177
2178    if test "$pac_cv_fc_module_case" = "upper" ; then
2179        MPIMODNAME=MPI
2180        MPICONSTMODNAME=MPI_CONSTANTS
2181	MPISIZEOFMODNAME=MPI_SIZEOFS
2182	MPIBASEMODNAME=MPI_BASE
2183    else
2184        MPIMODNAME=mpi
2185        MPICONSTMODNAME=mpi_constants
2186	MPISIZEOFMODNAME=mpi_sizeofs
2187	MPIBASEMODNAME=mpi_base
2188    fi
2189    AC_SUBST(MPIMODNAME)
2190    AC_SUBST(MPICONSTMODNAME)
2191    AC_SUBST(MPISIZEOFMODNAME)
2192    AC_SUBST(MPIBASEMODNAME)
2193    if test -z "$modincdir" ; then
2194        # The default module include dir is the same as the include dir
2195        modincdir=$includedir
2196    fi
2197    AC_SUBST(modincdir)
2198    #
2199    # Assume that all Fortran 90 compilers accept -I for include directories
2200    FCINC=-I
2201    AC_SUBST(FCINC)
2202    FCINCFLAG=-I
2203    AC_SUBST(FCINCFLAG)
2204
2205    # Check if $MPI_DEFAULT_FCOPTS is valid with $F90
2206    if test "$enable_default_optimize" = "yes" \
2207         -a -n "$MPI_DEFAULT_FCOPTS" ; then
2208        if test "$enable_check_compiler_flags" = "yes" ; then
2209            PAC_FC_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_FCOPTS], [
2210            FCFLAGS="$FCFLAGS $MPI_DEFAULT_FCOPTS"
2211                                     ] )
2212        else
2213            FCFLAGS="$FCFLAGS $MPI_DEFAULT_FCOPTS"
2214        fi
2215    fi
2216
2217    # Most systems allow the Fortran compiler to process .F and .F90 files
2218    # using the C preprocessor.  However, some systems either do not
2219    # allow this or have serious bugs (OSF Fortran compilers have a bug
2220    # that generates an error message from cpp).  The following test
2221    # checks to see if .F works, and if not, whether "cpp -P -C" can be used
2222    PAC_FC_WORKS_WITH_CPP([FCCPP])
2223    AC_SUBST(FCCPP)
2224
2225    # Check whether additional libraries are needed when linking with C
2226    PAC_PROG_FC_AND_C_STDIO_LIBS
2227    AC_SUBST(FC_OTHER_LIBS)
2228    # ------------------------------------------------
2229fi
2230
2231# ----------------------------------------------------------------------------
2232# We previously allowed "default" as a valid value for $enable_cxx.  Now we
2233# assume its available by default and error out if it doesn't work (just like
2234# F77 & FC).  The user must pass "--disable-cxx" in order to successfully
2235# complete configure in this case.
2236if test "$enable_cxx" = "default" ; then
2237    AC_MSG_ERROR([aborting because "--enable-cxx=default" is no longer a supported value])
2238fi
2239
2240if test "$enable_cxx" = "yes" ; then
2241    # Another bug in autoconf.  The checks for the C++ compiler do not
2242    # ensure that you can link a program that is built with the C++
2243    # compiler.  We've seen this error with gcc and icc, particularly
2244    # when those compilers accept C++ language elements but are unable
2245    # to link programs that are really C++.  For that reason,
2246    # we've added a test to see if the C++ compiler can produce
2247    # an executable.
2248    AC_CACHE_CHECK([whether the C++ compiler $CXX can build an executable],
2249    pac_cv_cxx_builds_exe,[
2250 AC_LANG_PUSH([C++])
2251 AC_TRY_LINK([
2252class mytest {
2253  int a;
2254public:
2255  mytest(void) : a(1) {}
2256  ~mytest(void) {}
2257};],[mytest a;],
2258 pac_cv_cxx_builds_exe=yes, pac_cv_cxx_builds_exe=no)
2259 AC_LANG_POP([C++])
2260])
2261    if test "$pac_cv_cxx_builds_exe" != yes ; then
2262        AC_MSG_ERROR([Aborting because C++ compiler does not work.  If you do not need a C++ compiler, configure with --disable-cxx])
2263    fi
2264    # Recent failures have come when a standard header is loaded
2265    # The Intel icpc 10.x compiler fails with <string> if gcc 4.2 is installed.
2266    AC_CACHE_CHECK([whether C++ compiler works with string],pac_cv_cxx_compiles_string,[
2267    AC_LANG_PUSH([C++])
2268    AC_TRY_COMPILE([#include <string>],[return 0;],pac_cv_cxx_compiles_string=yes,pac_cv_cxx_compiles_string=no)
2269    AC_LANG_POP([C++])
2270])
2271    if test "$pac_cv_cxx_compiles_string" != yes ; then
2272        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])
2273    fi
2274
2275    AC_LANG_CPLUSPLUS
2276    AX_CXX_EXCEPTIONS
2277    AX_CXX_BOOL
2278    AX_CXX_NAMESPACES
2279    if test "$ac_cv_cxx_namespaces" != "yes" ; then
2280        AC_MSG_ERROR([Namespaces are required for the MPI C++ interface])
2281    fi
2282    HAVE_CXX_EXCEPTIONS=0
2283    AC_SUBST(HAVE_CXX_EXCEPTIONS)
2284    if test "$ac_cv_cxx_exceptions" = "yes" ; then
2285        HAVE_CXX_EXCEPTIONS=1
2286    fi
2287    # iostream and math are needed for examples/cxx/cxxpi.cxx
2288    AC_CACHE_CHECK([whether <iostream> available],pac_cv_cxx_has_iostream,[
2289    AC_TRY_COMPILE([
2290#include <iostream>
2291],[using namespace std;],pac_cv_cxx_has_iostream=yes,pac_cv_cxx_has_iostream=no)])
2292    if test "$pac_cv_cxx_has_iostream" = yes ; then
2293        CXX_DEFS="$CXX_DEFS -DHAVE_CXX_IOSTREAM"
2294    fi
2295    AX_CXX_NAMESPACE_STD
2296    if test "$ac_cv_cxx_namespace_std" = "yes" ; then
2297        CXX_DEFS="$CXX_DEFS -DHAVE_NAMESPACE_STD"
2298    fi
2299
2300    AC_CACHE_CHECK([whether <math> available],pac_cv_cxx_has_math,[
2301    AC_TRY_COMPILE([
2302#include <math>
2303],[using namespace std;],pac_cv_cxx_has_math=yes,pac_cv_cxx_has_math=no)])
2304    if test "$pac_cv_cxx_has_math" = yes ; then
2305        CXX_DEFS="$CXX_DEFS -DHAVE_CXX_MATH"
2306    fi
2307    AC_SUBST(CXX_DEFS)
2308
2309    # GNU changed the calling conventions between minor releases (!!!)
2310    # This is too hard to detect, but we should be able to detect
2311    # the version mismatch.  By default, we set the GNU version to 0.
2312    # In a cross-compiling environment, these can be set with environment
2313    # variables, either directly or through the standard "CROSS" variable.
2314    if test -z "$GNUCXX_VERSION" ; then
2315        if test -n "$CROSS_GNUCXX_VERSION" ; then
2316	     GNUCXX_VERSION=$CROSS_GNUCXX_VERSION
2317        else
2318             GNUCXX_VERSION=0
2319        fi
2320    fi
2321    if test -z "$GNUCXX_MINORVERSION" ; then
2322	if test -n "$CROSS_GNUCXX_MINORVERSION" ; then
2323	     GNUCXX_MINORVERSION=$CROSS_GNUCXX_MINORVERSION
2324       	else
2325             GNUCXX_MINORVERSION=0
2326        fi
2327    fi
2328    if test "$cross_compiling" = "no" -a "$ac_compiler_gnu" = "yes" -a \
2329       "$GNUCXX_VERSION" = 0 -a "$GNUCXX_MINORVERSION" = 0 ; then
2330         ac_vals=""
2331	 AC_MSG_CHECKING([for GNU g++ version])
2332         AC_TRY_RUN([#include <stdio.h>
2333int main() {
2334    int v = -1, m = -1;
2335    FILE *fp = fopen("conftest.out","w");
2336#ifdef __GNUC_MINOR__
2337    m = __GNUC_MINOR__;
2338#endif
2339#ifdef __GNUC__
2340    v = __GNUC__;
2341#endif
2342    fprintf( fp, "v=%d, m=%d\n", v, m );
2343    fclose( fp );
2344    return 0;
2345}],ac_vals=`cat conftest.out`)
2346         if test -n "$ac_vals" ; then
2347             v=`echo "$ac_vals" | sed -e 's/v=\(.*\),.*/\1/'`
2348             m=`echo "$ac_vals" | sed -e 's/.*m=\(.*\)/\1/'`
2349             AC_MSG_RESULT([$v . $m])
2350             GNUCXX_VERSION=$v
2351             GNUCXX_MINORVERSION=$m
2352         else
2353             AC_MSG_RESULT([unknown])
2354         fi
2355    fi
2356    AC_SUBST(GNUCXX_VERSION)
2357    AC_SUBST(GNUCXX_MINORVERSION)
2358
2359    bindings="$bindings cxx"
2360    bindings_dirs="$bindings_dirs src/binding/cxx"
2361    AC_DEFINE(HAVE_CXX_BINDING,1,[Define if C++ is supported])
2362    INCLUDE_MPICXX_H='#include "mpicxx.h"'
2363    AC_SUBST(INCLUDE_MPICXX_H)
2364
2365    # In order to support the Fortran datatypes within C++,
2366    #
2367    # FORTRAN_BINDING always has a CPP-time value of either 0 or 1,
2368    # so that it may be used in #if statements without adding to
2369    # the CPP name space
2370    AC_SUBST(FORTRAN_BINDING)
2371
2372    # Special C++ datatypes.  Set to DATATYPE NULL first; we'll
2373    # replace the ones that we have later, after we have determined
2374    # the C datatypes
2375    MPIR_CXX_BOOL=0x0c000000
2376    MPIR_CXX_COMPLEX=0x0c000000
2377    MPIR_CXX_DOUBLE_COMPLEX=0x0c000000
2378    MPIR_CXX_LONG_DOUBLE_COMPLEX=0x0c000000
2379    AC_SUBST(MPIR_CXX_BOOL)
2380    AC_SUBST(MPIR_CXX_COMPLEX)
2381    AC_SUBST(MPIR_CXX_DOUBLE_COMPLEX)
2382    AC_SUBST(MPIR_CXX_LONG_DOUBLE_COMPLEX)
2383
2384    # determine rpath and other shared library flags for CXX
2385    cxx_shlib_conf=src/env/cxx_shlib.conf
2386    PAC_COMPILER_SHLIB_FLAGS([CXX],[$cxx_shlib_conf])
2387    AC_SUBST_FILE([cxx_shlib_conf])
2388fi
2389
2390if test "$enable_cxx" = yes; then
2391    # Check if $MPI_DEFAULT_CXXOPTS is valid with $CXX
2392    if test "$enable_default_optimize" = "yes" \
2393         -a -n "$MPI_DEFAULT_CXXOPTS" ; then
2394        if test "$enable_check_compiler_flags" = "yes" ; then
2395            PAC_CXX_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_CXXOPTS], [
2396            CXXFLAGS="$CXXFLAGS $MPI_DEFAULT_CXXOPTS"
2397                                     ] )
2398        else
2399            CXXFLAGS="$CXXFLAGS $MPI_DEFAULT_CXXOPTS"
2400        fi
2401    fi
2402fi
2403
2404AC_SUBST(bindings)
2405# Bindings dirs is used for the installation target
2406AC_SUBST(bindings_dirs)
2407#
2408# ----------------------------------------------------------------------------
2409# End of the bindings support
2410# ----------------------------------------------------------------------------
2411
2412AC_LANG_C
2413#
2414# ----------------------------------------------------------------------------
2415# Done with the basic argument processing and decisions about which
2416# subsystems to build
2417# ----------------------------------------------------------------------------
2418
2419# Look for perl.  Perl is used *only* in the tests of the commands such as
2420# mpiexec, mpicc, etc, in test/commands, and in some of the utility
2421# programs for processing log files .  If perl is not found,
2422# MPICH2 may still be built and used.
2423# We need the full path to perl since we'll use it as the interpreter for
2424# a shell script.
2425AC_PATH_PROG(PERL,perl)
2426# Look for ar.  If we fail, abort
2427AC_CHECK_PROGS(AR,ar)
2428if test -z "$AR" ; then
2429    AC_MSG_ERROR([The program ar is required for building MPICH2.  Make sure that your path includes ar])
2430fi
2431
2432# FIXME: this is probably unnecessary now that we only do one "ar" at the end
2433# (via libtool).  If anything, it's likely to cause problems instead.
2434# AR_FLAGS provides a way to potentially improve build performance on Mac OSX
2435AR_FLAGS=cr
2436# this logic is lame, should really write a real test at some point
2437AS_CASE([$host],
2438    # Barry proposes AR_FLAGS="Scq" in trac#754, but that won't work correctly for re-builds
2439    [*-*-darwin*], [AR_FLAGS=Scr]
2440)
2441AC_ARG_VAR(AR_FLAGS,[AR command flags]) # causes AC_SUBST too
2442
2443# Note that we set RANLIB to true if we don't find it (some systems neither
2444# need it nor provide it)
2445AC_CHECK_PROGS(RANLIB,ranlib,true)
2446
2447# Check for the killall program; this can be used in some of the tests
2448# in test/commands
2449AC_CHECK_PROGS(KILLALL,killall,true)
2450
2451# Does xargs need the -r option to handle the case where the input
2452# is empty (gnu utils do, Mac OSX does not accept -r)
2453xargs_out=`echo "" | xargs ls | wc -l | sed -e 's/ //g'`
2454if test "$xargs_out" != "0" ; then
2455    XARGS_NODATA_OPT=-r
2456fi
2457AC_SUBST(XARGS_NODATA_OPT)
2458
2459AC_PROG_INSTALL
2460PAC_PROG_CHECK_INSTALL_WORKS
2461#
2462# On Mac OS/X, install breaks libraries unless used with the -p switch
2463dnl FIXME not necessary now that we are using libtool
2464dnl PAC_PROG_INSTALL_BREAKS_LIBS
2465# We also need mkdir -p.
2466PAC_PROG_MKDIR_P
2467PAC_PROG_MAKE
2468
2469#
2470# Check for bash to allow more robust shell scripts
2471AC_PATH_PROG(BASH_SHELL,bash)
2472#
2473# Confirm that bash has working arrays.  We can use this to
2474# build more robust versions of the scripts (particularly the
2475# compliation scripts) by taking advantage of the array features in
2476# bash.
2477bashWorks=no
2478if test -x "$BASH_SHELL" ; then
2479changequote(%%,::)dnl
2480    cat >>conftest <<EOF
2481#! $BASH_SHELL
2482A[0]="b"
2483A[1]="c"
2484rc=1
2485if test \${A[1]} != "c" ; then rc=2 ; else rc=0 ; fi
2486exit \$rc
2487EOF
2488changequote([,])dnl
2489    AC_MSG_CHECKING([whether $BASH_SHELL supports arrays])
2490    chmod +x conftest
2491    if ./conftest 2>&1 >/dev/null ; then
2492        bashWorks=yes
2493    else
2494        bashWorks=no
2495    fi
2496    rm -f conftest*
2497    AC_MSG_RESULT($bashWorks)
2498fi
2499dnl BUILD_BASH_SCRIPTS used to be an AC_SUBST
2500AM_CONDITIONAL([BUILD_BASH_SCRIPTS], [test "x$bashWorks" = xyes])
2501
2502# ----------------------------------------------------------------------------
2503# At this point, we've finally settled on the value of PMPILIBNAME.  We
2504# can now set NEEDSPLIB.
2505if test "$NEEDSPLIB" = yes -a "$PMPILIBNAME" = "$MPILIBNAME" ; then
2506    NEEDSPLIB=no
2507fi
2508# Set the defaults for the Fortran libraries to be the same as the C libraries
2509if test -z "$MPIFLIBNAME" ; then
2510    MPIFLIBNAME=$MPILIBNAME
2511fi
2512if test -z "$PMPIFLIBNAME" ; then
2513    PMPIFLIBNAME=$PMPILIBNAME
2514fi
2515
2516# ----------------------------------------------------------------------------
2517#
2518# Add the steps for debugger support
2519BUILD_TVDLL=no
2520if test "$enable_debuginfo" = "yes" ; then
2521   # We can build the Totalview interface DLL only if we know how to build
2522   # shared libraries.
2523
2524   # FIXME is this really the right test?
2525   # No.  Before MPICH2 1.5, there was the capability to build the debugger
2526   # libraries without forcing the build of shared libraries for everything.
2527   # There may be some way to restore this capability, but until then, we
2528   # at least cause the configure to cleanly fail with a clear error message
2529   if test "X$enable_shared" = "Xyes" ; then
2530       BUILD_TVDLL=yes
2531   else
2532       AC_MSG_ERROR([Building with --enable-debuginfo now requires building with shared library support.  Add --enable-shared and reconfigure])
2533   fi
2534
2535   # One more nasty problem.  Totalview relies on debugger symbols
2536   # being present in the executable.  Some experimental versions of
2537   # gcc (3.2 20020329 for ia64) do *not* include the object symbols
2538   # when debugging.  For HPUX, the necessary linking options are
2539   #    +noobjdebug
2540   # for C, Fortran, and C++.  We don't have a good test for this yet,
2541   # so we add a warning
2542   if test "$ac_cv_prog_gcc" = "yes" ; then
2543       AC_MSG_WARN([Some versions of gcc do not include debugging information
2544within the executable.  Totalview requires this information to detect
2545an MPICH code.  If you have trouble, try linking with the additional
2546option
2547    +noobjdebug
2548on all link lines (consider adding it to LDFLAGS)])
2549   fi
2550   AC_SUBST(BUILD_TVDLL)
2551
2552    # The debugger library name cannot be set until we know the extension
2553    # of shared libraries - the name is so on most Unix system, dylib on OS X.
2554    debugger_dir=debugger
2555    AC_DEFINE(HAVE_DEBUGGER_SUPPORT,1,[Define if debugger support is included])
2556    # The debugger support requires a shared library.  This is handled
2557    # below, after we check for compiler support for shared libraries
2558    # Note: if libdir contains exec_prefix, handle the fact that the
2559    # default exec_prefix is NONE, which (much later in configure)
2560    # gets turned into the value of prefix
2561    ##ENVVAR: MPICH_DEBUGLIBNAME - Set this environment variable to
2562    ## override the default name of the debugger support library.
2563    ## The default name is libtvmpich2.$SHLIB_EXT (e.g., libtvmpich2.so for
2564    ## most Unix versions, libtvmpich2.dylib for Mac OSX).
2565    ##ENVVAR END:
2566
2567    # We are cheating a bit here and reaching inside of the libtool macros to
2568    # extract the correct shared library extension.  It would be nice if this
2569    # were publicly available in at least the same way that $libext is.
2570    eval SHLIB_EXT='"'$shrext_cmds'"'
2571
2572    if test -z "$MPICH_DEBUGLIBNAME" ; then
2573        DEBUGLIBNAME=libtvmpich2.$SHLIB_EXT
2574    else
2575        # FIXME DJG I don't think this can be supported arbitrarily by the new
2576        # build system (I'm not sure it was supported correctly by the old
2577        # system either)
2578        AC_MSG_WARN([overriding MPICH_DEBUGLIBNAME is currently untested and probably does not work])
2579        DEBUGLIBNAME=$MPICH_DEBUGLIBNAME
2580    fi
2581    if test "x$exec_prefix" = xNONE ; then
2582        saveExecPrefix=$exec_prefix
2583	exec_prefix=$prefix
2584        eval dlldir=$libdir/$DEBUGLIBNAME
2585	exec_prefix=$saveExecPrefix
2586    else
2587        eval dlldir=$libdir/$DEBUGLIBNAME
2588    fi
2589    dlldir='"'$dlldir'"'
2590    AC_DEFINE_UNQUOTED(MPICH_INFODLL_LOC,$dlldir,[Define as the name of the debugger support library])
2591fi
2592AC_SUBST(debugger_dir)
2593
2594# used by automakefiles to conditionally build the DLL
2595AM_CONDITIONAL([BUILD_DEBUGGER_DLL], [test x$BUILD_TVDLL = xyes])
2596
2597# ----------------------------------------------------------------------------
2598
2599nameserv_name=""
2600AC_SUBST(nameserv_name)
2601#
2602# Get the default nameserver, if no nameserver was selected.  A process
2603# manager may advertise a nameserver name by setting the variable
2604# MPID_PM_NAMESERVER.
2605if test "$with_namepublisher" = "default" ; then
2606   if test -n "$MPID_PM_NAMESERVER" ; then
2607       with_namepublisher=$MPID_PM_NAMESERVER
2608   else
2609       # The default is to use a file to communicate published names
2610       with_namepublisher=file
2611   fi
2612fi
2613
2614if test "$with_namepublisher" != no -a "$with_namepublisher" != "none" ; then
2615    case "$with_namepublisher" in
2616    none|no) ;;
2617    # Removed ldap namepublisher hook - we no longer support or distribute
2618    # the ldap-based name server
2619    file*)
2620    # Note that we always build the Makefile for the file version because
2621    # this name publisher is really too simple to require a
2622    # separate configure, and we might as well include a basic
2623    # name publisher with any MPICH2 distribution
2624    # We DO need to extract the directory name that is used for writing
2625    # the files, with the User's home directory as the default
2626    nameserv_name="file"
2627    basedir=`echo $with_namepublisher | sed -e 's/file://'`
2628    if test "$basedir" = "$with_namepublisher" ; then
2629        # Reset since no directory was set.
2630	basedir='"."';
2631    fi
2632    AC_DEFINE_UNQUOTED(FILE_NAMEPUB_BASEDIR,$basedir,[Directory to use in namepub])
2633    AC_DEFINE(USE_FILE_FOR_NAMEPUB,1,[Define if file should be used for name publisher])
2634    ;;
2635
2636    mpd)
2637    nameserv_name="mpd"
2638    # The mpd nameserver is specific to the mpd process manager
2639    foundMPD=no
2640    for pm_name in $pm_names ; do
2641        if test "$pm_name" = "mpd" ; then
2642	    foundMPD=yes
2643	    break
2644	fi
2645    done
2646    if test "$foundMPD" = no ; then
2647        AC_MSG_ERROR([The mpd nameserver requires the mpd process manager])
2648    fi
2649    ;;
2650
2651    *)
2652    # Check for a new namepublisher
2653    dir=$with_namepublisher
2654    # If we later need args, here is where we can strip them off of the
2655    # with argument
2656    if test -d "$use_top_srcdir/src/nameserv/$dir" ; then
2657        if test -x "$use_top_srcdir/src/nameserv/$dir/configure" ; then
2658	    # Run the configure in this directory if necessary
2659            subsystems="$subsystems src/nameserv/$dir"
2660        fi
2661	nameserv_name=$dir
2662    else
2663        AC_MSG_WARN([Unknown name publisher $with_namepublisher])
2664    fi
2665    ;;
2666    esac
2667fi
2668if test -n "$nameserv_name" ; then
2669   AC_DEFINE(HAVE_NAMEPUB_SERVICE,1,[Define if a name publishing service is available])
2670fi
2671AM_CONDITIONAL([BUILD_NAMEPUB_FILE],[test "X$nameserv_name" = "Xfile"])
2672AM_CONDITIONAL([BUILD_NAMEPUB_MPD],[test "X$nameserv_name" = "Xmpd"])
2673AM_CONDITIONAL([BUILD_NAMEPUB_PMI],[test "X$nameserv_name" = "Xpmi"])
2674
2675# In case the documentation targets are used, find doctext and attempt to
2676# find the source for the doctext LaTeX style files.  Use "false" if
2677# doctext is not found
2678AC_PATH_PROG(DOCTEXT,doctext,false)
2679if test -n "$DOCTEXT" -a "$DOCTEXT" != "false" ; then
2680    if test -z "$DOCTEXTSYTLE" ; then
2681        AC_MSG_CHECKING([for location of doctext style files])
2682        dpath=`$DOCTEXT -debug_paths 2>&1 | grep 'default path' | \
2683	      sed -e 's%.*default path\(.*\),%\1:%g'`
2684        saveIFS="$IFS"
2685        IFS=": "
2686	for dir in $dpath ; do
2687	    if test -s $dir/refman.sty ; then
2688	       DOCTEXTSTYLE=$dir
2689	       break
2690	    fi
2691	done
2692        IFS="$saveIFS"
2693	if test -n "$DOCTEXTSTYLE" ; then
2694	    AC_MSG_RESULT($DOCTEXTSTYLE)
2695        else
2696	    AC_MSG_RESULT([unavailable])
2697        fi
2698    fi
2699fi
2700export DOCTEXT
2701export DOCTEXTSTYLE
2702AC_SUBST(DOCTEXT)
2703AC_SUBST(DOCTEXTSTYLE)
2704
2705# ----------------------------------------------------------------------------
2706# Check for C compiler characteristics
2707AC_C_CONST
2708AC_C_VOLATILE
2709AC_C_RESTRICT
2710AC_C_INLINE
2711
2712PAC_C_GNU_ATTRIBUTE
2713# We need to check for the endianess in order to implement the
2714# "external32" representations.  This defines "WORDS_BIGENDIAN when
2715# the system is bigendian.
2716# As of autoconf 2.62, this macro takes an additional argument for systems
2717# that can produce object files for either endianess.
2718# With the as-always-incompatible-with-every-version autoconf, the
2719# arguments for this macro *changed* in 2.62 to
2720# (if-bigendian,if-littleendian,unknown,universal)
2721# The fourth argument is new.
2722# Also note that the definition emitted by autoheader requires that gcc
2723# be used to compile the programs - other compilers may not define the
2724# non-standard __BIG_ENDIAN__ or __LITTLE_ENDIAN__ CPP names on which
2725# autoconf 2.62 now depends.
2726byteOrdering=unknown
2727AC_C_BIGENDIAN(byteOrdering=big,byteOrdering=little,,byteOrdering=universal)
2728case $byteOrdering in
2729    big)
2730    # Nothing to do - the c_bigendian macro takes care of it
2731    :
2732    ;;
2733    little)
2734    AC_DEFINE(WORDS_LITTLEENDIAN,1,[Define if words are little endian])
2735    ;;
2736    universal)
2737    AC_DEFINE(WORDS_UNIVERSAL_ENDIAN,1,[Define if configure will not tell us, for universal binaries])
2738    ;;
2739    unknown)
2740    AC_MSG_ERROR([Unable to determine endianess])
2741    ;;
2742esac
2743
2744# We only need this test if we are using Fortran
2745if test "$enable_f77" ; then
2746    PAC_PROG_C_UNALIGNED_DOUBLES(,
2747[AC_MSG_WARN(Your C compiler $CC does not support unaligned accesses
2748to doubles.  This is required for interoperation with
2749Fortran (the Fortran standard requires it).
2750You may need to specify an additional argument to your C compiler to
2751force it to allow unaligned accesses.)])
2752fi
2753# Check for __func__ (defined in C99) or __FUNCTION__ (defined in older GCC)
2754AC_CACHE_CHECK([whether $CC supports __func__],pac_cv_cc_has___func__,
2755[AC_TRY_COMPILE([],
2756 [const char *cp = __func__; ],pac_cv_cc_has___func__=yes,
2757pac_cv_cc_has___func__=no)])
2758if test "$pac_cv_cc_has___func__" != "yes" ; then
2759    AC_CACHE_CHECK([whether $CC supports __FUNCTION__],pac_cv_cc_has___FUNCTION__,
2760[AC_TRY_COMPILE([],
2761 [const char *cp = __FUNCTION__;],pac_cv_cc_has___FUNCTION__=yes,
2762pac_cv_cc_has___FUNCTION__=no)])
2763fi
2764
2765# ----------------------------------------------------------------------------
2766# Check on support for long double and long long types.  Do this before the
2767# structure alignment test because it will test for including those
2768# types as well.  In addition, allow the device to suppress support for these
2769# optional C types by setting MPID_NO_LONG_DOUBLE and/or MPID_NO_LONG_LONG
2770# to yes.
2771if test "$MPID_NO_LONG_DOUBLE" != "yes" ; then
2772    AC_CACHE_CHECK([whether long double is supported],
2773    pac_cv_have_long_double,[
2774    AC_TRY_COMPILE(,[long double a;],
2775    pac_cv_have_long_double=yes,pac_cv_have_long_double=no)])
2776    if test "$pac_cv_have_long_double" = "yes" ; then
2777        AC_DEFINE(HAVE_LONG_DOUBLE,1,[Define if long double is supported])
2778    fi
2779fi
2780if test "$MPID_NO_LONG_LONG" != "yes" ; then
2781    AC_CACHE_CHECK([whether long long is supported],
2782    pac_cv_have_long_long,[
2783    AC_TRY_COMPILE(,[long long a;],
2784    pac_cv_have_long_long=yes,pac_cv_have_long_long=no)])
2785    if test "$pac_cv_have_long_long" = "yes" ; then
2786        AC_DEFINE(HAVE_LONG_LONG_INT,1,[Define if long long is supported])
2787    fi
2788fi
2789# ----------------------------------------------------------------------------
2790# Get default structure alignment for integers
2791dnl PAC_C_MAX_INTEGER_ALIGN places the default alignment into
2792dnl pac_cv_c_max_integer_align, with possible values including
2793dnl packed (byte), largest, two, four, eight (or other failure message).
2794PAC_C_MAX_INTEGER_ALIGN
2795
2796if test "$pac_cv_c_max_integer_align" = "packed" ; then
2797    pac_cv_c_struct_align_nr=1
2798elif test "$pac_cv_c_max_integer_align" = "two" ; then
2799    pac_cv_c_struct_align_nr=2
2800elif test "$pac_cv_c_max_integer_align" = "four" ; then
2801    pac_cv_c_struct_align_nr=4
2802elif test "$pac_cv_c_max_integer_align" = "eight" ; then
2803    pac_cv_c_struct_align_nr=8
2804fi
2805
2806if test -n "$pac_cv_c_struct_align_nr" ; then
2807    AC_DEFINE_UNQUOTED(HAVE_MAX_INTEGER_ALIGNMENT,$pac_cv_c_struct_align_nr,[Controls byte alignment of integer structures (for MPI structs)])
2808    AC_DEFINE_UNQUOTED(HAVE_MAX_STRUCT_ALIGNMENT,$pac_cv_c_struct_align_nr,[Controls byte alignment of structures (for aligning allocated structures)])
2809fi
2810# Get default structure alignment for floating point types
2811dnl PAC_C_MAX_FP_ALIGN places the default alignment into
2812dnl pac_cv_c_max_fp_align, with possible values including
2813dnl packed (byte), largest, two, four, eight (or other failure message).
2814PAC_C_MAX_FP_ALIGN
2815
2816if test "$pac_cv_c_max_fp_align" = "packed" ; then
2817    pac_cv_c_fp_align_nr=1
2818elif test "$pac_cv_c_max_fp_align" = "two" ; then
2819    pac_cv_c_fp_align_nr=2
2820elif test "$pac_cv_c_max_fp_align" = "four" ; then
2821    pac_cv_c_fp_align_nr=4
2822elif test "$pac_cv_c_max_fp_align" = "eight" ; then
2823    pac_cv_c_fp_align_nr=8
2824elif test "$pac_cv_c_max_fp_align" = "sixteen" ; then
2825    pac_cv_c_fp_align_nr=16
2826elif test "$pac_cv_c_max_fp_align" = "largest" ; then
2827    AC_MSG_ERROR([Configure detected unsupported structure alignment rules.])
2828fi
2829
2830if test -n "$pac_cv_c_fp_align_nr" ; then
2831    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)])
2832fi
2833
2834# Test for the alignment of structs containing only long doubles.
2835if test "$pac_cv_have_long_double" = yes ; then
2836    # Check for alignment of just float and double (no long doubles)
2837    PAC_C_MAX_DOUBLE_FP_ALIGN
2838    PAC_C_MAX_LONGDOUBLE_FP_ALIGN
2839    # FIXME: If this alignment is not the same as that for all float types,
2840    # we need to do something else in the alignment rule code.
2841    if test "$pac_cv_c_max_fp_align" != "$pac_cv_c_max_longdouble_fp_align" -o \
2842            "$pac_cv_c_max_fp_align" != "$pac_cv_c_max_double_fp_align" ; then
2843        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.])
2844
2845	double_align=-1
2846	case $pac_cv_c_max_double_fp_align in
2847	packed) double_align=1 ;;
2848	two)    double_align=2 ;;
2849	four)   double_align=4 ;;
2850	eight)  double_align=8 ;;
2851	esac
2852	longdouble_align=-1
2853	case $pac_cv_c_max_longdouble_fp_align in
2854	packed) longdouble_align=1 ;;
2855	two)    longdouble_align=2 ;;
2856	four)   longdouble_align=4 ;;
2857	eight)  longdouble_align=8 ;;
2858	sixteen)longdouble_align=16 ;;
2859	esac
2860
2861	AC_DEFINE_UNQUOTED(HAVE_MAX_DOUBLE_FP_ALIGNMENT,$double_align,[Controls byte alignment of structs with doubles])
2862	AC_DEFINE_UNQUOTED(HAVE_MAX_LONG_DOUBLE_FP_ALIGNMENT,$longdouble_align,[Controls byte alignment of structs with long doubles])
2863    fi
2864fi
2865
2866# Test for weird struct alignment rules that vary padding based on
2867# size of leading type only.
2868PAC_C_DOUBLE_POS_ALIGN
2869if test "$pac_cv_c_double_pos_align" = "yes" ; then
2870    AC_DEFINE_UNQUOTED(HAVE_DOUBLE_POS_ALIGNMENT,1,[Controls how alignment is applied based on position of doubles in the structure])
2871fi
2872
2873# Test for same weird issues with long long int.
2874PAC_C_LLINT_POS_ALIGN
2875if test "$pac_cv_c_llint_pos_align" = "yes" ; then
2876   AC_DEFINE_UNQUOTED(HAVE_LLINT_POS_ALIGNMENT,1,[Controls how alignment is applied based on position of long long ints in the structure])
2877fi
2878
2879# Test for double alignment not following all our other carefully constructed rules
2880PAC_C_DOUBLE_ALIGNMENT_EXCEPTION
2881if test "$pac_cv_c_double_alignment_exception" = "four" ; then
2882   AC_DEFINE_UNQUOTED(HAVE_DOUBLE_ALIGNMENT_EXCEPTION,4,[Controls how alignment of doubles is performed, separate from other FP values])
2883fi
2884
2885# Test whether pointers can be aligned on a int boundary or require
2886# a pointer boundary.
2887AC_MSG_CHECKING([for alignment restrictions on pointers])
2888AC_TRY_RUN(
2889changequote(<<,>>)
2890struct foo { int a; void *b; };
2891int main() {
2892    int buf[10];
2893    struct foo *p1;
2894    p1=(struct foo*)&buf[0];
2895    p1->b = (void *)0;
2896    p1=(struct foo*)&buf[1];
2897    p1->b = (void *)0;
2898    return 0;
2899changequote([,])
2900},pac_cv_pointers_have_int_alignment=yes,pac_cv_pointers_have_int_alignment=no,pac_cv_pointers_have_int_alignment=unknown)
2901
2902if test "$pac_cv_pointers_have_int_alignment" != "yes" ; then
2903   AC_DEFINE(NEEDS_POINTER_ALIGNMENT_ADJUST,1,[define if pointers must be aligned on pointer boundaries])
2904   AC_MSG_RESULT([pointer])
2905else
2906   AC_MSG_RESULT([int or better])
2907fi
2908
2909# There are further alignment checks after we test for int64_t etc. below.
2910
2911# Get the size of the C types for encoding in the basic datatypes and for
2912# the specific-sized integers
2913AC_CHECK_SIZEOF(char)
2914AC_CHECK_SIZEOF(unsigned char)
2915AC_CHECK_SIZEOF(short)
2916AC_CHECK_SIZEOF(unsigned short)
2917AC_CHECK_SIZEOF(int)
2918AC_CHECK_SIZEOF(unsigned int)
2919AC_CHECK_SIZEOF(long)
2920AC_CHECK_SIZEOF(unsigned long)
2921AC_CHECK_SIZEOF(long long)
2922AC_CHECK_SIZEOF(unsigned long long)
2923AC_CHECK_SIZEOF(float)
2924AC_CHECK_SIZEOF(double)
2925AC_CHECK_SIZEOF(long double)
2926AC_CHECK_SIZEOF(void *)
2927
2928AC_HEADER_STDC
2929AC_CHECK_HEADERS([stddef.h])
2930AC_CHECK_SIZEOF(wchar_t, 0, [
2931#ifdef HAVE_STDDEF_H
2932#include <stddef.h>
2933#endif
2934])
2935
2936AC_CHECK_SIZEOF(float_int, 0, [typedef struct { float a; int b; } float_int; ])
2937AC_CHECK_SIZEOF(double_int, 0, [typedef struct { double a; int b; } double_int; ])
2938AC_CHECK_SIZEOF(long_int, 0, [typedef struct { long a; int b; } long_int; ])
2939AC_CHECK_SIZEOF(short_int, 0, [typedef struct { short a; int b; } short_int; ])
2940AC_CHECK_SIZEOF(two_int, 0, [typedef struct { int a; int b; } two_int; ])
2941AC_CHECK_SIZEOF(long_double_int, 0, [typedef struct { long double a; int b;} long_double_int; ])
2942
2943# sys/bitypes.h defines the int16_t etc. on some systems (e.g., OSF1).
2944# Include it when testing for these types
2945AC_CHECK_HEADER(sys/bitypes.h,[use_bitypes="#include <sys/bitypes.h>"
2946AC_DEFINE(HAVE_SYS_BITYPES_H,1,[Define if sys/bitypes.h exists])])
2947# A C99 compliant compiler should have inttypes.h for fixed-size int types
2948AC_CHECK_HEADERS(inttypes.h stdint.h)
2949
2950# Check for types
2951AC_TYPE_INT8_T
2952AC_TYPE_INT16_T
2953AC_TYPE_INT32_T
2954AC_TYPE_INT64_T
2955
2956# Temporary issue in autoconf integer type checking (remove when
2957# autoconf fixes this or provides a workaround for it)
2958if test "$ac_cv_c_int8_t" != no ; then
2959    AC_DEFINE(HAVE_INT8_T,1,[Define if int8_t is supported by the C compiler])
2960fi
2961if test "$ac_cv_c_int16_t" != no ; then
2962    AC_DEFINE(HAVE_INT16_T,1,[Define if int16_t is supported by the C compiler])
2963fi
2964if test "$ac_cv_c_int32_t" != no ; then
2965    AC_DEFINE(HAVE_INT32_T,1,[Define if int32_t is supported by the C compiler])
2966fi
2967if test "$ac_cv_c_int64_t" != no ; then
2968    AC_DEFINE(HAVE_INT64_T,1,[Define if int64_t is supported by the C compiler])
2969fi
2970
2971# The following make these definitions:
2972#   define _UINT<n>_T 1
2973# if uint<n>_t is available.  E.g., define _UINT8_T as 1 if uint8_t is available
2974# if not available, define uint<n>_t as the related C type, e.g.,
2975#   define uint8_t unsigned char
2976#
2977AC_TYPE_UINT8_T
2978AC_TYPE_UINT16_T
2979AC_TYPE_UINT32_T
2980AC_TYPE_UINT64_T
2981
2982# Temporary issue in autoconf integer type checking (remove when
2983# autoconf fixes this or provides a workaround for it)
2984if test "$ac_cv_c_uint8_t" != no ; then
2985    AC_DEFINE(HAVE_UINT8_T,1,[Define if uint8_t is supported by the C compiler])
2986fi
2987if test "$ac_cv_c_uint16_t" != no ; then
2988    AC_DEFINE(HAVE_UINT16_T,1,[Define if uint16_t is supported by the C compiler])
2989fi
2990if test "$ac_cv_c_uint32_t" != no ; then
2991    AC_DEFINE(HAVE_UINT32_T,1,[Define if uint32_t is supported by the C compiler])
2992fi
2993if test "$ac_cv_c_uint64_t" != no ; then
2994    AC_DEFINE(HAVE_UINT64_T,1,[Define if uint64_t is supported by the C compiler])
2995fi
2996
2997# Other C99 types.
2998AC_CHECK_HEADERS([stdbool.h complex.h])
2999AC_CHECK_SIZEOF([_Bool],0,[
3000#ifdef HAVE_STDBOOL_H
3001#include <stdbool.h>
3002#endif
3003])
3004AC_CHECK_SIZEOF([float _Complex],0,[
3005#ifdef HAVE_COMPLEX_H
3006#include <complex.h>
3007#endif
3008])
3009AC_CHECK_SIZEOF([double _Complex],0,[
3010#ifdef HAVE_COMPLEX_H
3011#include <complex.h>
3012#endif
3013])
3014AC_CHECK_SIZEOF([long double _Complex],0,[
3015#ifdef HAVE_COMPLEX_H
3016#include <complex.h>
3017#endif
3018])
3019# we need really could just use the result of AC_CHECK_SIZEOF, but having a
3020# HAVE_typename macro is useful for consistency
3021AC_CHECK_TYPES([_Bool, float _Complex, double _Complex, long double _Complex])
3022
3023# Generate a hex version of the size of each type
3024for type in short int long long_long float double long_double wchar_t \
3025    float_int double_int long_int short_int two_int long_double_int     \
3026    _Bool float__Complex double__Complex long_double__Complex ; do
3027    eval len=\$ac_cv_sizeof_$type
3028    if test -z "$len" ; then
3029       len=0
3030       # Check for sizes from the CHECK_SIZEOF_DERIVED macro
3031       eval pclen=\$ac_cv_sizeof_$type
3032       if test -n "$pclen" ; then
3033           len=$pclen
3034       else
3035           # check for a non-optional type
3036           if test $type != long_long -a \
3037                   $type != long_double -a \
3038                   $type != long_double_int -a \
3039                   $type != _Bool -a \
3040                   $type != float__Complex -a \
3041                   $type != double__Complex -a \
3042                   $type != long_double__Complex ; then
3043               AC_MSG_ERROR([Configure was unable to determine the size of $type ; if cross compiling,
3044use the environment variables CROSS_SIZEOF_typename, e.g., CROSS_SIZEOF_SHORT,
3045or use the --with-cross=file configure option to specify a file containing
3046Bourne (sh) shell assignments to CROSS_SIZEOF_typename for all datatype
3047types.  The program maint/getcross.c can be compiled and run on the target
3048system; this program outputs an appropriate file for the --with-cross option])
3049	   fi
3050       fi
3051    fi
3052    #
3053    # Take len and turn it into two hex digits (there are 8 bits available
3054    # in the built-in datatype handle for the length; see
3055    # src/mpid/common/datatype/mpid_datatype.h)
3056    if test "$len" -gt 255 ; then
3057         AC_MSG_ERROR([Type sizes greater than 255 bytes are not supported (type $type is $len bytes)])
3058    fi
3059    tmplen=$len
3060    hexlen=""
3061    while test $tmplen -gt 0 ; do
3062        lowdigit=`expr $tmplen - 16 \* \( $tmplen / 16 \)`
3063	case $lowdigit in
3064         10) char=a ;;
3065	 11) char=b ;;
3066	 12) char=c ;;
3067	 13) char=d ;;
3068	 14) char=e ;;
3069	 15) char=f ;;
3070	  *) char=$lowdigit ;;
3071	esac
3072	hexlen="$char$hexlen"
3073	tmplen=`expr $tmplen / 16`
3074    done
3075    if test $len -lt 16 ; then
3076        hexlen="0$hexlen"
3077    fi
3078    if test $len = 0 ; then
3079        # This sometimes happens for wchar_t
3080        hexlen="00";
3081    fi
3082    eval len_$type=$hexlen
3083done
3084# By definition, sizeof char is 1
3085MPI_CHAR="0x4c000101"
3086MPI_UNSIGNED_CHAR="0x4c000102"
3087MPI_SHORT="0x4c00${len_short}03"
3088MPI_UNSIGNED_SHORT="0x4c00${len_short}04"
3089MPI_INT="0x4c00${len_int}05"
3090MPI_UNSIGNED_INT="0x4c00${len_int}06"
3091MPI_LONG="0x4c00${len_long}07"
3092MPI_UNSIGNED_LONG="0x4c00${len_long}08"
3093if test "$len_long_long" != 0 -a "$MPID_NO_LONG_LONG" != yes ; then
3094    MPI_LONG_LONG="0x4c00${len_long_long}09"
3095else
3096    MPI_LONG_LONG=MPI_DATATYPE_NULL;
3097fi
3098MPI_FLOAT="0x4c00${len_float}0a"
3099MPI_DOUBLE="0x4c00${len_double}0b"
3100if test "$len_long_double" != 0 -a "$MPID_NO_LONG_DOUBLE" != yes ; then
3101    MPI_LONG_DOUBLE="0x4c00${len_long_double}0c"
3102else
3103    MPI_LONG_DOUBLE=MPI_DATATYPE_NULL
3104fi
3105# If you change MPI_BYTE, you must change it in src/binding/f77/buildiface
3106MPI_BYTE="0x4c00010d"
3107MPI_WCHAR="0x4c00${len_wchar_t}0e"
3108MPI_PACKED="0x4c00010f"
3109MPI_LB="0x4c000010"
3110MPI_UB="0x4c000011"
3111#
3112# These should define the mixed types *only* for contiguous data.
3113# For example, MPI_SHORT_INT may have a gap; it will need to be defined
3114# as a derived type instead.  For IA32, this only affects short_int.
3115MPI_2INT="0x4c00${len_two_int}16"
3116#
3117# For now we aren't being too clever about figuring out which of these
3118# are in fact contiguous, so these are all allocated as "real" types.
3119#
3120# These values correspond to direct types 0..5.
3121#
3122dnl MPI_FLOAT_INT="0x4c00${len_float_int}12"
3123dnl MPI_DOUBLE_INT="0x4c00${len_double_int}13"
3124dnl MPI_LONG_INT="0x4c00${len_long_int}14"
3125dnl MPI_SHORT_INT="0x4c00${len_short_int}15"
3126dnl MPI_LONG_DOUBLE_INT="0x4c00${len_long_double_int}17"
3127MPI_FLOAT_INT="0x8c000000"
3128MPI_DOUBLE_INT="0x8c000001"
3129MPI_LONG_INT="0x8c000002"
3130MPI_SHORT_INT="0x8c000003"
3131if test "$MPID_NO_LONG_DOUBLE" != yes ; then
3132    MPI_LONG_DOUBLE_INT="0x8c000004"
3133else
3134    MPI_LONG_DOUBLE_INT=MPI_DATATYPE_NULL
3135fi
3136
3137# 2 additional predefined types named in MPI-2
3138MPI_SIGNED_CHAR="0x4c000118"
3139if test "$len_long_long" != 0 -a "$MPID_NO_LONG_LONG" != yes ; then
3140    MPI_UNSIGNED_LONG_LONG="0x4c00${len_long_long}19"
3141else
3142    MPI_UNSIGNED_LONG_LONG=MPI_DATATYPE_NULL
3143fi
3144
3145AC_SUBST(MPI_CHAR)
3146AC_SUBST(MPI_UNSIGNED_CHAR)
3147AC_SUBST(MPI_SHORT)
3148AC_SUBST(MPI_UNSIGNED_SHORT)
3149AC_SUBST(MPI_INT)
3150AC_SUBST(MPI_UNSIGNED_INT)
3151AC_SUBST(MPI_LONG)
3152AC_SUBST(MPI_UNSIGNED_LONG)
3153AC_SUBST(MPI_LONG_LONG)
3154AC_SUBST(MPI_FLOAT)
3155AC_SUBST(MPI_DOUBLE)
3156AC_SUBST(MPI_LONG_DOUBLE)
3157AC_SUBST(MPI_BYTE)
3158AC_SUBST(MPI_WCHAR)
3159AC_SUBST(MPI_PACKED)
3160AC_SUBST(MPI_LB)
3161AC_SUBST(MPI_UB)
3162AC_SUBST(MPI_FLOAT_INT)
3163AC_SUBST(MPI_DOUBLE_INT)
3164AC_SUBST(MPI_LONG_INT)
3165AC_SUBST(MPI_SHORT_INT)
3166AC_SUBST(MPI_2INT)
3167AC_SUBST(MPI_LONG_DOUBLE_INT)
3168AC_SUBST(MPI_SIGNED_CHAR)
3169AC_SUBST(MPI_UNSIGNED_LONG_LONG)
3170#
3171# FIXME: Leftover from separate fortran system
3172## Export the basic C types so that the Fortran system can use them
3173#export MPI_CHAR
3174#export MPI_SHORT
3175#export MPI_INT
3176#export MPI_LONG
3177#export MPI_LONG_LONG
3178#export MPI_FLOAT
3179#export MPI_DOUBLE
3180#export MPI_LONG_DOUBLE
3181#
3182# Size-specific types.  Initialize as NULL
3183MPI_REAL4=MPI_DATATYPE_NULL
3184MPI_REAL8=MPI_DATATYPE_NULL
3185MPI_REAL16=MPI_DATATYPE_NULL
3186MPI_COMPLEX8=MPI_DATATYPE_NULL
3187MPI_COMPLEX16=MPI_DATATYPE_NULL
3188MPI_COMPLEX32=MPI_DATATYPE_NULL
3189MPI_INTEGER1=MPI_DATATYPE_NULL
3190MPI_INTEGER2=MPI_DATATYPE_NULL
3191MPI_INTEGER4=MPI_DATATYPE_NULL
3192MPI_INTEGER8=MPI_DATATYPE_NULL
3193MPI_INTEGER16=MPI_DATATYPE_NULL
3194AC_SUBST(MPI_REAL4)
3195AC_SUBST(MPI_REAL8)
3196AC_SUBST(MPI_REAL16)
3197AC_SUBST(MPI_COMPLEX8)
3198AC_SUBST(MPI_COMPLEX16)
3199AC_SUBST(MPI_COMPLEX32)
3200AC_SUBST(MPI_INTEGER1)
3201AC_SUBST(MPI_INTEGER2)
3202AC_SUBST(MPI_INTEGER4)
3203AC_SUBST(MPI_INTEGER8)
3204AC_SUBST(MPI_INTEGER16)
3205export MPI_REAL4
3206export MPI_REAL8
3207export MPI_REAL16
3208export MPI_COMPLEX8
3209export MPI_COMPLEX16
3210export MPI_COMPLEX32
3211export MPI_INTEGER1
3212export MPI_INTEGER2
3213export MPI_INTEGER4
3214export MPI_INTEGER8
3215export MPI_INTEGER16
3216#
3217# Try to find corresponding types for the size-specific types.
3218#
3219# Assume that the float/double/long double are simply spaced
3220# Datatypes used up through 26 in Fortran
3221# 27,28,29,2a,2b,2c
3222if test "$ac_cv_sizeof_float" = "4" ; then
3223    MPI_REAL4="0x4c000427"
3224    MPI_COMPLEX8="0x4c000828"
3225    MPIR_REAL4_CTYPE=float
3226fi
3227if test "$ac_cv_sizeof_double" = "8" ; then
3228    MPI_REAL8="0x4c000829"
3229    MPI_COMPLEX16="0x4c00102a"
3230    MPIR_REAL8_CTYPE=double
3231fi
3232if test "$ac_cv_sizeof_long_double" = "16" -a "$MPID_NO_LONG_DOUBLE" != yes ; then
3233    MPI_REAL16="0x4c00102b"
3234    MPI_COMPLEX32="0x4c00202c"
3235    MPIR_REAL16_CTYPE="long double"
3236fi
3237if test -n "$MPIR_REAL4_CTYPE" ; then
3238    AC_DEFINE_UNQUOTED(MPIR_REAL4_CTYPE,$MPIR_REAL4_CTYPE,[C type to use for MPI_REAL4])
3239fi
3240if test -n "$MPIR_REAL8_CTYPE" ; then
3241    AC_DEFINE_UNQUOTED(MPIR_REAL8_CTYPE,$MPIR_REAL8_CTYPE,[C type to use for MPI_REAL8])
3242fi
3243if test -n "$MPIR_REAL16_CTYPE" ; then
3244    AC_DEFINE_UNQUOTED(MPIR_REAL16_CTYPE,$MPIR_REAL16_CTYPE,[C type to use for MPI_REAL16])
3245fi
3246# For complex 8/16/32, we assume that these are 2 consequetive real4/8/16
3247#
3248# Search for the integer types
3249for type in char short int long long_long ; do
3250    # ctype is a valid C type which we can use to declare a C version of
3251    # this item
3252    ctype=`echo $type | sed 's/_/ /'`
3253    eval len=\$ac_cv_sizeof_$type
3254    if test -n "$len" ; then
3255    case $len in
3256    1) if test "$MPI_INTEGER1" = "MPI_DATATYPE_NULL" ; then
3257           MPI_INTEGER1="0x4c00012d"
3258	   MPIR_INTEGER1_CTYPE="$ctype"
3259       fi
3260       ;;
3261    2) if test "$MPI_INTEGER2" = "MPI_DATATYPE_NULL" ; then
3262           MPI_INTEGER2="0x4c00022f"
3263	   MPIR_INTEGER2_CTYPE="$ctype"
3264       fi
3265       ;;
3266    4) if test "$MPI_INTEGER4" = "MPI_DATATYPE_NULL" ; then
3267           MPI_INTEGER4="0x4c000430"
3268	   MPIR_INTEGER4_CTYPE="$ctype"
3269       fi
3270       ;;
3271    8) if test "$MPI_INTEGER8" = "MPI_DATATYPE_NULL" ; then
3272           MPI_INTEGER8="0x4c000831"
3273	   MPIR_INTEGER8_CTYPE="$ctype"
3274       fi
3275       ;;
3276    16) if test "$MPI_INTEGER16" = "MPI_DATATYPE_NULL" ; then
3277           MPI_INTEGER16="0x4c001032"
3278	   MPIR_INTEGER16_CTYPE="$ctype"
3279       fi
3280       ;;
3281    *)
3282    ;;
3283    esac
3284    fi
3285done
3286#
3287# Add the definitions of these types
3288if test -n "$MPIR_INTEGER1_CTYPE" ; then
3289    AC_DEFINE_UNQUOTED(MPIR_INTEGER1_CTYPE,$MPIR_INTEGER1_CTYPE,[C type to use for MPI_INTEGER1])
3290fi
3291if test -n "$MPIR_INTEGER2_CTYPE" ; then
3292   AC_DEFINE_UNQUOTED(MPIR_INTEGER2_CTYPE,$MPIR_INTEGER2_CTYPE,[C type to use for MPI_INTEGER2])
3293fi
3294if test -n "$MPIR_INTEGER4_CTYPE" ; then
3295   AC_DEFINE_UNQUOTED(MPIR_INTEGER4_CTYPE,$MPIR_INTEGER4_CTYPE,[C type to use for MPI_INTEGER4])
3296fi
3297if test -n "$MPIR_INTEGER8_CTYPE" ; then
3298   AC_DEFINE_UNQUOTED(MPIR_INTEGER8_CTYPE,$MPIR_INTEGER8_CTYPE,[C type to use for MPI_INTEGER8])
3299fi
3300if test -n "$MPIR_INTEGER16_CTYPE" ; then
3301   AC_DEFINE_UNQUOTED(MPIR_INTEGER16_CTYPE,$MPIR_INTEGER16_CTYPE,[C type to use for MPI_INTEGER16])
3302fi
3303
3304# ----------------------------------------------------------------------------
3305
3306# C99 types
3307# The predefined types must be distinct types (as opposed to aliases to MPI_INT
3308# or MPI_WHATEVER) in order to correctly support MPI_Type_{get,set}_name.
3309#
3310# FIXME the "basic id" portion should be automatically assigned.  It's too easy
3311# to have a conflict when this is done by hand.
3312#
3313# Because we make up a matching type for the fixed-width types if one doesn't
3314# exist, we don't ever set these to MPI_DATATYPE_NULL.  If we come across a
3315# platform where 64-bit sizes aren't supported just add a test like the other
3316# types.
3317MPI_INT8_T=0x4c000137
3318MPI_INT16_T=0x4c000238
3319MPI_INT32_T=0x4c000439
3320MPI_INT64_T=0x4c00083a
3321MPI_UINT8_T=0x4c00013b
3322MPI_UINT16_T=0x4c00023c
3323MPI_UINT32_T=0x4c00043d
3324MPI_UINT64_T=0x4c00083e
3325
3326# The compiler may or may not support these types, depending on its level of C99
3327# compliance.  We check for each one individually before assigning a handle
3328# number.
3329MPI_C_BOOL=MPI_DATATYPE_NULL
3330MPI_C_FLOAT_COMPLEX=MPI_DATATYPE_NULL
3331MPI_C_DOUBLE_COMPLEX=MPI_DATATYPE_NULL
3332MPI_C_LONG_DOUBLE_COMPLEX=MPI_DATATYPE_NULL
3333if test ${len__Bool} != 0 ; then
3334    MPI_C_BOOL=0x4c00${len__Bool}3f
3335fi
3336if test ${len_float__Complex} != 0 ; then
3337    MPI_C_FLOAT_COMPLEX=0x4c00${len_float__Complex}40
3338fi
3339if test ${len_double__Complex} != 0 ; then
3340    MPI_C_DOUBLE_COMPLEX=0x4c00${len_double__Complex}41
3341fi
3342if test ${len_long_double__Complex} != 0 ; then
3343    MPI_C_LONG_DOUBLE_COMPLEX=0x4c00${len_long_double__Complex}42
3344fi
3345
3346AC_SUBST(MPI_INT8_T)
3347AC_SUBST(MPI_INT16_T)
3348AC_SUBST(MPI_INT32_T)
3349AC_SUBST(MPI_INT64_T)
3350AC_SUBST(MPI_UINT8_T)
3351AC_SUBST(MPI_UINT16_T)
3352AC_SUBST(MPI_UINT32_T)
3353AC_SUBST(MPI_UINT64_T)
3354AC_SUBST(MPI_C_BOOL)
3355AC_SUBST(MPI_C_FLOAT_COMPLEX)
3356AC_SUBST(MPI_C_DOUBLE_COMPLEX)
3357AC_SUBST(MPI_C_LONG_DOUBLE_COMPLEX)
3358export MPI_INT8_T
3359export MPI_INT16_T
3360export MPI_INT32_T
3361export MPI_INT64_T
3362export MPI_UINT8_T
3363export MPI_UINT16_T
3364export MPI_UINT32_T
3365export MPI_UINT64_T
3366export MPI_C_BOOL
3367export MPI_C_FLOAT_COMPLEX
3368export MPI_C_DOUBLE_COMPLEX
3369export MPI_C_LONG_DOUBLE_COMPLEX
3370
3371
3372# ----------------------------------------------------------------------------
3373# We can now create the Fortran versions of the datatype values, along with
3374# some of the other datatype-dependent sizes
3375
3376# There are two parts to handling the datatypes:
3377#    Convert the C datatype values to their Fortran equivalent.  This
3378#    involves converting the hex values for the C version into decimal
3379#    since standard Fortran does not have hex constants
3380#
3381#    Determine the existence of the Fortran 'sized' types and set those
3382#    values.
3383#
3384# In addition, we need to look at a few additional constants that depend
3385# on how the compiler sizes some datatypes.  These are:
3386#    STATUS_SIZE, INTEGER_KIND, ADDRESS_KIND, and OFFSET_KIND
3387#
3388# ----------------------------------------------------------------------------
3389if test "$enable_f77" = yes ; then
3390    # Up to size checking code in master configure.ac (where it tries to
3391    # find the matching C sizes) as part of defining mpi_integer8 etc.
3392    # The results are available in pac_cv_sizeof_f77_<type>
3393    # Size is 0 if unknown or unavailable (or cross-compiling)
3394    # Due to limitations in autoconf, we cannot put these into a loop.
3395    # We also check integer to find the type of MPI_Fint
3396    #
3397    # Cross-compilation results can be included with the --with-cross=file
3398    # option.
3399    CROSS_F77_SIZEOF_INTEGER=${CROSS_F77_SIZEOF_INTEGER:-0}
3400    CROSS_F77_SIZEOF_REAL=${CROSS_F77_SIZEOF_REAL:-0}
3401    CROSS_F77_SIZEOF_DOUBLE_PRECISION=${CROSS_F77_SIZEOF_DOUBLE_PRECISION:-0}
3402    PAC_PROG_F77_CHECK_SIZEOF_EXT(integer,$CROSS_F77_SIZEOF_INTEGER)
3403    PAC_PROG_F77_CHECK_SIZEOF_EXT(real,$CROSS_F77_SIZEOF_REAL)
3404    PAC_PROG_F77_CHECK_SIZEOF_EXT(double precision,$CROSS_F77_SIZEOF_DOUBLE_PRECISION)
3405    AC_LANG_FORTRAN77
3406    # If we have sizes for real and double, we do not need to call
3407    # mpir_get_fsize at run time.
3408    # For the size-defined types (e.g., integer*2), we assume that if the
3409    # compiler allows it, it has the stated size.
3410    AC_CACHE_CHECK([whether integer*1 is supported],pac_cv_fort_integer1,[
3411    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*1 i])],
3412         pac_cv_fort_integer1=yes,
3413         pac_cv_fort_integer1=no)])
3414    AC_CACHE_CHECK([whether integer*2 is supported],pac_cv_fort_integer2,[
3415    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*2 i])],
3416        pac_cv_fort_integer2=yes,
3417        pac_cv_fort_integer2=no)])
3418    AC_CACHE_CHECK([whether integer*4 is supported],pac_cv_fort_integer4,[
3419    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*4 i])],
3420        pac_cv_fort_integer4=yes,
3421        pac_cv_fort_integer4=no)])
3422    AC_CACHE_CHECK([whether integer*8 is supported],pac_cv_fort_integer8,[
3423    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*8 i])],
3424        pac_cv_fort_integer8=yes,
3425        pac_cv_fort_integer8=no)])
3426    AC_CACHE_CHECK([whether integer*16 is supported],pac_cv_fort_integer16,[
3427    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*16 i])],
3428        pac_cv_fort_integer16=yes,
3429        pac_cv_fort_integer16=no)])
3430    AC_CACHE_CHECK([whether real*4 is supported],pac_cv_fort_real4,[
3431    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      real*4 a])],
3432        pac_cv_fort_real4=yes,
3433        pac_cv_fort_real4=no)])
3434    AC_CACHE_CHECK([whether real*8 is supported],pac_cv_fort_real8,[
3435    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      real*8 a])],
3436        pac_cv_fort_real8=yes,
3437        pac_cv_fort_real8=no)])
3438    AC_CACHE_CHECK([whether real*16 is supported],pac_cv_fort_real16,[
3439    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      real*16 a])],
3440        pac_cv_fort_real16=yes,
3441        pac_cv_fort_real16=no)])
3442
3443    # Create the default datatype names for the standard MPI Fortran types
3444    MPI_CHARACTER=0x4c00011a
3445    AC_SUBST(MPI_CHARACTER)
3446
3447    if test -z "$pac_cv_f77_sizeof_integer" ; then
3448        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])
3449    fi
3450    len_integer=$pac_cv_f77_sizeof_integer
3451    # Convert to two digit hex
3452    len=$len_integer
3453    #
3454    # Take len and turn it into two hex digits (there are 8 bits available
3455    # in the built-in datatype handle for the length; see
3456    # src/mpid/common/datatype/mpid_datatype.h).  This code is taken
3457    # from the code in mpich2/configure.ac
3458    if test "$len" -gt 255 ; then
3459        AC_MSG_ERROR([Type sizes greater than 255 bytes are not supported (type INTEGER is $len bytes)])
3460    fi
3461    tmplen=$len
3462    hexlen=""
3463    while test $tmplen -gt 0 ; do
3464        lowdigit=`expr $tmplen - 16 \* \( $tmplen / 16 \)`
3465        case $lowdigit in
3466        10) char=a ;;
3467        11) char=b ;;
3468        12) char=c ;;
3469        13) char=d ;;
3470        14) char=e ;;
3471        15) char=f ;;
3472         *) char=$lowdigit ;;
3473        esac
3474        hexlen="$char$hexlen"
3475        tmplen=`expr $tmplen / 16`
3476    done
3477    if test $len -lt 16 ; then
3478        hexlen="0$hexlen"
3479    fi
3480    len_integer=$hexlen
3481    if test "$len_integer" = 0 ; then
3482        # We have a problem
3483        AC_MSG_WARN([Unable to determine size of an INTEGER type; using 4])
3484        # We make the length 4
3485        len_integer="04"
3486    fi
3487    MPI_INTEGER=0x4c00${len_integer}1b
3488    MPI_REAL=0x4c00${len_integer}1c
3489    MPI_LOGICAL=0x4c00${len_integer}1d
3490    AC_SUBST(MPI_INTEGER)
3491    AC_SUBST(MPI_REAL)
3492    AC_SUBST(MPI_LOGICAL)
3493
3494    if test -z "$pac_cv_f77_sizeof_double_precision" ; then
3495        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])
3496    fi
3497    len_double=$pac_cv_f77_sizeof_double_precision
3498    # Convert to two digit hex
3499    len=$len_double
3500    #
3501    # Take len and turn it into two hex digits (there are 8 bits available
3502    # in the built-in datatype handle for the length; see
3503    # src/mpid/common/datatype/mpid_datatype.h).  This code is taken
3504    # from the code in mpich2/configure.ac
3505    if test "$len" -gt 255 ; then
3506        AC_MSG_ERROR([Type sizes greater than 255 bytes are not supported (type DOUBLE is $len bytes)])
3507    fi
3508    tmplen=$len
3509    hexlen=""
3510    while test $tmplen -gt 0 ; do
3511        lowdigit=`expr $tmplen - 16 \* \( $tmplen / 16 \)`
3512        case $lowdigit in
3513        10) char=a ;;
3514        11) char=b ;;
3515        12) char=c ;;
3516        13) char=d ;;
3517        14) char=e ;;
3518        15) char=f ;;
3519         *) char=$lowdigit ;;
3520        esac
3521        hexlen="$char$hexlen"
3522        tmplen=`expr $tmplen / 16`
3523    done
3524    if test $len -lt 16 ; then
3525        hexlen="0$hexlen"
3526    fi
3527    len_double=$hexlen
3528    if test "$len_double" = 0 ; then
3529       # We have a problem
3530       AC_MSG_WARN([Unable to determine size of a DOUBLE PRECISION type; using 8])
3531       # We make the length 8
3532       len_double="08"
3533    fi
3534
3535    # Provide the corresponding C types for MPI_REAL and MPI_DOUBLE
3536    AC_MSG_CHECKING([for C type matching Fortran real])
3537    noval=yes
3538    for c_type in float double "long_double" ; do
3539        eval ctypelen=\$"ac_cv_sizeof_$c_type"
3540        if test "$pac_cv_f77_sizeof_real" = "$ctypelen" -a \
3541          "$ctypelen" -gt 0 ; then
3542	    c_type=`echo $c_type | sed -e 's/_/ /g'`
3543	    AC_MSG_RESULT($c_type)
3544	    MPIR_FC_REAL_CTYPE=$c_type
3545	    noval="no"
3546	    break
3547        fi
3548    done
3549    if test "$noval" = "yes" ; then
3550        # Set a default
3551        MPIR_FC_REAL_CTYPE="float"
3552        AC_MSG_RESULT([unavailable])
3553    fi
3554
3555    noval=yes
3556    AC_MSG_CHECKING([for C type matching Fortran double])
3557    for c_type in double "long_double" float ; do
3558        eval ctypelen=\$"ac_cv_sizeof_$c_type"
3559        if test "$pac_cv_f77_sizeof_double_precision" = "$ctypelen" -a \
3560          "$ctypelen" -gt 0 ; then
3561	    c_type=`echo $c_type | sed -e 's/_/ /g'`
3562	    AC_MSG_RESULT($c_type)
3563	    MPIR_FC_DOUBLE_CTYPE=$c_type
3564	    noval="no"
3565	    break
3566        fi
3567    done
3568    if test "$noval" = "yes" ; then
3569        # Set a default
3570        MPIR_FC_DOUBLE_CTYPE="double"
3571        AC_MSG_RESULT([unavailable])
3572    fi
3573
3574    # These are needed to correctly implement the MPI reduction operations
3575    AC_DEFINE_UNQUOTED([MPIR_FC_REAL_CTYPE],[$MPIR_FC_REAL_CTYPE],
3576     [The C type for FORTRAN REAL])
3577    AC_DEFINE_UNQUOTED([MPIR_FC_DOUBLE_CTYPE],[$MPIR_FC_DOUBLE_CTYPE],
3578     [The C type for FORTRAN DOUBLE PRECISION])
3579
3580    # Use the proper length values for these items in case we are building
3581    # with Fortran integers that are not the same size as C ints and
3582    # reals and double precision that are the same size (not valid Fortran,
3583    # but used by some applications)
3584
3585    len_2integer=`expr 2 \* $len_integer`
3586    len_2real=`expr 2 \* $len_integer`
3587    len_doublecplx=`expr $pac_cv_f77_sizeof_double_precision \* 2`
3588    if test "$len_doublecplx" = 0 ; then
3589        # We have a problem
3590        AC_MSG_WARN([Unable to determine size of a DOUBLE PRECISION type; using 8])
3591        # We make the length 8*2 (in hex)
3592        len_doublecplx="16"
3593    fi
3594
3595    for lenname in len_2integer len_2real len_doublecplx ; do
3596        eval len=\$$lenname
3597	if test "$len" -gt 255 ; then
3598            AC_MSG_ERROR([Type sizes greater than 255 bytes are not supported (type $lenname is $len bytes)])
3599	fi
3600    	tmplen=$len
3601        hexlen=""
3602        while test $tmplen -gt 0 ; do
3603            lowdigit=`expr $tmplen - 16 \* \( $tmplen / 16 \)`
3604            case $lowdigit in
3605            10) char=a ;;
3606            11) char=b ;;
3607            12) char=c ;;
3608            13) char=d ;;
3609            14) char=e ;;
3610            15) char=f ;;
3611            *) char=$lowdigit ;;
3612            esac
3613            hexlen="$char$hexlen"
3614            tmplen=`expr $tmplen / 16`
3615        done
3616        if test $len -lt 16 ; then
3617            hexlen="0$hexlen"
3618        fi
3619        eval ${lenname}=$hexlen
3620        if test "$hexlen" = 0 ; then
3621           # We have a problem
3622           AC_MSG_WARN([Unable to determine size of a $lenname type; using 8])
3623           # We make the length 8
3624           eval ${lenname}=$hexlen
3625        fi
3626    done
3627
3628    MPI_DOUBLE_PRECISION=0x4c00${len_double}1f
3629    MPI_2INTEGER=0x4c00${len_2integer}20
3630    MPI_2REAL=0x4c00${len_2real}21
3631    MPI_COMPLEX=0x4c00${len_2real}1e
3632    AC_SUBST(MPI_COMPLEX)
3633    AC_SUBST(MPI_DOUBLE_PRECISION)
3634    AC_SUBST(MPI_2INTEGER)
3635    AC_SUBST(MPI_2REAL)
3636
3637dnl     len=$len_doublecplx
3638dnl     #
3639dnl     # Take len and turn it into two hex digits (there are 8 bits available
3640dnl     # in the built-in datatype handle for the length; see
3641dnl     # src/mpid/common/datatype/mpid_datatype.h).  This code is taken
3642dnl     # from the code in mpich2/configure.ac
3643dnl     if test "$len" -gt 255 ; then
3644dnl         AC_MSG_ERROR([Type sizes greater than 255 bytes are not supported (type DOUBLE COMPLEX is $len bytes)])
3645dnl     fi
3646dnl     tmplen=$len
3647dnl     hexlen=""
3648dnl     while test $tmplen -gt 0 ; do
3649dnl         lowdigit=`expr $tmplen - 16 \* \( $tmplen / 16 \)`
3650dnl         case $lowdigit in
3651dnl         10) char=a ;;
3652dnl         11) char=b ;;
3653dnl         12) char=c ;;
3654dnl         13) char=d ;;
3655dnl         14) char=e ;;
3656dnl         15) char=f ;;
3657dnl          *) char=$lowdigit ;;
3658dnl         esac
3659dnl         hexlen="$char$hexlen"
3660dnl         tmplen=`expr $tmplen / 16`
3661dnl     done
3662dnl     if test $len -lt 16 ; then
3663dnl         hexlen="0$hexlen"
3664dnl     fi
3665dnl     len_doublecplx=$hexlen
3666
3667    MPI_DOUBLE_COMPLEX=0x4c00${len_doublecplx}22
3668    MPI_2DOUBLE_PRECISION=0x4c00${len_doublecplx}23
3669    MPI_2COMPLEX=0x4c00${len_doublecplx}24
3670    AC_SUBST(MPI_DOUBLE_COMPLEX)
3671    AC_SUBST(MPI_2DOUBLE_PRECISION)
3672    AC_SUBST(MPI_2COMPLEX)
3673
3674    #
3675    # Temporary for the vast majority of systems that use 4 byte reals and
3676    # 8 byte doubles
3677    # Lengths at this point are in hex, hence "10" = 10 base 16 = 16 base 10.
3678    if test "$len_double" = "08" ; then
3679        F77_COMPLEX8=$MPI_COMPLEX
3680    fi
3681    if test "$len_doublecplx" = "10" ; then
3682        F77_COMPLEX16=$MPI_DOUBLE_COMPLEX
3683    fi
3684    if test "$len_long_double" = "10" -a "$MPID_NO_LONG_DOUBLE" != "yes" ; then
3685        F77_COMPLEX32="0x4c002025"
3686    else
3687        F77_COMPLEX32="MPI_DATATYPE_NULL"
3688    fi
3689
3690    len_2dc=`expr $pac_cv_f77_sizeof_double_precision \* 4`
3691    firstdigit=0
3692    seconddigit=0
3693    while test $len_2dc -ge 16 ; do
3694        firstdigit=`expr $firstdigit + 1`
3695        len_2dc=`expr $len_2dc - 16`
3696    done
3697    case $len_2dc in
3698        10) seconddigit=a ;;
3699        11) seconddigit=b ;;
3700        12) seconddigit=c ;;
3701        13) seconddigit=d ;;
3702        14) seconddigit=e ;;
3703        15) seconddigit=f ;;
3704         *) seconddigit=$len_2dc ;;
3705    esac
3706    len_2dc="$firstdigit$seconddigit"
3707    #echo "2double complex = $len_2dc"
3708    MPI_2DOUBLE_COMPLEX=0x4c00${len_2dc}25
3709    AC_SUBST(MPI_2DOUBLE_COMPLEX)
3710    MPI_F77_PACKED=$MPI_PACKED
3711    MPI_F77_UB=$MPI_UB
3712    MPI_F77_LB=$MPI_LB
3713    MPI_F77_BYTE=$MPI_BYTE
3714    AC_SUBST(MPI_F77_PACKED)
3715    AC_SUBST(MPI_F77_UB)
3716    AC_SUBST(MPI_F77_LB)
3717    AC_SUBST(MPI_F77_BYTE)
3718    #
3719    # We must convert all hex values to decimal (!)
3720    # It would be nice to use expr to extract the next character rather than
3721    # the heavier-weight sed, but expr under Tru64 Unix discards leading zeros,
3722    # even when used only with the match (:) command.  Rather than have
3723    # configure figure out if expr works, we just use sed.  Sigh.
3724    for var in CHARACTER INTEGER REAL LOGICAL DOUBLE_PRECISION COMPLEX \
3725        DOUBLE_COMPLEX 2INTEGER 2REAL 2COMPLEX 2DOUBLE_PRECISION \
3726        2DOUBLE_COMPLEX F77_PACKED F77_UB F77_LB F77_BYTE; do
3727        fullvar="MPI_$var"
3728        eval fullvarvalue=\$$fullvar
3729        #echo "$fullvar = $fullvarvalue"
3730        value=0
3731        fullvarvalue=`echo $fullvarvalue | sed -e 's/..\(.*\)/\1/'`
3732        for pos in 3 4 5 6 7 8 9 10 ; do
3733            # This works, even for Tru64, because only a single character
3734  	    # is extracted
3735            char=`expr $fullvarvalue : '\(.\)'`
3736	    # FIXME: Tru64 Unix eliminates leading zeros (!)
3737 	    # How do we fix something that broken?
3738	    fullvarvalue=`echo $fullvarvalue | sed -e 's/.\(.*\)/\1/'`
3739            case $char in
3740                a) char=10 ;;
3741	        b) char=11 ;;
3742	        c) char=12 ;;
3743	        d) char=13 ;;
3744	        e) char=14 ;;
3745	        f) char=15 ;;
3746            esac
3747            value=`expr $value \* 16 + $char`
3748        done
3749        #echo "$fullvar = $value"
3750	if test "X$value" = "X"; then
3751            eval origvarvalue=\$$fullvar
3752	    AC_MSG_ERROR([Internal Error: Failed to convert $fullvar value to hex!  Original value was $origvarvalue])
3753        fi
3754        eval $fullvar=$value
3755    done
3756    AC_LANG_C
3757
3758    # Now, handle the sized types
3759    #
3760    # Preload the C mpi types
3761    # THESE MUST MATCH THE DEFINITIONS IN MPI.H and MPIF.H
3762    # We use these to match the optional Fortran types
3763    char_mpi=${MPI_CHAR:-0}
3764    short_mpi=${MPI_SHORT:-0}
3765    int_mpi=${MPI_INT:-0}
3766    long_mpi=${MPI_LONG:-0}
3767    long_long_mpi=${MPI_LONG_LONG:-0}
3768    float_mpi=${MPI_FLOAT:-0}
3769    double_mpi=${MPI_DOUBLE:-0}
3770    long_double_mpi=${MPI_LONG_DOUBLE:-0}
3771
3772    #
3773    # The following code was correct for MPI-1, which allowed these datatypes
3774    # to be an alias for another MPI type.  MPI-2 requires these to
3775    # be distinct types, so these are enumerated
3776    if test "$use_alias_types" = yes ; then
3777        for len in 1 2 4 8 16 ; do
3778            eval F77_INTEGER$len=0
3779            #eval testval=\$"pac_cv_f77_sizeof_integer_$len"
3780            eval testval=\$"pac_cv_fort_integer$len"
3781            if test "$testval" = no ; then continue ; fi
3782	    testval=$len
3783            noval="yes"
3784            AC_MSG_CHECKING([for C type matching Fortran integer*$len])
3785            for c_type in char short int long "long_long" ; do
3786	        eval ctypelen=\$"ac_cv_sizeof_$c_type"
3787  	        if test "$testval" = "$ctypelen" -a "$ctypelen" -gt 0 ; then
3788	            AC_MSG_RESULT($c_type)
3789  	            eval F77_INTEGER$len=\$"${c_type}_mpi"
3790	            noval="no"
3791	            break
3792                fi
3793            done
3794            if test "$noval" = "yes" ; then
3795                AC_MSG_RESULT([unavailable])
3796            fi
3797        done
3798
3799        # Complex is set separately above
3800        for len in 4 8 16 ; do
3801            len2=`expr $len + $len`
3802            eval F77_REAL$len=0
3803            #eval F77_COMPLEX$len2=0
3804            #eval testval=\$"pac_cv_f77_sizeof_real_$len"
3805            eval testval=\$"pac_cv_fort_real$len"
3806            if test "$testval" = no ; then continue ; fi
3807	    testval=$len
3808            noval="yes"
3809            AC_MSG_CHECKING([for C type matching Fortran real*$len])
3810            for c_type in float double "long_double" ; do
3811	        eval ctypelen=\$"ac_cv_sizeof_$c_type"
3812	        if test "$testval" = "$ctypelen" -a "$ctypelen" -gt 0 ; then
3813	            AC_MSG_RESULT($c_type)
3814  	            eval F77_REAL$len=\$"${c_type}_mpi"
3815	            #eval F77_COMPLEX$len2=\$"${c_type}_cplx_mpi"
3816                    noval="no"
3817	            break
3818                fi
3819            done
3820            if test "$noval" = "yes" ; then
3821                AC_MSG_RESULT([unavailable])
3822            fi
3823        done
3824    else
3825        # Simply determine which types exist.  These may have been set by the
3826        # toplevel configure
3827        for var in INTEGER1 INTEGER2 INTEGER4 INTEGER8 INTEGER16 \
3828            REAL4 REAL8 REAL16 COMPLEX8 COMPLEX16 COMPLEX32 ; do
3829  	    eval varname=MPI_$var
3830            eval varvalue=\$$varname
3831	    #echo "$varname = $varvalue"
3832  	    if test "$varvalue" = MPI_DATATYPE_NULL ; then
3833	        eval F77_$var=0
3834  	    else
3835                eval F77_$var=\$$varname
3836  	    fi
3837       done
3838    fi
3839    # We must convert all hex values to decimal (!)
3840    for var in INTEGER1 INTEGER2 INTEGER4 INTEGER8 INTEGER16 \
3841        REAL4 REAL8 REAL16 COMPLEX8 COMPLEX16 COMPLEX32 ; do
3842        fullvar="F77_$var"
3843        eval fullvarvalue=\$$fullvar
3844        if test "$fullvarvalue" = 0 -o -z "$fullvarvalue" ; then
3845            eval $fullvar=MPI_DATATYPE_NULL
3846            continue
3847        fi
3848        #echo "$fullvar = $fullvarvalue"
3849        value=0
3850        # See the comments above on why expr with : cannot be used here
3851        fullvarvalue=`echo $fullvarvalue | sed -e 's/..\(.*\)/\1/'`
3852        for pos in 3 4 5 6 7 8 9 10 ; do
3853            #char=`expr substr $fullvarvalue $pos 1`
3854            char=`expr $fullvarvalue : '\(.\)'`
3855	    # We don't test for success of expr here because some expr's are
3856  	    # buggy and set the status to one on expressions like
3857            #    expr 00ccc : '\(.\)'
3858            # while both
3859            #    expr 00ccc : '\(..\)'
3860            # and
3861            #    expr 100cc : '\(.\)'
3862            # return a zero status.  So the status is set even on success,
3863            # if the result is a single character that is a zero (!)
3864	    #rc=$?
3865    	    #if test "$rc" != 0 ; then
3866  	    dnl #    AC_MSG_WARN([Failure (status $rc) in extracting first char from $fullvarvalue])
3867  	    #    break
3868	    #fi
3869	    fullvarvalue=`echo $fullvarvalue | sed -e 's/.\(.*\)/\1/'`
3870            case $char in
3871                a) char=10 ;;
3872	        b) char=11 ;;
3873	        c) char=12 ;;
3874	        d) char=13 ;;
3875	        e) char=14 ;;
3876	        f) char=15 ;;
3877            esac
3878            value=`expr $value \* 16 + $char`
3879	    if test $? != 0 ; then
3880	        AC_MSG_WARN([Failure to evaluate $value \* 16 + $char])
3881	    fi
3882        done
3883        #echo "$fullvar = $value"
3884        eval $fullvar=$value
3885    done
3886    AC_SUBST(F77_INTEGER1)
3887    AC_SUBST(F77_INTEGER2)
3888    AC_SUBST(F77_INTEGER4)
3889    AC_SUBST(F77_INTEGER8)
3890    AC_SUBST(F77_INTEGER16)
3891    AC_SUBST(F77_REAL4)
3892    AC_SUBST(F77_REAL8)
3893    AC_SUBST(F77_REAL16)
3894    AC_SUBST(F77_COMPLEX8)
3895    AC_SUBST(F77_COMPLEX16)
3896    AC_SUBST(F77_COMPLEX32)
3897
3898    noval="yes"
3899    AC_MSG_CHECKING([for C type matching Fortran integer])
3900    for c_type in char short int long "long_long" ; do
3901        eval ctypelen=\$"ac_cv_sizeof_$c_type"
3902        if test "$pac_cv_f77_sizeof_integer" = "$ctypelen" -a \
3903          "$ctypelen" -gt 0 ; then
3904	    c_type=`echo $c_type | sed -e 's/_/ /g'`
3905	    AC_MSG_RESULT($c_type)
3906	    MPI_FINT=$c_type
3907	    noval="no"
3908	    break
3909        fi
3910    done
3911    if test "$noval" = "yes" ; then
3912        # Set a default
3913        MPI_FINT="int"
3914        AC_MSG_RESULT([unavailable])
3915    fi
3916    # We also need to check the size of MPI_Aint vs MPI_Fint, and
3917    # define AINT_LARGER_THAN_FINT if aint is larger (this
3918    # affects code in MPI_Address)
3919    if test "$ac_cv_sizeof_void_p" != "0" -a \
3920        "$ac_cv_sizeof_void_p" -gt "$pac_cv_f77_sizeof_integer" ; then
3921        AC_DEFINE(HAVE_AINT_LARGER_THAN_FINT,1,[Define if addresses are larger than Fortran integers])
3922    fi
3923    if test "$ac_cv_sizeof_void_p" != 0 -a \
3924        "$ac_cv_sizeof_void_p" != "$pac_cv_f77_sizeof_integer" ; then
3925	AC_DEFINE(HAVE_AINT_DIFFERENT_THAN_FINT,1,[Define if addresses are a different size than Fortran integers])
3926    fi
3927
3928    # Include a defined value for Fint is int
3929    if test "$MPI_FINT" = "int" ; then
3930        AC_DEFINE(HAVE_FINT_IS_INT,1,[Define if Fortran integer are the same size as C ints])
3931    elif test "$SIZEOF_F77_INTEGER" != "$ac_cv_sizeof_int" ; then
3932        # Make this fatal because we do not want to build a broken fortran
3933	# interface (was error)
3934	# Check to see if the f77 binding has enabled the code to support
3935	# the case of int != fint.
3936	if grep HAVE_FINT_IS_INT $master_top_srcdir/src/binding/f77/testf.c 2>&1 1>/dev/null ; then
3937	    AC_MSG_WARN([Fortran integers and C ints are not the same size.  Support for this case is experimental; use at your own risk])
3938	else
3939            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.])
3940	fi
3941    fi
3942
3943    #
3944    # Set size of MPI_Status.  We may need sizeof_int here as well
3945    #
3946
3947    #
3948    # The size of MPI_Status is needed for the Fortran interface.
3949    # This is not quite right unless the device setup script, executed above,
3950    # sets the EXTRA_STATUS_DECL that will be used in defining a status.
3951    # The default size assumes that there are 5 ints
3952    AC_CACHE_CHECK([for size of MPI_Status],pac_cv_sizeof_mpi_status,[
3953        rm -f pac_mpi_status.h
3954        cat > pac_mpi_status.h <<_EOF
3955typedef struct {
3956    int count;
3957    int cancelled;
3958    int MPI_SOURCE;
3959    int MPI_TAG;
3960    int MPI_ERROR;
3961    $EXTRA_STATUS_DECL
3962} MPI_Status;
3963_EOF
3964        dnl another alternative is to use AC_CHECK_SIZEOF as follows:
3965        dnl AC_CHECK_SIZEOF([MPI_Status],[], [#include "pac_status.h"])
3966        dnl But AC_CHECK_SIZEOF has its own AC_MSG_CHECKING, so can't use
3967        dnl AC_CACHE_CHECK, so use AC_COMPUTE_INT here.
3968        default_status_size=`expr 5 \* $ac_cv_sizeof_int`
3969        AC_COMPUTE_INT([pac_cv_sizeof_mpi_status],
3970                       [sizeof(MPI_Status)],
3971                       [#include "pac_mpi_status.h"],
3972                       [pac_cv_sizeof_mpi_status=$default_status_size])
3973        rm -f pac_mpi_status.h
3974    ])
3975
3976    SIZEOF_MPI_STATUS=$pac_cv_sizeof_mpi_status
3977    export SIZEOF_MPI_STATUS
3978    AC_SUBST(SIZEOF_MPI_STATUS)
3979
3980    if test -z "$MPI_STATUS_SIZE" ; then
3981        if test -n "$SIZEOF_MPI_STATUS" ; then
3982            # compute from the C sizeof
3983            MPI_STATUS_SIZE=`expr $SIZEOF_MPI_STATUS / $ac_cv_sizeof_int`
3984            if test "$MPI_STATUS_SIZE" = "0" ; then
3985                AC_MSG_WARN([Could not compute the size of MPI_Status])
3986                MPI_STATUS_SIZE=5
3987            fi
3988        else
3989            AC_MSG_WARN([MPI_STATUS_SIZE was not defined!])
3990            # The default size is 5.  See mpi.h.in
3991            MPI_STATUS_SIZE=5
3992        fi
3993    fi
3994    AC_SUBST(MPI_STATUS_SIZE)
3995    MPIF_STATUS_SIZE=$MPI_STATUS_SIZE
3996    AC_DEFINE_UNQUOTED(MPIF_STATUS_SIZE,$MPIF_STATUS_SIZE,[Size of an MPI_STATUS, in Fortran, in Fortran integers])
3997
3998    # We must convert all hex values to decimal (!).
3999    # This is for the C types so they are also available in Fortran
4000    for var in CHAR SIGNED_CHAR UNSIGNED_CHAR WCHAR SHORT \
4001                  UNSIGNED_SHORT INT UNSIGNED_INT LONG UNSIGNED_LONG \
4002                  FLOAT DOUBLE LONG_DOUBLE LONG_LONG_INT \
4003                  UNSIGNED_LONG_LONG LONG_LONG FLOAT_INT DOUBLE_INT \
4004                  LONG_INT SHORT_INT "2INT" LONG_DOUBLE_INT \
4005                  INT8_T INT16_T INT32_T INT64_T            \
4006                  UINT8_T UINT16_T UINT32_T UINT64_T        \
4007                  C_BOOL C_FLOAT_COMPLEX C_DOUBLE_COMPLEX   \
4008                  C_LONG_DOUBLE_COMPLEX AINT OFFSET ; do
4009        fullvar="MPI_$var"
4010        fullf77var="MPI_F77_$var"
4011        eval fullvarvalue=\$$fullvar
4012        #echo "$fullvar = $fullvarvalue"
4013        if test "x$fullvarvalue" = "x" -o \
4014                "x$fullvarvalue" = "xMPI_DATATYPE_NULL" ; then
4015             eval $fullf77var="MPI_DATATYPE_NULL"
4016              continue
4017        fi
4018        value=0
4019        fullvarvalue=`echo $fullvarvalue | sed -e 's/..\(.*\)/\1/'`
4020        offset=0
4021        for pos in 3 4 5 6 7 8 9 10 ; do
4022            # This works, even for Tru64, because only a single character
4023            # is extracted
4024            char=`expr $fullvarvalue : '\(.\)'`
4025            # FIXME: Tru64 Unix eliminates leading zeros (!)
4026            # How do we fix something that broken?
4027            fullvarvalue=`echo $fullvarvalue | sed -e 's/.\(.*\)/\1/'`
4028            case $char in
4029                a) char=10 ;;
4030                b) char=11 ;;
4031                c) char=12 ;;
4032                d) char=13 ;;
4033                e) char=14 ;;
4034                f) char=15 ;;
4035            esac
4036            # For Fortran, if the value is too big for an unsigned int,
4037            # we need to make it a signed (negative) int. Currently, the
4038            # types in this class are the minloc/maxloc types.
4039            if test $pos = 3 -a $char -ge 8 ; then
4040                #echo "for $var in position $pos found a value >= 8"
4041                char=`expr $char - 8`
4042                offset=-2147483648
4043            fi
4044            value=`expr $value \* 16 + $char`
4045        done
4046        if test "$offset" != 0 ; then
4047            #echo "$fullf77var: $value, $offset"
4048            value=`expr $value + $offset`
4049        fi
4050        #echo "$fullf77var = $value"
4051        eval $fullf77var=$value
4052    done
4053    AC_SUBST(MPI_F77_CHAR)
4054    AC_SUBST(MPI_F77_SIGNED_CHAR)
4055    AC_SUBST(MPI_F77_UNSIGNED_CHAR)
4056    AC_SUBST(MPI_F77_WCHAR)
4057    AC_SUBST(MPI_F77_SHORT)
4058    AC_SUBST(MPI_F77_UNSIGNED_SHORT)
4059    MPI_F77_UNSIGNED=$MPI_F77_UNSIGNED_INT
4060    AC_SUBST(MPI_F77_UNSIGNED)
4061    AC_SUBST(MPI_F77_INT)
4062    AC_SUBST(MPI_F77_LONG)
4063    AC_SUBST(MPI_F77_UNSIGNED_LONG)
4064    AC_SUBST(MPI_F77_FLOAT)
4065    AC_SUBST(MPI_F77_DOUBLE)
4066    AC_SUBST(MPI_F77_LONG_DOUBLE)
4067    AC_SUBST(MPI_F77_UNSIGNED_LONG_LONG)
4068    MPI_F77_LONG_LONG_INT=$MPI_F77_LONG_LONG
4069    AC_SUBST(MPI_F77_LONG_LONG_INT)
4070    AC_SUBST(MPI_F77_LONG_LONG)
4071    AC_SUBST(MPI_F77_FLOAT_INT)
4072    AC_SUBST(MPI_F77_DOUBLE_INT)
4073    AC_SUBST(MPI_F77_LONG_INT)
4074    AC_SUBST(MPI_F77_SHORT_INT)
4075    AC_SUBST(MPI_F77_2INT)
4076    AC_SUBST(MPI_F77_LONG_DOUBLE_INT)
4077    AC_SUBST(MPI_F77_INT8_T)
4078    AC_SUBST(MPI_F77_INT16_T)
4079    AC_SUBST(MPI_F77_INT32_T)
4080    AC_SUBST(MPI_F77_INT64_T)
4081    AC_SUBST(MPI_F77_UINT8_T)
4082    AC_SUBST(MPI_F77_UINT16_T)
4083    AC_SUBST(MPI_F77_UINT32_T)
4084    AC_SUBST(MPI_F77_UINT64_T)
4085    AC_SUBST(MPI_F77_C_BOOL)
4086    AC_SUBST(MPI_F77_C_FLOAT_COMPLEX)
4087    # C_COMPLEX is an alias for FLOAT_COMPLEX
4088    MPI_F77_C_COMPLEX=$MPI_F77_C_FLOAT_COMPLEX
4089    AC_SUBST(MPI_F77_C_COMPLEX)
4090    AC_SUBST(MPI_F77_C_DOUBLE_COMPLEX)
4091    AC_SUBST(MPI_F77_C_LONG_DOUBLE_COMPLEX)
4092    # these two are not yet defined, but AC_SUBST only cares about them at
4093    # AC_OUTPUT-time
4094    AC_SUBST(MPI_F77_AINT)
4095    AC_SUBST(MPI_F77_OFFSET)
4096
4097    # Try and compute the values of .true. and .false. in Fortran
4098    # This code has been removed because the Fortran binding code does
4099    # not yet support it.
4100    PAC_F77_LOGICALS_IN_C([$MPI_FINT])
4101
4102    # Check if multiple __attribute__((alias)) is available
4103    if test "$enable_multi_aliases" = "yes" ; then
4104        PAC_C_MULTI_ATTR_ALIAS
4105        if test "$pac_c_multi_attr_alias" = "yes" ; then
4106            PAC_F2C_ATTR_ALIGNED_SIZE([1],[CMB_1INT_ALIGNMENT])
4107            AC_SUBST(CMB_1INT_ALIGNMENT)
4108            PAC_F2C_ATTR_ALIGNED_SIZE([$MPI_STATUS_SIZE],[CMB_STATUS_ALIGNMENT],
4109                                      [32])
4110            AC_SUBST(CMB_STATUS_ALIGNMENT)
4111            if test "X$CMB_1INT_ALIGNMENT" != "X" \
4112                 -a "X$CMB_STATUS_ALIGNMENT" != "X" ; then
4113                AC_DEFINE(HAVE_C_MULTI_ATTR_ALIAS, 1,
4114                    [Define if multiple __attribute__((alias)) are supported])
4115            fi
4116        fi
4117    fi
4118
4119    # Get the INTEGER_KIND, ADDRESS_KIND and OFFSET_KIND if possible
4120    #
4121    # For Fortran 90, we'll also need MPI_ADDRESS_KIND and MPI_OFFSET_KIND
4122    # Since our compiler might BE a Fortran 90 compiler, try and determine the
4123    # values.
4124    if test -z "$FC" ; then
4125        PAC_F77_IS_FC([
4126            FC=$F77
4127            if test -z "$FCFLAGS" ; then
4128                FCFLAGS="$FFLAGS"
4129            fi
4130        ])
4131    fi
4132    if test -n "$FC" ; then
4133        # Offset kind should be for 8 bytes if possible (Romio prefers that)
4134        # address should be sizeof void * (unless --with-aint-size has
4135        # been set)
4136        # FIXME in the current configure implementation OFFSET_KIND and
4137        # MPI_Offset won't always agree, but generally will.  The MPI Standard
4138        # implies that these types must have identical size, so this is a bug
4139        # waiting to happen.
4140	if test "$with_aint_size" -gt 0 -a \
4141	        "$with_aint_size" -gt "$ac_cv_sizeof_void_p" ; then
4142	    testsize=$with_aint_size
4143        else
4144            testsize=$ac_cv_sizeof_void_p
4145        fi
4146        if test "$testsize" = 0 ; then
4147            # Set a default
4148            testsize=4
4149        fi
4150        dnl Using the {} around testsize helps the comments work correctly
4151        PAC_PROG_FC_INT_KIND(ADDRESS_KIND,${testsize},$CROSS_F90_ADDRESS_KIND)
4152        if test "$testsize" = 8 ; then
4153            OFFSET_KIND=$ADDRESS_KIND
4154        else
4155            PAC_PROG_FC_INT_KIND(OFFSET_KIND,8,$CROSS_F90_OFFSET_KIND)
4156        fi
4157        #
4158        PAC_PROG_FC_INT_KIND(INTEGER_KIND,$pac_cv_f77_sizeof_integer,$CROSS_F90_INTEGER_KIND)
4159        if test "$INTEGER_KIND" = "-1" ; then
4160	    # Wild guess; probably means that Fortran 90 is not available
4161	    AC_MSG_WARN([Unable to determine Fortran 90 KIND values for either address-sized integers or offset-sized integers.  Using 4 in that case.])
4162            INTEGER_KIND=4
4163        fi
4164	#
4165        # Some compilers won't allow a -1 kind (e.g., absoft).  In this case,
4166        # use a fallback (sizeof(int) kind)
4167        if test "$ADDRESS_KIND" = "-1" -o "$OFFSET_KIND" = "-1" ; then
4168            if test "$ADDRESS_KIND" = "-1" ; then
4169	        ADDRESS_KIND=$INTEGER_KIND
4170            fi
4171            if test "$OFFSET_KIND" = "-1" ; then
4172	        OFFSET_KIND=$INTEGER_KIND
4173            fi
4174        fi
4175	AC_LANG_PUSH([Fortran])
4176        AC_CACHE_CHECK([if real*8 is supported in Fortran 90],
4177                       [pac_cv_fort90_real8],[
4178            AC_COMPILE_IFELSE([
4179                AC_LANG_PROGRAM([],[      real*8 a])
4180            ],[
4181                pac_cv_fort90_real8=yes
4182            ],[
4183                pac_cv_fort90_real8=no
4184            ])
4185        ])
4186	AC_LANG_POP([Fortran])
4187	WTIME_DOUBLE_TYPE="DOUBLE PRECISION"
4188	# Save a copy of the original mpi_base.f90 file
4189	if test "$enable_fc" = "yes" -a "$pac_cv_fort90_real8" = "yes" ; then
4190	    WTIME_DOUBLE_TYPE="REAL*8"
4191        fi
4192	# WTIME_DOUBLE_TYPE is substituted into mpi_base.f90
4193	AC_SUBST(WTIME_DOUBLE_TYPE)
4194    fi
4195    # Make sure that address kind and offset kind have values.
4196    if test -z "$ADDRESS_KIND" ; then
4197        ADDRESS_KIND=0
4198    fi
4199    if test -z "$OFFSET_KIND" ; then
4200        OFFSET_KIND=0
4201    fi
4202    # Note, however, that zero value are (in all practical case) invalid
4203    # for Fortran 90, and indicate a failure.  Test and fail if Fortran 90
4204    # enabled.
4205    if test "$enable_fc" = "yes" ; then
4206        if test "$ADDRESS_KIND" -le 0 -o "$OFFSET_KIND" -le 0 ; then
4207	    AC_MSG_ERROR([Unable to determine Fortran 90 integer kinds for MPI types.  If you do not need Fortran 90, add --disable-fc to the configure options.])
4208	    # If the above is converted to a warning, you need to change
4209	    # enable_fc and remote f90 from the bindings
4210	    enable_fc=no
4211        fi
4212    fi
4213    AC_SUBST(ADDRESS_KIND)
4214    AC_SUBST(OFFSET_KIND)
4215    AC_SUBST(INTEGER_KIND)
4216
4217    # Some compilers may require special directives to handle the common
4218    # block in a library.  In particular, directives are needed for Microsoft
4219    # Windows to support dynamic library import.  The following six
4220    # directives may be needed:
4221    #  CMS\$ATTRIBUTES DLLIMPORT::/MPIPRIV1/
4222    #  CMS\$ATTRIBUTES DLLIMPORT::/MPIPRIV2/
4223    #  CMS\$ATTRIBUTES DLLIMPORT::/MPIPRIVC/
4224    #  CDEC\$ATTRIBUTES DLLIMPORT::/MPIPRIV1/
4225    #  CDEC\$ATTRIBUTES DLLIMPORT::/MPIPRIV2/
4226    #  CDEC\$ATTRIBUTES DLLIMPORT::/MPIPRIVC/
4227    # CMS is for the Microsoft compiler,
4228    # CDEC is (we believe) for the DEC Fortran compiler.
4229    # We need to make this a configure-time variable because some compilers
4230    # (in particular, a version of the Intel Fortran compiler for Linux)
4231    # will read directives for other compilers and then flag as fatal
4232    # errors directives that it does not support but does recognize.
4233
4234    DLLIMPORT=""
4235    AC_SUBST(DLLIMPORT)
4236
4237    # FIXME:
4238    # We also need to include
4239    # SIZEOF_FC_MPI_OFFSET
4240    # SIZEOF_FC_MPI_AINT
4241    #
4242    # If other "kinds" are supported, MPI_SIZEOF needs to identify
4243    # those as well.  This is very difficult to do in a general way.
4244
4245    # To start with, we use the sizes determined for the Fortran 77 values.
4246    # These must be the same as for the Fortran 90 values.
4247    CROSS_F90_SIZEOF_INTEGER=${CROSS_F90_SIZEOF_INTEGER:-0}
4248    CROSS_F90_SIZEOF_REAL=${CROSS_F90_SIZEOF_REAL:-0}
4249    CROSS_F90_SIZEOF_DOUBLE_PRECISION=${CROSS_F90_SIZEOF_DOUBLE_PRECISION:-0}
4250    SIZEOF_FC_INTEGER=$CROSS_F90_SIZEOF_INTEGER
4251    SIZEOF_FC_REAL=$CROSS_F90_SIZEOF_REAL
4252    SIZEOF_FC_CHARACTER=1
4253    SIZEOF_FC_DOUBLE_PRECISION=$CROSS_F90_SIZEOF_DOUBLE_PRECISION
4254    if test "$pac_cv_f77_sizeof_integer" -gt 0 -a \
4255	    "$SIZEOF_FC_INTEGER" = "0" ; then
4256        SIZEOF_FC_INTEGER=$pac_cv_f77_sizeof_integer
4257    fi
4258    if test "$pac_cv_f77_sizeof_real" -gt 0 -a "$SIZEOF_FC_REAL" = "0" ; then
4259        SIZEOF_FC_REAL=$pac_cv_f77_sizeof_real
4260    fi
4261    if test "$pac_cv_f77_sizeof_double_precision" -gt 0 -a \
4262       "$SIZEOF_FC_DOUBLE_PRECISION" = "0" ; then
4263        SIZEOF_FC_DOUBLE_PRECISION=$pac_cv_f77_sizeof_double_precision
4264    fi
4265    AC_SUBST(SIZEOF_FC_INTEGER)
4266    AC_SUBST(SIZEOF_FC_REAL)
4267    AC_SUBST(SIZEOF_FC_DOUBLE_PRECISION)
4268    AC_SUBST(SIZEOF_FC_CHARACTER)
4269
4270    # REQD is short for "real equal double precision" and is set to the
4271    # Fortran 90 comment character if true.  This is necessary to
4272    # allow the mpi_sizeofs module to be built, since if this part of the
4273    # Fortran standard is violated by the compiler (unfortunately common,
4274    # as some applications are written to require this non-standard
4275    # version), the double precision versions of the MPI_SIZEOF routine
4276    # must be commented out of the module (!).
4277    REQD=
4278    if test "$SIZEOF_FC_REAL" = "$SIZEOF_FC_DOUBLE_PRECISION" ; then
4279        REQD="!"
4280    fi
4281    AC_SUBST(REQD)
4282    # Is integer*1 supported, and is it a different size than integer?
4283    REQI1="!"
4284    if test "$pac_cv_fort_integer1" = yes -a "$SIZEOF_FC_INTEGER" != 1 ; then
4285        REQI1=
4286    fi
4287    AC_SUBST(REQI1)
4288    # Is integer*2 supported, and is it a different size than integer?
4289    REQI2="!"
4290    if test "$pac_cv_fort_integer2" = yes -a "$SIZEOF_FC_INTEGER" != 2 ; then
4291        REQI2=
4292    fi
4293    AC_SUBST(REQI2)
4294    # Is integer*8 supported, and is it a different size than integer?
4295    REQI8="!"
4296    if test "$pac_cv_fort_integer8" = yes -a "$SIZEOF_FC_INTEGER" != 8 ; then
4297        REQI8=
4298    fi
4299    AC_SUBST(REQI8)
4300    #
4301
4302    AC_LANG_C
4303fi
4304# ----------------------------------------------------------------------------
4305# C++ types
4306if test "$enable_cxx" = "yes" ; then
4307    AC_LANG_CPLUSPLUS
4308    AC_CHECK_SIZEOF(bool)
4309
4310    # Find a C type that matches the size of the C++ boolean type
4311    case "$ac_cv_sizeof_bool" in
4312    	 $ac_cv_sizeof__Bool)
4313		bool_type=_Bool
4314		;;
4315    	 $ac_cv_sizeof_unsigned_char)
4316		bool_type="unsigned char"
4317		;;
4318    	 $ac_cv_sizeof_unsigned_short)
4319		bool_type="unsigned short"
4320		;;
4321    	 $ac_cv_sizeof_unsigned_int)
4322		bool_type="unsigned int"
4323		;;
4324    	 $ac_cv_sizeof_unsigned_long)
4325		bool_type="unsigned long"
4326		;;
4327    	 $ac_cv_sizeof_unsigned_long_long)
4328		bool_type="unsigned long long"
4329		;;
4330         *)
4331		AC_MSG_ERROR([unable to determine matching C type for C++ bool])
4332		;;
4333    esac
4334    AC_DEFINE_UNQUOTED([MPIR_CXX_BOOL_CTYPE],[$bool_type],
4335			[a C type used to compute C++ bool reductions])
4336
4337    AC_CHECK_HEADER(complex)
4338    if test "$ac_cv_header_complex" = "yes" ; then
4339        # The C++ complex types are all templated.  We finagle this by
4340        # defining a standin name
4341        AC_CHECK_SIZEOF(Complex,0,[#include <stdio.h>
4342#include <complex>
4343using namespace std;
4344#define Complex complex<float>
4345])
4346        AC_CHECK_SIZEOF(DoubleComplex,0,[#include <stdio.h>
4347#include <complex>
4348using namespace std;
4349#define DoubleComplex complex<double>
4350])
4351        if test "$MPID_NO_LONG_DOUBLE" != yes ; then
4352             AC_CHECK_SIZEOF(LongDoubleComplex,0,[#include <stdio.h>
4353#include <complex>
4354using namespace std;
4355#define LongDoubleComplex complex<long double>
4356])
4357        fi
4358
4359        # If either complex or double complex have length 0, then mark
4360        # c++ complex as unavailable
4361        if test "$ac_cv_sizeof_Complex" != 0 -a \
4362                "$ac_cv_sizeof_DoubleComplex" != 0 ; then
4363            AC_DEFINE(HAVE_CXX_COMPLEX,1,[Define is C++ supports complex types])
4364        fi
4365
4366        # Datatypes are given by
4367        # 0x4c00 <length in bytes> (1 byte) <unique num> (1 byte)
4368        # where the unique nums are
4369        # 33,34,35,36
4370        case "$ac_cv_sizeof_bool" in
4371           1)    MPIR_CXX_BOOL=0x4c000133 ;;
4372           2)    MPIR_CXX_BOOL=0x4c000233 ;;
4373           4)    MPIR_CXX_BOOL=0x4c000433 ;;
4374           8)    MPIR_CXX_BOOL=0x4c000833 ;;
4375           *) ;;
4376        esac
4377        case "$ac_cv_sizeof_Complex" in
4378           8)    MPIR_CXX_COMPLEX=0x4c000834 ;;
4379           16)   MPIR_CXX_COMPLEX=0x4c001034 ;;
4380           *) ;;
4381        esac
4382        case "$ac_cv_sizeof_DoubleComplex" in
4383           8)    MPIR_CXX_DOUBLE_COMPLEX=0x4c000835 ;;
4384           16)   MPIR_CXX_DOUBLE_COMPLEX=0x4c001035 ;;
4385           32)   MPIR_CXX_DOUBLE_COMPLEX=0x4c002035 ;;
4386           *) ;;
4387        esac
4388        case "$ac_cv_sizeof_LongDoubleComplex" in
4389           8)    MPIR_CXX_LONG_DOUBLE_COMPLEX=0x4c000836 ;;
4390           16)   MPIR_CXX_LONG_DOUBLE_COMPLEX=0x4c001036 ;;
4391           24)   MPIR_CXX_LONG_DOUBLE_COMPLEX=0x4c001836 ;;
4392           32)   MPIR_CXX_LONG_DOUBLE_COMPLEX=0x4c002036 ;;
4393           *) ;;
4394        esac
4395    fi
4396    AC_LANG_C
4397
4398    # Make these available to the collective operations and other code
4399    AC_DEFINE_UNQUOTED(MPIR_CXX_BOOL_VALUE,$MPIR_CXX_BOOL,[Define as the MPI Datatype handle for MPI::BOOL])
4400    AC_DEFINE_UNQUOTED(MPIR_CXX_COMPLEX_VALUE,$MPIR_CXX_COMPLEX,[Define as the MPI Datatype handle for MPI::COMPLEX])
4401    AC_DEFINE_UNQUOTED(MPIR_CXX_DOUBLE_COMPLEX_VALUE,$MPIR_CXX_DOUBLE_COMPLEX,[Define as the MPI Datatype handle for MPI::DOUBLE_COMPLEX])
4402    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])
4403
4404fi
4405
4406
4407# ----------------------------------------------------------------------------
4408# Check for the alignment rules moves with types int64_t etc.  These
4409# are used in the datatype code to perform pack and unpack operations.
4410# These only determine if different alignments *work*, not whether they
4411# work efficiently.  The datatype pack code (should) allow the developer
4412# to include stricter alignment rules than are needed for correctness to
4413# get better performance.
4414if test "$ac_cv_c_int64_t" != "no" -o -n "$INT64_T" ; then
4415    default_int64_t_alignment=${CROSS_INT64_T_ALIGNMENT:-"unknown"}
4416    if test -z "$INT64_T" ; then
4417         if test "$ac_cv_c_int64_t" = yes ; then
4418	     INT64_T="int64_t"
4419         else
4420             INT64_T="$ac_cv_int64_t"
4421         fi
4422    fi
4423    # We use the type that we're going use for int64.
4424    AC_CACHE_CHECK([for alignment restrictions on $INT64_T],pac_cv_int64_t_alignment,[
4425    AC_TRY_RUN([
4426#include <sys/types.h>
4427#include <stdlib.h>
4428int main(int argc, char **argv )
4429{
4430    $INT64_T *p1, v;
4431    char    *buf_p = (char *)malloc( 64 ), *bp;
4432    bp = buf_p;
4433    /* Make bp aligned on 4, not 8 bytes */
4434    if (!( (long)bp & 0x7 ) ) bp += 4;
4435    p1 = ($INT64_T *)bp;
4436    v = -1;
4437    *p1 = v;
4438    if (!( (long)bp & 0x3 ) ) bp += 2;
4439    p1 = ($INT64_T *)bp;
4440    *p1 = 1;
4441    if (!( (long)bp & 0x1 ) ) bp += 1;
4442    p1 = ($INT64_T *)bp;
4443    *p1 = 1;
4444    return 0;
4445}
4446],pac_cv_int64_t_alignment=no,pac_cv_int64_t_alignment=yes,pac_cv_int64_t_alignment=$default_int64_t_alignment)
4447])
4448    if test "$pac_cv_int64_t_alignment" = "no" ; then
4449         AC_DEFINE(HAVE_ANY_INT64_T_ALIGNMENT,1,[Define if int64_t works with any alignment])
4450    fi
4451fi
4452
4453if test "$ac_cv_int32_t" != "no" ; then
4454    default_int32_t_alignment=${CROSS_INT32_T_ALIGNMENT:-"unknown"}
4455    if test -z "$INT32_T" ; then
4456         if test "$ac_cv_c_int32_t" = yes ; then
4457	     INT32_T="int32_t"
4458         else
4459             INT32_T="$ac_cv_int32_t"
4460         fi
4461    fi
4462
4463    AC_CACHE_CHECK([for alignment restrictions on int32_t],pac_cv_int32_t_alignment,[
4464    AC_TRY_RUN([
4465#include <sys/types.h>
4466#include <stdlib.h>
4467int main(int argc, char **argv )
4468{
4469    $INT32_T *p1, v;
4470    char    *buf_p = (char *)malloc( 64 ), *bp;
4471    bp = buf_p;
4472    /* Make bp aligned on 4, not 8 bytes */
4473    if (!( (long)bp & 0x7 ) ) bp += 4;
4474    p1 = ($INT32_T *)bp;
4475    v = -1;
4476    *p1 = v;
4477    if (!( (long)bp & 0x3 ) ) bp += 2;
4478    p1 = ($INT32_T *)bp;
4479    *p1 = 1;
4480    if (!( (long)bp & 0x1 ) ) bp += 1;
4481    p1 = ($INT32_T *)bp;
4482    *p1 = 1;
4483    return 0;
4484}
4485],pac_cv_int32_t_alignment=no,pac_cv_int32_t_alignment=yes,pac_cv_int32_t_alignment=$default_int32_t_alignment)
4486])
4487    if test "$pac_cv_int32_t_alignment" = "no" ; then
4488         AC_DEFINE(HAVE_ANY_INT32_T_ALIGNMENT,1,[Define if int32_t works with any alignment])
4489    fi
4490fi
4491
4492# Get the size for the bsendoverhead
4493AC_CHECK_SIZEOF(MPIR_Bsend_data_t,128,[
4494#define MPI_Datatype int
4495#include "${master_top_srcdir}/src/include/mpibsend.h"]
4496)
4497BSEND_OVERHEAD=$ac_cv_sizeof_MPIR_Bsend_data_t
4498export BSEND_OVERHEAD
4499AC_SUBST(BSEND_OVERHEAD)
4500
4501# Check for special compile characteristics
4502# If we are either gcc or icc, see if we can use __asm__
4503# We test on prog_gcc to allow gcc by any name; if we are using
4504# icc, the value of CC must be icc for this test to pass
4505if test "$ac_cv_prog_gcc" = "yes" -o "$ac_cv_prog_CC" = "icc" ; then
4506AC_MSG_CHECKING([for gcc __asm__ and pentium cmpxchgl instruction])
4507AC_TRY_RUN([
4508int main(int argc, char *argv[])
4509{
4510long int compval = 10;
4511volatile long int *p = &compval;
4512long int oldval = 10;
4513long int newval = 20;
4514char ret;
4515long int readval;
4516__asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
4517	: "=q" (ret), "=m" (*p), "=a" (readval)
4518	: "r" (newval), "m" (*p), "a" (oldval) : "memory");
4519return (compval == 20) ? 0 : -1;
4520}
4521], AC_MSG_RESULT(yes)
4522   AC_DEFINE(HAVE_GCC_AND_PENTIUM_ASM, 1,[Define if using gcc on a system with an Intel Pentium class chip])
4523   lac_cv_use_atomic_updates="yes",
4524AC_MSG_RESULT(no), AC_MSG_RESULT(not checking when cross compiling))
4525fi
4526if test "$lac_cv_use_atomic_updates" = "yes" ; then
4527    AC_DEFINE(USE_ATOMIC_UPDATES,, [Define if assembly language atomic update macros should be used (if available)])
4528fi
4529
4530# check for x86_64
4531if test "$ac_cv_prog_gcc" = "yes" ; then
4532AC_MSG_CHECKING([for gcc __asm__ and AMD x86_64 cmpxchgq instruction])
4533AC_TRY_RUN([
4534int main(int argc, char *argv[])
4535{
4536long int compval = 10;
4537volatile long int *p = &compval;
4538long int oldval = 10;
4539long int newval = 20;
4540char ret;
4541long int readval;
4542__asm__ __volatile__ ("lock; cmpxchgq %3, %1; sete %0"
4543	: "=q" (ret), "=m" (*p), "=a" (readval)
4544	: "r" (newval), "m" (*p), "a" (oldval) : "memory");
4545return (compval == 20) ? 0 : -1;
4546}
4547], AC_MSG_RESULT(yes)
4548   AC_DEFINE(HAVE_GCC_AND_X86_64_ASM, 1,[Define if using gcc on a system with an AMD x86_64 class chip]),
4549AC_MSG_RESULT(no), AC_MSG_RESULT(not checking when cross compiling))
4550fi
4551dnl
4552dnl check for asm() format
4553dnl
4554dnl AC_MSG_CHECKING([for asm() and pentium cmpxchgl instruction])
4555dnl AC_TRY_RUN([
4556dnl int main(int argc, char *argv[])
4557dnl {
4558dnl long int compval = 10;
4559dnl volatile long int *p = &compval;
4560dnl long int oldval = 10;
4561dnl long int newval = 20;
4562dnl char ret;
4563dnl long int readval;
4564dnl asm("lock; cmpxchgl %3, %1; sete %0"
4565dnl 	: "=q" (ret), "=m" (*p), "=a" (readval)
4566dnl 	: "r" (newval), "m" (*p), "a" (oldval) : "memory");
4567dnl return (compval == 20) ? 0 : -1;
4568dnl }
4569dnl ], AC_MSG_RESULT(yes)
4570dnl    AC_DEFINE(HAVE_PENTIUM_ASM, 1,[Define if using asm() on a system with an Intel Pentium class chip]),
4571dnl AC_MSG_RESULT(no), AC_MSG_RESULT(not checking when cross compiling))
4572dnl
4573dnl
4574dnl check for IA64
4575dnl
4576if test "$ac_cv_prog_gcc" = "yes" ; then
4577AC_MSG_CHECKING([for gcc __asm__ and IA64 xchg4 instruction])
4578AC_TRY_RUN([
4579unsigned long _InterlockedExchange(volatile void *ptr, unsigned long x)
4580{
4581   unsigned long result;
4582   __asm__ __volatile ("xchg4 %0=[%1],%2" : "=r" (result)
4583       : "r" (ptr), "r" (x) : "memory");
4584   return result;
4585}
4586int main(int argc, char *argv[])
4587{
4588long val = 1;
4589volatile long *p = &val;
4590long oldval = _InterlockedExchange(p, (unsigned long)2);
4591return (oldval == 1 && val == 2) ? 0 : -1;
4592}
4593], AC_MSG_RESULT(yes)
4594   AC_DEFINE(HAVE_GCC_AND_IA64_ASM, 1,[Define if using gcc on a system with an IA64 class chip]),
4595AC_MSG_RESULT(no), AC_MSG_RESULT(not checking when cross compiling))
4596fi
4597# -----------------------------------------------------------------------------
4598# Check for support of enable-coverage.  Put this near the end of the tests
4599# because the coverage options may affect the other tests.
4600PAC_ENABLE_COVERAGE
4601
4602# -----------------------------------------------------------------------------
4603# Look for Standard headers
4604AC_HEADER_STDC
4605# Check for a specific header
4606# Grrr.  OS/X fails the test for sys/uio.h because uio *requires* sys/types.h
4607# to compile.  Thus, we'll make that a separate test
4608# stddef.h is sometimes needed for types like wchar_t
4609AC_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)
4610AC_CACHE_CHECK([for sys/uio.h],ac_cv_header_sys_uio_h,[
4611AC_TRY_COMPILE([
4612#include <sys/types.h>
4613#include <sys/uio.h>
4614],[int a;],ac_cv_header_sys_uio_h=yes,ac_cv_header_sys_uio_h=no)])
4615if test "$ac_cv_header_sys_uio_h" = yes ; then
4616    AC_DEFINE(HAVE_SYS_UIO_H,1,[Define if you have the <sys/uio.h> header file.])
4617fi
4618
4619# Check for special types
4620AC_TYPE_SIZE_T
4621
4622# These are used to support timeouts
4623AC_CHECK_FUNCS(setitimer alarm)
4624# These are used for error reporting
4625AC_CHECK_FUNCS(vsnprintf vsprintf)
4626if test "$ac_cv_func_vsnprintf" = "yes" ; then
4627    # vsnprintf may be declared in stdio.h and may need stdarg.h
4628    PAC_FUNC_NEEDS_DECL([#include <stdio.h>
4629#include <stdarg.h>],vsnprintf)
4630fi
4631# We would like to use strerror in the file namepublisher; it is also used
4632# in MPIU_Strerror (whose implementation is broken if strerror is not found)
4633AC_CHECK_FUNCS(strerror strncasecmp)
4634AC_FUNC_STRERROR_R
4635if test "$ac_cv_func_strerror_r" = "yes" ; then
4636    PAC_FUNC_NEEDS_DECL([#include <string.h>],strerror_r)
4637fi
4638
4639# Use snprintf if possible when creating messages
4640AC_CHECK_FUNCS(snprintf)
4641if test "$ac_cv_func_snprintf" = "yes" ; then
4642    PAC_FUNC_NEEDS_DECL([#include <stdio.h>],snprintf)
4643fi
4644
4645# qsort will be used in MPI_Comm_split, if available
4646AC_CHECK_FUNCS([qsort])
4647
4648# if we are using stdarg, we may need va_copy .  Test to see if we have it
4649# Since it may be a built-in instead of a function, we must try to
4650# compile and link a program that uses it.
4651# va_copy is currently used only in src/util/dbg_printf.c, in an obsolete
4652# debugging routine.  We may want to withdraw this (saving the
4653# test in confdb/aclocal_cc.m4).
4654AC_CACHE_CHECK([for va_copy],pac_cv_func_va_copy,[
4655AC_TRY_LINK([
4656#include <stdarg.h>
4657void foo1( char *fmt, ... ) {
4658    va_list ap, list;
4659    va_start(ap,fmt);
4660    va_copy(list,ap);
4661    va_end(list);
4662    va_end(ap);
4663}
4664],[foo1("a test %d", 3);],pac_cv_func_va_copy=yes,pac_cv_func_va_copy=no)])
4665
4666if test "$pac_cv_func_va_copy" = "yes" ; then
4667    AC_DEFINE(HAVE_VA_COPY,1,[Define if we have va_copy])
4668else
4669    AC_CACHE_CHECK([for __va_copy],pac_cv_func___va_copy,[
4670    AC_TRY_LINK([
4671#include <stdarg.h>
4672void foo1( char *fmt, ... ) {
4673    va_list ap, list;
4674    va_start(ap,fmt);
4675    __va_copy(list,ap);
4676    va_end(list);
4677    va_end(ap);
4678}
4679],[foo1("a test %d", 3);],pac_cv_func___va_copy=yes,pac_cv_func___va_copy=no)])
4680    if test "$pac_cv_func___va_copy" = "yes" ; then
4681        AC_DEFINE(HAVE___VA_COPY,1,[Define if we have __va_copy])
4682    fi
4683fi
4684
4685PAC_C_MACRO_VA_ARGS
4686
4687dnl
4688dnl If internationalization selected, try to find the needed functions
4689dnl if test "$enable_internat" = "yes" ; then
4690dnl     AC_CHECK_HEADERS(libintl.h)
4691dnl     AC_CHECK_FUNCS(gettext dgettext)
4692dnl     if test "$ac_cv_header_libintl" = "yes" -a \
4693dnl 	    "$ac_cv_func_gettext" = "yes" -a \
4694dnl 	    "$ac_cv_func_dgettext" = "yes" ; then
4695dnl 	AC_DEFINE(USE_GETTEXT,1,[Define if messages should use gettext])
4696dnl     else
4697dnl         AC_MSG_WARN([Cannot use internationalization because necessary headers and functions are not available])
4698dnl     fi
4699dnl fi
4700# Check for alloca function.  May set HAVE_ALLOCA_H and HAVE_ALLOCA
4701AC_FUNC_ALLOCA
4702# We don't use alloca unless USE_ALLOCA is also set.
4703AC_ARG_ENABLE(alloca,
4704	AC_HELP_STRING([--enable-alloca],
4705		[Use alloca to allocate temporary memory if available]),,enable_alloca=no)
4706if test "$enable_alloca" = yes ; then
4707    AC_DEFINE(USE_ALLOCA,1,[Define if alloca should be used if available])
4708fi
4709
4710if test "$enable_g_mem" != "yes" ; then
4711    # Strdup is needed only if memory tracing is not enabled.
4712    AC_CHECK_FUNCS(strdup)
4713    if test "$ac_cv_func_strdup" = "yes" ; then
4714        # Do we need to declare strdup?
4715        PAC_FUNC_NEEDS_DECL([#include <string.h>],strdup)
4716    fi
4717else
4718    # search.h is used for fancier output from trmem.  Disabled for now,
4719    # since the tsearch routines have problematic prototypes.
4720    AC_CHECK_HEADERS(search)
4721    AC_CHECK_FUNCS(tsearch)
4722    # Check that we can compile tsearch without error.  Try to compile
4723    # it with the header and the char * args
4724    if test "$ac_cv_func_tsearch" = "yes" ; then
4725        AC_CACHE_CHECK([whether tsearch requires char* args],
4726	               pac_cv_tsearch_charp,[
4727        AC_TRY_COMPILE([#include <search.h>
4728    char *tsearch( char *k, char **r, (int (*)())compare ) { return k; }],
4729    [int f=0;],pac_cv_tsearch_charp=yes,pac_cv_tsearch_charp=no)])
4730        if test "$pac_cv_tsearch_charp" = "yes" ; then
4731	    # this should consider defining a name with the argument type
4732	    # so that no further ifdefs are needed
4733	    AC_DEFINE(USE_TSEARCH_WITH_CHARP,1,[Define if tsearch requires char pointers])
4734	fi
4735    fi
4736    # Note that HPUX and AIX may require _INCLUDE_XOPEN_SOURCE or
4737    # _XOPEN_SOURCE be defined respectively.
4738fi
4739
4740# ----------------------------------------------------------------------------
4741# Look for some non-posix, but commonly provided functions
4742# ----------------------------------------------------------------------------
4743# mkstemp() is a better replacement for mktemp()
4744AC_HAVE_FUNCS(mkstemp)
4745if test "$ac_cv_func_mkstemp" = "yes" ; then
4746    PAC_FUNC_NEEDS_DECL([#include <stdlib.h>],mkstemp)
4747fi
4748# fdopen() converts from an fd to a FILE*
4749AC_HAVE_FUNCS(fdopen)
4750if test "$ac_cv_func_fdopen" = "yes" ; then
4751    PAC_FUNC_NEEDS_DECL([#include <stdlib.h>],fdopen)
4752fi
4753# putenv() sets environment variable
4754AC_HAVE_FUNCS(putenv)
4755if test "$ac_cv_func_putenv" = "yes" ; then
4756    PAC_FUNC_NEEDS_DECL([#include <stdlib.h>],putenv)
4757fi
4758
4759
4760# ----------------------------------------------------------------------------
4761# Support for timers.  The following code processes the
4762#  --enable-timer-type=name argument and selects the timer based on
4763# both that field and what configure is able to determine is available.
4764# The file src/include/mpichtimer.h is also created.
4765# Note that at least the handling of the "device" option must come *after*
4766# the setup_device script is loaded so that the device can set the appropriate
4767# fields.  For now, we've split this so that there is an update to the timer
4768# after the setup_device script is loaded, but we should consider moving
4769# this entire block.
4770# FIXME DJG setup_device has been eliminated in favor of subconfigure.m4 files
4771# ----------------------------------------------------------------------------
4772# Default type for timer stamp.
4773MPID_TIMER_TYPE=long
4774AC_SUBST(MPID_TIMER_TYPE)
4775
4776# clock_gettime is the POSIX gettimeofday
4777# gethrtime is the Solaris high-resolution timer
4778dnl
4779dnl Specific checks that a function works correctly
4780dnl
4781dnl Now that we know what the options are, choose the timer to use
4782dnl
4783dnl The default preference is
4784dnl    Solaris gethrtime
4785dnl    Posix   clock_gettime
4786dnl    Unix    gettimeofday (one of two versions)
4787dnl
4788dnl Also available are various hardware time stamps
4789dnl    Linux-x86 cycle counter
4790dnl    Linux-alpha cycle counter
4791dnl
4792dnl We also allow --enable-timer-type=name to select a timer type
4793AC_ARG_ENABLE(timer-type,
4794[  --enable-timer-type=name - Select the timer to use for MPI_Wtime and
4795                             internal timestamps.
4796        gethrtime          - Solaris timer (Solaris systems only)
4797        clock_gettime      - Posix timer (where available)
4798        gettimeofday       - Most Unix systems
4799        linux86_cycle      - Linux x86; returns cycle counts, not time in seconds*
4800        gcc_ia64_cycle     - IPF ar.itc timer*
4801	mach_absolute_time - Mach absolute time (alternative to clock_gettime
4802                             for OSX)
4803        device - The timer is provided by the device
4804
4805        *Note that the cycle timers are intended to be used by MPICH2
4806        developers for internal low-level timing.  Normal users should
4807        not use these as they are not guaranteed to be accurate in
4808        certain situations.
4809
4810        linuxalpha_cycle is no longer supported.
4811],timer_type=$enable_timer_type)
4812
4813if test -z "$timer_type" ; then
4814    # Try to pick a timer based on what is available
4815    AC_CHECK_FUNCS(clock_gettime clock_getres gethrtime mach_absolute_time gettimeofday)
4816    if test "$ac_cv_func_gethrtime" = "yes" ; then
4817        # Sigh.  The Solaris include files do not define hrtime_t
4818	# Before we accept this choice, make sure that we can
4819	# do arithmetic with hrtime_t .
4820        AC_CACHE_CHECK([that hrtime_t is properly defined for gethrtime],
4821	pac_cv_hrtime_works,[
4822	AC_TRY_COMPILE([
4823#include <sys/time.h>
4824],[hrtime_t t1, t2; t1 = 1; t2 = 2; t1 = t1 + t2;],
4825pac_cv_hrtime_works=yes,pac_cv_hrtime_works=no)])
4826	# A more ambitious test would look to see if casting an
4827	# hrtime_t to int64_t works, and even more ambitious
4828	# would check whether long or long long was 64 bits (or even
4829	# better, the sizeof hrtime_t).
4830    fi
4831    if test "$ac_cv_func_gethrtime" = "yes" -a \
4832            "$pac_cv_hrtime_works" = "yes" ; then
4833        timer_type=gethrtime
4834    elif test "$ac_cv_func_clock_gettime" = "yes" -a \
4835              "$ac_cv_func_clock_getres" = "yes" ; then
4836	 # Test on both because some systems (e.g., cygwin) provide
4837	 # clock_gettime but not clock_getres
4838        timer_type=clock_gettime
4839    elif test "$ac_cv_func_mach_absolute_time" = "yes" ; then
4840        timer_type=mach_absolute_time
4841    elif test "$ac_cv_func_gettimeofday" = "yes" ; then
4842        timer_type=gettimeofday
4843    fi
4844fi
4845if test -z "$timer_type" ; then
4846    AC_MSG_ERROR([No timer found])
4847fi
4848
4849# Check for valid timer and select datatypes for the time stamp
4850case "$timer_type" in
4851
4852    gethrtime)
4853    MPID_TIMER_TYPE=hrtime_t
4854    AC_CHECK_FUNC(gethrtime,,[
4855         AC_MSG_ERROR([Requested timer gethrtime is not available])
4856])
4857    ;;
4858
4859    clock_gettime)
4860    missing_function=no
4861    AC_SEARCH_LIBS([clock_gettime],[rt],,AC_MSG_ERROR([clock_gettime is not available]))
4862    AC_SEARCH_LIBS([clock_getres],[rt],,AC_MSG_ERROR([clock_getres is not available]))
4863    MPID_TIMER_TYPE="struct timespec"
4864    # AIX does not always define struct timespec (!)
4865    # Make sure that we can use struct timespec
4866    AC_CACHE_CHECK([whether struct timespec is defined in time.h],
4867                    pac_cv_struct_timespec_defined,[
4868    AC_TRY_COMPILE([
4869#include <time.h>],[
4870    struct timespec t;],pac_cv_struct_timespec_defined=yes,
4871    pac_cv_struct_timespec_defined=no)
4872])
4873    if test "$pac_cv_struct_timespec_defined" != "yes" ; then
4874        # Try again, but with -D_XOPEN_SOURCE=500 (works for AIX)
4875        AC_CACHE_CHECK([whether struct timespec is defined in time.h with _XOPEN_SOURCE=500],
4876                    pac_cv_struct_timespec_defined_with_xopen500,[
4877        AC_TRY_COMPILE([
4878#define _XOPEN_SOURCE 500
4879#include <time.h>],[
4880    struct timespec t;],pac_cv_struct_timespec_defined_with_xopen500=yes,
4881    pac_cv_struct_timespec_defined_with_xopen500=no)
4882])
4883	if test "$pac_cv_struct_timespec_defined_with_xopen500" = "yes" ; then
4884	    # We need to define _XOPEN_SOURCE=500, but we need to ensure that
4885	    # this is done before any include files are loaded.  At
4886	    # this point it is really too late to add this definition,
4887	    # since it may make other tests incompatible.
4888	    AC_MSG_ERROR([The available timer requires _XOPEN_SOURCE=500.  Add -D_XOPEN_SOURCE=500 to CFLAGS and rerun configure])
4889        fi
4890    fi
4891    #
4892    # FreeBSD 4.3 incorrectly puts the header into sys/time.h;
4893    # time.h is required (see pages 45 and 46 in the POSIX standard).
4894    # See if we can compile
4895    AC_CACHE_CHECK([for CLOCK_REALTIME defined in time.h],pac_cv_posix_clock_realtime,[
4896    AC_TRY_COMPILE([
4897#include <time.h>],[
4898    clockid_t cid = CLOCK_REALTIME;],pac_cv_posix_clock_realtime=yes,
4899pac_cv_posix_clock_realtime=no)])
4900    if test "$pac_cv_posix_clock_realtime" = "no" ; then
4901         AC_MSG_WARN([POSIX timer requires definitions in time.h])
4902	 # Check for the definition in sys/time.h, which is where
4903	 # OpenBSD and FreeBSD have put it by mistake
4904         AC_TRY_COMPILE([
4905#include <time.h>
4906#include <sys/time.h>],[
4907    clockid_t cid = CLOCK_REALTIME;],pac_cv_posix_clock_realtime=yes,
4908pac_cv_posix_clock_realtime=no)
4909	if test "$pac_cv_posix_clock_realtime" = yes ; then
4910	    AC_MSG_WARN([sys/time.h required for POSIX timer])
4911	    AC_DEFINE(NEEDS_SYS_TIME_H,1,[Define if sys/time.h is required to get timer definitions])
4912	else
4913	    AC_MSG_ERROR([Cannot find the definition of CLOCK_REALTIME for the POSIX timer])
4914	fi
4915    fi
4916    ;;
4917
4918    gettimeofday)
4919    MPID_TIMER_TYPE="struct timeval"
4920    # We may have already tested for gettimeofday.  If we got a "yes",
4921    # we're good to go
4922    if test "$ac_cv_func_gettimeofday" != "yes" ; then
4923        AC_CHECK_FUNC(gettimeofday,,[
4924         AC_MSG_ERROR([Requested timer gettimeofday is not available])
4925])
4926    fi
4927    ;;
4928
4929    linux86_cycle|linux86_cycle_2)
4930
4931# The following AC_TRY_RUN statements are needed because x86_64 compilers
4932# usually know about rdtscp but the cpu may or may not actually implement the
4933# feature.  This is not cross-compile safe, unfortunately.  In the long run we
4934# should allow the user to override this with a configure flag.
4935    AC_CACHE_CHECK([that linux86 cycle counter is available],
4936        pac_cv_linux86_cycle,
4937            AC_TRY_RUN([
4938int main()
4939{
4940    /* rdtscp */
4941    long long var, *var_ptr=&var;
4942    __asm__ __volatile__("rdtscp; shl \$32, %%rdx; or %%rdx, %%rax" : "=a" (*var_ptr) : : "ecx", "rdx");
4943    return 0;
4944}
4945            ],pac_cv_linux86_cycle=rdtscp,
4946                AC_TRY_RUN([[
4947int main()
4948{
4949    /* cpuid 64 */
4950    long long var, *var_ptr=&var;
4951    __asm__ __volatile__("push %%rbx ; cpuid ; rdtsc ; pop %%rbx ; shl $32, %%rdx; or %%rdx, %%rax" : "=a" (*var_ptr) : : "ecx", "rdx");
4952    return 0;
4953}
4954                ]],pac_cv_linux86_cycle=cpuid_rdtsc64,
4955                    AC_TRY_RUN([[[
4956int main()
4957{
4958    /* cpuid 32 */
4959    long long var, *var_ptr=&var;
4960    __asm__ __volatile__("push %%ebx ; cpuid ; rdtsc ; pop %%ebx" : "=A" (*var_ptr) : : "ecx");
4961    return 0;
4962}
4963                    ]]],pac_cv_linux86_cycle=cpuid_rdtsc32,
4964                        AC_TRY_RUN([[[[
4965int main()
4966{
4967    /* simple */
4968    long long var, *var_ptr=&var;
4969    __asm__ __volatile__("rdtsc" : "=A" (*var_ptr));
4970    return 0;
4971}
4972                        ]]]],pac_cv_linux86_cycle=rdtsc,
4973                        pac_cv_linux86_cycle=no)
4974                    )
4975                ),
4976dnl The if-cross-compiling clause from the first AC_TRY_RUN.  Hope that if the
4977dnl compiler knows about the instruction then it's supported by the target
4978dnl platform.
4979                AC_TRY_COMPILE(,[[
4980                    long long var, *var_ptr=&var;
4981                    __asm__ __volatile__("rdtscp; shl \$32, %%rdx; or %%rdx, %%rax" : "=a" (*var_ptr) : : "ecx", "rdx");
4982                ]],pac_cv_linux86_cycle=rdtscp,
4983                    AC_TRY_COMPILE(,[[[
4984                        long long var, *var_ptr=&var;
4985                        __asm__ __volatile__("push %%rbx ; cpuid ; rdtsc ; pop %%rbx ; shl $32, %%rdx; or %%rdx, %%rax" : "=a" (*var_ptr) : : "ecx", "rdx");
4986                    ]]],pac_cv_linux86_cycle=cpuid_rdtsc64,
4987                        AC_TRY_COMPILE(,[[[[
4988                            long long var, *var_ptr=&var;
4989                            __asm__ __volatile__("push %%ebx ; cpuid ; rdtsc ; pop %%ebx" : "=A" (*var_ptr) : : "ecx");
4990                        ]]]],pac_cv_linux86_cycle=cpuid_rdtsc32,
4991                            AC_TRY_COMPILE(,[[[[[
4992                                long long var, *var_ptr=&var;
4993                                __asm__ __volatile__("rdtsc" : "=A" (*var_ptr));
4994                            ]]]]],pac_cv_linux86_cycle=rdtsc,
4995                            pac_cv_linux86_cycle=no)
4996                        )
4997                    )
4998                )
4999            )
5000    )
5001
5002    case "$pac_cv_linux86_cycle" in
5003        "rdtscp")
5004            AC_DEFINE(LINUX86_CYCLE_RDTSCP,1,[Define which x86 cycle counter to use])
5005	    ;;
5006        "cpuid_rdtsc64")
5007            AC_DEFINE(LINUX86_CYCLE_CPUID_RDTSC64,1,[Define which x86 cycle counter to use])
5008            ;;
5009        "cpuid_rdtsc32")
5010            AC_DEFINE(LINUX86_CYCLE_CPUID_RDTSC32,1,[Define which x86 cycle counter to use])
5011	    ;;
5012        "rdtsc")
5013            AC_DEFINE(LINUX86_CYCLE_RDTSC,1,[Define which x86 cycle counter to use])
5014	    ;;
5015        *)
5016            cpu_gcc_x86_cycle=no
5017	    ;;
5018    esac
5019
5020    if test "$cpu_gcc_x86_cycle" = "no" ; then
5021        AC_MSG_ERROR([Linux86 cycle counter is not available on this system and or with the $CC compiler])
5022    fi
5023    MPID_TIMER_TYPE="long long"
5024    ;;
5025
5026    gcc_ia64_cycle)
5027    AC_CACHE_CHECK([that IPF timer is available],
5028pac_cv_ia64_cycle,[
5029    AC_TRY_COMPILE(,[
5030    long var, *var_ptr=&var;
5031#ifdef __INTEL_COMPILER
5032#include "ia64regs.h"
5033    var=__getReg(_IA64_REG_AR_ITC);
5034#else
5035    __asm__ __volatile__("mov %0=ar.itc" : "=r" (var_ptr));
5036#endif
5037],pac_cv_gcc_ia64_cycle=yes,pac_cv_gcc_ia64_cycle=no)])
5038    if test "$pac_cv_gcc_ia64_cycle" != "yes" ; then
5039        AC_MSG_ERROR([IPF cycle counter is not available on this system and or with the $CC compiler])
5040     fi
5041     MPID_TIMER_TYPE="long"
5042     ;;
5043
5044    linuxalpha_cycle)
5045    AC_MSG_ERROR([linuxalpha_cycle is no longer supported])
5046    ;;
5047
5048    mach_absolute_time)
5049    AC_CHECK_FUNC(mach_absolute_time,,[AC_MSG_ERROR([mach_absolute_time is not available])])
5050    AC_CHECK_FUNC(mach_timebase_info,,[AC_MSG_ERROR([mach_timebase_info is not available])])
5051    MPID_TIMER_TYPE="uint64_t"
5052    ;;
5053
5054    device)
5055    # The device selected should export the datatype for the timer
5056    # in MPID_DEVICE_TIMER_TYPE if something other than long is needed
5057    if test -n "$MPID_DEVICE_TIMER_TYPE" ; then
5058       MPID_TIMER_TYPE=$MPID_DEVICE_TIMER_TYPE
5059    fi
5060    ;;
5061
5062    *)
5063    AC_MSG_ERROR([Invalid timer type $timer_type])
5064    ;;
5065esac
5066# Convert timer type to upper case
5067timer_type=`echo $timer_type | \
5068    tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
5069MPICH_TIMER_KIND=USE_$timer_type
5070AC_SUBST(MPICH_TIMER_KIND)
5071# ----------------------------------------------------------------------------
5072# End of code for timer support (except for ac_ OUTPUT)
5073# ----------------------------------------------------------------------------
5074# Setup other replaceable values
5075AC_SUBST(MPILIBNAME)
5076AC_SUBST(PMPILIBNAME)
5077
5078if test "$NEEDSPLIB" = "yes" ; then
5079   LPMPILIBNAME="-l${PMPILIBNAME}"
5080fi
5081AC_SUBST(LPMPILIBNAME)
5082
5083# Note that aint_size must be used instead of void_p where the desired check
5084# is on the size of MPI_Aint
5085aint_size=$ac_cv_sizeof_void_p
5086if test "$with_aint_size" -gt 0 ; then
5087   aint_size=$with_aint_size
5088   if test "$aint_size" != "$ac_cv_sizeof_void_p" ; then
5089        AC_MSG_RESULT([Overriding MPI_Aint to be $aint_size bytes])
5090   fi
5091fi
5092MPI_AINT=int
5093for type in int long long_long short ; do
5094    eval len=\$ac_cv_sizeof_$type
5095    if test "$len" = "$aint_size" ; then
5096        MPI_AINT=`echo $type | sed -e 's/_/ /'`
5097        # Make the sizeof AINT available to other configures
5098        MPI_SIZEOF_AINT=$len
5099        export MPI_SIZEOF_AINT
5100        case $type in
5101            int)
5102                MPI_AINT_FMT_DEC_SPEC="%d"
5103                MPI_AINT_FMT_HEX_SPEC="%x"
5104                ;;
5105            long)
5106                MPI_AINT_FMT_DEC_SPEC="%ld"
5107                MPI_AINT_FMT_HEX_SPEC="%lx"
5108                ;;
5109            long_long)
5110                MPI_AINT_FMT_DEC_SPEC="%lld"
5111                MPI_AINT_FMT_HEX_SPEC="%llx"
5112                ;;
5113            short)
5114                MPI_AINT_FMT_DEC_SPEC="%hd"
5115                MPI_AINT_FMT_HEX_SPEC="%hx"
5116                ;;
5117            *)
5118                AC_MSG_WARN([unable to determine format specifiers for MPI_Aint, defaulting to int])
5119                MPI_AINT_FMT_DEC_SPEC="%d"
5120                MPI_AINT_FMT_HEX_SPEC="%x"
5121            ;;
5122        esac
5123        export MPI_AINT_FMT_DEC_SPEC MPI_AINT_FMT_HEX_SPEC
5124        break
5125    fi
5126done
5127AC_SUBST(MPI_AINT)
5128AC_SUBST(MPI_AINT_FMT_DEC_SPEC)
5129AC_SUBST(MPI_AINT_FMT_HEX_SPEC)
5130
5131# If sizeof(mpi_aint) = sizeof(int), set this value
5132if test "$ac_cv_sizeof_int" = "$aint_size" ; then
5133    AC_DEFINE(SIZEOF_INT_IS_AINT,1,[define if sizeof(int) = sizeof(MPI_Aint)])
5134fi
5135
5136# Find a pointer-sized int
5137for type in int long long_long short ; do
5138    eval len=\$ac_cv_sizeof_$type
5139    if test "$len" = "$ac_cv_sizeof_void_p" ; then
5140        case $type in
5141            int)
5142                MPIR_PINT_FMT_DEC_SPEC="\"%d\""
5143                MPIR_UPINT_FMT_DEC_SPEC="\"%u\""
5144                ;;
5145            long)
5146                MPIR_PINT_FMT_DEC_SPEC="\"%ld\""
5147                MPIR_UPINT_FMT_DEC_SPEC="\"%lu\""
5148                ;;
5149            long_long)
5150                MPIR_PINT_FMT_DEC_SPEC="\"%lld\""
5151                MPIR_UPINT_FMT_DEC_SPEC="\"%llu\""
5152                ;;
5153            short)
5154                MPIR_PINT_FMT_DEC_SPEC="\"%hd\""
5155                MPIR_UPINT_FMT_DEC_SPEC="\"%hu\""
5156                ;;
5157            *)
5158                AC_MSG_WARN([unable to determine format specifiers for MPIR_Pint, defaulting to int])
5159                MPIR_PINT_FMT_DEC_SPEC="\"%d\""
5160                MPIR_UPINT_FMT_DEC_SPEC="\"%u\""
5161            ;;
5162        esac
5163        MPIR_PINT=`echo $type | sed -e 's/_/ /'`
5164        break
5165    fi
5166done
5167AC_DEFINE_UNQUOTED(MPIR_Pint,$MPIR_PINT,[MPIR_Pint is a pointer-sized integer])
5168# allow @MPIR_PINT@ substitution in glue_romio.h
5169AC_SUBST([MPIR_PINT])
5170
5171AC_DEFINE_UNQUOTED(MPIR_PINT_FMT_DEC_SPEC,
5172    $MPIR_PINT_FMT_DEC_SPEC,[MPIR_PINT_FMT_DEC_SPEC is the format
5173    specifier for printing Pint as a decimal])
5174AC_DEFINE_UNQUOTED(MPIR_Upint,unsigned $MPIR_PINT,[MPIR_Upint is an unsigned pointer-sized integer])
5175AC_DEFINE_UNQUOTED(MPIR_UPINT_FMT_DEC_SPEC,
5176    $MPIR_UPINT_FMT_DEC_SPEC,[MPIR_UPINT_FMT_DEC_SPEC is the format
5177    specifier for printing Upint as a decimal])
5178
5179# ----------------------------------------------------------------------------
5180# MPI_AINT datatype
5181# ----------------------------------------------------------------------------
5182# Must be done after MPI_Aint type determination but before subconfigures.
5183
5184# convert to 2-char hex size
5185case "$MPI_SIZEOF_AINT" in
5186    4)    len_mpi_aint=04 ;;
5187    8)    len_mpi_aint=08 ;;
5188    16)   len_mpi_aint=10 ;;
5189    *)    AC_MSG_ERROR([Unable to convert MPI_SIZEOF_AINT to a hex string.  This is either because we are building on a very strange platform or there is a bug somewhere in configure.]) ;;
5190esac
5191# MPI_AINT and MPI_OFFSET are already taken, appending a _DATATYPE suffix
5192MPI_AINT_DATATYPE=0x4c00${len_mpi_aint}43
5193AC_SUBST(MPI_AINT_DATATYPE)
5194export MPI_AINT_DATATYPE
5195
5196# 0x4c000043 is 1275068483 in decimal, add ($MPI_SIZEOF_AINT * 256) and you get
5197# the decimal equivalent of the hex number
5198MPI_F77_AINT=`expr 1275068483 '+' '(' 256 '*' $MPI_SIZEOF_AINT ')'`
5199AC_SUBST(MPI_F77_AINT)
5200export MPI_F77_AINT
5201# ----------------------------------------------------------------------------
5202
5203# define MPIU_Size_t - used to express the size of objects
5204# This is used in src/include/mpitypedefs.h to define MPIU_SIZE_T,
5205# and is used in various parts of ch3 and mpid/common/sock.
5206# This is used to handle the potential problem that a message is
5207# too long to fit with an int.  However, we may still need to make
5208# some more adjustments in the code (this may not be used everywhere
5209# that it is needed).
5210#
5211# FIXME: this should really be in a util configure file, but we don't
5212# have one at the moment
5213#
5214MPIU_SIZE_T="unsigned $MPI_AINT"
5215AC_DEFINE_UNQUOTED(MPIU_SIZE_T,$MPIU_SIZE_T,[Set to a type that can express the size of the entire address space])
5216
5217if test "$ac_cv_sizeof_void_p" -lt "$aint_size" ; then
5218    AC_DEFINE(USE_AINT_FOR_ATTRVAL,1,[Define if MPI_Aint should be used instead of void * for storing attribute values])
5219fi
5220#
5221# See if we need to update the timer type (which was converted to uppercase)
5222if test "$timer_type" = "DEVICE" ; then
5223    # The device selected should export the datatype for the timer
5224    # in MPID_DEVICE_TIMER_TYPE if something other than long is needed
5225    if test -n "$MPID_DEVICE_TIMER_TYPE" ; then
5226       MPID_TIMER_TYPE=$MPID_DEVICE_TIMER_TYPE
5227    fi
5228fi
5229
5230dnl Configure any subdirectories.  Note that config.status will *not*
5231dnl reexecute these!
5232dnl Export any important variables first:
5233dnl
5234dnl Gastly problem.  CONFIG_SUBDIRS only adds the directories to the
5235dnl list of directories to be configured.  It does NOT control the
5236dnl timing of the configuration.  For that, we must do something different.
5237dnl Our original solution was to use a separate macro that does cause
5238dnl immediate configure; this macro made use of the code that autoconf
5239dnl uses to handle the subdir configure.  However, later versions of
5240dnl autoconf did this in a way that caused problems, paritcularly with
5241dnl errors reported as inconsistent cache files.  Instead, we simply
5242dnl invoke the configure scripts (if present) directly.
5243export AR
5244export AR_FLAGS
5245export RANLIB
5246export MPILIBNAME
5247export PMPILIBNAME
5248export CC
5249export CPPFLAGS
5250export LIBS
5251export CXX
5252export CXXFLAGS
5253export FFLAGS
5254export CFLAGS
5255export FCFLAGS
5256export LDFLAGS
5257# Make sure that any Fortran 77 and Fortran 90 compilers are exported to
5258# the subdir builds (in particular, ROMIO may try to use the Fortran 90
5259# compiler to determine the Fortran 90 KINDS for MPI_OFFSET_KIND).
5260export F77
5261export FC
5262#
5263# -----------------------------------------------------------------------------
5264# Configure threads first.  This is necessary to obtain all required
5265# definitions, flags, and libraries that the other subsystems will need
5266#
5267#
5268# -----------------------------------------------------------------------------
5269MPIU_THREAD_DEFAULT=${MPIU_THREAD_DEFAULT:-posix}
5270
5271AC_ARG_WITH([thread-package],
5272[  --with-thread-package=package     Thread package to use. Supported thread packages include:
5273        posix or pthreads - POSIX threads
5274        solaris - Solaris threads (Solaris OS only)
5275        win - windows threads
5276        none - no threads
5277
5278    If the option is not specified, the default package is
5279    ${MPIU_THREAD_DEFAULT}.  If the option is specified, but a package
5280    is not given, then the default is posix
5281],,with_thread_package=${MPIU_THREAD_DEFAULT})
5282
5283if test "$with_thread_package" = "yes" ; then
5284   with_thread_package=posix
5285fi
5286
5287MPICH2_THREAD_PACKAGE=none
5288MPIU_THREAD_PACKAGE_NAME=MPIU_THREAD_PACKAGE_INVALID
5289case $with_thread_package in
5290    posix|pthreads)
5291	with_thread_package=posix
5292	AC_CHECK_HEADERS(pthread.h)
5293
5294        # If pthreads library is found, just include it on the link line. We don't try
5295        # to test if the C compiler needs it or not, since the C++ or Fortran
5296        # compilers might need it even if the C compiler doesn't
5297        # (nvcc with gfortran, for example).
5298        #
5299        # OSF1 has __pthread_create but not pthread_create (because of
5300        # inconsistencies in the pthread spec).  Thus, we look for pthread_key_create
5301        AC_CHECK_LIB([pthread],[pthread_key_create],have_pthreads=yes)
5302	if test "$have_pthreads" = "yes" ; then
5303	   PAC_PREPEND_FLAG([-lpthread],[LIBS])
5304	fi
5305
5306        AC_CHECK_FUNCS(pthread_yield)
5307
5308        # this check should come after the AC_CHECK_LIB for -lpthread
5309        AC_CHECK_FUNC([pthread_key_create],[],[AC_MSG_ERROR([unable to find pthreads library])])
5310
5311	# Check for a routine that specify a routine to call on
5312	# thread exit.  We can use this to release memory that may
5313	# be allocated by the MPICH2 library in the thread.
5314	# A complication: pthread_cleanup_push may be a macro; in that
5315	# case, check_funcs will fail to find it.
5316	# Under OSX, pthread_cleanup_push and pop are macros that must
5317	# appear together in the same lexical scope, and hence are
5318	# really useless in libraries that may allocate data within
5319	# a user-managed thread.
5320	AC_CHECK_FUNCS(pthread_cleanup_push)
5321	if test "$ac_cv_func_pthread_cleanup_push" = "no" ; then
5322            AC_CACHE_CHECK([whether pthread_cleanup_push is available (may be a macro in pthread.h)],pac_cv_func_pthread_cleanup_push,[
5323	    AC_TRY_LINK([
5324#include <pthread.h>
5325void f1(void *a) { return; }],
5326[pthread_cleanup_push( f1, (void *)0 );],
5327            pac_cv_func_pthread_cleanup_push=yes,
5328            pac_cv_func_pthread_cleanup_push=no)])
5329            if test "$pac_cv_func_pthread_cleanup_push" = yes ; then
5330	        AC_DEFINE(HAVE_PTHREAD_CLEANUP_PUSH_MACRO,1,[Define if pthread_cleanup_push is available, even as a macro])
5331            fi
5332
5333        fi
5334	# Check for PTHREAD_MUTEX_RECURSIVE_NP and PTHREAD_MUTEX_RECURSIVE
5335	AC_CACHE_CHECK([whether pthread.h defines PTHREAD_MUTEX_RECURSIVE_NP],
5336	pac_cv_has_pthread_mutex_recursive_np,[
5337        AC_TRY_COMPILE([#include <pthread.h>],
5338                       [int a=PTHREAD_MUTEX_RECURSIVE_NP;],
5339		       pac_cv_has_pthread_mutex_recursive_np=yes,
5340		       pac_cv_has_pthread_mutex_recursive_np=no)])
5341	AC_CACHE_CHECK([whether pthread.h defines PTHREAD_MUTEX_RECURSIVE],
5342	pac_cv_has_pthread_mutex_recursive,[
5343        AC_TRY_COMPILE([#include <pthread.h>],
5344                       [int a=PTHREAD_MUTEX_RECURSIVE;],
5345		       pac_cv_has_pthread_mutex_recursive=yes,
5346		       pac_cv_has_pthread_mutex_recursive=no)])
5347        if test "$pac_cv_has_pthread_mutex_recursive_np" = yes ; then
5348	    AC_DEFINE(HAVE_PTHREAD_MUTEX_RECURSIVE_NP,1,[Define if PTHREAD_MUTEX_RECURSIVE_NP is available in pthread.h])
5349	fi
5350        if test "$pac_cv_has_pthread_mutex_recursive" = yes ; then
5351	    AC_DEFINE(HAVE_PTHREAD_MUTEX_RECURSIVE,1,[Define if PTHREAD_MUTEX_RECURSIVE is available in pthread.h])
5352	fi
5353
5354        # Check for PTHREAD_MUTEX_ERRORCHECK_NP and PTHREAD_MUTEX_ERRORCHECK
5355        AC_CACHE_CHECK([whether pthread.h defines PTHREAD_MUTEX_ERRORCHECK_NP],
5356        pac_cv_has_pthread_mutex_errorcheck_np,[
5357        AC_TRY_COMPILE([#include <pthread.h>],
5358                       [int a=PTHREAD_MUTEX_ERRORCHECK_NP;],
5359                       pac_cv_has_pthread_mutex_errorcheck_np=yes,
5360                       pac_cv_has_pthread_mutex_errorcheck_np=no)])
5361        AC_CACHE_CHECK([whether pthread.h defines PTHREAD_MUTEX_ERRORCHECK],
5362        pac_cv_has_pthread_mutex_errorcheck,[
5363        AC_TRY_COMPILE([#include <pthread.h>],
5364                       [int a=PTHREAD_MUTEX_ERRORCHECK;],
5365                       pac_cv_has_pthread_mutex_errorcheck=yes,
5366                       pac_cv_has_pthread_mutex_errorcheck=no)])
5367
5368        if test "$pac_cv_has_pthread_mutex_errorcheck" = yes ; then
5369            AC_DEFINE(PTHREAD_MUTEX_ERRORCHECK_VALUE,PTHREAD_MUTEX_ERRORCHECK,
5370                      [Define to an expression that will result in an error checking mutex type.])
5371        elif test "$pac_cv_has_pthread_mutex_errorcheck_np" = yes ; then
5372            AC_DEFINE(PTHREAD_MUTEX_ERRORCHECK_VALUE,PTHREAD_MUTEX_ERRORCHECK_NP,
5373                      [Define to an expression that will result in an error checking mutex type.])
5374        fi
5375
5376	PAC_FUNC_NEEDS_DECL([#include <pthread.h>],pthread_mutexattr_settype)
5377
5378	MPICH2_THREAD_PACKAGE=pthreads
5379        MPIU_THREAD_PACKAGE_NAME=MPIU_THREAD_PACKAGE_POSIX
5380	;;
5381    solaris)
5382	AC_CHECK_HEADERS(thread.h)
5383	AC_CHECK_FUNCS(thr_yield)
5384	AC_SEARCH_LIBS(thr_create,thread,found=yes,found=no)
5385	if test "$found" != "yes" ; then
5386	   AC_MSG_ERROR([unable to find Solaris threads library])
5387	fi
5388	# FIXME: need to add -mt if using solaris compilers
5389	MPICH2_THREAD_PACKAGE=solaris
5390        MPIU_THREAD_PACKAGE_NAME=MPIU_THREAD_PACKAGE_SOLARIS
5391	;;
5392    win|windows)
5393        with_thread_package=win
5394        MPICH2_THREAD_PACKAGE=win
5395        MPIU_THREAD_PACKAGE_NAME=MPIU_THREAD_PACKAGE_WIN
5396        AC_MSG_ERROR([The 'win' thread package is not supported via autoconf builds at this time.])
5397        ;;
5398    no|none)
5399	with_thread_package=none
5400        MPIU_THREAD_PACKAGE_NAME=MPIU_THREAD_PACKAGE_NONE
5401	;;
5402    *)
5403	AC_MSG_ERROR([The specified thread package, $with_thread_package, is not supported.])
5404	;;
5405esac
5406
5407# Define and export the selected thread library so that other packages,
5408# such as MPE, will know what's used in MPICH2
5409export MPICH2_THREAD_PACKAGE
5410AC_DEFINE_UNQUOTED([MPIU_THREAD_PACKAGE_NAME],[$MPIU_THREAD_PACKAGE_NAME],[set to the name of the thread package])
5411
5412# check for compiler-support for thread-local storage (MPIU_TLS_SPECIFIER)
5413AX_TLS
5414
5415AC_CHECK_FUNCS(getpid)
5416
5417# Choose a method to yield the procesor.
5418
5419# If the user specified a method to use, we check if it's available.
5420# If a method was not specified, we make a guess based on the OS.  The
5421# default is to use sched_yield() or yield() if one is available,
5422# otherwise, default to nothing.  After that we define the appropriate
5423# macro.
5424
5425AC_CHECK_HEADERS(sched.h)
5426AC_CHECK_HEADERS(unistd.h)
5427AC_CHECK_HEADERS(sys/select.h)
5428AC_CHECK_FUNCS(sched_yield yield usleep sleep select)
5429
5430if test "$ac_cv_func_usleep" = "yes" ; then
5431    PAC_FUNC_NEEDS_DECL([#include <unistd.h>],usleep)
5432fi
5433
5434AC_ARG_ENABLE([yield],
5435    [AS_HELP_STRING([--enable-yield], [choose a method to yield the processor in busy loops.  Available methods are: sched_yield, yield, select, usleep, sleep, nothing])],
5436    [AS_CASE([$enableval],
5437        [sched_yield], [AS_IF([test "x$ac_cv_func_sched_yield" != "xyes"], [enable_yield=unavail])],
5438        [yield],       [AS_IF([test "x$ac_cv_func_yield"       != "xyes"], [enable_yield=unavail])],
5439        [select],      [AS_IF([test "x$ac_cv_func_select"      != "xyes"], [enable_yield=unavail])],
5440        [usleep],      [AS_IF([test "x$ac_cv_func_usleep"      != "xyes"], [enable_yield=unavail])],
5441        [sleep],       [AS_IF([test "x$ac_cv_func_sleep"       != "xyes"], [enable_yield=unavail])],
5442        [nothing|no|none], [],
5443        [AC_MSG_ERROR([Invalid option $enableval for --enable-yield])])
5444
5445     AS_IF([test "x$enable_yield" = "xunavail"],
5446              [AC_MSG_ERROR([Yield method $enableval is not available on this platform.])])
5447    ],
5448    [# none specified by user; make a guess based on os
5449     AS_CASE([$host],
5450        [*-*-darwin*],
5451            [# In Lion, sched_yield worked but none of the other options had any effect
5452             AS_IF([test "x$ac_cv_func_sched_yield" = "xyes"], [enable_yield=sched_yield],
5453                   [enable_yield=nothing])],
5454        [*-*-linux*],
5455            [# sched_yield() has been broken in linux since 2.6.23, and no good alternative exists.
5456             enable_yield=nothing],
5457        [# default: just use sched_yield() or yield()
5458         AS_IF([test "x$ac_cv_func_sched_yield" = "xyes"], [enable_yield=sched_yield],
5459               [test "x$ac_cv_func_yield" = "xyes"], [enable_yield=yield],
5460               [enable_yield=nothing])])
5461    ]
5462)
5463
5464# set the appropriate macro
5465AS_CASE([$enable_yield],
5466    [sched_yield],
5467        [AC_DEFINE(USE_SCHED_YIELD_FOR_YIELD,1,[Define to use sched_yield to yield processor])],
5468    [yield],
5469        [AC_DEFINE(USE_YIELD_FOR_YIELD,1,[Define to use yield to yield processor])],
5470    [select],
5471        [AC_DEFINE(USE_SELECT_FOR_YIELD,1,[Define to use select to yield processor])],
5472    [usleep],
5473        [AC_DEFINE(USE_USLEEP_FOR_YIELD,1,[Define to use usleep to yield processor])],
5474    [sleep],
5475        [AC_DEFINE(USE_SLEEP_FOR_YIELD,1,[Define to use sleep to yield processor])],
5476    [nothing|no|none],
5477        [AC_DEFINE(USE_NOTHING_FOR_YIELD,1,[Define to use nothing to yield processor])],
5478    [AC_MSG_ERROR([Invalid value $enable_yield for enable_yield.])]
5479)
5480
5481# Check for the Linux functions for controlling processor affinity.
5482# LINUX: sched_setaffinity
5483# AIX:   bindprocessor
5484# OSX (Leopard): thread_policy_set
5485AC_CHECK_FUNCS(sched_setaffinity sched_getaffinity bindprocessor thread_policy_set)
5486if test "$ac_cv_func_sched_setaffinity" = "yes" ; then
5487    # Test for the cpu process set type
5488    AC_CACHE_CHECK([whether cpu_set_t available],pac_cv_have_cpu_set_t,[
5489    AC_TRY_COMPILE( [
5490#include <sched.h>],[ cpu_set_t t; ],pac_cv_have_cpu_set_t=yes,pac_cv_have_cpu_set_t=no)])
5491    if test "$pac_cv_have_cpu_set_t" = yes ; then
5492        AC_DEFINE(HAVE_CPU_SET_T,1,[Define if cpu_set_t is defined in sched.h])
5493
5494	AC_CACHE_CHECK([whether the CPU_SET and CPU_ZERO macros are defined],
5495	pac_cv_cpu_set_defined,[
5496        AC_TRY_LINK( [
5497#include <sched.h>],[ cpu_set_t t; CPU_ZERO(&t); CPU_SET(1,&t); ],
5498        pac_cv_cpu_set_defined=yes,pac_cv_cpu_set_defined=no)])
5499	if test "$pac_cv_cpu_set_defined" = "yes" ; then
5500	    AC_DEFINE(HAVE_CPU_SET_MACROS,1,[Define if CPU_SET and CPU_ZERO defined])
5501        fi
5502	# FIXME: Some versions of sched_setaffinity return ENOSYS (!),
5503	# so we should test for the unfriendly and useless behavior
5504    fi
5505fi
5506if test "$ac_cv_func_thread_policy_set" = yes ; then
5507    AC_CACHE_CHECK([whether thread affinity macros defined],
5508    pac_cv_have_thread_affinity_policy,[
5509    AC_TRY_COMPILE([#include <mach/thread_policy.h>],[
5510#if !defined(THREAD_AFFINITY_POLICY) || !defined(THREAD_AFFINITY_TAG_NULL)
5511    :'thread macros not defined
5512],pac_cv_have_thread_affinity_policy=yes,
5513  pac_cv_have_thread_affinity_policy=no)])
5514    if test "$pac_cv_have_thread_affinity_policy" = yes ; then
5515        AC_DEFINE(HAVE_OSX_THREAD_AFFINITY,1,[Define is the OSX thread affinity policy macros defined])
5516    fi
5517fi
5518
5519MPIU_THREAD_LIB_NAME=${MPILIBNAME}
5520AC_SUBST(MPIU_THREAD_LIB_NAME)
5521
5522# -----------------------------------------------------------------------------
5523# End of thread configure
5524# -----------------------------------------------------------------------------
5525
5526
5527# Checkpointing
5528AC_ARG_ENABLE(checkpointing,
5529    [AC_HELP_STRING([--enable-checkpointing], [Enable application checkpointing])],
5530    [ if test "$enableval" != "no" ; then
5531        PAC_SET_HEADER_LIB_PATH(blcr)
5532	PAC_CHECK_HEADER_LIB_FATAL(blcr, libcr.h, cr, cr_init)
5533        AC_DEFINE(ENABLE_CHECKPOINTING,1,[Application checkpointing enabled])
5534      fi ],
5535)
5536
5537# Update the cache first with the results of the previous configure steps
5538# We don't use the subdir cache because ensuring that the cache is consistant
5539# with the way in which configure wishes to use it is very difficult and
5540# too prone to error.
5541dnl PAC_SUBDIR_CACHE(always)
5542# -----------------------------------------------------------------------------
5543# experiment with creating a cache file
5544#if test "$CONF_USE_CACHEFILE" = yes ; then
5545#    basecachefile=`pwd`/cache.base
5546#    set | grep ac_cv > $basecachefile
5547#    # Tell other configures to load this file
5548#    echo "Creating and exporting the base cache file $basecachefile"
5549#    CONF_BASE_CACHEFILE=$basecachefile
5550#    export CONF_BASE_CACHEFILE
5551#fi
5552PAC_CREATE_BASE_CACHE
5553# -----------------------------------------------------------------------------
5554
5555#
5556# Configure the device second.  This way, any libraries or variables that
5557# it needs can be extracted before building the other subsystems (this is
5558# particularly important for the bindings, which may need to know the
5559# libraries in order to create the compilation scripts)
5560
5561user_specified_atomic_primitives=no
5562if test "$DEBUG_SUBDIR_CACHE" = yes ; then
5563    set -x
5564fi
5565
5566dnl "configure" the device here via subconfigure.m4 files
5567m4_map([PAC_SUBCFG_CONFIGURE_SUBSYS], [PAC_SUBCFG_MODULE_LIST])
5568
5569# now configure any actual recursively configures subsystems, such as ROMIO and
5570# hydra, or older components that haven't been updated to a subconfigure.m4 yet
5571for subsys in $devsubsystems $subsystems ; do
5572    PAC_CONFIG_SUBDIR([$subsys],[],[AC_MSG_ERROR([$subsys configure failed])])
5573done
5574if test "$DEBUG_SUBDIR_CACHE" = yes -a "$enable_echo" != yes ; then
5575    set +x
5576fi
5577dnl PAC_SUBDIR_CACHE_CLEANUP
5578
5579## The MPE configure requires MPI_LIBS, and that requires all of the LIBS
5580#MPI_LIBS="$MPI_LIBS $LIBS"
5581#
5582# Get any localdefs that the subsystems created. Use a guard in case
5583# the list is empty
5584#for dir in $subsystems /dev/null ; do
5585#    if test -f $dir/localdefs ; then
5586#        . $dir/localdefs
5587#    fi
5588#done
5589#
5590# Make subsystems available to makefiles.
5591# FIXME does the makefile actually need this?
5592subsystems="$devsubsystems $subsystems $bindingsubsystems"
5593AC_SUBST(subsystems)
5594
5595# Find the size of OPA_ptr_t. This step needs to come after the OPA
5596# configure above in order to get the size OPA_ptr_t evaluated for
5597# this platform.
5598AC_CHECK_SIZEOF(OPA_ptr_t,-1,[
5599#include "${master_top_srcdir}/src/openpa/src/opa_primitives.h"
5600pthread_mutex_t *OPA_emulation_lock;
5601])
5602
5603if test "$enable_f77" != "yes" ; then
5604    # These are Fortran datatypes ONLY.  Set to null if no Fortran compiler.
5605    for name in CHARACTER INTEGER REAL LOGICAL COMPLEX DOUBLE_PRECISION \
5606	2INTEGER 2REAL DOUBLE_COMPLEX 2COMPLEX 2DOUBLE_PRECISION \
5607	2DOUBLE_COMPLEX ; do
5608	fullname="MPI_$name"
5609	eval $fullname=MPI_DATATYPE_NULL
5610    done
5611    AC_MSG_WARN([Could not define Fortran MPI datatypes for C])
5612    AC_DEFINE(HAVE_NO_FORTRAN_MPI_TYPES_IN_C,1,[Define if the Fortran types are not available in C])
5613    # Temporary values for MPI_Fint (need help from the Fortran subsystem)
5614    MPI_FINT=int
5615fi
5616AC_SUBST(MPI_CHARACTER)
5617AC_SUBST(MPI_INTEGER)
5618AC_SUBST(MPI_REAL)
5619AC_SUBST(MPI_LOGICAL)
5620AC_SUBST(MPI_COMPLEX)
5621AC_SUBST(MPI_DOUBLE_PRECISION)
5622AC_SUBST(MPI_2INTEGER)
5623AC_SUBST(MPI_2REAL)
5624AC_SUBST(MPI_DOUBLE_COMPLEX)
5625AC_SUBST(MPI_2DOUBLE_PRECISION)
5626AC_SUBST(MPI_2COMPLEX)
5627AC_SUBST(MPI_2DOUBLE_COMPLEX)
5628AC_SUBST(MPI_FINT)
5629
5630# If ROMIO was successfully configured, then ROMIO will have exported the
5631# definition of MPI_OFFSET_TYPE through its localdefs file (created by the
5632# ROMIO configure in src/mpi/romio/localdefs).  If MPI_OFFSET_TYPE was not
5633# defined, this code attempts to find a good choice for MPI_OFFSET_TYPE
5634# (As the offset type is used for File operations, the specific type
5635# really doesn't matter if ROMIO doesn't provide it).
5636if test -n "$MPI_OFFSET_TYPE" ; then
5637    # We got the value from the ROMIO configure
5638    MPI_OFFSET="$MPI_OFFSET_TYPE"
5639    # Get and export the size of this type if possible
5640    if test -z "$MPI_SIZEOF_OFFSET" ; then
5641        # set a default
5642        AC_CACHE_CHECK([the sizeof MPI_Offset],ac_cv_sizeof_MPI_Offset,[
5643            ac_cv_sizeof_MPI_Offset=unknown
5644            AC_COMPUTE_INT([ac_cv_sizeof_MPI_Offset],[sizeof($MPI_OFFSET)],[],[
5645                AC_MSG_WARN([Unable to determine the size of MPI_Offset])
5646            ])
5647	])
5648	if test "$ac_cv_sizeof_MPI_Offset" != "unknown" ; then
5649  	    MPI_SIZEOF_OFFSET=$ac_cv_sizeof_MPI_Offset
5650        fi
5651    fi
5652    export MPI_SIZEOF_OFFSET
5653else
5654    # Make a guess at the appropriate definition for offset.  Try to
5655    # find a 64bit type.
5656    if test "$ac_cv_sizeof_long" = 8 ; then
5657        MPI_OFFSET="long"
5658	# Make the size of this type available to other configures
5659	MPI_SIZEOF_OFFSET=8
5660    elif test "$ac_cv_sizeof_long_long" = 8 ; then
5661        MPI_OFFSET="long long"
5662	# Make the size of this type available to other configures
5663	MPI_SIZEOF_OFFSET=8
5664    else
5665        MPI_OFFSET=long
5666        MPI_SIZEOF_OFFSET=$ac_cv_sizeof_long
5667    fi
5668    export MPI_SIZEOF_OFFSET
5669fi
5670AC_SUBST(MPI_OFFSET)
5671#
5672# FIXME: we need an explanation of why we need both MPI_OFFSET and
5673# MPI_OFFSET_TYPEDEF.   Why is MPI_OFFSET_TYPEDEF necessary?
5674# This appears to be used by the Windows "winconfigure.wsf" which is used
5675# to create a multiline definition using an #ifdef check on USE_GCC
5676# We may wish to use a different approach
5677MPI_OFFSET_TYPEDEF="typedef $MPI_OFFSET MPI_Offset;"
5678AC_SUBST(MPI_OFFSET_TYPEDEF)
5679#
5680# Fortran type for an Offset type (needed to define MPI_DISPLACEMENT_CURRENT
5681# The value for this comes from ROMIO, and is needed in mpif.h.in
5682# First, we check that this works with both Fortran compilers (if
5683# they are defined)
5684#
5685# If there is no FORTRAN_MPI_OFFSET type (because ROMIO is disabled),
5686# just use INTEGER
5687if test -z "$FORTRAN_MPI_OFFSET" ; then
5688    FORTRAN_MPI_OFFSET=INTEGER
5689fi
5690if test "$enable_f77" = yes -a "$enable_fc" = yes ; then
5691    AC_LANG_PUSH([Fortran 77])
5692    AC_MSG_CHECKING([whether the Fortran Offset type works with Fortran 77])
5693    AC_COMPILE_IFELSE([
5694        AC_LANG_PROGRAM([],[      $FORTRAN_MPI_OFFSET i])
5695    ],[has_f77_offsettype=yes],[has_f77_offsetype=no])
5696    AC_MSG_RESULT($has_f77_offsettype)
5697    AC_LANG_POP([Fortran 77])
5698
5699    AC_LANG_PUSH([Fortran])
5700    AC_MSG_CHECKING([whether the Fortran Offset type works with Fortran 90])
5701    AC_COMPILE_IFELSE([
5702        AC_LANG_PROGRAM([],[      $FORTRAN_MPI_OFFSET i])
5703    ],[has_fc_offsettype=yes],[has_fc_offsetype=no])
5704    AC_LANG_POP([Fortran])
5705    AC_MSG_RESULT($has_fc_offsettype)
5706
5707    if test "$has_f77_offsettype" != yes -o "$has_fc_offsettype" != yes ; then
5708        AC_MSG_WARN([mpif.h is not compatible with both $F77 $FFLAGS and $FC $FCFLAGS.  We recommend that you set both F77 and FC to the same compiler and reconfigure.])
5709    fi
5710fi
5711AC_SUBST(FORTRAN_MPI_OFFSET)
5712#
5713
5714# ----------------------------------------------------------------------------
5715# MPI_OFFSET datatype
5716# ----------------------------------------------------------------------------
5717# must be done after ROMIO configure step
5718case "$MPI_SIZEOF_OFFSET" in
5719    4)    len_mpi_offset=04 ;;
5720    8)    len_mpi_offset=08 ;;
5721    16)   len_mpi_offset=10 ;;
5722    *)    AC_MSG_ERROR([Unable to convert MPI_SIZEOF_OFFSET to a hex string.  This is either because we are building on a very strange platform or there is a bug somewhere in configure.]) ;;
5723esac
5724MPI_OFFSET_DATATYPE=0x4c00${len_mpi_offset}44
5725AC_SUBST(MPI_OFFSET_DATATYPE)
5726export MPI_OFFSET_DATATYPE
5727
5728# 0x4c000044 is 1275068484 in decimal, add ($MPI_SIZEOF_OFFSET * 256) and you get
5729# the decimal equivalent of the hex number
5730MPI_F77_OFFSET=`expr 1275068484 '+' '(' 256 '*' $MPI_SIZEOF_OFFSET ')'`
5731AC_SUBST(MPI_F77_OFFSET)
5732export MPI_F77_OFFSET
5733# ----------------------------------------------------------------------------
5734
5735dnl Extra status information, from device subsystem, to be included in the
5736dnl declaration of MPI_Status in mpi.h.in
5737AC_SUBST(EXTRA_STATUS_DECL)
5738
5739dnl FIXME XXX DJG does this need to actually be conditional on something?
5740dnl previously it was conditional on the successful execution of
5741dnl "src/binding/f90/configure" but that would only fail if FC couldn't be
5742dnl determined or a bad VPATH build env was detected
5743AC_DEFINE(HAVE_FC_TYPE_ROUTINES,1,[Define if Fortran 90 type routines available])
5744
5745# -----------------------------------------------------------------------------
5746# Get the value of MPI_MAX_PROCESSOR_NAME
5747if test -z "$MPID_MAX_PROCESSOR_NAME" ; then
5748    if test -z "$MPI_MAX_PROCESSOR_NAME" ; then
5749       MPI_MAX_PROCESSOR_NAME=128
5750    fi
5751    AC_MSG_WARN([The $with_device device did not set the maximum size of a processor name, $MPI_MAX_PROCESSOR_NAME being used.])
5752else
5753    MPI_MAX_PROCESSOR_NAME=$MPID_MAX_PROCESSOR_NAME
5754fi
5755AC_SUBST(MPI_MAX_PROCESSOR_NAME)
5756
5757# Get the value of MPI_MAX_ERROR_STRING
5758if test -z "$MPID_MAX_ERROR_STRING" ; then
5759    if test -z "$MPI_MAX_ERROR_STRING" ; then
5760       MPI_MAX_ERROR_STRING=1024
5761    fi
5762    AC_MSG_WARN([The $with_device device did not set the maximum size of an error string, $MPI_MAX_ERROR_STRING being used.])
5763else
5764    MPI_MAX_ERROR_STRING=$MPID_MAX_ERROR_STRING
5765fi
5766AC_SUBST(MPI_MAX_ERROR_STRING)
5767
5768# Get the value of libtool_static_flag
5769if test ! -z "$MPID_LIBTOOL_STATIC_FLAG" ; then
5770   mpich_libtool_static_flag="$MPID_LIBTOOL_STATIC_FLAG"
5771else
5772   mpich_libtool_static_flag="-static"
5773fi
5774AC_SUBST([mpich_libtool_static_flag])
5775
5776# Add a definition that is used to help support Windows DLLs (used in mpi.h.in)
5777MPIU_DLL_SPEC_DEF="#define MPIU_DLL_SPEC"
5778AC_SUBST(MPIU_DLL_SPEC_DEF)
5779
5780dnl We can include external packages at configure/build time by
5781dnl adding them to EXTERNAL_SRC_DIRS.
5782AC_SUBST(EXTERNAL_SRC_DIRS)
5783
5784dnl We can configure the test directory after the rest of the configure
5785dnl steps because it does not depend on them.
5786# set and export values that the test/mpi configure will reference to ensure
5787# that the correct decisions are made since this configure happens before the
5788# MPICH2 library is built.
5789MPICH2_ENABLE_CXX=$enable_cxx
5790MPICH2_ENABLE_F77=$enable_f77
5791MPICH2_ENABLE_FC=$enable_fc
5792export MPICH2_ENABLE_CXX
5793export MPICH2_ENABLE_F77
5794export MPICH2_ENABLE_FC
5795AM_CONDITIONAL([BUILD_CXX_LIB],[test "$enable_cxx" = "yes"])
5796AM_CONDITIONAL([BUILD_F77_BINDING],[test "$enable_f77" = "yes"])
5797dnl FIXME DJG this has been moved to the f90 bindings subconfigure.m4 for now
5798dnl AM_CONDITIONAL([BUILD_F90_LIB],[test "$enable_fc" = "yes"])
5799# MPI_SRCDIR gives the test/mpi configure the location of the source
5800# files for an MPI implementation
5801if test -n "$ac_abs_srcdir" ; then
5802    MPI_SRCDIR=$ac_abs_srcdir
5803fi
5804# Pass these two values with "MPI" names to the test configure
5805MPI_NO_SPAWN=$MPID_NO_SPAWN
5806export MPI_NO_SPAWN
5807MPI_NO_RMA=$MPID_NO_RMA
5808export MPI_NO_RMA
5809
5810AC_CONFIG_SUBDIRS([test/mpi])
5811dnl
5812dnl Generate the Makefiles from Makefile.in
5813dnl Also generate mpi.h from mpi.h.in so that we can eliminate all ifdefs
5814dnl from the file.
5815dnl
5816dnl Run a setup command for any external modules (normally, this is empty)
5817dnl Pass a subset of the environment to the invoked process.
5818AC_OUTPUT_COMMANDS([
5819for prog in $EXTERNAL_SETUPS - ; do
5820    if test "$prog" != "-" ; then
5821      dir=`dirname $prog`
5822      name=`basename $prog`
5823      (cd $dir && ./$name)
5824    fi
5825done],[
5826EXTERNAL_SETUPS="$EXTERNAL_SETUPS"
5827LIBDIR="$libbuild_dir"
5828MPILIBNAME="$MPILIBNAME"
5829PMPILIBNAME="$PMPILIBNAME"
5830AR="$AR"
5831CC="$CC"
5832CPPFLAGS="$CPPFLAGS"
5833CFLAGS="$CFLAGS"
5834export LIBDIR ; export MPILIBNAME ; export AR ; export CC ; export CPPFLAGS
5835export PMPILIBNAME
5836export CFLAGS
5837# For test/mpi/configure
5838MPI_SRCDIR=$MPI_SRCDIR
5839MPI_NO_SPAWN=$MPID_NO_SPAWN
5840export MPI_SRCDIR
5841export MPI_NO_SPAWN
5842])
5843
5844if test -z "$includebuild_dir" ; then
5845    includebuild_dir=`pwd`/src/include
5846fi
5847if test -z "$libbuild_dir" ; then
5848    libbuild_dir=`pwd`/lib
5849fi
5850if test -z "$modincbuild_dir" ; then
5851    # The include files may be in a different directory from the mpif.h file
5852    modincbuild_dir=`pwd`/src/binding/f90
5853fi
5854
5855dnl
5856dnl If we rerun configure, place a file in the lib directory with the
5857dnl date.  We can use this to avoid rebuilding the library when
5858dnl a build aborts due to an error (this is intended to help developers)
5859AC_OUTPUT_COMMANDS([if [ ! -d lib ] ; then mkdir lib ; fi
5860date > lib/newconfig])
5861
5862AC_OUTPUT_COMMANDS([chmod a+x src/util/dbg/getfuncstack])
5863
5864AC_OUTPUT_COMMANDS([chmod a+x test/commands/cmdtests])
5865
5866
5867# For the examples, we want to use the scripts to encourage users
5868# to use them and to make them work more robustly with shared libraries
5869# and, for Fortran 90, any special Fortran 90 module features.
5870if test -z "$MPICC" ; then MPICC='$(bindir)/mpicc' ; fi
5871if test -z "$MPIF77" ; then MPIF77='$(bindir)/mpif77' ; fi
5872if test -z "$MPIFC" ; then MPIFC='$(bindir)/mpif90' ; fi
5873if test -z "$MPICXX" ; then MPICXX='$(bindir)/mpicxx' ; fi
5874AC_SUBST(MPICC)
5875AC_SUBST(MPICXX)
5876AC_SUBST(MPIF77)
5877AC_SUBST(MPIFC)
5878
5879AC_DEFINE(HAVE_MPICHCONF,1,[Define so that we can test whether the mpichconf.h file has been included])
5880
5881# Add the LDFLAGS/LIBS we got so far to WRAPPERs
5882WRAPPER_LDFLAGS="$WRAPPER_LDFLAGS $LDFLAGS"
5883WRAPPER_LIBS="$WRAPPER_LIBS $LIBS"
5884
5885if test "$USE_PMI2_API" = "yes" ; then
5886   AC_DEFINE(USE_PMI2_API, 1, [Define if PMI2 API must be used])
5887fi
5888
5889########################################################################
5890
5891# cause libtool script to be built now so that we can use it to test one last
5892# linking issue on Darwin
5893LT_OUTPUT
5894
5895# see ticket #1590 for some more background on these Darwin linking issues
5896if test "X$enable_shared" = "Xyes" ; then
5897    AS_CASE([$host],
5898        [*-*-darwin*],
5899        [
5900        # sanity check that -Wl,-flat_namespace works on darwin, unless the user
5901        # asked us not to add it
5902        if test "X$enable_two_level_namespace" = "Xno"; then
5903            # TODO, move this into a PAC macro with real autoconf caching
5904            pac_cv_wl_flat_namespace_works=no
5905            AC_MSG_CHECKING([if the C compiler accepts -Wl,-flat_namespace])
5906            PAC_PUSH_FLAG([LDFLAGS])
5907            PAC_APPEND_FLAG([-Wl,-flat_namespace],[LDFLAGS])
5908            AC_LINK_IFELSE([AC_LANG_PROGRAM([],[int i;])],
5909                           [AC_MSG_RESULT([yes])
5910                            pac_cv_wl_flat_namespace_works=yes],
5911                           [AC_MSG_RESULT([no])])
5912            PAC_POP_FLAG([LDFLAGS])
5913
5914            # Technically we may not be able to use the same form of the argument
5915            # for all four compilers (CC/CXX/F77/FC).  But we only think this is
5916            # necessary for Darwin for now, so this unconditional, single-var
5917            # approximation will work for now.
5918            if test "X$pac_cv_wl_flat_namespace_works" = "Xyes" ; then
5919                PAC_APPEND_FLAG([-Wl,-flat_namespace], [LDFLAGS])
5920                PAC_APPEND_FLAG([-Wl,-flat_namespace], [WRAPPER_LDFLAGS])
5921            fi
5922        fi
5923
5924        # We only need to bother with -Wl,-commons,-use_dylibs if we are
5925        # building fortran bindings (no common block usage in our C libs).
5926        if test "X$enable_f77" = "Xyes" ; then
5927            # We also don't need this argument if flat_namespace is used.
5928            if test "X$enable_two_level_namespace" != "Xno" ; then
5929                # TODO, move this into a PAC macro with real autoconf caching
5930                pac_cv_wl_commons_use_dylibs_works=no
5931                AC_MSG_CHECKING([if the F77 compiler accepts -Wl,-commons,use_dylibs])
5932                AC_LANG_PUSH([Fortran 77])
5933                PAC_PUSH_FLAG([LDFLAGS])
5934                PAC_APPEND_FLAG([-Wl,-commons,use_dylibs], [LDFLAGS])
5935                AC_LINK_IFELSE([AC_LANG_PROGRAM([],[      INTEGER i])],
5936                               [AC_MSG_RESULT([yes])
5937                                pac_cv_wl_commons_use_dylibs_works=yes],
5938                               [AC_MSG_RESULT([no])])
5939                PAC_POP_FLAG([LDFLAGS])
5940                AC_LANG_POP([Fortran 77])
5941
5942                # Add the flag to the WRAPPER_LDFLAGS, since this common block issue
5943                # is really only a problem for dynamically linked user programs.
5944                #
5945                # Technically we may not be able to use the same form of the argument
5946                # for all four compilers (CC/CXX/F77/FC).  But we only think this is
5947                # necessary for Darwin for now, so this unconditional, single-var
5948                # approximation will work for now.
5949                if test "X$pac_cv_wl_commons_use_dylibs_works" = "Xyes" ; then
5950                    PAC_APPEND_FLAG([-Wl,-commons,use_dylibs], [WRAPPER_LDFLAGS])
5951                fi
5952            fi
5953        fi
5954        ]
5955    )
5956fi
5957
5958########################################################################
5959
5960dnl This includes an experimental pkgconfig file for ch3 in the src/pkgconfig
5961dnl directory
5962AC_OUTPUT(Makefile \
5963          examples/Makefile \
5964          test/Makefile \
5965          test/commands/Makefile \
5966          src/include/mpich2info.h \
5967	  mpich2-doxygen \
5968          src/include/glue_romio.h \
5969          src/include/mpichtimer.h \
5970          src/binding/cxx/mpicxx.h \
5971	  src/binding/f77/mpif.h \
5972	  src/binding/f77/setbotf.f \
5973	  src/binding/f77/setbot.c \
5974	  src/binding/f90/mpi_sizeofs.f90 \
5975	  src/binding/f90/mpi_base.f90 \
5976	  src/packaging/pkgconfig/mpich2.pc \
5977	  src/packaging/envmods/mpich2.module \
5978          src/env/mpixxx_opts.conf \
5979          src/env/mpicc.sh \
5980	  src/env/mpicc.conf \
5981	  src/env/mpicc.bash \
5982          src/env/mpicxx.sh \
5983	  src/env/mpicxx.conf \
5984	  src/env/mpicxx.bash \
5985	  src/env/mpif77.sh \
5986	  src/env/mpif77.conf \
5987	  src/env/mpif77.bash \
5988	  src/env/mpif90.sh \
5989	  src/env/mpif90.conf \
5990	  src/env/mpif90.bash \
5991          src/env/parkill \
5992	  src/util/dbg/getfuncstack \
5993          src/include/mpi.h \
5994          doc/design/Makefile \
5995          doc/installguide/Makefile \
5996          doc/logging/Makefile \
5997          doc/refman/Makefile \
5998          doc/smpd/Makefile \
5999          doc/userguide/Makefile \
6000          doc/windev/Makefile \
6001          test/commands/cmdtests)
6002
6003echo 'Configuration completed.'
6004