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