gettext.m4 17 KB

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