From: David Levine Date: Thu, 15 Sep 2016 22:58:14 +0000 (-0400) Subject: Added NMH_ADDL_CPPFLAGS macro in new m4/cppflags.m4, to remove X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/303e8387acecca26329e939f228f78ca805b7a15?ds=sidebyside;hp=efa36b8cb2aae4cf57dde5118888ae2d4f78e2cd Added NMH_ADDL_CPPFLAGS macro in new m4/cppflags.m4, to remove explicit OS dependencies when deciding whether -DGNU_SOURCE is needed. (Cygwin now needs it.) --- diff --git a/configure.ac b/configure.ac old mode 100644 new mode 100755 index f8e69119..921580de --- a/configure.ac +++ b/configure.ac @@ -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 .]),, +[[#if HAVE_SYS_STREAM_H +# include +#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 .]),, -[[#if HAVE_SYS_STREAM_H -# include -#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 index 00000000..8b5615a0 --- /dev/null +++ b/m4/cppflags.m4 @@ -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 + #include ], + [return wcwidth(0) + strdup("x") == 0])], + [break;])], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([#include ], + [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= +])