diff --git a/.gitattributes b/.gitattributes index 73a5b0228ffc6d9b14d01ab384c0be4aa8161a1e..85b59f640122ee78a451d0689d8bbc541ea3ff0b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -165,6 +165,8 @@ interfaces/testdata/mulval.nc -text m4/ac_lang_program_fortran.m4 -text m4/acx_assert_lang_is_fortran_variant.m4 -text m4/acx_c_package.m4 -text +m4/acx_cfortran_flags.m4 -text +m4/acx_check_cfortran.m4 -text m4/acx_check_strptr_convert.m4 -text m4/acx_execinfo.m4 -text m4/acx_fortran_check_include.m4 -text diff --git a/Makefile.in b/Makefile.in index 66cd526986a0bf7b364cc7d6654e5fddbef6e0f9..80a932991220763cf076d4691c05efd4ee744893 100644 --- a/Makefile.in +++ b/Makefile.in @@ -97,6 +97,8 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = \ $(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \ $(top_srcdir)/m4/acx_c_package.m4 \ + $(top_srcdir)/m4/acx_cfortran_flags.m4 \ + $(top_srcdir)/m4/acx_check_cfortran.m4 \ $(top_srcdir)/m4/acx_check_strptr_convert.m4 \ $(top_srcdir)/m4/acx_execinfo.m4 \ $(top_srcdir)/m4/acx_fortran_package.m4 \ diff --git a/acinclude.m4 b/acinclude.m4 index b886306992ebafa8515078febab1dfa2df32fdc2..183afb1a877ca261e0785d1f92b71f6434b23adc 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1,19 +1,3 @@ -dnl -dnl AC_CHECK_CFINT -dnl -dnl Check C / Fortran interface -dnl -AC_DEFUN([ACX_CHECK_CFINT], - [AC_CACHE_CHECK([whether the C / Fortran interface works],[acx_cv_check_cfint], - [AC_LANG_PUSH([C]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include "$1"],[])], - [acx_cv_check_cfint=yes], - [acx_cv_check_cfint=no]) - AC_LANG_POP([C])]) - AS_IF([test x$acx_cv_check_cfint = xyes], - [AC_DEFINE(HAVE_CF_INTERFACE, [1], - [Define if C / Fortran interface cfortran.h works])]) - ]) m4_include([m4/ac_lang_program_fortran.m4]) m4_include([m4/acx_lang_fortran_check_include.m4]) m4_include([m4/acx_lang_c_check_include.m4]) diff --git a/aclocal.m4 b/aclocal.m4 index 3f8b4f3ee6dc90f5c09c900218da206e39eda11a..19644f2208af65e7529ce33943e75662f10b72fb 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1185,6 +1185,8 @@ AC_SUBST([am__untar]) m4_include([m4/acx_assert_lang_is_fortran_variant.m4]) m4_include([m4/acx_c_package.m4]) +m4_include([m4/acx_cfortran_flags.m4]) +m4_include([m4/acx_check_cfortran.m4]) m4_include([m4/acx_check_strptr_convert.m4]) m4_include([m4/acx_execinfo.m4]) m4_include([m4/acx_fortran_package.m4]) diff --git a/app/Makefile.in b/app/Makefile.in index b130d304eaf69661ec917fcc3f1b3008c3020006..eef4f669d70780f9c509d7f049469dbdfd799ff0 100644 --- a/app/Makefile.in +++ b/app/Makefile.in @@ -90,6 +90,8 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = \ $(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \ $(top_srcdir)/m4/acx_c_package.m4 \ + $(top_srcdir)/m4/acx_cfortran_flags.m4 \ + $(top_srcdir)/m4/acx_check_cfortran.m4 \ $(top_srcdir)/m4/acx_check_strptr_convert.m4 \ $(top_srcdir)/m4/acx_execinfo.m4 \ $(top_srcdir)/m4/acx_fortran_package.m4 \ diff --git a/config/default b/config/default index 9570e323e81190f33097d67d26c44375f8486410..96003d82998947b3d7725a0e6892cec3e6d37b62 100755 --- a/config/default +++ b/config/default @@ -22,7 +22,7 @@ case "${HOSTNAME}" in --with-grib_api=$HOME/local/gribapi-1.12.3 \ --with-netcdf=$HOME/local \ --with-szlib=$HOME/local \ - CC=icc CFLAGS="-g -D_REENTRANT -Wall -O3 -march=native -Df2cFortran -fp-model source" + CC=icc CFLAGS="-g -D_REENTRANT -Wall -O3 -march=native -fp-model source" ;; bailung*|d133*|d134*) ./configure --prefix=$HOME/local \ @@ -34,7 +34,7 @@ case "${HOSTNAME}" in --with-grib_api=$HOME/local/gribapi-1.12.3 \ --with-netcdf=$HOME/local \ --with-szlib=$HOME/local \ - CC=gcc CFLAGS="-g -pipe -D_REENTRANT -Wall -W -Wfloat-equal -pedantic -O3 -march=native -Df2cFortran" + CC=gcc CFLAGS="-g -pipe -D_REENTRANT -Wall -W -Wfloat-equal -pedantic -O3 -march=native" ;; cinglung*|feilung*|wanglung*) ./configure --prefix=$HOME/local \ @@ -49,7 +49,7 @@ case "${HOSTNAME}" in --with-netcdf=/opt/local \ --with-hdf5=/opt/local \ --with-szlib=/opt/local \ - CC=gcc CFLAGS="-g -pipe -D_REENTRANT -Wall -W -Wfloat-equal -pedantic -O2 -DpgiFortran" + CC=gcc CFLAGS="-g -pipe -D_REENTRANT -Wall -W -Wfloat-equal -pedantic -O2" ;; hama*) ./configure --prefix=$HOME/local \ @@ -59,14 +59,14 @@ case "${HOSTNAME}" in --enable-python \ --with-grib_api=$HOME/local/gribapi-1.13.0 \ --with-netcdf=$HOME/local \ - CC=gcc CFLAGS="-g -pipe -D_REENTRANT -Wall -W -Wfloat-equal -pedantic -O3 -Df2cFortran" + CC=gcc CFLAGS="-g -pipe -D_REENTRANT -Wall -W -Wfloat-equal -pedantic -O3" ;; # ia64-nec-linux ds*) ./configure --prefix=$HOME/local \ --with-netcdf=/pool/ia64/netcdf/netcdf-3.6.0-p1 \ --with-szlib=$HOME/local \ - CC=icc CFLAGS="-g -O2 -Wall -fno-alias -DMIN_BUF_SIZE=4194304 -Df2cFortran" + CC=icc CFLAGS="-g -O2 -Wall -fno-alias -DMIN_BUF_SIZE=4194304" ;; # i686-linux etch-ia32 | gata) @@ -141,7 +141,7 @@ case "${HOSTNAME}" in --with-zlib=/sw/aix61/zlib-1.2.6 \ --with-szlib=/sw/aix61/szip-2.1-threadsafe \ AR="ar -X 64" LDFLAGS="-brtl" FC=xlf2003_r CC=xlc_r \ - CFLAGS="-g -O3 -qhot -q64 -qarch=auto -qtune=auto -qlistfmt=html=transforms -DHAVE_MMAP -Dextname" \ + CFLAGS="-g -O3 -qhot -q64 -qarch=auto -qtune=auto -qlistfmt=html=transforms -DHAVE_MMAP" \ FCFLAGS="-qsuffix=cpp=f90 -qextname" \ SHELL=/bin/bash ;; diff --git a/configure b/configure index 0d5b1d60e0e6817e104af7bf4192dc6e9fe475f5..d933c3fb12a17e3b43d7458d7640af0ae0bdc9e5 100755 --- a/configure +++ b/configure @@ -2506,6 +2506,48 @@ $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_decl + +# ac_fn_fc_try_run LINENO +# ----------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes +# that executables *can* be run. +ac_fn_fc_try_run () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then : + ac_retval=0 +else + $as_echo "$as_me: program exited with status $ac_status" >&5 + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=$ac_status +fi + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_fc_try_run cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. @@ -28716,14 +28758,209 @@ else CREATE_INTERFACES_FALSE= fi -# ---------------------------------------------------------------------- -# Check C / Fortran interface -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C / Fortran interface works" >&5 -$as_echo_n "checking whether the C / Fortran interface works... " >&6; } -if ${acx_cv_check_cfint+:} false; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking C preprocessor flags for Fortran calling convention cfortran.h" >&5 +$as_echo_n "checking C preprocessor flags for Fortran calling convention cfortran.h... " >&6; } +if ${acx_cv_cf_flag+:} false; then : $as_echo_n "(cached) " >&6 else - ac_ext=c + acx_cv_cf_flag='' + for macro in pgiFortran NAGf90Fortran f2cFortran hpuxFortran apolloFortran sunFortran IBMR2Fortran CRAYFortran PATHSCALE_COMPILER gFortran mipsFortran DECFortran vmsFortran CONVEXFortran PowerStationFortran AbsoftUNIXFortran AbsoftProFortran SXFortran +do : + acx_temp=`echo "$CPPFLAGS $CFLAGS" | sed -n 's/^\(.* \)*-D\('"$macro"'\)\( .*\)*$/\2/;t print +b +: print +p'` + if test x"$acx_temp" != x; then : + if test x"$acx_cv_cf_flag" = x; then : + acx_cv_cf_flag="$acx_temp (user-specified)" +else + echo ; echo '"'"$acx_cv_cf_flag $acx_temp"'"' + as_fn_error $? "Multiple specification of cfortran.h flags" "$LINENO" 5 +fi +fi +done + if test x"$acx_cv_cf_flag" = x; then : + if test -n "$F77" -a X"$F77" != Xno; then : + ac_ext=${ac_fc_srcext-f} +ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5' +ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_fc_compiler_gnu + + + + + save_FC=$FC ; acx_FC=$FC + case $host in #( + x86_64-*-linux-*|i*86-*-linux-*|*-apple-darwin*|ia64-*-linux-*|x86_64-*-freebsd*|i*86-*-freebsd*) : + acx_temp=`$acx_FC -V 2>&1` + if echo "$acx_temp" | grep '^Copyright.*\(The Portland Group\|NVIDIA CORPORATION\)' >/dev/null; then : + acx_cv_fc_cf_flag=-DgFortran +elif echo "$acx_temp" | grep '^NAG Fortran Compiler Release' >/dev/null; then : + acx_cv_fc_cf_flag=-DNAGf90Fortran +elif echo "$acx_temp" | grep '^Intel(R) Fortran.*Compiler' >/dev/null; then : + acx_cv_fc_cf_flag=-DgFortran +elif echo "$acx_temp" | grep '^Cray Fortran' >/dev/null; then : + acx_cv_fc_cf_flag=-DgFortran +elif acx_temp=`$acx_FC --version 2>&1` \ + && echo $acx_temp | grep '^GNU Fortran' >/dev/null; then : + if echo $acx_temp | grep g77 >/dev/null; then : + acx_cv_fc_cf_flag=-Dg77Fortran +else + if echo "$FCFLAGS" | grep '^\(.* \)*-ff2c\( .*\)*$' >/dev/null; then : + acx_cv_fc_cf_flag=-Df2cFortran +else + acx_cv_fc_cf_flag=-DgFortran +fi +fi +elif acx_temp=`$acx_FC -v 2>&1` \ + && echo $acx_temp | grep '^f2c'; then : + acx_cv_fc_cf_flag=-Df2cFortran +fi ;; #( + *-ibm-aix*) : + if $CC -qversion 2>&1 | grep '^IBM XL C' >/dev/null; then : + +else + acx_cv_fc_cf_flag=-DIBMR2Fortran +fi + ;; #( + *-*-hpux*) : + acx_cv_fc_cf_flag=-DhpuxFortran ;; #( + sx*-*-*|es*-*-*) : + acx_cv_fc_cf_flag=-DSXFortran ;; #( + *) : + ;; +esac + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +fi + if test -n "$FC" -a X"$FC" != Xno; then : + ac_ext=f +ac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&5' +ac_link='$F77 -o conftest$ac_exeext $FFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_f77_compiler_gnu + + + + + save_F77=$F77 ; acx_FC=$F77 + case $host in #( + x86_64-*-linux-*|i*86-*-linux-*|*-apple-darwin*|ia64-*-linux-*|x86_64-*-freebsd*|i*86-*-freebsd*) : + acx_temp=`$acx_FC -V 2>&1` + if echo "$acx_temp" | grep '^Copyright.*\(The Portland Group\|NVIDIA CORPORATION\)' >/dev/null; then : + acx_cv_f77_cf_flag=-DgFortran +elif echo "$acx_temp" | grep '^NAG Fortran Compiler Release' >/dev/null; then : + acx_cv_f77_cf_flag=-DNAGf90Fortran +elif echo "$acx_temp" | grep '^Intel(R) Fortran.*Compiler' >/dev/null; then : + acx_cv_f77_cf_flag=-DgFortran +elif echo "$acx_temp" | grep '^Cray Fortran' >/dev/null; then : + acx_cv_f77_cf_flag=-DgFortran +elif acx_temp=`$acx_FC --version 2>&1` \ + && echo $acx_temp | grep '^GNU Fortran' >/dev/null; then : + if echo $acx_temp | grep g77 >/dev/null; then : + acx_cv_f77_cf_flag=-Dg77Fortran +else + if echo "$FFLAGS" | grep '^\(.* \)*-ff2c\( .*\)*$' >/dev/null; then : + acx_cv_f77_cf_flag=-Df2cFortran +else + acx_cv_f77_cf_flag=-DgFortran +fi +fi +elif acx_temp=`$acx_FC -v 2>&1` \ + && echo $acx_temp | grep '^f2c'; then : + acx_cv_f77_cf_flag=-Df2cFortran +fi ;; #( + *-ibm-aix*) : + if $CC -qversion 2>&1 | grep '^IBM XL C' >/dev/null; then : + +else + acx_cv_f77_cf_flag=-DIBMR2Fortran +fi + ;; #( + *-*-hpux*) : + acx_cv_f77_cf_flag=-DhpuxFortran ;; #( + sx*-*-*|es*-*-*) : + acx_cv_f77_cf_flag=-DSXFortran ;; #( + *) : + ;; +esac + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +fi + if test -z "$FC" -o X"$FC" != Xno; then : + acx_cv_cf_flag="$acx_cv_fc_cf_flag (probed)" +elif test -z "$F77" -o X"$F77" != Xno; then : + acx_cv_cf_flag="$acx_cv_f77_cf_flag (probed)" +else + if test x"$acx_cv_f77_cf_flag" = x"$acx_cv_fc_cf_flag"; then : + acx_cv_cf_flag="$acx_cv_f77_cf_flag (probed)" +else + as_fn_error $? "cfortran.h flag for $F77 does not match the flag for $FC. +Have you configured compatible compilers?" "$LINENO" 5 +fi +fi + + +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $acx_cv_cf_flag" >&5 +$as_echo "$acx_cv_cf_flag" >&6; } + if echo "$acx_cv_cf_flag" | grep ' (probed)$' >/dev/null; then : + CPPFLAGS="${CPPFLAGS+$CPPFLAGS }`echo "$acx_cv_cf_flag" | sed 's/ (probed)$//'`" +fi + +case $host in #( + *-ibm-aix*) : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if -Dappendus needs to be added to CPPFLAGS for cfortran.h" >&5 +$as_echo_n "checking if -Dappendus needs to be added to CPPFLAGS for cfortran.h... " >&6; } + if $CC -qversion 2>&1 | grep '^IBM XL C' >/dev/null; then : + acx_temp_qextname_f77flags=`echo "$FFLAGS" | sed -n '/-qextname/{ s/^\(.* \)*-qextname\( .*\)*$/-qextname/;p;}'` + acx_temp_qextname_fcflags=`echo "$FCFLAGS" | sed -n '/-qextname/{ s/^\(.* \)*-qextname\( .*\)*$/-qextname/;p;}'` + + if $FC -qversion 2>&1 | grep '^IBM XL Fortran' >/dev/null; then : + +else + acx_temp_qextname_fcflags=-qextname +fi + case x"$acx_temp_qextname_fcflags$acx_temp_qextname_f77flags" in #( + x-qextname) : + as_fn_error $? "Option -qextname must be provided consistently to F77 and FC" "$LINENO" 5 ;; #( + x-qextname-qextname) : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + CPPFLAGS="${CPPFLAGS+$CPPFLAGS }-Dappendus" ;; #( + *) : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } ;; +esac + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi ;; #( + *) : + ;; +esac +if test -n "$FC" -a X"$FC" != Xno -o -n "$F77" -a X"$F77" != Xno; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if C externals constructed with cfortran.h work" >&5 +$as_echo_n "checking if C externals constructed with cfortran.h work... " >&6; } +if ${acx_cv_cfortran_works+:} false; then : + $as_echo_n "(cached) " >&6 +else + acx_cv_cfortran_works=no + save_CPPFLAGS=$CPPFLAGS + CPPFLAGS="-I$srcdir/src $CPPFLAGS" + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' @@ -28731,19 +28968,172 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include "$srcdir/src/cfortran.h" -int -main () +#include "cfortran.h" +#include <math.h> +#include <stdio.h> +#include <stdlib.h> + +PROTOCCALLSFFUN1(FLOAT,CONFTEST_F,conftest_f,FLOAT) +#define conftest_F(v) \ + CCALLSFFUN1(CONFTEST_F,conftest_f,FLOAT,(v)); + +static float +conftest_C(int i, float v, int *p, float *q) { + float f; + *p = (int)roundf(v * i); + *q = f = conftest_F(v * i); + return f; +} - ; - return 0; +FCALLSCFUN4(FLOAT,conftest_C,CONFTEST_C,conftest_c,INT,FLOAT,PINT,PFLOAT) + +/* test string returns */ +static const char * +conftest_str_C(void) +{ + static const char msg[100] = "aaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + return msg; } + +FCALLSCFUN0(STRING,conftest_str_C,CONFTEST_STR_C,conftest_str_c) + +/* This function is required simply because some Fortran compilers + * won't stop with exit code n when encountering STOP n */ +static void +errExit(void) +{ + exit(1); +} + +FCALLSCSUB0(errExit,ERR_EXIT,err_exit) + + _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - acx_cv_check_cfint=yes + { { $as_echo "$as_me:${as_lineno-$LINENO}: Renaming C object file." >&5; } >&5 + (mv "conftest.$ac_objext" "conftest_c.$ac_objext") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + ac_ext=${ac_fc_srcext-f} +ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5' +ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_fc_compiler_gnu + + cat > conftest.$ac_ext <<_ACEOF + MODULE conftest_data + IMPLICIT NONE + PRIVATE + REAL :: ri + PUBLIC :: ri + END MODULE conftest_data + + FUNCTION conftest_f(v) RESULT(r) + USE conftest_data, ONLY: ri + REAL, INTENT(in) :: v + REAL :: r + r = v * 100.0 + ri = 1.0 / v + END FUNCTION conftest_f +_ACEOF +if ac_fn_fc_try_compile "$LINENO"; then : + { { $as_echo "$as_me:${as_lineno-$LINENO}: Renaming Fortran object file." >&5; } >&5 + (mv "conftest.$ac_objext" "conftest_f.$ac_objext") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + save_LIBS=$LIBS + LIBS="conftest_c.$ac_objext conftest_f.$ac_objext $LIBS" + if test "$cross_compiling" = yes; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: Skipping run test for cfortran.h in cross-compilation mode," >&5 +$as_echo "$as_me: Skipping run test for cfortran.h in cross-compilation mode," >&6;} + { $as_echo "$as_me:${as_lineno-$LINENO}: link test succeeded." >&5 +$as_echo "$as_me: link test succeeded." >&6;} + acx_cv_cfortran_works=yes +else + cat > conftest.$ac_ext <<_ACEOF + program conftest + USE conftest_data, ONLY: ri + IMPLICIT NONE + INTERFACE + FUNCTION conftest_c(i, v, p, q) RESULT(f) + INTEGER, INTENT(in) :: i + REAL, INTENT(in) :: v + INTEGER, INTENT(out) :: p + REAL, INTENT(out) :: q + REAL :: f + END FUNCTION conftest_c + FUNCTION conftest_str_c() result(s) + CHARACTER(99) :: s + END FUNCTION conftest_str_c + END INTERFACE + REAL, PARAMETER :: eps = 10e-6 + REAL :: foo, boo, too + INTEGER :: bar, baz, i + CHARACTER(99) :: aaaaaa + bar = 5 + foo = 0.3 + too = conftest_c(bar, foo, baz, boo) + IF (ABS(baz - NINT(bar * foo)) /= 0) THEN + WRITE (0, '(2(a,i0))') "error checking, when baz, baz=", baz, & + ", NINT(bar * foo) =", NINT(bar * foo) + FLUSH(0) + CALL err_exit + END IF + IF (ABS((ri - 1.0 / (bar * foo)) / ABS(ri)) > eps) THEN + WRITE (0, '(2(a,g24.15))') "error checking ri, ri=", ri, ", 1.0 / & + &(bar * foo) = ", 1.0 / (bar * foo) + FLUSH(0) + CALL err_exit + END IF + IF (ABS((boo - (bar * foo * 100.0))/ABS(boo)) > eps) THEN + WRITE (0, '(2(a,g24.15))') "error checking boo, boo=", boo, & + ", bar * foo * 100.0 = ", bar * foo * 100.0 + FLUSH(0) + CALL err_exit + END IF + IF (too /= boo) THEN + WRITE (0, '(2(a,g24.15))') "error checking too vs. boo, too=", too, & + ", boo = ", boo + FLUSH(0) + CALL err_exit + END IF + aaaaaa = conftest_str_c() + DO i = 1, 99 + IF (aaaaaa(i:i) /= 'a') THEN + WRITE (0, '(a,i0,a)') "error checking aaaaaa(", i, ")=", & + aaaaaa(i:i) + FLUSH(0) + CALL err_exit + END IF + END DO + end +_ACEOF +if ac_fn_fc_try_run "$LINENO"; then : + acx_cv_cfortran_works=yes else - acx_cv_check_cfint=no + acx_cv_cfortran_works="error" +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +else + acx_cv_cfortran_works="error compiling Fortran subroutine" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + LIBS=$save_LIBS +else + acx_cv_cfortran_works="compiling with cfortran.h failed" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_ext=c @@ -28752,16 +29142,40 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu + CPPFLAGS=$save_CPPFLAGS + fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $acx_cv_check_cfint" >&5 -$as_echo "$acx_cv_check_cfint" >&6; } - if test x$acx_cv_check_cfint = xyes; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $acx_cv_cfortran_works" >&5 +$as_echo "$acx_cv_cfortran_works" >&6; } + case x"$acx_cv_cfortran_works" in #( + x"error") : + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "Linking/Running with C EXTERNAL built with cfortran.h does not work! +See \`config.log' for more details" "$LINENO" 5; } ;; #( + x"compiling with cfortran.h failed") : + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "Compilation with cfortran.h is not working! +See \`config.log' for more details" "$LINENO" 5; } ;; #( + x"error compiling Fortran subroutine") : + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "compilation of simple Fortran source failed! +See \`config.log' for more details" "$LINENO" 5; } ;; #( + xyes) : $as_echo "#define HAVE_CF_INTERFACE 1" >>confdefs.h + ;; #( + *) : + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "Unexpected error when linking C and Fortran via cfortran.h! +See \`config.log' for more details" "$LINENO" 5; } ;; +esac fi - - if test -n "$FC" && test "X$FC" != "Xno" && test x$acx_cv_check_cfint = "xyes"; then + if test -n "$FC" -a X"$FC" != Xno -a x"$acx_cv_cfortran_works" = xyes; then USE_FC_TRUE= USE_FC_FALSE='#' else diff --git a/configure.ac b/configure.ac index 0dee0b87c994beab992b4c994bdc9aa0a757915e..525af26e9144cd179961121e10c6208431583a0f 100644 --- a/configure.ac +++ b/configure.ac @@ -319,10 +319,16 @@ AM_CONDITIONAL(ENABLE_PYTHON, [test "x$enable_python" != "xno"]) AS_IF([test "x$enable_python" != "xno"],[AC_SUBST([ENABLE_PYTHON],[true])],[AC_SUBST([ENABLE_PYTHON],[false])]) # ---------------------------------------------------------------------- AM_CONDITIONAL(CREATE_INTERFACES, [test "x$enable_ruby" = "xyes" -o "x$enable_python" = "xyes"]) -# ---------------------------------------------------------------------- -# Check C / Fortran interface -ACX_CHECK_CFINT([$srcdir/src/cfortran.h]) -AM_CONDITIONAL([USE_FC],[test -n "$FC" && test "X$FC" != "Xno" && test x$acx_cv_check_cfint = "xyes"])dnl +dnl ###################################################################### +dnl Test whether cfortran.h works correctly +dnl ###################################################################### +ACX_FIND_CFORTRAN_DEF +ACX_XLF_QEXTNAME_ADD_APPENDUS +AS_IF([test -n "$FC" -a X"$FC" != Xno -o -n "$F77" -a X"$F77" != Xno], + [ACX_CHECK_CFORTRAN([$srcdir/src], + [AC_DEFINE([HAVE_CF_INTERFACE],[1], + [Defined to 1 if C / Fortran interface cfortran.h works])])]) +AM_CONDITIONAL([USE_FC],[test -n "$FC" -a X"$FC" != Xno -a x"$acx_cv_cfortran_works" = xyes])dnl dnl AC_SUBST([CPPFLAGS])dnl dnl diff --git a/examples/Makefile.in b/examples/Makefile.in index e7ec26b544d0033eafd5c2539805e6dbb5d99dc2..f79ede202065cda4f3ab0a512032e8223c8af762 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -90,6 +90,8 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = \ $(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \ $(top_srcdir)/m4/acx_c_package.m4 \ + $(top_srcdir)/m4/acx_cfortran_flags.m4 \ + $(top_srcdir)/m4/acx_check_cfortran.m4 \ $(top_srcdir)/m4/acx_check_strptr_convert.m4 \ $(top_srcdir)/m4/acx_execinfo.m4 \ $(top_srcdir)/m4/acx_fortran_package.m4 \ diff --git a/examples/pio/Makefile.in b/examples/pio/Makefile.in index dee19eadfcaaaa2b3e4078d80261c9a68fc54a00..96e3572edf2e7640afe5193a13ab478daea13b00 100644 --- a/examples/pio/Makefile.in +++ b/examples/pio/Makefile.in @@ -91,6 +91,8 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = \ $(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \ $(top_srcdir)/m4/acx_c_package.m4 \ + $(top_srcdir)/m4/acx_cfortran_flags.m4 \ + $(top_srcdir)/m4/acx_check_cfortran.m4 \ $(top_srcdir)/m4/acx_check_strptr_convert.m4 \ $(top_srcdir)/m4/acx_execinfo.m4 \ $(top_srcdir)/m4/acx_fortran_package.m4 \ diff --git a/interfaces/Makefile.in b/interfaces/Makefile.in index 646a909aaad40acfe6727085f0b1bb0f13109a17..7238237e02fe450ec18ef74deda6b52645583c09 100644 --- a/interfaces/Makefile.in +++ b/interfaces/Makefile.in @@ -97,6 +97,8 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = \ $(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \ $(top_srcdir)/m4/acx_c_package.m4 \ + $(top_srcdir)/m4/acx_cfortran_flags.m4 \ + $(top_srcdir)/m4/acx_check_cfortran.m4 \ $(top_srcdir)/m4/acx_check_strptr_convert.m4 \ $(top_srcdir)/m4/acx_execinfo.m4 \ $(top_srcdir)/m4/acx_fortran_package.m4 \ diff --git a/m4/acx_cfortran_flags.m4 b/m4/acx_cfortran_flags.m4 new file mode 100644 index 0000000000000000000000000000000000000000..757e105b5466ff698d0179ee194f0370e7fc81bb --- /dev/null +++ b/m4/acx_cfortran_flags.m4 @@ -0,0 +1,169 @@ +dnl acx_fc_c_link.m4 --- transform library c flags into version +dnl that suits the fortran compiler +dnl +dnl Copyright (C) 2011 Thomas Jahns <jahns@dkrz.de> +dnl +dnl Version: 1.0 +dnl Keywords: +dnl Author: Thomas Jahns <jahns@dkrz.de> +dnl Maintainer: Thomas Jahns <jahns@dkrz.de> +dnl URL: https://www.dkrz.de/redmine/projects/show/scales-ppm +dnl +dnl Redistribution and use in source and binary forms, with or without +dnl modification, are permitted provided that the following conditions are +dnl met: +dnl +dnl Redistributions of source code must retain the above copyright notice, +dnl this list of conditions and the following disclaimer. +dnl +dnl Redistributions in binary form must reproduce the above copyright +dnl notice, this list of conditions and the following disclaimer in the +dnl documentation and/or other materials provided with the distribution. +dnl +dnl Neither the name of the DKRZ GmbH nor the names of its contributors +dnl may be used to endorse or promote products derived from this software +dnl without specific prior written permission. +dnl +dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +dnl IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +dnl TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +dnl PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +dnl OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +dnl +dnl ACX_FC_XLF_QEXTNAME_ADD_APPENDUS +dnl Test if compiler is xlf and if -qextname is in use. +dnl Add -Dappendus to CPPFLAGS if the above applies. +dnl +AC_DEFUN([ACX_XLF_QEXTNAME_ADD_APPENDUS], + [AS_CASE([$host], + [*-ibm-aix*], + [AC_MSG_CHECKING([if -Dappendus needs to be added to CPPFLAGS for cfortran.h]) + AS_IF([$CC -qversion 2>&1 | grep '^IBM XL C' >/dev/null], + [acx_temp_qextname_f77flags=`echo "$FFLAGS" | sed -n '/-qextname/{ s/^\(.* \)*-qextname\( .*\)*$/-qextname/;p;}'` + acx_temp_qextname_fcflags=`echo "$FCFLAGS" | sed -n '/-qextname/{ s/^\(.* \)*-qextname\( .*\)*$/-qextname/;p;}'` + dnl pretend the same option as for FC was used if F77 isn't used at all + dnl also in case a non-xl compiler is used it will append an underscore + AC_PROVIDE_IFELSE([AC_PROG_F77],, + [AC_PROVIDE_IFELSE([AC_PROG_FC], + [acx_temp_qextname_f77flags=$acx_temp_qextname_fcflags], + [m4_fatal([AC_PROG_F77 or AC_PROG_FC must have been invoked prior to ACX_XLF_QEXTNAME_ADD_APPENDUS])])]) + dnl and vice versa for FC + AC_PROVIDE_IFELSE([AC_PROG_FC], + [AS_IF([$FC -qversion 2>&1 | grep '^IBM XL Fortran' >/dev/null],, + [acx_temp_qextname_fcflags=-qextname])], + [AC_PROVIDE_IFELSE([AC_PROG_F77], + [acx_temp_qextname_fcflags=$acx_temp_qextname_f77flags])]) + AS_CASE([x"$acx_temp_qextname_fcflags$acx_temp_qextname_f77flags"], + [x-qextname], + [AC_MSG_ERROR([Option -qextname must be provided consistently to F77 and FC])], + [x-qextname-qextname], + [AC_MSG_RESULT([yes]) + CPPFLAGS="${CPPFLAGS+$CPPFLAGS }-Dappendus"], + [AC_MSG_RESULT([no])]) + ],[AC_MSG_RESULT([no])])])]) +dnl +dnl automate flag elicitation for cfortran.h +AC_DEFUN([_ACX_FIND_CFORTRAN_DEF], + [AC_REQUIRE([AC_CANONICAL_HOST]) + _AC_FORTRAN_ASSERT + AC_LANG_CASE([Fortran],[save_FC=$FC ; acx_FC=$FC], + [Fortran 77],[save_F77=$F77 ; acx_FC=$F77]) + AS_CASE([$host], + [x86_64-*-linux-*|i*86-*-linux-*|*-apple-darwin*|ia64-*-linux-*|x86_64-*-freebsd*|i*86-*-freebsd*], + [acx_temp=`$acx_FC -V 2>&1` + AS_IF([echo "$acx_temp" | grep '^Copyright.*\(The Portland Group\|NVIDIA CORPORATION\)' >/dev/null], + [AS_VAR_SET([acx_cf_flag],[-DgFortran])], + [echo "$acx_temp" | grep '^NAG Fortran Compiler Release' >/dev/null], + [AS_VAR_SET([acx_cf_flag],[-DNAGf90Fortran])], + [echo "$acx_temp" | grep '^Intel(R) Fortran.*Compiler' >/dev/null], + [AS_VAR_SET([acx_cf_flag],[-DgFortran])], + [echo "$acx_temp" | grep '^Cray Fortran' >/dev/null], + [AS_VAR_SET([acx_cf_flag],[-DgFortran])], + [acx_temp=`$acx_FC --version 2>&1` \ + && echo $acx_temp | grep '^GNU Fortran' >/dev/null], + [AS_IF([echo $acx_temp | grep g77 >/dev/null], + [AS_VAR_SET([acx_cf_flag],[-Dg77Fortran])], + [dnl assume gfortran +dnl check if compiling with f2c bindings or with default bindings + AS_IF([echo "]AC_LANG_CASE([Fortran],[$FCFLAGS], + [Fortran 77],[$FFLAGS])[" | grep '^\(.* \)*-ff2c\( .*\)*$' >/dev/null], + [AS_VAR_SET([acx_cf_flag],[-Df2cFortran])], + [AS_VAR_SET([acx_cf_flag],[-DgFortran])])])], + [acx_temp=`$acx_FC -v 2>&1` \ + && echo $acx_temp | grep '^f2c'], + [AS_VAR_SET([acx_cf_flag],[-Df2cFortran])])], + [*-ibm-aix*], + [dnl xlc set _IBMR2 so nothing needs to be done + AS_IF([$CC -qversion 2>&1 | grep '^IBM XL C' >/dev/null],, + [dnl but for other compilers set IBMR2Fortran + AS_VAR_SET([acx_cf_flag],[-DIBMR2Fortran])]) + ], + [*-*-hpux*], + [AS_VAR_SET([acx_cf_flag],[-DhpuxFortran])], + [sx*-*-*|es*-*-*], + [dnl fixme: make sure user is actually using sxf90 +dnl but currently there is no alternative I know of + AS_VAR_SET([acx_cf_flag],[-DSXFortran])])]) + +AC_DEFUN([ACX_FIND_CFORTRAN_DEF], + [AC_CACHE_CHECK([C preprocessor flags for Fortran calling convention cfortran.h], + [acx_cv_cf_flag], + [acx_cv_cf_flag='' +dnl test if user already provided a flag + AS_FOR([MACRO],[macro],[pgiFortran NAGf90Fortran f2cFortran hpuxFortran apolloFortran sunFortran IBMR2Fortran CRAYFortran PATHSCALE_COMPILER gFortran mipsFortran DECFortran vmsFortran CONVEXFortran PowerStationFortran AbsoftUNIXFortran AbsoftProFortran SXFortran], + [acx_temp=`echo "$CPPFLAGS $CFLAGS" | sed -n 's/^\(.* \)*-D\('"MACRO"'\)\( .*\)*$/\2/;t print +b +: print +p'` + AS_IF([test x"$acx_temp" != x], + [AS_IF([test x"$acx_cv_cf_flag" = x], + [acx_cv_cf_flag="$acx_temp (user-specified)"], + [echo ; echo '"'"$acx_cv_cf_flag $acx_temp"'"' + AC_MSG_ERROR([Multiple specification of cfortran.h flags])])])]) +dnl find automatically from machine/compiler + AS_IF([test x"$acx_cv_cf_flag" = x], + [AC_PROVIDE_IFELSE([AC_PROG_FC], + [AS_IF([test -n "$F77" -a X"$F77" != Xno], + [AC_LANG_PUSH([Fortran]) + AS_VAR_PUSHDEF([acx_cf_flag],[acx_cv_]_AC_LANG_ABBREV[_cf_flag]) + _ACX_FIND_CFORTRAN_DEF + AS_VAR_POPDEF([acx_cf_flag]) + AC_LANG_POP([Fortran])])]) + AC_PROVIDE_IFELSE([AC_PROG_F77], + [AS_IF([test -n "$FC" -a X"$FC" != Xno], + [AC_LANG_PUSH([Fortran 77]) + AS_VAR_PUSHDEF([acx_cf_flag],[acx_cv_]_AC_LANG_ABBREV[_cf_flag]) + _ACX_FIND_CFORTRAN_DEF + AS_VAR_POPDEF([acx_cf_flag]) + AC_LANG_POP([Fortran 77])])]) +dnl check f77 flag matches fc flag + AC_PROVIDE_IFELSE([AC_PROG_F77], + [AC_PROVIDE_IFELSE([AC_PROG_FC], + [dnl both FC and F77 are configured + AS_IF([test -z "$FC" -o X"$FC" != Xno], + [acx_cv_cf_flag="$acx_cv_fc_cf_flag (probed)"], + [test -z "$F77" -o X"$F77" != Xno], + [acx_cv_cf_flag="$acx_cv_f77_cf_flag (probed)"], + [AS_IF([test x"$acx_cv_f77_cf_flag" = x"$acx_cv_fc_cf_flag"], + [acx_cv_cf_flag="$acx_cv_f77_cf_flag (probed)"], + [AC_MSG_ERROR([cfortran.h flag for $F77 does not match the flag for $FC. +Have you configured compatible compilers?])])]) + ])],[acx_cv_cf_flag="$acx_cv_fc_cf_flag (probed)"]) + ]) + ]) +dnl now that flag is established, add (probed) defines to CPPFLAGS + AS_IF([echo "$acx_cv_cf_flag" | grep ' (probed)$' >/dev/null], + [CPPFLAGS="${CPPFLAGS+$CPPFLAGS }`echo "$acx_cv_cf_flag" | sed 's/ (probed)$//'`"]) + ]) +dnl +dnl Local Variables: +dnl mode: autoconf +dnl license-project-url: "https://www.dkrz.de/redmine/projects/show/scales-ppm" +dnl license-default: "bsd" +dnl End: diff --git a/m4/acx_check_cfortran.m4 b/m4/acx_check_cfortran.m4 new file mode 100644 index 0000000000000000000000000000000000000000..5efa49e41fa6359f97f9ca6a8f8c6591774fb88f --- /dev/null +++ b/m4/acx_check_cfortran.m4 @@ -0,0 +1,202 @@ +dnl acx_check_cfortran.m4 --- test if a program compiled from +dnl a main Fortran program and +dnl C functions gives expected results +dnl +dnl Copyright (C) 2013 Thomas Jahns <jahns@dkrz.de> +dnl +dnl Version: 1.0 +dnl Keywords: +dnl Author: Thomas Jahns <jahns@dkrz.de> +dnl Maintainer: Thomas Jahns <jahns@dkrz.de> +dnl URL: https://www.dkrz.de/redmine/projects/show/scales-ppm +dnl +dnl Redistribution and use in source and binary forms, with or without +dnl modification, are permitted provided that the following conditions are +dnl met: +dnl +dnl Redistributions of source code must retain the above copyright notice, +dnl this list of conditions and the following disclaimer. +dnl +dnl Redistributions in binary form must reproduce the above copyright +dnl notice, this list of conditions and the following disclaimer in the +dnl documentation and/or other materials provided with the distribution. +dnl +dnl Neither the name of the DKRZ GmbH nor the names of its contributors +dnl may be used to endorse or promote products derived from this software +dnl without specific prior written permission. +dnl +dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +dnl IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +dnl TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +dnl PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +dnl OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +dnl +dnl ACX_CHECK_CFORTRAN([OPTIONAL-CFORTRAN-INC-DIR],[ACTION-IF-SUCCESS], +dnl [ACTION-IF-FAILED]) +dnl Test if C compiler can produce objects that link fine to Fortran programs +dnl when using cfortran.h. +dnl +AC_DEFUN([ACX_CHECK_CFORTRAN], + [AC_CACHE_CHECK([if C externals constructed with cfortran.h work], + [acx_cv_cfortran_works], + [acx_cv_cfortran_works=no + save_CPPFLAGS=$CPPFLAGS + CPPFLAGS="-I]m4_ifval([$1],[$1],[$srcdir/include])[ $CPPFLAGS" +dnl build C function + AC_LANG_PUSH([C]) + AC_COMPILE_IFELSE([AC_LANG_SOURCE([@%:@include "cfortran.h" +@%:@include <math.h> +@%:@include <stdio.h> +@%:@include <stdlib.h> + +PROTOCCALLSFFUN1(FLOAT,CONFTEST_F,conftest_f,FLOAT) +#define conftest_F(v) \ + CCALLSFFUN1(CONFTEST_F,conftest_f,FLOAT,(v)); + +static float +conftest_C(int i, float v, int *p, float *q) +{ + float f; + *p = (int)roundf(v * i); + *q = f = conftest_F(v * i); + return f; +} + +FCALLSCFUN4(FLOAT,conftest_C,CONFTEST_C,conftest_c,INT,FLOAT,PINT,PFLOAT) + +/* test string returns */ +static const char * +conftest_str_C(void) +{ + static const char msg@<:@100@:>@ = "aaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + return msg; +} + +FCALLSCFUN0(STRING,conftest_str_C,CONFTEST_STR_C,conftest_str_c) + +/* This function is required simply because some Fortran compilers + * won't stop with exit code n when encountering STOP n */ +static void +errExit(void) +{ + exit(1); +} + +FCALLSCSUB0(errExit,ERR_EXIT,err_exit) + +])], + [_AC_RUN_LOG([mv "conftest.$ac_objext" "conftest_c.$ac_objext"], + [_AS_ECHO_LOG([Renaming C object file.])]) + AC_LANG_PUSH([Fortran]) + AC_COMPILE_IFELSE([AC_LANG_SOURCE( +[ MODULE conftest_data + IMPLICIT NONE + PRIVATE + REAL :: ri + PUBLIC :: ri + END MODULE conftest_data + + FUNCTION conftest_f(v) RESULT(r) + USE conftest_data, ONLY: ri + REAL, INTENT(in) :: v + REAL :: r + r = v * 100.0 + ri = 1.0 / v + END FUNCTION conftest_f])], + [_AC_RUN_LOG([mv "conftest.$ac_objext" "conftest_f.$ac_objext"], + [_AS_ECHO_LOG([Renaming Fortran object file.])]) + save_LIBS=$LIBS + LIBS="conftest_c.$ac_objext conftest_f.$ac_objext $LIBS" + AC_RUN_IFELSE([AC_LANG_PROGRAM(, +[ USE conftest_data, ONLY: ri + IMPLICIT NONE + INTERFACE + FUNCTION conftest_c(i, v, p, q) RESULT(f) + INTEGER, INTENT(in) :: i + REAL, INTENT(in) :: v + INTEGER, INTENT(out) :: p + REAL, INTENT(out) :: q + REAL :: f + END FUNCTION conftest_c + FUNCTION conftest_str_c() result(s) + CHARACTER(99) :: s + END FUNCTION conftest_str_c + END INTERFACE + REAL, PARAMETER :: eps = 10e-6 + REAL :: foo, boo, too + INTEGER :: bar, baz, i + CHARACTER(99) :: aaaaaa + bar = 5 + foo = 0.3 + too = conftest_c(bar, foo, baz, boo) + IF (ABS(baz - NINT(bar * foo)) /= 0) THEN + WRITE (0, '(2(a,i0))') "error checking, when baz, baz=", baz, & + ", NINT(bar * foo) =", NINT(bar * foo) + FLUSH(0) + CALL err_exit + END IF + IF (ABS((ri - 1.0 / (bar * foo)) / ABS(ri)) > eps) THEN + WRITE (0, '(2(a,g24.15))') "error checking ri, ri=", ri, ", 1.0 / & + &(bar * foo) = ", 1.0 / (bar * foo) + FLUSH(0) + CALL err_exit + END IF + IF (ABS((boo - (bar * foo * 100.0))/ABS(boo)) > eps) THEN + WRITE (0, '(2(a,g24.15))') "error checking boo, boo=", boo, & + ", bar * foo * 100.0 = ", bar * foo * 100.0 + FLUSH(0) + CALL err_exit + END IF + IF (too /= boo) THEN + WRITE (0, '(2(a,g24.15))') "error checking too vs. boo, too=", too, & + ", boo = ", boo + FLUSH(0) + CALL err_exit + END IF + aaaaaa = conftest_str_c() + DO i = 1, 99 + IF (aaaaaa(i:i) /= 'a') THEN + WRITE (0, '(a,i0,a)') "error checking aaaaaa(", i, ")=", & + aaaaaa(i:i) + FLUSH(0) + CALL err_exit + END IF + END DO])], + [acx_cv_cfortran_works=yes], + [acx_cv_cfortran_works="error"], + [AC_MSG_NOTICE([Skipping run test for cfortran.h in cross-compilation mode,]) + AC_MSG_NOTICE([link test succeeded.]) + acx_cv_cfortran_works=yes])], + [acx_cv_cfortran_works="error compiling Fortran subroutine"]) + AC_LANG_POP([Fortran]) + LIBS=$save_LIBS], + [acx_cv_cfortran_works="compiling with cfortran.h failed"]) + AC_LANG_POP([C]) + CPPFLAGS=$save_CPPFLAGS + ]) + m4_ifval([$3], + [AS_IF([test x"$acx_cv_cfortran_works" = xyes],[$2],[$3])], + [AS_CASE([x"$acx_cv_cfortran_works"], + [x"error"], + [AC_MSG_FAILURE([Linking/Running with C EXTERNAL built with cfortran.h does not work!])], + [x"compiling with cfortran.h failed"], + [AC_MSG_FAILURE([Compilation with cfortran.h is not working!])], + [x"error compiling Fortran subroutine"], + [AC_MSG_FAILURE([compilation of simple Fortran source failed!])], + [xyes],[$2], + [AC_MSG_FAILURE([Unexpected error when linking C and Fortran via cfortran.h!])])]) + ]) +dnl +dnl Local Variables: +dnl mode: autoconf +dnl license-project-url: "https://www.dkrz.de/redmine/projects/show/scales-ppm" +dnl license-default: "bsd" +dnl End: diff --git a/src/Makefile.in b/src/Makefile.in index 1342c7067183f383242259e4efdc2813b50a9623..108344b4d3f6d64747358787e71772740ed4dea5 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -107,6 +107,8 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = \ $(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \ $(top_srcdir)/m4/acx_c_package.m4 \ + $(top_srcdir)/m4/acx_cfortran_flags.m4 \ + $(top_srcdir)/m4/acx_check_cfortran.m4 \ $(top_srcdir)/m4/acx_check_strptr_convert.m4 \ $(top_srcdir)/m4/acx_execinfo.m4 \ $(top_srcdir)/m4/acx_fortran_package.m4 \ diff --git a/src/config.h.in b/src/config.h.in index 25182f7720e3d0c3bfaac92f36fa3e6ea5d59983..1d4b0ed3c6d83aa2cee385897d05f79263ee7305 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -12,7 +12,7 @@ /* Defined if backtrace() could be fully identified. */ #undef HAVE_BACKTRACE -/* Define if C / Fortran interface cfortran.h works */ +/* Defined to 1 if C / Fortran interface cfortran.h works */ #undef HAVE_CF_INTERFACE /* Define to 1 if you have the declaration of `isnan', and to 0 if you don't. diff --git a/tests/Makefile.in b/tests/Makefile.in index 2cd6deff2db08bb397e1e4c15dde6ea29ebb4694..83b25823cf91549e3302105cbdce4f082d6da931 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -110,6 +110,8 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = \ $(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \ $(top_srcdir)/m4/acx_c_package.m4 \ + $(top_srcdir)/m4/acx_cfortran_flags.m4 \ + $(top_srcdir)/m4/acx_check_cfortran.m4 \ $(top_srcdir)/m4/acx_check_strptr_convert.m4 \ $(top_srcdir)/m4/acx_execinfo.m4 \ $(top_srcdir)/m4/acx_fortran_package.m4 \