locale: Make locale_t available when possible.
[gnulib.git] / m4 / locale_h.m4
1 # locale_h.m4 serial 4
2 dnl Copyright (C) 2007, 2009 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.
6
7 AC_DEFUN([gl_LOCALE_H],
8 [
9   dnl Persuade glibc <locale.h> to define locale_t.
10   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
11
12   dnl If <stddef.h> is replaced, then <locale.h> must also be replaced.
13   AC_REQUIRE([gl_STDDEF_H])
14
15   AC_CACHE_CHECK([whether locale.h conforms to POSIX:2001],
16     [gl_cv_header_locale_h_posix2001],
17     [AC_TRY_COMPILE([#include <locale.h>
18 int x = LC_MESSAGES;], [],
19        [gl_cv_header_locale_h_posix2001=yes],
20        [gl_cv_header_locale_h_posix2001=no])])
21
22   dnl Check for <xlocale.h>.
23   AC_CHECK_HEADERS_ONCE([xlocale.h])
24   if test $ac_cv_header_xlocale_h = yes; then
25     HAVE_XLOCALE_H=1
26     dnl Check whether use of locale_t requires inclusion of <xlocale.h>,
27     dnl e.g. on MacOS X 10.5. If <locale.h> does not define locale_t by
28     dnl itself, we assume that <xlocale.h> will do so.
29     AC_CACHE_CHECK([whether locale.h defines locale_t],
30       [gl_cv_header_locale_has_locale_t],
31       [AC_TRY_COMPILE([#include <locale.h>
32 locale_t x;], [],
33          [gl_cv_header_locale_has_locale_t=yes],
34          [gl_cv_header_locale_has_locale_t=no])
35       ])
36     if test $gl_cv_header_locale_has_locale_t = yes; then
37       gl_cv_header_locale_h_needs_xlocale_h=no
38     else
39       gl_cv_header_locale_h_needs_xlocale_h=yes
40     fi
41   else
42     HAVE_XLOCALE_H=0
43     gl_cv_header_locale_h_needs_xlocale_h=no
44   fi
45   AC_SUBST([HAVE_XLOCALE_H])
46
47   if test -z "$STDDEF_H" \
48      && test $gl_cv_header_locale_h_posix2001 = yes \
49      && test $gl_cv_header_locale_h_needs_xlocale_h = no; then
50     LOCALE_H=
51   else
52     gl_CHECK_NEXT_HEADERS([locale.h])
53     LOCALE_H=locale.h
54   fi
55   AC_SUBST([LOCALE_H])
56 ])