configure.in 238 KB
Newer Older
1
AC_PREREQ(2.63)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# 
# (C) 2006 by Argonne National Laboratory.
#     See COPYRIGHT in top-level directory.
#
dnl Process this file with autoconf to produce a configure script.
dnl
dnl aclocal_cache.m4, included by sowing/confdb/aclocal.m4, fixes 
dnl bugs in autoconf caching.
dnl
dnl This is a large configure script and it is important to keep it
dnl clearly organized.  In addition, this script must coordinate with 
dnl the other modules that can be used to construct MPICH2, such as
dnl the communication device and the process manager.  Each of these
dnl may have special features or limitations that other modules or
dnl this configure may need to take into account.  To handle this, there
dnl are xx major steps in this configure script:
dnl
dnl 1. Identify major modules and source any prerequisite scripts
dnl 2. Determine compiler characteristics 
dnl 3. Setup and configure the other modules
dnl 4. Determine MPI features and characteristics (such as datatype values)
dnl
dnl Each of these is described in more detail below.
dnl
dnl 1. Identify the modules (most are specified by 
dnl --with-<modulename>=instance,
dnl for example, --with-pm=mpd or --with-device=ch3:nemesis).
dnl For each module, source the file mpich2prereq if present (in the
dnl module's top-level directory).  This
dnl must be a bourne (sh) shell script; it can access any of the variables
dnl in the configure script.  In addition, there are a few variables that
dnl are defined and provided to allow the modules to communicate their 
dnl needs or limitations to the other modules.  These are:
dnl    MPID_MAX_THREAD_LEVEL - thread level supported by device.
dnl                            if unset, is MPI_THREAD_FUNNELED
dnl    MPID_NO_LONG_LONG     - if yes, the device does not support the 
dnl                            long long integer type
dnl    MPID_NO_LONG_DOUBLE   - if yes, the device does not support the
dnl                            long double type
dnl    MPID_PM_NAMESERVER    - if set, provides the name of the nameserver
dnl                            that the process manager supports.
dnl                            This name server will be used if the
dnl                            default name server is selected.
dnl    MPID_NO_PM            - If yes, the device does not require any
dnl                            PM implementation.  
dnl    MPID_NO_PMI           - If yes, the device does not require any 
dnl                            PMI implementation.
dnl    EXTRA_STATUS_DECL     - Any extra declarations that the device
dnl                            needs added to the definition of MPI_Status.
dnl    MPID_MAX_PROCESSOR_NAME - The maximum number of character in a processor
dnl                            name.  If not set, 128 will be used.
dnl    PMI_REQUIRES_READABLE_TOKENS - if yes, define the C-preprocessor
dnl                            value USE_HUMAN_READABLE_TOKENS, which is
dnl                            used in src/include/mpimem.h to define token
dnl                            separators used in src/util/mem/argstr.c
dnl    PM_REQUIRES_PMI       - if set, provides the name of the PMI 
dnl                            interface implementation.  If not set,
dnl                            the "simple" PMI implementation is used.
dnl                            A process manager that needs a particular
dnl                            process manager should check that this is
dnl                            not set to an incompatible value.
dnl    MPID_NO_SPAWN         - if yes, the device does not support the
dnl                            dynamic process routines (spawn, connect
dnl                            attach, join, plus port and publish 
dnl                            routines).  The major effect of this
dnl                            is to let the test codes know that
dnl                            spawn is not implemented.
dnl    MPID_NO_RMA           - if yes, the device does not support the
dnl                            MPI RMA routines (MPI_Win_create and 
dnl                            MPI_Put etc.).  The major effect of this
dnl                            is to let the test codes know that 
dnl                            RMA is not implemented.
dnl
dnl Note that the meanings of these variables are defined so that an 
dnl undefined value gives the default.  This makes it easy to expand
dnl the set of such variables, since only modules that need the new
dnl variable will need to be changed.
dnl
dnl 2. Determine compiler characteristics
dnl Here is where features of the compilers are determined, including
dnl support for shared libraries and sizes of the basic datatype types.
dnl
dnl 3. Setup and configure the other modules
dnl Before each module configure is executed, the script setup_<module>
dnl is run if present.  This is a bourne (sh) shell script and may
dnl access configure variables.  It should not make any changes to the
dnl compiler name or flags (e.g., do not add -D_XOPEN_SOURCE to CFLAGS here,
dnl because that may invalidate the determination of the compiler 
dnl characteristics in the prior step).
dnl
dnl 4. Determine MPI features
dnl    
dnl
dnl Special environment variables
dnl To let other scripts and in particular the configure in test/mpi
dnl know that they are being invoked from within the MPICH2 configure,
dnl the following environment variables are set and exported:
dnl    FROM_MPICH2
dnl    MPICH2_ENABLE_F77
dnl    MPICH2_ENABLE_F90
dnl    MPICH2_ENABLE_CXX
dnl
dnl The file name here refers to a file in the source being configured
dnl In later versions of autoconf, the binding of AC_INIT changed (!!!)
dnl The original version was AC_INIT(a source file)
dnl The later version is AC_INIT(package,version,[bug-report],[tarname])
dnl Here we use the original version
dnl AC_INIT(src/include/mpiimpl.h)
dnl
dnl Note that no executable statements are allowed (and any are silently 
dnl dropped) before AC_INIT.
dnl
dnl AC_INIT requires an explicit version number
dnl Args are package name, version, bug report, and tar file name
dnl All must be literals
dnl Note that AC_PACKAGE_STRING is not a command but must be defined(!)
dnl Unfortunately, setting the PACKAGE names is not compatible with
dnl AC_CONFIG_SUBDIRS, since the resulting values in the generated
dnl conf file will not be consistent.
dnl define([AC_PACKAGE_STRING],[MPICH2 1.0.6])
dnl AC_INIT(mpich2,1.0.6,mpich2-maint@mcs.anl.gov,mpich2-1.0.6)
dnl Use the oldstyle AC_INIT instead
124

125
AC_INIT(src/include/mpichconf.h.in)
126

127
128
129
130
CONFIGURE_ARGS_CLEAN=`echo $* | tr '"' ' '`
AC_SUBST(CONFIGURE_ARGS_CLEAN)

# Try to find the release date
131
132
133
134
135
136
137
if test -s "$srcdir/maint/ReleaseDate" ; then
    RELEASE_DATE="`cat $srcdir/maint/ReleaseDate`"
else
    RELEASE_DATE="Unknown, built on `date`"
fi
AC_SUBST(RELEASE_DATE)

138
139
# Try to find the version
if test -s "$srcdir/maint/Version" ; then
140
    MPICH2_VERSION="`cat $srcdir/maint/Version | grep ^MPICH2_VERSION: | cut -f2 -d' '`"
141
    export MPICH2_VERSION
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
else
    AC_MSG_ERROR([Version information not found. Configuration aborted.])
fi

# Produce a numeric version assuming the following format:
# Version: [MAJ].[MIN].[REV][EXT][EXT_NUMBER]
# Example: 1.0.7rc1 has
#          MAJ = 1
#          MIN = 0
#          REV = 7
#          EXT = rc
#          EXT_NUMBER = 1
#
# Converting to numeric version will convert EXT to a format number:
#          ALPHA (a) = 0
#          BETA (b)  = 1
#          RC (rc)   = 2
#          PATCH (p) = 3
# Regular releases are treated as patch 0
#
# Numeric version will have 1 digit for MAJ, 2 digits for MIN,
163
# 2 digits for REV, 1 digit for EXT and 2 digits for EXT_NUMBER.
164
changequote(<<,>>)
165
166
167
168
169
V1=`expr $MPICH2_VERSION : '\([0-9]*\)\.[0-9]*\.*[0-9]*[a-zA-Z]*[0-9]*'`
V2=`expr $MPICH2_VERSION : '[0-9]*\.\([0-9]*\)\.*[0-9]*[a-zA-Z]*[0-9]*'`
V3=`expr $MPICH2_VERSION : '[0-9]*\.[0-9]*\.*\([0-9]*\)[a-zA-Z]*[0-9]*'`
V4=`expr $MPICH2_VERSION : '[0-9]*\.[0-9]*\.*[0-9]*\([a-zA-Z]*\)[0-9]*'`
V5=`expr $MPICH2_VERSION : '[0-9]*\.[0-9]*\.*[0-9]*[a-zA-Z]*\([0-9]*\)'`
170
changequote([,])
171

172
if test "$V2" -le 9 ; then V2=0$V2 ; fi
173
if test "$V3" = "" ; then V3=0; fi
174
if test "$V3" -le 9 ; then V3=0$V3 ; fi
175
176
177
178
179
180
181
182
183
184
185
186
if test "$V4" = "a" ; then
    V4=0
elif test "$V4" = "b" ; then
    V4=1
elif test "$V4" = "rc" ; then
    V4=2
elif test "$V4" = "" ; then
    V4=3
    V5=0
elif test "$V4" = "p" ; then
    V4=3
fi
187
if test "$V5" -le 9 ; then V5=0$V5 ; fi
188

189
190
191
MPICH2_NUMVERSION=`expr $V1$V2$V3$V4$V5 + 0`
AC_SUBST(MPICH2_NUMVERSION)
AC_SUBST(MPICH2_VERSION)
192

193

194
195
196
197
198
# ABIVERSION is incremented when there are changes in the ABI.  This is 
# used to let a shared library describe how compatible it is with executables
# that were linked against it.  In our use, the version number is x:y, where
#  x changes when the ABI changes
#  y changes when major behavior of the routines, without changing the ABI;
199
200
#    reset y to one when x changes.  Following libtool's versioning scheme, 0 is
#    the lowest value for any of the fields of the ABIVERSION string.
201
202
203
# The ABIVERSION is not the same as the VERSION. It is used principly in the
# Makefile.sm to pass the ABIVERSION to the createshlib script.
# We use libtool-style version numbers (see --version-info in the 
204
205
# libtool manual)
ABIVERSION="`cat $srcdir/maint/Version | grep ^MPICH2_ABIVERSION: | cut -f2 -d' '`"
206
AC_SUBST(ABIVERSION)
207

208
# Print out the configure options
209
210
211
CONFIGURE_ARGUMENTS="$ac_configure_args"
AC_SUBST(CONFIGURE_ARGUMENTS)
if test -n "$ac_configure_args" ; then
212
    echo "Configuring MPICH2 version $MPICH2_VERSION with $ac_configure_args"
213
else 
214
    echo "Configuring MPICH2 version $MPICH2_VERSION"
215
fi
216

217
218
# Add the information on the system:
echo "Running on system: `uname -a`"
219

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
dnl Definitions will be placed in this file rather than in the DEFS variable
AC_CONFIG_HEADER(src/include/mpichconf.h)
AH_TOP([/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*  
 *  (C) 2001 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */
#ifndef MPICHCONF_H_INCLUDED
#define MPICHCONF_H_INCLUDED
])
AH_BOTTOM([#endif])

dnl Set the directory that contains support scripts such as install-sh and
dnl config.guess
AC_CONFIG_AUX_DIR(confdb)
235
236
237
238
239
240
241

# Set the FROM_MPICH2 variable to tell subconfigures that they are
# built from within MPICH2
FROM_MPICH2=yes
export FROM_MPICH2
AC_ARG_VAR(FROM_MPICH2, [internally set flag to tell subconfigures that they are built from within MPICH2])

242
243
244
245
246
# compute canonical system types
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
# TARGET not needed, MPICH2 isn't a compiler

247
248
249
# Save a copy of precious flags as USER_* before any of these flags
# are being modified by configure tests.
PAC_PREFIX_ALL_FLAGS(USER)
250
251

# WRAPPER_xFLAGS are used by mpicc and friends.
252
253
254
255
256
257
258
259
260
261
262
263
#
# WRAPPER_CFLAGS and other compile flags are used for compile options
# that are added by MPICH2, but should be used by applications (such
# as include paths).
#
# All libraries that are detected by MPICH2 as needed for some of its
# functionality (such as -lpthread) should be added to LIBS so
# autoconf link tests can use them. Libraries that are built by MPICH2
# at make time (and hence are not available for autoconf link tests to
# use), such as OPA and MPL, should be added to WRAPPER_LIBS. All
# libraries in LIBS are added to WRAPPER_LIBS as well, at the end of
# configure.
264
PAC_PREFIX_ALL_FLAGS(WRAPPER)
265
WRAPPER_CFLAGS="$CFLAGS $MPICH2_MPICC_FLAGS"
266
WRAPPER_CPPFLAGS="$CPPFLAGS $MPICH2_MPICPP_FLAGS"
267
268
269
WRAPPER_CXXFLAGS="$CXXFLAGS $MPICH2_MPICXX_FLAGS"
WRAPPER_FFLAGS="$FFLAGS $MPICH2_MPIF77_FLAGS"
WRAPPER_F90FLAGS="$F90FLAGS $MPICH2_MPIF90_FLAGS"
270
WRAPPER_LDFLAGS="$LDFLAGS $MPICH2_LDFLAGS"
271
WRAPPER_LIBS="$LIBS $MPICH2_LIBS"
272
273
274

# Add MPICH2LIB_* to the appropriate flags
AC_ARG_VAR(MPICH2LIB_CFLAGS, [extra CFLAGS used in building MPICH2 libraries])
275
AC_ARG_VAR(MPICH2LIB_CPPFLAGS, [extra CPPFLAGS used in building MPICH2 libraries])
276
277
278
279
AC_ARG_VAR(MPICH2LIB_CXXFLAGS, [extra CXXFLAGS used in building MPICH2 libraries])
AC_ARG_VAR(MPICH2LIB_FFLAGS, [extra FFLAGS used in building MPICH2 libraries])
AC_ARG_VAR(MPICH2LIB_F90FLAGS, [extra F90FLAGS used in building MPICH2 libraries])
AC_ARG_VAR(MPICH2LIB_LDFLAGS, [extra LDFLAGS used in building MPICH2 libraries])
280
AC_ARG_VAR(MPICH2LIB_LIBS, [extra LIBS used in building MPICH2 libraries])
281
CFLAGS="$CFLAGS $MPICH2LIB_CFLAGS"
282
CPPFLAGS="$CPPFLAGS $MPICH2LIB_CPPFLAGS"
283
284
285
286
CXXFLAGS="$CXXFLAGS $MPICH2LIB_CXXFLAGS"
FFLAGS="$FFLAGS $MPICH2LIB_FFLAGS"
F90FLAGS="$F90FLAGS $MPICH2LIB_F90FLAGS"
LDFLAGS="$LDFLAGS $MPICH2LIB_LDFLAGS"
287
LIBS="$LIBS $MPICH2LIB_LIBS"
288

289
# Enable better caching control
290
PAC_ARG_CACHING
291
292
293
294
295

# Set CFLAGS for enable strict if necessary.  Do this *first* because
# it may influence the output of the other tests
PAC_ARG_STRICT

296
297
298
299
300
301
302
303
304
AC_ARG_ENABLE(echo, 
[--enable-echo  - Turn on strong echoing. The default is enable=no.] ,set -x)
dnl
dnl
AC_ARG_ENABLE(coverage,
[--enable-coverage - Turn on coverage analysis using gcc and gcov],,
enable_coverage=no)
dnl
AC_ARG_ENABLE(dynamiclibs,
305
306
[--enable-dynamiclibs - Enable the use of dynamic libraries by the devices
                       that support them],,enable_dynamiclibs=no)
307
308
309
310
311
312
313
314
315
dnl
AC_ARG_ENABLE(error-checking,
[--enable-error-checking=level - Control the amount of error checking.  
    no        - no error checking
    runtime   - error checking controllable at runtime through environment 
                variables
    all       - error checking always enabled],,enable_error_checking=all)
dnl
AC_ARG_ENABLE(error-messages,
316
[--enable-error-messages=level - Control the amount of detail in error messages.
317
318
319
320
321
322
323
    all       - Maximum amount of information
    generic   - Only generic messages (no information about the specific
                instance)
    class     - One message per MPI error class
    none      - No messages],,enable_error_messages=all)
dnl
AC_ARG_ENABLE(timing,
324
325
326
[--enable-timing=level - Control the amount of timing information
                        collected by the MPICH implementation.
    none    - Collect no data (default)
327
    all     - Collect lots of data
328
329
    runtime - Runtime control of data collected]
  ,,enable_timing=default)
330
331
dnl
AC_ARG_ENABLE(g,
332
333
334
[--enable-g=option - Control the level of debugging support in the
                    MPICH implementation.  option is a list of comma
                    separated names including
335
336
    none     - No debugging
    handle   - Trace handle operations
Pavan Balaji's avatar
Pavan Balaji committed
337
    handlealloc - Trace handle allocations
338
339
340
    dbg      - Add compiler flag, -g, to all internal
               compiler flags, i.e. MPICH2LIB_CFLAGS, MPICH2LIB_CXXFLAGS,
               MPICH2LIB_FFLAGS, and MPICH2LIB_F90FLAGS.
341
    debug    - Synonym for dbg
342
    log      - Enable debug event logging
343
    mem      - Memory usage tracing
344
345
    meminit  - Preinitialize memory associated structures and unions to
               eliminate access warnings from programs like valgrind
346
    memarena - Check for overwrite errors in memory allocation arena
347
    mutex    - Enable error checking on pthread mutexes
348
349
350
    mutexnesting - Check for non-nesting of mutexes
    nesting  - Check for proper nesting values
    fine-grain-nesting - Perform a fine-grain nesting check on exit
351
352
    all      - All of the above choices],,enable_g=none)
dnl
353
354
355
dnl We may want to force MPI_Aint to be the same size as MPI_Offset, 
dnl particularly on 32 bit systems with large (64 bit) file systems.
AC_ARG_WITH(aint-size,
356
[--with-aint-size - Override the size of MPI_AINT (in bytes)],,with_aint_size=0)
357
358
dnl
dnl
359
360
361
362
363
364
365
366
dnl --enable-sharedlibs=kind is set with the PAC_ARG_SHAREDLIBS macro 
dnl
dnl AC_ARG_ENABLE(internat,
dnl [--enable-internat - Enable internationalization of messages.
dnl  Not yet supported])
dnl
dnl --enable-fast
AC_ARG_ENABLE(fast,
367
368
369
370
371
372
[--enable-fast=option - Control the level of fast execution in the
                       MPICH implementation.  option is a list of
                       comma separated names including
    defopt   - Default compiler optimization -O2 for all language bindings,
               i.e. --enable-fast=O2, when neither --enable-fast
               nor --disable-fast is specified. (default)
373
374
375
    O<n>     - Appends default optimization flags, -O<n>, to all internal
               compiler flags, i.e. MPICH2LIB_CFLAGS, MPICH2LIB_CXXFLAGS,
               MPICH2LIB_FFLAGS, and MPICH2LIB_F90FLAGS.
376
    nochkmsg - No error checking, i.e. --disable-error-checking
377
    notiming - No timing collection, i.e. --disable-timing.
378
    ndebug   - Appends -DNDEBUG to MPICH2LIB_CFLAGS.
379
    all|yes  - "defopt", "nochkmsg", "notiming" and "ndebug" are enabled
380
               when --enable-fast is specified without any option.
381
382
383
    none     - None of above options, i.e. --disable-fast.  Note that 
    	       --enable-strict will add the -O2 option even if
	       --enable-fast=none is given.
384
],,enable_fast=defopt)
385

386
AC_ARG_ENABLE(check-compiler-flags,
387
388
389
390
[--enable-check-compiler-flags -- enable the checks for all compiler
                                 options, xxxFLAGS, MPICH2_xxxFLAGS.
                                 Default is on.]
    ,,enable_check_compiler_flags=yes)
391

392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
dnl
dnl We enable f77 and f90 if we can find compilers for them.
dnl In addition, we check whether f77 and f90 can work together.
dnl
AC_ARG_ENABLE(f77,
[--enable-f77 - Enable Fortran 77 bindings],,
enable_f77=default; enable_f77_wasdefault=yes)
AC_ARG_ENABLE(f90,
[--enable-f90 - Enable Fortran 90 bindings],,enable_f90=default)
AC_ARG_ENABLE(cxx,
[--enable-cxx - Enable C++ bindings],,enable_cxx=default)
AC_ARG_ENABLE(romio,
[--enable-romio - Enable ROMIO MPI I/O implementation],
,enable_romio=yes)
dnl
AC_ARG_ENABLE(debuginfo,
[--enable-debuginfo - Enable support for debuggers],,enable_debuginfo=no)
409
410
411
412
413
414
415
416
417
418

AC_ARG_ENABLE(smpcoll,
	[--enable-smpcoll - Enable support for SMP/multi-core aware collectives],
	smpcoll=$enableval,
	smpcoll=yes)

if test $smpcoll = "yes" ; then
   AC_DEFINE(USE_SMP_COLLECTIVES,1,[define to enable SMP/multi-core aware collectives])
fi

419
420
421
422
dnl The environment variable MPICH_DEBUGLIBNAME may be used to override the
dnl default name of the library that the debugger will load to access the
dnl MPICH2 internal data structures.
dnl
423
AC_ARG_ENABLE(nmpi-as-mpi,
424
425
426
427
428
[--enable-nmpi-as-mpi - Use MPI rather than PMPI routines for MPI
                       routines, such as the collectives, that may be
                       implemented in terms of other MPI routines]
  ,,enable_nmpi_as_mpi=no)

429
430
431
432
433
434
435
436
437
438
439
dnl
dnl With options
dnl "default" is a special device that allows MPICH to choose one based on 
dnl the environment.
AC_ARG_WITH(device,
[--with-device=name - Specify the communication device for MPICH.],,
with_device=default)
dnl
AC_ARG_WITH(pmi, [--with-pmi=name - Specify the pmi interface for MPICH.],,
with_pmi=default)
dnl
440
AC_ARG_WITH(pm, 
441
442
443
444
[--with-pm=name - Specify the process manager for MPICH.  "no" or "none" are
                  valid values.  Multiple process managers may be specified as
                  long as they all use the same pmi interface by separating them
                  with colons.  The mpiexec for the first named process manager
445
446
447
                  will be installed.  Example: "--with-pm=hydra:mpd:gforker"
                  builds the three process managers hydra, mpd and gforker;
                  only the mpiexec from hydra is installed into the bin
448
                  directory.]
449
    ,,with_pm=default)
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
dnl
AC_ARG_WITH(logging,
[--with-logging=name - Specify the logging library for MPICH.],
[if test -z "$withval" ; then with_logging=rlog ; fi],
with_logging=none)
dnl 
dnl both --without-mpe and --disable-mpe are supported
dnl AC_ARG_ENABLE(mpe) is used only when --with(out)-mpe is not used.
AC_ARG_WITH(mpe,
[--with-mpe - Build the MPE (MPI Parallel Environment) routines],,
with_mpe=default)
if test "$with_mpe" = "default" ; then
    AC_ARG_ENABLE(mpe,
    [--enable-mpe - Build the MPE (MPI Parallel Environment) routines],
    with_mpe=$enableval,with_mpe=default)
fi
dnl
AC_ARG_ENABLE(threads,
[--enable-threads=level - Control the level of thread support in the 
469
470
471
472
473
474
475
                         MPICH implementation.  The following levels
                         are supported.
    default         - Choose thread level at runtime based on parameters 
                      passed to MPI_Init_thread (default)
    single          - No threads (MPI_THREAD_SINGLE)
    funneled        - Only the main thread calls MPI (MPI_THREAD_FUNNELED)
    serialized      - User serializes calls to MPI (MPI_THREAD_SERIALIZED)
476
    multiple        - Fully multi-threaded (MPI_THREAD_MULTIPLE). DO NOT
477
478
479
                      select this option. The default option is more
                      efficient and also supports thread_multiple.

480
481
    See also the --enable-thread-cs option for controlling the granularity of
    the concurrency inside of the library.
482
483
484
485
486
487
488
489
490
491
492

    For the ch3:sock and ch3:nemesis channels, a separate build is no
    longer needed for thread-multiple.  It is compiled by default and
    is selectable at run time with MPI_Init_thread.  If
    MPI_Init_thread is not called, the default is funneled.  For
    other channels, the --enable-threads option is not supported
    currently, and the default is funneled.]
    ,
    , 
    enable_threads=default)

493
dnl
494
AC_ARG_ENABLE(thread-cs,
495
496
497
[--enable-thread-cs=type - Choose the method used for critical
                          sections and other atomic updates when
                          multiple threads are present.  Values may
498
                          be global (default), per-object, lock-free]
499
500
 , , enable_thread_cs=global)

501
AC_ARG_ENABLE(refcount,
502
503
504
505
506
[--enable-refcount=type - Choose the method for ensuring atomic
                         updates to the reference counts for MPI
                         objects.  Values may be lock, lock-free,
                         none.  The default depends on the thread-cs
                         choice; for global it is none (because none
507
508
                         is required), for per-object it is lock, and for
                         lock-free it is lock-free]
509
510
511
512
513
514
    ,,enable_refcount=default)

AC_ARG_ENABLE(mutex-timing, [--enable-mutex-timing - calculate the time spent waiting on mutexes.],
    AC_DEFINE(MPIU_MUTEX_WAIT_TIME,1,[Define to enable timing mutexes])
 )

515
AC_ARG_ENABLE(handle-allocation,
516
517
518
519
520
521
[--enable-handle-allocation=type - Choose the method used for
                                  allocating MPI object handles.
                                  Values may be 'tls' for thread-local
                                  storage or 'mutex' for simple
                                  locking.  'mutex' is the default.]
    ,, enable_handle_allocation=default)
522

523
524
525
526
527
528
529
AC_ARG_ENABLE([predefined-refcount],
              [AS_HELP_STRING([--enable-predefined-refcount],
                              [control whether predefined objects like MPI_COMM_WORLD are
                               reference counted (default depends on --enable-thread-cs choice)])],
              [],
              [enable_predefined_refcount=default])

530
531
532
533
534
535
536
537
538
539
dnl 
dnl
AC_ARG_ENABLE(weak-symbols,
[--enable-weak-symbols - Use weak symbols to implement PMPI routines (default)],,
enable_weak_symbols=yes)
dnl
dnl
dnl
AC_ARG_WITH(cross,
[--with-cross=file - Specify the values of variables that configure cannot
540
541
                    determine in a cross-compilation environment]
    ,,with_cross=no)
542
543
544
545
546
547
548
549
dnl
AC_ARG_WITH(namepublisher,
[--with-namepublisher=name - Choose the system that will support 
                             MPI_PUBLISH_NAME and MPI_LOOKUP_NAME.  Options
                             include
                               no (no service available)
                               mpd
			       file[:directory] (optional directory)
550
                               pmi
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
			       ],,
with_namepublisher=default)
dnl
dnl AC_ARG_WITH(cxxlibname,
dnl [--with-cxxlibname=name  - Specify name of library containing C++ interface
dnl routines],[MPICXXLIBNAME=$withval;set_MPICXXLIBNAME="yes"],MPICXXLIBNAME=)

dnl flibname complicates the handling of MPIR_F_TRUE and MPIR_F_FALSE, 
dnl particularly when using IBM/MS-style shared libraries.  Withdraw this
dnl option and see if anyone misses it.
dnl
dnl AC_ARG_WITH(flibname,
dnl [--with-flibname=name  - Specify name of library containing Fortran interface
dnl routines],[MPIFLIBNAME=$withval;set_MPIFLIBNAME="yes"],MPIFLIBNAME=)
AC_SUBST(MPIFLIBNAME)
AC_SUBST(PMPIFLIBNAME)
dnl
dnl The default is a special wrapper library
AC_ARG_WITH(fwrapname,
570
571
572
[--with-fwrapname=name - Specify name of library containing Fortran interface
                        routines]
    ,[FWRAPNAME=$withval;set_FWRAPNAME="yes"],FWRAPNAME=fmpich)
573
AC_SUBST(FWRAPNAME)
574

575

576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
# -----------------------------------------------------------------------------
# First check that we have a clean build if we are doing a VPATH build
PAC_VPATH_CHECK(src/include/mpi.h src/env/mpicc src/env/mpicc.conf,lib)

# ----------------------------------------------------------------------------
# This test is complicated by the fact that top_srcdir is not set until
# the very end of configure.  Instead, we get it ourselves
if test -z "$top_srcdir" ; then
   use_top_srcdir=$srcdir   
else
   use_top_srcdir=$top_srcdir
fi
if test -z "$master_top_srcdir" ; then 
    # This needs to be an absolute pathname
    case "$use_top_srcdir" in
    /*) ;;
    *)
        use_top_srcdir=`(cd $use_top_srcdir && pwd)`
	;;	
    esac
    master_top_srcdir=$use_top_srcdir
fi
# Get the directory that we're running in...
if test -z "$master_top_builddir" ; then
   master_top_builddir="`pwd`"
fi
AC_SUBST(master_top_builddir)
AC_SUBST(master_top_srcdir)
export master_top_builddir
export master_top_srcdir
# ----------------------------------------------------------------------------
# We create this file to allow other configures to find the "master" 
# top builddir
rm -f .mpich2
date > .mpich2
# ----------------------------------------------------------------------------
# with-device
if test "$with_device" = "default" ; then
    # Pick the device.  For now, always choose ch3
    with_device=ch3
fi
# Extract the device name from any options
# Allow the device to specify a directory; if no directory, use the
# included directories
# 
DEVICE=$with_device
AC_SUBST(DEVICE)

device_name=`echo $with_device | sed -e 's/:.*$//'`
changequote(<<,>>)
device_args=`echo $with_device | sed -e 's/^[^:]*//' -e 's/^://'`
changequote([,])

devicedir=$use_top_srcdir/src/mpid/$device_name
devicereldir=src/mpid/$device_name
case "$device_name" in
     /*) 
     devicedir=$DEVICE
     # Get the name from the leaf
     device_name=`echo $device_name ~ sed -e 's%.*/%%'`
     # FIXME: should the devicereldir be different (perhaps not -
     # this allows use to build within our tree, even when other data
     # is outside of the tree)
     ;;
     *) 
     ;;
esac
export device_name
export device_args
export devicedir
# Make the device base name and args available to generated files
DEVICE_NAME=$device_name
AC_SUBST(DEVICE_NAME)
DEVICE_ARGS=$device_args
AC_SUBST(DEVICE_ARGS)
#
# Give the device an opportunity to include a header file in mpi.h.  The
# default value of INCLUDE_MPIDDEFS_H is set prior to the inclusion of the
# device's mpich2prereq script.  The device's script may override the value
# if needed.
INCLUDE_MPIDDEFS_H='/* ... no device specific definitions ... */'
AC_SUBST(INCLUDE_MPIDDEFS_H)

#
# See if the device wants to say something about the compilers (for example,
# the globus device may need to do this)
if test -f $devicedir/mpich2prereq ; then
    . $devicedir/mpich2prereq
fi

# ----------------------------------------------------------------------------
# Set default library names if names haven't already been provided
MPILIBNAME=${MPILIBNAME:-"mpich"}
PMPILIBNAME_set=no
if test -n "$PMPILIBNAME" ; then 
   PMPILIBNAME_set=yes
fi
PMPILIBNAME=${PMPILIBNAME:-"p$MPILIBNAME"}
# Note that the name for this library may be updated after we check for 
# enable_shmem
# Fortran names are set later.
# We use a different library for the C++ wrappers to avoid problems when
# creating shared libraries
if test -z "$MPICXXLIBNAME" ; then MPICXXLIBNAME="${MPILIBNAME}cxx" ; fi
export MPIFLIBNAME
export PMPIFLIBNAME
export MPICXXLIBNAME
AC_SUBST(MPICXXLIBNAME)

# We'll set FORTRAN_BINDING to 1 if we support Fortran 
FORTRAN_BINDING=0

688
689
690
691
692
693
694
695
696
697
698
699
700
# Set up default compiler optimization
MPI_DEFAULT_COPTS="-O2"
MPI_DEFAULT_CXXOPTS="-O2"
MPI_DEFAULT_FOPTS="-O2"
MPI_DEFAULT_F90OPTS="-O2"

# enable-fast
# strip off multiple options, separated by commas
save_IFS="$IFS"
IFS=","
for option in $enable_fast ; do
    case "$option" in
        defopt)
701
        enable_default_optimize=yes
702
        ;;
703
704
705
706
707
        nochkmsg)
        enable_fast_nochkmsg=yes
        ;;
        notiming)
        enable_timing=no
708
709
710
711
        ;;
        ndebug)
        enable_append_ndebug=yes
        ;;
712
713
714
715
716
717
718
#
# [BRT] removed the reseting of enable_g so that --with-enable=dbg,meminit
# can be specified with -enable-fast.  This change was largely made for the
# PETSc folks who want to use --enable-fast to eliminate parameter checking
# overhead, but also wish to use meminit to eliminate initialization
# warnings from valgrind.
#
719
        all|yes)
720
721
722
723
        enable_default_optimize=yes
        enable_fast_nochkmsg=yes
        # Disable timing/logging stuffs
        enable_timing=no
724
725
726
        enable_append_ndebug=yes
        ;;
        O*)
727
        # Allows O<n> where <n> can be [0-9] or ' '.
728
729
        opt_flags=`echo $option | sed -e 's%\(O[0-9] \)%\1%g'`
        if test -n "$opt_flags" ; then
730
            enable_default_optimize=yes
731
732
733
734
735
736
737
738
            MPI_DEFAULT_COPTS="-$option"
            MPI_DEFAULT_CXXOPTS="-$option"
            MPI_DEFAULT_FOPTS="-$option"
            MPI_DEFAULT_F90OPTS="-$option"
        else
            AC_MSG_WARN([Unknown value $option for --enable-fast])
        fi
        ;;
739
        none|no)
740
741
742
743
        enable_default_optimize=no
        enable_fast_nochkmsg=no
        # Reset timing/logging stuffs to when --enable-timing isn't specified.
        enable_timing=default
744
745
746
747
748
749
750
751
752
        enable_append_ndebug=no
        ;;
        *)
        AC_MSG_WARN([Unknown value $option for --enable-fast])
        ;;
    esac
done
IFS="$save_IFS"

753
754
755
# ----------------------------------------------------------------------------
# Process any enable or with values
# We must do enable-fast first, because it changes the other enable values
756
if test "$enable_fast_nochkmsg" = "yes" ; then
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
    enable_error_checking=no
    # Export a variable that will allow the test suite to detect that
    # MPICH has no error testing
    MPICH_FAST=yes
    export MPICH_FAST
fi

# error-checking
case "$enable_error_checking" in 
    no)
    # if error checking has been diabled, then automatically diable the error
    # checking tests in the test suite
    ac_configure_args="${ac_configure_args} --disable-checkerrors"
    ;;
    all|yes|runtime)
    error_checking_kind=`echo $enable_error_checking | \
    tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
    error_checking_kind=MPID_ERROR_LEVEL_$error_checking_kind
    AC_DEFINE_UNQUOTED(HAVE_ERROR_CHECKING,$error_checking_kind,[Define to enable error checking])
    ;;
    *)
    AC_MSG_WARN([Unknown value $enable_error_checking for enable-error-checking])
    ;;
esac

# error-messages
case "$enable_error_messages" in 
    no|none)
        error_message_kind="MPICH_ERROR_MSG_NONE"
    ;;
    all|yes)
	error_message_kind="MPICH_ERROR_MSG_ALL"
    ;;
    generic)
	error_message_kind="MPICH_ERROR_MSG_GENERIC"
    ;;
    class)
	error_message_kind="MPICH_ERROR_MSG_CLASS"
    ;;
    *)
    AC_MSG_WARN([Unknown value $enable_error_messages for enable-error-messages])
    ;;
esac
AC_DEFINE_UNQUOTED(MPICH_ERROR_MSG_LEVEL,$error_message_kind,[define to enable error messages])

802
# ----------------------------------------------------------------------------
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
#
# enable-timing and with-logging
#
# Still to do: add subsets: e.g., class=pt2pt,class=coll.  See mpich2 doc
#
# Logging and timing are intertwined.  If you select logging, you
# may also need to select a timing level.  If no timing is selected 
# but logging with rlog is selected, make "all" the default timing level.
#
# FIXME: make timing and logging options work more cleanly together,
# particularly when other logging options are selected (e.g., logging is not
# rlog).
# ----------------------------------------------------------------------------
collect_stats=false
logging_required=false
if test "$enable_timing" = "default" ; then
    if test "$with_logging" = "rlog" ; then
        enable_timing=all
    fi
fi
timing_name=$enable_timing
case "$enable_timing" in
    no)
    timing_name=none
    ;;
    time)
    collect_stats=true
    ;;
    log|log_detailed)
    logging_required=true
    ;;
    yes)
    timing_name=all
    collect_stats=true
    logging_required=true
    ;;
    all|runtime)
    collect_stats=true
    logging_required=true
    ;;
    none|default)
    timing_name=none
    ;;
    *)
    AC_MSG_WARN([Unknown value $enable_timing for enable-timing])
    enable_timing=no
    timing_name=none
    ;; 
esac
#
# The default logging package is rlog; you can get it by 
# specifying --with-logging or --with-logging=rlog
#
case $with_logging in 
    yes)
    logging_name=rlog
    ;;
    no|none)
    logging_name=none
    ;;
    default)
    if test "$logging_required" = "true" ; then
        logging_name=rlog
    else
        logging_name=none
    fi
    ;;
    *)
    logging_name=$with_logging
    ;;
esac
# 
# Include the selected logging subsystem
#
# Choices:
# 1) A subdir of src/util/logging
#     This directory must contain a configure which will be executed
#     to build the 
# 2) An external directory
#     This directory must contain 
#          a mpilogging.h file
#     It may contain 
#          a setup_logging script
#          a configure
#     
#   
logging_subsystems=
if test "$logging_name" != "none" ; then
    # Check for an external name (directory containing a /)
    hasSlash=`echo A$logging_name | sed -e 's%[[^/]]%%g'`
    if test -n "$hasSlash" ; then
        # Check that the external logging system is complete.
	# Any failure will cause configure to abort
        if test ! -d $logging_name ; then
	    AC_MSG_ERROR([External logging directory $logging_name not found.  Configure aborted])
	    logging_name=none
        elif test ! -s $logging_name/mpilogging.h ; then
	    AC_MSG_ERROR([External logging header $logging_name/mpilogging.h not found.  Configure aborted])
	    logging_name=none
        fi

        logdir=$logging_name
	# Force the logdir to be absolute
	logdir=`cd $logdir && pwd`
	# Switch name to "external" because that is how the MPICH2
	# code will know it
	logging_name=external
	# Add the dir to the include paths
	#CPPFLAGS="$CPPFLAGS -I$logdir"
912
	CPPFLAGS="$CPPFLAGS -I$logdir"
913
914
915
916
917
918
919
	EXTERNAL_SRC_DIRS="$EXTERNAL_SRC_DIRS $logdir"
	# Add to the list of external modules to setup
	if test -x $logdir/setup_logging ; then
	     EXTERNAL_SETUPS="$EXTERNAL_SETUPS $logdir/setup_logging"
	fi
    else
        logdir=$srcdir/src/util/logging
920
921
        logreldir=src/util/logging/$logging_name
        logging_subsystems="$logging_subsystems $logreldir"
922
923
924
925
926
927
928
929
930
931
932
933
        logging_subdirs=$logging_name
        for dir in $logging_subdirs ; do
            if test ! -d $logdir/$dir ; then
	        AC_MSG_ERROR([$logdir/$dir does not exist.  Configure aborted])
	        logging_name=none
            fi
        done
        for dir in $logging_subsystems ; do
            if test ! -x $srcdir/$dir/configure ; then
	        AC_MSG_ERROR([$logdir/$dir has no configure (required).  Configure aborted])
	        logging_name=none
            fi
934
            other_install_dirs="${other_install_dirs} $logreldir"
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
        done
    fi
fi
#
# FIXME: Logging doesn't necessarily require timing (e.g., simply logging the 
# sequence of routines).  
if test "$logging_name" != "none" ; then
    if test "$enable_timing" != "no" ; then
	if test "$enable_timing" = "default" -o "$enable_timing" = "none" ; then
	    enable_timing=log
	    timing_name=log
    	fi
	logging_dir=logging
	subsystems="$subsystems $logging_subsystems"
    else
	AC_MSG_WARN([Timing was disabled.  Logging has been disabled as well.])
	with_logging=no
	logging_name=none
        logging_dir=
        logging_subdirs=
    fi
else
    if test "$logging_required" = "true" ; then
	AC_MSG_WARN([Timing was enabled with log option but no logging library is available.  Timing has been disabled.])
	enable_timing=no
	timing_name=none
    fi
    logging_dir=
    logging_subdirs=
fi
if test "$timing_name" != "none" ; then
    timing_kind=`echo $timing_name | \
       tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
    timing_kind=MPID_TIMING_KIND_$timing_kind
    AC_DEFINE_UNQUOTED(HAVE_TIMING,$timing_kind,[define to enable timing collection])
    if test "$collect_stats" = "true" ; then
        AC_DEFINE(COLLECT_STATS,1,[define to enable collection of statistics])
    fi
fi
#
AC_SUBST(logging_dir)
AC_SUBST(logging_name)
AC_SUBST(logging_subdirs)
use_logging_variable="MPID_LOGGING_`echo $logging_name | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
AC_DEFINE_UNQUOTED(USE_LOGGING,$use_logging_variable,[define to choose logging library])
# ----------------------------------------------------------------------------
# End of logging tests
# ----------------------------------------------------------------------------

# ----------------------------------------------------------------------------
# Check to see if the device does not support spawn.  
# FIXME: This should provide the option of not building the dynamic
# process routines.  It could also allow us to specialize support
# for all processes are members of MPI_COMM_WORLD (only one comm_world).
# ----------------------------------------------------------------------------
if test "$MPID_NO_SPAWN" = yes ; then
    AC_MSG_WARN([The device $with_device does not support MPI dynamic process routines])   
fi

994
# MPL
995
PAC_CONFIG_SUBDIR(src/mpl,,AC_ERROR(MPL configure failed))
996
PAC_PREPEND_FLAG([-lmpl], [WRAPPER_LIBS])
997
998
PAC_APPEND_FLAG([-I${master_top_builddir}/src/mpl/include], [CPPFLAGS])
PAC_APPEND_FLAG([-I${use_top_srcdir}/src/mpl/include], [CPPFLAGS])
999
1000
EXTERNAL_SRC_DIRS="$EXTERNAL_SRC_DIRS src/mpl"
other_install_dirs="$other_install_dirs src/mpl"
1001

1002
# OpenPA
1003
opadir="${use_top_srcdir}/src/openpa"
1004
if test -e "$opadir" ; then
1005
1006
    EXTERNAL_SRC_DIRS="$EXTERNAL_SRC_DIRS src/openpa"
    CPPFLAGS="$CPPFLAGS -I${use_top_srcdir}/src/openpa/src -I${master_top_builddir}/src/openpa/src"
1007

1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
    # OPA defaults to "auto", but in MPICH2 we want "auto_allow_emulation" to
    # easily permit using channels like ch3:sock that don't care about atomics
    AC_ARG_WITH([atomic-primitives],
                [AS_HELP_STRING([--with-atomic-primitives],
                                [Force OPA to use a specific atomic primitives
                                 implementation.  See the src/openpa directory
                                 for more info.])],
                [],[with_atomic_primitives=not_specified])
    opa_subdir_args=""
    if test "$with_atomic_primitives" = "not_specified" ; then
        opa_subdir_args="--with-atomic-primitives=auto_allow_emulation"
    fi
    PAC_CONFIG_SUBDIR_ARGS([src/openpa],[$opa_subdir_args],[],[AC_ERROR([OpenPA configure failed])])
1021
    PAC_PREPEND_FLAG([-lopa],[WRAPPER_LIBS])
1022
1023

    other_install_dirs="$other_install_dirs src/openpa"
1024
1025
fi

1026

1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
# ----------------------------------------------------------------------------
# Threads
# ----------------------------------------------------------------------------
#
# Threads must be supported by the device.  First, set the default to
# be the highest supported by the device
if test "$enable_threads" = default ; then
    if test -n "$MPID_MAX_THREAD_LEVEL" ; then
        case $MPID_MAX_THREAD_LEVEL in
            MPI_THREAD_SINGLE)     enable_threads=single ;;
            MPI_THREAD_FUNNELED)   enable_threads=funneled ;;
            MPI_THREAD_SERIALIZED) enable_threads=serialized ;;
            MPI_THREAD_MULTIPLE)   enable_threads=runtime ;;
            *) AC_MSG_ERROR([Unrecognized thread level from device $MPID_MAX_THREAD_LEVEL])
    	    ;;
        esac
    else
        enable_threads=single
    fi
fi

if test "$enable_threads" = "yes" ; then 
    enable_threads=multiple
elif test "$enable_threads" = "no" ; then
    enable_threads=single
elif test "$enable_threads" = "default"; then
    if test "$with_device" = "default" -o "$with_device" = "ch3:sock" ; then
        enable_threads=runtime
    fi
fi
# Runtime is an alias for multiple with an additional value
if test "$enable_threads" = "runtime" ; then
    AC_DEFINE(HAVE_RUNTIME_THREADCHECK,1,[Define if MPI supports MPI_THREAD_MULTIPLE with a runtime check for thread level])
    enable_threads=multiple
fi

MPICH_THREAD_LEVEL=MPI_THREAD_FUNNELED
case "$enable_threads" in 
    single)
    thread_pkg_required=no
    MPICH_THREAD_LEVEL=MPI_THREAD_SINGLE
    ;;
    funneled)
    thread_pkg_required=no
    MPICH_THREAD_LEVEL=MPI_THREAD_FUNNELED
    ;;
    serialized)
    # FIXME: Why does serialized require a thread package?
    thread_pkg_required=yes
    MPICH_THREAD_LEVEL=MPI_THREAD_SERIALIZED
    ;;
    multiple)
    thread_pkg_required=yes
    MPICH_THREAD_LEVEL=MPI_THREAD_MULTIPLE
    ;;
    *)
    AC_MSG_ERROR(["$enable_threads" is not a valid value for --enable-threads])     
    ;;
esac
# Check that the requested thread level is available.
threadLevelOK=yes
if test -z "$MPID_MAX_THREAD_LEVEL" ; then
    if test "$MPICH_THREAD_LEVEL" = "MPI_THREAD_MULTIPLE" -o "$MPICH_THREAD_LEVEL" = "MPI_THREAD_SERIALIZED" ; then
        threadLevelOK=no
    fi
else
    # Check that MPID_MAX_THREAD_LEVEL is at least as large as the
    # selected MPICH_THREAD_LEVEL
    case $MPICH_THREAD_LEVEL in 
        MPI_THREAD_MULTIPLE)
	if test "$MPID_MAX_THREAD_LEVEL" != "MPI_THREAD_MULTIPLE" ; then
	    threadLevelOK=no
        fi
	;;
	MPI_THREAD_SERIALIZED)
	if test "$MPID_MAX_THREAD_LEVEL" != "MPI_THREAD_MULTIPLE" -a \
	        "$MPID_MAX_THREAD_LEVEL" != "MPI_THREAD_SERIALIZED" ; then
            threadLevelOK=no
        fi
	;;
	MPI_THREAD_FUNNELED)
        if test "$MPID_MAX_THREAD_LEVEL" = "MPI_THREAD_SINGLE" ; then
            threadLevelOK=no
        fi
	;;
	MPI_THREAD_SINGLE)
	;;
    esac
fi
if test "$threadLevelOK" != yes ; then
   AC_MSG_ERROR([The device $with_device does not support $MPICH_THREAD_LEVEL])
fi

export MPICH_THREAD_LEVEL
AC_DEFINE_UNQUOTED(MPICH_THREAD_LEVEL,$MPICH_THREAD_LEVEL,[Level of thread support selected at compile time])

if test "$thread_pkg_required" = "no" ; then
1124
    MPIU_THREAD_DEFAULT=${MPIU_THREAD_DEFAULT:-none}
1125
fi
1126
export MPIU_THREAD_DEFAULT
1127

1128
# Check for value thread_cs choice; set the refcount default if necessary
1129
1130
thread_granularity=MPIU_THREAD_GRANULARITY_SINGLE
thread_refcount=MPIU_REFCOUNT_NONE
1131
1132
1133
1134
1135
1136
1137
if test "$enable_threads" = "multiple" ; then
    case $enable_thread_cs in 
    global)
    thread_granularity=MPIU_THREAD_GRANULARITY_GLOBAL
    if test "$enable_refcount" = "default" ; then enable_refcount=none ; fi
    ;;
    brief-global|brief_global)
1138
    AC_MSG_ERROR([--enable-thread-cs=brief-global is no longer supported, please select a different granularity])
1139
1140
1141
1142
1143
1144
1145
1146
    ;;
    per-object|per_object)
    thread_granularity=MPIU_THREAD_GRANULARITY_PER_OBJECT
    if test "$enable_refcount" = "default" ; then enable_refcount=lock ; fi
    ;;
    lock-free|lock_free|lockfree)
    thread_granularity=MPIU_THREAD_GRANULARITY_LOCK_FREE
    if test "$enable_refcount" = "default" ; then enable_refcount=lock-free ; fi
1147
    if test "$enable_predefined_refcount" = "default" ; then enable_predefined_refcount=no ; fi
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
    ;;
    *)
    AC_MSG_ERROR([Unrecognized value $enable_thread_cs for --enable-thread-cs])
    ;;
    esac

    case $enable_refcount in
    lock)
    thread_refcount=MPIU_REFCOUNT_LOCK
    ;;
    lock-free|lock_free|lockfree)
    thread_refcount=MPIU_REFCOUNT_LOCKFREE
    ;;
    none)
    thread_refcount=MPIU_REFCOUNT_NONE
    ;;
    *)
    AC_MSG_ERROR([Unrecognized value $enable_refcount for --enable-refcount])
    ;;
    esac
fi
AC_DEFINE_UNQUOTED([MPIU_THREAD_GRANULARITY],$thread_granularity,[Method used to implement atomic updates and access])

1171
1172
1173
1174
if test "$enable_predefined_refcount" = "no" ; then
    AC_DEFINE([MPIU_THREAD_SUPPRESS_PREDEFINED_REFCOUNTS],[1],[define to disable reference counting predefined objects like MPI_COMM_WORLD])
fi

1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
case $enable_handle_allocation in
    mutex|default)
        handle_allocation_method=MPIU_HANDLE_ALLOCATION_MUTEX
    ;;
    tls)
        handle_allocation_method=MPIU_HANDLE_ALLOCATION_THREAD_LOCAL
    ;;
    *)
        AC_MSG_ERROR([Unrecognized value $enable_handle_allocation for --enable-handle-allocation])
    ;;
esac
AC_DEFINE_UNQUOTED([MPIU_HANDLE_ALLOCATION_METHOD],$handle_allocation_method,[Method used to allocate MPI object handles])


AC_DEFINE_UNQUOTED([MPIU_THREAD_REFCOUNT],$thread_refcount,[Method used to implement refcount updates])

1191
1192
1193
1194
1195
1196
1197
# enable-g
# strip off multiple options, separated by commas
save_IFS="$IFS"
IFS=","
for option in $enable_g ; do
    case "$option" in 
        debug|dbg)
1198
        enable_append_g=yes
1199
1200
1201
	;;
        no|none)
	;;
1202
1203
1204
	handlealloc)
	perform_handlealloc=yes
	;;
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
	handle)
	AC_DEFINE(MPICH_DEBUG_HANDLES,1,[Define to enable handle checking])
	;;
	meminit)
	perform_meminit=yes
	;;
	memarena)
	perform_memarena=yes
	perform_memtracing=yes
	;;
	nesting)
	perform_nesttesting=yes
	;;	
	fine-grain-nesting|fg-nesting)
	perform_fg_nesttesting=yes
	;;	
	mem)
	perform_memtracing=yes
	;;
	log)
	perform_dbglog=yes
	;;
	mutex)
	perform_dbgmutex=yes
	;;
1230
1231
1232
	mutexnesting)
	perform_mutexnesting=yes
	;;
1233
1234
1235
1236
	all|yes)
	perform_memtracing=yes
	perform_nesttesting=yes
	perform_dbglog=yes
1237
	enable_append_g=yes
1238
1239
	perform_meminit=yes
	perform_dbgmutex=yes
1240
	perform_mutexnesting=yes
1241
	perform_handlealloc=yes
1242
1243
1244
1245
1246
1247
1248
	;;
	*)
	AC_MSG_WARN([Unknown value $enable_g for enable-g])
	;;
    esac
done
IFS="$save_IFS"
1249
1250
1251
1252
1253
1254
1255
1256

if test "$enable_append_g" = "yes" ; then
    CFLAGS="$CFLAGS -g"
    CXXFLAGS="$CXXFLAGS -g"
    FFLAGS="$FFLAGS -g"
    F90FLAGS="$F90FLAGS -g"
fi
if test "$enable_append_ndebug" = "yes" ; then
1257
1258
1259
1260
    CFLAGS="$CFLAGS -DNDEBUG -DNVALGRIND"
    CXXFLAGS="$CXXFLAGS -DNDEBUG -DNVALGRIND"
    FFLAGS="$FFLAGS -DNDEBUG -DNVALGRIND"
    F90FLAGS="$F90FLAGS -DNDEBUG -DNVALGRIND"
1261
fi
1262
1263
1264
if test -n "$perform_meminit" ; then
    AC_DEFINE(MPICH_DEBUG_MEMINIT,1,[Define to enable preinitialization of memory used by structures and unions])
fi
1265
1266
1267
1268
if test "$perform_handlealloc" = yes ; then
   AC_DEFINE(MPICH_DEBUG_HANDLEALLOC,1,[Define to enable checking of handles still allocated at MPI_Finalize])
fi

1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
if test -n "$perform_memtracing" ; then
    enable_g_mem=yes
    AC_DEFINE(USE_MEMORY_TRACING,1,[Define to enable memory tracing])
    if test -n "$perform_memarena" ; then
        AC_DEFINE(MPICH_DEBUG_MEMARENA,1,[Define if each function exit should confirm memory arena correctness])
    fi
fi
if test -n "$perform_nesttesting" ; then
    AC_DEFINE(MPICH_DEBUG_NESTING,1,[Define to check nesting level on exit])
fi
1279
1280
1281
if test -n "$perform_mutexnesting" ; then 
    AC_DEFINE(MPICH_DEBUG_MUTEXNESTING,1,[Define to check nesting in mutexes])
fi
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
if test -n "$perform_fg_nesttesting" ; then
    AC_DEFINE(MPICH_DEBUG_FINE_GRAIN_NESTING,1,[Define to perform a fine-grain nesting level check on exit])
fi
if test -n "$perform_dbglog" ; then
   if test "$with_logging" != "none" ; then
       AC_MSG_WARN([--with-logging overrides --enable-g=log])
   else
       AC_DEFINE(USE_DBG_LOGGING,1,[Define to enable logging macros])
   fi
fi

if test -n "$perform_dbgmutex" ; then 
   AC_DEFINE(MPICH_DEBUG_MUTEX,1,[Define to enable mutex debugging])
fi

pac_cross_compiling=no
if test "$with_cross" != "no" ; then
    if test -s "$with_cross" ; then
        AC_MSG_RESULT([Reading values from cross-compilation file $with_cross])
        . $with_cross
	# Autoconf 2.52 no longer sets cross_compiling except with the
	# awkward "targethost" options.
	pac_cross_compiling=yes
	cross_compiling=yes
	ac_cv_prog_cc_cross=yes
	ac_cv_prog_f77_cross=yes
 	ac_cv_prog_f90_cross=yes
        ac_cv_prog_cxx_cross=yes
        export cross_compiling
	# Export all cross variables.  Any subsidiary configure should also
        # export CROSS_xxx
	rm -f confcross
	(set) 2>&1 | grep CROSS_ | \
	      sed -e 's/^/export /g' -e 's/=.*//g' > confcross
	. confcross
	rm -f confcross      
    fi
fi

if test "$enable_nmpi_as_mpi" = yes ; then
   AC_DEFINE(USE_MPI_FOR_NMPI,1,[Define if the NMPI names should use MPI instead of PMPI])
fi

# This goes here because we need the top_srcdir
if test "$enable_romio" = "yes" ; then
   if test -d $use_top_srcdir/src/mpi/romio ; then
       subsystems="$subsystems src/mpi/romio"
       AC_DEFINE(HAVE_ROMIO,1,[Define if ROMIO is enabled])
       # Set environment variables that the romio configure expects
       romio_dir=romio
       AC_SUBST(romio_dir)
       export use_top_srcdir
       top_build_dir=`pwd`
       export top_build_dir
       # if there is no $top_build_dir/lib, romio puts lib in wrong place
       # This test used -e under Linux, but not all test programs understand
       # -e
       if test ! -d lib ; then mkdir lib ; fi
       # tell mpi.h to include mpio.h
       PAC_HAVE_ROMIO
   else
       AC_MSG_WARN([ROMIO src directory is not available])
   fi
fi
#
# FIXME: If an external device, don't necessarily complain (e.g.,
# if the device is already built)
if test ! -d $devicedir ; then
dnl     WAIT UNTIL WE INCLUDE A DEVICE
dnl     AC_MSG_ERROR([Device $device_name is unknown)]
    AC_MSG_WARN([Device $device_name is unknown])
elif test ! -x $devicedir/configure ; then
    if test -s $devicedir/configure ; then
        AC_MSG_WARN([The configure in $devicedir exists but is not executable])
    else
        AC_MSG_WARN([Device $device_name has no configure])
    fi
    device_name=""
else 
    # Add the device to the configure list
    devsubsystems="$devsubsystems $devicereldir"
    # Make device_name available to subdirs
fi
1365
1366
1367
1368
1369
1370
#
# Allow the device to request that the install step invoke the install 
# target in the device's Makefile.
if test -n "$device_name" -a "$INSTALL_FROM_DEVICE" = yes ; then
    other_install_dirs="${other_install_dirs} $devicereldir"
fi
1371
1372
1373
AC_SUBST(device_name)
#
# with-pm
1374
1375
1376
1377
if test "$with_pm" = "none" ; then
    # add "none" as synonym for "no" to agree with older erroneous docs
    with_pm="no"
fi
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
if test "$MPID_NO_PM" = yes ; then
    if test "$with_pm" != "default" -a "$with_pm" != no ; then
        AC_MSG_ERROR([The PM chosen ($with_pm) is is not valid for the selected device ($with_device)])
    fi
    # This is used to change with_pm=default to with_pm=no in the case
    # where the device does not want a PM
    with_pm=no
fi
if test -z "$with_pm" ; then
    with_pm="no"
fi
if test "$with_pmi" = "uni" -a "$with_pm" = "default" ; then
    with_pm="no"
fi
if test "$with_pm" = "default" -o "$with_pm" = "yes" ; then
1393
    with_pm=hydra
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
fi

# We allow multiple pm names, separated by : or ,
# If multiple PMs are provided, we set the value MANY_PM to yes
MANY_PM=no
AC_SUBST(MANY_PM)
if test "$with_pm" != "no" ; then
    pm_names="`echo $with_pm | sed -e 's/:/ /g' -e 's/,/ /g'`"
else
    pm_names=""
fi
#
hasError=no
# We need to be careful about PM's that have either conflicting 
# requirements (e.g., different PMI implementations) or different
# optional features (e.g., MPID_PM_NAMESERVER).
# In addition, we need to interleave the setup of the PMI and PM
# modules.  The order is as follows:
#
# For each PM, execute the mpich2prereq script for that pm (if present).  
# This script provides information about the PM, including which PMI
# implementations are supported.
# 
# Then, for the selected PMI, the setup script (if any) is run.  This is
# necessary because the setup of the PM may require information discovered
# or provided duing the PMI setup step (e.g., smpd requires this)
#
# Finally, for each PM, the setup script is executed.
# 
# Step 1: invoke the mpich2prereq for each PM
for pm_name in $pm_names ; do
    if test -z "$first_pm_name" ; then
       first_pm_name=$pm_name
    else 
       # Only add to other_pm_names if the directory exists,
       # since the Makefile in src/pm/Makefile will try to cd to
       # that directory
       if test -d $use_top_srcdir/src/pm/$pm_name ; then
           other_pm_names="$other_pm_names $pm_name"
       fi
    fi
    if test ! -d $use_top_srcdir/src/pm/$pm_name ; then
        AC_MSG_WARN([$use_top_srcdir/src/pm/$pm_name does not exist. PM is unknown])
	hasError=yes
    elif test ! -x $use_top_srcdir/src/pm/$pm_name/configure ; then
        if test -s $use_top_srcdir/src/pm/$pm_name/configure ; then
	    AC_MSG_WARN([The configure in $use_top_srcdir/src/pm/$pm_name exists but is not executable])
        else
            AC_MSG_WARN([pm $pm_name has no configure])
        fi
        pm_name=""
	hasError=yes
    else
	nameserver=$MPID_PM_NAMESERVER
        if test -f $use_top_srcdir/src/pm/$pm_name/mpich2prereq ; then 
	    echo sourcing $use_top_srcdir/src/pm/$pm_name/mpich2prereq
	    . $use_top_srcdir/src/pm/$pm_name/mpich2prereq
	fi
	# Check for a change; if found, we'll take the default
	if test "$MPID_PM_NAMESERVER" != "$nameserver" ; then
            if test "$first_pm_name" != "$pm_name" ; then
	        # Reject suggestion (use the default, common mode)
		MPID_PM_NAMESERVER=""
	    fi
	fi
    fi
done
if test "$hasError" != no ; then
    AC_MSG_ERROR([Aborting configure because an error was seen in the selection of process managers])
fi
#
# pm_name is the *primary* pm
pm_name=$first_pm_name
AC_SUBST(pm_name)
AC_SUBST(other_pm_names)

# Some versions of PM and PMI require a special definition (currently, only
# smpd requires this)
if test "$PMI_REQUIRES_READABLE_TOKENS" = "yes" ; then
    AC_DEFINE(USE_HUMAN_READABLE_TOKENS,1,[Define to use ='s and spaces in the string utilities.])
fi

if test -n "$first_pm_name" ; then
    other_install_dirs="${other_install_dirs} src/pm/$first_pm_name"
fi
# Step 2:
# Once we've selected the process manager (or managers), we can
# check that we have a compatible PMI implemenatation.
# with-pmi
if test "$MPID_NO_PMI" = yes ; then
    if test "$with_pmi" != "default" -a "$with_pmi" != no ; then
        AC_MSG_ERROR([The PMI chosen ($with_pmi) is is not valid for the selected device ($with_device)])
    fi
    # This is used to change with_pmi=default to with_pmi=no in the case
    # where the device does not want a PMI
    with_pmi=no
elif test "$with_pmi" != "no" ; then
    if test "$with_pmi" = "default" -o "$with_pmi" = "yes" ; then
        if test -n "$PM_REQUIRES_PMI" ; then
	    with_pmi=$PM_REQUIRES_PMI
        else
            with_pmi=simple
        fi
    elif test -n "$PM_REQUIRES_PMI" ; then
        # Test for compatibility between pm and pmi choices
        if test "$PM_REQUIRES_PMI" != "$with_pmi" ; then
	    AC_MSG_ERROR([The PM chosen ($with_pm) requires the PMI implementation $PM_REQUIRES_PMI but $with_pmi was selected as the PMI implementation.])
        fi
    fi
    pmi_name=$with_pmi
    
    if test ! -d $use_top_srcdir/src/pmi/$pmi_name ; then
        AC_MSG_WARN([$use_top_srcdir/src/pmi/$pmi_name does not exist. PMI is unknown])
    elif test ! -x $use_top_srcdir/src/pmi/$pmi_name/configure ; then
        AC_MSG_WARN([pmi $pmi_name has no configure or Makefile])
        pmi_name=""
    else
        subsystems="$subsystems src/pmi/$pmi_name"
    fi
else
    AC_MSG_ERROR([A PMI implementation must be selected or the default used.])
fi
AC_SUBST(pmi_name)

# Step 3: complete pm setup.
# Note that checks for errors have already been performed, so this
# loop does not need to perform any extra error checks.
# Note that this uses this_pm_name because pm_name must be the *first*
# of the PM names
for this_pm_name in $pm_names ; do
    subsystems="$subsystems src/pm/$this_pm_name"
    if test -f $use_top_srcdir/src/pm/$this_pm_name/setup_pm ; then 
	echo sourcing $use_top_srcdir/src/pm/$this_pm_name/setup_pm
	. $use_top_srcdir/src/pm/$this_pm_name/setup_pm
    fi
done

# ----------------------------------------------------------------------------
if test $with_mpe != no ; then
    if test ! -d $use_top_srcdir/src/mpe2 ; then
        if test $with_mpe = yes ; then
	    # No warning message on the default
            AC_MSG_WARN([No MPE directory available])
        fi
    elif test ! -x $use_top_srcdir/src/mpe2/configure ; then
        if test $with_mpe = yes ; then
	    # No warning message on the default
            AC_MSG_WARN([No configure available for MPE])
        fi
    else
        subsystems="$subsystems src/mpe2"
	other_install_dirs="$other_install_dirs src/mpe2"
	mpe_dir=mpe2
	# Temporarily replace the default NONE value for exec_prefix
	# and prefix with the actual, default values.
	savePrefix=$prefix
	saveExecprefix=$exec_prefix
	test "x$prefix" = xNONE && prefix=$ac_default_prefix
	test "x$exec_prefix" = xNONE && exec_prefix=$prefix
	eval actualbindir=$bindir
	# MPI_CC and MPIF77 must use the local (build) bin dir, not
	# the installation bin dir
	#MPI_CC=$actualbindir/mpicc
	#MPI_F77=$actualbindir/mpif77
	#eval actuallibdir=$libdir
	#MPI_LIBS="-L$actuallibdir -lmpich -lpmpich"
	buildbindir=`pwd`/bin
	MPI_CC=$buildbindir/mpicc
	MPI_F77=$buildbindir/mpif77
	prefix=$savePrefix
	exec_prefix=$saveExecprefix
	# NOTE: You must append LIBS to MPI_LIBS before invoking the mpe
	# configure
	export MPI_CC
	export MPI_F77
	#export MPI_LIBS
        export use_top_srcdir
        top_build_dir=`pwd`
        export top_build_dir
    fi
fi
AC_SUBST(mpe_dir)
AC_SUBST(other_install_dirs)

dnl
dnl The recommended order for items in a configure.in file is
dnl     check for programs
dnl     check for libraries
dnl     check for header files
dnl     check for typedefs
dnl     check for structures
dnl     check for compiler characteristics
dnl     check for library functions
dnl     check for system services
dnl
dnl We actually check for compilers first, then roughly follow this order,
dnl though logical subsystems (like Fortran support) my use this order
dnl within their part of the configure.
dnl
#
#
# Find a C compiler (choose gcc first).
# We also need to do this before the F77 and F90 test to ensure that we
# find the C preprocessor reliably.
saveCFLAGS=$CFLAGS
AC_PROG_CC
1600
AC_PROG_CPP
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
# Bug in autoconf.  Restore cross settings
if test "$pac_cross_compiling" = "yes" -a "$ac_cv_prog_cc_cross" = "no" ; then
    AC_MSG_RESULT([Resetting cross compilation to yes])
    cross_compiling=yes
    ac_cv_prog_cc_cross=yes
    ac_cv_prog_f77_cross=yes
    ac_cv_prog_f90_cross=yes
    ac_cv_prog_cxx_cross=yes
fi
# Misfeature in autoconf.  When using gcc, PROG_CC insists on setting 
# CFLAGS to -g -O2 if CFLAGS is not set.  This may be appropriate for
# many tools built with configure and gcc, but not always.  In particular,
# there seems to be no way to get gcc to use no extra flags if that is desired.
if test -z "$saveCFLAGS" -a -n "$CFLAGS" ; then
    # restore CFLAGS
    # Note: This may not be correct if PROG_CC decided to add other 
    # flags to CFLAGS to enforce some behavior (such as ANSI/ISO C),
    # But we haven't seen that in practice.  It would be better
    # if the CFLAGS were decomposed into flags-that-change-the-language
    # that the compiler accepts from optimizations
    CFLAGS=$saveCFLAGS
fi

# Check whether shared libraries are enabled.  We need to know this
# before we start chosing the Fortran, Fortran 90, and C++ compilers
ENABLE_SHLIB=$enable_sharedlibs
if test -z "$ENABLE_SHLIB" -o "$ENABLE_SHLIB" = "no" ; then
    ENABLE_SHLIB=none
    # Also turn off the libtool tests
    enable_shared=no
fi
# We need the script that is used to create shared libraries if either
# we are creating shared libraries for MPICH2 or we are creating the
# dynamically loadable library for the debugger interface
CREATESHLIB=false
if test "$ENABLE_SHLIB" != "none" -o "$enable_debuginfo" != "no" ; then
   CREATESHLIB=`pwd`/src/util/createshlib
fi
AC_SUBST(CREATESHLIB)
1640

1641
1642
1643
1644
1645
1646
1647
1648
# Check for whether the compiler defines a symbol that contains the 
# function name.  The MPICH2 code, for greater portability, defines
# its own symbols, FCNAME (a string) and FUNCNAME (a token that is not a 
# string).  Code should use these symbols where possible.  However, 
# some debugging macros may want to use a compiler-provided symbol
# for the function name, and this check makes it possible to 
# define such macros in a way that is always correct.
PAC_CC_FUNCTION_NAME_SYMBOL
1649
1650
1651
1652

# Check if $MPI_DEFAULT_COPTS is valid with $CC
if test "$enable_default_optimize" = "yes" \
     -a -n "$MPI_DEFAULT_COPTS" ; then
1653
1654
    if test "$enable_check_compiler_flags" = "yes" ; then
        PAC_C_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_COPTS], [
1655
        CFLAGS="$CFLAGS $MPI_DEFAULT_COPTS"
1656
1657
1658
1659
                                   ] )
    else
        CFLAGS="$CFLAGS $MPI_DEFAULT_COPTS"
    fi
1660
1661
fi

1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
# Check for support for weak symbols.  If not found, set NO_WEAK_SYM
# to the Make target name understood by simplemake.
# Set NEEDSPLIB to yes if link commands need both -l$MPILIBNAME
# and -lp$MPILIBNAME.
NEEDSPLIB=yes
NO_WEAK_SYM_TARGET=build_proflib
if test $enable_weak_symbols = yes ; then
    # Turn off weak symbols if they aren't available
    PAC_PROG_C_WEAK_SYMBOLS(,enable_weak_symbols=no)
fi
if test $enable_weak_symbols = "yes" ; then
    AC_DEFINE(USE_WEAK_SYMBOLS,1,[Define if weak symbols should be used])
    NEEDSPLIB=no
    # Check for the ability to support multiple weak symbols
    if test "$pac_cv_prog_c_weak_symbols" = "pragma weak" ; then
       PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS(AC_DEFINE(HAVE_MULTIPLE_PRAGMA_WEAK,1,[Define if multiple weak symbols may be defined]))
    fi
else
    NO_WEAK_SYM=build_proflib
    PROFILE_DEF_MPI="-DMPICH_MPI_FROM_PMPI"
fi
export NEEDSPLIB
export NO_WEAK_SYM
export NO_WEAK_SYM_TARGET
export PROFILE_DEF_MPI
AC_SUBST(NEEDSPLIB)
AC_SUBST(NO_WEAK_SYM)
AC_SUBST(NO_WEAK_SYM_TARGET)
AC_SUBST(PROFILE_DEF_MPI)

1692
# ---------------------------------------------------------------------------
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
# Support for the language bindings: Fortran 77, Fortran 90, and C++
#
# First, we handle the case of no explicit enable/disable option.  In that
# case, we look for a usable compiler.  We cannot use the ac macros for this
# because they abort the configure step if they fail to find a compiler 
# (earlier versions of autoconf did not have this behavior!).
#
# Second, we perform the langugage-specific tests, if necessary.  This may
# be relatively simple (C++) or complex (Fortran 77, including formation of 
# the encoded MPI handles).
#
# Note that the bindings support needs to know some of the properties of
# the C compiler, so those tests (particularly for weak symbols)
# must come first.
# ----------------------------------------------------------------------------

#
# First, determine whether we are/can support the language bindings
#
# Handle the case that the user set FC but not F77 before we run the
# PROG_F77 command
if test -n "$F77" -a -n "$FC" -a "$F77" != "$FC" ; then
    AC_MSG_ERROR([The values of the environment variables F77 (=$F77) and FC (=$FC) are not the same.  Unset one or both and rerun configure])
fi
if test -z "$F77" -a -n "$FC" ; then F77="$FC" ; fi
if test -z "$FC" -a -n "$F77" ; then FC="$F77" ; fi
# ----------------------------------------------------------------------------
# Handle default choices for the Fortran compilers
if test "$enable_f77" = "default" ; then
    enable_f77=no
    # Check for a Fortran compiler
    # Warning: the PROG_F77 command aborts if it fails to 
    # find a compiler.  We should first try to find a compiler, then
    # check to see if it works (which the PROG_F77 command does as well)
    # It also prefers g77 to f77, and doesn't know about other compilers
    # Also handle the bug that autoconf sets FFLAGS for you
    saveFFLAGS=$FFLAGS
    AC_PROG_F77
    FFLAGS=$saveFFLAGS
    if test -n "$F77" ; then 
        enable_f77_wasdefault=yes
        enable_f77=yes
    fi
elif test "$enable_f77" = "yes" ; then
    saveFFLAGS=$FFLAGS
    AC_PROG_F77
    FFLAGS=$saveFFLAGS
fi

if test "$enable_f77" = yes ; then
1743
1744
1745
    # Check if $MPI_DEFAULT_FOPTS is valid with $F77
    if test "$enable_default_optimize" = "yes" \
         -a -n "$MPI_DEFAULT_FOPTS" ; then
1746
1747
        if test "$enable_check_compiler_flags" = "yes" ; then
            PAC_F77_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_FOPTS], [
1748
            FFLAGS="$FFLAGS $MPI_DEFAULT_FOPTS"
1749
1750
1751
1752
                                         ] )
        else
            FFLAGS="$FFLAGS $MPI_DEFAULT_FOPTS"
        fi
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
    fi
fi

#
# We need to know the name mangling for Fortran before testing for F90
# compatibility (we need this because of the way we decide to generate
# the Fortran 77 bindings)
if test "$enable_f77" = yes ; then
    FLIBS_save="$FLIBS"
    FLIBS=""
    AC_F77_LIBRARY_LDFLAGS
    # The autoconf macro for finding FLIBS sometimes makes mistakes
    # (particularly with the Fujitsu frt compiler).  This next step
    # first sees if the FLIBS is valid with the Fortran compiler
    PAC_PROG_F77_FLIBS_VALID
    # Now see if FLIBS works with the C compiler
    PAC_PROG_F77_CHECK_FLIBS

    PAC_PROG_F77_LINKER_WITH_C
1772
    PAC_PROG_F77_OBJ_LINKS_WITH_C
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
    # For name mangle, we need the library flags
    PAC_PROG_F77_NAME_MANGLE
    # Check whether additional libraries are needed when linking with C
    PAC_PROG_F77_AND_C_STDIO_LIBS
    AC_SUBST(F77_OTHER_LIBS)

    # Warn about mixed name mangling, since many of the tests will fail
    if test "$pac_cv_prog_f77_name_mangle" = "mixed" ; then
        AC_MSG_WARN([The compiler $F77 uses mixed case names.  Fortran is monocase
and many Fortran programs may use either upper or lower case names for MPI
calls.  Consider specifying a particular parameter to your Fortran compiler
to select either upper or lower case names.  For the Absoft compiler, 
-f selects lower case and -N109 selects upper case (if you use -f, also use 
-B108 to enable the iargc and getarg routines, which are needed for some
tests and by many user programs).  Specify new command
line options by setting the environment variable FFLAGS to include
the options (e.g., setenv FFLAGS "-f -B108").  In addition, make sure that your
Fortran 90 compiler uses a compatible naming choice.  For the 
Absoft Fortran 90, -YALL_NAMES=LCS selects lower case names and -B108 
adds underscores to names, as required for iargc and getarg.  Pass this
information to configure with the F90FLAGS environment variable.])
        # If Fortran implicitly enabled, disable it now.  Otherwise,
	# abort the configure since warning messages are often lost in
	# the output.
	if test "$enable_f77_wasdefault" = yes ; then
	    AC_MSG_WARN([Turning off Fortran support because of mixed case names])
	    enable_f77=no
	    enable_f90=no
	else
	    AC_MSG_ERROR([Aborting configure because of mixed case names in Fortran.  Either select --disable-f77 or set FFLAGS to force the compiler to select monocase names])
	fi
    fi
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873

    # The MPI standard requires that MPI_Init in any language initialize
    # MPI in all languages.  This can be a problem when objects produced 
    # by the Fortran compiler require symbols from the Fortran runtime
    # (making linking C-only programs unnecessarily difficult).  What we test 
    # here is whether the much more restricted needs of the Fortran 
    # initialize can be met with no special use of the Fortran runtime
    pac_f_init_works_with_c=unknown
    AC_MSG_CHECKING([whether Fortran init will work with C])
    rm -f conftest*
    cat > conftestc.c <<EOF
#include <stdio.h>
#include "confdefs.h"
#ifdef F77_NAME_UPPER
#define minit_ MINIT
#elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
#define minit_ minit
#endif
int main( int argc, char *argv )
{
    minit_();
    return 0;
}
char *v1 = 0;
char *vc2 = 0;
int  v2 = 0;
minitc_( char *dv1, int d, char *dv2, int d2, int dv3 )
{
v1 = dv1;
v2 = dv3;
vc2 = dv2;
*vc2 = ' ';
}
EOF
    cat > conftestf.f <<EOF
       subroutine minit()
       common /m1/ vc, vc2
       character *1 vc(1,1), vc2(1)
       common /m2/ vd
       integer vd
       save /m1/, /m2/
       call minitc( vc, vc2, vd )
       end
EOF
   myfcompile='${F77-f77} -c $FFLAGS conftestf.f 1>&AC_FD_CC'
   myccompile='${CC-cc} -c $CFLAGS conftestc.c 1>&AC_FD_CC'
   if AC_TRY_EVAL(myfcompile) && test -s conftestf.o ; then
       :
   else 
	echo "configure: failed program was:" >&AC_FD_CC
        cat conftestf.f >&AC_FD_CC
   fi
   if AC_TRY_EVAL(myccompile) && test -s conftestc.o ; then
       :
   else 
	echo "configure: failed program was:" >&AC_FD_CC
        cat conftestc.c >&AC_FD_CC
   fi
   # Now try the link step
   myclink='${CC-cc} $CFLAGS -o conftest conftestc.o conftestf.o $LDFLAGS >conftest.out 2>&1'
   if AC_TRY_EVAL(myclink) && test -x conftest${ac_exeext} ; then
      pac_f_init_works_with_c=yes
   else
      pac_f_init_works_with_c=no
   fi
   AC_MSG_RESULT($pac_f_init_works_with_c)
   if test "$pac_f_init_works_with_c" = "yes" ; then
       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])
   fi
1874
1875
fi

1876
1877
1878
1879
1880
1881
# Check if multiple __attribute__((alias)) is available
if test "$enable_f77" = yes ; then
    PAC_C_ATTR_ALIGNED
    PAC_C_MULTI_ATTR_ALIAS
fi

1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
# F90 requires F77 as well.  If the user disabled f77, do not run the
# next test; instead, drop into the warning message
# Set a default value for f90 works with f77.  This value is
# set to no *only* if f90 was selected but was not compatible with f77
f90_with_f77=yes
if test "$enable_f90" = "default" -a "$enable_f77" = yes ; then
    enable_f90=no
    # Check for a Fortran compiler.  Work around bug in autoconf that 
    # adds -g to F90FLAGS
    saveF90FLAGS="$F90FLAGS"
    PAC_PROG_F90
    F90FLAGS=$saveF90FLAGS
    if test -n "$F90" ; then 
        if test -z "$F77" ; then
	    saveFFLAGS=$FFLAGS
	    AC_PROG_F77
	    FFLAGS=$saveFFLAGS
	fi
	#
	# If we allow multiple weak symbols, we should test a name
	# that does not contain an underscore.  The Fortran binding uses
	# this rule for enabling multiple weak symbols:
	# if defined(USE_WEAK_SYMBOLS) && !defined(USE_ONLY_MPI_NAMES) &&
	#    defined(HAVE_MULTIPLE_PRAGMA_WEAK) && 
	#    defined(F77_NAME_LOWER_2USCORE)
	# 
	testRoutine="t1_2"
	if test "$pac_cv_prog_c_multiple_weak_symbols" = "yes" -a \
               "$enable_weak_symbols" = "yes" -a \
	       "$pac_cv_prog_f77_name_mangle" = "lower doubleunderscore" ; then
	    testRoutine="t12"
        fi
        PAC_F90_AND_F77_COMPATIBLE(f90_with_f77=yes,f90_with_f77=no,$testRoutine)
        if test "$f90_with_f77" != yes ; then
	    enable_f90=no
	    AC_MSG_WARN([The selected Fortran 90 compiler $F90 does not work with the selected Fortran 77 compiler $F77.  Use the environment variables F90 and F77 respectively to select compatible Fortran compilers.  The check here tests to see if a main program compiled with the Fortran 90 compiler can link with a subroutine compiled with the Fortran 77 compiler.])
        elif test "$f90_with_f77" = "yes" ; then
            # If we got here, there is a Fortran 90 compiler that we can use
            enable_f90=yes
        fi
    elif test "$pac_cv_prog_f90_works" = no; then
        AC_MSG_WARN([Use --disable-f90 to keep configure from searching for a Fortran 90 compiler])
    fi
fi
if test "$enable_f90" = "yes" -a "$enable_f77" != "yes" ; then
   # Fortran 90 support requires compatible Fortran 77 support
   AC_MSG_WARN([Fortran 90 support requires compatible Fortran 77 support.  To force the use of the Fortran 90 compiler for Fortran 77, set the environment variable F77 to the name of the Fortran 90 compiler.])
   # We should probably do the compatibility test as well
   enable_f77=yes
fi

# ----------------------------------------------------------------------------
# Now test for Fortran compiler characteristics
# ----------------------------------------------------------------------------
if test "$enable_f77" = "yes" ; then
    AC_LANG_FORTRAN77
    PAC_PROG_F77_EXCLAIM_COMMENTS(has_exclaim="yes",has_exclaim="no")
    PAC_PROG_F77_HAS_INCDIR(src)
    if test -n "$F77_INCDIR" ; then
        # For building the Fortran files, add the directory where we are building 
        # the object to the include list.  This is needed for g77, which makes
        # includes relative to the source directory of the file, not the 
        # directory that the command is executed in
        FINCLUDES="$F77_INCDIR`pwd`/src"
    fi
    AC_SUBST(FINCLUDES)
    #
    PAC_PROG_F77_LIBRARY_DIR_FLAG

    AC_SUBST(MPIFPMPI)
    if test "$MPI_WITH_PMPI" = "no" ; then
        # If the PMPI routines are not in the same library with the MPI
        # routines, we may need to remove the pmpi declarations
        PAC_PROG_F77_ALLOWS_UNUSED_EXTERNALS([MPIFPMPI=",PMPI_WTIME,PMPI_WTICK"],[
        MPIFPMPI=""; 
        AC_MSG_WARN([Removed PMPI_WTIME and PMPI_WTICK from mpif.h])])
    else
        MPIFPMPI=",PMPI_WTIME,PMPI_WTICK"
    fi

    # Once we have name mangle, we can try to limit the number of needed libs
    PAC_PROG_F77_IN_C_LIBS
    AC_SUBST(F77_IN_C_LIBS)

    # ------------------------------------------------
    # Shared library support
    # ------------------------------------------------
# Note that USE_GCC_G77_DECLS is not used anywhere within the code, so
# this check has been commented out.
dnl    # If both C and Fortran are gnu, define the following to simplify 
dnl    # shared library support.  
dnl    AC_MSG_CHECKING([whether using gcc and g77 together])
dnl    if test "$ac_cv_prog_gcc" = "yes" -a "$ac_cv_prog_g77" = "yes" ; then
dnl        # FIXME: Who uses this definition?
dnl        AC_DEFINE(USE_GCC_G77_DECLS,1,[Define if using gcc and g77 together])
dnl        AC_MSG_RESULT(yes)
dnl    else 
dnl        AC_MSG_RESULT(no)
dnl    fi
    AC_SUBST(FC_SHL)
    AC_SUBST(FC_LINKPATH_SHL)
    case "$ENABLE_SHLIB" in
	 gcc-osx|osx-gcc)
	 FC_SHL="$F77 -fPIC"
	 FC_LINKPATH_SHL=""
	 ;;
	 gcc)
	 # Assume that the compiler is g77 if gcc style shared libraries chosen
	 # (unfortunately, the name may be g77 or f77)
	 # To make this a little more robust, only add the -shared
	 # if the compiler allows it (e.g., building with gcc but
	 # a different Fortran compiler. Another option is to
	 # *require* g77.
	 rm -f conftest.f
	 cat > conftest.f <<EOF
       program main
       end
EOF
2000
         FC_SHL=false
2001
         for sh_arg in "-shared -fPIC" "-fPIC" "-shared -fpic" "-fpic" "-KPIC" ; do
2002
2003
2004
 	     AC_MSG_CHECKING([whether $F77 allows $sh_arg])
             if $F77 $sh_arg -o conftest conftest.f >/dev/null 2>&1 ; then
	         FC_SHL="$F77 $sh_arg"
2005
                 AC_MSG_RESULT(yes)
2006
	         break
2007
2008
2009
             else
                 AC_MSG_RESULT(no)
             fi
2010
2011
	 done
	 if test "$FC_SHL" = "false" ; then
2012
	     AC_ERROR([Cannot build shared libraries for Fortran with this compiler])
2013
         fi
2014
2015
	 # This is needed for Mac OSX 10.5
	 rm -rf conftest.dSYM
2016
2017
2018
         rm -f conftest*
	 FC_LINKPATH_SHL="-Wl,-rpath -Wl,"
	 ;;
2019

2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
	 cygwin|cygwin-gcc)
	 FC_SHL="$F77 -shared"
	 FC_LINKPATH_SHL=""
	 ;;

	 solaris|solaris-cc)
	 FC_SHL="$F77 -xcode=pic32"
         FC_LINKPATH_SHL=-R
	 ;;

	 # Do we need a solaris-64 with -xcode=pic64?

	 libtool)
	 FC_SHL='${LIBTOOL} --mode=compile ${F77}'
         FC_LINKPATH_SHL="-rpath "
	 ;;

	 *)
	 FC_SHL=false
	 ;;
    esac
    # ------------------------------------------------

    #
    # Most systems allow the Fortran compiler to process .F and .F90 files
    # using the C preprocessor.  However, some systems either do not
    # allow this or have serious bugs (OSF Fortran compilers have a bug
    # that generates an error message from cpp).  The following test
    # checks to see if .F works, and if not, whether "cpp -P -C" can be used
2049
2050
    # This is needed for Mac OSX 10.5
    rm -rf conftest.dSYM
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
    rm -f conftest*
    AC_MSG_CHECKING([whether Fortran compiler processes .F files with C preprocessor])
    cat >conftest.F <<EOF
        program main
#define SIZE 10
        integer a(SIZE)
        end
EOF
    pac_cv_fort_accepts_F=no
    pac_Fcompile='${F77} -c $FFLAGS $CPPFLAGS conftest.F 1>&AC_FD_CC'

    if AC_TRY_EVAL(pac_Fcompile) && test -s conftest.o ; then
        pac_cv_fort_accepts_F=yes
    else
        # Can we use cpp?
        pac_Fcpp='${CPP} -C -P $CPPFLAGS conftest.F >conftest.f 2>&AC_FD_CC'
        if AC_TRY_EVAL(pac_Fcpp) && test -s conftest.f ; then
            pac_fFcompile='${F77} -c $FFLAGS $CPPFLAGS conftest.f 1>&AC_FD_CC'
   	    if AC_TRY_EVAL(pac_fFcompile) && test -s conftest.o ; then
	        pac_cv_fort_accepts_F="no, use cpp"
 	    fi
        fi
    fi
    rm -f conftest.*
    AC_MSG_RESULT($pac_cv_fort_accepts_F)
    case "$pac_cv_fort_accepts_F" in 
        yes)
        F77CPP=""
        ;;
        "no, use cpp")
         F77CPP="$CPP -C -P"
        ;;
        no) 
        F77CPP="false"
        ;;
    esac
    AC_SUBST(F77CPP)

    bindings="$bindings f77"
    bindings_dirs="$bindings_dirs src/binding/f77"
    AC_DEFINE(HAVE_FORTRAN_BINDING,1,[Define if Fortran is supported])
    # Also define the name FORTRAN_BINDING for use in #if @FORTRAN_BINDING@..
    FORTRAN_BINDING=1
fi

dnl By modifying mpif.h to use ! for comments, it can work with many f90 
dnl compilers without creating a separate version.  
dnl Note that this is run AFTER the AC_OUTPUT actions
2099
AC_OUTPUT_COMMANDS([if test "$enable_f77" = yes ; then 
2100
2101
2102
2103
2104
2105
2106
2107
if test "$bashWorks" = yes ; then cp -f src/env/mpif77.bash src/env/mpif77 ; fi
chmod a+x src/env/mpif77
if test "$has_exclaim" = "yes" ; then
    sed -e 's/^C/\!/g' src/binding/f77/mpif.h > src/include/mpif.h
	cp src/include/mpif.h src/binding/f77/mpif.h
else
    cp src/binding/f77/mpif.h src/include
fi
2108
2109
2110
2111
2112
if test "$has_fort_real8" = "yes" ; then
    sed -e 's/DOUBLE PRECISION/REAL*8/g' src/include/mpif.h > src/include/mpif.h.new
    mv src/include/mpif.h.new src/include/mpif.h
    cp src/include/mpif.h src/binding/f77/mpif.h
fi
2113
2114
2115
2116
2117
2118
# Save a copy of the original mpi_base.f90 file
if test "$enable_f90" = "yes" ; then
  if test ! -f "$master_top_srcdir/src/binding/f90/mpi_base.f90.orig" ; then
    cp $master_top_srcdir/src/binding/f90/mpi_base.f90 $master_top_srcdir/src/binding/f90/mpi_base.f90.orig
  fi
  if test "$has_fort90_real8" = "yes" ; then
2119
    sed -e 's/DOUBLE PRECISION/REAL*8/g' $master_top_srcdir/src/binding/f90/mpi_base.f90.orig > $master_top_srcdir/src/binding/f90/mpi_base.f90.new
2120
    mv -f $master_top_srcdir/src/binding/f90/mpi_base.f90.new $master_top_srcdir/src/binding/f90/mpi_base.f90
2121
  else
2122
    cp -f $master_top_srcdir/src/binding/f90/mpi_base.f90.orig $master_top_srcdir/src/binding/f90/mpi_base.f90
2123
2124
  fi
fi
2125

2126
2127
if test ! -d bin  ; then mkdir bin ; fi 
sed -e 's%includedir=.*%includedir='$includebuild_dir% \
2128
2129
    -e 's%libdir=.*%libdir='$libbuild_dir% \
    src/env/mpif77 > bin/mpif77 ;
2130
2131
2132
2133
chmod a+x bin/mpif77
else
    rm -f src/env/mpif77 src/env/mpif77.conf
fi],
2134
master_top_srcdir=$master_top_srcdir
2135
enable_f77=$enable_f77
2136
enable_f90=$enable_f90
2137
has_exclaim=$has_exclaim
2138
has_fort_real8=$pac_cv_fort_real8
2139
has_fort90_real8=$pac_cv_fort90_real8
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
includebuild_dir=$includebuild_dir
libbuild_dir=$libbuild_dir
bashWorks=$bashWorks)

if test "$enable_f90" = "yes" ; then
    if test "$enable_f77" != "yes" ; then
        AC_MSG_WARN([Fortran 90 requires Fortran 77])
        enable_f90=no
    else 
        bindingsubsystems="$bindingsubsystems src/binding/f90"
        bindings="$bindings f90"
        bindings_dirs="$bindings_dirs src/binding/f90"
    fi
fi

# Set defaults for these values so that the Makefile in src/bindings/f90
# is valid even if f90 is not enabled (this is necessary for the 
# distclean target)
MPIMODNAME=mpi
MPICONSTMODNAME=mpi_constants
MPISIZEOFMODNAME=mpi_sizeofs
MPIBASEMODNAME=mpi_base
if test "$enable_f90" = "yes" ; then
    # Determine characteristics of the Fortran 90 compiler
    # Find a Fortran 90 compiler.  Sets F90
    # Work around bug in autoconf that adds -g to F90FLAGS
    saveF90FLAGS="$F90FLAGS"
    PAC_PROG_F90
    PAC_PROG_F90_WORKS
    F90FLAGS=$saveF90FLAGS
    if test "$pac_cv_prog_f90_works" = no ; then 
        # Reject this compiler
        if test -n "$F90" ; then
            f90_rejected=yes
            oldF90="$F90"
            F90=""
        fi
    fi

    if test -z "$F90" ; then
        if test "$f90_rejected" = "yes" ; then
            AC_MSG_ERROR([Could not find a usable F90 compiler.  The compiler $oldF90 may be incompatible with the Fortran 77 compiler $F77; check the output of configure and consult the installation manuals])
        else
            AC_MSG_ERROR([Could not find a usable F90 compiler.])
        fi
    fi

    # Find the extension that this compiler uses for modules.
    # Sets F90MODEXT (and adds it to the list substed)
    # Sets F90MODINCFLAG (and adds it to the list substed)
    PAC_F90_MODULE
    AC_SUBST(F90MODINCSPEC)
    if test "$pac_cv_f90_module_case" = "upper" ; then
        MPIMODNAME=MPI
        MPICONSTMODNAME=MPI_CONSTANTS
	MPISIZEOFMODNAME=MPI_SIZEOFS
	MPIBASEMODNAME=MPI_BASE
    else
        MPIMODNAME=mpi
        MPICONSTMODNAME=mpi_constants
	MPISIZEOFMODNAME=mpi_sizeofs
	MPIBASEMODNAME=mpi_base
    fi
    AC_SUBST(MPIMODNAME)
    AC_SUBST(MPICONSTMODNAME)
    AC_SUBST(MPISIZEOFMODNAME)
    AC_SUBST(MPIBASEMODNAME)
    if test -z "$modincdir" ; then
        # The default module include dir is the same as the include dir
        modincdir=$includedir
    fi
    AC_SUBST(modincdir)    
    #
    # For now, assume that all f90 compilers accept -I for include directories
    F90INC=-I
    AC_SUBST(F90INC)
    F90INCFLAG=-I
    AC_SUBST(F90INCFLAG)

    #
    # Determine the extension for f90 files (it isn't always .f90)
    PAC_F90_EXT
    F90EXT=$pac_cv_f90_ext
    AC_SUBST(F90EXT)
2224

2225
2226
2227
    # Check if $MPI_DEFAULT_F90OPTS is valid with $F90
    if test "$enable_default_optimize" = "yes" \
         -a -n "$MPI_DEFAULT_F90OPTS" ; then
2228
2229
        if test "$enable_check_compiler_flags" = "yes" ; then
            PAC_F90_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_F90OPTS], [