]> diplodocus.org Git - nmh/blobdiff - m4/cppflags.m4
vector.c: Move interface to own file.
[nmh] / m4 / cppflags.m4
old mode 100755 (executable)
new mode 100644 (file)
index 04b7dda..b860ea6
@@ -1,3 +1,6 @@
+dnl This is intended to be extensible, by just adding candidate C preprocessor
+dnl options to be checked in the for loop.  The first candidate is empty, in
+dnl case none are needed.  Also, the test program can be readily augmented.
 dnl
 dnl On glibc we need to define at least the '_XOPEN_SOURCE' level of features,
 dnl or wchar.h doesn't declare a prototype for wcwidth(). But if we only define
@@ -11,10 +14,6 @@ dnl include config.h before system header files.
 dnl
 dnl Setting AM_CPPFLAGS directly is like DEFS, but doesn't get stomped on by
 dnl configure when using config.h.
-dnl
-dnl This is intended to be extensible, by just adding candidate C preprocessor
-dnl options to be checked in the for loop.  The first candidate is empty, in
-dnl case none are needed.  Also, the test program can be readily augmented.
 
 AC_DEFUN([NMH_ADDL_CPPFLAGS],
     [AC_CACHE_CHECK([platform-specific additional CPPFLAGS],
@@ -23,8 +22,14 @@ AC_DEFUN([NMH_ADDL_CPPFLAGS],
     AC_LANG_WERROR
 
     nmh_saved_cppflags="$CPPFLAGS"
+    dnl autoconf doesn't look at AM_CFLAGS, so merge it into CFLAGS.
+    nmh_saved_cflags="$CFLAGS"
+    CFLAGS="$AM_CFLAGS $CFLAGS"
+    dnl On successful compilation, break out of loop with the AM_CPPFLAGS.
     for nmh_cv_addl_cppflags in "" "-D_GNU_SOURCE"; do
+        dnl Reload initial CPPFLAGS so candidates aren't accumulated.
         CPPFLAGS="$nmh_saved_cppflags"
+        dnl Only add non-empty nmh_cv_addl_cppflags to CPPFLAGS.
         AS_IF([test x"${nmh_cv_addl_cppflags}" != x],
               [CPPFLAGS="${CPPFLAGS:+$CPPFLAGS }$nmh_cv_addl_cppflags"])
         AS_IF([test ${MULTIBYTE_ENABLED} = 1],
@@ -37,12 +42,14 @@ AC_DEFUN([NMH_ADDL_CPPFLAGS],
                   [AC_LANG_PROGRAM([#include <string.h>],
                                    [return strdup("x") == 0])],
                   [AM_CPPFLAGS="${nmh_cv_addl_cppflags}"; break;])])
-    done])
+    done
+    CFLAGS="$nmh_saved_cflags"
     CPPFLAGS="$nmh_saved_cppflags"
+    ])
 
     dnl autoconf doesn't currently provide a macro to disable AC_LANG_WERROR,
     dnl so do it this way:
-    ac_c_werror_flag=
+    AS_UNSET(ac_c_werror_flag)
 
     AC_SUBST([AM_CPPFLAGS])
 ])