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