immutable: Add tests.
[gnulib.git] / m4 / langinfo_h.m4
blob950fe20af1294f43e128339a03a516efce8285e2
1 # langinfo_h.m4 serial 9
2 dnl Copyright (C) 2009-2021 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_LANGINFO_H],
9   AC_REQUIRE([gl_LANGINFO_H_DEFAULTS])
11   dnl Persuade glibc-2.0.6 <langinfo.h> to define CODESET.
12   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
14   dnl <langinfo.h> is always overridden, because of GNULIB_POSIXCHECK.
15   gl_CHECK_NEXT_HEADERS([langinfo.h])
17   dnl Determine whether <langinfo.h> exists. It is missing on mingw and BeOS.
18   HAVE_LANGINFO_CODESET=0
19   HAVE_LANGINFO_T_FMT_AMPM=0
20   HAVE_LANGINFO_ALTMON=0
21   HAVE_LANGINFO_ERA=0
22   HAVE_LANGINFO_YESEXPR=0
23   AC_CHECK_HEADERS_ONCE([langinfo.h])
24   if test $ac_cv_header_langinfo_h = yes; then
25     HAVE_LANGINFO_H=1
26     dnl Determine what <langinfo.h> defines.
27     dnl CODESET is missing on OpenBSD 3.8.
28     dnl ERA etc. are missing on OpenBSD 6.7.
29     dnl T_FMT_AMPM and YESEXPR, NOEXPR are missing on IRIX 5.3.
30     dnl ALTMON_* are missing on glibc 2.26 and many other systems.
31     AC_CACHE_CHECK([whether langinfo.h defines CODESET],
32       [gl_cv_header_langinfo_codeset],
33       [AC_COMPILE_IFELSE(
34          [AC_LANG_PROGRAM([[#include <langinfo.h>
35 int a = CODESET;
36 ]])],
37          [gl_cv_header_langinfo_codeset=yes],
38          [gl_cv_header_langinfo_codeset=no])
39       ])
40     if test $gl_cv_header_langinfo_codeset = yes; then
41       HAVE_LANGINFO_CODESET=1
42     fi
43     AC_CACHE_CHECK([whether langinfo.h defines T_FMT_AMPM],
44       [gl_cv_header_langinfo_t_fmt_ampm],
45       [AC_COMPILE_IFELSE(
46          [AC_LANG_PROGRAM([[#include <langinfo.h>
47 int a = T_FMT_AMPM;
48 ]])],
49          [gl_cv_header_langinfo_t_fmt_ampm=yes],
50          [gl_cv_header_langinfo_t_fmt_ampm=no])
51       ])
52     if test $gl_cv_header_langinfo_t_fmt_ampm = yes; then
53       HAVE_LANGINFO_T_FMT_AMPM=1
54     fi
55     AC_CACHE_CHECK([whether langinfo.h defines ALTMON_1],
56       [gl_cv_header_langinfo_altmon],
57       [AC_COMPILE_IFELSE(
58          [AC_LANG_PROGRAM([[#include <langinfo.h>
59 int a = ALTMON_1;
60 ]])],
61          [gl_cv_header_langinfo_altmon=yes],
62          [gl_cv_header_langinfo_altmon=no])
63       ])
64     if test $gl_cv_header_langinfo_altmon = yes; then
65       HAVE_LANGINFO_ALTMON=1
66     fi
67     AC_CACHE_CHECK([whether langinfo.h defines ERA],
68       [gl_cv_header_langinfo_era],
69       [AC_COMPILE_IFELSE(
70          [AC_LANG_PROGRAM([[#include <langinfo.h>
71 int a = ERA;
72 ]])],
73          [gl_cv_header_langinfo_era=yes],
74          [gl_cv_header_langinfo_era=no])
75       ])
76     if test $gl_cv_header_langinfo_era = yes; then
77       HAVE_LANGINFO_ERA=1
78     fi
79     AC_CACHE_CHECK([whether langinfo.h defines YESEXPR],
80       [gl_cv_header_langinfo_yesexpr],
81       [AC_COMPILE_IFELSE(
82          [AC_LANG_PROGRAM([[#include <langinfo.h>
83 int a = YESEXPR;
84 ]])],
85          [gl_cv_header_langinfo_yesexpr=yes],
86          [gl_cv_header_langinfo_yesexpr=no])
87       ])
88     if test $gl_cv_header_langinfo_yesexpr = yes; then
89       HAVE_LANGINFO_YESEXPR=1
90     fi
91   else
92     HAVE_LANGINFO_H=0
93   fi
94   AC_SUBST([HAVE_LANGINFO_H])
95   AC_SUBST([HAVE_LANGINFO_CODESET])
96   AC_SUBST([HAVE_LANGINFO_T_FMT_AMPM])
97   AC_SUBST([HAVE_LANGINFO_ALTMON])
98   AC_SUBST([HAVE_LANGINFO_ERA])
99   AC_SUBST([HAVE_LANGINFO_YESEXPR])
101   dnl Check for declarations of anything we want to poison if the
102   dnl corresponding gnulib module is not in use.
103   gl_WARN_ON_USE_PREPARE([[#include <langinfo.h>
104     ]], [nl_langinfo])
107 AC_DEFUN([gl_LANGINFO_MODULE_INDICATOR],
109   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
110   AC_REQUIRE([gl_LANGINFO_H_DEFAULTS])
111   gl_MODULE_INDICATOR_SET_VARIABLE([$1])
112   dnl Define it also as a C macro, for the benefit of the unit tests.
113   gl_MODULE_INDICATOR_FOR_TESTS([$1])
116 AC_DEFUN([gl_LANGINFO_H_DEFAULTS],
118   GNULIB_NL_LANGINFO=0;  AC_SUBST([GNULIB_NL_LANGINFO])
119   dnl Assume proper GNU behavior unless another module says otherwise.
120   HAVE_NL_LANGINFO=1;    AC_SUBST([HAVE_NL_LANGINFO])
121   REPLACE_NL_LANGINFO=0; AC_SUBST([REPLACE_NL_LANGINFO])