1dnl
2dnl Caching is usually WRONG for systems with cross-mounted file systems
3dnl (the cache file may correspond to a different system).  Since configure
4dnl is not on a performance-critical path, go for robustness over speed.
5dnl
6define([AC_CACHE_LOAD], )dnl
7define([AC_CACHE_SAVE], )dnl
8dnl
9dnl
10AC_INIT()
11AC_PREREQ(2.52)
12AC_CONFIG_AUX_DIR([.])
13AC_CONFIG_HEADER(mpe_conf.h)
14#
15echo "Configuring MPE Profiling System with $ac_configure_args"
16dnl
17dnl  Set top_srcdir_abs to be the ABSOLUTE path to the home directory of MPE
18dnl  top_srcdir is in relative path.
19if test "X$srcdir" != "X." -a -s $srcdir/include/mpe.h ; then
20    top_srcdir_abs=$srcdir
21else
22    PAC_GETWD( top_srcdir_abs, include/mpe.h )
23fi
24AC_SUBST(top_srcdir_abs)
25
26# Determine this package's name based on its directory name
27changequote(,)dnl
28tmpname="`echo $top_srcdir_abs | sed -e 's%\(.*\)/\([^/]*\)%\2%'`"
29pkgname="`echo $tmpname | sed -e 'y%abcdefghijklmnopqrstuvwxyz/%ABCDEFGHIJKLMNOPQRSTUVWXYZ_%'`"
30changequote([,])dnl
31if test "x$pkgname" = "x" ; then
32    pkgname="MPE-2"
33fi
34
35AC_ARG_ENABLE( echo,
36[--enable-echo                      - Turn on strong echoing.
37                                     The default is enable=no.],
38set -x )
39
40AC_ARG_ENABLE( softerror,
41[--enable-softerror                 - Turn on soft error, i.e. instead of
42                                     issuing MSG_ERROR, MSG_WARN + exit 0
43                                     are used.  The default is enable=no.],
44, enable_softerror=${mpe_enable_softerror:-no} )
45
46dnl Don't preset F77 when MPE is configured with MPICH2
47dnl otherwise AC_PROG_F77 or other PAC F77 tests could be messed up below.
48dnl This is especially true when no fortran compiler in PATH.
49VERSION=""
50if test "$FROM_MPICH2" != "yes" ; then
51    CC=${CC:-cc}
52    F77=${F77:-f77}
53    CFLAGS=${CFLAGS}
54    FFLAGS=${FFLAGS}
55fi
56MPE_LIBNAME=""
57
58dnl Read FROM_MPICHx variables from the environment
59MAKE=${MAKE:-make}
60FROM_MPICH=${FROM_MPICH:-no}
61FROM_MPICH2=${FROM_MPICH2:-no}
62FROM_LAM=${FROM_LAM:-no}
63
64
65dnl Fixup for make
66PAC_MAKE_IS_GNUMAKE
67PAC_MAKE_IS_BSD44
68PAC_MAKE_IS_OSF
69PAC_MAKE_VPATH
70AC_SUBST(MAKE)
71
72dnl If we are relying on vpath and no vpath is set, then we must exit
73if test ! -s include/mpe.h -a -z "$VPATH" ; then
74    AC_MSG_ERROR( [No virtual MAKE path command found.
75	You may need to set your make command
76	The GNU make (sometimes available as gnumake) can be used.] )
77fi
78
79dnl CPRP is the version of cp that accepts -r and -p arguments.
80MKDIR=mkdir
81CPRP=cp
82RM=rm
83MV=mv
84AC_SUBST(MKDIR)
85AC_SUBST(CPRP)
86AC_SUBST(RM)
87AC_SUBST(MV)
88
89AC_ARG_ENABLE( strict,
90[--enable-strict                    - Turn on strict compilation testing
91                                     when using gcc],,enable_strict=no )
92dnl
93AC_ARG_ENABLE( g,
94[--enable-g                         - Turn on/off the compilation flag -g.
95                                     The default is enable=no.],
96[if test "$enable_g" != "no" ; then enable_g=yes ; fi],
97[enable_g=no] )
98
99dnl MPE_BUILD_FORTRAN2C=yes means that ALL subpackages will be building
100dnl the fortran2c wrapper libraries.  This does not necessarily mean that
101dnl specific subpackage has to build fortran2c wrapper library.  One example:
102dnl src/wrappers may have --with-f2cmpilibs set by user, so src/wrappers's
103dnl own libmpe_f2cmpi.a will not be built but MPE_BUILD_FORTRAN2C could
104dnl still be set to yes because it means other subpackages like src/graphics
105dnl and src/logging will build their fortran2c wrapper objects.  So treat
106dnl MPE_BUILD_FORTRAN2C as a directive, i.e. generally a necessary but
107dnl insufficient condition to build fortran2c wrapper library.
108AC_ARG_ENABLE( f77,
109[--enable-f77                       - Compile routines that require a Fortran
110                                     compiler.  If configuring with MPICH, the
111                                     configure in the top-level MPICH directory
112                                     will choose the appropriate value for you.
113                                     The default is enable=yes.], ,
114enable_f77=yes )
115if test "$enable_f77" = "yes" ; then
116    MPE_BUILD_FORTRAN2C=yes
117else
118    MPE_BUILD_FORTRAN2C=no
119fi
120
121AC_ARG_ENABLE( mpich,
122[--enable-mpich                     - Indicates if this MPE will be built as
123                                     part of the MPICH build.  The default is
124                                     enable=no.], ,
125enable_mpich=no )
126
127dnl  Translating FROM_MPICHx into MPI_IMPL.  So don't pass FROM_MPICHx down
128dnl  to subpackages.  All subpackages will use MPI_IMPL instead.
129dnl  BUILDING_MPI=yes disables the linkage test during building, i.e. make
130dnl  BUILDING_MPI=yes when MPI_IMPL=MPICH or MPI_IMPL=MPICH2
131dnl  MPE_KNOWN_MPI_IMPL can be tested by testing MPI_IMPL = MPICH, MPICH2
132if test "$enable_mpich" = "yes" -o "$FROM_MPICH" = "yes" ; then
133    AC_MSG_RESULT([This MPE build is part of the MPICH build])
134    MPI_IMPL="MPICH"
135    enable_softerror=yes
136    enable_checkMPI=no
137dnl BUILDING_MPI=yes & MPE_KNOWN_MPI_IMPL=yes
138elif test "$FROM_MPICH2" = "yes" ; then
139    AC_MSG_RESULT([This MPE build is part of the MPICH2 build])
140    MPI_IMPL="MPICH2"
141    if test -d "$includebuild_dir" ; then
142        MPICPPFLAGS="$MPICPPFLAGS -I$includebuild_dir"
143    else
144        MPICPPFLAGS="$MPICPPFLAGS -I$master_top_srcdir/src/include -I$master_top_builddir/src/include"
145    fi
146    enable_softerror=yes
147    enable_checkMPI=no
148dnl BUILDING_MPI=yes & MPE_KNOWN_MPI_IMPL=yes
149dnl elif test "$FROM_LAM" = yes ; then
150dnl    AC_MSG_RESULT([This MPE build is part of the LAM build])
151dnl    MPI_IMPL="LAM"
152dnl BUILDING_MPI=yes & MPE_KNOWN_MPI_IMPL=yes
153else
154    AC_MSG_RESULT([User supplied MPI implmentation (Good Luck!)])
155    MPI_IMPL="UserSupplied"
156    enable_checkMPI=yes
157dnl BUILDING_MPI=no & MPE_KNOWN_MPI_IMPL=no
158fi
159
160AC_ARG_ENABLE( checkMPI,
161[--enable-checkMPI                  - Turn on/off the linking test for the MPI
162                                     include files, MPI libraries and MPI_CC
163                                     compiler. The default is enable=yes.],
164enable_checkMPI=${mpe_enable_checkMPI:-$enableval} )
165
166AC_ARG_ENABLE( checkMPIwtime,
167[--enable-checkMPIwtime             - Turn on/off the linking test for the
168                                     MPI_Wtime(). The default is enable=no.], ,
169enable_checkMPIwtime=no )
170
171dnl
172dnl  Set the MPE Libraries name
173dnl
174AC_ARG_WITH( mpelibname,
175[--with-mpelibname=MPE_LIBNAME      - Set the MPE library name instead of the
176                                     default 'mpe', e.g. if MPE_LIBNAME=mpe_new,
177                                     then the libraries generated will be
178                                     libmpe_new.a, liblmpe_new.a, libtmpe_new.a
179                                     and libampe_new.a.],
180MPE_LIBNAME="$withval" )
181
182dnl
183dnl  Set the Fortran Include Library Leading Characters
184dnl
185AC_ARG_WITH( finc_path_leader,
186[--with-finc_path_leader=FINC_PATH_LEADER - Specify a Fortran include path
187                                     leader for compilation,
188                                     default value is -I.],
189FINC_PATH_LEADER="$withval" )
190dnl
191AC_ARG_WITH( flib_path_leader,
192[--with-flib_path_leader=FLIB_PATH_LEADER - Specify a Fortran library path
193                                     leader for linking, default value is -L.],
194FLIB_PATH_LEADER="$withval" )
195dnl
196
197dnl
198dnl Check if -g is needed to appended to CFLAGS and FFLAGS
199dnl
200dnl Append "-g" to xFLAGS and MPI_xFLAGS if enable_g=yes
201if test "$enable_g" = "yes" ; then
202    for flagname in CFLAGS FFLAGS MPI_CFLAGS MPI_FFLAGS ; do
203        eval flagvalue=\$"$flagname"
204        case " $flagvalue " in
205           *" -g "*)
206              ;;  # Avoid duplication, do nothing
207           *)
208              # Split eval command into 2 lines so
209              # vi's hightlight mode won't get confused.
210              flagcmd="$flagname=\"$flagvalue -g\""
211              eval ${flagcmd}
212              ;;
213        esac
214    done
215fi
216
217# Set the various build directories and export them as environmental variables.
218#
219# [mpe_]includebuild_dir is for all user header files
220# [mpe_]libbuild_dir is for building the libraries in before they are installed.
221# [mpe_]binbuild_dir is for the scripts/programs
222# [mpe_]sbinbuild_dir is for all system admin tools
223# [mpe_]etcbuild_dir is for all system admin configuration settings
224#
225rootbuild_dir=`pwd`
226for dir in include lib bin sbin etc ; do
227    dirname=${dir}build_dir
228    eval dirvalue=\$"$dirname"
229    eval $dirname=$rootbuild_dir/$dir
230    mpe_dirname=mpe_$dirname
231    eval $mpe_dirname=\$"$dirname"
232    export $mpe_dirname
233done
234
235srcbuild_dir=$rootbuild_dir/src
236for dir in include lib bin sbin src etc ; do
237    dirname=${dir}build_dir
238    eval dirvalue=\$"$dirname"
239    if test -n "$dirvalue" ; then
240        if test ! -d $dirvalue ; then
241            if mkdir -p $dirvalue ; then
242                :
243            else
244                PAC_MSG_ERROR( $enable_softerror,
245                               [Could not create directory $dirvalue] )
246            fi
247        fi
248    fi
249done
250
251AC_SUBST(includebuild_dir)
252AC_SUBST(libbuild_dir)
253AC_SUBST(binbuild_dir)
254AC_SUBST(sbinbuild_dir)
255AC_SUBST(etcbuild_dir)
256
257
258dnl
259dnl  Unknown MPI implmentation, i.e. User defined MPI_LIBS and MPI_INC
260dnl
261AC_ARG_WITH( mpicc,
262[--with-mpicc=MPI_CC                - C compiler for MPI program,
263                                     e.g. mpixlc_r for BG/P MPI, or
264                                     mpicc from MPICHx, Open-MPI, or LAM-MPI.
265                                     Setting --with-mpicc to MPI wrapper
266                                     means no need to set --with-mpiinc
267                                     and --with-mpilibs.],
268MPI_CC="$withval" )
269
270AC_ARG_WITH( mpif77,
271[--with-mpif77=MPI_F77              - Fortran compiler for MPI program,
272                                     e.g. mpixlf77_r for BG/P MPI, or
273                                     mpif77 from MPICHx, Open-MPI, or LAM-MPI.
274                                     Setting --with-mpif77 to MPI wrapper
275                                     means no need to set --with-mpiinc
276                                     and --with-mpilibs.],
277MPI_F77="$withval" )
278
279AC_ARG_WITH( mpiinc,
280[--with-mpiinc=MPI_INC              - MPI include path prefixed with -I.
281                                     It specifies MPI header files location,
282                                     where mpi.h and mpif.h are located,
283                                     e.g. -I/pkgs/MPI/include. This flag will
284                                     be added to MPI_CFLAGS and MPI_FFLAGS,
285                                     i.e. the MPI include path can be
286                                     explicitly set in MPI_CFLAGS and
287                                     MPI_FFLAGS without setting --with-mpiinc.],
288MPI_INC="$withval" )
289
290AC_ARG_WITH( mpilibs,
291[--with-mpilibs=MPI_LIBS            - MPI library flags with -L and -l.
292                                     It specifies the location of the MPI
293                                     libraries.  The flags contains library
294                                     path prefixed with -L and MPI libraries
295                                     name prefixed with -l,
296                                     e.g. -L/opt/MPI/lib -lpmpich -lmpich.],
297MPI_LIBS="$withval" )
298
299dnl
300misc_dirname="src/misc"
301callstack_dirname="src/callstack"
302logging_dirname="src/logging"
303wrappers_dirname="src/wrappers"
304graphics_dirname="src/graphics"
305collchk_dirname="src/collchk"
306slog2_dirname="src/slog2sdk"
307
308dnl Cleanup the subpackages' Makefiles if they exist
309AC_MSG_CHECKING( [for leftover Makefiles in subpackages] )
310leftover_pkgs=""
311for pkg in misc callstack logging wrappers graphics collchk slog2 ; do
312    dirname=${pkg}_dirname
313    eval dirvalue=\$"$dirname"
314    if test -s $rootbuild_dir/$dirvalue/Makefile ; then
315        leftover_pkgs="$leftover_pkgs \"$dirvalue\""
316        ( cd $rootbuild_dir/$dirvalue && $MAKE distclean > /dev/null 2>&1 )
317        dnl Just in case "make distclean" does not remove Makefile.
318        if test -f $rootbuild_dir/$dirvalue/Makefile ; then
319            $RM -f $rootbuild_dir/$dirvalue/Makefile
320        fi
321    fi
322done
323if test "X$leftover_pkgs" = "X" ; then
324    AC_MSG_RESULT( [none] )
325else
326    AC_MSG_RESULT( [$leftover_pkgs cleaned] )
327fi
328
329dnl trial_pkgs="misc callstack logging wrappers graphics collchk"
330
331dnl
332AC_ARG_ENABLE( misc,
333[--enable-misc                      - Build MPE miscellaneous routines, e.g.
334                                     MPE_Errors_xxx(), MPE_Seq_xxx(),
335                                     MPE_xxxTags() and MPE_GetHostName()....
336                                     The default enable=yes.],
337, enable_misc=yes )
338
339dnl
340AC_ARG_ENABLE( callstack,
341[--enable-callstack                 - Build MPE callstack routines, i.e.
342                                     MPE_CallStack_xxx()...
343                                     The default enable=yes.],
344, enable_callstack=yes )
345
346dnl
347AC_ARG_ENABLE( logging,
348[--enable-logging                   - Build MPE logging routines for
349                                     CLOG-2, e.g.  MPE_Log_xxx()...
350                                     The default enable=yes.],
351, enable_logging=yes )
352
353dnl
354AC_ARG_ENABLE( wrappers,
355[--enable-wrappers                  - Build various MPI wrapper libraries.
356                                     MPI logging library, liblmpe.a;
357                                     MPI tracing library, libtmpe.a;
358                                     MPI Fortran to C library, libmpe_f2cmpi.a],
359, enable_wrappers=yes )
360dnl  src/wrappers requires at least src/logging
361if test "$enable_wrappers" = "yes" ; then
362    if test "$enable_logging" != "yes" ; then
363        enable_logging=yes
364        AC_MSG_WARN( [Enabling Logging which is required by Wrappers.] );
365    fi
366fi
367
368dnl  Determine if the X graphics is going to be configured
369AC_ARG_ENABLE( graphics,
370[--enable-graphics                  - Build MPE graphics routines and MPI
371                                     animation library, libampe.a.  If disabled
372                                     then the MPE routines that make use of X11
373                                     graphics will NOT be built.  This is
374                                     appropriate for systems that either do not
375                                     have the X11 include files or that do not
376                                     support X11 graphics.
377                                     The default enable=yes.],
378, enable_graphics=yes )
379dnl  src/graphics's libmpe_nompi.a requires mpehname.c defined in src/misc
380dnl  but then libmpe_nompi.a is rarely used, tests in src/grahics will pass
381dnl  without src/misc.  Let user decides.
382if test "$enable_graphics" = "yes" -a "$enable_misc" != "yes" ; then
383    AC_MSG_WARN( [libmpe_nompi.a in src/graphics needs mpehname.c in src/misc!
384	If you need libmpe_nompi.a, reconfigure with --enable-misc.] )
385fi
386
387AC_ARG_ENABLE( collchk,
388[--enable-collchk                   - Build MPI Collective and Datatype
389                                     checking library, libmpe_collchk.a],
390, enable_collchk=yes )
391dnl  src/collchk requires at least src/callstack
392if test "$enable_collchk" = "yes" ; then
393    if test "$enable_callstack" != "yes" ; then
394        enable_callstack=yes
395        AC_MSG_WARN( [Enabling CallStack which is required by CollChk.] );
396    fi
397fi
398
399selected_pkgs=""
400
401if test "$enable_misc" = "yes" -a -s $srcdir/src/misc/configure ; then
402    selected_pkgs="$selected_pkgs misc"
403    AC_CONFIG_SUBDIRS(src/misc)
404fi
405if test "$enable_callstack" = "yes" -a -s $srcdir/src/callstack/configure ; then
406    selected_pkgs="$selected_pkgs callstack"
407    AC_CONFIG_SUBDIRS(src/callstack)
408fi
409if test "$enable_logging" = "yes" -a -s $srcdir/src/logging/configure ; then
410    selected_pkgs="$selected_pkgs logging"
411    AC_CONFIG_SUBDIRS(src/logging)
412fi
413if test "$enable_wrappers" = "yes" -a -s $srcdir/src/wrappers/configure ; then
414    selected_pkgs="$selected_pkgs wrappers"
415    AC_CONFIG_SUBDIRS(src/wrappers)
416fi
417if test "$enable_graphics" = "yes" -a -s $srcdir/src/graphics/configure ; then
418    selected_pkgs="$selected_pkgs graphics"
419    AC_CONFIG_SUBDIRS(src/graphics)
420fi
421if test "$enable_collchk" = "yes" -a -s $srcdir/src/collchk/configure ; then
422    selected_pkgs="$selected_pkgs collchk"
423    AC_CONFIG_SUBDIRS(src/collchk)
424fi
425
426dnl  Determine if the slog2sdk directory is going to be configured.
427AC_ARG_ENABLE( slog2,
428[--enable-slog2{=build}             - Configure all the SLOG-2 tools.
429                                     --enable-slog2 without any argument will
430                                     use the prebuilt jar files.
431                                     --enable-slog2=build will rebuild all the
432                                     jar files from the source code.
433                                     The default is enable=yes.], ,
434enable_slog2=yes )
435
436
437dnl if SLOG-2 is here, configure it
438if test -s $srcdir/$slog2_dirname/configure ; then
439    if test "$enable_slog2" = "yes" -o "$enable_slog2" = "build" ; then
440        if test "$enable_slog2" = "build" ; then
441            slog2_enable_source=yes
442        else
443            slog2_enable_source=no
444        fi
445        export slog2_enable_source
446        dnl  Enable softerror in SLOG2 configure won't abort the entire process
447        slog2_enable_softerror=yes
448        export slog2_enable_softerror
449        selected_pkgs="$selected_pkgs slog2"
450        if test "$MPI_IMPL" = "MPICH" -o "$MPI_IMPL" = "MPICH2" ; then
451            dnl  Disable the SAMPLE code in slog2sdk for MPICH2
452            slog2_enable_sample=no
453            export slog2_enable_sample
454        fi
455        AC_CONFIG_SUBDIRS(src/slog2sdk)
456    fi
457fi
458
459dnl The following statement is no longer true as of 6/24/2007,
460dnl a thread-specific MPE logging on/off switch has been added
461dnl to mpe_log_thread[.h/.c] and MPI logging wrappper library
462dnl has been updated accordingly.
463dnl
464dnl AC_ARG_ENABLE( threadlogging,
465dnl [--enable-threadlogging             - Turn on/off the coarse-grained thread
466dnl                                      support in MPE logging.  The default
467dnl                                      is enable=no.], ,
468dnl enable_threadlogging=no )
469dnl
470dnl When thread-logging is enabled in multi-thread environment,
471dnl safePMPI guard can't be used, i.e. global variables is_mpelog_on
472dnl can't be used in coarse-grained thread support,
473dnl becasue these varaibles need to be thread-specific.  Otherwise
474dnl turn off logging on 1 thread would mean turning it off for all
475dnl threads.
476dnl
477dnl if test "$enable_threadlogging" = "yes" ; then
478dnl     enable_safePMPI=no
479dnl     export enable_safePMPI
480dnl fi
481
482
483AC_ARG_VAR( MPI_CC, [C compiler for MPI program, e.g. mpixlc_r for BG/P MPI, or mpicc from MPICHx, Open-MPI, or LAM-MPI.  Setting MPI_CC to MPI wrapper means no need to set MPI_INC and MPI_LIBS.] )
484AC_ARG_VAR( MPI_F77, [Fortran compiler for MPI program, e.g. mpixlf77_r for BG/P MPI, or mpif77 from MPICHx, Open-MPI, or LAM-MPI.  Setting MPI_F77 to MPI wrapper means no need to set MPI_INC and MPI_LIBS.] )
485AC_ARG_VAR( MPI_INC, [MPI include path prefixed with -I.  It specifies MPI header files location, where mpi.h and mpif.h are located, e.g. -I/pkgs/MPI/include. This flag will be added to MPI_CFLAGS and MPI_FFLAGS, i.e. the MPI include path can be explicitly set in MPI_CFLAGS and MPI_FFLAGS without setting MPI_INC.] )
486AC_ARG_VAR( MPI_CFLAGS, [MPI C compiler flags to compile MPI program.] )
487AC_ARG_VAR( MPI_FFLAGS, [MPI Fortran compiler flags to compile MPI Fortran program.] )
488AC_ARG_VAR( MPI_LIBS, [MPI library flags with -L and -l. It specifies the location of the MPI libraries.  The flags contains library path prefixed with -L and MPI libraries name prefixed with -l, e.g. -L/opt/MPI/lib -lpmpich -lmpich.] )
489dnl AC_ARG_VAR( MPI_LDFLAGS, [MPI linker flags used with MPI_CC or MPI_F77 during linking.] )
490AC_ARG_VAR( MPERUN, [MPI application launch command.  This variable is necessary only if user wants to run "make check", "make installcheck-all" or "$sbindir/mpecheckinstall -run" when the default MPERUN value, "$bindir/mpiexec -n 4", is not correct.] )
491
492# Prepend/Append '"' before/after MPERUN.
493if test "x$MPERUN" != "x" ; then
494    MPERUN="\"$MPERUN\""
495fi
496
497# Preppend MPI_INC to MPI_CFLAGS/MPI_FFLAGS
498if test "x$MPI_INC" != "x" ; then
499    MPI_CFLAGS="$MPI_INC $MPI_CFLAGS"
500    MPI_FFLAGS="$MPI_INC $MPI_FFLAGS"
501fi
502
503dnl
504AC_ARG_WITH( cross-spec,
505[--with-cross-spec=file             - Specify the values of variables that
506                                     configure cannot determine in a
507                                     cross-compilation environment through
508                                     a file], ,
509with_cross_spec=no )
510dnl
511pac_cross_compiling=no
512if test "$with_cross_spec" != "no" ; then
513    if test -s "$with_cross_spec" ; then
514        AC_MSG_RESULT([Reading the cross-compilation file $with_cross_spec])
515        . $with_cross_spec
516        # Autoconf 2.52 no longer sets cross_compiling except with the
517        # awkward "targethost" options.
518        pac_cross_compiling=yes
519        cross_compiling=yes
520        ac_cv_prog_cc_cross=yes
521        ac_cv_prog_f77_cross=yes
522        ac_cv_prog_f90_cross=yes
523        ac_cv_prog_cxx_cross=yes
524        export cross_compiling
525        # Export all the variables in cross_spec/cross_spec.txt
526        # i.e. CROSS_xxx, MPI_xxx and friends...
527        cross_spec_vars=`grep -v '^#' $with_cross_spec | sed -e 's/=.*//g'`
528        for var in $cross_spec_vars ; do
529            eval value=\$"$var"
530            echo "Exporting $var=$value ..."
531            export $var
532        done
533    fi
534fi
535
536
537dnl
538AC_ARG_WITH( config-args,
539[--with-config-args=filename        - Specify configure argument file that
540                                     contains the values of variables that
541                                     configure reads, e.g. CC, CFLAGS,
542                                     F77, FFLAGS, MPI_CC, MPI_F77....
543                                     If the filename does not begin with
544                                     / (absolute path), . or .. (relative path),
545                                     the filename will be assumed to be
546                                     $top_srcdir/configargs/<filename>.cfg.], ,
547with_config_args=no )
548dnl
549if test "$with_config_args" != "no" ; then
550    case "$with_config_args" in
551        /*|../*|./*)
552            config_args_file="$with_config_args"
553            ;;
554        *)
555            config_args_file="$srcdir/configargs/${with_config_args}.cfg"
556            ;;
557    esac
558    if test -s "$config_args_file" ; then
559        AC_MSG_RESULT([Reading the configure arguments in ${config_args_file}.])
560        . $config_args_file
561        # Export all the variables in $config_args_file
562        # i.e. CC, F77, CFLAGS, FFLAGS and friends...
563        config_args_vars=`grep -v '^#' $config_args_file | sed -e 's/=.*//g'`
564        for var in $config_args_vars ; do
565            eval value=\$"$var"
566            echo "Exporting $var=$value ..."
567            export $var
568        done
569    else
570        AC_MSG_WARN([Non-existent ${config_args_file}.])
571    fi
572fi
573
574
575AC_PROG_CC
576dnl Check for broken handling of common symbols
577dnl PAC_PROG_C_BROKEN_COMMON
578
579dnl Adding --enable-strict flags to CFLAGS if needed.
580dnl No space should be added after "(" and before ")", otherwise invalid
581dnl statement, like 'CFLAGS  ="$CFLAGS ..."', will be resulted in configure.
582dnl Also, PAC_GET_GCC_STRICT_FLAGS should be called after AC_PROG_CC.
583if test "$FROM_MPICH2" != "yes" ; then
584    MPE_COPTION=""
585    PAC_GET_GCC_STRICT_FLAGS([MPE_COPTION])
586    if test "x$MPE_COPTION" != "x" ; then
587        CFLAGS="$CFLAGS $MPE_COPTION"
588        MPI_CFLAGS="$MPI_CFLAGS $MPE_COPTION"
589    fi
590fi
591
592dnl  MPI_CC is only use for MPI programs.
593dnl  CC should be the same compiler that is used within the MPI_CC
594dnl  environment.  MPI_LIBS should also be set for linking MPI programs
595AC_MSG_CHECKING( whether MPI_CC has been set )
596if test -z "$MPI_CC" ; then
597    MPI_CC="$CC $MPICPPFLAGS"
598fi
599AC_MSG_RESULT( $MPI_CC )
600
601if test "$MPE_BUILD_FORTRAN2C" = "yes" ; then
602    AC_PROG_F77
603    if test "x$F77" = "x" ; then
604        MPE_BUILD_FORTRAN2C=no
605    fi
606    AC_MSG_CHECKING( whether MPI_F77 has been set )
607    if test -z "$MPI_F77" ; then
608        # FIXME: Temporary for F77 accepting the same flags as CC for
609        # file includes
610        MPI_F77="$F77 $MPICPPFLAGS"
611    fi
612    AC_MSG_RESULT( $MPI_F77 )
613fi
614
615# Determine the name of the various library being built
616if test -z "$MPE_LIBNAME" ; then
617    MPE_LIBNAME=mpe
618fi
619
620
621
622dnl
623dnl  Check if MPI_CC, MPI_CFLAGS, and MPI_LIBS together provide
624dnl  a linkable environment for a simple MPI program
625dnl
626if test "$MPI_IMPL" != "MPICH" -a "$MPI_IMPL" != "MPICH2" ; then
627    if test "$enable_checkMPI" = "yes" ; then
628        AC_MSG_CHECKING( [for the linkage of the supplied MPI C definitions] )
629        PAC_MPI_LINK_CC_FUNC( $MPI_CC, [$MPI_CFLAGS], $MPI_LIBS, , , ,
630                              [ mpe_link_ok=yes ], [ mpe_link_ok=no ] )
631        if test "$mpe_link_ok" = "yes" ; then
632            AC_MSG_RESULT(yes)
633        else
634            AC_MSG_RESULT(no)
635            PAC_MSG_ERROR( $enable_softerror,
636                           [Cannot link with basic MPI C program!
637	Check your MPI include paths, MPI libraries and MPI CC compiler] )
638        fi
639    fi
640    if test "$enable_checkMPI" = "yes" -a "$MPE_BUILD_FORTRAN2C" = "yes" ; then
641        AC_MSG_CHECKING( [for the linkage of the supplied MPI F77 definitions] )
642        PAC_MPI_LINK_F77_FUNC( $MPI_F77, [$MPI_FFLAGS], $MPI_LIBS, [
643        integer mytid
644        integer ierr
645        ], [
646        call MPI_Comm_rank( MPI_COMM_WORLD, mytid, ierr )
647        ],
648        [ mpe_link_ok=yes ], [ mpe_link_ok=no ] )
649        if test "$mpe_link_ok" = "yes" ; then
650            AC_MSG_RESULT(yes)
651        else
652            AC_MSG_RESULT(no)
653            PAC_MSG_ERROR( $enable_softerror,
654                           [Cannot link with basic MPI F77 program!
655	Check your MPI include paths, MPI libraries and MPI F77 compiler ] )
656        fi
657    fi
658
659    dnl
660    dnl Some MPI's seem to have trouble with
661    dnl MPI_Wtime, PMPI_Wtime, and MPI_Attr_get
662    dnl (Fujitsu for MPI_Wtime and MPI_Attr_get; IBM's PMPI_Wtime returned 0)
663    dnl Check at least that we can link with MPI_Wtime and MPI_Attr_get
664    dnl
665    if test "$enable_checkMPI" = "yes" -a "$enable_checkMPIwtime" = "yes" ; then
666        AC_MSG_CHECKING( [for the C version of MPI_Wtime()] )
667        PAC_MPI_LINK_CC_FUNC( $MPI_CC, [$MPI_CFLAGS], $MPI_LIBS, ,
668                              [ double d ],
669                              [ d=MPI_Wtime() ],
670                              [ mpe_link_ok=yes ], [ mpe_link_ok=no ] )
671        if test "$mpe_link_ok" = "yes" ; then
672            AC_MSG_RESULT(yes)
673            AC_DEFINE( HAVE_MPI_WTIME,1,[Define if MPI_Wtime available] )
674        else
675            AC_MSG_RESULT(no)
676            PAC_MSG_ERROR( $enable_softerror, [Cannot link with MPI_Wtime()!
677	Check your MPI include paths, MPI libraries and MPI CC compiler ] )
678        fi
679    fi
680fi
681
682if test -z "$CC" -o -z "$MPI_CC"; then
683    PAC_MSG_ERROR( $enable_softerror,
684                   [You must configure MPE with a specific MPI] )
685fi
686
687if test -n "$F77" -a "$MPE_BUILD_FORTRAN2C" = "yes" ; then
688    FLIBS_save="$FLIBS"
689    FLIBS=""
690    AC_F77_LIBRARY_LDFLAGS
691    # The autoconf macro for finding FLIBS sometimes makes mistakes
692    # (particularly with the Fujitsu frt compiler).  This next step
693    # first sees if the FLIBS is valid with the Fortran compiler
694    PAC_PROG_F77_FLIBS_VALID
695    # Now see if FLIBS works with the C compiler
696    PAC_PROG_F77_CHECK_FLIBS
697
698    PAC_PROG_F77_LINKER_WITH_C
699    PAC_PROG_F77_OBJ_LINKS_WITH_C
700    # For name mangle, we need the library flags
701    PAC_PROG_F77_NAME_MANGLE
702    # Check whether additional libraries are needed when linking with C
703    PAC_PROG_F77_AND_C_STDIO_LIBS
704    AC_SUBST(F77_OTHER_LIBS)
705
706    PAC_PROG_F77_LIBRARY_DIR_FLAG
707    if test -z "$FLIB_PATH_LEADER" ; then
708        FLIB_PATH_LEADER=$F77_LIBDIR_LEADER
709    fi
710    PAC_PROG_F77_HAS_INCDIR(f77tmpdir)
711    FINC_PATH_LEADER=$F77_INCDIR
712
713    # Replace all -I in MPI_FFLAGS by $FINC_PATH_LEADER
714    MPI_FFLAGS=`echo "$MPI_FFLAGS" | sed -e "s|-I|$FINC_PATH_LEADER|g"`
715    # If there is MPI_FLIBS, to replace -L by $FLIB_PATH_LEADER
716fi
717
718dnl  We need to check that this has worked.  The autoconf macro is broken
719AC_PROG_CPP
720if test "$CPP" = "/lib/cpp" -a ! -x /lib/cpp ; then
721    AC_MSG_ERROR( [configure could not find a working C preprocessor] )
722fi
723
724dnl  check for "ln -s" exists.  It is for install program, mpeinstall
725AC_PROG_LN_S
726
727dnl checking for working INSTALL
728AC_PROG_INSTALL
729PAC_PROG_CHECK_INSTALL_WORKS
730PAC_PROG_INSTALL_BREAKS_LIBS
731
732dnl
733dnl MPE_CFLAGS/MPE_FFLAGS are used to pass MPE-modified CFLAGS/FFLAGS
734dnl to other subpackages.  Can't use CFLAGS to pass this info because
735dnl user may have set CFLAGS in the environment.  In that scenario,
736dnl env variable CFLAGS can't be set! So subpackages cannot get the
737dnl MPE-modified CFLAGS.
738dnl
739MPE_CFLAGS="$CFLAGS"
740if test "$MPE_BUILD_FORTRAN2C" = "yes" ; then
741    MPE_FFLAGS="$FFLAGS"
742fi
743
744dnl Determine if this is "UserSupplied" MPI implmentation.
745dnl If so, build mpecc and mpefc.
746dnl    MPE_CLINKER/MPE_FLINKER need to sync with sbin/mpeinstall
747if test "$MPI_IMPL" != "MPICH" -a "$MPI_IMPL" != "MPICH2" ; then
748    mpe_compilers=bin/mpecc
749    if test "$MPE_BUILD_FORTRAN2C" = "yes" ; then
750        mpe_compilers="$mpe_compilers bin/mpefc"
751    fi
752    MPE_CLINKER="$binbuild_dir/mpecc -"
753    MPE_FLINKER="$binbuild_dir/mpefc -"
754else dnl This is MPICH2.
755    MPE_CLINKER="$MPI_CC -mpe="
756    MPE_FLINKER="$MPI_F77 -mpe="
757fi
758
759dnl The following does not work as expected because
760dnl AC_CONFIG_SUBDIRS sets the "precious" variables like CFLAGS from the
761dnl settings recorded at the top of the configure. That means CFLAGS cannot
762dnl be inherit from the mpich2's configure enviroment.
763dnl
764dnl Include --enable-strict option only if this isn't part of MPICHx build.
765dnl MPE does not even need to check enable_strict_done passed down by MPICH2.
766dnl if test "$MPI_IMPL" != "MPICH" -a "$MPI_IMPL" != "MPICH2" ; then
767dnl     MPE_CFLAGS="$MPE_CFLAGS $STRICT_COPTS"
768dnl fi
769dnl
770if test -z "$CLINKER" ; then CLINKER="$CC" ; fi
771if test -z "$FLINKER" ; then FLINKER="$F77" ; fi
772AC_SUBST(MPI_IMPL)
773AC_SUBST(MPE_LIBNAME)
774AC_SUBST(MPE_BUILD_FORTRAN2C)
775dnl "precious" AC_SUBST(CC)
776AC_SUBST(CLINKER)
777AC_SUBST(MPE_CFLAGS)
778dnl "precious" AC_SUBST(MPI_CC)
779dnl "precious" AC_SUBST(MPI_CFLAGS)
780AC_SUBST(MPE_CLINKER)
781AC_SUBST(F77)
782AC_SUBST(FLINKER)
783AC_SUBST(MPE_FFLAGS)
784dnl "precious" AC_SUBST(MPI_F77)
785dnl "precious" AC_SUBST(MPI_FFLAGS)
786AC_SUBST(MPE_FLINKER)
787dnl "precious" AC_SUBST(MPI_LIBS)
788dnl "precious" AC_SUBST(LDFLAGS)
789dnl "precious" AC_SUBST(MPERUN)
790
791dnl  Make the directories that do not contain Makefiles (should they?) but
792dnl  are needed for the subsequent directories.
793$RM -f $srcdir/mpe_conf.h
794
795export MPI_IMPL
796export MPE_LIBNAME
797export MPE_BUILD_FORTRAN2C
798export CC
799export CLINKER
800export MPI_CC
801export MPI_CFLAGS
802export MPE_CLINKER
803export MPE_CFLAGS
804export F77
805export FLINKER
806export MPI_F77
807export MPI_FFLAGS
808export MPE_FLINKER
809export MPE_FFLAGS
810export MPI_LIBS
811export LDFLAGS
812export FINC_PATH_LEADER
813export FLIB_PATH_LEADER
814
815mpe_enable_softerror=yes
816export mpe_enable_softerror
817
818
819
820
821AC_OUTPUT_COMMANDS( [
822if test ! -x ./sbin/mpeinstall -a -s ./sbin/mpeinstall ; then
823    chmod u+x ./sbin/mpeinstall
824fi
825if test ! -x ./sbin/mpecheckinstall -a -s ./sbin/mpecheckinstall ; then
826    chmod u+x ./sbin/mpecheckinstall
827fi
828if test ! -x ./sbin/mpecheckbuild -a -s ./sbin/mpecheckbuild ; then
829    chmod u+x ./sbin/mpecheckbuild
830fi
831if test ! -x ./sbin/mpetestlink -a -s ./sbin/mpetestlink ; then
832    chmod u+x ./sbin/mpetestlink
833fi
834if test ! -x ./sbin/mpetestexec -a -s ./sbin/mpetestexec ; then
835    chmod u+x ./sbin/mpetestexec
836fi
837if test ! -x ./sbin/mpetestexeclog -a -s ./sbin/mpetestexeclog ; then
838    chmod u+x ./sbin/mpetestexeclog
839fi
840if test ! -x ./bin/mpecc -a -s ./bin/mpecc ; then
841    chmod a+x ./bin/mpecc
842fi
843if test ! -x ./bin/mpefc -a -s ./bin/mpefc ; then
844    chmod a+x ./bin/mpefc
845fi
846] )
847AC_OUTPUT( Makefile sbin/mpetestlink sbin/mpetestexec sbin/mpetestexeclog \
848           sbin/mpeinstall sbin/mpecheckinstall sbin/mpecheckbuild \
849           etc/mpe_help.conf etc/mpe_f77env.conf $mpe_compilers )
850
851configured_pkgs=""
852for pkg in $selected_pkgs ; do
853    dirname=${pkg}_dirname
854    eval dirvalue=\$"$dirname"
855    if test -s $dirvalue/Makefile ; then
856        configured_pkgs="$configured_pkgs \"$dirvalue\""
857    fi
858done
859
860if test -z "$configured_pkgs" ; then
861    AC_MSG_WARN([$pkgname: No sub-package has been configured])
862else
863    AC_MSG_RESULT([$pkgname: $configured_pkgs have been configured])
864fi
865