[ldns-users] Issues with CHECK_COMPILER_FLAG_NEEDED macro

Alexander Gall gall at switch.ch
Fri Oct 26 13:05:42 UTC 2007


I've encountered two issues with the usage of the AC macro
CHECK_COMPILER_FLAG_NEEDED for ldns and drill.  For ldns, configure
first checks for *all* of the flags

-std=c99 -D__EXTENSIONS__ -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600

On my system (OpenSolaris build 61, gcc 3.4.3), this test is positive
(i.e. the test program doesn't compile without the flags).  As a
result, all these flags are added to CFLAGS.  However, this makes all
subsequent checks for the individual flags irrelevant, because the
macro always uses CFLAGS, which already contains all of the flags.

It seems to me that one ends up either with all of the flags or none
of them on any system.  Maybe the check for all flags together should
simply be dropped?

In fact, this is done for drill, but then there is a different
problem.  Apparently "-std=c99" is not needed and when testing for
"-D_POSIX_C_SOURCE=200112" by itself, the header files of my system
complain:

/usr/include/sys/feature_tests.h:357:2: #error "Compiler or options invalid; UNIX 03 and POSIX.1-2001 applications      require the use of c99"                                                                                  

I think this is because gcc 3.4 by default uses -std=c89 (or, more
precisely, gnu89, which is c89 with GNU extensions).  It seems like
you need to check -D_POSIX_C_SOURCE=200112 together with -std=c99. In
that case, maybe the check for -std=c99 by itself is not necessary as
well (it certainly isn't if you require POSIX.1-2001 anyway, I'd say).

It also turns out that ldns and drill use slightly different versions
of the CHECK_COMPILER_FLAG_NEEDED macro.  The one in drill does not
convert spaces to underscores in the construction of the "cache"
variable (which is necessary it you want to check for multiple flags).

The patch below solves the problem for me.

-- 
Alex

diff -Naur ldns-1.2.1.orig/drill/configure.ac ldns-1.2.1/drill/configure.ac
--- ldns-1.2.1.orig/drill/configure.ac  2007-09-05 14:57:12.000000000 +0200
+++ ldns-1.2.1/drill/configure.ac       2007-10-26 14:42:30.998096000 +0200
@@ -49,7 +49,7 @@
 [
 AC_REQUIRE([AC_PROG_CC])
 AC_MSG_CHECKING(whether we need -$1 as a flag for $CC)
-cache=`echo $1 | sed 'y%.=/+-%___p_%'`
+cache=`echo $1 | sed 'y%.=/+- %___p__%'`
 AC_CACHE_VAL(cv_prog_cc_flag_needed_$cache,
 [
 echo '$2' > conftest.c
@@ -84,7 +84,7 @@
 
 CHECK_COMPILER_FLAG(O2, [CFLAGS="$CFLAGS -O2"])
 CHECK_COMPILER_FLAG_NEEDED(-std=c99, [#include <stdbool.h>], [CFLAGS="$CFLAGS -std=c99"])
-CHECK_COMPILER_FLAG_NEEDED(-D_POSIX_C_SOURCE=200112, 
+CHECK_COMPILER_FLAG_NEEDED(-std=c99 -D_POSIX_C_SOURCE=200112, 
 [
 #include <time.h>
 
@@ -96,7 +96,7 @@
        t = ctime_r(&time, buf);
         return a;
 }
-], [CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112"])
+], [CFLAGS="$CFLAGS -std=c99 -D_POSIX_C_SOURCE=200112"])
 CHECK_COMPILER_FLAG_NEEDED(-D__EXTENSIONS__, 
 [
 #include <stdlib.h>









More information about the ldns-users mailing list