Second refactoring of this part of code. The result is admittedly more unelegant and "spaghetti-code-style", but it's necessary to the next patch ("Clobber global CFLAGS etc. when requiring GNU compilers.")
Regads, Stefano -*-*-*- Refactor code requiring compilers in testsuite. * tests/defs.in (require_gnu_compilers): Removed, merged ... (require_compiler): ... with this one, and added knowledge of which compilers/variables should be used with which language (e.g. gcc, $CC for the C language, g++, $CXX for C++, etc). All usages updated accordingly. --- ChangeLog | 7 ++++ tests/defs.in | 111 +++++++++++++++++++++++++++++++++----------------------- 2 files changed, 72 insertions(+), 46 deletions(-)
From 3e874d9a21214789bdda6a2b6c77d5887533c7ba Mon Sep 17 00:00:00 2001 From: Stefano Lattarini <stefano.lattar...@gmail.com> Date: Fri, 2 Jul 2010 12:41:30 +0200 Subject: [PATCH 12/14] Refactor code requiring compilers in testsuite. * tests/defs.in (require_gnu_compilers): Removed, merged ... (require_compiler): ... with this one, and added knowledge of which compilers/variables should be used with which language (e.g. gcc, $CC for the C language, g++, $CXX for C++, etc). All usages updated accordingly. --- ChangeLog | 7 ++++ tests/defs.in | 111 +++++++++++++++++++++++++++++++++----------------------- 2 files changed, 72 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6a1d5a0..0d1e536 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2010-07-02 Stefano Lattarini <stefano.lattar...@gmail.com> + Refactor code requiring compilers in testsuite. + * tests/defs.in (require_gnu_compilers): Removed, merged ... + (require_compiler): ... with this one, and added knowledge of + which compilers/variables should be used with which language (e.g. + gcc, $CC for the C language, g++, $CXX for C++, etc). + All usages updated accordingly. + Fix code for requiring gfortran in tests. * tests/defs.in: Correctly set and export F77 and/or FC when gfortran is in $required. diff --git a/tests/defs.in b/tests/defs.in index 42a23ef..d34d425 100644 --- a/tests/defs.in +++ b/tests/defs.in @@ -88,51 +88,71 @@ echo "$PATH" # (See note about `export' in the Autoconf manual.) export PATH -# Usage: require_compiler ENV-VARIABLE [FALLBACK-GNU-COMPILERS] +# require_compiler [--force-gnu|--avoid-gnu] {c|c++|gcj|f9x|f77} # Presently, this function is meant for internal use only. require_compiler() { - eval compiler=\$$1 - if eval test x"$compiler" = x"no"; then + what_gnu=try + case $1 in + --force-gnu) what_gnu=force; shift;; + --avoid-gnu) what_gnu=avoid; shift;; + -*) echo "$me: require_compiler: $1: invalid option" >&2; exit 99;; + esac + + case $1 in + c) + compiler_variable=CC + gnu_compiler_candidates=gcc;; + c++) + compiler_variable=CXX + gnu_compiler_candidates=g++;; + f77) + compiler_variable=F77 + # gfortran should be able to seamlessly compile Fortran 77 code + gnu_compiler_candidates='g77 gfortran';; + f9x) + compiler_variable=FC + gnu_compiler_candidates=gfortran;; + gcj) + compiler_variable=GCJ + gnu_compiler_candidates=gcj;; + *) + echo "$me: $1: invalid compiler language" >&2; exit 99;; + esac + + eval compiler=\$$compiler_variable + + if test x"$what_gnu" != x"force" && test x"$compiler" = x"no"; then # The user told explicitly he doesn't want a compiler of this kind # to be used. - echo "$me: \$$1 is \"no\", skipping test" + echo "$me: \$$compiler_variable is \"no\", skipping test" exit 77 - elif test -z "$compiler"; then - if test $# -gt 1; then - # The user specified no explicit compiler in its environment, so - # we try to force the use of a GNU compiler. - require_gnu_compiler "$@" - else - echo "$me: \$$1 is unset or empty, and no default GNU compiler" \ - "has been specified" - exit 77 - fi fi - unset compiler -} -# Usage: require_gnu_compiler ENV-VARIABLE GNU-COMPILER [OTHER-GNU-COMPILERS] -# Presently, this function is meant for internal use only. -require_gnu_compiler() -{ - environment_variable=$1 - shift - have_gnu_compiler=false - for gnu_compiler in ${1+"$@"}; do - echo "$me: running $gnu_compiler --version" - "$gnu_compiler" --version || continue - # This gives more information about the compiler, and also checks for - # e.g. broken gcj installations. - echo "$me: running $gnu_compiler -v" - "$gnu_compiler" -v || continue - echo # gracefully separate verbose information from rest of testlog - have_gnu_compiler=: - done - $have_gnu_compiler || exit 77 - eval $environment_variable=\$gnu_compiler - export $environment_variable - unset environment_variable gnu_compiler have_gnu_compiler + if { test x"$what_gnu" = x"try" && test -z "$compiler"; } \ + || test x"$what_gnu" = x"force"; then + # Either the user specified no explicit compiler in its environment, + # or the script asked to force the use of a GNU compiler, so we try + # to enable the use of a GNU compiler. + have_gnu_compiler=false + for compiler in $gnu_compiler_candidates; do + echo "$me: running $compiler --version" + "$compiler" --version || continue + # This gives more information about the compiler, and also checks + # for e.g. broken gcj installations. + echo "$me: running $compiler -v" + "$compiler" -v || continue + echo # gracefully separate verbose information from rest of testlog + have_gnu_compiler=: + done + $have_gnu_compiler || exit 77 + eval "$compiler_variable=\$compiler" + export $compiler_variable + fi + + # Remove local variables. + unset what_gnu compiler_variable compiler + unset gnu_compiler_candidates have_gnu_compiler } for tool in : $required @@ -168,29 +188,28 @@ do ( $MAKE --version -v | grep GNU ) || exit 77 ;; cc) - require_compiler 'CC' gcc + require_compiler c ;; gcc) - require_gnu_compiler 'CC' gcc + require_compiler --force-gnu c ;; gcj) - require_gnu_compiler 'GCJ' gcj + require_compiler --force-gnu gcj ;; c++) - require_compiler 'CXX' g++ + require_compiler c++ ;; g++) - require_gnu_compiler 'CXX' g++ + require_compiler --force-gnu c++ ;; fortran) - require_compiler 'FC' gfortran + require_compiler f9x ;; fortran77) - # gfortran should be able to seamlessly compile Fortran 77 code - require_compiler 'F77' g77 gfortran + require_compiler f77 ;; gfortran) - require_gnu_compiler 'FC' gfortran + require_compiler --force-gnu f9x # This ensures that gfortran and a fortran77 compiler can both be # required. case " $required " in -- 1.6.5