glib-gettext.m4 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. # Copyright (C) 1995-2002 Free Software Foundation, Inc.
  2. # Copyright (C) 2001-2003 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. # We need this here as well, since someone might use autoconf-2.5x
  27. # to configure GLib then an older version to configure a package
  28. # using AM_GLIB_GNU_GETTEXT
  29. AC_PREREQ(2.53)
  30. dnl
  31. dnl We go to great lengths to make sure that aclocal won't
  32. dnl try to pull in the installed version of these macros
  33. dnl when running aclocal in the glib directory.
  34. dnl
  35. m4_copy([AC_DEFUN],[glib_DEFUN])
  36. m4_copy([AC_REQUIRE],[glib_REQUIRE])
  37. dnl
  38. dnl At the end, if we're not within glib, we'll define the public
  39. dnl definitions in terms of our private definitions.
  40. dnl
  41. # GLIB_LC_MESSAGES
  42. #--------------------
  43. glib_DEFUN([GLIB_LC_MESSAGES],
  44. [AC_CHECK_HEADERS([locale.h])
  45. if test $ac_cv_header_locale_h = yes; then
  46. AC_CACHE_CHECK([for LC_MESSAGES], am_cv_val_LC_MESSAGES,
  47. [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES],
  48. am_cv_val_LC_MESSAGES=yes, am_cv_val_LC_MESSAGES=no)])
  49. if test $am_cv_val_LC_MESSAGES = yes; then
  50. AC_DEFINE(HAVE_LC_MESSAGES, 1,
  51. [Define if your <locale.h> file defines LC_MESSAGES.])
  52. fi
  53. fi])
  54. # GLIB_PATH_PROG_WITH_TEST
  55. #----------------------------
  56. dnl GLIB_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
  57. dnl TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
  58. glib_DEFUN([GLIB_PATH_PROG_WITH_TEST],
  59. [# Extract the first word of "$2", so it can be a program name with args.
  60. set dummy $2; ac_word=[$]2
  61. AC_MSG_CHECKING([for $ac_word])
  62. AC_CACHE_VAL(ac_cv_path_$1,
  63. [case "[$]$1" in
  64. /*)
  65. ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
  66. ;;
  67. *)
  68. IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
  69. for ac_dir in ifelse([$5], , $PATH, [$5]); do
  70. test -z "$ac_dir" && ac_dir=.
  71. if test -f $ac_dir/$ac_word; then
  72. if [$3]; then
  73. ac_cv_path_$1="$ac_dir/$ac_word"
  74. break
  75. fi
  76. fi
  77. done
  78. IFS="$ac_save_ifs"
  79. dnl If no 4th arg is given, leave the cache variable unset,
  80. dnl so AC_PATH_PROGS will keep looking.
  81. ifelse([$4], , , [ test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
  82. ])dnl
  83. ;;
  84. esac])dnl
  85. $1="$ac_cv_path_$1"
  86. if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then
  87. AC_MSG_RESULT([$]$1)
  88. else
  89. AC_MSG_RESULT(no)
  90. fi
  91. AC_SUBST($1)dnl
  92. ])
  93. # GLIB_WITH_NLS
  94. #-----------------
  95. glib_DEFUN([GLIB_WITH_NLS],
  96. dnl NLS is obligatory
  97. [USE_NLS=yes
  98. AC_SUBST(USE_NLS)
  99. gt_cv_have_gettext=no
  100. CATOBJEXT=NONE
  101. XGETTEXT=:
  102. INTLLIBS=
  103. AC_CHECK_HEADER(libintl.h,
  104. [gt_cv_func_dgettext_libintl="no"
  105. libintl_extra_libs=""
  106. #
  107. # First check in libc
  108. #
  109. AC_CACHE_CHECK([for dgettext in libc], gt_cv_func_dgettext_libc,
  110. [AC_TRY_LINK([
  111. #include <libintl.h>
  112. ],
  113. [return (int) dgettext ("","")],
  114. gt_cv_func_dgettext_libc=yes,
  115. gt_cv_func_dgettext_libc=no)
  116. ])
  117. if test "$gt_cv_func_dgettext_libc" = "yes" ; then
  118. AC_CHECK_FUNCS(bind_textdomain_codeset)
  119. fi
  120. #
  121. # If we don't have everything we want, check in libintl
  122. #
  123. if test "$gt_cv_func_dgettext_libc" != "yes" \
  124. || test "$ac_cv_func_bind_textdomain_codeset" != "yes" ; then
  125. AC_CHECK_LIB(intl, bindtextdomain,
  126. [AC_CHECK_LIB(intl, dgettext,
  127. gt_cv_func_dgettext_libintl=yes)])
  128. if test "$gt_cv_func_dgettext_libintl" != "yes" ; then
  129. AC_MSG_CHECKING([if -liconv is needed to use gettext])
  130. AC_MSG_RESULT([])
  131. AC_CHECK_LIB(intl, dcgettext,
  132. [gt_cv_func_dgettext_libintl=yes
  133. libintl_extra_libs=-liconv],
  134. :,-liconv)
  135. fi
  136. #
  137. # If we found libintl, then check in it for bind_textdomain_codeset();
  138. # we'll prefer libc if neither have bind_textdomain_codeset(),
  139. # and both have dgettext
  140. #
  141. if test "$gt_cv_func_dgettext_libintl" = "yes" ; then
  142. glib_save_LIBS="$LIBS"
  143. LIBS="$LIBS -lintl $libintl_extra_libs"
  144. unset ac_cv_func_bind_textdomain_codeset
  145. AC_CHECK_FUNCS(bind_textdomain_codeset)
  146. LIBS="$glib_save_LIBS"
  147. if test "$ac_cv_func_bind_textdomain_codeset" = "yes" ; then
  148. gt_cv_func_dgettext_libc=no
  149. else
  150. if test "$gt_cv_func_dgettext_libc" = "yes"; then
  151. gt_cv_func_dgettext_libintl=no
  152. fi
  153. fi
  154. fi
  155. fi
  156. if test "$gt_cv_func_dgettext_libc" = "yes" \
  157. || test "$gt_cv_func_dgettext_libintl" = "yes"; then
  158. gt_cv_have_gettext=yes
  159. fi
  160. if test "$gt_cv_func_dgettext_libintl" = "yes"; then
  161. INTLLIBS="-lintl $libintl_extra_libs"
  162. fi
  163. if test "$gt_cv_have_gettext" = "yes"; then
  164. AC_DEFINE(HAVE_GETTEXT,1,
  165. [Define if the GNU gettext() function is already present or preinstalled.])
  166. GLIB_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
  167. [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
  168. if test "$MSGFMT" != "no"; then
  169. glib_save_LIBS="$LIBS"
  170. LIBS="$LIBS $INTLLIBS"
  171. AC_CHECK_FUNCS(dcgettext)
  172. AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
  173. GLIB_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
  174. [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
  175. AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
  176. return _nl_msg_cat_cntr],
  177. [CATOBJEXT=.gmo
  178. DATADIRNAME=share],
  179. [case $host in
  180. *-*-solaris*)
  181. dnl On Solaris, if bind_textdomain_codeset is in libc,
  182. dnl GNU format message catalog is always supported,
  183. dnl since both are added to the libc all together.
  184. dnl Hence, we'd like to go with DATADIRNAME=share and
  185. dnl and CATOBJEXT=.gmo in this case.
  186. AC_CHECK_FUNC(bind_textdomain_codeset,
  187. [CATOBJEXT=.gmo
  188. DATADIRNAME=share],
  189. [CATOBJEXT=.mo
  190. DATADIRNAME=lib])
  191. ;;
  192. *)
  193. CATOBJEXT=.mo
  194. DATADIRNAME=lib
  195. ;;
  196. esac])
  197. LIBS="$glib_save_LIBS"
  198. INSTOBJEXT=.mo
  199. else
  200. gt_cv_have_gettext=no
  201. fi
  202. fi
  203. ])
  204. if test "$gt_cv_have_gettext" = "yes" ; then
  205. AC_DEFINE(ENABLE_NLS, 1,
  206. [always defined to indicate that i18n is enabled])
  207. fi
  208. dnl Test whether we really found GNU xgettext.
  209. if test "$XGETTEXT" != ":"; then
  210. dnl If it is not GNU xgettext we define it as : so that the
  211. dnl Makefiles still can work.
  212. if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
  213. : ;
  214. else
  215. AC_MSG_RESULT(
  216. [found xgettext program is not GNU xgettext; ignore it])
  217. XGETTEXT=":"
  218. fi
  219. fi
  220. # We need to process the po/ directory.
  221. POSUB=po
  222. AC_OUTPUT_COMMANDS(
  223. [case "$CONFIG_FILES" in *po/Makefile.in*)
  224. sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
  225. esac])
  226. dnl These rules are solely for the distribution goal. While doing this
  227. dnl we only have to keep exactly one list of the available catalogs
  228. dnl in configure.in.
  229. for lang in $ALL_LINGUAS; do
  230. GMOFILES="$GMOFILES $lang.gmo"
  231. POFILES="$POFILES $lang.po"
  232. done
  233. dnl Make all variables we use known to autoconf.
  234. AC_SUBST(CATALOGS)
  235. AC_SUBST(CATOBJEXT)
  236. AC_SUBST(DATADIRNAME)
  237. AC_SUBST(GMOFILES)
  238. AC_SUBST(INSTOBJEXT)
  239. AC_SUBST(INTLLIBS)
  240. AC_SUBST(PO_IN_DATADIR_TRUE)
  241. AC_SUBST(PO_IN_DATADIR_FALSE)
  242. AC_SUBST(POFILES)
  243. AC_SUBST(POSUB)
  244. ])
  245. # AM_GLIB_GNU_GETTEXT
  246. # -------------------
  247. # Do checks necessary for use of gettext. If a suitable implementation
  248. # of gettext is found in either in libintl or in the C library,
  249. # it will set INTLLIBS to the libraries needed for use of gettext
  250. # and AC_DEFINE() HAVE_GETTEXT and ENABLE_NLS. (The shell variable
  251. # gt_cv_have_gettext will be set to "yes".) It will also call AC_SUBST()
  252. # on various variables needed by the Makefile.in.in installed by
  253. # glib-gettextize.
  254. dnl
  255. glib_DEFUN([GLIB_GNU_GETTEXT],
  256. [AC_REQUIRE([AC_PROG_CC])dnl
  257. AC_REQUIRE([AC_HEADER_STDC])dnl
  258. GLIB_LC_MESSAGES
  259. GLIB_WITH_NLS
  260. if test "$gt_cv_have_gettext" = "yes"; then
  261. if test "x$ALL_LINGUAS" = "x"; then
  262. LINGUAS=
  263. else
  264. AC_MSG_CHECKING(for catalogs to be installed)
  265. NEW_LINGUAS=
  266. for presentlang in $ALL_LINGUAS; do
  267. useit=no
  268. if test "%UNSET%" != "${LINGUAS-%UNSET%}"; then
  269. desiredlanguages="$LINGUAS"
  270. else
  271. desiredlanguages="$ALL_LINGUAS"
  272. fi
  273. for desiredlang in $desiredlanguages; do
  274. # Use the presentlang catalog if desiredlang is
  275. # a. equal to presentlang, or
  276. # b. a variant of presentlang (because in this case,
  277. # presentlang can be used as a fallback for messages
  278. # which are not translated in the desiredlang catalog).
  279. case "$desiredlang" in
  280. "$presentlang"*) useit=yes;;
  281. esac
  282. done
  283. if test $useit = yes; then
  284. NEW_LINGUAS="$NEW_LINGUAS $presentlang"
  285. fi
  286. done
  287. LINGUAS=$NEW_LINGUAS
  288. AC_MSG_RESULT($LINGUAS)
  289. fi
  290. dnl Construct list of names of catalog files to be constructed.
  291. if test -n "$LINGUAS"; then
  292. for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
  293. fi
  294. fi
  295. dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
  296. dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
  297. dnl Try to locate is.
  298. MKINSTALLDIRS=
  299. if test -n "$ac_aux_dir"; then
  300. MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
  301. fi
  302. if test -z "$MKINSTALLDIRS"; then
  303. MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
  304. fi
  305. AC_SUBST(MKINSTALLDIRS)
  306. dnl Generate list of files to be processed by xgettext which will
  307. dnl be included in po/Makefile.
  308. test -d po || mkdir po
  309. if test "x$srcdir" != "x."; then
  310. if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
  311. posrcprefix="$srcdir/"
  312. else
  313. posrcprefix="../$srcdir/"
  314. fi
  315. else
  316. posrcprefix="../"
  317. fi
  318. rm -f po/POTFILES
  319. sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
  320. < $srcdir/po/POTFILES.in > po/POTFILES
  321. ])
  322. # AM_GLIB_DEFINE_LOCALEDIR(VARIABLE)
  323. # -------------------------------
  324. # Define VARIABLE to the location where catalog files will
  325. # be installed by po/Makefile.
  326. glib_DEFUN([GLIB_DEFINE_LOCALEDIR],
  327. [glib_REQUIRE([GLIB_GNU_GETTEXT])dnl
  328. glib_save_prefix="$prefix"
  329. glib_save_exec_prefix="$exec_prefix"
  330. test "x$prefix" = xNONE && prefix=$ac_default_prefix
  331. test "x$exec_prefix" = xNONE && exec_prefix=$prefix
  332. if test "x$CATOBJEXT" = "x.mo" ; then
  333. localedir=`eval echo "${libdir}/locale"`
  334. else
  335. localedir=`eval echo "${datadir}/locale"`
  336. fi
  337. prefix="$glib_save_prefix"
  338. exec_prefix="$glib_save_exec_prefix"
  339. AC_DEFINE_UNQUOTED($1, "$localedir",
  340. [Define the location where the catalogs will be installed])
  341. ])
  342. dnl
  343. dnl Now the definitions that aclocal will find
  344. dnl
  345. ifdef(glib_configure_in,[],[
  346. AC_DEFUN([AM_GLIB_GNU_GETTEXT],[GLIB_GNU_GETTEXT($@)])
  347. AC_DEFUN([AM_GLIB_DEFINE_LOCALEDIR],[GLIB_DEFINE_LOCALEDIR($@)])
  348. ])dnl