gettext.m4 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. # gettext.m4 serial 66 (gettext-0.18.2)
  2. dnl Copyright (C) 1995-2013 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 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 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 <[email protected]>, 1995-2000.
  17. dnl Bruno Haible <[email protected]>, 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. $gt_revision_test_code
  151. extern int _nl_msg_cat_cntr;
  152. extern int *_nl_domain_bindings;
  153. ]],
  154. [[
  155. bindtextdomain ("", "");
  156. return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_domain_bindings
  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. $gt_revision_test_code
  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. ]],
  189. [[
  190. bindtextdomain ("", "");
  191. return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")
  192. ]])],
  193. [eval "$gt_func_gnugettext_libintl=yes"],
  194. [eval "$gt_func_gnugettext_libintl=no"])
  195. dnl Now see whether libintl exists and depends on libiconv.
  196. if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then
  197. LIBS="$LIBS $LIBICONV"
  198. AC_LINK_IFELSE(
  199. [AC_LANG_PROGRAM(
  200. [[
  201. #include <libintl.h>
  202. $gt_revision_test_code
  203. extern int _nl_msg_cat_cntr;
  204. extern
  205. #ifdef __cplusplus
  206. "C"
  207. #endif
  208. const char *_nl_expand_alias (const char *);
  209. ]],
  210. [[
  211. bindtextdomain ("", "");
  212. return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")
  213. ]])],
  214. [LIBINTL="$LIBINTL $LIBICONV"
  215. LTLIBINTL="$LTLIBINTL $LTLIBICONV"
  216. eval "$gt_func_gnugettext_libintl=yes"
  217. ])
  218. fi
  219. CPPFLAGS="$gt_save_CPPFLAGS"
  220. LIBS="$gt_save_LIBS"])
  221. fi
  222. dnl If an already present or preinstalled GNU gettext() is found,
  223. dnl use it. But if this macro is used in GNU gettext, and GNU
  224. dnl gettext is already preinstalled in libintl, we update this
  225. dnl libintl. (Cf. the install rule in intl/Makefile.in.)
  226. if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \
  227. || { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \
  228. && test "$PACKAGE" != gettext-runtime \
  229. && test "$PACKAGE" != gettext-tools; }; then
  230. gt_use_preinstalled_gnugettext=yes
  231. else
  232. dnl Reset the values set by searching for libintl.
  233. LIBINTL=
  234. LTLIBINTL=
  235. INCINTL=
  236. fi
  237. ifelse(gt_included_intl, yes, [
  238. if test "$gt_use_preinstalled_gnugettext" != "yes"; then
  239. dnl GNU gettext is not found in the C library.
  240. dnl Fall back on included GNU gettext library.
  241. nls_cv_use_gnu_gettext=yes
  242. fi
  243. fi
  244. if test "$nls_cv_use_gnu_gettext" = "yes"; then
  245. dnl Mark actions used to generate GNU NLS library.
  246. BUILD_INCLUDED_LIBINTL=yes
  247. USE_INCLUDED_LIBINTL=yes
  248. LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV $LIBTHREAD"
  249. LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV $LTLIBTHREAD"
  250. LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
  251. fi
  252. CATOBJEXT=
  253. if test "$gt_use_preinstalled_gnugettext" = "yes" \
  254. || test "$nls_cv_use_gnu_gettext" = "yes"; then
  255. dnl Mark actions to use GNU gettext tools.
  256. CATOBJEXT=.gmo
  257. fi
  258. ])
  259. if test -n "$INTL_MACOSX_LIBS"; then
  260. if test "$gt_use_preinstalled_gnugettext" = "yes" \
  261. || test "$nls_cv_use_gnu_gettext" = "yes"; then
  262. dnl Some extra flags are needed during linking.
  263. LIBINTL="$LIBINTL $INTL_MACOSX_LIBS"
  264. LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS"
  265. fi
  266. fi
  267. if test "$gt_use_preinstalled_gnugettext" = "yes" \
  268. || test "$nls_cv_use_gnu_gettext" = "yes"; then
  269. AC_DEFINE([ENABLE_NLS], [1],
  270. [Define to 1 if translation of program messages to the user's native language
  271. is requested.])
  272. else
  273. USE_NLS=no
  274. fi
  275. fi
  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 { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "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. if test "$USE_NLS" = "yes"; then
  292. if test "$gt_use_preinstalled_gnugettext" = "yes"; then
  293. if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
  294. AC_MSG_CHECKING([how to link with libintl])
  295. AC_MSG_RESULT([$LIBINTL])
  296. AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL])
  297. fi
  298. dnl For backward compatibility. Some packages may be using this.
  299. AC_DEFINE([HAVE_GETTEXT], [1],
  300. [Define if the GNU gettext() function is already present or preinstalled.])
  301. AC_DEFINE([HAVE_DCGETTEXT], [1],
  302. [Define if the GNU dcgettext() function is already present or preinstalled.])
  303. fi
  304. dnl We need to process the po/ directory.
  305. POSUB=po
  306. fi
  307. ifelse(gt_included_intl, yes, [
  308. dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL
  309. dnl to 'yes' because some of the testsuite requires it.
  310. if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then
  311. BUILD_INCLUDED_LIBINTL=yes
  312. fi
  313. dnl Make all variables we use known to autoconf.
  314. AC_SUBST([BUILD_INCLUDED_LIBINTL])
  315. AC_SUBST([USE_INCLUDED_LIBINTL])
  316. AC_SUBST([CATOBJEXT])
  317. dnl For backward compatibility. Some configure.ins may be using this.
  318. nls_cv_header_intl=
  319. nls_cv_header_libgt=
  320. dnl For backward compatibility. Some Makefiles may be using this.
  321. DATADIRNAME=share
  322. AC_SUBST([DATADIRNAME])
  323. dnl For backward compatibility. Some Makefiles may be using this.
  324. INSTOBJEXT=.mo
  325. AC_SUBST([INSTOBJEXT])
  326. dnl For backward compatibility. Some Makefiles may be using this.
  327. GENCAT=gencat
  328. AC_SUBST([GENCAT])
  329. dnl For backward compatibility. Some Makefiles may be using this.
  330. INTLOBJS=
  331. if test "$USE_INCLUDED_LIBINTL" = yes; then
  332. INTLOBJS="\$(GETTOBJS)"
  333. fi
  334. AC_SUBST([INTLOBJS])
  335. dnl Enable libtool support if the surrounding package wishes it.
  336. INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix
  337. AC_SUBST([INTL_LIBTOOL_SUFFIX_PREFIX])
  338. ])
  339. dnl For backward compatibility. Some Makefiles may be using this.
  340. INTLLIBS="$LIBINTL"
  341. AC_SUBST([INTLLIBS])
  342. dnl Make all documented variables known to autoconf.
  343. AC_SUBST([LIBINTL])
  344. AC_SUBST([LTLIBINTL])
  345. AC_SUBST([POSUB])
  346. ])
  347. dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized.
  348. m4_define([gt_NEEDS_INIT],
  349. [
  350. m4_divert_text([DEFAULTS], [gt_needs=])
  351. m4_define([gt_NEEDS_INIT], [])
  352. ])
  353. dnl Usage: AM_GNU_GETTEXT_NEED([NEEDSYMBOL])
  354. AC_DEFUN([AM_GNU_GETTEXT_NEED],
  355. [
  356. m4_divert_text([INIT_PREPARE], [gt_needs="$gt_needs $1"])
  357. ])
  358. dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version])
  359. AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])