]> diplodocus.org Git - nmh/commitdiff
Added NMH_ADDL_CPPFLAGS macro in new m4/cppflags.m4, to remove
authorDavid Levine <levinedl@acm.org>
Thu, 15 Sep 2016 22:58:14 +0000 (18:58 -0400)
committerDavid Levine <levinedl@acm.org>
Thu, 15 Sep 2016 23:59:12 +0000 (19:59 -0400)
explicit OS dependencies when deciding whether -DGNU_SOURCE is
needed.  (Cygwin now needs it.)

configure.ac [changed mode: 0644->0755]
m4/cppflags.m4 [new file with mode: 0755]

old mode 100644 (file)
new mode 100755 (executable)
index f8e6911..921580d
@@ -92,10 +92,43 @@ dnl ------------------
 AC_PROG_CC([cc gcc])
 AM_PROG_CC_C_O
 
+dnl ------------------
+dnl CHECK HEADER FILES
+dnl ------------------
+
+AC_HEADER_TIOCGWINSZ
+AC_CHECK_HEADERS([fcntl.h wchar.h wctype.h sys/param.h sys/time.h sys/stream.h])
+
+AC_CHECK_HEADER([sys/ptem.h], AC_DEFINE(WINSIZE_IN_PTEM,1,
+  [Define to 1 if `struct winsize' requires <sys/ptem.h>.]),,
+[[#if HAVE_SYS_STREAM_H
+#  include <sys/stream.h>
+#endif
+]])
+
+dnl ---------------
+dnl CHECK FUNCTIONS
+dnl ---------------
+AC_CHECK_FUNCS([wcwidth mbtowc getutxent arc4random mkstemps])
+
+dnl -----------------------
+dnl CHECK MULTIBYTE SUPPORT
+dnl -----------------------
+AS_IF([test "x$ac_cv_header_wchar_h" = "xyes" -a \
+           "x$ac_cv_header_wctype_h" = "xyes" -a \
+           "x$ac_cv_func_wcwidth" = "xyes" -a \
+           "x$ac_cv_func_mbtowc" = "xyes"],
+      [AC_DEFINE([MULTIBYTE_SUPPORT], [1],
+                [Define to enable support for multibyte character sets.])
+       MULTIBYTE_ENABLED=1],
+      [MULTIBYTE_ENABLED=0])
+AC_SUBST([MULTIBYTE_ENABLED])
+
 dnl ----------------
 dnl CUSTOMIZE CFLAGS
 dnl ----------------
 dnl The user didn't specify CFLAGS, so customize them.
+
 if test "$GCC" != yes; then
   dnl Use -v and some other options with SunStudio cc.  lex produces
   dnl code that causes unreachable-statement warnings.  It might be
@@ -121,6 +154,10 @@ AC_CACHE_CHECK([whether compiler supports -Wextra], [nmh_cv_has_wextra],
                CFLAGS="$nmh_saved_cflags"])
 test "$nmh_cv_has_wextra" = "yes"  &&  CFLAGS="${CFLAGS:+$CFLAGS }-Wextra"
 
+dnl Check for any platform-specific additional CPPFLAGS.  This depends on
+dnl MULTIBYTE_ENABLED having already been set.
+NMH_ADDL_CPPFLAGS
+
 if test "$GCC" = yes; then
   dnl Do this regardless of auto_cflags value.
   dnl Enable _FORTIFY_SOURCE checking, which is supported by
@@ -233,7 +270,9 @@ pathtmp=/usr/sbin:/usr/lib:/usr/etc:/usr/ucblib:/usr/bin:/bin
 AC_PATH_PROG([sendmailpath], [sendmail], [/usr/sbin/sendmail], [$pathtmp])
 
 dnl Cygwin FAT filesystems do not support hard links.  So default to
-dnl cp instead, even if running on an NTFS or other filesystem.
+dnl cp instead, even if running on an NTFS or other filesystem.  (And
+dnl therefore, this cannot be made into a dynamic test, in order to
+dnl support the least common Cygwin denominator.
 AS_CASE(["$host_os"],
   [cygwin*], [LN=cp],
   [LN=ln])
@@ -307,51 +346,6 @@ AC_SUBST([MAIL_SPOOL_GRP])dnl
 NMH_MIMETYPEPROC
 NMH_MIMEENCODINGPROC
 
-dnl ------------------
-dnl CHECK HEADER FILES
-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 wcwidth()
-dnl declared; if so they should have an entry added to this case statement.
-dnl NB that we must define this on the compiler command line, not in config.h,
-dnl because it must be set before any system header is included and there's no
-dnl portable way to make sure that files generated by lex include config.h
-dnl before system header files.
-
-AS_CASE(["$host_os"],
-       [linux*],
-       [# Like DEFS, but doesn't get stomped on by configure when using config.h:
-       CPPFLAGS="${CPPFLAGS:+$CPPFLAGS }-D_GNU_SOURCE"])
-
-AC_HEADER_TIOCGWINSZ
-AC_CHECK_HEADERS([fcntl.h wchar.h wctype.h sys/param.h sys/time.h sys/stream.h])
-
-AC_CHECK_HEADER([sys/ptem.h], AC_DEFINE(WINSIZE_IN_PTEM,1,
-  [Define to 1 if `struct winsize' requires <sys/ptem.h>.]),,
-[[#if HAVE_SYS_STREAM_H
-#  include <sys/stream.h>
-#endif
-]])
-
-dnl ---------------
-dnl CHECK FUNCTIONS
-dnl ---------------
-AC_CHECK_FUNCS([wcwidth mbtowc getutxent arc4random mkstemps])
-
-dnl Check for multibyte character set support
-AS_IF([test "x$ac_cv_header_wchar_h" = "xyes" -a \
-           "x$ac_cv_header_wctype_h" = "xyes" -a \
-           "x$ac_cv_func_wcwidth" = "xyes" -a \
-           "x$ac_cv_func_mbtowc" = "xyes"],
-      [AC_DEFINE([MULTIBYTE_SUPPORT], [1],
-                [Define to enable support for multibyte character sets.])
-       MULTIBYTE_ENABLED=1],
-      [MULTIBYTE_ENABLED=0])
-AC_SUBST([MULTIBYTE_ENABLED])
-
 dnl -------------------
 dnl CHECK FOR LIBRARIES
 dnl -------------------
diff --git a/m4/cppflags.m4 b/m4/cppflags.m4
new file mode 100755 (executable)
index 0000000..8b5615a
--- /dev/null
@@ -0,0 +1,44 @@
+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=
+])