Prepare for locale dependent tests on mingw.
[gnulib.git] / m4 / locale-tr.m4
1 # locale-tr.m4 serial 7
2 dnl Copyright (C) 2003, 2005-2011 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 dnl From Bruno Haible.
8
9 dnl Determine the name of a turkish locale with UTF-8 encoding.
10 AC_DEFUN([gt_LOCALE_TR_UTF8],
11 [
12   AC_REQUIRE([AM_LANGINFO_CODESET])
13   AC_CACHE_CHECK([for a turkish Unicode locale], [gt_cv_locale_tr_utf8], [
14     AC_LANG_CONFTEST([AC_LANG_SOURCE([
15 changequote(,)dnl
16 #include <locale.h>
17 #include <time.h>
18 #if HAVE_LANGINFO_CODESET
19 # include <langinfo.h>
20 #endif
21 #include <stdlib.h>
22 #include <string.h>
23 struct tm t;
24 char buf[16];
25 int main () {
26   /* On BeOS, locales are not implemented in libc.  Rather, libintl
27      imitates locale dependent behaviour by looking at the environment
28      variables, and all locales use the UTF-8 encoding.  But BeOS does not
29      implement the Turkish upper-/lowercase mappings.  Therefore, let this
30      program return 1 on BeOS.  */
31   /* Check whether the given locale name is recognized by the system.  */
32 #if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
33   /* On native Win32, setlocale(category, "") looks at the system settings,
34      not at the environment variables.  Also, when an encoding suffix such
35      as ".65001" or ".54936" is speficied, it succeeds but sets the LC_CTYPE
36      category of the locale to "C".  */
37   if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
38       || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
39     return 1;
40 #else
41   if (setlocale (LC_ALL, "") == NULL) return 1;
42 #endif
43   /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
44      On MacOS X 10.3.5 (Darwin 7.5) in the tr_TR locale, nl_langinfo(CODESET)
45      is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
46      On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
47      succeeds but then nl_langinfo(CODESET) is "646". In this situation,
48      some unit tests fail.  */
49 #if HAVE_LANGINFO_CODESET
50   {
51     const char *cs = nl_langinfo (CODESET);
52     if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0)
53       return 1;
54   }
55 #endif
56 #ifdef __CYGWIN__
57   /* On Cygwin, avoid locale names without encoding suffix, because the
58      locale_charset() function relies on the encoding suffix.  Note that
59      LC_ALL is set on the command line.  */
60   if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
61 #endif
62   /* Check whether in the abbreviation of the eighth month, the second
63      character (should be U+011F: LATIN SMALL LETTER G WITH BREVE) is
64      two bytes long, with UTF-8 encoding.  */
65   t.tm_year = 1992 - 1900; t.tm_mon = 8 - 1; t.tm_mday = 19;
66   if (strftime (buf, sizeof (buf), "%b", &t) < 4
67       || buf[1] != (char) 0xc4 || buf[2] != (char) 0x9f)
68     return 1;
69   /* Check whether the upper-/lowercase mappings are as expected for
70      Turkish.  */
71   if (towupper ('i') != 0x0130 || towlower (0x0130) != 'i'
72       || towupper(0x0131) != 'I' || towlower ('I') != 0x0131)
73     return 1;
74   return 0;
75 }
76 changequote([,])dnl
77       ])])
78     if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
79       # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
80       # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
81       # configure script would override the LC_ALL setting. Likewise for
82       # LC_CTYPE, which is also set at the beginning of the configure script.
83       # Test for the usual locale name.
84       if (LC_ALL=tr_TR LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
85         gt_cv_locale_tr_utf8=tr_TR
86       else
87         # Test for the locale name with explicit encoding suffix.
88         if (LC_ALL=tr_TR.UTF-8 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
89           gt_cv_locale_tr_utf8=tr_TR.UTF-8
90         else
91           # Test for the Solaris 7 locale name.
92           if (LC_ALL=tr.UTF-8 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
93             gt_cv_locale_tr_utf8=tr.UTF-8
94           else
95             # None found.
96             gt_cv_locale_tr_utf8=none
97           fi
98         fi
99       fi
100     else
101       gt_cv_locale_tr_utf8=none
102     fi
103     rm -fr conftest*
104   ])
105   LOCALE_TR_UTF8=$gt_cv_locale_tr_utf8
106   AC_SUBST([LOCALE_TR_UTF8])
107 ])