gettext.m4 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. # gettext.m4 serial 62 (gettext-0.18)
  2. dnl Copyright (C) 1995-2009 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 <drepper@cygnus.com>, 1995-2000.
  17. dnl Bruno Haible <haible@clisp.cons.org>, 2000-2006.
  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([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], ,
  61. [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
  62. ])])])])
  63. define([gt_included_intl],
  64. ifelse([$1], [external],
  65. ifdef([AM_GNU_GETTEXT_][INTL_SUBDIR], [yes], [no]),
  66. [yes]))
  67. define([gt_libtool_suffix_prefix], ifelse([$1], [use-libtool], [l], []))
  68. gt_NEEDS_INIT
  69. AM_GNU_GETTEXT_NEED([$2])
  70. AC_REQUIRE([AM_PO_SUBDIRS])dnl
  71. ifelse(gt_included_intl, yes, [
  72. AC_REQUIRE([AM_INTL_SUBDIR])dnl
  73. ])
  74. dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
  75. AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
  76. AC_REQUIRE([AC_LIB_RPATH])
  77. dnl Sometimes libintl requires libiconv, so first search for libiconv.
  78. dnl Ideally we would do this search only after the
  79. dnl if test "$USE_NLS" = "yes"; then
  80. dnl if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
  81. dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT
  82. dnl the configure script would need to contain the same shell code
  83. dnl again, outside any 'if'. There are two solutions:
  84. dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'.
  85. dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE.
  86. dnl Since AC_PROVIDE_IFELSE is only in autoconf >= 2.52 and not
  87. dnl documented, we avoid it.
  88. ifelse(gt_included_intl, yes, , [
  89. AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
  90. ])
  91. dnl Sometimes, on MacOS X, libintl requires linking with CoreFoundation.
  92. gt_INTL_MACOSX
  93. dnl Set USE_NLS.
  94. AC_REQUIRE([AM_NLS])
  95. ifelse(gt_included_intl, yes, [
  96. BUILD_INCLUDED_LIBINTL=no
  97. USE_INCLUDED_LIBINTL=no
  98. ])
  99. LIBINTL=
  100. LTLIBINTL=
  101. POSUB=
  102. dnl Add a version number to the cache macros.
  103. case " $gt_needs " in
  104. *" need-formatstring-macros "*) gt_api_version=3 ;;
  105. *" need-ngettext "*) gt_api_version=2 ;;
  106. *) gt_api_version=1 ;;
  107. esac
  108. gt_func_gnugettext_libc="gt_cv_func_gnugettext${gt_api_version}_libc"
  109. gt_func_gnugettext_libintl="gt_cv_func_gnugettext${gt_api_version}_libintl"
  110. dnl If we use NLS figure out what method
  111. if test "$USE_NLS" = "yes"; then
  112. gt_use_preinstalled_gnugettext=no
  113. ifelse(gt_included_intl, yes, [
  114. AC_MSG_CHECKING([whether included gettext is requested])
  115. AC_ARG_WITH([included-gettext],
  116. [ --with-included-gettext use the GNU gettext library included here],
  117. nls_cv_force_use_gnu_gettext=$withval,
  118. nls_cv_force_use_gnu_gettext=no)
  119. AC_MSG_RESULT([$nls_cv_force_use_gnu_gettext])
  120. nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
  121. if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
  122. ])
  123. dnl User does not insist on using GNU NLS library. Figure out what
  124. dnl to use. If GNU gettext is available we use this. Else we have
  125. dnl to fall back to GNU NLS library.
  126. if test $gt_api_version -ge 3; then
  127. gt_revision_test_code='
  128. #ifndef __GNU_GETTEXT_SUPPORTED_REVISION
  129. #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
  130. #endif
  131. changequote(,)dnl
  132. typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
  133. changequote([,])dnl
  134. '
  135. else
  136. gt_revision_test_code=
  137. fi
  138. if test $gt_api_version -ge 2; then
  139. gt_expression_test_code=' + * ngettext ("", "", 0)'
  140. else
  141. gt_expression_test_code=
  142. fi
  143. AC_CACHE_CHECK([for GNU gettext in libc], [$gt_func_gnugettext_libc],
  144. [AC_TRY_LINK([#include <libintl.h>
  145. $gt_revision_test_code
  146. extern int _nl_msg_cat_cntr;
  147. extern int *_nl_domain_bindings;],
  148. [bindtextdomain ("", "");
  149. return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_domain_bindings],
  150. [eval "$gt_func_gnugettext_libc=yes"],
  151. [eval "$gt_func_gnugettext_libc=no"])])
  152. if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
  153. dnl Sometimes libintl requires libiconv, so first search for libiconv.
  154. ifelse(gt_included_intl, yes, , [
  155. AM_ICONV_LINK
  156. ])
  157. dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
  158. dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv])
  159. dnl because that would add "-liconv" to LIBINTL and LTLIBINTL
  160. dnl even if libiconv doesn't exist.
  161. AC_LIB_LINKFLAGS_BODY([intl])
  162. AC_CACHE_CHECK([for GNU gettext in libintl],
  163. [$gt_func_gnugettext_libintl],
  164. [gt_save_CPPFLAGS="$CPPFLAGS"
  165. CPPFLAGS="$CPPFLAGS $INCINTL"
  166. gt_save_LIBS="$LIBS"
  167. LIBS="$LIBS $LIBINTL"
  168. dnl Now see whether libintl exists and does not depend on libiconv.
  169. AC_TRY_LINK([#include <libintl.h>
  170. $gt_revision_test_code
  171. extern int _nl_msg_cat_cntr;
  172. extern
  173. #ifdef __cplusplus
  174. "C"
  175. #endif
  176. const char *_nl_expand_alias (const char *);],
  177. [bindtextdomain ("", "");
  178. return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")],
  179. [eval "$gt_func_gnugettext_libintl=yes"],
  180. [eval "$gt_func_gnugettext_libintl=no"])
  181. dnl Now see whether libintl exists and depends on libiconv.
  182. if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then
  183. LIBS="$LIBS $LIBICONV"
  184. AC_TRY_LINK([#include <libintl.h>
  185. $gt_revision_test_code
  186. extern int _nl_msg_cat_cntr;
  187. extern
  188. #ifdef __cplusplus
  189. "C"
  190. #endif
  191. const char *_nl_expand_alias (const char *);],
  192. [bindtextdomain ("", "");
  193. return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")],
  194. [LIBINTL="$LIBINTL $LIBICONV"
  195. LTLIBINTL="$LTLIBINTL $LTLIBICONV"
  196. eval "$gt_func_gnugettext_libintl=yes"
  197. ])
  198. fi
  199. CPPFLAGS="$gt_save_CPPFLAGS"
  200. LIBS="$gt_save_LIBS"])
  201. fi
  202. dnl If an already present or preinstalled GNU gettext() is found,
  203. dnl use it. But if this macro is used in GNU gettext, and GNU
  204. dnl gettext is already preinstalled in libintl, we update this
  205. dnl libintl. (Cf. the install rule in intl/Makefile.in.)
  206. if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \
  207. || { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \
  208. && test "$PACKAGE" != gettext-runtime \
  209. && test "$PACKAGE" != gettext-tools; }; then
  210. gt_use_preinstalled_gnugettext=yes
  211. else
  212. dnl Reset the values set by searching for libintl.
  213. LIBINTL=
  214. LTLIBINTL=
  215. INCINTL=
  216. fi
  217. ifelse(gt_included_intl, yes, [
  218. if test "$gt_use_preinstalled_gnugettext" != "yes"; then
  219. dnl GNU gettext is not found in the C library.
  220. dnl Fall back on included GNU gettext library.
  221. nls_cv_use_gnu_gettext=yes
  222. fi
  223. fi
  224. if test "$nls_cv_use_gnu_gettext" = "yes"; then
  225. dnl Mark actions used to generate GNU NLS library.
  226. BUILD_INCLUDED_LIBINTL=yes
  227. USE_INCLUDED_LIBINTL=yes
  228. LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV $LIBTHREAD"
  229. LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV $LTLIBTHREAD"
  230. LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
  231. fi
  232. CATOBJEXT=
  233. if test "$gt_use_preinstalled_gnugettext" = "yes" \
  234. || test "$nls_cv_use_gnu_gettext" = "yes"; then
  235. dnl Mark actions to use GNU gettext tools.
  236. CATOBJEXT=.gmo
  237. fi
  238. ])
  239. if test -n "$INTL_MACOSX_LIBS"; then
  240. if test "$gt_use_preinstalled_gnugettext" = "yes" \
  241. || test "$nls_cv_use_gnu_gettext" = "yes"; then
  242. dnl Some extra flags are needed during linking.
  243. LIBINTL="$LIBINTL $INTL_MACOSX_LIBS"
  244. LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS"
  245. fi
  246. fi
  247. if test "$gt_use_preinstalled_gnugettext" = "yes" \
  248. || test "$nls_cv_use_gnu_gettext" = "yes"; then
  249. AC_DEFINE([ENABLE_NLS], [1],
  250. [Define to 1 if translation of program messages to the user's native language
  251. is requested.])
  252. else
  253. USE_NLS=no
  254. fi
  255. fi
  256. AC_MSG_CHECKING([whether to use NLS])
  257. AC_MSG_RESULT([$USE_NLS])
  258. if test "$USE_NLS" = "yes"; then
  259. AC_MSG_CHECKING([where the gettext function comes from])
  260. if test "$gt_use_preinstalled_gnugettext" = "yes"; then
  261. if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
  262. gt_source="external libintl"
  263. else
  264. gt_source="libc"
  265. fi
  266. else
  267. gt_source="included intl directory"
  268. fi
  269. AC_MSG_RESULT([$gt_source])
  270. fi
  271. if test "$USE_NLS" = "yes"; then
  272. if test "$gt_use_preinstalled_gnugettext" = "yes"; then
  273. if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
  274. AC_MSG_CHECKING([how to link with libintl])
  275. AC_MSG_RESULT([$LIBINTL])
  276. AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL])
  277. fi
  278. dnl For backward compatibility. Some packages may be using this.
  279. AC_DEFINE([HAVE_GETTEXT], [1],
  280. [Define if the GNU gettext() function is already present or preinstalled.])
  281. AC_DEFINE([HAVE_DCGETTEXT], [1],
  282. [Define if the GNU dcgettext() function is already present or preinstalled.])
  283. fi
  284. dnl We need to process the po/ directory.
  285. POSUB=po
  286. fi
  287. ifelse(gt_included_intl, yes, [
  288. dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL
  289. dnl to 'yes' because some of the testsuite requires it.
  290. if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then
  291. BUILD_INCLUDED_LIBINTL=yes
  292. fi
  293. dnl Make all variables we use known to autoconf.
  294. AC_SUBST([BUILD_INCLUDED_LIBINTL])
  295. AC_SUBST([USE_INCLUDED_LIBINTL])
  296. AC_SUBST([CATOBJEXT])
  297. dnl For backward compatibility. Some configure.ins may be using this.
  298. nls_cv_header_intl=
  299. nls_cv_header_libgt=
  300. dnl For backward compatibility. Some Makefiles may be using this.
  301. DATADIRNAME=share
  302. AC_SUBST([DATADIRNAME])
  303. dnl For backward compatibility. Some Makefiles may be using this.
  304. INSTOBJEXT=.mo
  305. AC_SUBST([INSTOBJEXT])
  306. dnl For backward compatibility. Some Makefiles may be using this.
  307. GENCAT=gencat
  308. AC_SUBST([GENCAT])
  309. dnl For backward compatibility. Some Makefiles may be using this.
  310. INTLOBJS=
  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 gt_NEEDS_INIT ensures that the gt_needs variable is initialized.
  328. m4_define([gt_NEEDS_INIT],
  329. [
  330. m4_divert_text([DEFAULTS], [gt_needs=])
  331. m4_define([gt_NEEDS_INIT], [])
  332. ])
  333. dnl Usage: AM_GNU_GETTEXT_NEED([NEEDSYMBOL])
  334. AC_DEFUN([AM_GNU_GETTEXT_NEED],
  335. [
  336. m4_divert_text([INIT_PREPARE], [gt_needs="$gt_needs $1"])
  337. ])
  338. dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version])
  339. AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])