Needed for tests of modules 'mbscasestr' and 'mbscasecmp'.
[gnulib.git] / m4 / locale-tr.m4
1 # locale-tr.m4 serial 1
2 dnl Copyright (C) 2003, 2005-2007 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 struct tm t;
22 char buf[16];
23 int main () {
24   /* On BeOS, locales are not implemented in libc.  Rather, libintl
25      imitates locale dependent behaviour by looking at the environment
26      variables, and all locales use the UTF-8 encoding.  */
27 #if !defined(__BEOS__)
28   /* Check whether the given locale name is recognized by the system.  */
29   if (setlocale (LC_ALL, "") == NULL) return 1;
30   /* Check whether nl_langinfo(CODESET) is nonempty.
31      On MacOS X 10.3.5 (Darwin 7.5) in the tr_TR locale, nl_langinfo(CODESET)
32      is empty, and the behaviour of Tcl 8.4 in this locale is not useful.  */
33 # if HAVE_LANGINFO_CODESET
34   if (nl_langinfo (CODESET) [0] == '\0') return 1;
35 # endif
36   /* Check whether in the abbreviation of the eighth month, the second
37      character (should be U+011F: LATIN SMALL LETTER G WITH BREVE) is
38      two bytes long, with UTF-8 encoding.  */
39   t.tm_year = 1992 - 1900; t.tm_mon = 8 - 1; t.tm_mday = 19;
40   if (strftime (buf, sizeof (buf), "%b", &t) < 4
41       || buf[1] != (char) 0xc4 || buf[2] != (char) 0x9f)
42     return 1;
43   /* Check whether the upper-/lowercase mappings are as expected for
44      Turkish.  */
45   if (towupper ('i') != 0x0130 || towlower (0x0130) != 'i'
46       || towupper(0x0131) != 'I' || towlower ('I') != 0x0131)
47     return 1;
48 #endif
49   return 0;
50 }
51 changequote([,])dnl
52       ])])
53     if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
54       # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
55       # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
56       # configure script would override the LC_ALL setting. Likewise for
57       # LC_CTYPE, which is also set at the beginning of the configure script.
58       # Test for the usual locale name.
59       if (LC_ALL=tr_TR LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
60         gt_cv_locale_tr_utf8=tr_TR
61       else
62         # Test for the locale name with explicit encoding suffix.
63         if (LC_ALL=tr_TR.UTF-8 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
64           gt_cv_locale_tr_utf8=tr_TR.UTF-8
65         else
66           # Test for the Solaris 7 locale name.
67           if (LC_ALL=tr.UTF-8 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
68             gt_cv_locale_tr_utf8=tr.UTF-8
69           else
70             # None found.
71             gt_cv_locale_tr_utf8=none
72           fi
73         fi
74       fi
75     fi
76     rm -fr conftest*
77   ])
78   LOCALE_TR_UTF8=$gt_cv_locale_tr_utf8
79   AC_SUBST([LOCALE_TR_UTF8])
80 ])