glib-gettext.m4 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. # Copyright (C) 1995-2002 Free Software Foundation, Inc.
  2. # Copyright (C) 2001-2003,2004 Red Hat, Inc.
  3. #
  4. # This file is free software, distributed under the terms of the GNU
  5. # General Public License. As a special exception to the GNU General
  6. # Public License, this file may be distributed as part of a program
  7. # that contains a configuration script generated by Autoconf, under
  8. # the same distribution terms as the rest of that program.
  9. #
  10. # This file can be copied and used freely without restrictions. It can
  11. # be used in projects which are not available under the GNU Public License
  12. # but which still want to provide support for the GNU gettext functionality.
  13. #
  14. # Macro to add for using GNU gettext.
  15. # Ulrich Drepper <drepper@cygnus.com>, 1995, 1996
  16. #
  17. # Modified to never use included libintl.
  18. # Owen Taylor <otaylor@redhat.com>, 12/15/1998
  19. #
  20. # Major rework to remove unused code
  21. # Owen Taylor <otaylor@redhat.com>, 12/11/2002
  22. #
  23. # Added better handling of ALL_LINGUAS from GNU gettext version
  24. # written by Bruno Haible, Owen Taylor <otaylor.redhat.com> 5/30/3002
  25. #
  26. # Modified to require ngettext
  27. # Matthias Clasen <mclasen@redhat.com> 08/06/2004
  28. #
  29. # We need this here as well, since someone might use autoconf-2.5x
  30. # to configure GLib then an older version to configure a package
  31. # using AM_GLIB_GNU_GETTEXT
  32. AC_PREREQ(2.53)
  33. dnl
  34. dnl We go to great lengths to make sure that aclocal won't
  35. dnl try to pull in the installed version of these macros
  36. dnl when running aclocal in the glib directory.
  37. dnl
  38. m4_copy([AC_DEFUN],[glib_DEFUN])
  39. m4_copy([AC_REQUIRE],[glib_REQUIRE])
  40. dnl
  41. dnl At the end, if we're not within glib, we'll define the public
  42. dnl definitions in terms of our private definitions.
  43. dnl
  44. # GLIB_LC_MESSAGES
  45. #--------------------
  46. glib_DEFUN([GLIB_LC_MESSAGES],
  47. [AC_CHECK_HEADERS([locale.h])
  48. if test $ac_cv_header_locale_h = yes; then
  49. AC_CACHE_CHECK([for LC_MESSAGES], am_cv_val_LC_MESSAGES,
  50. [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES],
  51. am_cv_val_LC_MESSAGES=yes, am_cv_val_LC_MESSAGES=no)])
  52. if test $am_cv_val_LC_MESSAGES = yes; then
  53. AC_DEFINE(HAVE_LC_MESSAGES, 1,
  54. [Define if your <locale.h> file defines LC_MESSAGES.])
  55. fi
  56. fi])
  57. # GLIB_PATH_PROG_WITH_TEST
  58. #----------------------------
  59. dnl GLIB_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
  60. dnl TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
  61. glib_DEFUN([GLIB_PATH_PROG_WITH_TEST],
  62. [# Extract the first word of "$2", so it can be a program name with args.
  63. set dummy $2; ac_word=[$]2
  64. AC_MSG_CHECKING([for $ac_word])
  65. AC_CACHE_VAL(ac_cv_path_$1,
  66. [case "[$]$1" in
  67. /*)
  68. ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
  69. ;;
  70. *)
  71. IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
  72. for ac_dir in ifelse([$5], , $PATH, [$5]); do
  73. test -z "$ac_dir" && ac_dir=.
  74. if test -f $ac_dir/$ac_word; then
  75. if [$3]; then
  76. ac_cv_path_$1="$ac_dir/$ac_word"
  77. break
  78. fi
  79. fi
  80. done
  81. IFS="$ac_save_ifs"
  82. dnl If no 4th arg is given, leave the cache variable unset,
  83. dnl so AC_PATH_PROGS will keep looking.
  84. ifelse([$4], , , [ test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
  85. ])dnl
  86. ;;
  87. esac])dnl
  88. $1="$ac_cv_path_$1"
  89. if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then
  90. AC_MSG_RESULT([$]$1)
  91. else
  92. AC_MSG_RESULT(no)
  93. fi
  94. AC_SUBST($1)dnl
  95. ])
  96. # GLIB_WITH_NLS
  97. #-----------------
  98. glib_DEFUN([GLIB_WITH_NLS],
  99. dnl NLS is obligatory
  100. [USE_NLS=yes
  101. AC_SUBST(USE_NLS)
  102. gt_cv_have_gettext=no
  103. CATOBJEXT=NONE
  104. XGETTEXT=:
  105. INTLLIBS=
  106. AC_CHECK_HEADER(libintl.h,
  107. [gt_cv_func_dgettext_libintl="no"
  108. libintl_extra_libs=""
  109. #
  110. # First check in libc
  111. #
  112. AC_CACHE_CHECK([for ngettext in libc], gt_cv_func_ngettext_libc,
  113. [AC_TRY_LINK([
  114. #include <libintl.h>
  115. ],
  116. [return !ngettext ("","", 1)],
  117. gt_cv_func_ngettext_libc=yes,
  118. gt_cv_func_ngettext_libc=no)
  119. ])
  120. if test "$gt_cv_func_ngettext_libc" = "yes" ; then
  121. AC_CACHE_CHECK([for dgettext in libc], gt_cv_func_dgettext_libc,
  122. [AC_TRY_LINK([
  123. #include <libintl.h>
  124. ],
  125. [return !dgettext ("","")],
  126. gt_cv_func_dgettext_libc=yes,
  127. gt_cv_func_dgettext_libc=no)
  128. ])
  129. fi
  130. if test "$gt_cv_func_ngettext_libc" = "yes" ; then
  131. AC_CHECK_FUNCS(bind_textdomain_codeset)
  132. fi
  133. #
  134. # If we don't have everything we want, check in libintl
  135. #
  136. if test "$gt_cv_func_dgettext_libc" != "yes" \
  137. || test "$gt_cv_func_ngettext_libc" != "yes" \
  138. || test "$ac_cv_func_bind_textdomain_codeset" != "yes" ; then
  139. AC_CHECK_LIB(intl, bindtextdomain,
  140. [AC_CHECK_LIB(intl, ngettext,
  141. [AC_CHECK_LIB(intl, dgettext,
  142. gt_cv_func_dgettext_libintl=yes)])])
  143. if test "$gt_cv_func_dgettext_libintl" != "yes" ; then
  144. AC_MSG_CHECKING([if -liconv is needed to use gettext])
  145. AC_MSG_RESULT([])
  146. AC_CHECK_LIB(intl, ngettext,
  147. [AC_CHECK_LIB(intl, dcgettext,
  148. [gt_cv_func_dgettext_libintl=yes
  149. libintl_extra_libs=-liconv],
  150. :,-liconv)],
  151. :,-liconv)
  152. fi
  153. #
  154. # If we found libintl, then check in it for bind_textdomain_codeset();
  155. # we'll prefer libc if neither have bind_textdomain_codeset(),
  156. # and both have dgettext and ngettext
  157. #
  158. if test "$gt_cv_func_dgettext_libintl" = "yes" ; then
  159. glib_save_LIBS="$LIBS"
  160. LIBS="$LIBS -lintl $libintl_extra_libs"
  161. unset ac_cv_func_bind_textdomain_codeset
  162. AC_CHECK_FUNCS(bind_textdomain_codeset)
  163. LIBS="$glib_save_LIBS"
  164. if test "$ac_cv_func_bind_textdomain_codeset" = "yes" ; then
  165. gt_cv_func_dgettext_libc=no
  166. else
  167. if test "$gt_cv_func_dgettext_libc" = "yes" \
  168. && test "$gt_cv_func_ngettext_libc" = "yes"; then
  169. gt_cv_func_dgettext_libintl=no
  170. fi
  171. fi
  172. fi
  173. fi
  174. if test "$gt_cv_func_dgettext_libc" = "yes" \
  175. || test "$gt_cv_func_dgettext_libintl" = "yes"; then
  176. gt_cv_have_gettext=yes
  177. fi
  178. if test "$gt_cv_func_dgettext_libintl" = "yes"; then
  179. INTLLIBS="-lintl $libintl_extra_libs"
  180. fi
  181. if test "$gt_cv_have_gettext" = "yes"; then
  182. AC_DEFINE(HAVE_GETTEXT,1,
  183. [Define if the GNU gettext() function is already present or preinstalled.])
  184. GLIB_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
  185. [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
  186. if test "$MSGFMT" != "no"; then
  187. glib_save_LIBS="$LIBS"
  188. LIBS="$LIBS $INTLLIBS"
  189. AC_CHECK_FUNCS(dcgettext)
  190. MSGFMT_OPTS=
  191. AC_MSG_CHECKING([if msgfmt accepts -c])
  192. GLIB_RUN_PROG([$MSGFMT -c -o /dev/null],[
  193. msgid ""
  194. msgstr ""
  195. "Content-Type: text/plain; charset=UTF-8\n"
  196. "Project-Id-Version: test 1.0\n"
  197. "PO-Revision-Date: 2007-02-15 12:01+0100\n"
  198. "Last-Translator: test <foo@bar.xx>\n"
  199. "Language-Team: C <LL@li.org>\n"
  200. "MIME-Version: 1.0\n"
  201. "Content-Transfer-Encoding: 8bit\n"
  202. ], [MSGFMT_OPTS=-c; AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
  203. AC_SUBST(MSGFMT_OPTS)
  204. AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
  205. GLIB_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
  206. [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
  207. AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
  208. return _nl_msg_cat_cntr],
  209. [CATOBJEXT=.gmo
  210. DATADIRNAME=share],
  211. [case $host in
  212. *-*-solaris*)
  213. dnl On Solaris, if bind_textdomain_codeset is in libc,
  214. dnl GNU format message catalog is always supported,
  215. dnl since both are added to the libc all together.
  216. dnl Hence, we'd like to go with DATADIRNAME=share and
  217. dnl and CATOBJEXT=.gmo in this case.
  218. AC_CHECK_FUNC(bind_textdomain_codeset,
  219. [CATOBJEXT=.gmo
  220. DATADIRNAME=share],
  221. [CATOBJEXT=.mo
  222. DATADIRNAME=lib])
  223. ;;
  224. *-*-openbsd*)
  225. CATOBJEXT=.mo
  226. DATADIRNAME=share
  227. ;;
  228. *-*-musl* | *-*-linux-uclibc*)
  229. CATOBJEXT=.gmo
  230. DATADIRNAME=share
  231. ;;
  232. *)
  233. CATOBJEXT=.mo
  234. DATADIRNAME=lib
  235. ;;
  236. esac])
  237. LIBS="$glib_save_LIBS"
  238. INSTOBJEXT=.mo
  239. else
  240. gt_cv_have_gettext=no
  241. fi
  242. fi
  243. ])
  244. if test "$gt_cv_have_gettext" = "yes" ; then
  245. AC_DEFINE(ENABLE_NLS, 1,
  246. [always defined to indicate that i18n is enabled])
  247. fi
  248. dnl Test whether we really found GNU xgettext.
  249. if test "$XGETTEXT" != ":"; then
  250. dnl If it is not GNU xgettext we define it as : so that the
  251. dnl Makefiles still can work.
  252. if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
  253. : ;
  254. else
  255. AC_MSG_RESULT(
  256. [found xgettext program is not GNU xgettext; ignore it])
  257. XGETTEXT=":"
  258. fi
  259. fi
  260. # We need to process the po/ directory.
  261. POSUB=po
  262. AC_OUTPUT_COMMANDS(
  263. [case "$CONFIG_FILES" in *po/Makefile.in*)
  264. sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
  265. esac])
  266. dnl These rules are solely for the distribution goal. While doing this
  267. dnl we only have to keep exactly one list of the available catalogs
  268. dnl in configure.ac.
  269. for lang in $ALL_LINGUAS; do
  270. GMOFILES="$GMOFILES $lang.gmo"
  271. POFILES="$POFILES $lang.po"
  272. done
  273. dnl Make all variables we use known to autoconf.
  274. AC_SUBST(CATALOGS)
  275. AC_SUBST(CATOBJEXT)
  276. AC_SUBST(DATADIRNAME)
  277. AC_SUBST(GMOFILES)
  278. AC_SUBST(INSTOBJEXT)
  279. AC_SUBST(INTLLIBS)
  280. AC_SUBST(PO_IN_DATADIR_TRUE)
  281. AC_SUBST(PO_IN_DATADIR_FALSE)
  282. AC_SUBST(POFILES)
  283. AC_SUBST(POSUB)
  284. ])
  285. # AM_GLIB_GNU_GETTEXT
  286. # -------------------
  287. # Do checks necessary for use of gettext. If a suitable implementation
  288. # of gettext is found in either in libintl or in the C library,
  289. # it will set INTLLIBS to the libraries needed for use of gettext
  290. # and AC_DEFINE() HAVE_GETTEXT and ENABLE_NLS. (The shell variable
  291. # gt_cv_have_gettext will be set to "yes".) It will also call AC_SUBST()
  292. # on various variables needed by the Makefile.in.in installed by
  293. # glib-gettextize.
  294. dnl
  295. AU_DEFUN([GLIB_GNU_GETTEXT],
  296. [AC_REQUIRE([AC_PROG_CC])dnl
  297. GLIB_LC_MESSAGES
  298. GLIB_WITH_NLS
  299. if test "$gt_cv_have_gettext" = "yes"; then
  300. if test "x$ALL_LINGUAS" = "x"; then
  301. LINGUAS=
  302. else
  303. AC_MSG_CHECKING(for catalogs to be installed)
  304. NEW_LINGUAS=
  305. for presentlang in $ALL_LINGUAS; do
  306. useit=no
  307. if test "%UNSET%" != "${LINGUAS-%UNSET%}"; then
  308. desiredlanguages="$LINGUAS"
  309. else
  310. desiredlanguages="$ALL_LINGUAS"
  311. fi
  312. for desiredlang in $desiredlanguages; do
  313. # Use the presentlang catalog if desiredlang is
  314. # a. equal to presentlang, or
  315. # b. a variant of presentlang (because in this case,
  316. # presentlang can be used as a fallback for messages
  317. # which are not translated in the desiredlang catalog).
  318. case "$desiredlang" in
  319. "$presentlang"*) useit=yes;;
  320. esac
  321. done
  322. if test $useit = yes; then
  323. NEW_LINGUAS="$NEW_LINGUAS $presentlang"
  324. fi
  325. done
  326. LINGUAS=$NEW_LINGUAS
  327. AC_MSG_RESULT($LINGUAS)
  328. fi
  329. dnl Construct list of names of catalog files to be constructed.
  330. if test -n "$LINGUAS"; then
  331. for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
  332. fi
  333. fi
  334. dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
  335. dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
  336. dnl Try to locate is.
  337. MKINSTALLDIRS=
  338. if test -n "$ac_aux_dir"; then
  339. MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
  340. fi
  341. if test -z "$MKINSTALLDIRS"; then
  342. MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
  343. fi
  344. AC_SUBST(MKINSTALLDIRS)
  345. dnl Generate list of files to be processed by xgettext which will
  346. dnl be included in po/Makefile.
  347. test -d po || mkdir po
  348. if test "x$srcdir" != "x."; then
  349. if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
  350. posrcprefix="$srcdir/"
  351. else
  352. posrcprefix="../$srcdir/"
  353. fi
  354. else
  355. posrcprefix="../"
  356. fi
  357. rm -f po/POTFILES
  358. sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
  359. < $srcdir/po/POTFILES.in > po/POTFILES
  360. ],
  361. [[$0: This macro is deprecated. You should use upstream gettext instead.]])
  362. # AM_GLIB_DEFINE_LOCALEDIR(VARIABLE)
  363. # -------------------------------
  364. # Define VARIABLE to the location where catalog files will
  365. # be installed by po/Makefile.
  366. glib_DEFUN([GLIB_DEFINE_LOCALEDIR],
  367. [glib_REQUIRE([GLIB_GNU_GETTEXT])dnl
  368. glib_save_prefix="$prefix"
  369. glib_save_exec_prefix="$exec_prefix"
  370. glib_save_datarootdir="$datarootdir"
  371. test "x$prefix" = xNONE && prefix=$ac_default_prefix
  372. test "x$exec_prefix" = xNONE && exec_prefix=$prefix
  373. datarootdir=`eval echo "${datarootdir}"`
  374. if test "x$CATOBJEXT" = "x.mo" ; then
  375. localedir=`eval echo "${libdir}/locale"`
  376. else
  377. localedir=`eval echo "${datadir}/locale"`
  378. fi
  379. prefix="$glib_save_prefix"
  380. exec_prefix="$glib_save_exec_prefix"
  381. datarootdir="$glib_save_datarootdir"
  382. AC_DEFINE_UNQUOTED($1, "$localedir",
  383. [Define the location where the catalogs will be installed])
  384. ])
  385. dnl
  386. dnl Now the definitions that aclocal will find
  387. dnl
  388. ifdef(glib_configure_ac,[],[
  389. AC_DEFUN([AM_GLIB_GNU_GETTEXT],[GLIB_GNU_GETTEXT($@)])
  390. AC_DEFUN([AM_GLIB_DEFINE_LOCALEDIR],[GLIB_DEFINE_LOCALEDIR($@)])
  391. ])dnl
  392. # GLIB_RUN_PROG(PROGRAM, TEST-FILE, [ACTION-IF-PASS], [ACTION-IF-FAIL])
  393. #
  394. # Create a temporary file with TEST-FILE as its contents and pass the
  395. # file name to PROGRAM. Perform ACTION-IF-PASS if PROGRAM exits with
  396. # 0 and perform ACTION-IF-FAIL for any other exit status.
  397. AC_DEFUN([GLIB_RUN_PROG],
  398. [cat >conftest.foo <<_ACEOF
  399. $2
  400. _ACEOF
  401. if AC_RUN_LOG([$1 conftest.foo]); then
  402. m4_ifval([$3], [$3], [:])
  403. m4_ifvaln([$4], [else $4])dnl
  404. echo "$as_me: failed input was:" >&AS_MESSAGE_LOG_FD
  405. sed 's/^/| /' conftest.foo >&AS_MESSAGE_LOG_FD
  406. fi])