dnl $Id: acinclude.m4,v 1.18 2007/02/08 16:17:51 ed Exp $ dnl UD macros for netcdf configure dnl Convert a string to all uppercase. dnl define([uppercase], [translit($1, abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ)]) dnl dnl Check for an m4(1) preprocessor utility. dnl AC_DEFUN([UD_PROG_M4], [ case "${M4-unset}" in unset) AC_CHECK_PROGS(M4, m4 gm4, m4) ;; *) AC_CHECK_PROGS(M4, $M4 m4 gm4, m4) ;; esac AC_MSG_CHECKING(m4 flags) case "${M4FLAGS-unset}" in unset) M4FLAGS=-B10000 ;; esac AC_MSG_RESULT($M4FLAGS) AC_SUBST(M4FLAGS) ]) dnl dnl Check for an ar(1) utility. dnl AC_DEFUN([UD_PROG_AR], [ case "${AR-unset}" in unset) AC_CHECK_PROGS(AR, ar, ar) ;; *) AC_CHECK_PROGS(AR, $AR ar, ar) ;; esac AC_MSG_CHECKING(ar flags) case "${ARFLAGS-unset}" in unset) ARFLAGS=cru ;; esac AC_MSG_RESULT($ARFLAGS) AC_SUBST(ARFLAGS) ]) dnl dnl Check for an nm(1) utility. dnl AC_DEFUN([UD_PROG_NM], [ case "${NM-unset}" in unset) AC_CHECK_PROGS(NM, nm, nm) ;; *) AC_CHECK_PROGS(NM, $NM nm, nm) ;; esac AC_MSG_CHECKING(nm flags) case "${NMFLAGS-unset}" in unset) NMFLAGS= ;; esac AC_MSG_RESULT($NMFLAGS) AC_SUBST(NMFLAGS) ]) dnl dnl Set the top-level source-directory. dnl AC_DEFUN([UD_SRCDIR], [ AC_MSG_CHECKING(for top-level source-directory) SRCDIR=`(cd $srcdir && pwd)` AC_MSG_RESULT($SRCDIR) AC_SUBST(SRCDIR) ]) dnl dnl Check for a Standard C compiler. Prefer a native one over the dnl GNU one to reduce the chance that the environment variable LIBS dnl will have to be set to reference the GNU C runtime library. dnl AC_DEFUN([UD_PROG_CC], [ # Because we must have a C compiler, we treat an unset CC # the same as an empty CC. case "${CC}" in '') case `uname` in ULTRIX) # The native ULTRIX C compiler isn't standard. ccs='gcc cc' ;; *) # xlc is before c89 because AIX's sizeof(long long) # differs between the two. # ccs='xlc c89 acc cc gcc' ;; esac for cc in $ccs; do AC_CHECK_PROG(CC, $cc, $cc) case "$CC" in '') ;; *) break ;; esac done case "${CC}" in '') AC_MSG_ERROR("Could not find C compiler") ;; esac ;; esac # # On some systems, a discovered compiler nevertheless won't # work (due to licensing, for example); thus, we check the # compiler with a test program. # AC_MSG_CHECKING(C compiler \"$CC\") AC_TRY_COMPILE(, , AC_MSG_RESULT(works), AC_MSG_RESULT(failed to compile test program)) AC_SUBST(CC) case "$CC" in *gcc*) GCC=yes # Expected by autoconf(1) macros ;; esac case `uname -sr` in 'HP-UX A.09'*) AC_DEFINE([_HPUX_SOURCE], [], [building on HPUX system]) ;; esac ]) dnl dnl Check for a C++ compiler. Prefer a native one over the dnl GNU one to reduce the chance that the environment variable LIBS dnl will have to be set to reference the GNU C runtime library. dnl AC_DEFUN([UD_PROG_CXX], [ case "${CXX-unset}" in unset) case `uname` in AIX) preferred_cxx='xlC' ;; esac possible_cxxs="${preferred_cxx} CC cxx c++ g++ gcc" ;; '') AC_MSG_WARN("Empty CXX variable") possible_cxxs= ;; *) possible_cxxs=$CXX ;; esac case "${possible_cxxs}" in '') CXX= ;; *) AC_LANG_SAVE() AC_LANG_CPLUSPLUS() for cxx in $possible_cxxs; do AC_CHECK_PROG(CXX, $cxx, $cxx) case "$CXX" in '') ;; *) # On some systems, a discovered compiler nevertheless # won't work (because it's a script to a non-existant # executable, for example); thus, we check the compiler # with a test program. We also test for "iostream" and # the standard C++ library because we need these to # work. # AC_MSG_CHECKING(C++ compiler \"$CXX\") AC_TRY_RUN( [ #include int main() { std::cout << ""; return 0; } ], [ AC_MSG_RESULT(works) break ], [ AC_MSG_WARN($CXX failed on standard C++ test program) CXX= unset ac_cv_prog_CXX ]) ;; esac done AC_LANG_RESTORE() case "${CXX}" in '') AC_MSG_WARN("Could not find working C++ compiler") AC_MSG_WARN(Setting CXX to the empty string) ;; esac ;; esac case "${CXX}" in '') AC_MSG_WARN(The C++ interface will not be built) ;; esac AC_SUBST(CXX) case `uname` in 'HP-UX A.09'*) AC_DEFINE([_HPUX_SOURCE], [], [building on HPUX system]) ;; esac ]) dnl dnl like AC_LONG_DOUBLE, except checks for 'long long' dnl AC_DEFUN([UD_C_LONG_LONG], [AC_MSG_CHECKING(for long long) AC_CACHE_VAL(ac_cv_c_long_long, [if test "$GCC" = yes; then ac_cv_c_long_long=yes else AC_TRY_RUN([int main() { long long foo = 0; exit(sizeof(long long) < sizeof(long)); }], ac_cv_c_long_long=yes, ac_cv_c_long_long=no, :) fi])dnl AC_MSG_RESULT($ac_cv_c_long_long) if test $ac_cv_c_long_long = yes; then AC_DEFINE([HAVE_LONG_LONG], [], [have long long type]) fi ]) dnl UD_CHECK_SIZEOF(TYPE) AC_DEFUN([UD_CHECK_SIZEOF], [changequote(<<, >>)dnl dnl The name to #define. define(<>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl dnl The cache variable name. define(<>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl changequote([, ])dnl AC_MSG_CHECKING(size of $1) AC_CACHE_VAL(AC_CV_NAME, [AC_TRY_RUN([#include #include #if STDC_HEADERS #include #endif main() { FILE *f=fopen("conftestval", "w"); if (!f) exit(1); fprintf(f, "%d\n", sizeof($1)); exit(0); }], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=0, AC_CV_NAME=0)])dnl AC_MSG_RESULT($AC_CV_NAME) AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [type size]) undefine([AC_TYPE_NAME])dnl undefine([AC_CV_NAME])dnl ]) dnl dnl UD_CHECK_IEEE dnl If the 'double' is not an IEEE double dnl or the 'float' is not and IEEE single, dnl define NO_IEEE_FLOAT dnl AC_DEFUN([UD_CHECK_IEEE], [ AC_MSG_CHECKING(for IEEE floating point format) AC_TRY_RUN([#ifndef NO_FLOAT_H #include #endif #define EXIT_NOTIEEE 1 #define EXIT_MAYBEIEEE 0 int main() { #if defined(FLT_RADIX) && FLT_RADIX != 2 return EXIT_NOTIEEE; #elif defined(DBL_MAX_EXP) && DBL_MAX_EXP != 1024 return EXIT_NOTIEEE; #elif defined(DBL_MANT_DIG) && DBL_MANT_DIG != 53 return EXIT_NOTIEEE; #elif defined(FLT_MAX_EXP) && !(FLT_MAX_EXP == 1024 || FLT_MAX_EXP == 128) return EXIT_NOTIEEE; #elif defined(FLT_MANT_DIG) && !(FLT_MANT_DIG == 53 || FLT_MANT_DIG == 24) return EXIT_NOTIEEE; #else /* (assuming eight bit char) */ if(sizeof(double) != 8) return EXIT_NOTIEEE; if(!(sizeof(float) == 4 || sizeof(float) == 8)) return EXIT_NOTIEEE; return EXIT_MAYBEIEEE; #endif }],ac_cv_c_ieeefloat=yes, ac_cv_c_ieeefloat=no, :) AC_MSG_RESULT($ac_cv_c_ieeefloat) if test $ac_cv_c_ieeefloat = no; then AC_DEFINE([NO_IEEE_FLOAT], [], [no IEEE float on this platform]) fi ]) dnl Check for utility for generating makefile dependencies. dnl Should only be used at the UPC. dnl AC_DEFUN([UD_PROG_CC_MAKEDEPEND], [ AC_MSG_CHECKING(how to make dependencies) case `uname -s` in IRIX*|OSF1) CC_MAKEDEPEND='cc -M' ;; SunOS) case `uname -r` in 4*) CC_MAKEDEPEND='cc -M' ;; 5*|*) CC_MAKEDEPEND='cc -xM' ;; esac ;; ULTRIX) case `uname -m` in RISC) CC_MAKEDEPEND='cc -M' ;; VAX) # Can't handle prototypes in netcdf.h ;; esac ;; AIX) # Writes to .u files rather than standard out ;; HP-UX) # Writes escaped newlines to standard error ;; esac case "${CC_MAKEDEPEND}" in '') CC_MAKEDEPEND=false ;; esac AC_MSG_RESULT($CC_MAKEDEPEND) AC_SUBST(CC_MAKEDEPEND) ]) dnl Check for a Fortran type equivalent to a netCDF type. dnl dnl UD_CHECK_FORTRAN_NCTYPE(forttype, possibs, nctype) dnl AC_DEFUN([UD_CHECK_FORTRAN_NCTYPE], [ AC_MSG_CHECKING(for Fortran-equivalent to netCDF \"$3\") for type in $2; do cat >conftest.f <conftest.f <conftest.c < #include void main() { $3 values[[]] = {0, $4, 0, $5, 0}; $3 minval, maxval; void $FCALLSCSUB($3*, $3*, $3*); $FCALLSCSUB(values, &minval, &maxval); exit(!(minval == $4 && maxval == $5)); } EOF doit='$CC -o conftest ${CPPFLAGS} ${CFLAGS} ${CFLAGS_64} ${LDFLAGS} conftest.c conftestf.o ${LIBS}' if AC_TRY_EVAL(doit); then doit=./conftest if AC_TRY_EVAL(doit); then AC_MSG_RESULT($2) $1=$2 AC_DEFINE_UNQUOTED($1,$2, [take a guess]) else AC_MSG_RESULT(no equivalent type) unset $1 fi else AC_MSG_ERROR(Could not compile-and-link conftest.c and conftestf.o) fi else AC_MSG_ERROR(Could not compile conftest.f) fi rm -f conftest* ]) dnl Check for a Fortran data type. dnl dnl UD_CHECK_FORTRAN_TYPE(varname, ftypes) dnl AC_DEFUN([UD_CHECK_FORTRAN_TYPE], [ for ftype in $2; do AC_MSG_CHECKING(for Fortran \"$ftype\") cat >conftest.f <conftest.f <<\EOF call sub() end EOF doit='$FC -c ${FFLAGS} ${FFLAGS_64} conftest.f' if AC_TRY_EVAL(doit); then FCALLSCSUB=`$NM $NMFLAGS conftest.o | awk ' /SUB_/{print "SUB_";exit} /SUB/ {print "SUB"; exit} /sub_/{print "sub_";exit} /sub/ {print "sub"; exit}'` case "$FCALLSCSUB" in '') AC_MSG_ERROR(not found) ;; *) AC_MSG_RESULT($FCALLSCSUB) ;; esac else AC_MSG_ERROR(Could not compile conftest.f) fi rm -f conftest* ;; esac ]) dnl Check for a C type equivalent to a Fortran type. dnl dnl UD_CHECK_CTYPE_FORTRAN(ftype, ctypes, fmacro_root) dnl AC_DEFUN([UD_CHECK_CTYPE_FORTRAN], [ cat >conftestf.f <conftest.c </dev/null || echo dummy_system` FTPBINDIR=${FTPDIR-/home/ftp}/pub/binary/$system ;; esac AC_SUBST(FTPBINDIR)dnl AC_MSG_RESULT($FTPBINDIR) ]) dnl dnl dnl dnl dnl These headers won't get C style comments dnl dnl UD_CONFIG_HEADER(HEADER-TO-CREATE ...) AC_DEFUN([UD_CONFIG_HEADER], [define(UD_LIST_HEADER, $1)]) dnl dnl Print which compilers are going to be used, the flags, and their dnl locations. This is all to assist in debugging, and help with dnl support questions. dnl AC_DEFUN([UD_DISPLAY_RESULTS], [ AC_MSG_CHECKING(CPPFLAGS) AC_MSG_RESULT($CPPFLAGS) AC_MSG_CHECKING(CC CFLAGS) AC_MSG_RESULT($CC $CFLAGS) ud_type_cc=`type $CC` AC_MSG_CHECKING(type $CC) AC_MSG_RESULT($ud_type_cc) AC_MSG_CHECKING(CXX) if test -n "$CXX"; then AC_MSG_RESULT($CXX) AC_MSG_CHECKING(CXXFLAGS) AC_MSG_RESULT($CXXFLAGS) ud_type_CXX=`type $CXX` AC_MSG_CHECKING(type $CXX) AC_MSG_RESULT($ud_type_CXX) else AC_MSG_RESULT(unset) fi AC_MSG_CHECKING(FC) if test -n "$FC"; then AC_MSG_RESULT($FC) AC_MSG_CHECKING(FFLAGS) AC_MSG_RESULT($FFLAGS) ud_type_fc=`type $FC` AC_MSG_CHECKING(type $FC) AC_MSG_RESULT($ud_type_fc) else AC_MSG_RESULT(unset) fi AC_MSG_CHECKING(F90) if test -n "$F90"; then AC_MSG_RESULT($F90) AC_MSG_CHECKING(F90FLAGS) AC_MSG_RESULT($F90FLAGS) ud_type_F90=`type $F90` AC_MSG_CHECKING(type $F90) AC_MSG_RESULT($ud_type_F90) else AC_MSG_RESULT(unset) fi AC_MSG_CHECKING(AR) if test -n "$AR"; then AC_MSG_RESULT($AR) AC_MSG_CHECKING(ARFLAGS) AC_MSG_RESULT($ARFLAGS) ud_type_AR=`type $AR` AC_MSG_CHECKING(type $AR) AC_MSG_RESULT($ud_type_AR) else AC_MSG_RESULT(unset) fi AC_MSG_CHECKING(NM) if test -n "$NM"; then AC_MSG_RESULT($NM) AC_MSG_CHECKING(NMFLAGS) AC_MSG_RESULT($NMFLAGS) # ud_type_NM=`type $NM` # AC_MSG_CHECKING(type $NM) # AC_MSG_RESULT($ud_type_NM) else AC_MSG_RESULT(unset) fi ]) # AC_PROG_FC_MOD # --------------- AC_DEFUN([AC_PROG_FC_UPPERCASE_MOD], [ AC_LANG_PUSH(Fortran) AC_MSG_CHECKING([if Fortran 90 compiler capitalizes .mod filenames]) cat <conftest.f90 module conftest end module conftest EOF ac_try='$F90 ${F90FLAGS} conftest.f90 ${F90LIBS}>&AS_MESSAGE_LOG_FD' if AC_TRY_EVAL(ac_try) && test -f CONFTEST.mod ; then ac_cv_prog_f90_uppercase_mod=yes rm -f CONFTEST.mod else ac_cv_prog_f90_uppercase_mod=no fi AC_MSG_RESULT($ac_cv_prog_f90_uppercase_mod) #rm -f conftest* AC_LANG_POP(Fortran) ]) # [AC_LANG_CONFTEST([AC_LANG_SOURCE([ module conftest # end module])]) # ac_try='$F90 -o conftest ${F90FLAGS} conftest.f90 ${F90LIBS}>&AS_MESSAGE_LOG_FD' # if AC_TRY_EVAL(ac_try) && # test -f CONFTEST.mod ; then # ac_cv_prog_f90_uppercase_mod=yes # rm -f CONFTEST.mod # else # ac_cv_prog_f90_uppercase_mod=no # fi # rm -f conftest* AC_DEFUN([AX_F90_MODULE_FLAG],[ AC_CACHE_CHECK([fortran 90 modules inclusion flag], ax_f90_modflag, [AC_LANG_PUSH(Fortran) i=0 while test \( -f tmpdir_$i \) -o \( -d tmpdir_$i \) ; do i=`expr $i + 1` done mkdir tmpdir_$i cd tmpdir_$i AC_COMPILE_IFELSE([module conftest_module contains subroutine conftest_routine write(*,'(a)') 'gotcha!' end subroutine conftest_routine end module conftest_module ],[],[]) cd .. ax_f90_modflag="not found" for ax_flag in "-I" "-M" "-p"; do if test "$ax_f90_modflag" = "not found" ; then ax_save_FCFLAGS="$FCFLAGS" FCFLAGS="$ax_save_FCFLAGS ${ax_flag}tmpdir_$i" AC_COMPILE_IFELSE([program conftest_program use conftest_module call conftest_routine end program conftest_program ],[ax_f90_modflag="$ax_flag"],[]) FCFLAGS="$ax_save_FCFLAGS" fi done rm -fr tmpdir_$i if test "$ax_flag" = "not found" ; then AC_MSG_ERROR([unable to find compiler flag for modules inclusion]) fi AC_LANG_POP(Fortran) ])])