1# -*- Mode: shell-script -*-
2# build with
3# autoconf --localdir=../confdb configure.ac
4# (or wherever the confdb is)
5#
6AC_PREREQ([2.63])
7
8m4_include([version.m4])
9dnl 2nd arg is intentionally underquoted
10AC_INIT([ROMIO],
11        MPICH2_VERSION_m4,
12        [mpich-discuss@mcs.anl.gov],
13        [romio],
14        [http://www.mcs.anl.gov/research/projects/mpich2/])
15
16dnl AC_CONFIG_AUX_DIR(../../../confdb)
17dnl Set the directory that contains the required install-sh, config.sub,
18dnl and config.guess .  Make sure that these are updated (in MPICH2, use
19dnl the top-level confdb files).  This separate directory is used for
20dnl the moment to allow ROMIO to be separatedly distributed.
21dnl scripts.
22AC_CONFIG_AUX_DIR([confdb])
23AC_CONFIG_MACRO_DIR([confdb])
24
25AM_INIT_AUTOMAKE([-Wall -Werror foreign 1.12.3 silent-rules subdir-objects])
26AM_MAINTAINER_MODE([enable])
27
28AM_PROG_AR
29
30LT_INIT([])
31# Non-verbose make by default
32m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
33
34# VERSION=1.2.6
35# AC_MSG_RESULT([Configuring ROMIO Version $VERSION])
36CONFIGURE_ARGS="$*"
37if test -n "$CONFIGURE_ARGS" ; then
38    echo "Configuring with args $CONFIGURE_ARGS"
39fi
40
41AC_CONFIG_HEADER(adio/include/romioconf.h)
42AH_TOP([/*
43 *  (C) 2011 by Argonne National Laboratory.
44 *      See COPYRIGHT in top-level directory.
45 */
46#ifndef ROMIOCONF_H_INCLUDED
47#define ROMIOCONF_H_INCLUDED
48])
49AH_BOTTOM([
50/* quash PACKAGE and PACKAGE_* vars, see MPICH2 top-level configure.ac for
51 * more info */
52#include "nopackage.h"
53
54#endif /* !defined(ROMIOCONF_H_INCLUDED) */
55])
56
57dnl
58NOF77=0
59NOF90=0
60ARCH=""
61arch_IRIX=""
62MPI_IMPL=""
63MPI_INCLUDE_DIR=""
64ROMIO_INCLUDE=""
65
66# Used by the new build system, should contain zero or more "-Iblah" args for
67# inclusion in AM_CPPFLAGS.  Should not contain relative paths.  This probably
68# overlaps with ROMIO_INCLUDE some, but adding a new var is easier than teasing
69# apart all of the current usages of that variable and re-testing all of the
70# non-MPICH2 and exotic platform cases.
71MPI_H_INCLUDE=""
72AC_SUBST([MPI_H_INCLUDE])
73
74TEST_LIBNAME=""
75FILE_SYSTEM=""
76# Do not set variables to empty that may be communicated from the
77# outside environment (e.g., MPI_LIB, MPI_BIN_DIR, LIBNAME)
78DEBUG=no
79MIPS=0
80BITS=0
81
82AC_ARG_VAR([FROM_MPICH],[set to "yes" if building ROMIO inside of MPICH])
83AC_ARG_VAR([FROM_MPICH2],[set to "yes" if building ROMIO inside of MPICH2])
84FROM_MPICH=${FROM_MPICH:-no}
85FROM_MPICH2=${FROM_MPICH2:-no}
86if test "$FROM_MPICH" = yes -a "$FROM_MPICH2" = yes ; then
87    AC_MSG_WARN([Both FROM_MPICH and FROM_MPICH2 set to yes; at most one should be yes])
88fi
89
90AC_ARG_VAR([FROM_LAM],[set to "yes" if building ROMIO inside of LAM])
91FROM_LAM=${FROM_LAM:-no}
92if test "$FROM_LAM" = 1 ; then FROM_LAM=yes ; fi
93
94CFLAGS=${CFLAGS:-""}
95LL="lld"
96AR_LOCAL=""
97DEFINE_HAVE_MPI_GREQUEST="#undef HAVE_MPI_GREQUEST"
98HAVE_MPI_INFO=""
99BUILD_MPI_INFO=""
100MPI_FINFO1=""
101MPI_FINFO2=""
102MPI_FINFO3=""
103MPI_FINFO4=""
104MPI_FARRAY1=""
105MPI_FARRAY2=""
106MPI_FARRAY3=""
107MPI_FARRAY4=""
108MPI_FARRAY5=""
109MPI_FARRAY6=""
110MPI_FARRAY7=""
111DEFS=""
112ROMIO_LFLAGS=""
113ROMIO_TCFLAGS=""
114ROMIO_TCPPFLAGS=""
115ROMIO_TFFLAGS=""
116NOPROFILE=0
117MPIRUN=""
118FORTRAN_TEST=""
119MAKE=${MAKE:-"make"}
120# foll. needed for f77 test programs
121F77GETARG="call getarg(i,str)"
122F77IARGC="iargc()"
123F77MPIOINC=""
124FTESTDEFINE=""
125FORTRAN_MPI_OFFSET=""
126MPIOF_H_INCLUDED=0
127MPI_OFFSET_KIND1="!"
128MPI_OFFSET_KIND2="!"
129TEST_CC=""
130TEST_F77=""
131TRY_WEAK_SYMBOLS=1
132#
133have_aio=no
134#
135known_mpi_impls="mpich2_mpi mpich_mpi sgi_mpi hp_mpi cray_mpi lam_mpi"
136
137dnl An m4 macro for use with m4_foreach_w and friends.  You should modify this
138dnl list if you want to add a known file system.  The list is just whitespace
139dnl separated, so you can use newlines and tabs as well.
140m4_define([known_filesystems_m4_w],
141          [nfs ufs pfs pvfs pvfs2 testfs xfs panfs gridftp lustre bg bgl bglockless zoidfs hfs piofs sfs])dnl
142dnl
143dnl An m4 macro for use with m4_foreach and friends.  Expands to a quoted list of
144dnl quoted elements.  A bit easier to use without unintended expansion than the
145dnl whitespace version.
146m4_define([known_filesystems_m4], m4_dquote(m4_map_args_w(m4_defn([known_filesystems_m4_w]),[],[],[,])))dnl
147dnl
148# a shell var for checking arguments given via --with-file-system=...
149known_filesystems="m4_join([ ],known_filesystems_m4)"
150
151#####################################################################
152
153#
154# Defaults
155AC_ARG_ENABLE(aio,[
156--enable-aio - Request use of asynchronous I/O routines (default)],
157[
158  if test "x$enableval" = "xno" ; then
159    disable_aio=yes
160  else
161    disable_aio=no
162  fi
163], disable_aio=no)
164AC_ARG_ENABLE(echo,
165[--enable-echo  - Turn on strong echoing. The default is enable=no.] ,set -x)
166AC_ARG_ENABLE(f77,
167[--enable-f77 - Turn on support for Fortran 77 (default)],,enable_f77=yes)
168AC_ARG_ENABLE(f90,
169[--enable-f90 - Turn on support for Fortran 90 (default)],,enable_f90=yes)
170AC_ARG_ENABLE(weak-symbols,
171[--enable-weak-symbols - Turn on support for weak symbols],,enable_weak_symbols=yes)
172AC_ARG_ENABLE(debug,
173[--enable-debug - Build a debugging version],,)
174AC_ARG_WITH(file-system,[
175--with-file-system=name - Build with support for the named file systems],,)
176AC_ARG_WITH(pvfs2,[
177--with-pvfs2=path - Path to installation of PVFS (version 2)],,)
178AC_ARG_WITH(mpi-impl,[
179--with-mpi-impl=name - Specify MPI implementation to build ROMIO for],,)
180dnl
181AC_ARG_WITH(mpi, [
182--with-mpi=path   - Path to instalation of MPI (headers, libs, etc)],,)
183dnl
184if test "$enable_f77" != "yes" ; then
185   NOF77=1
186fi
187if test "$enable_f90" != "yes" ; then
188   NOF90=1
189fi
190if test "$enable_debug" = "yes" ; then
191    DEBUG=yes
192fi
193if test "$enable_weak_symbols" = "no" ; then
194    TRY_WEAK_SYMBOLS=0
195fi
196MPI=$with_mpi
197if test -n "$with_mpi"; then
198       CC=$MPI/bin/mpicc
199fi
200
201# start with the set of file systems that the user asked for
202FILE_SYSTEM=$with_file_system
203
204
205# Check if Make is working
206PAC_PROG_MAKE
207#
208# Check that an arch was set
209# If it wasn't set, try to guess using "util/tarch"
210#
211# Sometimes tarch looses its execute bit (!)
212if test -s $srcdir/util/tarch -a ! -x $srcdir/util/tarch ; then
213    chmod a+x $srcdir/util/tarch
214fi
215if test -z "$ARCH" -a -x $srcdir/util/tarch ; then
216    AC_MSG_CHECKING([for architecture])
217    ARCH=`$srcdir/util/tarch | sed s/-/_/g`
218    if test -z "$ARCH" ; then
219       AC_MSG_RESULT([Unknown!])
220       AC_MSG_ERROR([Error: Could not guess target architecture, you must
221set an architecture type with the environment variable ARCH])
222    fi
223    eval "arch_$ARCH=1"
224    AC_MSG_RESULT($ARCH)
225fi
226#
227# check for valid architecture.  Use __ so that _ALPHA_ does not match
228# LINUX_ALPHA_
229#### WE SHOULD REMOVE THIS SOON
230grep __"$ARCH"_ $srcdir/.config_params > /dev/null 2>&1
231if test $? != 0 ; then
232   AC_MSG_WARN([Unknown architecture $ARCH... proceeding anyway])
233fi
234#
235#
236# Find the home directory if not specified
237if test "X$srcdir" != "X." -a -s $srcdir/mpi-io/Makefile.in ; then
238    ROMIO_HOME_TRIAL=$srcdir
239else
240    # Take advantage of autoconf2 features
241    if test -n "$ac_confdir" ; then
242        ROMIO_HOME_TRIAL=$ac_confdir
243    else
244        if test -s configure ; then
245	    ROMIO_HOME_TRIAL=`pwd`
246	else
247	    ac_confdir=`dirname "$0" 2>/dev/null`
248	    if test -n "$ac_confdir" ; then
249	        ROMIO_HOME_TRIAL=$ac_confdir
250	    fi
251	fi
252    fi
253fi
254AC_MSG_RESULT([ROMIO home directory is $ROMIO_HOME_TRIAL])
255ROMIO_HOME=$ROMIO_HOME_TRIAL
256
257# get a fully qualified pathname for our build directory
258top_build_dir=`pwd`
259# used in romioinstall
260AC_SUBST(top_build_dir)
261
262#
263# Create the "autoconf" style directory names...
264# Most of these are done for us; add the documentation directories
265#
266# mandir is the root for the man pages
267if test -z "$mandir" ; then mandir='${prefix}/man' ; fi
268AC_SUBST(mandir)
269if test -z "$docdir" ; then docdir='${prefix}/doc' ; fi
270AC_SUBST(docdir)
271if test -z "$htmldir" ; then htmldir='${prefix}/www' ; fi
272AC_SUBST(htmldir)
273
274
275# If we are building within a known MPI implementation, we must avoid the
276# tests about an existing implementation
277if test "$FROM_MPICH" != no -o "$FROM_MPICH2" != no -o "$FROM_LAM" != no ; then
278    WITHIN_KNOWN_MPI_IMPL=yes
279else
280    WITHIN_KNOWN_MPI_IMPL=no
281fi
282# check for valid MPI implementation
283if test -n "$MPI_IMPL" ; then
284   found=no
285   for mpi in $known_mpi_impls ; do
286      if test "${MPI_IMPL}_mpi" = "$mpi" ; then
287          found=yes
288	  break
289      fi
290   done
291   if test $found = no ; then
292      AC_MSG_WARN([Unknown MPI implementation $MPI... proceeding anyway])
293   fi
294fi
295#
296
297if test -n "${with_mpi}" ; then
298	MPI_INCLUDE_DIR="${with_mpi}"/include
299	MPI_LIB_DIR="${with_mpi}"/lib
300fi
301
302# check for valid MPI include directory if specified
303if test $WITHIN_KNOWN_MPI_IMPL = no ; then
304   if test -n "$MPI_INCLUDE_DIR"; then
305      if test ! -f "$MPI_INCLUDE_DIR/mpi.h" ; then
306         AC_MSG_ERROR([Include file $MPI_INCLUDE_DIR/mpi.h not found])
307      fi
308   else
309#     assume that mpi.h is in the default path
310#     set MPI_INCLUDE_DIR to ".", so that it translates to -I. in the
311#     compile command. Some compilers complain if it's only -I
312      MPI_INCLUDE_DIR=.
313   fi
314else
315   MPI_INCLUDE_DIR=.
316fi
317#
318# check for valid MPI library if specified
319if test $WITHIN_KNOWN_MPI_IMPL = no ; then
320   if test -n "$MPI_LIB" ; then
321      if test ! -f "$MPI_LIB" ; then
322         AC_MSG_ERROR([MPI library $MPI_LIB not found])
323      fi
324   fi
325fi
326
327# USER_CFLAGS and USER_FFLAGS are used only in test/Makefile.in
328if test $DEBUG = "yes"; then
329    USER_CFLAGS="$CFLAGS -g"
330    USER_FFLAGS="$FFLAGS -g"
331else
332    USER_CFLAGS="$CFLAGS -O"
333    USER_FFLAGS="$FFLAGS -O"
334fi
335#
336# Here begin the architecture-specific tests.
337# --------------------------------------------------------------------------
338# We must first select the C and Fortran compilers.  Because of the
339# way that the PROG_CC autoconf macro works (and all of the macros that
340# require it, including CHECK_HEADERS), that macro must occur exactly
341# once in the configure.ac file, at least as of autoconf 2.57 .
342# Unfortunately, this requirement is not enforced.  To handle this,
343# we first case on the architecture; then use PROG_CC, then case on the
344# architecture again for any arch-specific features.  We also set the
345# C_DEBUG_FLAG and F77_DEBUG_FLAG in case debugging is selected.
346#
347# For the MPICH and MPICH2 configures, the compilers will already be
348# selected, so most of the compiler-selection code will be bypassed.
349# --------------------------------------------------------------------------
350# For historical reasons
351if test -z "$FC" ; then
352    FC=$F77
353fi
354#
355C_DEBUG_FLAG="-g"
356F77_DEBUG_FLAG="-g"
357# C_OPT_FLAG=${CFLAGS:-"-O"}
358# MPICH1 uses OPTFLAGS and OPTFLAGSC to specify separate optimization
359# flags for the C compiler (this is better that adding it to the
360# undifferentiated CFLAGS, at least on input).
361if test -n "$OPTFLAGS" ; then
362    C_OPT_FLAG="$C_OPT_FLAG $OPTFLAGS"
363fi
364if test -n "$OPTFLAGSC" ; then
365    C_OPT_FLAG="$C_OPT_FLAG $OPTFLAGSC"
366fi
367case $ARCH in
368     solaris|solaris86)
369     CC=${CC:-cc}
370     F77=${FC:-f77}
371     if test "$CC" != "gcc" ; then
372	C_DEBUG_FLAG="-g -v"
373     fi
374     ;;
375
376     rs6000)
377     F77=${FC}
378     # Try to use mpcc if no CC specified
379     AC_PROGRAMS_CHECK(CC, mpcc, cc)
380     if test $NOF77 = 0 && test -z "$F77"; then
381        AC_PROGRAMS_CHECK(F77, mpxlf, f77)
382     fi
383     ;;
384
385     tflop|tflops)
386     CC=${CC:-pgcc}
387     F77=${FC:-pgf77}
388     CFLAGS="$CFLAGS -cougar -D__PUMA"
389     if test "$CC" = "pgcc" ; then
390         C_OPT_FLAG="-Knoieee -Mvect -O3"
391     fi
392     ;;
393
394     freebsd|LINUX|netbsd|openbsd|LINUX_ALPHA)
395     CC=${CC:-gcc}
396     # Let the prog_f77 file g77/f77/others
397     F77=${FC}
398     ;;
399
400     SX4)
401     CC=${CC:-mpicc}
402     F77=${FC:-mpif90}
403     if test $DEBUG != "yes" ; then
404        USER_FFLAGS="$FFLAGS -Chopt"
405        F77_OPT_FLAG="-Chopt"
406    fi
407    ;;
408
409    hpux|sppux)
410    C_DEBUG_FLAG="-g +w1"
411    ;;
412
413    alpha|ALPHA)
414    CC=${CC:-cc}
415    F77=${FC:-f77}
416    dnl CFLAGS="$CFLAGS -g -std1 -warnprotos -verbose"
417    C_DEBUG_FLAG="-g -verbose"
418    ;;
419
420    CRAY)
421    CC=${CC:-cc}
422    F77=${FC:-f90}
423    NOF77=1
424    CFLAGS="$CFLAGS -D_UNICOS"
425    ;;
426
427    sgi|IRIX64|IRIX32|IRIXN32)
428    arch_IRIX=1
429    CC=${CC:-cc}
430    F77=${FC:-f77}
431    C_DEBUG_FLAG="-g -fullwarn"
432    ;;
433
434    sgi5)
435    ;;
436
437    *)
438    # Fall-through case.  Take FC
439    F77=${FC:-f77}
440    ;;
441esac
442
443PAC_PROG_CC
444
445dnl AC_PROG_{CXX,F77,FC} must come early in configure.ac in order to control
446dnl compiler search order and avoid some esoteric autoconf macro expansion
447dnl errors
448if test "$enable_f77" = "yes" ; then
449    # suppress default "-g -O2" from AC_PROG_F77
450    : ${FFLAGS=""}
451    AC_PROG_F77([PAC_F77_SEARCH_LIST])
452fi
453if test "$enable_f90" = "yes" ; then
454    # suppress default "-g -O2" from AC_PROG_FC
455    : ${FCFLAGS=""}
456    AC_PROG_FC([PAC_FC_SEARCH_LIST])
457fi
458
459if test "$CC" = "gcc" -a -z "$C_DEBUG_FLAG" ; then
460     C_DEBUG_FLAG="-g -O -Wall -Wstrict-prototypes -Wmissing-prototypes"
461fi
462if test $DEBUG = "yes" ; then
463    CFLAGS="$CFLAGS $C_DEBUG_FLAG"
464else
465    CFLAGS="$CFLAGS $C_OPT_FLAG"
466fi
467# ---------------------------------------------------------------------------
468# Here go the rest of the tests
469# ---------------------------------------------------------------------------
470if test -n "$arch_solaris" || test -n "$arch_solaris86" ; then
471    if test -z "$MPI_IMPL" ; then
472        MPI_IMPL=mpich
473        mpi_mpich=1
474    fi
475    if test $MPI_IMPL = "mpich" ; then
476        TEST_CC=mpicc
477        TEST_F77=mpif77
478    else
479        TEST_CC="$CC"
480        TEST_F77="$F77"
481    fi
482fi
483
484
485if test -n "$arch_rs6000"; then
486    if test -z "$MPI_IMPL" ; then
487        MPI_IMPL=mpich
488        mpi_mpich=1
489    fi
490    AC_DEFINE(AIX,1,[Define for AIX])
491# assume long long exists.
492    ac_cv_sizeof_long_long=${ac_cv_sizeof_long_long:-8}
493    MPI_OFFSET_KIND1="      INTEGER MPI_OFFSET_KIND"
494    MPI_OFFSET_KIND2="      PARAMETER (MPI_OFFSET_KIND=8)"
495    MPI_OFFSET_KIND_VAL=8
496fi
497#
498
499if test -n "$arch_freebsd" || test -n "$arch_LINUX" || test -n "$arch_LINUX_ALPHA" || test -n "$arch_netbsd" || test -n "$arch_openbsd" ; then
500    if test -n "$arch_freebsd" || test -n "$arch_netbsd" || test -n "$arch_openbsd"; then
501        ac_cv_sizeof_long_long=${ac_cv_sizeof_long_long:-0}
502	# printf doesn't work properly and no integer*8 as far as I can tell
503    fi
504    # Find the CPP before the header check
505    AC_PROG_CPP
506    if test -z "$MPI_IMPL" ; then
507        MPI_IMPL=mpich
508        mpi_mpich=1
509    fi
510fi
511#
512if test -n "$arch_SX4" ; then
513    have_aio=no
514    AC_DEFINE(SX4,1,[Define for NEC SX4])
515    if test -z "$MPI_IMPL" ; then
516        MPI_IMPL=mpich
517        mpi_mpich=1
518    fi
519    # supply a reasonable default fs
520    if test -z "$FILE_SYSTEM" ; then
521        FILE_SYSTEM="sfs nfs"
522    fi
523    MPI_OFFSET_KIND1="      INTEGER MPI_OFFSET_KIND"
524    MPI_OFFSET_KIND2="      PARAMETER (MPI_OFFSET_KIND=8)"
525    MPI_OFFSET_KIND_VAL=8
526fi
527#
528if test -n "$arch_hpux" || test -n "$arch_sppux" ; then
529    have_aio=no
530    RANLIB=":"
531    if test -z "$MPI_IMPL"; then
532        if test -f "/opt/mpi/include/mpi.h" ; then
533            echo "assuming that you want to use ROMIO with HP MPI"
534            MPI_IMPL=hp
535        else
536            echo "assuming that you want to use ROMIO with MPICH"
537            MPI_IMPL=mpich
538        fi
539    fi
540    if test $MPI_IMPL = "mpich" ; then
541        mpi_mpich=1
542        MPI_LIB="$MPI_LIB -lV3"
543        CC=${CC:-cc -Ae}
544        F77=${FC:-f77 +U77}
545    fi
546    if test $MPI_IMPL = "hp" ; then
547        mpi_hp=1
548        CC=${CC:-mpicc -Ae}
549        F77=${FC:-mpif77 +U77}
550    fi
551    if test $MPI_IMPL = "lam" && test "$FC" != ""; then
552        F77="$F77 +U77"
553    fi
554    FTESTDEFINE="external iargc, getarg"
555    if test -n "$arch_hpux" ; then
556        CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE"
557        AC_DEFINE(HPUX,1,[Define for HPUX])
558        if test $MPI_IMPL = "hp" ; then
559           F77=${FC:-mpif90 +U77}
560        else
561           F77=${FC:-f90 +U77}
562        fi
563    else
564        AC_DEFINE(SPPUX,1,[Define for SPPUX (Convex)])
565    fi
566
567    MPI_OFFSET_KIND1="      INTEGER MPI_OFFSET_KIND"
568    MPI_OFFSET_KIND2="      PARAMETER (MPI_OFFSET_KIND=8)"
569    MPI_OFFSET_KIND_VAL=8
570    if test "$CC" != "gcc" ; then
571        ROMIO_TCFLAGS="-Ae"
572    fi
573    if test "$F77" != "g77" ; then
574        ROMIO_TFFLAGS="+U77"
575    fi
576fi
577#
578if test -n "$arch_alpha" || test -n "$arch_ALPHA" ; then
579    if test -z "$MPI_IMPL" ; then
580        MPI_IMPL=mpich
581        mpi_mpich=1
582    fi
583
584    MPI_OFFSET_KIND1="      INTEGER MPI_OFFSET_KIND"
585    MPI_OFFSET_KIND2="      PARAMETER (MPI_OFFSET_KIND=8)"
586    MPI_OFFSET_KIND_VAL=8
587    LIBS="$LIBS -laio"
588fi
589#
590if test -n "$arch_CRAY" ; then
591    NOF77=1
592    FTESTDEFINE="integer ilen"
593    F77GETARG="call pxfgetarg(i, str, ilen, ierr)"
594    have_aio=no
595    RANLIB=":"
596    AC_DEFINE(CRAY,1,[Define if Cray])
597    if test -z "$MPI_IMPL" || test -n "$mpi_sgi" ; then
598        MPI_IMPL=cray
599        mpi_cray=1
600        mpi_sgi=""
601# above is to disable configure tests specific to SGI MPI
602        AC_DEFINE(MPISGI,1,[Define if SGI MPI])
603        AC_DEFINE(HAVE_MPI_COMBINERS,1,[Define if MPI supports datatype combiners])
604        AC_DEFINE(NO_MPI_SGI_type_is_contig,1,[Define if no types show contig])
605    fi
606#       MPISGI needed because of error in Cray's and SGI's
607#       MPI_Type_get_contents (does not increment reference count).
608#       Others needed because MPISGI needed.
609
610    MPI_OFFSET_KIND1="      INTEGER MPI_OFFSET_KIND"
611    MPI_OFFSET_KIND2="      PARAMETER (MPI_OFFSET_KIND=8)"
612    MPI_OFFSET_KIND_VAL=8
613fi
614#
615if test -n "$arch_sgi" ; then
616    arch_IRIX=1
617    ARCH=IRIX
618fi
619if test -n "$arch_IRIX64" || test -n "$arch_IRIX32" || test -n "$arch_IRIXN32" ; then
620    arch_IRIX=1
621fi
622if test -n "$arch_sgi5" ; then
623    arch_IRIX5=1
624    ARCH=IRIX
625fi
626#
627PAC_GET_SPECIAL_SYSTEM_INFO
628#
629# special case 'sgi5' for use on MESHINE which is much like an SGI running
630# irix 5 with r4400 chips, but does not have 'hinv', so above code doesn't
631# work
632if test -n "$arch_sgi5"; then
633   osversion=5
634   cputype=4400
635   IRIXARCH="$ARCH_$osversion"
636   IRIXARCH="$IRIXARCH_$cputype"
637# now set arch_IRIX to 1
638   arch_IRIX=1
639   echo "IRIX-specific architecture is $IRIXARCH"
640   AC_DEFINE(IRIX,1,[Define if IRIX])
641fi
642#
643if test -n "$arch_IRIX"; then
644   if test $osversion = 4 ; then
645	RANLIB="ar ts"
646        if test -n "$mpi_sgi"; then
647            AC_MSG_ERROR([SGI\'s MPI does not work with IRIX 4.x])
648        fi
649   elif test $osversion = 5 ; then
650        if test -n "$mpi_sgi"; then
651            AC_MSG_ERROR([SGI\'s MPI does not work with IRIX 5.x])
652        fi
653   elif test $osversion = 6 ; then
654	if test -z "$MPI_IMPL"; then
655	    if test "$FROM_MPICH2" = "yes" ; then
656	        # Building with MPICH2.  Distinguish from MPICH-1
657		MPI_IMPL=mpich2
658		mpi_mpich2=1
659            elif test -f "/usr/include/mpi.h" ; then
660                # removed use of escaped single quotes in messages
661		# because they confuse Emacs, making it hard to
662		# read the files (with emacs :) )
663                AC_MSG_WARN([assuming that you want to use ROMIO with the SGI MPI])
664                MPI_IMPL=sgi
665                mpi_sgi=1
666            else
667	        AC_MSG_WARN([assuming that you want to use ROMIO with MPICH])
668                MPI_IMPL=mpich
669                mpi_mpich=1
670            fi
671	fi
672        RANLIB=":"
673        AC_DEFINE(AIO_SIGNOTIFY_NONE,1,[Define if no signotify])
674	if test $cputype -ge 5000 ; then
675            MIPS=4
676        else
677            MIPS=3
678        fi
679   fi
680   if test -n "$mpi_sgi" && test -z "$MPI_LIB" ; then
681       MPI_LIB="-lmpi"
682   fi
683#  check if pread64 is defined
684   PAC_HAVE_PREAD64
685
686   # supply a reasonable default fs
687   if test -z "$FILE_SYSTEM" ; then
688       FILE_SYSTEM="nfs"
689       AC_MSG_CHECKING(for xfs)
690       AC_TRY_COMPILE([
691#include <aio.h>],
692[aiocb64_t *t1;],xfs_works=1;FILE_SYSTEM="xfs $FILE_SYSTEM";)
693       if test "$xfs_works" = 1 ; then
694          AC_MSG_RESULT(yes)
695       else
696          AC_MSG_RESULT(no)
697          FILE_SYSTEM="ufs $FILE_SYSTEM"
698       fi
699   fi
700   AC_DEFINE(IRIX,1,[Define if IRIX])
701   MPI_OFFSET_KIND1="      INTEGER MPI_OFFSET_KIND"
702   MPI_OFFSET_KIND2="      PARAMETER (MPI_OFFSET_KIND=8)"
703   MPI_OFFSET_KIND_VAL=8
704fi
705
706AC_HAVE_FUNCS(memalign)
707
708#
709# Question: Should ROMIO under MPICH2 ignore the Fortran tests, since
710# MPICH2 provides all of the Fortran interface routines?
711#
712if test $NOF77 = 0 ; then
713    echo "checking Fortran external names"
714    PAC_GET_FORTNAMES
715    if test -n "$WDEF" ; then
716        CFLAGS="$CFLAGS $WDEF"
717    fi
718    dnl PAC_PROG_F77_NAME_MANGLE
719    dnl (need to set the new name format)
720    rm -f test/mpif.h
721    if test "$MPI_INCLUDE_DIR" != "." && test $WITHIN_KNOWN_MPI_IMPL = no ; then
722        if test ! -d test ; then mkdir test ; fi
723        ln -s $MPI_INCLUDE_DIR/mpif.h test
724    fi
725else
726    F77=":"
727fi
728#
729AC_C_INLINE
730
731# Header files
732# Find the CPP before the header check
733AC_PROG_CPP
734AC_CHECK_HEADERS([unistd.h fcntl.h malloc.h stddef.h sys/types.h])
735#
736
737# When compiling ROMIO on Darwin with _POSIX_C_SOURCE defined (such as when
738# using --enable-strict in MPICH2), sys/types.h does not define u_short and
739# friends unless _DARWIN_C_SOURCE is also defined (see compat(5) on a Darwin
740# box).  This would normally be fine, except sys/stat.h defines struct stat to
741# use u_long, so strict compiles fail.  One option is to also compile with
742# _DARWIN_C_SOURCE, but this disables much of the strictness that is intended
743# by _POSIX_C_SOURCE.  Instead we just define our own types if they are not
744# provided by the system.  This isn't quite as safe as typedef'ing the
745# replacement types, but it will apply to later configure tests, which is
746# important.
747AC_CHECK_TYPE([u_char],[],[AC_DEFINE_UNQUOTED([u_char],[unsigned char],[Define to "unsigned char" if sys/types.h does not define.])])
748AC_CHECK_TYPE([u_short],[],[AC_DEFINE_UNQUOTED([u_short],[unsigned short],[Define to "unsigned short" if sys/types.h does not define.])])
749AC_CHECK_TYPE([u_int],[],[AC_DEFINE_UNQUOTED([u_int],[unsigned int],[Define to "unsigned int" if sys/types.h does not define.])])
750AC_CHECK_TYPE([u_long],[],[AC_DEFINE_UNQUOTED([u_long],[unsigned long],[Define to "unsigned long" if sys/types.h does not define.])])
751
752# must come _after_ the above checks for u_char/u_short/u_int/u_long
753AC_CHECK_HEADERS([sys/attr.h])
754
755AC_CHECK_SIZEOF(int)
756AC_CHECK_SIZEOF(void *)
757AC_CACHE_CHECK([for int large enough for pointers],
758pac_cv_int_hold_pointer,[
759if test "$ac_cv_sizeof_int" = "0" -o \
760	"$ac_cv_sizeof_void_p" = "0" ; then
761    pac_cv_int_hold_pointer=unknown
762elif test "$ac_cv_sizeof_int" -lt "$ac_cv_sizeof_void_p" ; then
763    pac_cv_int_hold_pointer=no
764else
765    pac_cv_int_hold_pointer=yes
766fi
767])
768if test "$pac_cv_int_hold_pointer" != yes ; then
769    AC_DEFINE(INT_LT_POINTER,1,[Define if int smaller than pointer])
770    dnl Switch to a conforming name (start with HAVE or USE)
771    AC_DEFINE(HAVE_INT_LT_POINTER,1,[Define if int smaller than pointer])
772fi
773
774# LL is the printf-style format name for output of a MPI_Offset.
775# We have to match this to the type that we use for MPI_Offset.
776AC_CHECK_SIZEOF(long long)
777if test "$ac_cv_sizeof_long_long" != 0 ; then
778    if test "$ac_cv_sizeof_long_long" = "8" ; then
779       AC_DEFINE(HAVE_LONG_LONG_64,1,[Define if long long is 64 bits])
780       MPI_OFFSET_TYPE="long long"
781       DEFINE_MPI_OFFSET="typedef long long MPI_Offset;"
782       FORTRAN_MPI_OFFSET="integer*8"
783       LL="lld"
784    elif test "$ac_cv_sizeof_long_long" = "$ac_cv_sizeof_int" ; then
785       MPI_OFFSET_TYPE="int"
786       DEFINE_MPI_OFFSET="typedef int MPI_Offset;"
787       FORTRAN_MPI_OFFSET="integer"
788       AC_DEFINE(MPI_OFFSET_IS_INT,1,[Define if MPI_Offset is int])
789       LL="d"
790       MPI_OFFSET_KIND1="!"
791       MPI_OFFSET_KIND2="!"
792    else
793       echo "defining MPI_Offset as long in C and integer in Fortran"
794       MPI_OFFSET_TYPE="long"
795       DEFINE_MPI_OFFSET="typedef long MPI_Offset;"
796       FORTRAN_MPI_OFFSET="integer"
797       LL="ld"
798       MPI_OFFSET_KIND1="!"
799       MPI_OFFSET_KIND2="!"
800    fi
801else
802    echo "defining MPI_Offset as long in C and integer in Fortran"
803    MPI_OFFSET_TYPE="long"
804    DEFINE_MPI_OFFSET="typedef long MPI_Offset;"
805    FORTRAN_MPI_OFFSET="integer"
806    LL="ld"
807    MPI_OFFSET_KIND1="!"
808    MPI_OFFSET_KIND2="!"
809fi
810
811
812#
813if test -n "$ac_cv_sizeof_long_long"; then
814   if test $WITHIN_KNOWN_MPI_IMPL = no ; then
815       PAC_MPI_LONG_LONG_INT
816   else
817       AC_DEFINE(HAVE_MPI_LONG_LONG_INT,1,[Define if supports long long int])
818   fi
819fi
820#
821if test -n "$OFFSET_KIND" -a "A$MPI_OFFSET_KIND1" = "A!" ; then
822  MPI_OFFSET_KIND1="        INTEGER MPI_OFFSET_KIND"
823  MPI_OFFSET_KIND2="        PARAMETER (MPI_OFFSET_KIND=$OFFSET_KIND)"
824  MPI_OFFSET_KIND_VAL=$OFFSET_KIND
825else
826 if test "$FORTRAN_MPI_OFFSET" = "integer*8" && test "A$MPI_OFFSET_KIND2" = "A!" && test $NOF77 = 0 && test $NOF90 = 0 ; then
827   PAC_MPI_OFFSET_KIND
828 fi
829 #
830  if test "$FORTRAN_MPI_OFFSET" = "integer" && test "A$MPI_OFFSET_KIND2" = "A!" && test $NOF77 = 0 && test $NOF90 = 0 ; then
831   PAC_MPI_OFFSET_KIND_4BYTE
832  fi
833fi
834#
835# Test that we can use the FORTRAN_MPI_OFFSET type.  If the environment
836# is a strict Fortran 90/95 or later compiler, the "integer*8" format
837# may not work.
838if test "$NOF77" = 0 ; then
839    rm -f conftest*
840    ac_cv_f77_offset_type_works=no
841    AC_MSG_CHECKING([that we can use $FORTRAN_MPI_OFFSET to declare MPI_DISPLACMENT_CURRENT])
842    cat >conftest.f <<EOF
843        program main
844        $FORTRAN_MPI_OFFSET j
845        end
846EOF
847    if $F77 -o conftest$EXEEXT conftest.f >>config.log 2>&1 && test -x conftest$EXEEXT ; then
848        ac_cv_f77_offset_type_works=yes
849    fi
850    rm -f conftest*
851    AC_MSG_RESULT($ac_cv_f77_offset_type_works)
852
853    if test "$ac_cv_f77_offset_type_works" != "yes" -a -n "$MPI_OFFSET_KIND_VAL"; then
854        AC_MSG_CHECKING([whether we can use KIND with the selected F77 compiler $F77])
855        ac_cv_f77_allows_offset_kind=no
856        rm -f conftest*
857        cat >conftest.f <<EOF
858        program main
859        integer (kind=$MPI_OFFSET_KIND_VAL) j
860        end
861EOF
862        if $F77 -o conftest$EXEEXT conftest.f >>config.log 2>&1 && test -x conftest$EXEEXT ; then
863            ac_cv_f77_allows_offset_kind=yes
864        fi
865        rm -f conftest*
866        AC_MSG_RESULT($ac_cv_f77_allows_offset_kind)
867        if test "$ac_cv_f77_allows_offset_kind" ; then
868             FORTRAN_MPI_OFFSET="integer (kind=$MPI_OFFSET_KIND_VAL)"
869        else
870             AC_MSG_WARN([Could not find a way to declare an integer type corresponding to MPI_Offset in Fortran.])
871        fi
872    fi
873fi
874
875#
876# check if MPI_Info functions are defined in the MPI implementation
877if test $WITHIN_KNOWN_MPI_IMPL = no ; then
878   PAC_MPI_INFO
879else
880   AC_DEFINE(HAVE_MPI_INFO,1,[Define if MPI Info is available])
881   HAVE_MPI_INFO="#define HAVE_MPI_INFO"
882   MPI_FINFO1="!"
883   MPI_FINFO2="!"
884   MPI_FINFO3="!"
885   MPI_FINFO4="!"
886fi
887#
888if test -n "$mpi_sgi"; then
889dnl   if test -z "$HAVE_MPI_INFO" ; then
890dnl      PAC_CHECK_MPI_SGI_INFO_NULL  # is MPI_INFO_NULL defined in mpi.h?
891dnl   fi
892   PAC_TEST_MPI_SGI_type_is_contig
893   PAC_TEST_MPI_COMBINERS
894   PAC_TEST_MPI_HAVE_OFFSET_KIND
895fi
896#
897# check if darray and subarray constructors are defined in the MPI
898# implementation
899if test $WITHIN_KNOWN_MPI_IMPL = no ; then
900   PAC_MPI_DARRAY_SUBARRAY
901fi
902if test $FROM_MPICH2 = yes ; then
903   dnl Made this a message instead of a warning because the warning is
904   dnl likely to confuse users.
905   AC_MSG_RESULT([Overriding Array test for MPICH2])
906   unset BUILD_MPI_ARRAY
907   AC_DEFINE(HAVE_MPI_DARRAY_SUBARRAY,1,[Define if Darray is available])
908   HAVE_MPI_DARRAY_SUBARRAY="#define HAVE_MPI_DARRAY_SUBARRAY"
909   MPI_FARRAY1="!"
910   MPI_FARRAY2="!"
911   MPI_FARRAY3="!"
912   MPI_FARRAY4="!"
913   MPI_FARRAY5="!"
914   MPI_FARRAY6="!"
915   MPI_FARRAY7="!"
916fi
917#
918#
919# Test for weak symbol support...
920# We can't put # in the message because it causes autoconf to generate
921# incorrect code
922HAVE_WEAK_SYMBOLS=0
923if test -n "$arch_hpux" || test -n "$arch_sppux" ; then
924# multiple secondary definitions not allowed by HP compilers
925# Fortran interface for HP already uses one secondary defn.
926# therefore, do not use this method for profiling interface.
927# build profiling interface explicitly.
928   TRY_WEAK_SYMBOLS=0
929fi
930if test $TRY_WEAK_SYMBOLS = 1 ; then
931  AC_MSG_CHECKING([for weak symbol support])
932  AC_TRY_LINK([
933extern int PFoo(int);
934#pragma weak PFoo = Foo
935int Foo(int a) { return a; }
936],[return PFoo(1);],has_pragma_weak=1)
937  #
938  # Some systems (Linux ia64 and ecc, for example), support weak symbols
939  # only within a single object file!  This tests that case.
940  # Note that there is an extern int PFoo declaration before the
941  # pragma.  Some compilers require this in order to make the weak symbol
942  # extenally visible.
943if test "$has_pragma_weak" = 1 ; then
944    AC_MSG_RESULT([pragma weak])
945    AC_MSG_CHECKING([that weak symbols are visible to other files])
946    rm -f conftest*
947    cat >>conftest1.c <<EOF
948extern int PFoo(int);
949#pragma weak PFoo = Foo
950int Foo(int);
951int Foo(int a) { return a; }
952EOF
953    cat >>conftest2.c <<EOF
954extern int PFoo(int);
955int main(int argc, char **argv) {
956return PFoo(0);}
957EOF
958    ac_link2='${CC-cc} -o conftest$EXEEXT $CFLAGS $CPPFLAGS $LDFLAGS conftest1.c conftest2.c $LIBS >conftest.out 2>&1'
959    if eval $ac_link2 ; then
960        AC_MSG_RESULT(yes)
961        AC_MSG_CHECKING([that the compiler correctly implements weak symbols])
962        # The gcc 3.4.x compiler accepts the pragma weak, but does not
963        # correctly implement it on systems where the loader doesn't
964        # support weak symbols (e.g., cygwin).  This is a bug in gcc, but it
965        # it is one that *we* have to detect.
966        rm -f conftest*
967        cat >>conftest1.c <<EOF
968extern int PFoo(int);
969#pragma weak PFoo = Foo
970int Foo(int);
971int Foo(int a) { return a; }
972EOF
973    cat >>conftest2.c <<EOF
974extern int Foo(int);
975int PFoo(int a) { return a+1;}
976int main(int argc, char **argv) {
977return Foo(0);}
978EOF
979        if eval $ac_link2 ; then
980            AC_MSG_RESULT(yes)
981            has_pragma_weak=1
982        else
983            AC_MSG_RESULT(no)
984            echo "$ac_link2" >> config.log
985	    echo "Failed program was" >> config.log
986            cat conftest1.c >>config.log
987            cat conftest2.c >>config.log
988            if test -s conftest.out ; then cat conftest.out >> config.log ; fi
989            has_pragma_weak=0
990        fi
991    else
992      echo "$ac_link2" 1>&AC_FD_CC
993      echo "Failed program was" 1>&AC_FD_CC
994      cat conftest1.c 1>&AC_FD_CC
995      cat conftest2.c 1>&AC_FD_CC
996      if test -s conftest.out ; then cat conftest.out 1>&AC_FD_CC ; fi
997      AC_MSG_RESULT(no)
998      has_pragma_weak=0
999    fi
1000    rm -f conftest*
1001  fi
1002  if test "$has_pragma_weak" = 1 ; then
1003    HAVE_WEAK_SYMBOLS=1
1004    AC_DEFINE(HAVE_PRAGMA_WEAK,1,[Define if pragma weak available])
1005  else
1006    AC_TRY_LINK([
1007extern int PFoo(int);
1008#pragma _HP_SECONDARY_DEF Foo PFoo
1009int Foo(int a) { return a; }
1010],[return PFoo(1);],has_pragma_hp_secondary=1)
1011    if test "$has_pragma_hp_secondary" = 1 ; then
1012        AC_MSG_RESULT([pragma _HP_SECONDARY_DEF])
1013        HAVE_WEAK_SYMBOLS=1
1014        AC_DEFINE(HAVE_PRAGMA_HP_SEC_DEF,1,[Define for HP weak pragma])
1015    else
1016        AC_TRY_LINK([
1017extern int PFoo(int);
1018#pragma _CRI duplicate PFoo as Foo
1019int Foo(int a) { return a; }
1020],[return PFoo(1);],has_pragma_cri_duplicate=1)
1021        if test "$has_pragma_cri_duplicate" = 1 ; then
1022	    AC_MSG_RESULT([pragma _CRI duplicate x as y])
1023	    HAVE_WEAK_SYMBOLS=1
1024	    AC_DEFINE(HAVE_PRAGMA_CRI_DUP,1,[Define for CRAY weak dup])
1025        else
1026            AC_MSG_RESULT(no)
1027        fi
1028    fi
1029  fi
1030fi
1031if test "$HAVE_WEAK_SYMBOLS" = 1 ; then
1032    AC_DEFINE(HAVE_WEAK_SYMBOLS,1,[Define if weak symbols available])
1033fi
1034AC_SUBST(HAVE_WEAK_SYMBOLS)
1035
1036# FIXME we only build ROMIO in embedded mode for now
1037AM_CONDITIONAL([BUILD_ROMIO_EMBEDDED],[true])
1038# FIXME need to get this right for non-MPICH2 builds
1039AM_CONDITIONAL([BUILD_MPIO_REQUEST],[false])
1040# FIXME need to get this right for non-MPICH2 builds
1041AM_CONDITIONAL([BUILD_MPIO_ERRHAN],[false])
1042
1043# if we don't have weak symbol support, we must build a separate convenience
1044# library in order to provide the "PMPI_" symbols
1045AM_CONDITIONAL([BUILD_PROFILING_LIB],[test "x$HAVE_WEAK_SYMBOLS" = "x0"])
1046
1047# weird: we have conflated "buid ROMIO's versions of the fortran bindings" and
1048# "build ROMIO"s fortran I/O tests". Of course the common situaiton is that we
1049# are building as part of MPICH2, which builds its own fortran bindings, but we
1050# still want tests built
1051AM_CONDITIONAL([BUILD_F77_BINDINGS],[test "x$NOF77" != "x1" && test "x$FROM_MPICH2" != "xyes"])
1052
1053AM_CONDITIONAL([BUILD_F77_TESTS],[test "x$NOF77" != "x1"])
1054
1055#
1056# Check whether the MPI Offset type is compatible with struct flock
1057AC_MSG_CHECKING([whether struct flock compatible with MPI_Offset])
1058AC_TRY_COMPILE([#include <fcntl.h>],
1059[struct flock l;
1060 $MPI_OFFSET_TYPE a=1;
1061 l.l_start = a;
1062 l.l_len   = a;
1063],pac_cv_struct_flock_and_mpi_offset=yes,pac_cv_struct_flock_and_mpi_offset=no)
1064AC_MSG_RESULT($pac_cv_struct_flock_and_mpi_offset)
1065# FIXME: We should look for struct flock64 and the F_SETLK64/F_GETLK64
1066# ADIOI_Set_lock could use these instead.
1067if test "$pac_cv_struct_flock_and_mpi_offset" = no ; then
1068    AC_MSG_CHECKING([whether struct flock compatible with int])
1069    AC_TRY_COMPILE([#include <fcntl.h>],
1070[struct flock l;
1071 int a=1;
1072 l.l_start = a;
1073 l.l_len   = a;
1074],pac_cv_struct_flock_and_int=yes,pac_cv_struct_flock_and_int=no)
1075    AC_MSG_RESULT($pac_cv_struct_flock_and_int)
1076    if test "$pac_cv_struct_flock_and_int" = yes ; then
1077        AC_DEFINE(NEEDS_INT_CAST_WITH_FLOCK,1,[Define if l_start and l_len data should be cast as int])
1078    fi
1079    # FIXME.  Solaris header files define off_t as a UNION if 64bit file
1080    # sizes are selected.  Gah!
1081fi
1082
1083#
1084# if FILE_SYSTEM is not set above, use ufs and nfs as default
1085#
1086if test -z "$FILE_SYSTEM" ; then
1087    FILE_SYSTEM="ufs nfs"
1088fi
1089
1090# no matter what, always build testfs
1091FILE_SYSTEM="testfs $FILE_SYSTEM"
1092
1093# check for valid file system
1094if test -n "$FILE_SYSTEM" ; then
1095   # if multiple filesystems are passed in, they are '+'-delimited
1096   # we could set the IFS to tokenize FILE_SYSTEM, but the FILE_SYSTEM env var
1097   # is used in multiple places in the build system: get rid of the '+'s so we
1098   # can use the 'for x in $FILE_SYSTEM ...' idiom
1099   FILE_SYSTEM=`echo $FILE_SYSTEM|sed -e 's/\+/ /g'`
1100   for x in $FILE_SYSTEM
1101   do
1102      found=no
1103      # We could also do test -d "ad_$y" to test for known file systems
1104      # based on having access to the adio code.  Then adding a file
1105      # system would not require changing configure to change known_filesystems
1106      for y in $known_filesystems ; do
1107          if test $x = $y ; then
1108	      found=yes
1109	      eval "file_system_`echo $x`=1"
1110	      break
1111	  fi
1112      done
1113      if test "$found" = "no" ; then
1114         AC_MSG_WARN([Unknown file system $x... proceeding anyway])
1115      fi
1116   done
1117fi
1118
1119#############################################
1120# This PVFS2 logic is special because it's hard to get it right if it comes
1121# before the known_filesystems check loop above.  So we handle it down here,
1122# after the loop but before the AM_CONDITIONAL m4 loop.
1123#############################################
1124#
1125# An attempt to "do the right thing" with as little help from the end-user as
1126# possible:
1127# - if 'with-pvfs2' given, use that to find pvfs2-config.  complain if we
1128#   cannot find it, as this is probably what the user would expect
1129# - if we can find 'pvfs2-config' in our path, we can use it to set CFLAGS,
1130#   LIBS, and LDFLAGS accordingly
1131# - as a fallback, use CFLAGS, LIBS, and LDFLAGS passed in by the user
1132# - don't do any of this if --with-file-system was given and did not include
1133#   'pvfs2': i.e. don't surprise the user with pvfs support.
1134
1135AC_PATH_PROG(PVFS2_CONFIG, pvfs2-config, notfound, [${with_pvfs2}/bin:$PATH])
1136if test $PVFS2_CONFIG != "notfound" ; then
1137	if test -n "${with_pvfs2}" -o -n "${file_system_pvfs2}" ; then
1138		# the user either told us where pvfs is or asked for it in
1139		# --with-file-system (or both)
1140		CFLAGS="$CFLAGS $( $PVFS2_CONFIG --cflags)"
1141		LIBS="$LIBS $( $PVFS2_CONFIG --libs)"
1142		FILE_SYSTEM="pvfs2 $FILE_SYSTEM"
1143		file_system_pvfs2=1
1144	fi
1145fi
1146
1147if test "$PVFS2_CONFIG" = "notfound" -a -n "$with_pvfs2" ; then
1148	AC_MSG_ERROR([pvfs2-config not found in $with_pvfs2])
1149fi
1150#############################################
1151
1152
1153# Setup an AM_CONDITIONAL named BUILD_AD_FOO for use in each adio's Makefile.mk.
1154# This must come *after* the condition becomes valid, in this case after all
1155# $file_system_foo variables have been set.
1156#
1157# If you fiddle with this, please watch the m4 quoting carefully.  m4_foreach
1158# expands any macros in the "list" argument exactly once.  The defn bits ensure
1159# that any macro names in "fs"'s value will not be expanded, such as if someone
1160# is daft enough to "m4_define([ufs],[some crazy value])".
1161m4_foreach([fs],[known_filesystems_m4],[
1162AM_CONDITIONAL([BUILD_AD_]m4_toupper(defn([fs])),[test x$file_system_]defn([fs])[ = x1])
1163])
1164
1165
1166#
1167# Print list of configured file systems
1168#
1169# TODO: REMOVE BAD ONES FROM THE LIST SOMEHOW?
1170#
1171AC_MSG_CHECKING([configured file systems])
1172AC_MSG_RESULT([$FILE_SYSTEM])
1173
1174
1175if test -n "$file_system_nfs" ; then
1176    AC_DEFINE(ROMIO_NFS,1,[Define for ROMIO with NFS])
1177    AC_MSG_WARN([File locks may not work with NFS.  See the Installation and
1178users manual for instructions on testing and if necessary fixing this])
1179fi
1180
1181if test -n "$file_system_panfs"; then
1182    AC_DEFINE(ROMIO_PANFS,1,[Define for ROMIO with PANFS])
1183fi
1184if test -n "$file_system_ufs"; then
1185    AC_DEFINE(ROMIO_UFS,1,[Define for ROMIO with UFS])
1186fi
1187if test -n "$file_system_bgl"; then
1188    AC_DEFINE(ROMIO_BGL,1,[Define for ROMIO with BGL])
1189fi
1190if test -n "$file_system_bg"; then
1191    AC_DEFINE(ROMIO_BG,1,[Define for ROMIO with BG])
1192fi
1193if test -n "$file_system_bglockless"; then
1194    if test x"$file_system_bgl" != x; then
1195        AC_DEFINE(ROMIO_BGLOCKLESS,1,[Define for lock-free ROMIO with BGL])
1196    fi
1197
1198    if test x"$file_system_bg" != x; then
1199        AC_DEFINE(ROMIO_BGLOCKLESS,1,[Define for lock-free ROMIO with BG])
1200    fi
1201
1202    if test x"$ROMIO_BGLOCKLESS" -ne x1; then
1203        AC_MSG_ERROR("bglockless requested without [bgl|bg]")
1204    fi
1205fi
1206if test -n "$file_system_hfs"; then
1207    AC_DEFINE(ROMIO_HFS,1,[Define for ROMIO with HFS])
1208fi
1209if test -n "$file_system_sfs"; then
1210    AC_DEFINE(ROMIO_SFS,1,[Define for ROMIO with SFS])
1211fi
1212
1213if test -n "$file_system_pfs"; then
1214    AC_DEFINE(ROMIO_PFS,1,[Define for ROMIO with PFS])
1215fi
1216
1217if test -n "$file_system_testfs"; then
1218    AC_DEFINE(ROMIO_TESTFS,1,[Define for ROMIO with TESTFS])
1219fi
1220#
1221# Verify presence of lustre/lustre_user.h
1222#
1223if test -n "$file_system_lustre"; then
1224    AC_CHECK_HEADERS(lustre/lustre_user.h,
1225        AC_DEFINE(ROMIO_LUSTRE,1,[Define for ROMIO with LUSTRE]),
1226        AC_MSG_ERROR([LUSTRE support requested but cannot find lustre/lustre_user.h header file])
1227    )
1228fi
1229
1230if test -n "$file_system_xfs"; then
1231    AC_DEFINE(ROMIO_XFS,1,[Define for ROMIO with XFS])
1232    # Check for memalign value
1233    AC_CACHE_CHECK([for memory alignment needed for direct I/O],
1234    pac_cv_memalignval,
1235    [
1236    rm -f confmemalignval
1237    rm -f /tmp/romio_tmp.bin
1238    AC_TRY_RUN([
1239#include <stdio.h>
1240#include <unistd.h>
1241#include <fcntl.h>
1242#include <stdio.h>
1243int main(int argc, char **argv) {
1244	struct dioattr st;
1245	int fd = open("/tmp/romio_tmp.bin", O_RDWR | O_CREAT, 0644);
1246	FILE *f=fopen("confmemalignval","w");
1247	if (fd == -1) exit(1);
1248	if (!f) exit(1);
1249	fcntl(fd, F_DIOINFO, &st);
1250	fprintf( f, "%u\n", st.d_mem);
1251	exit(0);
1252	}
1253	],
1254	pac_cv_memalignval=`cat confmemalignval`,
1255	pac_cv_memalignval="unknown",pac_cv_memalignval="unknown"
1256    )
1257    rm -f confmemalignval
1258    rm -f /tmp/romio_tmp.bin
1259    ])
1260    if test -n "$pac_cv_memalignval" -a "$pac_cv_memalignval" != 0 -a \
1261	"$pac_cv_memalignval" != "unknown" ; then
1262        CFLAGS="$CFLAGS -DXFS_MEMALIGN=$pac_cv_memalignval"
1263    else
1264        AC_MSG_RESULT(assuming 128 for memory alignment)
1265        CFLAGS="$CFLAGS -DXFS_MEMALIGN=128"
1266    fi
1267fi
1268
1269#
1270# Verify presence of pvfs.h, issue with int64
1271#
1272if test -n "$file_system_pvfs"; then
1273    CPPFLAGS="$CPPFLAGS $CFLAGS"
1274    AC_CHECK_HEADERS(pvfs.h,
1275    	AC_DEFINE(ROMIO_PVFS,1,[Define for ROMIO with PVFS]),
1276	AC_MSG_ERROR([PVFS support requested but cannot find pvfs.h header file])
1277	)
1278    # Check for missing int64_t (intel version 8 compiler and -no-gcc
1279    # selected)
1280    AC_MSG_CHECKING([that pvfs.h can be compiled])
1281    AC_TRY_COMPILE([
1282#include <pvfs.h>
1283        ],[
1284        ],pvfs_header_ok=yes,pvfs_header_ok=no
1285    )
1286    AC_MSG_RESULT($pvfs_header_ok)
1287    if test "$pvfs_header_ok" = no -a "$ac_cv_sizeof_long_long" = 8 ; then
1288        AC_MSG_CHECKING([if pvfs.h can be compiled if we define int64_t])
1289        # Try again, but with int64_t
1290        AC_TRY_COMPILE([
1291            typedef long long int int64_t;
1292#include <pvfs.h>
1293            ],[
1294            ],
1295            pvfs_header_ok="yes with int64 definition"
1296        )
1297        AC_MSG_RESULT($pvfs_header_ok)
1298    fi
1299    if test "$pvfs_header_ok" = "yes with int64 definition" ; then
1300        AC_DEFINE(ROMIO_PVFS_NEEDS_INT64_DEFINITION,1,[Define if int64_t must be defined for PVFS])
1301    fi
1302    if test "$pvfs_header_ok" != "no" ; then
1303        AC_DEFINE(ROMIO_PVFS,1,[Define for ROMIO with PVFS])
1304	AC_DEFINE(HAVE_PVFS_SUPER_MAGIC, 1, [Define if PVFS_SUPER_MAGIC defined.])
1305    else
1306	AC_MSG_WARN(missing or broken pvfs.h header file; disabling ROMIO PVFS support)
1307    fi
1308fi
1309
1310
1311
1312if test -n "$file_system_zoidfs"; then
1313	AC_CHECK_HEADERS(zoidfs.h,
1314		AC_DEFINE(ROMIO_ZOIDFS,1,[Define for ROMIO with ZoidFD]),
1315		AC_MSG_ERROR([ZoidFS support requested but cannot find zoidfs.h header file])
1316	)
1317fi
1318
1319#
1320# Verify presence of pvfs2.h
1321#
1322if test -n "$file_system_pvfs2"; then
1323    CPPFLAGS="$CPPFLAGS $CFLAGS"
1324    AC_CHECK_HEADERS(pvfs2.h,
1325	AC_DEFINE(ROMIO_PVFS2,1,[Define for ROMIO with PVFS2])
1326	AC_DEFINE(HAVE_PVFS2_SUPER_MAGIC, 1, [Define if PVFS2_SUPER_MAGIC defined.]),
1327        AC_MSG_ERROR([PVFS2 support requested but cannot find pvfs2.h header file])
1328    )
1329fi
1330
1331# layout change after pvfs-2.6.3:
1332if test -n "$file_system_pvfs2"; then
1333    AC_COMPILE_IFELSE([
1334        AC_LANG_SOURCE([
1335#include <stdlib.h>
1336#include "pvfs2.h"
1337          int main(int argc, char **argv) {
1338	      PVFS_object_ref ref;
1339	      PVFS_sys_attr attr;
1340	      PVFS_sys_create(NULL, ref, attr, NULL, NULL, NULL, NULL);
1341	  return 0; }
1342       ])],
1343       , AC_DEFINE(HAVE_PVFS2_CREATE_WITHOUT_LAYOUT, 1,
1344       		[Define if PVFS_sys_create does not have layout parameter])
1345       )
1346fi
1347
1348
1349if test -n "$file_system_gridftp"; then
1350	AC_DEFINE(ROMIO_GRIDFTP, 1, [Define for ROMIO with gridftp])
1351fi
1352
1353if test -n "$file_system_bgl" -o -n "$file_system_bg"; then
1354    SYSDEP_INC=-I${prefix}/include
1355else
1356    SYSDEP_INC=
1357
1358# Check for presence and characteristics of async. I/O calls if
1359# not disabled.
1360
1361# Some systems need pthreads to get AIO to work.  However, we don't want
1362# to add pthreads just because it is there, as that can cause problems
1363# with some implementations of pthreads and compilers (e.g., gcc version 3
1364# would fail if there was an int a[100000] on the stack if the application
1365# was *linked* with pthreads, but would succeed if the application was
1366# *not linked* with pthreads.
1367#
1368if test "x$disable_aio" = "xno" ; then
1369    AC_SEARCH_LIBS(aio_write,aio rt,aio_write_found=yes,aio_write_found=no)
1370    if test "$aio_write_found" = no ; then
1371        # If not found, try finding pthread_create first, and if
1372        # found, try the test again.
1373        AC_SEARCH_LIBS(pthread_create,pthread,foundPTHREAD=yes,foundPTHREAD=no)
1374        if test "$foundPTHREAD" = yes ; then
1375            AC_SEARCH_LIBS(aio_write,aio rt,aio_write_found=yes,aio_write_found=no)
1376        fi
1377    fi
1378fi
1379
1380if test "x$disable_aio" = "xno" -a -n "$aio_write_found" ; then
1381    AC_CHECK_HEADERS(signal.h)
1382    # Just because aio.h is found by CPP doesn't mean that we can use it
1383    # We try to compile it, not just read it.
1384    AC_MSG_CHECKING([if aio.h exists and can be compiled])
1385    AC_TRY_COMPILE([
1386#include <sys/types.h>
1387#include <aio.h>],
1388[],have_aio_h=yes,have_aio_h=no)
1389    AC_MSG_RESULT($have_aio_h)
1390    if test "$have_aio_h" = yes ; then
1391        AC_DEFINE(HAVE_AIO_H,1,[Define if aio.h exists and can be compiled])
1392    fi
1393
1394    AC_MSG_CHECKING([if sys/aio.h exists and can be compiled])
1395    AC_TRY_COMPILE([
1396#include <sys/types.h>
1397#include <sys/aio.h>],
1398[],have_sys_aio_h=yes,have_sys_aio_h=no)
1399    AC_MSG_RESULT($have_sys_aio_h)
1400    if test "$have_sys_aio_h" = yes ; then
1401        AC_DEFINE(HAVE_SYS_AIO_H,1,[Define if sys/aio.h exists and can be compiled])
1402    fi
1403    if test "$have_aio_h" = "no" -a "$have_sys_aio_h" = "no" ; then
1404    	disable_aio=yes
1405    fi
1406fi
1407
1408if test "$have_aio_h" = "yes" -o "$have_sys_aio_h" = "yes" -o "x$disable_aio" = "xno"; then
1409
1410    # Check that aio is available (many systems appear to have aio
1411    # either installed improperly or turned off).
1412    # The test is the following: if not cross compiling, try to run a
1413    # program that includes a *reference* to aio_write but does not call it
1414    # If the libraries are not set up correctly, then this will fail.
1415
1416    AC_MSG_CHECKING([whether aio routines can be used])
1417    # Include aio.h and the aiocb struct (since we'll need these to
1418    # actually use the aio_write interface).  Note that this will
1419    # fail for some pre-POSIX implementations of the aio interface
1420    # (an old IBM interface needs an fd argument as well)
1421    AC_TRY_RUN([
1422#include <sys/types.h>
1423#ifdef HAVE_SIGNAL_H
1424#include <signal.h>
1425#endif
1426#ifdef HAVE_AIO_H
1427#include <aio.h>
1428#endif
1429#ifdef HAVE_SYS_AIO_H
1430#include <sys/aio.h>
1431#endif
1432	int main(int argc, char **argv)
1433	{
1434            struct aiocb *aiocbp;
1435	    if (argc > 10) aio_write(aiocbp);
1436	    return 0;
1437	}
1438	],
1439	aio_runs=yes
1440	AC_MSG_RESULT(yes),
1441	aio_runs=no
1442	AC_MSG_RESULT(no),
1443	aio_runs=no
1444	AC_MSG_RESULT(no: aio routines disabled when cross compiling)
1445    )
1446    if test "$aio_runs" != "no" ; then
1447	AC_DEFINE(ROMIO_HAVE_WORKING_AIO, 1, Define if AIO calls seem to work)
1448    fi
1449
1450    # now about that old IBM interface...
1451    # modern AIO interfaces have the file descriptor in the aiocb structure,
1452    # and will set ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_FILDES.  Old IBM
1453    # implementations pass the file descriptor as an argument to aio_write and
1454    # aio_read.  AIO still works on these platforms, but we have to test with
1455    # two-argument aio_write to avoid a false negative.  no need to worry about
1456    # the two-argument vs. one-argument aio_write and aio_read: ROMIO already
1457    # uses ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_FILDES to call aio_write and
1458    # aio_read correctly
1459
1460    AC_MSG_CHECKING([for obsolete two-argument aio_write])
1461    AC_TRY_RUN([
1462#include <sys/types.h>
1463#ifdef HAVE_SIGNAL_H
1464#include <signal.h>
1465#endif
1466#ifdef HAVE_AIO_H
1467#include <aio.h>
1468#endif
1469#ifdef HAVE_SYS_AIO_H
1470#include <sys/aio.h>
1471#endif
1472	int main(int argc, char **argv)
1473	{
1474		int fd;
1475		struct aiocb *aiocbp;
1476		if (argc > 10) aio_write(fd, aiocbp);
1477		return 0;
1478	}
1479	],
1480	aio_two_arg_write=yes
1481	AC_MSG_RESULT(yes),
1482	aio_two_arg_write=no
1483	AC_MSG_RESULT(no),
1484	aio_two_arg_write=no
1485	AC_MSG_RESULT(no: cannot test when cross-compiling)
1486    )
1487
1488    if test "$aio_two_arg_write" != "no" -a "$aio_runs" != "yes" ; then
1489    	AC_DEFINE(ROMIO_HAVE_WORKING_AIO, 1, Define if AIO calls seem to work)
1490	AC_DEFINE(ROMIO_HAVE_AIO_CALLS_NEED_FILEDES, 1, Define if AIO calls need file descriptor)
1491    fi
1492
1493    AC_MSG_CHECKING([for obsolete two-argument aio_suspend])
1494    AC_TRY_RUN([
1495#include <sys/types.h>
1496#ifdef HAVE_SIGNAL_H
1497#include <signal.h>
1498#endif
1499#ifdef HAVE_AIO_H
1500#include <aio.h>
1501#endif
1502#ifdef HAVE_SYS_AIO_H
1503#include <sys/aio.h>
1504#endif
1505	int main(int argc, char **argv)
1506	{
1507		struct aiocb *aiocbp;
1508		if (argc > 10) aio_suspend(1, &aiocbp);
1509		return 0;
1510	}
1511	],
1512	aio_two_arg_suspend=yes
1513	AC_MSG_RESULT(yes),
1514	aio_two_arg_suspend=no
1515	AC_MSG_RESULT(no),
1516	aio_two_arg_suspend=no
1517	AC_MSG_RESULT(no: cannot test when cross compiling)
1518    )
1519
1520    if test "$aio_two_arg_suspend" != "no" -a "$aio_runs" != "yes" ; then
1521	AC_DEFINE(ROMIO_HAVE_AIO_SUSPEND_TWO_ARGS, 1, Define if aio_suspend needs two arguments)
1522    fi
1523
1524    AC_MSG_CHECKING([for aio_fildes member of aiocb structure])
1525    AC_TRY_COMPILE([
1526#ifdef HAVE_SIGNAL_H
1527#include <signal.h>
1528#endif
1529#ifdef HAVE_SYS_TYPES_H
1530#include <sys/types.h>
1531#endif
1532#ifdef HAVE_AIO_H
1533#include <aio.h>
1534#endif
1535#ifdef HAVE_SYS_AIO_H
1536#include <sys/aio.h>
1537#endif
1538	],[
1539	struct aiocb a;
1540	a.aio_fildes = 0;
1541	],
1542	AC_MSG_RESULT(yes)
1543	AC_DEFINE(ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_FILDES, 1, [Define if aiocb has aio_fildes member]),
1544	AC_MSG_RESULT(no)
1545    )
1546    AC_MSG_CHECKING(for aio_whence member of aiocb structure)
1547    AC_TRY_COMPILE([
1548#ifdef HAVE_SIGNAL_H
1549#include <signal.h>
1550#endif
1551#ifdef HAVE_SYS_TYPES_H
1552#include <sys/types.h>
1553#endif
1554#ifdef HAVE_AIO_H
1555#include <aio.h>
1556#endif
1557#ifdef HAVE_SYS_AIO_H
1558#include <sys/aio.h>
1559#endif
1560#include <sys/types.h>
1561#include <unistd.h>
1562	],[
1563	struct aiocb a;
1564	a.aio_whence = SEEK_SET;
1565	],
1566	AC_MSG_RESULT(yes)
1567	AC_DEFINE(ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_WHENCE, 1, [Define if aiocb has aio_whence member]),
1568	AC_MSG_RESULT(no)
1569    )
1570    AC_MSG_CHECKING(for aio_handle member of aiocb structure)
1571    AC_TRY_COMPILE([
1572#ifdef HAVE_SIGNAL_H
1573#include <signal.h>
1574#endif
1575#ifdef HAVE_SYS_TYPES_H
1576#include <sys/types.h>
1577#endif
1578#ifdef HAVE_AIO_H
1579#include <aio.h>
1580#endif
1581#ifdef HAVE_SYS_AIO_H
1582#include <sys/aio.h>
1583#endif
1584	],[
1585	struct aiocb a;
1586	aio_handle_t h;
1587
1588	a.aio_handle = h;
1589	],
1590	AC_MSG_RESULT(yes)
1591	AC_DEFINE(ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_HANDLE, 1, [Define if aiocb has aio_handle member]),
1592	AC_MSG_RESULT(no)
1593    )
1594    AC_MSG_CHECKING(for aio_reqprio member of aiocb structure)
1595    AC_TRY_COMPILE([
1596#ifdef HAVE_SIGNAL_H
1597#include <signal.h>
1598#endif
1599#ifdef HAVE_SYS_TYPES_H
1600#include <sys/types.h>
1601#endif
1602#ifdef HAVE_AIO_H
1603#include <aio.h>
1604#endif
1605#ifdef HAVE_SYS_AIO_H
1606#include <sys/aio.h>
1607#endif
1608	],[
1609	struct aiocb a;
1610
1611	a.aio_reqprio = 0;
1612	],
1613	AC_MSG_RESULT(yes)
1614	AC_DEFINE(ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_REQPRIO, 1, [Define if aiocb has aio_reqprio member]),
1615	AC_MSG_RESULT(no)
1616    )
1617    AC_MSG_CHECKING(for aio_sigevent member of aiocb structure)
1618    AC_TRY_COMPILE([
1619#ifdef HAVE_SIGNAL_H
1620#include <signal.h>
1621#endif
1622#ifdef HAVE_SYS_TYPES_H
1623#include <sys/types.h>
1624#endif
1625#ifdef HAVE_AIO_H
1626#include <aio.h>
1627#endif
1628#ifdef HAVE_SYS_AIO_H
1629#include <sys/aio.h>
1630#endif
1631	],[
1632	struct aiocb a;
1633
1634	a.aio_sigevent.sigev_signo = 0;
1635	],
1636	AC_MSG_RESULT(yes)
1637	AC_DEFINE(ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_SIGEVENT, 1, [Define if aiocb has aio_sigevent member]),
1638	AC_MSG_RESULT(no)
1639    )
1640
1641fi
1642fi
1643# End of aio-related tests
1644
1645#
1646# Check for statfs (many) and specifically f_fstypename field (BSD)
1647#
1648AC_CHECK_HEADERS(sys/vfs.h sys/param.h sys/mount.h sys/statvfs.h)
1649AC_MSG_CHECKING([whether struct statfs properly defined])
1650AC_TRY_COMPILE([
1651#ifdef HAVE_SYS_VFS_H
1652#include <sys/vfs.h>
1653#endif
1654#ifdef HAVE_SYS_STATVFS_H
1655#include <sys/statvfs.h>
1656#endif
1657#ifdef HAVE_SYS_PARAM_H
1658#include <sys/param.h>
1659#endif
1660#ifdef HAVE_SYS_MOUNT_H
1661#include <sys/mount.h>
1662#endif
1663    ],[
1664    struct statfs f;
1665    ],
1666    pac_cv_have_statfs=yes,pac_cv_have_statfs=no
1667)
1668AC_MSG_RESULT($pac_cv_have_statfs)
1669# At this point, we could check for whether defining
1670# __SWORD_TYPE as sizet_t or int/long (size of pointer)
1671# would help.  FIXME
1672
1673if test "$pac_cv_have_statfs" = yes ; then
1674    AC_DEFINE(HAVE_STRUCT_STATFS,1,[Define if struct statfs can be compiled])
1675fi
1676
1677AC_MSG_CHECKING([for f_fstypename member of statfs structure])
1678AC_TRY_COMPILE([
1679#include <sys/param.h>
1680#include <sys/mount.h>
1681#include <string.h>
1682    ],[
1683    struct statfs f;
1684    memset(&f, 0, sizeof(f));
1685    strncmp("nfs", f.f_fstypename, 3);
1686    ],
1687    pac_cv_have_statfs_f_fstypename=yes,
1688    pac_cv_have_statfs_f_fstypename=no
1689)
1690AC_MSG_RESULT($pac_cv_have_statfs_f_fstypename)
1691if test $pac_cv_have_statfs_f_fstypename = yes ; then
1692    AC_DEFINE(ROMIO_HAVE_STRUCT_STATFS_WITH_F_FSTYPENAME, 1,[Define if statfs has f_fstypename])
1693fi
1694
1695#
1696# Check for stat and st_fstype field (NEC SX4)
1697#
1698AC_CHECK_HEADERS(sys/stat.h sys/types.h unistd.h)
1699AC_CHECK_FUNCS(stat,
1700    AC_DEFINE(HAVE_STAT, 1, Define if stat function is present)
1701    AC_MSG_CHECKING([for st_fstype member of stat structure])
1702    AC_TRY_COMPILE([
1703#ifdef HAVE_SYS_TYPES_H
1704#include <sys/types.h>
1705#endif
1706#ifdef HAVE_SYS_STAT_H
1707#include <sys/stat.h>
1708#endif
1709#ifdef HAVE_UNISTD_H
1710#include <unistd.h>
1711#endif
1712	],[
1713	struct stat s;
1714
1715	s.st_fstype = NULL;
1716	],
1717	AC_MSG_RESULT(yes)
1718	AC_DEFINE(ROMIO_HAVE_STRUCT_STAT_WITH_ST_FSTYPE, 1, Define if struct stat has a st_fstype member),
1719	AC_MSG_RESULT(no)
1720    )
1721)
1722
1723#
1724# Check for statvfs and f_basetype field (Solaris, Irix, AIX, etc.)
1725#
1726AC_CHECK_HEADERS(sys/types.h sys/statvfs.h sys/vfs.h)
1727AC_CHECK_FUNCS(statvfs,
1728    AC_DEFINE(HAVE_STATVFS, 1, Define if statvfs function is present)
1729    AC_MSG_CHECKING([for f_basetype member of statvfs structure])
1730    AC_TRY_COMPILE([
1731#ifdef HAVE_SYS_TYPES_H
1732#include <sys/types.h>
1733#endif
1734#ifdef HAVE_SYS_VFS_H
1735#include <sys/vfs.h>
1736#endif
1737#ifdef HAVE_SYS_STATVFS_H
1738#include <sys/statvfs.h>
1739#endif
1740	], [[
1741	struct statvfs foo;
1742
1743	foo.f_basetype[0] = 'a';
1744	]],
1745	AC_MSG_RESULT(yes)
1746	AC_DEFINE(ROMIO_HAVE_STRUCT_STATVFS_WITH_F_BASETYPE, 1, defined if struct statvfs has a f_basetype member),
1747	AC_MSG_RESULT(no)
1748    )
1749)
1750
1751#
1752# Check for large file support.  Make sure that we can use the off64_t
1753# type (in some cases, it is an array, and the ROMIO code isn't prepared for
1754# that).
1755#
1756AC_CHECK_HEADERS(unistd.h)
1757if test "$ac_cv_header_unistd_h" = "yes" ; then
1758    AC_CACHE_CHECK([for large file defines],ac_cv_has_large_file_defines,[
1759    AC_TRY_COMPILE([
1760#include <unistd.h>
1761        ], [
1762#ifndef _LFS64_LARGEFILE
1763#error no largefile defines
1764#endif
1765        ],ac_cv_has_large_file_defines=yes,ac_cv_has_large_file_defines=no)])
1766    if test "$ac_cv_has_large_file_defines" = "yes" ; then
1767        # See if we can use them
1768    AC_CACHE_CHECK([whether off64_t is an scalar type],ac_cv_off64_t_scalar,[
1769    AC_TRY_COMPILE([
1770#define _LARGEFILE64_SOURCE
1771#define _FILE_OFFSET_BITS 64
1772#include <sys/types.h>
1773#include <unistd.h>
1774],[off64_t a = 3;],ac_cv_off64_t_scalar=yes,ac_cv_off64_t_scalar=no)])
1775
1776        if test "$ac_cv_off64_t_scalar" = "yes" ; then
1777            CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64"
1778        fi
1779    fi
1780fi
1781
1782
1783####################################################################
1784# We're about to mess with CC etc.  No more feature tests past here,
1785# because we may set CC to something that does not yet exist!
1786####################################################################
1787
1788if test -n "$mpi_mpich"; then
1789   if test -z "$arch_SX4" ; then
1790      MPIOF_H_INCLUDED=1
1791   fi
1792   if test "$FROM_MPICH2" = no; then
1793      AC_DEFINE(NEEDS_MPI_TEST,1,[Define if mpi_test needed])
1794      AC_DEFINE(MPICH,1,[Define if using MPICH])
1795   fi
1796fi
1797
1798if test -n "$mpi_sgi"; then
1799   AC_DEFINE(MPISGI,1,[Define if SGI MPI])
1800fi
1801
1802if test -n "$mpi_lam"; then
1803   AC_DEFINE(MPILAM,1,[Define if using LAM/MPI])
1804fi
1805
1806if test -n "$mpi_hp"; then
1807   AC_DEFINE(MPIHP,1,[Define if using HP MPI])
1808   if test "$NOF77" = 0; then
1809      PAC_CHECK_MPIOF_H
1810   fi
1811fi
1812#
1813AC_CHECK_FUNCS(strerror)
1814if test -z "$srcdir" -o "$srcdir" = "." ; then srcdir="$ROMIO_HOME" ; fi
1815AC_SUBST(srcdir)
1816
1817# preserve these values across a config.status --recheck
1818AC_ARG_VAR([master_top_srcdir],[set by the MPICH2 configure to indicate the MPICH2 source root])
1819AC_ARG_VAR([master_top_builddir],[set by the MPICH2 configure to indicate the MPICH2 build root])
1820
1821# The master_top_srcdir is the location of the source for the building
1822# package.  This is used only as part of the MPICH2 build, including
1823# the documentation targets mandoc, htmldoc, and latexdoc
1824if test -z "$master_top_srcdir" ; then
1825    if test "$FROM_MPICH2" = yes ; then
1826        AC_MSG_WARN([Could not determine master_top_srcdir])
1827    fi
1828fi
1829#
1830# Get the master builddir (which may be imported from above)
1831if test -z "$master_top_builddir" ; then
1832    if test "$FROM_MPICH2" = yes ; then
1833        # this variable is essential to proper build operation
1834        AC_MSG_ERROR([Could not determine master_top_srcdir])
1835    fi
1836    master_top_builddir=`pwd`
1837fi
1838# Make sure the alternate spelling is used until we clean up all of the code
1839master_topbuild_dir=$master_top_builddir
1840export master_topbuild_dir
1841AC_SUBST(master_topbuild_dir)
1842
1843# The following definitions are needed within adio/common/status_setb.c
1844if test "$FROM_MPICH" = yes ; then
1845   AC_DEFINE(MPICH,1,[Define if compiling within MPICH])
1846elif test "$FROM_MPICH2" = yes ; then
1847   AC_DEFINE(ROMIO_INSIDE_MPICH2,1,[Define if compiling within MPICH2])
1848elif test "$FROM_MPILAM" = yes ; then
1849   AC_DEFINE(MPILAM,1,[Define if compiling within LAM/MPI])
1850fi
1851
1852if test "$FROM_MPICH2" = no -a "$FROM_MPICH" = no ; then
1853    if test -z "$LIBNAME"; then
1854        LIBNAME="$top_build_dir/lib/libmpio.a"
1855    fi
1856    #
1857    if test ! -d $top_build_dir/lib ; then
1858        mkdir $top_build_dir/lib
1859    fi
1860else
1861    MPILIBNAME=${MPILIBNAME:-mpich}
1862    if test -z "$LIBNAME" ; then
1863        if test -d "$master_top_builddir/lib" ; then
1864            LIBNAME=$master_top_builddir/lib/lib${MPILIBNAME}.a
1865        else
1866            LIBNAME="$ROMIO_HOME/lib${MPILIBNAME}.a"
1867	fi
1868    fi
1869fi
1870if test "$FROM_MPICH2" != no ; then
1871    # use the error handlers from MPICH2
1872    MPIO_EXTRA_OBJECTS=
1873    MPIO_EXTRA_TMP_POBJECTS=
1874    MPIO_EXTRA_REAL_POBJECTS=
1875    # Use generalized request to get the multiple-completion routines
1876    MPIO_REQOBJECTS=
1877fi
1878AC_SUBST(MPIO_EXTRA_OBJECTS)
1879AC_SUBST(MPIO_EXTRA_TMP_POBJECTS)
1880AC_SUBST(MPIO_EXTRA_REAL_POBJECTS)
1881#
1882# Use DOCTEXT instead of doctext
1883AC_CHECK_PROGS(DOCTEXT,doctext,true)
1884AC_SUBST(DOCTEXT)
1885#
1886if test $NOF77 = 1 ; then
1887   F77=":"
1888else
1889   FORTRAN_TEST="fperf fcoll_test fmisc pfcoll_test"
1890fi
1891#
1892if test $WITHIN_KNOWN_MPI_IMPL = no ; then
1893   PAC_TEST_MPI
1894   PAC_NEEDS_FINT
1895else
1896   NEEDS_MPI_FINT=""
1897fi
1898#
1899if test "$MPI_INCLUDE_DIR" = "." ; then
1900   ROMIO_INCLUDE="-I../include"
1901else
1902   ROMIO_INCLUDE="-I../include -I$MPI_INCLUDE_DIR"
1903fi
1904#
1905TEST_LIBNAME=$LIBNAME
1906MPIRUN=mpirun
1907#
1908# if MPICH, use mpicc in test programs
1909#
1910if test "$FROM_MPICH" = yes ; then
1911   MPICH_HOME=`dirname $ROMIO_HOME`
1912   if test -z "$MPI_BIN_DIR" ; then MPI_BIN_DIR=$MPICH_HOME/bin ; fi
1913   TEST_CC=$MPI_BIN_DIR/mpicc
1914   MPI_LIB=""
1915   ROMIO_INCLUDE=""
1916   USER_CFLAGS=""
1917   USER_FFLAGS=""
1918   TEST_LIBNAME=""
1919   MPIRUN=$MPI_BIN_DIR/mpirun
1920   if test -n "$arch_SX4" || test -n "$arch_hpux" ; then
1921      TEST_F77=$MPI_BIN_DIR/mpif90
1922   else
1923      TEST_F77=$MPI_BIN_DIR/mpif77
1924   fi
1925   CC=$MPI_BIN_DIR/mpicc
1926   # A later test will insert the mpi2-other/info and array directories based
1927   # on the value of BUILD_MPI_xxxx.  This lets MPICH2 turn these off,
1928   # since MPICH2 provides these routines elsewhere
1929   EXTRA_DIRS="mpi-io/fortran"
1930   # Some older implementations of the ADI do not include the
1931   # MPID_Status_set_bytes routine.   This uses either the
1932   # environment variable ADI3_WITHOUT_SET_BYTES or the
1933   # with arg --without-setbytes
1934   if test "$ADI2_WITHOUT_SET_BYTES" != yes -a \
1935           "$with_setbytes" != no ; then
1936       AC_DEFINE(HAVE_STATUS_SET_BYTES,1,[Define if have MPIR_Status_set_bytes])
1937   fi
1938elif test $FROM_LAM = yes ; then
1939   # LAM does have the status set bytes functionality
1940   AC_DEFINE(HAVE_STATUS_SET_BYTES,1,[Define if have MPIR_Status_set_bytes])
1941
1942   # Used in the tests/ subdirectory for after ROMIO is built
1943   TEST_CC=mpicc
1944   TEST_F77=mpif77
1945   MPIRUN=mpirun
1946   MPI_LIB=
1947   ROMIO_INCLUDE=
1948   USER_CFLAGS=
1949   USER_FFLAGS=
1950   TEST_LIBNAME=
1951   EXTRA_DIRS="mpi-io/fortran mpi2-other/info mpi2-other/info/fortran mpi2-other/array mpi2-other/array/fortran"
1952elif test $FROM_MPICH2 = yes ; then
1953   # For now, separate the mpich2 from mpich cases
1954   MPICH_HOME=`dirname $ROMIO_HOME`
1955   MPICH_HOME=`dirname $MPICH_HOME`
1956   MPICH_HOME=`dirname $MPICH_HOME`
1957   if test -z "$MPI_BIN_DIR" ; then MPI_BIN_DIR=$MPICH_HOME/bin ; fi
1958   # No special compiler script.
1959   # BUT we need the include paths
1960   # CC="$CC -I${use_top_srcdir}/src/include -I${top_build_dir}/src/include"
1961   # TEST_CC="$CC"
1962   # MPI_LIB="$LIBNAME"
1963   # To allow ROMIO to work with the LIBTOOL scripts, we want to
1964   # work directly with the CC, not the mpicc, compiler.
1965   # Note that in the "FROM_MPICH2" case, the CPPFLAGS and INCLUDES are already
1966   # properly set
1967   #CC=${top_build_dir}/bin/mpicc
1968   #
1969   # set the compilers to the ones in MPICH2 bin directory (master_top_builddir/bin)
1970   TEST_CC='$(bindir)/mpicc'
1971   TEST_F77='$(bindir)/mpif77'
1972   MPI_H_INCLUDE="-I${master_top_builddir}/src/include"
1973   ROMIO_INCLUDE=""
1974   USER_CFLAGS=""
1975   USER_FFLAGS=""
1976   TEST_LIBNAME=""
1977   MPIRUN='${bindir}/mpiexec'
1978   #
1979   # Turn off the building of the Fortran interface and the Info routines
1980   EXTRA_DIRS=""
1981   AC_DEFINE(HAVE_STATUS_SET_BYTES,1,[Define if status_set_bytes available])
1982   DEFINE_HAVE_MPI_GREQUEST="#define HAVE_MPI_GREQUEST 1"
1983   AC_DEFINE(HAVE_MPIU_FUNCS,1,[Define if MPICH2 memory tracing macros defined])
1984fi
1985#
1986#
1987# feature tests:  we can't test features if building as part of MPICH because
1988# we don't yet have an implementation against which we can test
1989#
1990if test $WITHIN_KNOWN_MPI_IMPL = no ; then
1991   PAC_TEST_MPIR_STATUS_SET_BYTES
1992   PAC_TEST_MPI_GREQUEST
1993   PAC_TEST_MPIU_FUNCS
1994   AC_DEFINE(PRINT_ERR_MSG,1,[Define for printing error messages])
1995fi
1996#
1997if test -z "$TEST_CC" ; then
1998   TEST_CC="$CC"
1999fi
2000if test -z "$TEST_F77" ; then
2001   TEST_F77="$F77"
2002fi
2003#
2004AC_CHECK_FUNCS(strdup)
2005if test "$ac_cv_func_strdup" = "yes" ; then
2006    # Do we need to declare strdup?
2007    PAC_FUNC_NEEDS_DECL([#include <string.h>],strdup)
2008fi
2009AC_CHECK_FUNCS(snprintf)
2010if test "$ac_cv_func_snprintf" = "yes" ; then
2011    # Do we need to declare snprintf?
2012    PAC_FUNC_NEEDS_DECL([#include <stdio.h>],snprintf)
2013fi
2014AC_CHECK_FUNCS(lstat)
2015if test "$ac_cv_func_lstat" = "yes" ; then
2016    # Do we need to declare lstat?
2017    PAC_FUNC_NEEDS_DECL([#include <unistd.h>],lstat)
2018fi
2019AC_CHECK_FUNCS(readlink)
2020if test "$ac_cv_func_readlink" = "yes" ; then
2021    # Do we need to declare readlink?
2022    PAC_FUNC_NEEDS_DECL([#include <unistd.h>],readlink)
2023fi
2024AC_CHECK_FUNCS(fsync)
2025if test "$ac_cv_func_fsync" = "yes" ; then
2026    # Do we need to declare fsync?
2027    PAC_FUNC_NEEDS_DECL([#include <unistd.h>],fsync)
2028fi
2029AC_CHECK_FUNCS(ftruncate)
2030if test "$ac_cv_func_ftruncate" = "yes" ; then
2031    # Do we need to declare ftruncate?
2032    PAC_FUNC_NEEDS_DECL([#include <unistd.h>],ftruncate)
2033fi
2034
2035AC_CHECK_FUNCS(lseek64)
2036if test "$ac_cv_func_lseek64" = "yes" ; then
2037    PAC_FUNC_NEEDS_DECL([#include <unistd.h>],lseek64)
2038fi
2039#
2040# Create the directory lists for the Makefile
2041FILE_SYS_DIRS=""
2042for dir in $FILE_SYSTEM ; do
2043    FILE_SYS_DIRS="$FILE_SYS_DIRS adio/ad_$dir"
2044done
2045# FIXME eliminate FILE_SYS_DIRS and EXTRA_SRC_DIRS
2046EXTRA_SRC_DIRS=""
2047
2048mpio_glue=""
2049if test "$FROM_MPICH2" = yes -o "${MPI_IMPL}_mpi" = "mpich2_mpi"; then
2050    mpio_glue=mpich2
2051elif test "$FROM_MPICH" = yes -o "${MPI_IMPL}_mpi" = "mpich_mpi"; then
2052    mpio_glue=mpich1
2053else
2054    mpio_glue=default
2055fi
2056
2057AM_CONDITIONAL([MPIO_GLUE_MPICH2],[test "X$mpio_glue" = "Xmpich2"])
2058AM_CONDITIONAL([MPIO_GLUE_MPICH1],[test "X$mpio_glue" = "Xmpich1"])
2059AM_CONDITIONAL([MPIO_GLUE_DEFAULT],[test "X$mpio_glue" = "Xdefault"])
2060
2061if test "$BUILD_MPI_INFO" = 1 ; then
2062    EXTRA_SRC_DIRS="$EXTRA_SRC_DIRS mpi2-other/info"
2063    if test "$NOF77" = 0 -a "$FROM_MPICH2" != yes ; then
2064        EXTRA_SRC_DIRS="$EXTRA_SRC_DIRS mpi2-other/info/fortran"
2065    fi
2066fi
2067if test "$BUILD_MPI_ARRAY" = 1 ; then
2068    EXTRA_SRC_DIRS="$EXTRA_SRC_DIRS mpi2-other/array"
2069    if test "$NOF77" = 0 -a "$FROM_MPICH2" != yes ; then
2070        EXTRA_SRC_DIRS="$EXTRA_SRC_DIRS mpi2-other/array/fortran"
2071    fi
2072fi
2073if test "$NOF77" = 0 -a "$FROM_MPICH2" != yes ; then
2074   EXTRA_SRC_DIRS="$EXTRA_SRC_DIRS mpi-io/fortran"
2075fi
2076AC_SUBST(EXTRA_SRC_DIRS)
2077AC_SUBST(FILE_SYS_DIRS)
2078
2079#
2080CFLAGS="$CFLAGS -DHAVE_ROMIOCONF_H"
2081#
2082
2083if test -n "$MPIOF_H_INCLUDED"; then
2084   F77MPIOINC=""
2085else
2086   F77MPIOINC="include 'mpiof.h'"
2087fi
2088
2089AC_CHECK_HEADERS(unistd.h,
2090        AC_MSG_CHECKING([for large file defines])
2091        AC_TRY_COMPILE([
2092                #include <unistd.h>
2093                ], [
2094                #ifndef _LFS64_LARGEFILE
2095                #error no largefile defines
2096                #endif
2097                ],
2098                CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64"
2099                AC_MSG_RESULT(yes),
2100                AC_MSG_RESULT(none) )
2101        )
2102
2103echo "setting SYSDEP_INC to $SYSDEP_INC"
2104AC_SUBST(SYSDEP_INC)
2105
2106AC_C_RESTRICT
2107PAC_C_GNU_ATTRIBUTE
2108
2109# support gcov test coverage information
2110PAC_ENABLE_COVERAGE
2111
2112echo "setting CC to $CC"
2113echo "setting F77 to $F77"
2114echo "setting TEST_CC to $TEST_CC"
2115echo "setting TEST_F77 to $TEST_F77"
2116echo "setting CFLAGS to $CFLAGS"
2117echo "setting USER_CFLAGS to $USER_CFLAGS"
2118echo "setting USER_FFLAGS to $USER_FFLAGS"
2119
2120AC_SUBST(ARCH)
2121AC_SUBST(FILE_SYSTEM)
2122AC_SUBST(CC)
2123AC_SUBST(CPPFLAGS)
2124AC_SUBST(CFLAGS)
2125AC_SUBST(USER_CFLAGS)
2126AC_SUBST(USER_FFLAGS)
2127AC_SUBST(MIPS)
2128AC_SUBST(BITS)
2129AC_SUBST(AR)
2130AC_SUBST(AR_FLAGS)
2131AC_SUBST(MPI_INCLUDE_DIR)
2132AC_SUBST(MPI_LIB)
2133AC_SUBST(F77)
2134AC_SUBST(NOF77)
2135AC_SUBST(NOPROFILE)
2136AC_SUBST(MAKE)
2137AC_SUBST(arch_IRIX)
2138AC_SUBST(ROMIO_HOME)
2139AC_SUBST(LIBNAME)
2140AC_SUBST(TEST_LIBNAME)
2141AC_SUBST(LL)
2142AC_SUBST(F77GETARG)
2143AC_SUBST(F77IARGC)
2144AC_SUBST(F77MPIOINC)
2145AC_SUBST(FTESTDEFINE)
2146AC_SUBST(FORTRAN_MPI_OFFSET)
2147AC_SUBST(FROM_MPICH)
2148AC_SUBST(FROM_MPICH2)
2149AC_SUBST(FROM_LAM)
2150AC_SUBST(WITHIN_KNOWN_MPI_IMPL)
2151AC_SUBST(NEEDS_MPI_FINT)
2152AC_SUBST(HAVE_MPI_INFO)
2153AC_SUBST(BUILD_MPI_INFO)
2154AC_SUBST(HAVE_MPI_DARRAY_SUBARRAY)
2155AC_SUBST(BUILD_MPI_ARRAY)
2156AC_SUBST(DEFINE_MPI_OFFSET)
2157AC_SUBST(DEFINE_HAVE_MPI_GREQUEST)
2158AC_SUBST(MPI_OFFSET_TYPE)
2159AC_SUBST(MPI_FINFO1)
2160AC_SUBST(MPI_FINFO2)
2161AC_SUBST(MPI_FINFO3)
2162AC_SUBST(MPI_FINFO4)
2163AC_SUBST(MPI_FARRAY1)
2164AC_SUBST(MPI_FARRAY2)
2165AC_SUBST(MPI_FARRAY3)
2166AC_SUBST(MPI_FARRAY4)
2167AC_SUBST(MPI_FARRAY5)
2168AC_SUBST(MPI_FARRAY6)
2169AC_SUBST(MPI_FARRAY7)
2170AC_SUBST(MPI_OFFSET_KIND1)
2171AC_SUBST(MPI_OFFSET_KIND2)
2172AC_SUBST(TEST_CC)
2173AC_SUBST(TEST_F77)
2174AC_SUBST(ROMIO_INCLUDE)
2175AC_SUBST(ROMIO_LFLAGS)
2176AC_SUBST(ROMIO_TCFLAGS)
2177AC_SUBST(ROMIO_TCPPFLAGS)
2178AC_SUBST(ROMIO_TFFLAGS)
2179AC_SUBST(MPIRUN)
2180AC_SUBST(FORTRAN_TEST)
2181dnl
2182dnl Support shared libraries
2183if test -z "$ENABLE_SHLIB" ; then
2184   ENABLE_SHLIB=none
2185fi
2186AC_SUBST(ENABLE_SHLIB)
2187AC_SUBST(CC_SHL)
2188AC_SUBST(LIBTOOL)
2189# Remove the .a from the library file name (so that we can use .so or
2190# other appropriate suffix)
2191SHLIBNAME=`echo $LIBNAME | sed 's/\.a$//'`
2192AC_SUBST(SHLIBNAME)
2193dnl
2194if test ! -d adio ; then mkdir adio ; fi
2195if test ! -d adio/include ; then mkdir adio/include ; fi
2196if test ! -d mpi2-other ; then mkdir mpi2-other ; fi
2197if test ! -d mpi-io ; then mkdir mpi-io ; fi
2198if test ! -d mpi-io/glue ; then mkdir mpi-io/glue ; fi
2199
2200# Create makefiles for all of the adio devices.  Only the ones that
2201# are active will be called by the top level ROMIO make
2202AC_OUTPUT_COMMANDS([chmod 755 util/romioinstall test/runtests])
2203AC_CONFIG_FILES([
2204    Makefile
2205    localdefs
2206    mpi2-other/info/Makefile
2207    mpi2-other/array/Makefile
2208    test/Makefile
2209    test/misc.c
2210    test/large_file.c
2211    test/runtests
2212    test-internal/Makefile
2213    util/romioinstall
2214    include/mpio.h
2215    include/mpiof.h
2216    mpi2-other/info/fortran/Makefile
2217    mpi2-other/array/fortran/Makefile
2218    test/fmisc.f
2219    test/fcoll_test.f
2220    test/pfcoll_test.f
2221    test/fperf.f
2222])
2223AC_OUTPUT
2224
2225#
2226rm -f *.o
2227
2228if test $FROM_MPICH = no -a $FROM_MPICH2 = no ; then
2229   AC_MSG_RESULT([Configure done. Now type make.])
2230fi
2231dnl PAC_SUBDIR_CACHE_CLEANUP
2232exit 0
2233