autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

to conditionally test, or not to conditionally test?


From: Ed Hartnett
Subject: to conditionally test, or not to conditionally test?
Date: Fri, 20 May 2005 08:51:41 -0600
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Howdy all!

I am refactoring an autoconf configure.in file for an open source
software library for climate scientists.

I read somewhere in my autoconf researches on the web that tests
should not be run conditionally, based on earlier tests - they should
always run. In other words, don't try and optimize configure.ac.

Is this really good advice?

For example, in my library, there are optionally-built C++, F77, and
F90 APIs. If you want the C++ API, I need to run a bunch of C++ tests.

If you don't want C++, I would prefer not to run them. 

I wonder if anyone would like to comment on the configure.ac fragment
below. This code seems to work fine, but am I missing something? Note
that checking the C++ compiler occurs only if $nc_build_cxx = yes.

Most of my configure script has to do with C++, F77, and F90 APIs,
which I hardly ever need build when working on my C library. Does it
really make me a bad person if I run these tests conditionally?

But whatever I do must be portable. This library is run on just about
every flavor of Unix, plus Windows.

>From configure.ac:

# On some systems, a discovered compiler nevertheless won't work
# (because it's a script to a non-existent 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.
if test "x${nc_build_cxx}" = xyes; then
   AC_MSG_CHECKING([if C++ compiler works])
   AC_LANG_SAVE()
   AC_LANG_CPLUSPLUS()
   AC_RUN_IFELSE([
      AC_LANG_SOURCE([[
                #include <iostream>
                int main() {
                    std::cout << "";
                    return 0;
                }
                ]])],
   [nc_cxx_worked=yes],
   [nc_cxx_worked=no],
   [])
   AC_LANG_RESTORE()
   AC_MSG_RESULT([$nc_cxx_worked])

# If the CXX compiler doesn't work, exit if --disable-compiler-recover
# was used, otherwise, turn off the C++ API build.
   AC_MSG_CHECKING([whether CXX API can be built])
   if test "x$nc_cxx_worked" = xno ; then
      nc_build_cxx=no && CXX=''
   fi
   AC_MSG_RESULT([$nc_build_cxx])
   if test "x${nc_cxx_worked}" = xno ; then
      if test "x${nc_compiler_recover}" = xno ; then
         AC_MSG_WARN([exiting because of broken CXX compiler and 
--disable-compiler-recover])
         exit 1
      else
         AC_MSG_WARN([Can't get C++ compiler to work. C++ API won't be built.])
      fi
   fi
fi
AM_CONDITIONAL(BUILD_CXX, [test "x$nc_build_cxx" = xyes])


-- 
Ed Hartnett  -- address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]