Unset ac_cv_func_bind_textdomain_codeset before calling
[platform/upstream/glib.git] / m4macros / glib-gettext.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 # Major rework to remove unused code
8 # Owen Taylor <otaylor@redhat.com>, 12/11/2002
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
15 dnl
16 dnl We go to great lengths to make sure that aclocal won't 
17 dnl try to pull in the installed version of these macros
18 dnl when running aclocal in the glib directory.
19 dnl
20 m4_copy([AC_DEFUN],[glib_DEFUN])
21 m4_copy([AC_REQUIRE],[glib_REQUIRE])
22 dnl
23 dnl At the end, if we're not within glib, we'll define the public
24 dnl definitions in terms of our private definitions.
25 dnl
26
27 # GLIB_LC_MESSAGES
28 #--------------------
29 glib_DEFUN([GLIB_LC_MESSAGES],
30   [AC_CHECK_HEADERS([locale.h])
31     if test $ac_cv_header_locale_h = yes; then
32     AC_CACHE_CHECK([for LC_MESSAGES], am_cv_val_LC_MESSAGES,
33       [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES],
34        am_cv_val_LC_MESSAGES=yes, am_cv_val_LC_MESSAGES=no)])
35     if test $am_cv_val_LC_MESSAGES = yes; then
36       AC_DEFINE(HAVE_LC_MESSAGES, 1,
37         [Define if your <locale.h> file defines LC_MESSAGES.])
38     fi
39   fi])
40
41 # GLIB_PATH_PROG_WITH_TEST
42 #----------------------------
43 dnl GLIB_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
44 dnl   TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
45 glib_DEFUN([GLIB_PATH_PROG_WITH_TEST],
46 [# Extract the first word of "$2", so it can be a program name with args.
47 set dummy $2; ac_word=[$]2
48 AC_MSG_CHECKING([for $ac_word])
49 AC_CACHE_VAL(ac_cv_path_$1,
50 [case "[$]$1" in
51   /*)
52   ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
53   ;;
54   *)
55   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
56   for ac_dir in ifelse([$5], , $PATH, [$5]); do
57     test -z "$ac_dir" && ac_dir=.
58     if test -f $ac_dir/$ac_word; then
59       if [$3]; then
60         ac_cv_path_$1="$ac_dir/$ac_word"
61         break
62       fi
63     fi
64   done
65   IFS="$ac_save_ifs"
66 dnl If no 4th arg is given, leave the cache variable unset,
67 dnl so AC_PATH_PROGS will keep looking.
68 ifelse([$4], , , [  test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
69 ])dnl
70   ;;
71 esac])dnl
72 $1="$ac_cv_path_$1"
73 if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then
74   AC_MSG_RESULT([$]$1)
75 else
76   AC_MSG_RESULT(no)
77 fi
78 AC_SUBST($1)dnl
79 ])
80
81 # GLIB_WITH_NLS
82 #-----------------
83 glib_DEFUN([GLIB_WITH_NLS],
84   dnl NLS is obligatory
85   [USE_NLS=yes
86     AC_SUBST(USE_NLS)
87
88     gt_cv_have_gettext=no
89
90     CATOBJEXT=NONE
91     XGETTEXT=:
92
93     AC_CHECK_HEADER(libintl.h,
94      [gt_cv_func_dgettext_libintl="no"
95       libintl_extra_libs=""
96
97       #
98       # First check in libc
99       #
100       AC_CACHE_CHECK([for dgettext in libc], gt_cv_func_dgettext_libc,
101         [AC_TRY_LINK([
102 #include <libintl.h>
103 ],
104           [return (int) dgettext ("","")],
105           gt_cv_func_dgettext_libc=yes,
106           gt_cv_func_dgettext_libc=no)
107         ])
108   
109       if test "$gt_cv_func_dgettext_libc" = "yes" ; then
110         AC_CHECK_FUNCS(bind_textdomain_codeset)
111       fi
112
113       #
114       # If we don't have everything we want, check in libintl
115       #
116       if test "$gt_cv_func_dgettext_libc" != "yes" \
117          || test "$ac_cv_func_bind_textdomain_codeset" != "yes" ; then
118         
119         AC_CHECK_LIB(intl, bindtextdomain,
120             [AC_CHECK_LIB(intl, dgettext,
121                           gt_cv_func_dgettext_libintl=yes)])
122
123         if test "$gt_cv_func_dgettext_libintl" != "yes" ; then
124           AC_MSG_CHECKING([if -liconv is needed to use gettext])
125           AC_MSG_RESULT([])
126           AC_CHECK_LIB(intl, dcgettext,
127                        [gt_cv_func_dgettext_libintl=yes
128                         libintl_extra_libs=-liconv],
129                         :,-liconv)
130         fi
131
132         #
133         # If we found libintl, then check in it for bind_textdomain_codeset();
134         # we'll prefer libc if neither have bind_textdomain_codeset(),
135         # and both have dgettext
136         #
137         if test "$gt_cv_func_dgettext_libintl" = "yes" ; then
138           glib_save_LIBS="$LIBS"
139           LIBS="$LIBS -lintl $libintl_extra_libs"
140           unset ac_cv_func_bind_textdomain_codeset
141           AC_CHECK_FUNCS(bind_textdomain_codeset)
142           LIBS="$glib_save_LIBS"
143
144           if test "$ac_cv_func_bind_textdomain_codeset" = "yes" ; then
145             gt_cv_func_dgettext_libc=no
146           else
147             if test "$gt_cv_func_dgettext_libc" = "yes"; then
148               gt_cv_func_dgettext_libintl=no
149             fi
150           fi
151         fi
152       fi
153
154       if test "$gt_cv_func_dgettext_libc" = "yes" \
155         || test "$gt_cv_func_dgettext_libintl" = "yes"; then
156         gt_cv_have_gettext=yes
157       fi
158   
159       if test "$gt_cv_have_gettext" = "yes"; then
160         AC_DEFINE(HAVE_GETTEXT,1,
161           [Define if the GNU gettext() function is already present or preinstalled.])
162         GLIB_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
163           [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
164         if test "$MSGFMT" != "no"; then
165           AC_CHECK_FUNCS(dcgettext)
166           AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
167           GLIB_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
168             [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
169           AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
170                          return _nl_msg_cat_cntr],
171             [CATOBJEXT=.gmo 
172              DATADIRNAME=share],
173             [CATOBJEXT=.mo
174              DATADIRNAME=lib])
175           INSTOBJEXT=.mo
176         fi
177       fi
178
179       LIBS="$glib_save_LIBS"
180     ])
181
182     if test "$gt_cv_have_gettext" = "yes" ; then
183       AC_DEFINE(ENABLE_NLS, 1,
184         [always defined to indicate that i18n is enabled])
185     fi
186
187     dnl Test whether we really found GNU xgettext.
188     if test "$XGETTEXT" != ":"; then
189       dnl If it is not GNU xgettext we define it as : so that the
190       dnl Makefiles still can work.
191       if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
192         : ;
193       else
194         AC_MSG_RESULT(
195           [found xgettext program is not GNU xgettext; ignore it])
196         XGETTEXT=":"
197       fi
198     fi
199
200     # We need to process the po/ directory.
201     POSUB=po
202
203     AC_OUTPUT_COMMANDS(
204       [case "$CONFIG_FILES" in *po/Makefile.in*)
205         sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
206       esac])
207
208     dnl These rules are solely for the distribution goal.  While doing this
209     dnl we only have to keep exactly one list of the available catalogs
210     dnl in configure.in.
211     for lang in $ALL_LINGUAS; do
212       GMOFILES="$GMOFILES $lang.gmo"
213       POFILES="$POFILES $lang.po"
214     done
215
216     dnl Make all variables we use known to autoconf.
217     AC_SUBST(CATALOGS)
218     AC_SUBST(CATOBJEXT)
219     AC_SUBST(GMOFILES)
220     AC_SUBST(INSTOBJEXT)
221     AC_SUBST(INTLLIBS)
222     AC_SUBST(PO_IN_DATADIR_TRUE)
223     AC_SUBST(PO_IN_DATADIR_FALSE)
224     AC_SUBST(POFILES)
225     AC_SUBST(POSUB)
226   ])
227
228 # AM_GLIB_GNU_GETTEXT
229 # -------------------
230 # Do checks necessary for use of gettext. If a suitable implementation 
231 # of gettext is found in either in libintl or in the C library,
232 # it will set INTLLIBS to the libraries needed for use of gettext
233 # and AC_DEFINE() HAVE_GETTEXT and ENABLE_NLS. (The shell variable
234 # gt_cv_have_gettext will be set to "yes".) It will also call AC_SUBST()
235 # on various variables needed by the Makefile.in.in installed by 
236 # glib-gettextize.
237 dnl
238 glib_DEFUN(GLIB_GNU_GETTEXT,
239   [AC_REQUIRE([AC_PROG_CC])dnl
240    AC_REQUIRE([AC_HEADER_STDC])dnl
241    
242    GLIB_LC_MESSAGES
243    GLIB_WITH_NLS
244
245    if test "$gt_cv_have_gettext" = "yes"; then
246      if test "x$ALL_LINGUAS" = "x"; then
247        LINGUAS=
248      else
249        AC_MSG_CHECKING(for catalogs to be installed)
250        NEW_LINGUAS=
251        for lang in ${LINGUAS=$ALL_LINGUAS}; do
252          case "$ALL_LINGUAS" in
253           *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
254          esac
255        done
256        LINGUAS=$NEW_LINGUAS
257        AC_MSG_RESULT($LINGUAS)
258      fi
259
260      dnl Construct list of names of catalog files to be constructed.
261      if test -n "$LINGUAS"; then
262        for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
263      fi
264    fi
265
266    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
267    dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
268    dnl Try to locate is.
269    MKINSTALLDIRS=
270    if test -n "$ac_aux_dir"; then
271      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
272    fi
273    if test -z "$MKINSTALLDIRS"; then
274      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
275    fi
276    AC_SUBST(MKINSTALLDIRS)
277
278    dnl Generate list of files to be processed by xgettext which will
279    dnl be included in po/Makefile.
280    test -d po || mkdir po
281    if test "x$srcdir" != "x."; then
282      if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
283        posrcprefix="$srcdir/"
284      else
285        posrcprefix="../$srcdir/"
286      fi
287    else
288      posrcprefix="../"
289    fi
290    rm -f po/POTFILES
291    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
292         < $srcdir/po/POTFILES.in > po/POTFILES
293   ])
294
295 # AM_GLIB_DEFINE_LOCALEDIR(VARIABLE)
296 # -------------------------------
297 # Define VARIABLE to the location where catalog files will
298 # be installed by po/Makefile.
299 glib_DEFUN(GLIB_DEFINE_LOCALEDIR,
300 [glib_REQUIRE([GLIB_GNU_GETTEXT])dnl
301 glib_save_prefix="$prefix"
302 test "x$prefix" = xNONE && prefix=$ac_default_prefix
303 if test "x$CATOBJEXT" = "x.mo" ; then
304   localedir=`eval echo "${libdir}/locale"`
305 else
306   localedir=`eval echo "${datadir}/locale"`
307 fi
308 prefix="$glib_save_prefix"
309 AC_DEFINE_UNQUOTED($1, "$localedir",
310   [Define the location where the catalogs will be installed])
311 ])
312
313 dnl
314 dnl Now the definitions that aclocal will find
315 dnl
316 ifdef(glib_configure_in,[],[
317 AC_DEFUN(AM_GLIB_GNU_GETTEXT,[GLIB_GNU_GETTEXT($@)])
318 AC_DEFUN(AM_GLIB_DEFINE_LOCALEDIR,[GLIB_DEFINE_LOCALEDIR($@)])
319 ])dnl