Require AC_CANONICAL_HOST in GLIB_WITH_NLS. (#385132, Laszlo Peter)
[platform/upstream/glib.git] / m4macros / glib-gettext.m4
1 # Copyright (C) 1995-2002 Free Software Foundation, Inc.
2 # Copyright (C) 2001-2003,2004 Red Hat, Inc.
3 #
4 # This file is free software, distributed under the terms of the GNU
5 # General Public License.  As a special exception to the GNU General
6 # Public License, this file may be distributed as part of a program
7 # that contains a configuration script generated by Autoconf, under
8 # the same distribution terms as the rest of that program.
9 #
10 # This file can be copied and used freely without restrictions.  It can
11 # be used in projects which are not available under the GNU Public License
12 # but which still want to provide support for the GNU gettext functionality.
13 #
14 # Macro to add for using GNU gettext.
15 # Ulrich Drepper <drepper@cygnus.com>, 1995, 1996
16 #
17 # Modified to never use included libintl. 
18 # Owen Taylor <otaylor@redhat.com>, 12/15/1998
19 #
20 # Major rework to remove unused code
21 # Owen Taylor <otaylor@redhat.com>, 12/11/2002
22 #
23 # Added better handling of ALL_LINGUAS from GNU gettext version 
24 # written by Bruno Haible, Owen Taylor <otaylor.redhat.com> 5/30/3002
25 #
26 # Modified to require ngettext
27 # Matthias Clasen <mclasen@redhat.com> 08/06/2004
28 #
29 # We need this here as well, since someone might use autoconf-2.5x
30 # to configure GLib then an older version to configure a package
31 # using AM_GLIB_GNU_GETTEXT
32 AC_PREREQ(2.53)
33
34 dnl
35 dnl We go to great lengths to make sure that aclocal won't 
36 dnl try to pull in the installed version of these macros
37 dnl when running aclocal in the glib directory.
38 dnl
39 m4_copy([AC_DEFUN],[glib_DEFUN])
40 m4_copy([AC_REQUIRE],[glib_REQUIRE])
41 dnl
42 dnl At the end, if we're not within glib, we'll define the public
43 dnl definitions in terms of our private definitions.
44 dnl
45
46 # GLIB_LC_MESSAGES
47 #--------------------
48 glib_DEFUN([GLIB_LC_MESSAGES],
49   [AC_CHECK_HEADERS([locale.h])
50     if test $ac_cv_header_locale_h = yes; then
51     AC_CACHE_CHECK([for LC_MESSAGES], am_cv_val_LC_MESSAGES,
52       [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES],
53        am_cv_val_LC_MESSAGES=yes, am_cv_val_LC_MESSAGES=no)])
54     if test $am_cv_val_LC_MESSAGES = yes; then
55       AC_DEFINE(HAVE_LC_MESSAGES, 1,
56         [Define if your <locale.h> file defines LC_MESSAGES.])
57     fi
58   fi])
59
60 # GLIB_PATH_PROG_WITH_TEST
61 #----------------------------
62 dnl GLIB_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
63 dnl   TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
64 glib_DEFUN([GLIB_PATH_PROG_WITH_TEST],
65 [# Extract the first word of "$2", so it can be a program name with args.
66 set dummy $2; ac_word=[$]2
67 AC_MSG_CHECKING([for $ac_word])
68 AC_CACHE_VAL(ac_cv_path_$1,
69 [case "[$]$1" in
70   /*)
71   ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
72   ;;
73   *)
74   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
75   for ac_dir in ifelse([$5], , $PATH, [$5]); do
76     test -z "$ac_dir" && ac_dir=.
77     if test -f $ac_dir/$ac_word; then
78       if [$3]; then
79         ac_cv_path_$1="$ac_dir/$ac_word"
80         break
81       fi
82     fi
83   done
84   IFS="$ac_save_ifs"
85 dnl If no 4th arg is given, leave the cache variable unset,
86 dnl so AC_PATH_PROGS will keep looking.
87 ifelse([$4], , , [  test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
88 ])dnl
89   ;;
90 esac])dnl
91 $1="$ac_cv_path_$1"
92 if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then
93   AC_MSG_RESULT([$]$1)
94 else
95   AC_MSG_RESULT(no)
96 fi
97 AC_SUBST($1)dnl
98 ])
99
100 # GLIB_WITH_NLS
101 #-----------------
102 glib_DEFUN([GLIB_WITH_NLS],
103   dnl NLS is obligatory
104   [AC_REQUIRE([AC_CANONICAL_HOST])dnl
105     USE_NLS=yes
106     AC_SUBST(USE_NLS)
107
108     gt_cv_have_gettext=no
109
110     CATOBJEXT=NONE
111     XGETTEXT=:
112     INTLLIBS=
113
114     AC_CHECK_HEADER(libintl.h,
115      [gt_cv_func_dgettext_libintl="no"
116       libintl_extra_libs=""
117
118       #
119       # First check in libc
120       #
121       AC_CACHE_CHECK([for ngettext in libc], gt_cv_func_ngettext_libc,
122         [AC_TRY_LINK([
123 #include <libintl.h>
124 ],
125          [return !ngettext ("","", 1)],
126           gt_cv_func_ngettext_libc=yes,
127           gt_cv_func_ngettext_libc=no)
128         ])
129   
130       if test "$gt_cv_func_ngettext_libc" = "yes" ; then
131               AC_CACHE_CHECK([for dgettext in libc], gt_cv_func_dgettext_libc,
132                 [AC_TRY_LINK([
133 #include <libintl.h>
134 ],
135                   [return !dgettext ("","")],
136                   gt_cv_func_dgettext_libc=yes,
137                   gt_cv_func_dgettext_libc=no)
138                 ])
139       fi
140   
141       if test "$gt_cv_func_ngettext_libc" = "yes" ; then
142         AC_CHECK_FUNCS(bind_textdomain_codeset)
143       fi
144
145       #
146       # If we don't have everything we want, check in libintl
147       #
148       if test "$gt_cv_func_dgettext_libc" != "yes" \
149          || test "$gt_cv_func_ngettext_libc" != "yes" \
150          || test "$ac_cv_func_bind_textdomain_codeset" != "yes" ; then
151         
152         AC_CHECK_LIB(intl, bindtextdomain,
153             [AC_CHECK_LIB(intl, ngettext,
154                     [AC_CHECK_LIB(intl, dgettext,
155                                   gt_cv_func_dgettext_libintl=yes)])])
156
157         if test "$gt_cv_func_dgettext_libintl" != "yes" ; then
158           AC_MSG_CHECKING([if -liconv is needed to use gettext])
159           AC_MSG_RESULT([])
160           AC_CHECK_LIB(intl, ngettext,
161                 [AC_CHECK_LIB(intl, dcgettext,
162                        [gt_cv_func_dgettext_libintl=yes
163                         libintl_extra_libs=-liconv],
164                         :,-liconv)],
165                 :,-liconv)
166         fi
167
168         #
169         # If we found libintl, then check in it for bind_textdomain_codeset();
170         # we'll prefer libc if neither have bind_textdomain_codeset(),
171         # and both have dgettext and ngettext
172         #
173         if test "$gt_cv_func_dgettext_libintl" = "yes" ; then
174           glib_save_LIBS="$LIBS"
175           LIBS="$LIBS -lintl $libintl_extra_libs"
176           unset ac_cv_func_bind_textdomain_codeset
177           AC_CHECK_FUNCS(bind_textdomain_codeset)
178           LIBS="$glib_save_LIBS"
179
180           if test "$ac_cv_func_bind_textdomain_codeset" = "yes" ; then
181             gt_cv_func_dgettext_libc=no
182           else
183             if test "$gt_cv_func_dgettext_libc" = "yes" \
184                 && test "$gt_cv_func_ngettext_libc" = "yes"; then
185               gt_cv_func_dgettext_libintl=no
186             fi
187           fi
188         fi
189       fi
190
191       if test "$gt_cv_func_dgettext_libc" = "yes" \
192         || test "$gt_cv_func_dgettext_libintl" = "yes"; then
193         gt_cv_have_gettext=yes
194       fi
195   
196       if test "$gt_cv_func_dgettext_libintl" = "yes"; then
197         INTLLIBS="-lintl $libintl_extra_libs"
198       fi
199   
200       if test "$gt_cv_have_gettext" = "yes"; then
201         AC_DEFINE(HAVE_GETTEXT,1,
202           [Define if the GNU gettext() function is already present or preinstalled.])
203         GLIB_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
204           [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
205         if test "$MSGFMT" != "no"; then
206           glib_save_LIBS="$LIBS"
207           LIBS="$LIBS $INTLLIBS"
208           AC_CHECK_FUNCS(dcgettext)
209           AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
210           GLIB_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
211             [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
212           AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
213                          return _nl_msg_cat_cntr],
214             [CATOBJEXT=.gmo 
215              DATADIRNAME=share],
216             [case $host in
217             *-*-solaris*)
218             dnl On Solaris, if bind_textdomain_codeset is in libc,
219             dnl GNU format message catalog is always supported,
220             dnl since both are added to the libc all together.
221             dnl Hence, we'd like to go with DATADIRNAME=share and
222             dnl and CATOBJEXT=.gmo in this case.
223             AC_CHECK_FUNC(bind_textdomain_codeset,
224               [CATOBJEXT=.gmo 
225                DATADIRNAME=share],
226               [CATOBJEXT=.mo
227                DATADIRNAME=lib])
228             ;;
229             *)
230             CATOBJEXT=.mo
231             DATADIRNAME=lib
232             ;;
233             esac])
234           LIBS="$glib_save_LIBS"
235           INSTOBJEXT=.mo
236         else
237           gt_cv_have_gettext=no
238         fi
239       fi
240     ])
241
242     if test "$gt_cv_have_gettext" = "yes" ; then
243       AC_DEFINE(ENABLE_NLS, 1,
244         [always defined to indicate that i18n is enabled])
245     fi
246
247     dnl Test whether we really found GNU xgettext.
248     if test "$XGETTEXT" != ":"; then
249       dnl If it is not GNU xgettext we define it as : so that the
250       dnl Makefiles still can work.
251       if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
252         : ;
253       else
254         AC_MSG_RESULT(
255           [found xgettext program is not GNU xgettext; ignore it])
256         XGETTEXT=":"
257       fi
258     fi
259
260     # We need to process the po/ directory.
261     POSUB=po
262
263     AC_OUTPUT_COMMANDS(
264       [case "$CONFIG_FILES" in *po/Makefile.in*)
265         sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
266       esac])
267
268     dnl These rules are solely for the distribution goal.  While doing this
269     dnl we only have to keep exactly one list of the available catalogs
270     dnl in configure.in.
271     for lang in $ALL_LINGUAS; do
272       GMOFILES="$GMOFILES $lang.gmo"
273       POFILES="$POFILES $lang.po"
274     done
275
276     dnl Make all variables we use known to autoconf.
277     AC_SUBST(CATALOGS)
278     AC_SUBST(CATOBJEXT)
279     AC_SUBST(DATADIRNAME)
280     AC_SUBST(GMOFILES)
281     AC_SUBST(INSTOBJEXT)
282     AC_SUBST(INTLLIBS)
283     AC_SUBST(PO_IN_DATADIR_TRUE)
284     AC_SUBST(PO_IN_DATADIR_FALSE)
285     AC_SUBST(POFILES)
286     AC_SUBST(POSUB)
287   ])
288
289 # AM_GLIB_GNU_GETTEXT
290 # -------------------
291 # Do checks necessary for use of gettext. If a suitable implementation 
292 # of gettext is found in either in libintl or in the C library,
293 # it will set INTLLIBS to the libraries needed for use of gettext
294 # and AC_DEFINE() HAVE_GETTEXT and ENABLE_NLS. (The shell variable
295 # gt_cv_have_gettext will be set to "yes".) It will also call AC_SUBST()
296 # on various variables needed by the Makefile.in.in installed by 
297 # glib-gettextize.
298 dnl
299 glib_DEFUN([GLIB_GNU_GETTEXT],
300   [AC_REQUIRE([AC_PROG_CC])dnl
301    AC_REQUIRE([AC_HEADER_STDC])dnl
302    
303    GLIB_LC_MESSAGES
304    GLIB_WITH_NLS
305
306    if test "$gt_cv_have_gettext" = "yes"; then
307      if test "x$ALL_LINGUAS" = "x"; then
308        LINGUAS=
309      else
310        AC_MSG_CHECKING(for catalogs to be installed)
311        NEW_LINGUAS=
312        for presentlang in $ALL_LINGUAS; do
313          useit=no
314          if test "%UNSET%" != "${LINGUAS-%UNSET%}"; then
315            desiredlanguages="$LINGUAS"
316          else
317            desiredlanguages="$ALL_LINGUAS"
318          fi
319          for desiredlang in $desiredlanguages; do
320            # Use the presentlang catalog if desiredlang is
321            #   a. equal to presentlang, or
322            #   b. a variant of presentlang (because in this case,
323            #      presentlang can be used as a fallback for messages
324            #      which are not translated in the desiredlang catalog).
325            case "$desiredlang" in
326              "$presentlang"*) useit=yes;;
327            esac
328          done
329          if test $useit = yes; then
330            NEW_LINGUAS="$NEW_LINGUAS $presentlang"
331          fi
332        done
333        LINGUAS=$NEW_LINGUAS
334        AC_MSG_RESULT($LINGUAS)
335      fi
336
337      dnl Construct list of names of catalog files to be constructed.
338      if test -n "$LINGUAS"; then
339        for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
340      fi
341    fi
342
343    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
344    dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
345    dnl Try to locate is.
346    MKINSTALLDIRS=
347    if test -n "$ac_aux_dir"; then
348      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
349    fi
350    if test -z "$MKINSTALLDIRS"; then
351      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
352    fi
353    AC_SUBST(MKINSTALLDIRS)
354
355    dnl Generate list of files to be processed by xgettext which will
356    dnl be included in po/Makefile.
357    test -d po || mkdir po
358    if test "x$srcdir" != "x."; then
359      if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
360        posrcprefix="$srcdir/"
361      else
362        posrcprefix="../$srcdir/"
363      fi
364    else
365      posrcprefix="../"
366    fi
367    rm -f po/POTFILES
368    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
369         < $srcdir/po/POTFILES.in > po/POTFILES
370   ])
371
372 # AM_GLIB_DEFINE_LOCALEDIR(VARIABLE)
373 # -------------------------------
374 # Define VARIABLE to the location where catalog files will
375 # be installed by po/Makefile.
376 glib_DEFUN([GLIB_DEFINE_LOCALEDIR],
377 [glib_REQUIRE([GLIB_GNU_GETTEXT])dnl
378 glib_save_prefix="$prefix"
379 glib_save_exec_prefix="$exec_prefix"
380 glib_save_datarootdir="$datarootdir"
381 test "x$prefix" = xNONE && prefix=$ac_default_prefix
382 test "x$exec_prefix" = xNONE && exec_prefix=$prefix
383 datarootdir=`eval echo "${datarootdir}"`
384 if test "x$CATOBJEXT" = "x.mo" ; then
385   localedir=`eval echo "${libdir}/locale"`
386 else
387   localedir=`eval echo "${datadir}/locale"`
388 fi
389 prefix="$glib_save_prefix"
390 exec_prefix="$glib_save_exec_prefix"
391 datarootdir="$glib_save_datarootdir"
392 AC_DEFINE_UNQUOTED($1, "$localedir",
393   [Define the location where the catalogs will be installed])
394 ])
395
396 dnl
397 dnl Now the definitions that aclocal will find
398 dnl
399 ifdef(glib_configure_in,[],[
400 AC_DEFUN([AM_GLIB_GNU_GETTEXT],[GLIB_GNU_GETTEXT($@)])
401 AC_DEFUN([AM_GLIB_DEFINE_LOCALEDIR],[GLIB_DEFINE_LOCALEDIR($@)])
402 ])dnl