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(cross_conf.h)
14#
15echo "Configuring MPE Cross-Compilation Spec 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/cross_cc.c ; then
20    top_srcdir_abs=$srcdir
21else
22    PAC_GETWD( top_srcdir_abs, cross_cc.c )
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 Cross-Compilation Spec"
33fi
34
35AC_ARG_ENABLE( echo,
36[--enable-echo                      - Turn on strong echoing.
37                                     The default is enable=no.],
38set -x )
39
40VERSION=""
41CC=${CC:-cc}
42F77=${F77:-f77}
43CFLAGS=${CFLAGS}
44FFLAGS=${FFLAGS}
45MAKE=${MAKE:-make}
46
47dnl Fixup for make
48PAC_MAKE_IS_GNUMAKE
49PAC_MAKE_IS_BSD44
50PAC_MAKE_IS_OSF
51PAC_MAKE_VPATH
52AC_SUBST(MAKE)
53
54dnl If we are relying on vpath and no vpath is set, then we must exit
55if test ! -s cross_cc.c -a -z "$VPATH" ; then
56    AC_MSG_ERROR( [No virtual MAKE path command found.
57        You may need to set your make command
58        The GNU make (sometimes available as gnumake) can be used.] )
59fi
60
61RM=rm
62MV=mv
63CPRP=cp
64AC_SUBST(RM)
65AC_SUBST(MV)
66AC_SUBST(CPRP)
67
68AC_ARG_WITH( spec,
69[--with-spec=filename               - Specify the default filename to
70                                     store the cross-compilation
71                                     variables and property values to
72                                     be used in MPE2's --with-cross-spec
73                                     option.  The default filename is
74                                     cross_spec.txt],
75[CROSS_SPEC_FILE=$withval], [CROSS_SPEC_FILE="cross_spec.txt"] )
76dnl Export CROSS_SPEC_FILE so cross_env.in and *.c can use it.
77AC_SUBST(CROSS_SPEC_FILE)
78AC_DEFINE_UNQUOTED( CROSS_SPEC_FILE, "$CROSS_SPEC_FILE",
79                    [Define Cross-Spec's output filename] )
80
81dnl MPE_BUILD_FORTRAN2C=yes means that ALL subpackages will be building
82dnl the fortran2c wrapper libraries.  This does not necessarily mean that
83dnl specific subpackage has to build fortran2c wrapper library.  One example:
84dnl src/wrappers may have --with-f2cmpilibs set by user, so src/wrappers's
85dnl own libmpe_f2cmpi.a will not be built but MPE_BUILD_FORTRAN2C could
86dnl still be set to yes because it means other subpackages like src/graphics
87dnl and src/logging will build their fortran2c wrapper objects.  So treat
88dnl MPE_BUILD_FORTRAN2C as a directive, i.e. generally a necessary but
89dnl insufficient condition to build fortran2c wrapper library.
90AC_ARG_ENABLE( f77,
91[--enable-f77                       - Compile routines that require a Fortran
92                                     compiler.  If configuring with MPICH, the
93                                     configure in the top-level MPICH directory
94                                     will choose the appropriate value for you.
95                                     The default is enable=yes.], ,
96enable_f77=yes )
97if test "$enable_f77" = "yes" ; then
98    MPE_BUILD_FORTRAN2C=yes
99else
100    MPE_BUILD_FORTRAN2C=no
101fi
102
103dnl
104dnl  Unknown MPI implmentation, i.e. User defined MPI_LIBS and MPI_INC
105dnl
106AC_ARG_WITH( mpicc,
107[--with-mpicc=MPI_CC                - C compiler used to compile MPI program
108                                     and to create parallel executable,
109                                     e.g. mpcc for IBM MPI, or mpicc from
110                                     MPICHx or LAM-MPI.],
111MPI_CC="$withval" )
112
113AC_ARG_WITH( mpif77,
114[--with-mpif77=MPI_F77              - F77 compiler used to compile MPI program
115                                     and to create parallel executable,
116                                     e.g. mpxlf for IBM MPI, or mpif77 from
117                                     MPICHx or LAM-MPI.],
118MPI_F77="$withval" )
119
120AC_ARG_WITH( mpiinc,
121[--with-mpiinc=MPI_INC              - MPI compiler's include flags prefixed
122                                     with -I.  It specifies where mpi.h and
123                                     mpif.h are located,
124                                     e.g. -I/pkgs/MPI/include.],
125MPI_INC="$withval" )
126
127AC_ARG_WITH( mpilibs,
128[--with-mpilibs=MPI_LIBS            - MPI compiler's library flags prefixed
129                                     with -L for the library path and prefixed
130                                     with -l for the name of the MPI libraries.
131                                     It specifies the location of the MPI
132                                     libraries.
133                                     e.g. -L/pkgs/MPI/lib -lpmpich -lmpich.],
134MPI_LIBS="$withval" )
135
136AC_ARG_VAR( MPI_LIBS, [MPI compiler's library flags prefixed with -L for the library path and prefixed with -l for the name of the MPI libraries. It specifies the location of the MPI libraries. e.g. -L/pkgs/MPI/lib -lpmpich -lmpich.] )
137
138AC_ARG_VAR( MPI_CC, [C compiler to compile MPI program and to create parallel executable, e.g. mpcc for IBM MPI, or mpicc from MPICHx, Open-MPI, or LAM-MPI.] )
139AC_ARG_VAR( MPI_F77, [Fortran compiler to compile MPI program and to create parallel executable, e.g. mpxlf for IBM MPI, or mpif77 from MPICHx, Open-MPI, or LAM-MPI.] )
140AC_ARG_VAR( MPI_INC, [MPI compiler's include path prefixed with -I.  It specifies 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.] )
141AC_ARG_VAR( MPI_CFLAGS, [MPI C compiler flags to compile MPI program.] )
142AC_ARG_VAR( MPI_FFLAGS, [MPI Fortran compiler flags to compile MPI Fortran program.] )
143AC_ARG_VAR( MPI_LIBS, [MPI compiler library flags which specifies the location of the MPI libraries.  The flags contains library path prefixed with -L and MPI library name prefixed with -l, e.g. -L/opt/MPI/lib -lpmpich -lmpich.] )
144dnl AC_ARG_VAR( MPI_LDFLAGS, [MPI linker flags used with MPI_CC or MPI_F77 during linking.] )
145
146AC_ARG_VAR( MPERUN, [MPI application launch command for the test programs created by this package.  This variable is necessary only if user needs a special command to launch MPI testing application to run in the backend compute nodes.] )
147
148# Preppend MPI_INC to MPI_CFLAGS/MPI_FFLAGS
149if test "x$MPI_INC" != "x" ; then
150    MPI_CFLAGS="$MPI_INC $MPI_CFLAGS"
151    MPI_FFLAGS="$MPI_INC $MPI_FFLAGS"
152fi
153
154AC_PROG_CC
155AC_OBJEXT
156AC_EXEEXT
157AC_HEADER_STDC
158AC_CHECK_HEADERS(stdio.h)
159
160AC_MSG_CHECKING( whether MPI_CC has been set )
161if test -z "$MPI_CC" ; then
162    MPI_CC="$CC $MPICPPFLAGS"
163fi
164AC_MSG_RESULT( $MPI_CC )
165
166if test "$MPE_BUILD_FORTRAN2C" = "yes" ; then
167    AC_PROG_F77
168    if test "x$F77" = "x" ; then
169        MPE_BUILD_FORTRAN2C=no
170    fi
171    AC_MSG_CHECKING( whether MPI_F77 has been set )
172    if test -z "$MPI_F77" ; then
173        # FIXME: Temporary for F77 accepting the same flags as CC for
174        # file includes
175        MPI_F77="$F77 $MPICPPFLAGS"
176    fi
177    AC_MSG_RESULT( $MPI_F77 )
178fi
179
180AC_MSG_CHECKING( [for the linkage of the supplied MPI C definitions] )
181PAC_MPI_LINK_CC_FUNC( $MPI_CC, [$MPI_CFLAGS], $MPI_LIBS, , , ,
182                      [ mpe_link_ok=yes ], [ mpe_link_ok=no ] )
183if test "$mpe_link_ok" = "yes" ; then
184    AC_MSG_RESULT(yes)
185else
186    AC_MSG_RESULT(no)
187    PAC_MSG_ERROR( $enable_softerror,
188                   [Cannot link with basic MPI C program!
189        Check your MPI include paths, MPI libraries and MPI CC compiler] )
190fi
191
192if test "$MPE_BUILD_FORTRAN2C" = "yes" ; then
193    AC_MSG_CHECKING( [for the linkage of the supplied MPI F77 definitions] )
194    PAC_MPI_LINK_F77_FUNC( $MPI_F77, [$MPI_FFLAGS], $MPI_LIBS, [
195        integer mytid
196        integer ierr
197    ], [
198        call MPI_Comm_rank( MPI_COMM_WORLD, mytid, ierr )
199    ], [ mpe_link_ok=yes ], [ mpe_link_ok=no ] )
200    if test "$mpe_link_ok" = "yes" ; then
201        AC_MSG_RESULT(yes)
202    else
203        AC_MSG_RESULT(no)
204        PAC_MSG_ERROR( $enable_softerror,
205                       [Cannot link with basic MPI F77 program!
206        Check your MPI include paths, MPI libraries and MPI F77 compiler ] )
207    fi
208fi
209
210if test -z "$CC" -o -z "$MPI_CC"; then
211    PAC_MSG_ERROR( $enable_softerror,
212                   [You must configure MPE with a specific MPI] )
213fi
214
215if test -n "$F77" -a "$MPE_BUILD_FORTRAN2C" = "yes" ; then
216    FLIBS_save="$FLIBS"
217    FLIBS=""
218    AC_F77_LIBRARY_LDFLAGS
219    # The autoconf macro for finding FLIBS sometimes makes mistakes
220    # (particularly with the Fujitsu frt compiler).  This next step
221    # first sees if the FLIBS is valid with the Fortran compiler
222    PAC_PROG_F77_FLIBS_VALID
223    # Now see if FLIBS works with the C compiler
224    PAC_PROG_F77_CHECK_FLIBS
225
226    PAC_PROG_F77_LINKER_WITH_C
227    # For name mangle, we need the library flags
228    PAC_PROG_F77_NAME_MANGLE
229    # Check whether additional libraries are needed when linking with C
230    PAC_PROG_F77_AND_C_STDIO_LIBS
231    AC_SUBST(F77_OTHER_LIBS)
232
233    PAC_PROG_F77_LIBRARY_DIR_FLAG
234    if test -z "$FLIB_PATH_LEADER" ; then
235        FLIB_PATH_LEADER=$F77_LIBDIR_LEADER
236    fi
237    PAC_PROG_F77_HAS_INCDIR(f77tmpdir)
238    FINC_PATH_LEADER=$F77_INCDIR
239
240dnl Determine MPI_Fint
241dnl (same test done in graphics's configure.ac)
242    AC_MSG_CHECKING( [for MPI_Fint] )
243    PAC_MPI_LINK_CC_FUNC( $MPI_CC, [$MPI_CFLAGS], $MPI_LIBS, ,
244                          [ MPI_Fint aa=1 ], ,
245                          [ mpe_link_ok=yes ], [ mpe_link_ok=no ] )
246    if test "$mpe_link_ok" = "yes" ; then
247        AC_MSG_RESULT(yes)
248        MPI_FINT_TYPE=MPI_Fint
249    else
250        AC_MSG_RESULT([no, assumed MPI_Fint to be int])
251        MPI_FINT_TYPE=int
252        AC_DEFINE( MPI_Fint, int, [Define MPI_Fint as int] )
253    fi
254fi
255
256if test -z "$CLINKER" ; then CLINKER="$CC" ; fi
257if test -z "$FLINKER" ; then FLINKER="$F77" ; fi
258AC_SUBST(MPE_BUILD_FORTRAN2C)
259AC_SUBST(CC)
260AC_SUBST(CLINKER)
261AC_SUBST(MPI_CC)
262AC_SUBST(MPE_CLINKER)
263AC_SUBST(F77)
264AC_SUBST(FLINKER)
265AC_SUBST(MPI_F77)
266AC_SUBST(MPE_FLINKER)
267AC_SUBST(MPI_CFLAGS)
268AC_SUBST(MPI_FFLAGS)
269AC_SUBST(MPI_LIBS)
270AC_SUBST(LDFLAGS)
271AC_SUBST(MPERUN)
272AC_SUBST(AR)
273AC_SUBST(AR_FLAGS)
274AC_SUBST(RANLIB)
275
276AC_OUTPUT_COMMANDS( [
277if test ! -x ./cross_env -a -s ./cross_env ; then
278    chmod u+x ./cross_env
279fi
280] )
281AC_OUTPUT( Makefile cross_env )
282