gettext.m4 15 KB

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