Hi Ed, * Ed Hartnett wrote on Fri, May 20, 2005 at 04:51:41PM CEST: > > 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? In a way, yes. Autoconf cannot see the condition, and thus when a later test depends on an earlier test (but is not run because of some shell condition), things break. There is AS_IF, but it's rather a kludge than a solution. > 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 believe that should be ok. F77 tests are not going to depend on C++ tests, generally. > 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. > >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> I believe that should be AC_LANG_SOURCE([[#include <iostream> #include <whatever_else_is_necessary> At least portable C needs the hash in the first column, I'm unsure about C++. > int main() { > std::cout << ""; > return 0; > } > ]])], I believe there are useful C++ macros in the Autoconf macro archive[1] which you might want to check out. > [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]) I believe conditionalizing on this will in practice work quite well. Regards, Ralf [1] http://autoconf-archive.cryp.to/ _______________________________________________ Autoconf mailing list Autoconf@xxxxxxx http://lists.gnu.org/mailman/listinfo/autoconf