gettext.m4 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. # gettext.m4 serial 71 (gettext-0.20.2)
  2. dnl Copyright (C) 1995-2014, 2016, 2018-2021 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. dnl
  7. dnl This file can be used in projects which are not available under
  8. dnl the GNU General Public License or the GNU Lesser General Public
  9. dnl License but which still want to provide support for the GNU gettext
  10. dnl functionality.
  11. dnl Please note that the actual code of the GNU gettext library is covered
  12. dnl by the GNU Lesser General Public License, and the rest of the GNU
  13. dnl gettext package is covered by the GNU General Public License.
  14. dnl They are *not* in the public domain.
  15. dnl Authors:
  16. dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
  17. dnl Bruno Haible <haible@clisp.cons.org>, 2000-2006, 2008-2010.
  18. dnl Macro to add for using GNU gettext.
  19. dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]).
  20. dnl INTLSYMBOL must be one of 'external', 'use-libtool'.
  21. dnl INTLSYMBOL should be 'external' for packages other than GNU gettext, and
  22. dnl 'use-libtool' for the packages 'gettext-runtime' and 'gettext-tools'.
  23. dnl If INTLSYMBOL is 'use-libtool', then a libtool library
  24. dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static,
  25. dnl depending on --{enable,disable}-{shared,static} and on the presence of
  26. dnl AM-DISABLE-SHARED).
  27. dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
  28. dnl implementations (in libc or libintl) without the ngettext() function
  29. dnl will be ignored. If NEEDSYMBOL is specified and is
  30. dnl 'need-formatstring-macros', then GNU gettext implementations that don't
  31. dnl support the ISO C 99 <inttypes.h> formatstring macros will be ignored.
  32. dnl INTLDIR is used to find the intl libraries. If empty,
  33. dnl the value '$(top_builddir)/intl/' is used.
  34. dnl
  35. dnl The result of the configuration is one of three cases:
  36. dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled
  37. dnl and used.
  38. dnl Catalog format: GNU --> install in $(datadir)
  39. dnl Catalog extension: .mo after installation, .gmo in source tree
  40. dnl 2) GNU gettext has been found in the system's C library.
  41. dnl Catalog format: GNU --> install in $(datadir)
  42. dnl Catalog extension: .mo after installation, .gmo in source tree
  43. dnl 3) No internationalization, always use English msgid.
  44. dnl Catalog format: none
  45. dnl Catalog extension: none
  46. dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur.
  47. dnl The use of .gmo is historical (it was needed to avoid overwriting the
  48. dnl GNU format catalogs when building on a platform with an X/Open gettext),
  49. dnl but we keep it in order not to force irrelevant filename changes on the
  50. dnl maintainers.
  51. dnl
  52. AC_DEFUN([AM_GNU_GETTEXT],
  53. [
  54. dnl Argument checking.
  55. ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [use-libtool], ,
  56. [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT
  57. ])])])])
  58. ifelse(ifelse([$1], [], [old])[]ifelse([$1], [no-libtool], [old]), [old],
  59. [errprint([ERROR: Use of AM_GNU_GETTEXT without [external] argument is no longer supported.
  60. ])])
  61. ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], ,
  62. [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
  63. ])])])])
  64. define([gt_included_intl],
  65. ifelse([$1], [external], [no], [yes]))
  66. gt_NEEDS_INIT
  67. AM_GNU_GETTEXT_NEED([$2])
  68. AC_REQUIRE([AM_PO_SUBDIRS])dnl
  69. ifelse(gt_included_intl, yes, [
  70. AC_REQUIRE([AM_INTL_SUBDIR])dnl
  71. ])
  72. dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
  73. AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
  74. AC_REQUIRE([AC_LIB_RPATH])
  75. dnl Sometimes libintl requires libiconv, so first search for libiconv.
  76. dnl Ideally we would do this search only after the
  77. dnl if test "$USE_NLS" = "yes"; then
  78. dnl if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
  79. dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT
  80. dnl the configure script would need to contain the same shell code
  81. dnl again, outside any 'if'. There are two solutions:
  82. dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'.
  83. dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE.
  84. dnl Since AC_PROVIDE_IFELSE is not documented, we avoid it.
  85. ifelse(gt_included_intl, yes, , [
  86. AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
  87. ])
  88. dnl Sometimes, on Mac OS X, libintl requires linking with CoreFoundation.
  89. gt_INTL_MACOSX
  90. dnl Set USE_NLS.
  91. AC_REQUIRE([AM_NLS])
  92. ifelse(gt_included_intl, yes, [
  93. BUILD_INCLUDED_LIBINTL=no
  94. USE_INCLUDED_LIBINTL=no
  95. ])
  96. LIBINTL=
  97. LTLIBINTL=
  98. POSUB=
  99. dnl Add a version number to the cache macros.
  100. case " $gt_needs " in
  101. *" need-formatstring-macros "*) gt_api_version=3 ;;
  102. *" need-ngettext "*) gt_api_version=2 ;;
  103. *) gt_api_version=1 ;;
  104. esac
  105. gt_func_gnugettext_libc="gt_cv_func_gnugettext${gt_api_version}_libc"
  106. gt_func_gnugettext_libintl="gt_cv_func_gnugettext${gt_api_version}_libintl"
  107. dnl If we use NLS figure out what method
  108. if test "$USE_NLS" = "yes"; then
  109. gt_use_preinstalled_gnugettext=no
  110. ifelse(gt_included_intl, yes, [
  111. AC_MSG_CHECKING([whether included gettext is requested])
  112. AC_ARG_WITH([included-gettext],
  113. [ --with-included-gettext use the GNU gettext library included here],
  114. nls_cv_force_use_gnu_gettext=$withval,
  115. nls_cv_force_use_gnu_gettext=no)
  116. 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
  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. if test $gt_api_version -ge 3; then
  124. gt_revision_test_code='
  125. #ifndef __GNU_GETTEXT_SUPPORTED_REVISION
  126. #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
  127. #endif
  128. changequote(,)dnl
  129. typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
  130. changequote([,])dnl
  131. '
  132. else
  133. gt_revision_test_code=
  134. fi
  135. if test $gt_api_version -ge 2; then
  136. gt_expression_test_code=' + * ngettext ("", "", 0)'
  137. else
  138. gt_expression_test_code=
  139. fi
  140. AC_CACHE_CHECK([for GNU gettext in libc], [$gt_func_gnugettext_libc],
  141. [AC_LINK_IFELSE(
  142. [AC_LANG_PROGRAM(
  143. [[
  144. #include <libintl.h>
  145. #ifndef __GNU_GETTEXT_SUPPORTED_REVISION
  146. extern int _nl_msg_cat_cntr;
  147. extern int *_nl_domain_bindings;
  148. #define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_domain_bindings)
  149. #else
  150. #define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
  151. #endif
  152. $gt_revision_test_code
  153. ]],
  154. [[
  155. bindtextdomain ("", "");
  156. return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
  157. ]])],
  158. [eval "$gt_func_gnugettext_libc=yes"],
  159. [eval "$gt_func_gnugettext_libc=no"])])
  160. if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
  161. dnl Sometimes libintl requires libiconv, so first search for libiconv.
  162. ifelse(gt_included_intl, yes, , [
  163. AM_ICONV_LINK
  164. ])
  165. dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
  166. dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv])
  167. dnl because that would add "-liconv" to LIBINTL and LTLIBINTL
  168. dnl even if libiconv doesn't exist.
  169. AC_LIB_LINKFLAGS_BODY([intl])
  170. AC_CACHE_CHECK([for GNU gettext in libintl],
  171. [$gt_func_gnugettext_libintl],
  172. [gt_save_CPPFLAGS="$CPPFLAGS"
  173. CPPFLAGS="$CPPFLAGS $INCINTL"
  174. gt_save_LIBS="$LIBS"
  175. LIBS="$LIBS $LIBINTL"
  176. dnl Now see whether libintl exists and does not depend on libiconv.
  177. AC_LINK_IFELSE(
  178. [AC_LANG_PROGRAM(
  179. [[
  180. #include <libintl.h>
  181. #ifndef __GNU_GETTEXT_SUPPORTED_REVISION
  182. extern int _nl_msg_cat_cntr;
  183. extern
  184. #ifdef __cplusplus
  185. "C"
  186. #endif
  187. const char *_nl_expand_alias (const char *);
  188. #define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_expand_alias (""))
  189. #else
  190. #define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
  191. #endif
  192. $gt_revision_test_code
  193. ]],
  194. [[
  195. bindtextdomain ("", "");
  196. return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
  197. ]])],
  198. [eval "$gt_func_gnugettext_libintl=yes"],
  199. [eval "$gt_func_gnugettext_libintl=no"])
  200. dnl Now see whether libintl exists and depends on libiconv.
  201. if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then
  202. LIBS="$LIBS $LIBICONV"
  203. AC_LINK_IFELSE(
  204. [AC_LANG_PROGRAM(
  205. [[
  206. #include <libintl.h>
  207. #ifndef __GNU_GETTEXT_SUPPORTED_REVISION
  208. extern int _nl_msg_cat_cntr;
  209. extern
  210. #ifdef __cplusplus
  211. "C"
  212. #endif
  213. const char *_nl_expand_alias (const char *);
  214. #define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_expand_alias (""))
  215. #else
  216. #define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
  217. #endif
  218. $gt_revision_test_code
  219. ]],
  220. [[
  221. bindtextdomain ("", "");
  222. return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
  223. ]])],
  224. [LIBINTL="$LIBINTL $LIBICONV"
  225. LTLIBINTL="$LTLIBINTL $LTLIBICONV"
  226. eval "$gt_func_gnugettext_libintl=yes"
  227. ])
  228. fi
  229. CPPFLAGS="$gt_save_CPPFLAGS"
  230. LIBS="$gt_save_LIBS"])
  231. fi
  232. dnl If an already present or preinstalled GNU gettext() is found,
  233. dnl use it. But if this macro is used in GNU gettext, and GNU
  234. dnl gettext is already preinstalled in libintl, we update this
  235. dnl libintl. (Cf. the install rule in intl/Makefile.in.)
  236. if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \
  237. || { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \
  238. && test "$PACKAGE" != gettext-runtime \
  239. && test "$PACKAGE" != gettext-tools; }; then
  240. gt_use_preinstalled_gnugettext=yes
  241. else
  242. dnl Reset the values set by searching for libintl.
  243. LIBINTL=
  244. LTLIBINTL=
  245. INCINTL=
  246. fi
  247. ifelse(gt_included_intl, yes, [
  248. if test "$gt_use_preinstalled_gnugettext" != "yes"; then
  249. dnl GNU gettext is not found in the C library.
  250. dnl Fall back on included GNU gettext library.
  251. nls_cv_use_gnu_gettext=yes
  252. fi
  253. fi
  254. if test "$nls_cv_use_gnu_gettext" = "yes"; then
  255. dnl Mark actions used to generate GNU NLS library.
  256. BUILD_INCLUDED_LIBINTL=yes
  257. USE_INCLUDED_LIBINTL=yes
  258. LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.la $LIBICONV $LIBTHREAD"
  259. LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.la $LTLIBICONV $LTLIBTHREAD"
  260. LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
  261. fi
  262. CATOBJEXT=
  263. if test "$gt_use_preinstalled_gnugettext" = "yes" \
  264. || test "$nls_cv_use_gnu_gettext" = "yes"; then
  265. dnl Mark actions to use GNU gettext tools.
  266. CATOBJEXT=.gmo
  267. fi
  268. ])
  269. if test -n "$INTL_MACOSX_LIBS"; then
  270. if test "$gt_use_preinstalled_gnugettext" = "yes" \
  271. || test "$nls_cv_use_gnu_gettext" = "yes"; then
  272. dnl Some extra flags are needed during linking.
  273. LIBINTL="$LIBINTL $INTL_MACOSX_LIBS"
  274. LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS"
  275. fi
  276. fi
  277. if test "$gt_use_preinstalled_gnugettext" = "yes" \
  278. || test "$nls_cv_use_gnu_gettext" = "yes"; then
  279. AC_DEFINE([ENABLE_NLS], [1],
  280. [Define to 1 if translation of program messages to the user's native language
  281. is requested.])
  282. else
  283. USE_NLS=no
  284. fi
  285. fi
  286. AC_MSG_CHECKING([whether to use NLS])
  287. AC_MSG_RESULT([$USE_NLS])
  288. if test "$USE_NLS" = "yes"; then
  289. AC_MSG_CHECKING([where the gettext function comes from])
  290. if test "$gt_use_preinstalled_gnugettext" = "yes"; then
  291. if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
  292. gt_source="external libintl"
  293. else
  294. gt_source="libc"
  295. fi
  296. else
  297. gt_source="included intl directory"
  298. fi
  299. AC_MSG_RESULT([$gt_source])
  300. fi
  301. if test "$USE_NLS" = "yes"; then
  302. if test "$gt_use_preinstalled_gnugettext" = "yes"; then
  303. if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
  304. AC_MSG_CHECKING([how to link with libintl])
  305. AC_MSG_RESULT([$LIBINTL])
  306. AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL])
  307. fi
  308. dnl For backward compatibility. Some packages may be using this.
  309. AC_DEFINE([HAVE_GETTEXT], [1],
  310. [Define if the GNU gettext() function is already present or preinstalled.])
  311. AC_DEFINE([HAVE_DCGETTEXT], [1],
  312. [Define if the GNU dcgettext() function is already present or preinstalled.])
  313. fi
  314. dnl We need to process the po/ directory.
  315. POSUB=po
  316. fi
  317. ifelse(gt_included_intl, yes, [
  318. dnl In GNU gettext we have to set BUILD_INCLUDED_LIBINTL to 'yes'
  319. dnl because some of the testsuite requires it.
  320. BUILD_INCLUDED_LIBINTL=yes
  321. dnl Make all variables we use known to autoconf.
  322. AC_SUBST([BUILD_INCLUDED_LIBINTL])
  323. AC_SUBST([USE_INCLUDED_LIBINTL])
  324. AC_SUBST([CATOBJEXT])
  325. ])
  326. dnl For backward compatibility. Some Makefiles may be using this.
  327. INTLLIBS="$LIBINTL"
  328. AC_SUBST([INTLLIBS])
  329. dnl Make all documented variables known to autoconf.
  330. AC_SUBST([LIBINTL])
  331. AC_SUBST([LTLIBINTL])
  332. AC_SUBST([POSUB])
  333. ])
  334. dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized.
  335. m4_define([gt_NEEDS_INIT],
  336. [
  337. m4_divert_text([DEFAULTS], [gt_needs=])
  338. m4_define([gt_NEEDS_INIT], [])
  339. ])
  340. dnl Usage: AM_GNU_GETTEXT_NEED([NEEDSYMBOL])
  341. AC_DEFUN([AM_GNU_GETTEXT_NEED],
  342. [
  343. m4_divert_text([INIT_PREPARE], [gt_needs="$gt_needs $1"])
  344. ])
  345. dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version])
  346. AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])
  347. dnl Usage: AM_GNU_GETTEXT_REQUIRE_VERSION([gettext-version])
  348. AC_DEFUN([AM_GNU_GETTEXT_REQUIRE_VERSION], [])