gettext.m4 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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.in 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. ]ifelse([$2], [need-formatstring-macros],
  120. [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
  121. #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
  122. #endif
  123. changequote(,)dnl
  124. typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
  125. changequote([,])dnl
  126. ], [])[extern int _nl_msg_cat_cntr;
  127. extern int *_nl_domain_bindings;],
  128. [bindtextdomain ("", "");
  129. return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_domain_bindings],
  130. gt_cv_func_gnugettext_libc=yes,
  131. gt_cv_func_gnugettext_libc=no)])
  132. if test "$gt_cv_func_gnugettext_libc" != "yes"; then
  133. dnl Sometimes libintl requires libiconv, so first search for libiconv.
  134. ifelse(gt_included_intl, yes, , [
  135. AM_ICONV_LINK
  136. ])
  137. dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
  138. dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv])
  139. dnl because that would add "-liconv" to LIBINTL and LTLIBINTL
  140. dnl even if libiconv doesn't exist.
  141. AC_LIB_LINKFLAGS_BODY([intl])
  142. AC_CACHE_CHECK([for GNU gettext in libintl],
  143. gt_cv_func_gnugettext_libintl,
  144. [gt_save_CPPFLAGS="$CPPFLAGS"
  145. CPPFLAGS="$CPPFLAGS $INCINTL"
  146. gt_save_LIBS="$LIBS"
  147. LIBS="$LIBS $LIBINTL"
  148. dnl Now see whether libintl exists and does not depend on libiconv.
  149. AC_TRY_LINK([#include <libintl.h>
  150. ]ifelse([$2], [need-formatstring-macros],
  151. [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
  152. #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
  153. #endif
  154. changequote(,)dnl
  155. typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
  156. changequote([,])dnl
  157. ], [])[extern int _nl_msg_cat_cntr;
  158. extern
  159. #ifdef __cplusplus
  160. "C"
  161. #endif
  162. const char *_nl_expand_alias ();],
  163. [bindtextdomain ("", "");
  164. return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias (0)],
  165. gt_cv_func_gnugettext_libintl=yes,
  166. gt_cv_func_gnugettext_libintl=no)
  167. dnl Now see whether libintl exists and depends on libiconv.
  168. if test "$gt_cv_func_gnugettext_libintl" != yes && test -n "$LIBICONV"; then
  169. LIBS="$LIBS $LIBICONV"
  170. AC_TRY_LINK([#include <libintl.h>
  171. ]ifelse([$2], [need-formatstring-macros],
  172. [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
  173. #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
  174. #endif
  175. changequote(,)dnl
  176. typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
  177. changequote([,])dnl
  178. ], [])[extern int _nl_msg_cat_cntr;
  179. extern
  180. #ifdef __cplusplus
  181. "C"
  182. #endif
  183. const char *_nl_expand_alias ();],
  184. [bindtextdomain ("", "");
  185. return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias (0)],
  186. [LIBINTL="$LIBINTL $LIBICONV"
  187. LTLIBINTL="$LTLIBINTL $LTLIBICONV"
  188. gt_cv_func_gnugettext_libintl=yes
  189. ])
  190. fi
  191. CPPFLAGS="$gt_save_CPPFLAGS"
  192. LIBS="$gt_save_LIBS"])
  193. fi
  194. dnl If an already present or preinstalled GNU gettext() is found,
  195. dnl use it. But if this macro is used in GNU gettext, and GNU
  196. dnl gettext is already preinstalled in libintl, we update this
  197. dnl libintl. (Cf. the install rule in intl/Makefile.in.)
  198. if test "$gt_cv_func_gnugettext_libc" = "yes" \
  199. || { test "$gt_cv_func_gnugettext_libintl" = "yes" \
  200. && test "$PACKAGE" != gettext-runtime \
  201. && test "$PACKAGE" != gettext-tools; }; then
  202. gt_use_preinstalled_gnugettext=yes
  203. else
  204. dnl Reset the values set by searching for libintl.
  205. LIBINTL=
  206. LTLIBINTL=
  207. INCINTL=
  208. fi
  209. ifelse(gt_included_intl, yes, [
  210. if test "$gt_use_preinstalled_gnugettext" != "yes"; then
  211. dnl GNU gettext is not found in the C library.
  212. dnl Fall back on included GNU gettext library.
  213. nls_cv_use_gnu_gettext=yes
  214. fi
  215. fi
  216. if test "$nls_cv_use_gnu_gettext" = "yes"; then
  217. dnl Mark actions used to generate GNU NLS library.
  218. BUILD_INCLUDED_LIBINTL=yes
  219. USE_INCLUDED_LIBINTL=yes
  220. LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV"
  221. LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV"
  222. LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
  223. fi
  224. if test "$gt_use_preinstalled_gnugettext" = "yes" \
  225. || test "$nls_cv_use_gnu_gettext" = "yes"; then
  226. dnl Mark actions to use GNU gettext tools.
  227. CATOBJEXT=.gmo
  228. fi
  229. ])
  230. if test "$gt_use_preinstalled_gnugettext" = "yes" \
  231. || test "$nls_cv_use_gnu_gettext" = "yes"; then
  232. AC_DEFINE(ENABLE_NLS, 1,
  233. [Define to 1 if translation of program messages to the user's native language
  234. is requested.])
  235. else
  236. USE_NLS=no
  237. fi
  238. fi
  239. AC_MSG_CHECKING([whether to use NLS])
  240. AC_MSG_RESULT([$USE_NLS])
  241. if test "$USE_NLS" = "yes"; then
  242. AC_MSG_CHECKING([where the gettext function comes from])
  243. if test "$gt_use_preinstalled_gnugettext" = "yes"; then
  244. if test "$gt_cv_func_gnugettext_libintl" = "yes"; then
  245. gt_source="external libintl"
  246. else
  247. gt_source="libc"
  248. fi
  249. else
  250. gt_source="included intl directory"
  251. fi
  252. AC_MSG_RESULT([$gt_source])
  253. fi
  254. if test "$USE_NLS" = "yes"; then
  255. if test "$gt_use_preinstalled_gnugettext" = "yes"; then
  256. if test "$gt_cv_func_gnugettext_libintl" = "yes"; then
  257. AC_MSG_CHECKING([how to link with libintl])
  258. AC_MSG_RESULT([$LIBINTL])
  259. AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL])
  260. fi
  261. dnl For backward compatibility. Some packages may be using this.
  262. AC_DEFINE(HAVE_GETTEXT, 1,
  263. [Define if the GNU gettext() function is already present or preinstalled.])
  264. AC_DEFINE(HAVE_DCGETTEXT, 1,
  265. [Define if the GNU dcgettext() function is already present or preinstalled.])
  266. fi
  267. dnl We need to process the po/ directory.
  268. POSUB=po
  269. fi
  270. ifelse(gt_included_intl, yes, [
  271. dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL
  272. dnl to 'yes' because some of the testsuite requires it.
  273. if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then
  274. BUILD_INCLUDED_LIBINTL=yes
  275. fi
  276. dnl Make all variables we use known to autoconf.
  277. AC_SUBST(BUILD_INCLUDED_LIBINTL)
  278. AC_SUBST(USE_INCLUDED_LIBINTL)
  279. AC_SUBST(CATOBJEXT)
  280. dnl For backward compatibility. Some configure.ins may be using this.
  281. nls_cv_header_intl=
  282. nls_cv_header_libgt=
  283. dnl For backward compatibility. Some Makefiles may be using this.
  284. DATADIRNAME=share
  285. AC_SUBST(DATADIRNAME)
  286. dnl For backward compatibility. Some Makefiles may be using this.
  287. INSTOBJEXT=.mo
  288. AC_SUBST(INSTOBJEXT)
  289. dnl For backward compatibility. Some Makefiles may be using this.
  290. GENCAT=gencat
  291. AC_SUBST(GENCAT)
  292. dnl For backward compatibility. Some Makefiles may be using this.
  293. if test "$USE_INCLUDED_LIBINTL" = yes; then
  294. INTLOBJS="\$(GETTOBJS)"
  295. fi
  296. AC_SUBST(INTLOBJS)
  297. dnl Enable libtool support if the surrounding package wishes it.
  298. INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix
  299. AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX)
  300. ])
  301. dnl For backward compatibility. Some Makefiles may be using this.
  302. INTLLIBS="$LIBINTL"
  303. AC_SUBST(INTLLIBS)
  304. dnl Make all documented variables known to autoconf.
  305. AC_SUBST(LIBINTL)
  306. AC_SUBST(LTLIBINTL)
  307. AC_SUBST(POSUB)
  308. ])
  309. dnl Checks for all prerequisites of the intl subdirectory,
  310. dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS,
  311. dnl USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL.
  312. AC_DEFUN([AM_INTL_SUBDIR],
  313. [
  314. AC_REQUIRE([AC_PROG_INSTALL])dnl
  315. AC_REQUIRE([AM_MKINSTALLDIRS])dnl
  316. AC_REQUIRE([AC_PROG_CC])dnl
  317. AC_REQUIRE([AC_CANONICAL_HOST])dnl
  318. AC_REQUIRE([AC_PROG_RANLIB])dnl
  319. AC_REQUIRE([AC_ISC_POSIX])dnl
  320. AC_REQUIRE([AC_HEADER_STDC])dnl
  321. AC_REQUIRE([AC_C_CONST])dnl
  322. AC_REQUIRE([AC_C_INLINE])dnl
  323. AC_REQUIRE([AC_TYPE_OFF_T])dnl
  324. AC_REQUIRE([AC_TYPE_SIZE_T])dnl
  325. AC_REQUIRE([AC_FUNC_ALLOCA])dnl
  326. AC_REQUIRE([AC_FUNC_MMAP])dnl
  327. AC_REQUIRE([jm_GLIBC21])dnl
  328. AC_REQUIRE([gt_INTDIV0])dnl
  329. AC_REQUIRE([jm_AC_TYPE_UINTMAX_T])dnl
  330. AC_REQUIRE([gt_HEADER_INTTYPES_H])dnl
  331. AC_REQUIRE([gt_INTTYPES_PRI])dnl
  332. AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \
  333. stdlib.h string.h unistd.h sys/param.h])
  334. AC_CHECK_FUNCS([feof_unlocked fgets_unlocked getc_unlocked getcwd getegid \
  335. geteuid getgid getuid mempcpy munmap putenv setenv setlocale stpcpy \
  336. strcasecmp strdup strtoul tsearch __argz_count __argz_stringify __argz_next \
  337. __fsetlocking])
  338. AM_ICONV
  339. AM_LANGINFO_CODESET
  340. if test $ac_cv_header_locale_h = yes; then
  341. AM_LC_MESSAGES
  342. fi
  343. dnl intl/plural.c is generated from intl/plural.y. It requires bison,
  344. dnl because plural.y uses bison specific features. It requires at least
  345. dnl bison-1.26 because earlier versions generate a plural.c that doesn't
  346. dnl compile.
  347. dnl bison is only needed for the maintainer (who touches plural.y). But in
  348. dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put
  349. dnl the rule in general Makefile. Now, some people carelessly touch the
  350. dnl files or have a broken "make" program, hence the plural.c rule will
  351. dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not
  352. dnl present or too old.
  353. AC_CHECK_PROGS([INTLBISON], [bison])
  354. if test -z "$INTLBISON"; then
  355. ac_verc_fail=yes
  356. else
  357. dnl Found it, now check the version.
  358. AC_MSG_CHECKING([version of bison])
  359. changequote(<<,>>)dnl
  360. ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'`
  361. case $ac_prog_version in
  362. '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
  363. 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*)
  364. changequote([,])dnl
  365. ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
  366. *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
  367. esac
  368. AC_MSG_RESULT([$ac_prog_version])
  369. fi
  370. if test $ac_verc_fail = yes; then
  371. INTLBISON=:
  372. fi
  373. ])
  374. dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version])
  375. AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])