1 # Macro to add for using GNU gettext.
2 # Ulrich Drepper <drepper@cygnus.com>, 1995.
4 # This file can be copied and used freely without restrictions. It can
5 # be used in projects which are not available under the GNU Public License
6 # but which still want to provide support for the GNU gettext functionality.
7 # Please note that the actual code is *not* freely available.
11 dnl Usage: AM_WITH_NLS([TOOLSYMBOL], [NEEDSYMBOL], [LIBDIR]).
12 dnl If TOOLSYMBOL is specified and is 'use-libtool', then a libtool library
13 dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static,
14 dnl depending on --{enable,disable}-{shared,static} and on the presence of
15 dnl AM-DISABLE-SHARED). Otherwise, a static library
16 dnl $(top_builddir)/intl/libintl.a will be created.
17 dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
18 dnl implementations (in libc or libintl) without the ngettext() function
20 dnl LIBDIR is used to find the intl libraries. If empty,
21 dnl the value `$(top_builddir)/intl/' is used.
23 dnl The result of the configuration is one of three cases:
24 dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled
26 dnl Catalog format: GNU --> install in $(datadir)
27 dnl Catalog extension: .mo after installation, .gmo in source tree
28 dnl 2) GNU gettext has been found in the system's C library.
29 dnl Catalog format: GNU --> install in $(datadir)
30 dnl Catalog extension: .mo after installation, .gmo in source tree
31 dnl 3) No internationalization, always use English msgid.
32 dnl Catalog format: none
33 dnl Catalog extension: none
34 dnl The use of .gmo is historical (it was needed to avoid overwriting the
35 dnl GNU format catalogs when building on a platform with an X/Open gettext),
36 dnl but we keep it in order not to force irrelevant filename changes on the
39 AC_DEFUN([AM_WITH_NLS],
40 [AC_MSG_CHECKING([whether NLS is requested])
41 dnl Default is enabled NLS
43 [ --disable-nls do not use Native Language Support],
44 USE_NLS=$enableval, USE_NLS=yes)
45 AC_MSG_RESULT($USE_NLS)
48 BUILD_INCLUDED_LIBINTL=no
49 USE_INCLUDED_LIBINTL=no
52 dnl If we use NLS figure out what method
53 if test "$USE_NLS" = "yes"; then
54 AC_DEFINE(ENABLE_NLS, 1,
55 [Define to 1 if translation of program messages to the user's native language
57 AC_MSG_CHECKING([whether included gettext is requested])
58 AC_ARG_WITH(included-gettext,
59 [ --with-included-gettext use the GNU gettext library included here],
60 nls_cv_force_use_gnu_gettext=$withval,
61 nls_cv_force_use_gnu_gettext=no)
62 AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
64 nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
65 if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
66 dnl User does not insist on using GNU NLS library. Figure out what
67 dnl to use. If GNU gettext is available we use this. Else we have
68 dnl to fall back to GNU NLS library.
71 dnl Add a version number to the cache macros.
72 define(gt_cv_func_gnugettext_libc, [gt_cv_func_gnugettext]ifelse([$2], need-ngettext, 2, 1)[_libc])
73 define(gt_cv_func_gnugettext_libintl, [gt_cv_func_gnugettext]ifelse([$2], need-ngettext, 2, 1)[_libintl])
75 AC_CHECK_HEADER(libintl.h,
76 [AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc,
77 [AC_TRY_LINK([#include <libintl.h>
78 extern int _nl_msg_cat_cntr;],
79 [bindtextdomain ("", "");
80 return (int) gettext ("")]ifelse([$2], need-ngettext, [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr],
81 gt_cv_func_gnugettext_libc=yes,
82 gt_cv_func_gnugettext_libc=no)])
84 if test "$gt_cv_func_gnugettext_libc" != "yes"; then
85 AC_CACHE_CHECK([for GNU gettext in libintl],
86 gt_cv_func_gnugettext_libintl,
88 LIBS="$LIBS -lintl $LIBICONV"
89 AC_TRY_LINK([#include <libintl.h>
90 extern int _nl_msg_cat_cntr;],
91 [bindtextdomain ("", "");
92 return (int) gettext ("")]ifelse([$2], need-ngettext, [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr],
93 gt_cv_func_gnugettext_libintl=yes,
94 gt_cv_func_gnugettext_libintl=no)
95 LIBS="$gt_save_LIBS"])
98 dnl If an already present or preinstalled GNU gettext() is found,
99 dnl use it. But if this macro is used in GNU gettext, and GNU
100 dnl gettext is already preinstalled in libintl, we update this
101 dnl libintl. (Cf. the install rule in intl/Makefile.in.)
102 if test "$gt_cv_func_gnugettext_libc" = "yes" \
103 || { test "$gt_cv_func_gnugettext_libintl" = "yes" \
104 && test "$PACKAGE" != gettext; }; then
105 AC_DEFINE(HAVE_GETTEXT, 1,
106 [Define if the GNU gettext() function is already present or preinstalled.])
108 if test "$gt_cv_func_gnugettext_libintl" = "yes"; then
109 dnl If iconv() is in a separate libiconv library, then anyone
110 dnl linking with libintl{.a,.so} also needs to link with
112 INTLLIBS="-lintl $LIBICONV"
116 LIBS="$LIBS $INTLLIBS"
117 AC_CHECK_FUNCS(dcgettext)
120 AM_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_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
126 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
127 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
133 if test "$CATOBJEXT" = "NONE"; then
134 dnl GNU gettext is not found in the C library.
135 dnl Fall back on GNU gettext library.
136 nls_cv_use_gnu_gettext=yes
140 if test "$nls_cv_use_gnu_gettext" = "yes"; then
141 dnl Mark actions used to generate GNU NLS library.
142 INTLOBJS="\$(GETTOBJS)"
143 AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
144 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], msgfmt)
145 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
146 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
147 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
149 BUILD_INCLUDED_LIBINTL=yes
150 USE_INCLUDED_LIBINTL=yes
152 INTLLIBS="ifelse([$3],[],\$(top_builddir)/intl,[$3])/libintl.ifelse([$1], use-libtool, [l], [])a $LIBICONV"
153 LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
156 dnl Test whether we really found GNU xgettext.
157 if test "$XGETTEXT" != ":"; then
158 dnl If it is no GNU xgettext we define it as : so that the
159 dnl Makefiles still can work.
160 if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
164 [found xgettext program is not GNU xgettext; ignore it])
169 dnl We need to process the po/ directory.
173 [for ac_file in $CONFIG_FILES; do
174 # Support "outfile[:infile[:infile...]]"
176 *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
178 # PO directories have a Makefile.in generated from Makefile.in.in.
179 case "$ac_file" in */Makefile.in)
180 # Adjust a relative srcdir.
181 ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
182 ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
183 ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
184 test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
185 case "$ac_given_srcdir" in
186 .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
187 /*) top_srcdir="$ac_given_srcdir" ;;
188 *) top_srcdir="$ac_dots$ac_given_srcdir" ;;
190 if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then
191 rm -f "$ac_dir/POTFILES"
192 test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES"
193 sed -e "/^#/d" -e "/^[ ]*\$/d" -e "s,.*, $top_srcdir/& \\\\," -e "\$s/\(.*\) \\\\/\1/" < "$ac_given_srcdir/$ac_dir/POTFILES.in" > "$ac_dir/POTFILES"
194 test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile"
195 sed -e "/POTFILES =/r $ac_dir/POTFILES" "$ac_dir/Makefile.in" > "$ac_dir/Makefile"
202 dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL
203 dnl to 'yes' because some of the testsuite requires it.
204 if test "$PACKAGE" = gettext; then
205 BUILD_INCLUDED_LIBINTL=yes
208 dnl intl/plural.c is generated from intl/plural.y. It requires bison,
209 dnl because plural.y uses bison specific features. It requires at least
210 dnl bison-1.26 because earlier versions generate a plural.c that doesn't
212 dnl bison is only needed for the maintainer (who touches plural.y). But in
213 dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put
214 dnl the rule in general Makefile. Now, some people carelessly touch the
215 dnl files or have a broken "make" program, hence the plural.c rule will
216 dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not
217 dnl present or too old.
218 AC_CHECK_PROGS([INTLBISON], [bison])
219 if test -z "$INTLBISON"; then
222 dnl Found it, now check the version.
223 AC_MSG_CHECKING([version of bison])
224 changequote(<<,>>)dnl
225 ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison .* \([0-9]*\.[0-9.]*\).*$/\1/p'`
226 case $ac_prog_version in
227 '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
228 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*)
230 ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
231 *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
233 AC_MSG_RESULT([$ac_prog_version])
235 if test $ac_verc_fail = yes; then
239 dnl These rules are solely for the distribution goal. While doing this
240 dnl we only have to keep exactly one list of the available catalogs
242 for lang in $ALL_LINGUAS; do
243 GMOFILES="$GMOFILES $lang.gmo"
244 POFILES="$POFILES $lang.po"
247 dnl Make all variables we use known to autoconf.
248 AC_SUBST(BUILD_INCLUDED_LIBINTL)
249 AC_SUBST(USE_INCLUDED_LIBINTL)
258 dnl For backward compatibility. Some configure.ins may be using this.
262 dnl For backward compatibility. Some Makefiles may be using this.
264 AC_SUBST(DATADIRNAME)
266 dnl For backward compatibility. Some Makefiles may be using this.
270 dnl For backward compatibility. Some Makefiles may be using this.
275 dnl Usage: Just like AM_WITH_NLS, which see.
276 AC_DEFUN([AM_GNU_GETTEXT],
277 [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
278 AC_REQUIRE([AC_PROG_CC])dnl
279 AC_REQUIRE([AC_CANONICAL_HOST])dnl
280 AC_REQUIRE([AC_PROG_RANLIB])dnl
281 AC_REQUIRE([AC_ISC_POSIX])dnl
282 AC_REQUIRE([AC_HEADER_STDC])dnl
283 AC_REQUIRE([AC_C_CONST])dnl
284 AC_REQUIRE([AC_C_INLINE])dnl
285 AC_REQUIRE([AC_TYPE_OFF_T])dnl
286 AC_REQUIRE([AC_TYPE_SIZE_T])dnl
287 AC_REQUIRE([AC_FUNC_ALLOCA])dnl
288 AC_REQUIRE([AC_FUNC_MMAP])dnl
289 AC_REQUIRE([jm_GLIBC21])dnl
291 AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \
292 stdlib.h string.h unistd.h sys/param.h])
293 AC_CHECK_FUNCS([feof_unlocked fgets_unlocked getcwd getegid geteuid \
294 getgid getuid mempcpy munmap putenv setenv setlocale stpcpy strchr strcasecmp \
295 strdup strtoul tsearch __argz_count __argz_stringify __argz_next])
300 AM_WITH_NLS([$1],[$2],[$3])
302 if test "x$CATOBJEXT" != "x"; then
303 if test "x$ALL_LINGUAS" = "x"; then
306 AC_MSG_CHECKING(for catalogs to be installed)
308 for presentlang in $ALL_LINGUAS; do
310 for desiredlang in ${LINGUAS-$ALL_LINGUAS}; do
311 # Use the presentlang catalog if desiredlang is
312 # a. equal to presentlang, or
313 # b. a variant of presentlang (because in this case,
314 # presentlang can be used as a fallback for messages
315 # which are not translated in the desiredlang catalog).
316 case "$desiredlang" in
317 "$presentlang"*) useit=yes;;
320 if test $useit = yes; then
321 NEW_LINGUAS="$NEW_LINGUAS $presentlang"
325 AC_MSG_RESULT($LINGUAS)
328 dnl Construct list of names of catalog files to be constructed.
329 if test -n "$LINGUAS"; then
330 for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
334 dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
335 dnl find the mkinstalldirs script in another subdir but $(top_srcdir).
336 dnl Try to locate is.
338 if test -n "$ac_aux_dir"; then
339 MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
341 if test -z "$MKINSTALLDIRS"; then
342 MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
344 AC_SUBST(MKINSTALLDIRS)
346 dnl Enable libtool support if the surrounding package wishes it.
347 INTL_LIBTOOL_SUFFIX_PREFIX=ifelse([$1], use-libtool, [l], [])
348 AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX)