]> git.saurik.com Git - bison.git/blame - m4/gettext.m4
* src/reader.c (readgram): Display hidden chars in error messages.
[bison.git] / m4 / gettext.m4
CommitLineData
8c44d3ec
AD
1# Macro to add for using GNU gettext.
2# Ulrich Drepper <drepper@cygnus.com>, 1995.
3#
4# This file can be copied and used freely without restrictions. It can
459dd1a6
AD
5# be used in projects which are not available under the GNU General Public
6# License but which still want to provide support for the GNU gettext
7# functionality.
8# Please note that the actual code of GNU gettext is covered by the GNU
9# General Public License and is *not* in the public domain.
8c44d3ec 10
459dd1a6 11# serial 10
1e24cc5b
AD
12
13dnl Usage: AM_WITH_NLS([TOOLSYMBOL], [NEEDSYMBOL], [LIBDIR]).
14dnl If TOOLSYMBOL is specified and is 'use-libtool', then a libtool library
15dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static,
16dnl depending on --{enable,disable}-{shared,static} and on the presence of
17dnl AM-DISABLE-SHARED). Otherwise, a static library
18dnl $(top_builddir)/intl/libintl.a will be created.
19dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
20dnl implementations (in libc or libintl) without the ngettext() function
21dnl will be ignored.
22dnl LIBDIR is used to find the intl libraries. If empty,
23dnl the value `$(top_builddir)/intl/' is used.
24dnl
25dnl The result of the configuration is one of three cases:
26dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled
27dnl and used.
28dnl Catalog format: GNU --> install in $(datadir)
29dnl Catalog extension: .mo after installation, .gmo in source tree
30dnl 2) GNU gettext has been found in the system's C library.
31dnl Catalog format: GNU --> install in $(datadir)
32dnl Catalog extension: .mo after installation, .gmo in source tree
33dnl 3) No internationalization, always use English msgid.
34dnl Catalog format: none
35dnl Catalog extension: none
36dnl The use of .gmo is historical (it was needed to avoid overwriting the
37dnl GNU format catalogs when building on a platform with an X/Open gettext),
38dnl but we keep it in order not to force irrelevant filename changes on the
39dnl maintainers.
40dnl
41AC_DEFUN([AM_WITH_NLS],
8c44d3ec
AD
42 [AC_MSG_CHECKING([whether NLS is requested])
43 dnl Default is enabled NLS
44 AC_ARG_ENABLE(nls,
45 [ --disable-nls do not use Native Language Support],
46 USE_NLS=$enableval, USE_NLS=yes)
47 AC_MSG_RESULT($USE_NLS)
48 AC_SUBST(USE_NLS)
49
1e24cc5b 50 BUILD_INCLUDED_LIBINTL=no
8c44d3ec 51 USE_INCLUDED_LIBINTL=no
1e24cc5b 52 INTLLIBS=
8c44d3ec
AD
53
54 dnl If we use NLS figure out what method
55 if test "$USE_NLS" = "yes"; then
1e24cc5b
AD
56 AC_DEFINE(ENABLE_NLS, 1,
57 [Define to 1 if translation of program messages to the user's native language
58 is requested.])
8c44d3ec
AD
59 AC_MSG_CHECKING([whether included gettext is requested])
60 AC_ARG_WITH(included-gettext,
61 [ --with-included-gettext use the GNU gettext library included here],
62 nls_cv_force_use_gnu_gettext=$withval,
63 nls_cv_force_use_gnu_gettext=no)
64 AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
65
66 nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
67 if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
68 dnl User does not insist on using GNU NLS library. Figure out what
1e24cc5b
AD
69 dnl to use. If GNU gettext is available we use this. Else we have
70 dnl to fall back to GNU NLS library.
8c44d3ec
AD
71 CATOBJEXT=NONE
72
1e24cc5b
AD
73 dnl Add a version number to the cache macros.
74 define(gt_cv_func_gnugettext_libc, [gt_cv_func_gnugettext]ifelse([$2], need-ngettext, 2, 1)[_libc])
75 define(gt_cv_func_gnugettext_libintl, [gt_cv_func_gnugettext]ifelse([$2], need-ngettext, 2, 1)[_libintl])
8c44d3ec 76
1e24cc5b
AD
77 AC_CHECK_HEADER(libintl.h,
78 [AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc,
79 [AC_TRY_LINK([#include <libintl.h>
80extern int _nl_msg_cat_cntr;],
81 [bindtextdomain ("", "");
82return (int) gettext ("")]ifelse([$2], need-ngettext, [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr],
83 gt_cv_func_gnugettext_libc=yes,
84 gt_cv_func_gnugettext_libc=no)])
85
86 if test "$gt_cv_func_gnugettext_libc" != "yes"; then
87 AC_CACHE_CHECK([for GNU gettext in libintl],
88 gt_cv_func_gnugettext_libintl,
89 [gt_save_LIBS="$LIBS"
90 LIBS="$LIBS -lintl $LIBICONV"
91 AC_TRY_LINK([#include <libintl.h>
92extern int _nl_msg_cat_cntr;],
93 [bindtextdomain ("", "");
94return (int) gettext ("")]ifelse([$2], need-ngettext, [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr],
95 gt_cv_func_gnugettext_libintl=yes,
96 gt_cv_func_gnugettext_libintl=no)
97 LIBS="$gt_save_LIBS"])
8c44d3ec
AD
98 fi
99
1e24cc5b
AD
100 dnl If an already present or preinstalled GNU gettext() is found,
101 dnl use it. But if this macro is used in GNU gettext, and GNU
102 dnl gettext is already preinstalled in libintl, we update this
103 dnl libintl. (Cf. the install rule in intl/Makefile.in.)
104 if test "$gt_cv_func_gnugettext_libc" = "yes" \
105 || { test "$gt_cv_func_gnugettext_libintl" = "yes" \
106 && test "$PACKAGE" != gettext; }; then
107 AC_DEFINE(HAVE_GETTEXT, 1,
108 [Define if the GNU gettext() function is already present or preinstalled.])
109
110 if test "$gt_cv_func_gnugettext_libintl" = "yes"; then
111 dnl If iconv() is in a separate libiconv library, then anyone
112 dnl linking with libintl{.a,.so} also needs to link with
113 dnl libiconv.
114 INTLLIBS="-lintl $LIBICONV"
115 fi
116
117 gt_save_LIBS="$LIBS"
118 LIBS="$LIBS $INTLLIBS"
119 AC_CHECK_FUNCS(dcgettext)
120 LIBS="$gt_save_LIBS"
121
459dd1a6 122 dnl Search for GNU msgfmt in the PATH.
1e24cc5b 123 AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
459dd1a6
AD
124 [$ac_dir/$ac_word --statistics /dev/null >/dev/null 2>&1], :)
125 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
1e24cc5b 126
459dd1a6 127 dnl Search for GNU xgettext in the PATH.
1e24cc5b 128 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
459dd1a6 129 [$ac_dir/$ac_word --omit-header /dev/null >/dev/null 2>&1], :)
1e24cc5b
AD
130
131 CATOBJEXT=.gmo
132 fi
8c44d3ec
AD
133 ])
134
135 if test "$CATOBJEXT" = "NONE"; then
1e24cc5b 136 dnl GNU gettext is not found in the C library.
8c44d3ec
AD
137 dnl Fall back on GNU gettext library.
138 nls_cv_use_gnu_gettext=yes
139 fi
140 fi
141
142 if test "$nls_cv_use_gnu_gettext" = "yes"; then
143 dnl Mark actions used to generate GNU NLS library.
144 INTLOBJS="\$(GETTOBJS)"
145 AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
459dd1a6 146 [$ac_dir/$ac_word --statistics /dev/null >/dev/null 2>&1], :)
8c44d3ec
AD
147 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
148 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
459dd1a6 149 [$ac_dir/$ac_word --omit-header /dev/null >/dev/null 2>&1], :)
8c44d3ec 150 AC_SUBST(MSGFMT)
1e24cc5b 151 BUILD_INCLUDED_LIBINTL=yes
8c44d3ec
AD
152 USE_INCLUDED_LIBINTL=yes
153 CATOBJEXT=.gmo
1e24cc5b
AD
154 INTLLIBS="ifelse([$3],[],\$(top_builddir)/intl,[$3])/libintl.ifelse([$1], use-libtool, [l], [])a $LIBICONV"
155 LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
8c44d3ec
AD
156 fi
157
459dd1a6
AD
158 dnl This could go away some day; the PATH_PROG_WITH_TEST already does it.
159 dnl Test whether we really found GNU msgfmt.
160 if test "$GMSGFMT" != ":"; then
161 dnl If it is no GNU msgfmt we define it as : so that the
162 dnl Makefiles still can work.
163 if $GMSGFMT --statistics /dev/null >/dev/null 2>&1; then
164 : ;
165 else
166 AC_MSG_RESULT(
167 [found msgfmt program is not GNU msgfmt; ignore it])
168 GMSGFMT=":"
169 fi
170 fi
171
172 dnl This could go away some day; the PATH_PROG_WITH_TEST already does it.
8c44d3ec
AD
173 dnl Test whether we really found GNU xgettext.
174 if test "$XGETTEXT" != ":"; then
175 dnl If it is no GNU xgettext we define it as : so that the
176 dnl Makefiles still can work.
459dd1a6 177 if $XGETTEXT --omit-header /dev/null >/dev/null 2>&1; then
8c44d3ec
AD
178 : ;
179 else
180 AC_MSG_RESULT(
181 [found xgettext program is not GNU xgettext; ignore it])
182 XGETTEXT=":"
183 fi
184 fi
185
1e24cc5b 186 dnl We need to process the po/ directory.
8c44d3ec 187 POSUB=po
8c44d3ec 188 fi
8c44d3ec 189 AC_OUTPUT_COMMANDS(
1e24cc5b
AD
190 [for ac_file in $CONFIG_FILES; do
191 # Support "outfile[:infile[:infile...]]"
192 case "$ac_file" in
193 *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
194 esac
195 # PO directories have a Makefile.in generated from Makefile.in.in.
196 case "$ac_file" in */Makefile.in)
197 # Adjust a relative srcdir.
198 ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
199 ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
200 ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
459dd1a6
AD
201 # In autoconf-2.13 it is called $ac_given_srcdir.
202 # In autoconf-2.50 it is called $srcdir.
1e24cc5b
AD
203 test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
204 case "$ac_given_srcdir" in
205 .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
206 /*) top_srcdir="$ac_given_srcdir" ;;
207 *) top_srcdir="$ac_dots$ac_given_srcdir" ;;
208 esac
209 if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then
210 rm -f "$ac_dir/POTFILES"
211 test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES"
212 sed -e "/^#/d" -e "/^[ ]*\$/d" -e "s,.*, $top_srcdir/& \\\\," -e "\$s/\(.*\) \\\\/\1/" < "$ac_given_srcdir/$ac_dir/POTFILES.in" > "$ac_dir/POTFILES"
213 test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile"
214 sed -e "/POTFILES =/r $ac_dir/POTFILES" "$ac_dir/Makefile.in" > "$ac_dir/Makefile"
215 fi
216 ;;
217 esac
218 done])
219
220
221 dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL
222 dnl to 'yes' because some of the testsuite requires it.
8c44d3ec 223 if test "$PACKAGE" = gettext; then
1e24cc5b
AD
224 BUILD_INCLUDED_LIBINTL=yes
225 fi
226
227 dnl intl/plural.c is generated from intl/plural.y. It requires bison,
228 dnl because plural.y uses bison specific features. It requires at least
229 dnl bison-1.26 because earlier versions generate a plural.c that doesn't
230 dnl compile.
231 dnl bison is only needed for the maintainer (who touches plural.y). But in
232 dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put
233 dnl the rule in general Makefile. Now, some people carelessly touch the
234 dnl files or have a broken "make" program, hence the plural.c rule will
235 dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not
236 dnl present or too old.
237 AC_CHECK_PROGS([INTLBISON], [bison])
238 if test -z "$INTLBISON"; then
239 ac_verc_fail=yes
240 else
241 dnl Found it, now check the version.
242 AC_MSG_CHECKING([version of bison])
243changequote(<<,>>)dnl
244 ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison .* \([0-9]*\.[0-9.]*\).*$/\1/p'`
245 case $ac_prog_version in
246 '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
247 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*)
248changequote([,])dnl
249 ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
250 *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
251 esac
252 AC_MSG_RESULT([$ac_prog_version])
253 fi
254 if test $ac_verc_fail = yes; then
255 INTLBISON=:
8c44d3ec
AD
256 fi
257
258 dnl These rules are solely for the distribution goal. While doing this
259 dnl we only have to keep exactly one list of the available catalogs
260 dnl in configure.in.
261 for lang in $ALL_LINGUAS; do
262 GMOFILES="$GMOFILES $lang.gmo"
263 POFILES="$POFILES $lang.po"
264 done
265
266 dnl Make all variables we use known to autoconf.
1e24cc5b 267 AC_SUBST(BUILD_INCLUDED_LIBINTL)
8c44d3ec
AD
268 AC_SUBST(USE_INCLUDED_LIBINTL)
269 AC_SUBST(CATALOGS)
270 AC_SUBST(CATOBJEXT)
8c44d3ec 271 AC_SUBST(GMOFILES)
8c44d3ec
AD
272 AC_SUBST(INTLLIBS)
273 AC_SUBST(INTLOBJS)
274 AC_SUBST(POFILES)
275 AC_SUBST(POSUB)
1e24cc5b
AD
276
277 dnl For backward compatibility. Some configure.ins may be using this.
278 nls_cv_header_intl=
279 nls_cv_header_libgt=
280
281 dnl For backward compatibility. Some Makefiles may be using this.
282 DATADIRNAME=share
283 AC_SUBST(DATADIRNAME)
284
285 dnl For backward compatibility. Some Makefiles may be using this.
286 INSTOBJEXT=.mo
287 AC_SUBST(INSTOBJEXT)
288
289 dnl For backward compatibility. Some Makefiles may be using this.
290 GENCAT=gencat
291 AC_SUBST(GENCAT)
8c44d3ec
AD
292 ])
293
1e24cc5b
AD
294dnl Usage: Just like AM_WITH_NLS, which see.
295AC_DEFUN([AM_GNU_GETTEXT],
8c44d3ec
AD
296 [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
297 AC_REQUIRE([AC_PROG_CC])dnl
1e24cc5b 298 AC_REQUIRE([AC_CANONICAL_HOST])dnl
8c44d3ec
AD
299 AC_REQUIRE([AC_PROG_RANLIB])dnl
300 AC_REQUIRE([AC_ISC_POSIX])dnl
301 AC_REQUIRE([AC_HEADER_STDC])dnl
302 AC_REQUIRE([AC_C_CONST])dnl
303 AC_REQUIRE([AC_C_INLINE])dnl
304 AC_REQUIRE([AC_TYPE_OFF_T])dnl
305 AC_REQUIRE([AC_TYPE_SIZE_T])dnl
306 AC_REQUIRE([AC_FUNC_ALLOCA])dnl
307 AC_REQUIRE([AC_FUNC_MMAP])dnl
1e24cc5b 308 AC_REQUIRE([jm_GLIBC21])dnl
8c44d3ec 309
1e24cc5b
AD
310 AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \
311stdlib.h string.h unistd.h sys/param.h])
312 AC_CHECK_FUNCS([feof_unlocked fgets_unlocked getcwd getegid geteuid \
313getgid getuid mempcpy munmap putenv setenv setlocale stpcpy strchr strcasecmp \
314strdup strtoul tsearch __argz_count __argz_stringify __argz_next])
8c44d3ec 315
1e24cc5b
AD
316 AM_ICONV
317 AM_LANGINFO_CODESET
8c44d3ec 318 AM_LC_MESSAGES
1e24cc5b 319 AM_WITH_NLS([$1],[$2],[$3])
8c44d3ec
AD
320
321 if test "x$CATOBJEXT" != "x"; then
322 if test "x$ALL_LINGUAS" = "x"; then
323 LINGUAS=
324 else
325 AC_MSG_CHECKING(for catalogs to be installed)
326 NEW_LINGUAS=
1e24cc5b
AD
327 for presentlang in $ALL_LINGUAS; do
328 useit=no
329 for desiredlang in ${LINGUAS-$ALL_LINGUAS}; do
330 # Use the presentlang catalog if desiredlang is
331 # a. equal to presentlang, or
332 # b. a variant of presentlang (because in this case,
333 # presentlang can be used as a fallback for messages
334 # which are not translated in the desiredlang catalog).
335 case "$desiredlang" in
336 "$presentlang"*) useit=yes;;
337 esac
338 done
339 if test $useit = yes; then
340 NEW_LINGUAS="$NEW_LINGUAS $presentlang"
341 fi
8c44d3ec
AD
342 done
343 LINGUAS=$NEW_LINGUAS
344 AC_MSG_RESULT($LINGUAS)
345 fi
346
347 dnl Construct list of names of catalog files to be constructed.
348 if test -n "$LINGUAS"; then
349 for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
350 fi
351 fi
352
8c44d3ec 353 dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
1e24cc5b 354 dnl find the mkinstalldirs script in another subdir but $(top_srcdir).
8c44d3ec
AD
355 dnl Try to locate is.
356 MKINSTALLDIRS=
357 if test -n "$ac_aux_dir"; then
1e24cc5b 358 MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
8c44d3ec
AD
359 fi
360 if test -z "$MKINSTALLDIRS"; then
361 MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
362 fi
363 AC_SUBST(MKINSTALLDIRS)
364
1e24cc5b
AD
365 dnl Enable libtool support if the surrounding package wishes it.
366 INTL_LIBTOOL_SUFFIX_PREFIX=ifelse([$1], use-libtool, [l], [])
367 AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX)
8c44d3ec 368 ])