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