gettext.m4 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. # Macro to add for using GNU gettext.
  2. # Ulrich Drepper <[email protected]>, 1995.
  3. #
  4. # This file can be copied and used freely without restrictions. It can
  5. # be used in projects which are not available under the GNU General Public
  6. # License but which still want to provide support for the GNU gettext
  7. # functionality.
  8. # Please note that the actual code of GNU gettext is covered by the GNU
  9. # General Public License and is *not* in the public domain.
  10. # serial 10
  11. dnl Usage: AM_WITH_NLS([TOOLSYMBOL], [NEEDSYMBOL], [LIBDIR]).
  12. dnl If TOOLSYMBOL is specified and is 'use-libtool', then a libtool library
  13. dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static,
  14. dnl depending on --{enable,disable}-{shared,static} and on the presence of
  15. dnl AM-DISABLE-SHARED). Otherwise, a static library
  16. dnl $(top_builddir)/intl/libintl.a will be created.
  17. dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
  18. dnl implementations (in libc or libintl) without the ngettext() function
  19. dnl will be ignored.
  20. dnl LIBDIR is used to find the intl libraries. If empty,
  21. dnl the value `$(top_builddir)/intl/' is used.
  22. dnl
  23. dnl The result of the configuration is one of three cases:
  24. dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled
  25. dnl and used.
  26. dnl Catalog format: GNU --> install in $(datadir)
  27. dnl Catalog extension: .mo after installation, .gmo in source tree
  28. dnl 2) GNU gettext has been found in the system's C library.
  29. dnl Catalog format: GNU --> install in $(datadir)
  30. dnl Catalog extension: .mo after installation, .gmo in source tree
  31. dnl 3) No internationalization, always use English msgid.
  32. dnl Catalog format: none
  33. dnl Catalog extension: none
  34. dnl The use of .gmo is historical (it was needed to avoid overwriting the
  35. dnl GNU format catalogs when building on a platform with an X/Open gettext),
  36. dnl but we keep it in order not to force irrelevant filename changes on the
  37. dnl maintainers.
  38. dnl
  39. AC_DEFUN([AM_WITH_NLS],
  40. [AC_MSG_CHECKING([whether NLS is requested])
  41. dnl Default is enabled NLS
  42. AC_ARG_ENABLE(nls,
  43. [ --disable-nls do not use Native Language Support],
  44. USE_NLS=$enableval, USE_NLS=yes)
  45. AC_MSG_RESULT($USE_NLS)
  46. AC_SUBST(USE_NLS)
  47. BUILD_INCLUDED_LIBINTL=no
  48. USE_INCLUDED_LIBINTL=no
  49. INTLLIBS=
  50. dnl If we use NLS figure out what method
  51. if test "$USE_NLS" = "yes"; then
  52. AC_DEFINE(ENABLE_NLS, 1,
  53. [Define to 1 if translation of program messages to the user's native language
  54. is requested.])
  55. AC_MSG_CHECKING([whether included gettext is requested])
  56. AC_ARG_WITH(included-gettext,
  57. [ --with-included-gettext use the GNU gettext library included here],
  58. nls_cv_force_use_gnu_gettext=$withval,
  59. nls_cv_force_use_gnu_gettext=no)
  60. AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
  61. nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
  62. if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
  63. dnl User does not insist on using GNU NLS library. Figure out what
  64. dnl to use. If GNU gettext is available we use this. Else we have
  65. dnl to fall back to GNU NLS library.
  66. CATOBJEXT=NONE
  67. dnl Add a version number to the cache macros.
  68. define(gt_cv_func_gnugettext_libc, [gt_cv_func_gnugettext]ifelse([$2], need-ngettext, 2, 1)[_libc])
  69. define(gt_cv_func_gnugettext_libintl, [gt_cv_func_gnugettext]ifelse([$2], need-ngettext, 2, 1)[_libintl])
  70. AC_CHECK_HEADER(libintl.h,
  71. [AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc,
  72. [AC_TRY_LINK([#include <libintl.h>
  73. extern int _nl_msg_cat_cntr;],
  74. [bindtextdomain ("", "");
  75. return (int) gettext ("")]ifelse([$2], need-ngettext, [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr],
  76. gt_cv_func_gnugettext_libc=yes,
  77. gt_cv_func_gnugettext_libc=no)])
  78. if test "$gt_cv_func_gnugettext_libc" != "yes"; then
  79. AC_CACHE_CHECK([for GNU gettext in libintl],
  80. gt_cv_func_gnugettext_libintl,
  81. [gt_save_LIBS="$LIBS"
  82. LIBS="$LIBS -lintl $LIBICONV"
  83. AC_TRY_LINK([#include <libintl.h>
  84. extern int _nl_msg_cat_cntr;],
  85. [bindtextdomain ("", "");
  86. return (int) gettext ("")]ifelse([$2], need-ngettext, [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr],
  87. gt_cv_func_gnugettext_libintl=yes,
  88. gt_cv_func_gnugettext_libintl=no)
  89. LIBS="$gt_save_LIBS"])
  90. fi
  91. dnl If an already present or preinstalled GNU gettext() is found,
  92. dnl use it. But if this macro is used in GNU gettext, and GNU
  93. dnl gettext is already preinstalled in libintl, we update this
  94. dnl libintl. (Cf. the install rule in intl/Makefile.in.)
  95. if test "$gt_cv_func_gnugettext_libc" = "yes" \
  96. || { test "$gt_cv_func_gnugettext_libintl" = "yes" \
  97. && test "$PACKAGE" != gettext; }; then
  98. AC_DEFINE(HAVE_GETTEXT, 1,
  99. [Define if the GNU gettext() function is already present or preinstalled.])
  100. if test "$gt_cv_func_gnugettext_libintl" = "yes"; then
  101. dnl If iconv() is in a separate libiconv library, then anyone
  102. dnl linking with libintl{.a,.so} also needs to link with
  103. dnl libiconv.
  104. INTLLIBS="-lintl $LIBICONV"
  105. fi
  106. gt_save_LIBS="$LIBS"
  107. LIBS="$LIBS $INTLLIBS"
  108. AC_CHECK_FUNCS(dcgettext)
  109. LIBS="$gt_save_LIBS"
  110. dnl Search for GNU msgfmt in the PATH.
  111. AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
  112. [$ac_dir/$ac_word --statistics /dev/null >/dev/null 2>&1], :)
  113. AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
  114. dnl Search for GNU xgettext in the PATH.
  115. AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
  116. [$ac_dir/$ac_word --omit-header /dev/null >/dev/null 2>&1], :)
  117. CATOBJEXT=.gmo
  118. fi
  119. ])
  120. if test "$CATOBJEXT" = "NONE"; then
  121. dnl GNU gettext is not found in the C library.
  122. dnl Fall back on GNU gettext library.
  123. nls_cv_use_gnu_gettext=yes
  124. fi
  125. fi
  126. if test "$nls_cv_use_gnu_gettext" = "yes"; then
  127. dnl Mark actions used to generate GNU NLS library.
  128. INTLOBJS="\$(GETTOBJS)"
  129. AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
  130. [$ac_dir/$ac_word --statistics /dev/null >/dev/null 2>&1], :)
  131. AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
  132. AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
  133. [$ac_dir/$ac_word --omit-header /dev/null >/dev/null 2>&1], :)
  134. AC_SUBST(MSGFMT)
  135. BUILD_INCLUDED_LIBINTL=yes
  136. USE_INCLUDED_LIBINTL=yes
  137. CATOBJEXT=.gmo
  138. INTLLIBS="ifelse([$3],[],\$(top_builddir)/intl,[$3])/libintl.ifelse([$1], use-libtool, [l], [])a $LIBICONV"
  139. LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
  140. fi
  141. dnl This could go away some day; the PATH_PROG_WITH_TEST already does it.
  142. dnl Test whether we really found GNU msgfmt.
  143. if test "$GMSGFMT" != ":"; then
  144. dnl If it is no GNU msgfmt we define it as : so that the
  145. dnl Makefiles still can work.
  146. if $GMSGFMT --statistics /dev/null >/dev/null 2>&1; then
  147. : ;
  148. else
  149. AC_MSG_RESULT(
  150. [found msgfmt program is not GNU msgfmt; ignore it])
  151. GMSGFMT=":"
  152. fi
  153. fi
  154. dnl This could go away some day; the PATH_PROG_WITH_TEST already does it.
  155. dnl Test whether we really found GNU xgettext.
  156. if test "$XGETTEXT" != ":"; then
  157. dnl If it is no GNU xgettext we define it as : so that the
  158. dnl Makefiles still can work.
  159. if $XGETTEXT --omit-header /dev/null >/dev/null 2>&1; then
  160. : ;
  161. else
  162. AC_MSG_RESULT(
  163. [found xgettext program is not GNU xgettext; ignore it])
  164. XGETTEXT=":"
  165. fi
  166. fi
  167. dnl We need to process the po/ directory.
  168. POSUB=po
  169. fi
  170. AC_OUTPUT_COMMANDS(
  171. [for ac_file in $CONFIG_FILES; do
  172. # Support "outfile[:infile[:infile...]]"
  173. case "$ac_file" in
  174. *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
  175. esac
  176. # PO directories have a Makefile.in generated from Makefile.in.in.
  177. case "$ac_file" in */Makefile.in)
  178. # Adjust a relative srcdir.
  179. ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
  180. ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
  181. ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
  182. # In autoconf-2.13 it is called $ac_given_srcdir.
  183. # In autoconf-2.50 it is called $srcdir.
  184. test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
  185. case "$ac_given_srcdir" in
  186. .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
  187. /*) top_srcdir="$ac_given_srcdir" ;;
  188. *) top_srcdir="$ac_dots$ac_given_srcdir" ;;
  189. esac
  190. if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then
  191. rm -f "$ac_dir/POTFILES"
  192. test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES"
  193. sed -e "/^#/d" -e "/^[ ]*\$/d" -e "s,.*, $top_srcdir/& \\\\," -e "\$s/\(.*\) \\\\/\1/" < "$ac_given_srcdir/$ac_dir/POTFILES.in" > "$ac_dir/POTFILES"
  194. test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile"
  195. sed -e "/POTFILES =/r $ac_dir/POTFILES" "$ac_dir/Makefile.in" > "$ac_dir/Makefile"
  196. fi
  197. ;;
  198. esac
  199. done])
  200. dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL
  201. dnl to 'yes' because some of the testsuite requires it.
  202. if test "$PACKAGE" = gettext; then
  203. BUILD_INCLUDED_LIBINTL=yes
  204. fi
  205. dnl intl/plural.c is generated from intl/plural.y. It requires bison,
  206. dnl because plural.y uses bison specific features. It requires at least
  207. dnl bison-1.26 because earlier versions generate a plural.c that doesn't
  208. dnl compile.
  209. dnl bison is only needed for the maintainer (who touches plural.y). But in
  210. dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put
  211. dnl the rule in general Makefile. Now, some people carelessly touch the
  212. dnl files or have a broken "make" program, hence the plural.c rule will
  213. dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not
  214. dnl present or too old.
  215. AC_CHECK_PROGS([INTLBISON], [bison])
  216. if test -z "$INTLBISON"; then
  217. ac_verc_fail=yes
  218. else
  219. dnl Found it, now check the version.
  220. AC_MSG_CHECKING([version of bison])
  221. changequote(<<,>>)dnl
  222. ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison .* \([0-9]*\.[0-9.]*\).*$/\1/p'`
  223. case $ac_prog_version in
  224. '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
  225. 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*)
  226. changequote([,])dnl
  227. ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
  228. *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
  229. esac
  230. AC_MSG_RESULT([$ac_prog_version])
  231. fi
  232. if test $ac_verc_fail = yes; then
  233. INTLBISON=:
  234. fi
  235. dnl These rules are solely for the distribution goal. While doing this
  236. dnl we only have to keep exactly one list of the available catalogs
  237. dnl in configure.in.
  238. for lang in $ALL_LINGUAS; do
  239. GMOFILES="$GMOFILES $lang.gmo"
  240. POFILES="$POFILES $lang.po"
  241. done
  242. dnl Make all variables we use known to autoconf.
  243. AC_SUBST(BUILD_INCLUDED_LIBINTL)
  244. AC_SUBST(USE_INCLUDED_LIBINTL)
  245. AC_SUBST(CATALOGS)
  246. AC_SUBST(CATOBJEXT)
  247. AC_SUBST(GMOFILES)
  248. AC_SUBST(INTLLIBS)
  249. AC_SUBST(INTLOBJS)
  250. AC_SUBST(POFILES)
  251. AC_SUBST(POSUB)
  252. dnl For backward compatibility. Some configure.ins may be using this.
  253. nls_cv_header_intl=
  254. nls_cv_header_libgt=
  255. dnl For backward compatibility. Some Makefiles may be using this.
  256. DATADIRNAME=share
  257. AC_SUBST(DATADIRNAME)
  258. dnl For backward compatibility. Some Makefiles may be using this.
  259. INSTOBJEXT=.mo
  260. AC_SUBST(INSTOBJEXT)
  261. dnl For backward compatibility. Some Makefiles may be using this.
  262. GENCAT=gencat
  263. AC_SUBST(GENCAT)
  264. ])
  265. dnl Usage: Just like AM_WITH_NLS, which see.
  266. AC_DEFUN([AM_GNU_GETTEXT],
  267. [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
  268. AC_REQUIRE([AC_PROG_CC])dnl
  269. AC_REQUIRE([AC_CANONICAL_HOST])dnl
  270. AC_REQUIRE([AC_PROG_RANLIB])dnl
  271. AC_REQUIRE([AC_ISC_POSIX])dnl
  272. AC_REQUIRE([AC_HEADER_STDC])dnl
  273. AC_REQUIRE([AC_C_CONST])dnl
  274. AC_REQUIRE([AC_C_INLINE])dnl
  275. AC_REQUIRE([AC_TYPE_OFF_T])dnl
  276. AC_REQUIRE([AC_TYPE_SIZE_T])dnl
  277. AC_REQUIRE([AC_FUNC_ALLOCA])dnl
  278. AC_REQUIRE([AC_FUNC_MMAP])dnl
  279. AC_REQUIRE([jm_GLIBC21])dnl
  280. AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \
  281. stdlib.h string.h unistd.h sys/param.h])
  282. AC_CHECK_FUNCS([feof_unlocked fgets_unlocked getcwd getegid geteuid \
  283. getgid getuid mempcpy munmap putenv setenv setlocale stpcpy strchr strcasecmp \
  284. strdup strtoul tsearch __argz_count __argz_stringify __argz_next])
  285. AM_ICONV
  286. AM_LANGINFO_CODESET
  287. AM_LC_MESSAGES
  288. AM_WITH_NLS([$1],[$2],[$3])
  289. if test "x$CATOBJEXT" != "x"; then
  290. if test "x$ALL_LINGUAS" = "x"; then
  291. LINGUAS=
  292. else
  293. AC_MSG_CHECKING(for catalogs to be installed)
  294. NEW_LINGUAS=
  295. for presentlang in $ALL_LINGUAS; do
  296. useit=no
  297. for desiredlang in ${LINGUAS-$ALL_LINGUAS}; do
  298. # Use the presentlang catalog if desiredlang is
  299. # a. equal to presentlang, or
  300. # b. a variant of presentlang (because in this case,
  301. # presentlang can be used as a fallback for messages
  302. # which are not translated in the desiredlang catalog).
  303. case "$desiredlang" in
  304. "$presentlang"*) useit=yes;;
  305. esac
  306. done
  307. if test $useit = yes; then
  308. NEW_LINGUAS="$NEW_LINGUAS $presentlang"
  309. fi
  310. done
  311. LINGUAS=$NEW_LINGUAS
  312. AC_MSG_RESULT($LINGUAS)
  313. fi
  314. dnl Construct list of names of catalog files to be constructed.
  315. if test -n "$LINGUAS"; then
  316. for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
  317. fi
  318. fi
  319. dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
  320. dnl find the mkinstalldirs script in another subdir but $(top_srcdir).
  321. dnl Try to locate is.
  322. MKINSTALLDIRS=
  323. if test -n "$ac_aux_dir"; then
  324. MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
  325. fi
  326. if test -z "$MKINSTALLDIRS"; then
  327. MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
  328. fi
  329. AC_SUBST(MKINSTALLDIRS)
  330. dnl Enable libtool support if the surrounding package wishes it.
  331. INTL_LIBTOOL_SUFFIX_PREFIX=ifelse([$1], use-libtool, [l], [])
  332. AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX)
  333. ])