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