File: cppflags.m4

package info (click to toggle)
nmh 1.8-4
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 7,860 kB
  • sloc: ansic: 50,445; sh: 22,697; makefile: 1,138; lex: 740; perl: 509; yacc: 265
file content (57 lines) | stat: -rw-r--r-- 2,747 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
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 AM_CPPFLAGS directly is like DEFS, but doesn't get stomped on by
dnl configure when using config.h.

AC_DEFUN([NMH_ADDL_CPPFLAGS],
    [AC_CACHE_CHECK([platform-specific additional CPPFLAGS],
                    [nmh_cv_addl_cppflags], [
    dnl Turn warnings into errors.
    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.
    dnl Try without any additional defines on the first iteration.
    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],
              [AC_COMPILE_IFELSE(
                  [AC_LANG_PROGRAM([#include <string.h>
                                    #include <wchar.h>],
                                   [return strdup("x") == 0
                                             ? -wcwidth(0) : wcwidth(0)])],
                  [AM_CPPFLAGS="${nmh_cv_addl_cppflags}"; break;])],
              [AC_COMPILE_IFELSE(
                  [AC_LANG_PROGRAM([#include <string.h>],
                                   [return strdup("x") == 0])],
                  [AM_CPPFLAGS="${nmh_cv_addl_cppflags}"; break;])])
    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:
    AS_UNSET(ac_c_werror_flag)

    AC_SUBST([AM_CPPFLAGS])
])