Move iconv tests before gettext checks. (#81999)
[platform/upstream/glib.git] / acinclude.m4
1 # Macro to add for using GNU gettext.
2 # Ulrich Drepper <drepper@cygnus.com>, 1995, 1996
3 #
4 # Modified to never use included libintl. 
5 # Owen Taylor <otaylor@redhat.com>, 12/15/1998
6 #
7 #
8 # This file can be copied and used freely without restrictions.  It can
9 # be used in projects which are not available under the GNU Public License
10 # but which still want to provide support for the GNU gettext functionality.
11 # Please note that the actual code is *not* freely available.
12 #
13 #
14 # If you make changes to this file, you MUST update the copy in
15 # acinclude.m4. [ aclocal dies on duplicate macros, so if
16 # we run 'aclocal -I macros/' then we'll run into problems
17 # once we've installed glib-gettext.m4 :-( ]
18 #
19
20 AC_DEFUN([AM_GLIB_LC_MESSAGES],
21   [if test $ac_cv_header_locale_h = yes; then
22     AC_CACHE_CHECK([for LC_MESSAGES], am_cv_val_LC_MESSAGES,
23       [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES],
24        am_cv_val_LC_MESSAGES=yes, am_cv_val_LC_MESSAGES=no)])
25     if test $am_cv_val_LC_MESSAGES = yes; then
26       AC_DEFINE(HAVE_LC_MESSAGES, 1,
27         [Define if your <locale.h> file defines LC_MESSAGES.])
28     fi
29   fi])
30
31 dnl AM_GLIB_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
32 dnl   TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
33 AC_DEFUN([AM_GLIB_PATH_PROG_WITH_TEST],
34 [# Extract the first word of "$2", so it can be a program name with args.
35 set dummy $2; ac_word=[$]2
36 AC_MSG_CHECKING([for $ac_word])
37 AC_CACHE_VAL(ac_cv_path_$1,
38 [case "[$]$1" in
39   /*)
40   ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
41   ;;
42   *)
43   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
44   for ac_dir in ifelse([$5], , $PATH, [$5]); do
45     test -z "$ac_dir" && ac_dir=.
46     if test -f $ac_dir/$ac_word; then
47       if [$3]; then
48         ac_cv_path_$1="$ac_dir/$ac_word"
49         break
50       fi
51     fi
52   done
53   IFS="$ac_save_ifs"
54 dnl If no 4th arg is given, leave the cache variable unset,
55 dnl so AC_PATH_PROGS will keep looking.
56 ifelse([$4], , , [  test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
57 ])dnl
58   ;;
59 esac])dnl
60 $1="$ac_cv_path_$1"
61 if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then
62   AC_MSG_RESULT([$]$1)
63 else
64   AC_MSG_RESULT(no)
65 fi
66 AC_SUBST($1)dnl
67 ])
68
69 # serial 5
70
71 AC_DEFUN(AM_GLIB_WITH_NLS,
72   dnl NLS is obligatory
73   [USE_NLS=yes
74     AC_SUBST(USE_NLS)
75
76     dnl Figure out what method
77     nls_cv_force_use_gnu_gettext="no"
78
79     nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
80     if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
81       dnl User does not insist on using GNU NLS library.  Figure out what
82       dnl to use.  If gettext or catgets are available (in this order) we
83       dnl use this.  Else we have to fall back to GNU NLS library.
84       dnl catgets is only used if permitted by option --with-catgets.
85       nls_cv_header_intl=
86       nls_cv_header_libgt=
87       CATOBJEXT=NONE
88       XGETTEXT=:
89
90       AC_CHECK_HEADER(libintl.h,
91         [AC_CACHE_CHECK([for dgettext in libc], gt_cv_func_dgettext_libc,
92           [AC_TRY_LINK([#include <libintl.h>], [return (int) dgettext ("","")],
93             gt_cv_func_dgettext_libc=yes, gt_cv_func_dgettext_libc=no)])
94
95           gt_cv_func_dgettext_libintl="no"
96           libintl_extra_libs=""
97
98           if test "$gt_cv_func_dgettext_libc" != "yes" ; then
99             AC_CHECK_LIB(intl, bindtextdomain,
100               [AC_CHECK_LIB(intl, dgettext,
101                             gt_cv_func_dgettext_libintl=yes)])
102
103             if test "$gt_cv_func_dgettext_libc" != "yes" ; then
104               AC_MSG_NOTICE([Seeing if -liconv is needed to use gettext])
105               AC_CHECK_LIB(intl, dcgettext,
106                            [gt_cv_func_dgettext_libintl=yes
107                             libintl_extra_libs=-liconv],
108                            :,-liconv)
109             fi
110           fi
111
112           if test "$gt_cv_func_dgettext_libintl" = "yes"; then
113             LIBS="$LIBS -lintl $libintl_extra_libs";
114           fi
115
116           if test "$gt_cv_func_dgettext_libc" = "yes" \
117             || test "$gt_cv_func_dgettext_libintl" = "yes"; then
118             AC_DEFINE(HAVE_GETTEXT,1,
119               [Define if the GNU gettext() function is already present or preinstalled.])
120             AM_GLIB_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
121               [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
122             if test "$MSGFMT" != "no"; then
123               AC_CHECK_FUNCS(dcgettext)
124               AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
125               AM_GLIB_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
126                 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
127               AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
128                              return _nl_msg_cat_cntr],
129                 [CATOBJEXT=.gmo
130                  DATADIRNAME=share],
131                 [CATOBJEXT=.mo
132                  DATADIRNAME=lib])
133               INSTOBJEXT=.mo
134             fi
135           fi
136
137           # Added by Martin Baulig 12/15/98 for libc5 systems
138           if test "$gt_cv_func_dgettext_libc" != "yes" \
139             && test "$gt_cv_func_dgettext_libintl" = "yes"; then
140             INTLLIBS="-lintl $libintl_extra_libs"
141             LIBS=`echo $LIBS | sed -e 's/-lintl//'`
142           fi
143       ])
144
145       if test "$CATOBJEXT" = "NONE"; then
146         dnl Neither gettext nor catgets in included in the C library.
147         dnl Fall back on GNU gettext library.
148         nls_cv_use_gnu_gettext=yes
149       fi
150     fi
151
152     if test "$nls_cv_use_gnu_gettext" != "yes"; then
153       AC_DEFINE(ENABLE_NLS, 1,
154         [always defined to indicate that i18n is enabled])
155     else
156       dnl Unset this variable since we use the non-zero value as a flag.
157       CATOBJEXT=
158     fi
159
160     dnl Test whether we really found GNU xgettext.
161     if test "$XGETTEXT" != ":"; then
162       dnl If it is no GNU xgettext we define it as : so that the
163       dnl Makefiles still can work.
164       if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
165         : ;
166       else
167         AC_MSG_RESULT(
168           [found xgettext program is not GNU xgettext; ignore it])
169         XGETTEXT=":"
170       fi
171     fi
172
173     # We need to process the po/ directory.
174     POSUB=po
175
176     AC_OUTPUT_COMMANDS(
177       [case "$CONFIG_FILES" in *po/Makefile.in*)
178         sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
179       esac])
180
181     dnl These rules are solely for the distribution goal.  While doing this
182     dnl we only have to keep exactly one list of the available catalogs
183     dnl in configure.in.
184     for lang in $ALL_LINGUAS; do
185       GMOFILES="$GMOFILES $lang.gmo"
186       POFILES="$POFILES $lang.po"
187     done
188
189     dnl Make all variables we use known to autoconf.
190     AC_SUBST(CATALOGS)
191     AC_SUBST(CATOBJEXT)
192     AC_SUBST(DATADIRNAME)
193     AC_SUBST(GMOFILES)
194     AC_SUBST(INSTOBJEXT)
195     AC_SUBST(INTLDEPS)
196     AC_SUBST(INTLLIBS)
197     AC_SUBST(INTLOBJS)
198     AC_SUBST(POFILES)
199     AC_SUBST(POSUB)
200   ])
201
202 AC_DEFUN(AM_GLIB_GNU_GETTEXT,
203   [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
204    AC_REQUIRE([AC_PROG_CC])dnl
205    AC_REQUIRE([AC_PROG_RANLIB])dnl
206    AC_REQUIRE([AC_HEADER_STDC])dnl
207    AC_REQUIRE([AC_C_CONST])dnl
208    AC_REQUIRE([AC_C_INLINE])dnl
209    AC_REQUIRE([AC_TYPE_OFF_T])dnl
210    AC_REQUIRE([AC_TYPE_SIZE_T])dnl
211    AC_REQUIRE([AC_FUNC_ALLOCA])dnl
212    AC_REQUIRE([AC_FUNC_MMAP])dnl
213
214    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
215 unistd.h sys/param.h])
216    AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
217 strdup __argz_count __argz_stringify __argz_next])
218
219    AM_GLIB_LC_MESSAGES
220    AM_GLIB_WITH_NLS
221
222    if test "x$CATOBJEXT" != "x"; then
223      if test "x$ALL_LINGUAS" = "x"; then
224        LINGUAS=
225      else
226        AC_MSG_CHECKING(for catalogs to be installed)
227        NEW_LINGUAS=
228        for lang in ${LINGUAS=$ALL_LINGUAS}; do
229          case "$ALL_LINGUAS" in
230           *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
231          esac
232        done
233        LINGUAS=$NEW_LINGUAS
234        AC_MSG_RESULT($LINGUAS)
235      fi
236
237      dnl Construct list of names of catalog files to be constructed.
238      if test -n "$LINGUAS"; then
239        for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
240      fi
241    fi
242
243    dnl Determine which catalog format we have (if any is needed)
244    dnl For now we know about two different formats:
245    dnl   Linux libc-5 and the normal X/Open format
246    test -d po || mkdir po
247    if test "$CATOBJEXT" = ".cat"; then
248      AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
249
250      dnl Transform the SED scripts while copying because some dumb SEDs
251      dnl cannot handle comments.
252      sed -e '/^#/d' $srcdir/po/$msgformat-msg.sed > po/po2msg.sed
253    fi
254
255    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
256    dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
257    dnl Try to locate is.
258    MKINSTALLDIRS=
259    if test -n "$ac_aux_dir"; then
260      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
261    fi
262    if test -z "$MKINSTALLDIRS"; then
263      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
264    fi
265    AC_SUBST(MKINSTALLDIRS)
266
267    dnl Generate list of files to be processed by xgettext which will
268    dnl be included in po/Makefile.
269    test -d po || mkdir po
270    if test "x$srcdir" != "x."; then
271      if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
272        posrcprefix="$srcdir/"
273      else
274        posrcprefix="../$srcdir/"
275      fi
276    else
277      posrcprefix="../"
278    fi
279    rm -f po/POTFILES
280    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
281         < $srcdir/po/POTFILES.in > po/POTFILES
282   ])
283
284
285 dnl @synopsis AC_FUNC_VSNPRINTF_C99
286 dnl
287 dnl Check whether there is a vsnprintf() function with C99 semantics installed.
288 dnl
289 AC_DEFUN([AC_FUNC_VSNPRINTF_C99],
290 [AC_CACHE_CHECK(for C99 vsnprintf,
291   ac_cv_func_vsnprintf_c99,
292 [AC_TRY_RUN(
293 [#include <stdio.h>
294 #include <stdarg.h>
295
296 int
297 doit(char * s, ...)
298 {
299   char buffer[32];
300   va_list args;
301   int r;
302
303   va_start(args, s);
304   r = vsnprintf(buffer, 5, s, args);
305   va_end(args);
306
307   if (r != 7)
308     exit(1);
309
310   exit(0);
311 }
312
313 int
314 main(void)
315 {
316   doit("1234567");
317   exit(1);
318 }], ac_cv_func_vsnprintf_c99=yes, ac_cv_func_vsnprintf_c99=no, ac_cv_func_vsnprintf_c99=no)])
319 dnl Note that the default is to be pessimistic in the case of cross compilation.
320 dnl If you know that the target has a C99 vsnprintf(), you can get around this
321 dnl by setting ac_func_vsnprintf_c99 to yes, as described in the Autoconf manual.
322 if test $ac_cv_func_vsnprintf_c99 = yes; then
323   AC_DEFINE(HAVE_C99_VSNPRINTF, 1,
324             [Define if you have a version of the vsnprintf function
325              with semantics as specified by the ISO C99 standard.])
326 fi
327 ])# AC_FUNC_VSNPRINTF_C99
328