locale: Make locale_t available when possible.
authorBruno Haible <bruno@clisp.org>
Sun, 22 Nov 2009 22:31:11 +0000 (23:31 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 23 Nov 2009 00:05:11 +0000 (01:05 +0100)
ChangeLog
doc/posix-headers/locale.texi
lib/locale.in.h
m4/locale_h.m4
modules/locale

index 637578a559a50374676a7b3bab9191e963b09e4a..3e7980f5c3c042a7d23c5094337e83d0c136013b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-11-22  Bruno Haible  <bruno@clisp.org>
+
+       locale: Make locale_t available when possible.
+       * lib/locale.in.h: Include <xlocale.h> when it exists.
+       * m4/locale_h.m4 (gl_LOCALE_H): Check for <xlocale.h> and arrange to
+       replace <locale.h> if it does not define locale_t but <xlocale.h> does.
+       * modules/locale (Depends-on): Add extensions.
+       (Makefile.am): Also substitute HAVE_XLOCALE_H.
+       * doc/posix-headers/locale.texi: Document the problem with locale_t.
+
 2009-11-22  Bruno Haible  <bruno@clisp.org>
 
        Add comments.
index df0673b5a88a0104b645b92355e84af146b214f1..8f927770c073ee22db0b96ec3b0fdcb3d20a221c 100644 (file)
@@ -11,6 +11,10 @@ Portability problems fixed by Gnulib:
 The definition of @samp{LC_MESSAGES} is missing on some platforms:
 mingw.
 
+@item
+The @code{locale_t} type is not defined on some platforms:
+glibc 2.11, MacOS X 10.5.
+
 @item
 Some platforms provide a @code{NULL} macro that cannot be used in arbitrary
 expressions:
index 0557c9f1705ef64b8d37c841b32cfef33d74e4d4..49835c5cab64d0296f4636af6f254109c891ac80 100644 (file)
 /* NetBSD 5.0 mis-defines NULL.  */
 #include <stddef.h>
 
+/* MacOS X 10.5 defines the locale_t type in <xlocale.h>.  */
+#if @HAVE_XLOCALE_H@
+# include <xlocale.h>
+#endif
+
 /* The LC_MESSAGES locale category is specified in POSIX, but not in ISO C.
    On systems that don't define it, use the same value as GNU libintl.  */
 #if !defined LC_MESSAGES
index 86123670f95f8150f7ceb0661a2a5ee7de38626b..913a2009bc432b747f6c7c2860148b637480326d 100644 (file)
@@ -1,4 +1,4 @@
-# locale_h.m4 serial 3
+# locale_h.m4 serial 4
 dnl Copyright (C) 2007, 2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -6,17 +6,47 @@ dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_LOCALE_H],
 [
-  AC_CACHE_CHECK([whether locale.h conforms to POSIX],
-    [gl_cv_header_working_locale_h],
-    [AC_TRY_COMPILE([#include <locale.h>
-int x = LC_MESSAGES;], [],
-       [gl_cv_header_working_locale_h=yes],
-       [gl_cv_header_working_locale_h=no])])
+  dnl Persuade glibc <locale.h> to define locale_t.
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
 
   dnl If <stddef.h> is replaced, then <locale.h> must also be replaced.
   AC_REQUIRE([gl_STDDEF_H])
 
-  if test $gl_cv_header_working_locale_h = yes && test -z "$STDDEF_H"; then
+  AC_CACHE_CHECK([whether locale.h conforms to POSIX:2001],
+    [gl_cv_header_locale_h_posix2001],
+    [AC_TRY_COMPILE([#include <locale.h>
+int x = LC_MESSAGES;], [],
+       [gl_cv_header_locale_h_posix2001=yes],
+       [gl_cv_header_locale_h_posix2001=no])])
+
+  dnl Check for <xlocale.h>.
+  AC_CHECK_HEADERS_ONCE([xlocale.h])
+  if test $ac_cv_header_xlocale_h = yes; then
+    HAVE_XLOCALE_H=1
+    dnl Check whether use of locale_t requires inclusion of <xlocale.h>,
+    dnl e.g. on MacOS X 10.5. If <locale.h> does not define locale_t by
+    dnl itself, we assume that <xlocale.h> will do so.
+    AC_CACHE_CHECK([whether locale.h defines locale_t],
+      [gl_cv_header_locale_has_locale_t],
+      [AC_TRY_COMPILE([#include <locale.h>
+locale_t x;], [],
+         [gl_cv_header_locale_has_locale_t=yes],
+         [gl_cv_header_locale_has_locale_t=no])
+      ])
+    if test $gl_cv_header_locale_has_locale_t = yes; then
+      gl_cv_header_locale_h_needs_xlocale_h=no
+    else
+      gl_cv_header_locale_h_needs_xlocale_h=yes
+    fi
+  else
+    HAVE_XLOCALE_H=0
+    gl_cv_header_locale_h_needs_xlocale_h=no
+  fi
+  AC_SUBST([HAVE_XLOCALE_H])
+
+  if test -z "$STDDEF_H" \
+     && test $gl_cv_header_locale_h_posix2001 = yes \
+     && test $gl_cv_header_locale_h_needs_xlocale_h = no; then
     LOCALE_H=
   else
     gl_CHECK_NEXT_HEADERS([locale.h])
index 41f9e536e87104c6fbe0c05e9fd94994fa681ed1..953237dea7a9e8187473b6f817402cb17a342846 100644 (file)
@@ -7,6 +7,7 @@ m4/locale_h.m4
 
 Depends-on:
 include_next
+extensions
 stddef
 
 configure.ac:
@@ -23,6 +24,7 @@ locale.h: locale.in.h
          sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''NEXT_LOCALE_H''@|$(NEXT_LOCALE_H)|g' \
+             -e 's|@''HAVE_XLOCALE_H''@|$(HAVE_XLOCALE_H)|g' \
              < $(srcdir)/locale.in.h; \
        } > $@-t && \
        mv $@-t $@