1# gettext.m4 serial 20 (gettext-0.12) 2dnl Copyright (C) 1995-2003 Free Software Foundation, Inc. 3dnl This file is free software, distributed under the terms of the GNU 4dnl General Public License. As a special exception to the GNU General 5dnl Public License, this file may be distributed as part of a program 6dnl that contains a configuration script generated by Autoconf, under 7dnl the same distribution terms as the rest of that program. 8dnl 9dnl This file can can be used in projects which are not available under 10dnl the GNU General Public License or the GNU Library General Public 11dnl License but which still want to provide support for the GNU gettext 12dnl functionality. 13dnl Please note that the actual code of the GNU gettext library is covered 14dnl by the GNU Library General Public License, and the rest of the GNU 15dnl gettext package package is covered by the GNU General Public License. 16dnl They are *not* in the public domain. 17 18dnl Authors: 19dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000. 20dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003. 21 22dnl Macro to add for using GNU gettext. 23 24dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]). 25dnl INTLSYMBOL can be one of 'external', 'no-libtool', 'use-libtool'. The 26dnl default (if it is not specified or empty) is 'no-libtool'. 27dnl INTLSYMBOL should be 'external' for packages with no intl directory, 28dnl and 'no-libtool' or 'use-libtool' for packages with an intl directory. 29dnl If INTLSYMBOL is 'use-libtool', then a libtool library 30dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static, 31dnl depending on --{enable,disable}-{shared,static} and on the presence of 32dnl AM-DISABLE-SHARED). If INTLSYMBOL is 'no-libtool', a static library 33dnl $(top_builddir)/intl/libintl.a will be created. 34dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext 35dnl implementations (in libc or libintl) without the ngettext() function 36dnl will be ignored. If NEEDSYMBOL is specified and is 37dnl 'need-formatstring-macros', then GNU gettext implementations that don't 38dnl support the ISO C 99 <inttypes.h> formatstring macros will be ignored. 39dnl INTLDIR is used to find the intl libraries. If empty, 40dnl the value `$(top_builddir)/intl/' is used. 41dnl 42dnl The result of the configuration is one of three cases: 43dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled 44dnl and used. 45dnl Catalog format: GNU --> install in $(datadir) 46dnl Catalog extension: .mo after installation, .gmo in source tree 47dnl 2) GNU gettext has been found in the system's C library. 48dnl Catalog format: GNU --> install in $(datadir) 49dnl Catalog extension: .mo after installation, .gmo in source tree 50dnl 3) No internationalization, always use English msgid. 51dnl Catalog format: none 52dnl Catalog extension: none 53dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur. 54dnl The use of .gmo is historical (it was needed to avoid overwriting the 55dnl GNU format catalogs when building on a platform with an X/Open gettext), 56dnl but we keep it in order not to force irrelevant filename changes on the 57dnl maintainers. 58dnl 59AC_DEFUN([AM_GNU_GETTEXT], 60[ 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 64])])])])]) 65 ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], , 66 [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT 67])])])]) 68 define(gt_included_intl, ifelse([$1], [external], [no], [yes])) 69 define(gt_libtool_suffix_prefix, ifelse([$1], [use-libtool], [l], [])) 70 71 AC_REQUIRE([AM_PO_SUBDIRS])dnl 72 ifelse(gt_included_intl, yes, [ 73 AC_REQUIRE([AM_INTL_SUBDIR])dnl 74 ]) 75 76 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY. 77 AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 78 AC_REQUIRE([AC_LIB_RPATH]) 79 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.ac 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]) 93 ]) 94 95 dnl Set USE_NLS. 96 AM_NLS 97 98 ifelse(gt_included_intl, yes, [ 99 BUILD_INCLUDED_LIBINTL=no 100 USE_INCLUDED_LIBINTL=no 101 ]) 102 LIBINTL= 103 LTLIBINTL= 104 POSUB= 105 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) 116 117 nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext" 118 if test "$nls_cv_force_use_gnu_gettext" != "yes"; then 119 ]) 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. 123 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]) 128 129 AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc, 130 [AC_TRY_LINK([#include <libintl.h> 131#ifndef __GNU_GETTEXT_SUPPORTED_REVISION 132extern int _nl_msg_cat_cntr; 133extern int *_nl_domain_bindings; 134#define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_domain_bindings) 135#else 136#define __GNU_GETTEXT_SYMBOL_EXPRESSION 0 137#endif 138]ifelse([$2], [need-formatstring-macros], 139[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION 140#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) 141#endif 142changequote(,)dnl 143typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; 144changequote([,])dnl 145], []), 146 [bindtextdomain ("", ""); 147return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + __GNU_GETTEXT_SYMBOL_EXPRESSION], 148 gt_cv_func_gnugettext_libc=yes, 149 gt_cv_func_gnugettext_libc=no)]) 150 151 if test "$gt_cv_func_gnugettext_libc" != "yes"; then 152 dnl Sometimes libintl requires libiconv, so first search for libiconv. 153 ifelse(gt_included_intl, yes, , [ 154 AM_ICONV_LINK 155 ]) 156 dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL 157 dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv]) 158 dnl because that would add "-liconv" to LIBINTL and LTLIBINTL 159 dnl even if libiconv doesn't exist. 160 AC_LIB_LINKFLAGS_BODY([intl]) 161 AC_CACHE_CHECK([for GNU gettext in libintl], 162 gt_cv_func_gnugettext_libintl, 163 [gt_save_CPPFLAGS="$CPPFLAGS" 164 CPPFLAGS="$CPPFLAGS $INCINTL" 165 gt_save_LIBS="$LIBS" 166 LIBS="$LIBS $LIBINTL" 167 dnl Now see whether libintl exists and does not depend on libiconv. 168 AC_TRY_LINK([#include <libintl.h> 169#ifndef __GNU_GETTEXT_SUPPORTED_REVISION 170extern int _nl_msg_cat_cntr; 171extern 172#ifdef __cplusplus 173"C" 174#endif 175const char *_nl_expand_alias (); 176#define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_expand_alias (0)) 177#else 178#define __GNU_GETTEXT_SYMBOL_EXPRESSION 0 179#endif 180]ifelse([$2], [need-formatstring-macros], 181[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION 182#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) 183#endif 184changequote(,)dnl 185typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; 186changequote([,])dnl 187], []), 188 [bindtextdomain ("", ""); 189return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + __GNU_GETTEXT_SYMBOL_EXPRESSION], 190 gt_cv_func_gnugettext_libintl=yes, 191 gt_cv_func_gnugettext_libintl=no) 192 dnl Now see whether libintl exists and depends on libiconv. 193 if test "$gt_cv_func_gnugettext_libintl" != yes && test -n "$LIBICONV"; then 194 LIBS="$LIBS $LIBICONV" 195 AC_TRY_LINK([#include <libintl.h> 196#ifndef __GNU_GETTEXT_SUPPORTED_REVISION 197extern int _nl_msg_cat_cntr; 198extern 199#ifdef __cplusplus 200"C" 201#endif 202const char *_nl_expand_alias (); 203#define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_expand_alias (0)) 204#else 205#define __GNU_GETTEXT_SYMBOL_EXPRESSION 0 206#endif 207]ifelse([$2], [need-formatstring-macros], 208[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION 209#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) 210#endif 211changequote(,)dnl 212typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; 213changequote([,])dnl 214], []), 215 [bindtextdomain ("", ""); 216return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + __GNU_GETTEXT_SYMBOL_EXPRESSION], 217 [LIBINTL="$LIBINTL $LIBICONV" 218 LTLIBINTL="$LTLIBINTL $LTLIBICONV" 219 gt_cv_func_gnugettext_libintl=yes 220 ]) 221 fi 222 CPPFLAGS="$gt_save_CPPFLAGS" 223 LIBS="$gt_save_LIBS"]) 224 fi 225 226 dnl If an already present or preinstalled GNU gettext() is found, 227 dnl use it. But if this macro is used in GNU gettext, and GNU 228 dnl gettext is already preinstalled in libintl, we update this 229 dnl libintl. (Cf. the install rule in intl/Makefile.in.) 230 if test "$gt_cv_func_gnugettext_libc" = "yes" \ 231 || { test "$gt_cv_func_gnugettext_libintl" = "yes" \ 232 && test "$PACKAGE" != gettext-runtime \ 233 && test "$PACKAGE" != gettext-tools; }; then 234 gt_use_preinstalled_gnugettext=yes 235 else 236 dnl Reset the values set by searching for libintl. 237 LIBINTL= 238 LTLIBINTL= 239 INCINTL= 240 fi 241 242 ifelse(gt_included_intl, yes, [ 243 if test "$gt_use_preinstalled_gnugettext" != "yes"; then 244 dnl GNU gettext is not found in the C library. 245 dnl Fall back on included GNU gettext library. 246 nls_cv_use_gnu_gettext=yes 247 fi 248 fi 249 250 if test "$nls_cv_use_gnu_gettext" = "yes"; then 251 dnl Mark actions used to generate GNU NLS library. 252 BUILD_INCLUDED_LIBINTL=yes 253 USE_INCLUDED_LIBINTL=yes 254 LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV" 255 LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV" 256 LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'` 257 fi 258 259 if test "$gt_use_preinstalled_gnugettext" = "yes" \ 260 || test "$nls_cv_use_gnu_gettext" = "yes"; then 261 dnl Mark actions to use GNU gettext tools. 262 CATOBJEXT=.gmo 263 fi 264 ]) 265 266 if test "$gt_use_preinstalled_gnugettext" = "yes" \ 267 || test "$nls_cv_use_gnu_gettext" = "yes"; then 268 AC_DEFINE(ENABLE_NLS, 1, 269 [Define to 1 if translation of program messages to the user's native language 270 is requested.]) 271 else 272 USE_NLS=no 273 fi 274 fi 275 276 AC_MSG_CHECKING([whether to use NLS]) 277 AC_MSG_RESULT([$USE_NLS]) 278 if test "$USE_NLS" = "yes"; then 279 AC_MSG_CHECKING([where the gettext function comes from]) 280 if test "$gt_use_preinstalled_gnugettext" = "yes"; then 281 if test "$gt_cv_func_gnugettext_libintl" = "yes"; then 282 gt_source="external libintl" 283 else 284 gt_source="libc" 285 fi 286 else 287 gt_source="included intl directory" 288 fi 289 AC_MSG_RESULT([$gt_source]) 290 fi 291 292 if test "$USE_NLS" = "yes"; then 293 294 if test "$gt_use_preinstalled_gnugettext" = "yes"; then 295 if test "$gt_cv_func_gnugettext_libintl" = "yes"; then 296 AC_MSG_CHECKING([how to link with libintl]) 297 AC_MSG_RESULT([$LIBINTL]) 298 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL]) 299 fi 300 301 dnl For backward compatibility. Some packages may be using this. 302 AC_DEFINE(HAVE_GETTEXT, 1, 303 [Define if the GNU gettext() function is already present or preinstalled.]) 304 AC_DEFINE(HAVE_DCGETTEXT, 1, 305 [Define if the GNU dcgettext() function is already present or preinstalled.]) 306 fi 307 308 dnl We need to process the po/ directory. 309 POSUB=po 310 fi 311 312 ifelse(gt_included_intl, yes, [ 313 dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL 314 dnl to 'yes' because some of the testsuite requires it. 315 if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then 316 BUILD_INCLUDED_LIBINTL=yes 317 fi 318 319 dnl Make all variables we use known to autoconf. 320 AC_SUBST(BUILD_INCLUDED_LIBINTL) 321 AC_SUBST(USE_INCLUDED_LIBINTL) 322 AC_SUBST(CATOBJEXT) 323 324 dnl For backward compatibility. Some configure.acs may be using this. 325 nls_cv_header_intl= 326 nls_cv_header_libgt= 327 328 dnl For backward compatibility. Some Makefiles may be using this. 329 DATADIRNAME=share 330 AC_SUBST(DATADIRNAME) 331 332 dnl For backward compatibility. Some Makefiles may be using this. 333 INSTOBJEXT=.mo 334 AC_SUBST(INSTOBJEXT) 335 336 dnl For backward compatibility. Some Makefiles may be using this. 337 GENCAT=gencat 338 AC_SUBST(GENCAT) 339 340 dnl For backward compatibility. Some Makefiles may be using this. 341 if test "$USE_INCLUDED_LIBINTL" = yes; then 342 INTLOBJS="\$(GETTOBJS)" 343 fi 344 AC_SUBST(INTLOBJS) 345 346 dnl Enable libtool support if the surrounding package wishes it. 347 INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix 348 AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX) 349 ]) 350 351 dnl For backward compatibility. Some Makefiles may be using this. 352 INTLLIBS="$LIBINTL" 353 AC_SUBST(INTLLIBS) 354 355 dnl Make all documented variables known to autoconf. 356 AC_SUBST(LIBINTL) 357 AC_SUBST(LTLIBINTL) 358 AC_SUBST(POSUB) 359]) 360 361 362dnl Checks for all prerequisites of the intl subdirectory, 363dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS, 364dnl USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL. 365AC_DEFUN([AM_INTL_SUBDIR], 366[ 367 AC_REQUIRE([AC_PROG_INSTALL])dnl 368 AC_REQUIRE([AM_MKINSTALLDIRS])dnl 369 AC_REQUIRE([AC_PROG_CC])dnl 370 AC_REQUIRE([AC_CANONICAL_HOST])dnl 371 AC_REQUIRE([AC_PROG_RANLIB])dnl 372 AC_REQUIRE([AC_ISC_POSIX])dnl 373 AC_REQUIRE([AC_HEADER_STDC])dnl 374 AC_REQUIRE([AC_C_CONST])dnl 375 AC_REQUIRE([AC_C_INLINE])dnl 376 AC_REQUIRE([AC_TYPE_OFF_T])dnl 377 AC_REQUIRE([AC_TYPE_SIZE_T])dnl 378 AC_REQUIRE([AC_FUNC_ALLOCA])dnl 379 AC_REQUIRE([AC_FUNC_MMAP])dnl 380 AC_REQUIRE([jm_GLIBC21])dnl 381 AC_REQUIRE([gt_INTDIV0])dnl 382 AC_REQUIRE([jm_AC_TYPE_UINTMAX_T])dnl 383 AC_REQUIRE([gt_HEADER_INTTYPES_H])dnl 384 AC_REQUIRE([gt_INTTYPES_PRI])dnl 385 386 AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \ 387stdlib.h string.h unistd.h sys/param.h]) 388 AC_CHECK_FUNCS([feof_unlocked fgets_unlocked getc_unlocked getcwd getegid \ 389geteuid getgid getuid mempcpy munmap putenv setenv setlocale stpcpy \ 390strcasecmp strdup strtoul tsearch __argz_count __argz_stringify __argz_next \ 391__fsetlocking]) 392 393 AM_ICONV 394 AM_LANGINFO_CODESET 395 if test $ac_cv_header_locale_h = yes; then 396 AM_LC_MESSAGES 397 fi 398 399 dnl intl/plural.c is generated from intl/plural.y. It requires bison, 400 dnl because plural.y uses bison specific features. It requires at least 401 dnl bison-1.26 because earlier versions generate a plural.c that doesn't 402 dnl compile. 403 dnl bison is only needed for the maintainer (who touches plural.y). But in 404 dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put 405 dnl the rule in general Makefile. Now, some people carelessly touch the 406 dnl files or have a broken "make" program, hence the plural.c rule will 407 dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not 408 dnl present or too old. 409 AC_CHECK_PROGS([INTLBISON], [bison]) 410 if test -z "$INTLBISON"; then 411 ac_verc_fail=yes 412 else 413 dnl Found it, now check the version. 414 AC_MSG_CHECKING([version of bison]) 415changequote(<<,>>)dnl 416 ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'` 417 case $ac_prog_version in 418 '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; 419 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*) 420changequote([,])dnl 421 ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; 422 *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;; 423 esac 424 AC_MSG_RESULT([$ac_prog_version]) 425 fi 426 if test $ac_verc_fail = yes; then 427 INTLBISON=: 428 fi 429]) 430 431 432dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version]) 433AC_DEFUN([AM_GNU_GETTEXT_VERSION], []) 434