glib-gettext.m4 15 KB

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