2 dnl Copyright (C) 1995-2004 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
9 dnl This file can can be used in projects which are not available under
10 dnl the GNU General Public License or the GNU Library General Public
11 dnl License but which still want to provide support for the GNU gettext
13 dnl Please note that the actual code of the GNU gettext library is covered
14 dnl by the GNU Library General Public License, and the rest of the GNU
15 dnl gettext package package is covered by the GNU General Public License.
16 dnl They are *not* in the public domain.
19 dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
20 dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003.
22 dnl Macro to add for using GNU gettext.
24 dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]).
25 dnl INTLSYMBOL can be one of 'external', 'no-libtool', 'use-libtool'. The
26 dnl default (if it is not specified or empty) is 'no-libtool'.
27 dnl INTLSYMBOL should be 'external' for packages with no intl directory,
28 dnl and 'no-libtool' or 'use-libtool' for packages with an intl directory.
29 dnl If INTLSYMBOL is 'use-libtool', then a libtool library
30 dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static,
31 dnl depending on --{enable,disable}-{shared,static} and on the presence of
32 dnl AM-DISABLE-SHARED). If INTLSYMBOL is 'no-libtool', a static library
33 dnl $(top_builddir)/intl/libintl.a will be created.
34 dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
35 dnl implementations (in libc or libintl) without the ngettext() function
36 dnl will be ignored. If NEEDSYMBOL is specified and is
37 dnl 'need-formatstring-macros', then GNU gettext implementations that don't
38 dnl support the ISO C 99 <inttypes.h> formatstring macros will be ignored.
39 dnl INTLDIR is used to find the intl libraries. If empty,
40 dnl the value `$(top_builddir)/intl/' is used.
42 dnl The result of the configuration is one of three cases:
43 dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled
45 dnl Catalog format: GNU --> install in $(datadir)
46 dnl Catalog extension: .mo after installation, .gmo in source tree
47 dnl 2) GNU gettext has been found in the system's C library.
48 dnl Catalog format: GNU --> install in $(datadir)
49 dnl Catalog extension: .mo after installation, .gmo in source tree
50 dnl 3) No internationalization, always use English msgid.
51 dnl Catalog format: none
52 dnl Catalog extension: none
53 dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur.
54 dnl The use of .gmo is historical (it was needed to avoid overwriting the
55 dnl GNU format catalogs when building on a platform with an X/Open gettext),
56 dnl but we keep it in order not to force irrelevant filename changes on the
59 AC_DEFUN([AM_GNU_GETTEXT],
61 dnl Argument checking.
62 ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], ,
63 [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT
65 ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], ,
66 [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
68 define(gt_included_intl, ifelse([$1], [external], [no], [yes]))
69 define(gt_libtool_suffix_prefix, ifelse([$1], [use-libtool], [l], []))
71 AC_REQUIRE([AM_PO_SUBDIRS])dnl
72 # ifelse(gt_included_intl, yes, [
73 # AC_REQUIRE([AM_INTL_SUBDIR])dnl
76 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
77 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
78 AC_REQUIRE([AC_LIB_RPATH])
80 dnl Sometimes libintl requires libiconv, so first search for libiconv.
81 dnl Ideally we would do this search only after the
82 dnl if test "$USE_NLS" = "yes"; then
83 dnl if test "$gt_cv_func_gnugettext_libc" != "yes"; then
84 dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT
85 dnl the configure script would need to contain the same shell code
86 dnl again, outside any 'if'. There are two solutions:
87 dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'.
88 dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE.
89 dnl Since AC_PROVIDE_IFELSE is only in autoconf >= 2.52 and not
90 dnl documented, we avoid it.
91 ifelse(gt_included_intl, yes, , [
92 AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
98 ifelse(gt_included_intl, yes, [
99 BUILD_INCLUDED_LIBINTL=no
100 USE_INCLUDED_LIBINTL=no
106 dnl If we use NLS figure out what method
107 if test "$USE_NLS" = "yes"; then
108 gt_use_preinstalled_gnugettext=no
109 ifelse(gt_included_intl, yes, [
110 AC_MSG_CHECKING([whether included gettext is requested])
111 AC_ARG_WITH(included-gettext,
112 [ --with-included-gettext use the GNU gettext library included here],
113 nls_cv_force_use_gnu_gettext=$withval,
114 nls_cv_force_use_gnu_gettext=no)
115 AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
117 nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
118 if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
120 dnl User does not insist on using GNU NLS library. Figure out what
121 dnl to use. If GNU gettext is available we use this. Else we have
122 dnl to fall back to GNU NLS library.
124 dnl Add a version number to the cache macros.
125 define([gt_api_version], ifelse([$2], [need-formatstring-macros], 3, ifelse([$2], [need-ngettext], 2, 1)))
126 define([gt_cv_func_gnugettext_libc], [gt_cv_func_gnugettext]gt_api_version[_libc])
127 define([gt_cv_func_gnugettext_libintl], [gt_cv_func_gnugettext]gt_api_version[_libintl])
129 AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc,
130 [AC_TRY_LINK([#include <libintl.h>
131 ]ifelse([$2], [need-formatstring-macros],
132 [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
133 #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
136 typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
138 ], [])[extern int _nl_msg_cat_cntr;
139 extern int *_nl_domain_bindings;],
140 [bindtextdomain ("", "");
141 return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_domain_bindings],
142 gt_cv_func_gnugettext_libc=yes,
143 gt_cv_func_gnugettext_libc=no)])
145 if test "$gt_cv_func_gnugettext_libc" != "yes"; then
146 dnl Sometimes libintl requires libiconv, so first search for libiconv.
147 ifelse(gt_included_intl, yes, , [
150 dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
151 dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv])
152 dnl because that would add "-liconv" to LIBINTL and LTLIBINTL
153 dnl even if libiconv doesn't exist.
154 AC_LIB_LINKFLAGS_BODY([intl])
155 AC_CACHE_CHECK([for GNU gettext in libintl],
156 gt_cv_func_gnugettext_libintl,
157 [gt_save_CPPFLAGS="$CPPFLAGS"
158 CPPFLAGS="$CPPFLAGS $INCINTL"
160 LIBS="$LIBS $LIBINTL"
161 dnl Now see whether libintl exists and does not depend on libiconv.
162 AC_TRY_LINK([#include <libintl.h>
163 ]ifelse([$2], [need-formatstring-macros],
164 [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
165 #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
168 typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
170 ], [])[extern int _nl_msg_cat_cntr;
175 const char *_nl_expand_alias ();],
176 [bindtextdomain ("", "");
177 return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias (0)],
178 gt_cv_func_gnugettext_libintl=yes,
179 gt_cv_func_gnugettext_libintl=no)
180 dnl Now see whether libintl exists and depends on libiconv.
181 if test "$gt_cv_func_gnugettext_libintl" != yes && test -n "$LIBICONV"; then
182 LIBS="$LIBS $LIBICONV"
183 AC_TRY_LINK([#include <libintl.h>
184 ]ifelse([$2], [need-formatstring-macros],
185 [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
186 #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
189 typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
191 ], [])[extern int _nl_msg_cat_cntr;
196 const char *_nl_expand_alias ();],
197 [bindtextdomain ("", "");
198 return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias (0)],
199 [LIBINTL="$LIBINTL $LIBICONV"
200 LTLIBINTL="$LTLIBINTL $LTLIBICONV"
201 gt_cv_func_gnugettext_libintl=yes
204 CPPFLAGS="$gt_save_CPPFLAGS"
205 LIBS="$gt_save_LIBS"])
208 dnl If an already present or preinstalled GNU gettext() is found,
209 dnl use it. But if this macro is used in GNU gettext, and GNU
210 dnl gettext is already preinstalled in libintl, we update this
211 dnl libintl. (Cf. the install rule in intl/Makefile.in.)
212 if test "$gt_cv_func_gnugettext_libc" = "yes" \
213 || { test "$gt_cv_func_gnugettext_libintl" = "yes" \
214 && test "$PACKAGE" != gettext-runtime \
215 && test "$PACKAGE" != gettext-tools; }; then
216 gt_use_preinstalled_gnugettext=yes
218 dnl Reset the values set by searching for libintl.
224 ifelse(gt_included_intl, yes, [
225 if test "$gt_use_preinstalled_gnugettext" != "yes"; then
226 dnl GNU gettext is not found in the C library.
227 dnl Fall back on included GNU gettext library.
228 nls_cv_use_gnu_gettext=yes
232 if test "$nls_cv_use_gnu_gettext" = "yes"; then
233 dnl Mark actions used to generate GNU NLS library.
234 BUILD_INCLUDED_LIBINTL=yes
235 USE_INCLUDED_LIBINTL=yes
236 LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV"
237 LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV"
238 LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
241 if test "$gt_use_preinstalled_gnugettext" = "yes" \
242 || test "$nls_cv_use_gnu_gettext" = "yes"; then
243 dnl Mark actions to use GNU gettext tools.
248 if test "$gt_use_preinstalled_gnugettext" = "yes" \
249 || test "$nls_cv_use_gnu_gettext" = "yes"; then
250 AC_DEFINE(ENABLE_NLS, 1,
251 [Define to 1 if translation of program messages to the user's native language
258 AC_MSG_CHECKING([whether to use NLS])
259 AC_MSG_RESULT([$USE_NLS])
260 if test "$USE_NLS" = "yes"; then
261 AC_MSG_CHECKING([where the gettext function comes from])
262 if test "$gt_use_preinstalled_gnugettext" = "yes"; then
263 if test "$gt_cv_func_gnugettext_libintl" = "yes"; then
264 gt_source="external libintl"
269 gt_source="included intl directory"
271 AC_MSG_RESULT([$gt_source])
274 if test "$USE_NLS" = "yes"; then
276 if test "$gt_use_preinstalled_gnugettext" = "yes"; then
277 if test "$gt_cv_func_gnugettext_libintl" = "yes"; then
278 AC_MSG_CHECKING([how to link with libintl])
279 AC_MSG_RESULT([$LIBINTL])
280 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL])
283 dnl For backward compatibility. Some packages may be using this.
284 AC_DEFINE(HAVE_GETTEXT, 1,
285 [Define if the GNU gettext() function is already present or preinstalled.])
286 AC_DEFINE(HAVE_DCGETTEXT, 1,
287 [Define if the GNU dcgettext() function is already present or preinstalled.])
290 dnl We need to process the po/ directory.
294 ifelse(gt_included_intl, yes, [
295 dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL
296 dnl to 'yes' because some of the testsuite requires it.
297 if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then
298 BUILD_INCLUDED_LIBINTL=yes
301 dnl Make all variables we use known to autoconf.
302 AC_SUBST(BUILD_INCLUDED_LIBINTL)
303 AC_SUBST(USE_INCLUDED_LIBINTL)
306 dnl For backward compatibility. Some configure.ins may be using this.
310 dnl For backward compatibility. Some Makefiles may be using this.
312 AC_SUBST(DATADIRNAME)
314 dnl For backward compatibility. Some Makefiles may be using this.
318 dnl For backward compatibility. Some Makefiles may be using this.
322 dnl For backward compatibility. Some Makefiles may be using this.
323 if test "$USE_INCLUDED_LIBINTL" = yes; then
324 INTLOBJS="\$(GETTOBJS)"
328 dnl Enable libtool support if the surrounding package wishes it.
329 INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix
330 AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX)
333 dnl For backward compatibility. Some Makefiles may be using this.
337 dnl Make all documented variables known to autoconf.
344 dnl Checks for all prerequisites of the intl subdirectory,
345 dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS,
346 dnl USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL.
347 #AC_DEFUN([AM_INTL_SUBDIR],
349 # AC_REQUIRE([AC_PROG_INSTALL])dnl
350 # AC_REQUIRE([AM_MKINSTALLDIRS])dnl
351 # AC_REQUIRE([AC_PROG_CC])dnl
352 # AC_REQUIRE([AC_CANONICAL_HOST])dnl
353 # AC_REQUIRE([AC_PROG_RANLIB])dnl
354 # AC_REQUIRE([AC_ISC_POSIX])dnl
355 # AC_REQUIRE([AC_HEADER_STDC])dnl
356 # AC_REQUIRE([AC_C_CONST])dnl
357 # AC_REQUIRE([bh_C_SIGNED])dnl
358 # AC_REQUIRE([AC_C_INLINE])dnl
359 # AC_REQUIRE([AC_TYPE_OFF_T])dnl
360 # AC_REQUIRE([AC_TYPE_SIZE_T])dnl
361 # AC_REQUIRE([gl_AC_TYPE_LONG_LONG])dnl
362 # AC_REQUIRE([gt_TYPE_LONGDOUBLE])dnl
363 # AC_REQUIRE([gt_TYPE_WCHAR_T])dnl
364 # AC_REQUIRE([gt_TYPE_WINT_T])dnl
365 # AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
366 # AC_REQUIRE([gl_AC_HEADER_STDINT_H])
367 # AC_REQUIRE([gt_TYPE_INTMAX_T])
368 # AC_REQUIRE([gt_PRINTF_POSIX])
369 # AC_REQUIRE([AC_FUNC_ALLOCA])dnl
370 # AC_REQUIRE([AC_FUNC_MMAP])dnl
371 # AC_REQUIRE([gl_GLIBC21])dnl
372 # AC_REQUIRE([gt_INTDIV0])dnl
373 # AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])dnl
374 # AC_REQUIRE([gt_HEADER_INTTYPES_H])dnl
375 # AC_REQUIRE([gt_INTTYPES_PRI])dnl
376 # AC_REQUIRE([gl_XSIZE])dnl
378 # AC_CHECK_TYPE([ptrdiff_t], ,
379 # [AC_DEFINE([ptrdiff_t], [long],
380 # [Define as the type of the result of subtracting two pointers, if the system doesn't define it.])
382 # AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \
383 #stdlib.h string.h unistd.h sys/param.h])
384 # AC_CHECK_FUNCS([asprintf fwprintf getcwd getegid geteuid getgid getuid \
385 #mempcpy munmap putenv setenv setlocale snprintf stpcpy strcasecmp strdup \
386 #strtoul tsearch wcslen __argz_count __argz_stringify __argz_next \
389 # dnl Use the _snprintf function only if it is declared (because on NetBSD it
390 # dnl is defined as a weak alias of snprintf; we prefer to use the latter).
391 # gt_CHECK_DECL(_snprintf, [#include <stdio.h>])
392 # gt_CHECK_DECL(_snwprintf, [#include <stdio.h>])
394 # dnl Use the *_unlocked functions only if they are declared.
395 # dnl (because some of them were defined without being declared in Solaris
396 # dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built
397 # dnl on Solaris 2.5.1 to run on Solaris 2.6).
398 # dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13.
399 # gt_CHECK_DECL(feof_unlocked, [#include <stdio.h>])
400 # gt_CHECK_DECL(fgets_unlocked, [#include <stdio.h>])
401 # gt_CHECK_DECL(getc_unlocked, [#include <stdio.h>])
403 # case $gt_cv_func_printf_posix in
404 # *yes) HAVE_POSIX_PRINTF=1 ;;
405 # *) HAVE_POSIX_PRINTF=0 ;;
407 # AC_SUBST([HAVE_POSIX_PRINTF])
408 # if test "$ac_cv_func_asprintf" = yes; then
413 # AC_SUBST([HAVE_ASPRINTF])
414 # if test "$ac_cv_func_snprintf" = yes; then
419 # AC_SUBST([HAVE_SNPRINTF])
420 # if test "$ac_cv_func_wprintf" = yes; then
425 # AC_SUBST([HAVE_WPRINTF])
428 # AM_LANGINFO_CODESET
429 # if test $ac_cv_header_locale_h = yes; then
433 # dnl intl/plural.c is generated from intl/plural.y. It requires bison,
434 # dnl because plural.y uses bison specific features. It requires at least
435 # dnl bison-1.26 because earlier versions generate a plural.c that doesn't
437 # dnl bison is only needed for the maintainer (who touches plural.y). But in
438 # dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put
439 # dnl the rule in general Makefile. Now, some people carelessly touch the
440 # dnl files or have a broken "make" program, hence the plural.c rule will
441 # dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not
442 # dnl present or too old.
443 # AC_CHECK_PROGS([INTLBISON], [bison])
444 # if test -z "$INTLBISON"; then
447 # dnl Found it, now check the version.
448 # AC_MSG_CHECKING([version of bison])
449 #changequote(<<,>>)dnl
450 # ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'`
451 # case $ac_prog_version in
452 # '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
453 # 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*)
455 # ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
456 # *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
458 # AC_MSG_RESULT([$ac_prog_version])
460 # if test $ac_verc_fail = yes; then
466 dnl gt_CHECK_DECL(FUNC, INCLUDES)
467 dnl Check whether a function is declared.
468 AC_DEFUN([gt_CHECK_DECL],
470 AC_CACHE_CHECK([whether $1 is declared], ac_cv_have_decl_$1,
471 [AC_TRY_COMPILE([$2], [
473 char *p = (char *) $1;
475 ], ac_cv_have_decl_$1=yes, ac_cv_have_decl_$1=no)])
476 if test $ac_cv_have_decl_$1 = yes; then
481 AC_DEFINE_UNQUOTED([HAVE_DECL_]translit($1, [a-z], [A-Z]), [$gt_value],
482 [Define to 1 if you have the declaration of `$1', and to 0 if you don't.])
486 dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version])
487 AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])