test defs: setup `*FLAGS' variables for GNU compilers
authorStefano Lattarini <stefano.lattarini@gmail.com>
Wed, 28 Dec 2011 10:40:20 +0000 (11:40 +0100)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Mon, 23 Jan 2012 08:53:55 +0000 (09:53 +0100)
* configure.ac: Setup some `*FLAGS' variables for use by the
GNU compilers in our testsuite.  For example, use `GNU_CFLAGS'
instead of `CFLAGS', and so on for similar variables.  This
is especially useful in case the compilers found or defined
at configure time are not the GNU ones.
* tests/defs-static.in: Initialize those same variables with
the values set at configure time, but allowing overrides
from the environment.
* tests/Makefile.am (do_subst): Process configure-style
substitutions of those variables (e.g., `@GNU_CFLAGS@').
* tests/defs: When a GNU compiler is required, override the
corresponding generic `*FLAGS' variable with the GNU-specific
variant (e.g., redefine `$CFLAGS' to take the value of
`$GNU_CFLAGS').

configure.ac
tests/Makefile.am
tests/defs
tests/defs-static.in

index 2771efd..aea14ad 100644 (file)
@@ -261,6 +261,7 @@ AC_DEFUN([_AM_COMPILER_CAN_FAIL], [
 
 # C compiler.
 _AM_COMPILER_CAN_FAIL([AC_PROG_CC([cc gcc])], [CC=false])
+AS_IF([test x"$GCC" = x"yes"], [am_CC_is_GNU=yes], [am_CC_is_GNU=no])
 
 # The list of C++ compilers here has been copied, pasted and edited
 # from `lib/autoconf/c.m4:AC_PROG_CXX' in the Autoconf distribution.
@@ -269,18 +270,44 @@ _AM_COMPILER_CAN_FAIL([AC_PROG_CC([cc gcc])], [CC=false])
 _AM_COMPILER_CAN_FAIL([AC_PROG_CXX(dnl
   [aCC CC FCC KCC RCC xlC_r xlC c++ cxx cc++ gpp g++])],
   [CXX=false])
+AS_IF([test x"$GXX" = x"yes"], [am_CXX_is_GNU=yes], [am_CXX_is_GNU=no])
 
 # The lists of Fortran compilers here has been copied, pasted and edited
 # from file `lib/autoconf/fortran.m4' in the Autoconf distribution.
 # Keep it in sync, or better again, find out a way to avoid this code
 # duplication.
+
 _AM_COMPILER_CAN_FAIL([AC_PROG_FC(dnl
   [xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn nagfor] dnl
   [xlf90 f90 pgf90 pghpf epcf90 g95 gfortran])],
   [FC=false])
+# FIXME this won't work as expected until we can assume autoconf 2.69 :-(
+AS_IF([test x"$GFC" = x"yes"], [am_FC_is_GNU=yes], [am_FC_is_GNU=no])
+
 _AM_COMPILER_CAN_FAIL([AC_PROG_F77(dnl
   [xlf f77 frt pgf77 cf77 fort77 fl32 af77 g77 gfortran])],
   [F77=false])
+AS_IF([test x"$G77" = x"yes"], [am_F77_is_GNU=yes], [am_F77_is_GNU=no])
+
+# Some tests will need the GNU compilers.  Searching for them here would
+# be overkill, since our testsuite already handles their search and setup
+# pretty well.  However, in case the compilers detected above at configure
+# time are not the GNU ones, we cannot use the values of CFLAGS, CXXFLAGS,
+# FCFLAGS and FFLAGS detected for them with the GNU compilers too, since
+# it's likely they won't be compatible.  So we allow the user to define
+# variants of this variables for the GNU compilers separately.
+
+test $am_CC_is_GNU = yes && GNU_CFLAGS=${GNU_CFLAGS-$CFLAGS}
+AC_ARG_VAR([GNU_CFLAGS], [GNU C compiler flags])
+
+test $am_CXX_is_GNU = yes && GNU_CXXFLAGS=${GNU_CXXFLAGS-$CXXFLAGS}
+AC_ARG_VAR([GNU_CXXFLAGS], [GNU C++ compiler flags])
+
+test $am_F77_is_GNU = yes && GNU_FCFLAGS=${GNU_FCFLAGS-$FCFLAGS}
+AC_ARG_VAR([GNU_FCFLAGS], [GNU Fortran compiler flags])
+
+test $am_FC_is_GNU = yes && GNU_FFLAGS=${GNU_FFLAGS-$FFLAGS}
+AC_ARG_VAR([GNU_FFLAGS], [GNU Fortran 77 compiler flags])
 
 # If we have been able to find at least a working compiler above, we
 # know what the object and executable extensions for this platform are.
index 5696b44..d47be78 100644 (file)
@@ -147,6 +147,10 @@ do_subst = sed \
   -e 's|@PERL[@]|$(PERL)|g' \
   -e 's|@EGREP[@]|$(EGREP)|g' \
   -e 's|@FGREP[@]|$(FGREP)|g' \
+  -e 's|@GNU_CFLAGS[@]|$(GNU_CFLAGS)|g' \
+  -e 's|@GNU_CXXFLAGS[@]|$(GNU_CXXFLAGS)|g' \
+  -e 's|@GNU_FFLAGS[@]|$(GNU_FFLAGS)|g' \
+  -e 's|@GNU_FCFLAGS[@]|$(GNU_FCFLAGS)|g' \
   -e 's|@TEX[@]|$(TEX)|g' \
   -e 's|@MODIFICATION_DELAY[@]|$(MODIFICATION_DELAY)|g' \
   -e 's|@am_AUTOCONF[@]|$(am_AUTOCONF)|g' \
index 41ee262..1c50523 100644 (file)
@@ -703,7 +703,8 @@ do
       # has defined CC in his environment, otherwise ./configure will
       # prefer gcc to other compilers.
       CC=${am__tool_prefix}gcc
-      export CC
+      CFLAGS=$GNU_CFLAGS
+      export CC CFLAGS
       echo "$me: running $CC --version"
       $CC --version || skip_all_ "GNU C compiler not available"
       echo "$me: running $CC -v"
@@ -719,7 +720,8 @@ do
       ;;
     g++)
       CXX=${am__tool_prefix}g++
-      export CXX
+      CXXFLAGS=$GNU_CXXFLAGS
+      export CXX CXXFLAGS
       echo "$me: running $CXX --version"
       $CXX --version || skip_all_ "GNU C++ compiler not available"
       echo "$me: running $CXX -v"
@@ -727,26 +729,28 @@ do
       ;;
     gfortran)
       FC=${am__tool_prefix}gfortran
-      export FC
+      FCFLAGS=$GNU_FCFLAGS
+      export FC FCFLAGS
       echo "$me: running $FC --version"
       $FC --version || skip_all_ "GNU Fortran compiler not available"
       echo "$me: running $FC -v"
       $FC -v || skip_all_ "botched installation for GNU Fortran compiler"
       case " $required " in
         *\ g77\ *) ;;
-        *) F77=$FC; export F77;;
+        *) F77=$FC FFLAGS=$FCFLAGS; export F77 FFLAGS;;
       esac
       ;;
     g77)
       F77=${am__tool_prefix}g77
-      export F77
+      FFLAGS=$GNU_FFLAGS
+      export F77 FFLAGS
       echo "$me: running $F77 --version"
       $F77 --version || skip_all_ "GNU Fortran 77 compiler not available"
       echo "$me: running $F77 -v"
       $F77 -v || skip_all_ "botched installation for GNU Fortran 77 compiler"
       case " $required " in
         *\ gfortran\ *) ;;
-        *) FC=$F77; export FC;;
+        *) FC=$F77 FCFLAGS=$FFLAGS; export FC FCFLAGS;;
       esac
       ;;
     icc)
index 2bae9c1..e58a1a1 100644 (file)
@@ -194,6 +194,12 @@ AUTORECONF="$AUTORECONF -B /no/such/dir"
 EGREP=${AM_TESTSUITE_EGREP-'@EGREP@'}
 FGREP=${AM_TESTSUITE_FGREP-'@FGREP@'}
 
+# Flags for the GNU compilers.
+GNU_FFLAGS=${AM_TESTSUITE_GNU_FFLAGS-${GNU_FFLAGS-'@GNU_FFLAGS@'}}
+GNU_FCFLAGS=${AM_TESTSUITE_GNU_FCFLAGS-${GNU_FCFLAGS-'@GNU_FCFLAGS@'}}
+GNU_CXXFLAGS=${AM_TESTSUITE_GNU_CXXFLAGS-${GNU_CXXFLAGS-'@GNU_CXXFLAGS@'}}
+GNU_CFLAGS=${AM_TESTSUITE_GNU_CFLAGS-${GNU_CFLAGS-'@GNU_CFLAGS@'}}
+
 # No all versions of Tex support `--version', so we use a configure
 # check to decide if tex is available.  This decision is embodied in
 # this variable.