+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
+dnl that level then db.h won't compile. So we define _GNU_SOURCE which turns
+dnl on everything. Perhaps other OSes need some feature switch set to get
+dnl wcwidth() declared; if so they should have an entry added to this case
+dnl statement. NB that we must define this on the compiler command line, not
+dnl in config.h, because it must be set before any system header is included
+dnl and there's no portable way to make sure that files generated by lex
+dnl include config.h before system header files.
+dnl
+dnl Setting 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],
+ [nmh_cv_addl_cppflags], [
+ dnl Turn warnings into errors.
+ AC_LANG_WERROR
+ for nmh_cv_addl_cppflags in "" "-D_GNU_SOURCE"; do
+ nmh_saved_cppflags="$CPPFLAGS"
+ AS_IF([test x"${nmh_cv_addl_cppflags}" != x],
+ [CPPFLAGS="${CPPFLAGS:+$CPPFLAGS }$nmh_cv_addl_cppflags"])
+ AS_IF([test ${MULTIBYTE_ENABLED} = 1],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([#include <string.h>
+ #include <wchar.h>],
+ [return wcwidth(0) + strdup("x") == 0])],
+ [break;])],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([#include <string.h>],
+ [return strdup("x") == 0])],
+ [break;])])
+ CPPFLAGS="$nmh_saved_cppflags"
+ done])
+
+ dnl autoconf doesn't currently provide a macro to disable AC_LANG_WERROR,
+ dnl so do it this way:
+ ac_c_werror_flag=
+])