]> git.saurik.com Git - bison.git/blob - m4/gettext.m4
* doc/bison.texinfo: Update.
[bison.git] / m4 / gettext.m4
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
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.
8
9 # serial 9
10
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
19 dnl will be ignored.
20 dnl LIBDIR is used to find the intl libraries. If empty,
21 dnl the value `$(top_builddir)/intl/' is used.
22 dnl
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
25 dnl and used.
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
37 dnl maintainers.
38 dnl
39 AC_DEFUN([AM_WITH_NLS],
40 [AC_MSG_CHECKING([whether NLS is requested])
41 dnl Default is enabled NLS
42 AC_ARG_ENABLE(nls,
43 [ --disable-nls do not use Native Language Support],
44 USE_NLS=$enableval, USE_NLS=yes)
45 AC_MSG_RESULT($USE_NLS)
46 AC_SUBST(USE_NLS)
47
48 BUILD_INCLUDED_LIBINTL=no
49 USE_INCLUDED_LIBINTL=no
50 INTLLIBS=
51
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
56 is requested.])
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)
63
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.
69 CATOBJEXT=NONE
70
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])
74
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)])
83
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,
87 [gt_save_LIBS="$LIBS"
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"])
96 fi
97
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.])
107
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
111 dnl libiconv.
112 INTLLIBS="-lintl $LIBICONV"
113 fi
114
115 gt_save_LIBS="$LIBS"
116 LIBS="$LIBS $INTLLIBS"
117 AC_CHECK_FUNCS(dcgettext)
118 LIBS="$gt_save_LIBS"
119
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)
124 fi
125
126 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
127 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
128
129 CATOBJEXT=.gmo
130 fi
131 ])
132
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
137 fi
138 fi
139
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)'`"], :)
148 AC_SUBST(MSGFMT)
149 BUILD_INCLUDED_LIBINTL=yes
150 USE_INCLUDED_LIBINTL=yes
151 CATOBJEXT=.gmo
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/ $//'`
154 fi
155
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
161 : ;
162 else
163 AC_MSG_RESULT(
164 [found xgettext program is not GNU xgettext; ignore it])
165 XGETTEXT=":"
166 fi
167 fi
168
169 dnl We need to process the po/ directory.
170 POSUB=po
171 fi
172 AC_OUTPUT_COMMANDS(
173 [for ac_file in $CONFIG_FILES; do
174 # Support "outfile[:infile[:infile...]]"
175 case "$ac_file" in
176 *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
177 esac
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" ;;
189 esac
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"
196 fi
197 ;;
198 esac
199 done])
200
201
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
206 fi
207
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
211 dnl compile.
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
220 ac_verc_fail=yes
221 else
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].*)
229 changequote([,])dnl
230 ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
231 *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
232 esac
233 AC_MSG_RESULT([$ac_prog_version])
234 fi
235 if test $ac_verc_fail = yes; then
236 INTLBISON=:
237 fi
238
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
241 dnl in configure.in.
242 for lang in $ALL_LINGUAS; do
243 GMOFILES="$GMOFILES $lang.gmo"
244 POFILES="$POFILES $lang.po"
245 done
246
247 dnl Make all variables we use known to autoconf.
248 AC_SUBST(BUILD_INCLUDED_LIBINTL)
249 AC_SUBST(USE_INCLUDED_LIBINTL)
250 AC_SUBST(CATALOGS)
251 AC_SUBST(CATOBJEXT)
252 AC_SUBST(GMOFILES)
253 AC_SUBST(INTLLIBS)
254 AC_SUBST(INTLOBJS)
255 AC_SUBST(POFILES)
256 AC_SUBST(POSUB)
257
258 dnl For backward compatibility. Some configure.ins may be using this.
259 nls_cv_header_intl=
260 nls_cv_header_libgt=
261
262 dnl For backward compatibility. Some Makefiles may be using this.
263 DATADIRNAME=share
264 AC_SUBST(DATADIRNAME)
265
266 dnl For backward compatibility. Some Makefiles may be using this.
267 INSTOBJEXT=.mo
268 AC_SUBST(INSTOBJEXT)
269
270 dnl For backward compatibility. Some Makefiles may be using this.
271 GENCAT=gencat
272 AC_SUBST(GENCAT)
273 ])
274
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
290
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])
296
297 AM_ICONV
298 AM_LANGINFO_CODESET
299 AM_LC_MESSAGES
300 AM_WITH_NLS([$1],[$2],[$3])
301
302 if test "x$CATOBJEXT" != "x"; then
303 if test "x$ALL_LINGUAS" = "x"; then
304 LINGUAS=
305 else
306 AC_MSG_CHECKING(for catalogs to be installed)
307 NEW_LINGUAS=
308 for presentlang in $ALL_LINGUAS; do
309 useit=no
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;;
318 esac
319 done
320 if test $useit = yes; then
321 NEW_LINGUAS="$NEW_LINGUAS $presentlang"
322 fi
323 done
324 LINGUAS=$NEW_LINGUAS
325 AC_MSG_RESULT($LINGUAS)
326 fi
327
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
331 fi
332 fi
333
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.
337 MKINSTALLDIRS=
338 if test -n "$ac_aux_dir"; then
339 MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
340 fi
341 if test -z "$MKINSTALLDIRS"; then
342 MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
343 fi
344 AC_SUBST(MKINSTALLDIRS)
345
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)
349 ])