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