blob: 09bf009bd04d5b351f5a7e8ed622bb3a1aab7fc6 [file] [log] [blame]
Theodore Ts'oa64c9c12000-02-08 20:17:21 +00001# Macro to add for using GNU gettext.
2# Ulrich Drepper <drepper@cygnus.com>, 1995.
3#
4# This file can be copied and used freely without restrictions. It can
5# be used in projects which are not available under the GNU Public License
6# but which still want to provide support for the GNU gettext functionality.
7# Please note that the actual code is *not* freely available.
8
9# serial 5
10
11AC_DEFUN(AM_WITH_NLS,
12 [AC_MSG_CHECKING([whether NLS is requested])
13 dnl Default is enabled NLS
14 AC_ARG_ENABLE(nls,
15 [ --enable-nls Turn on Native Language Support],
16 USE_NLS=$enableval, USE_NLS=no)
17 AC_MSG_RESULT($USE_NLS)
18 AC_SUBST(USE_NLS)
19
20 USE_INCLUDED_LIBINTL=no
21
22 dnl If we use NLS figure out what method
23 if test "$USE_NLS" = "yes"; then
24 AC_DEFINE(ENABLE_NLS)
25 AC_MSG_CHECKING([whether included gettext is requested])
26 AC_ARG_WITH(included-gettext,
27 [ --with-included-gettext use the GNU gettext library included here],
28 nls_cv_force_use_gnu_gettext=$withval,
29 nls_cv_force_use_gnu_gettext=no)
30 AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
31
32 nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
33 if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
34 dnl User does not insist on using GNU NLS library. Figure out what
35 dnl to use. If gettext or catgets are available (in this order) we
36 dnl use this. Else we have to fall back to GNU NLS library.
37 dnl catgets is only used if permitted by option --with-catgets.
38 nls_cv_header_intl=
39 nls_cv_header_libgt=
40 CATOBJEXT=NONE
41
42 AC_CHECK_HEADER(libintl.h,
43 [AC_CACHE_CHECK([for gettext in libc], gt_cv_func_gettext_libc,
44 [AC_TRY_LINK([#include <libintl.h>], [return (int) gettext ("")],
45 gt_cv_func_gettext_libc=yes, gt_cv_func_gettext_libc=no)])
46
47 if test "$gt_cv_func_gettext_libc" != "yes"; then
48 AC_CHECK_LIB(intl, bindtextdomain,
49 [AC_CACHE_CHECK([for gettext in libintl],
50 gt_cv_func_gettext_libintl,
51 [AC_CHECK_LIB(intl, gettext,
52 gt_cv_func_gettext_libintl=yes,
53 gt_cv_func_gettext_libintl=no)],
54 gt_cv_func_gettext_libintl=no)])
55 fi
56
57 if test "$gt_cv_func_gettext_libc" = "yes" \
58 || test "$gt_cv_func_gettext_libintl" = "yes"; then
59 AC_DEFINE(HAVE_GETTEXT)
60 AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
61 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
62 if test "$MSGFMT" != "no"; then
63 AC_CHECK_FUNCS(dcgettext)
64 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
65 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
66 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
67 AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
68 return _nl_msg_cat_cntr],
69 [CATOBJEXT=.gmo
70 DATADIRNAME=share],
71 [CATOBJEXT=.mo
72 DATADIRNAME=lib])
73 INSTOBJEXT=.mo
74 fi
75 fi
76 ])
77
78 if test "$CATOBJEXT" = "NONE"; then
79 AC_MSG_CHECKING([whether catgets can be used])
80 AC_ARG_WITH(catgets,
81 [ --with-catgets use catgets functions if available],
82 nls_cv_use_catgets=$withval, nls_cv_use_catgets=no)
83 AC_MSG_RESULT($nls_cv_use_catgets)
84
85 if test "$nls_cv_use_catgets" = "yes"; then
86 dnl No gettext in C library. Try catgets next.
87 AC_CHECK_LIB(i, main)
88 AC_CHECK_FUNC(catgets,
89 [AC_DEFINE(HAVE_CATGETS)
90 INTLOBJS="\$(CATOBJS)"
91 AC_PATH_PROG(GENCAT, gencat, no)dnl
92 if test "$GENCAT" != "no"; then
93 AC_PATH_PROG(GMSGFMT, gmsgfmt, no)
94 if test "$GMSGFMT" = "no"; then
95 AM_PATH_PROG_WITH_TEST(GMSGFMT, msgfmt,
96 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)
97 fi
98 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
99 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
100 USE_INCLUDED_LIBINTL=yes
101 CATOBJEXT=.cat
102 INSTOBJEXT=.cat
103 DATADIRNAME=lib
104 INTLDEPS='$(top_builddir)/intl/libintl.a'
105 INTLLIBS=$INTLDEPS
106 LIBS=`echo $LIBS | sed -e 's/-lintl//'`
107 nls_cv_header_intl=intl/libintl.h
108 nls_cv_header_libgt=intl/libgettext.h
109 fi])
110 fi
111 fi
112
113 if test "$CATOBJEXT" = "NONE"; then
114 dnl Neither gettext nor catgets in included in the C library.
115 dnl Fall back on GNU gettext library.
116 nls_cv_use_gnu_gettext=yes
117 fi
118 fi
119
120 if test "$nls_cv_use_gnu_gettext" = "yes"; then
121 dnl Mark actions used to generate GNU NLS library.
122 INTLOBJS="\$(GETTOBJS)"
123 AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
124 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], msgfmt)
125 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
126 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
127 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
128 AC_SUBST(MSGFMT)
129 USE_INCLUDED_LIBINTL=yes
130 CATOBJEXT=.gmo
131 INSTOBJEXT=.mo
132 DATADIRNAME=share
133 INTLDEPS='$(top_builddir)/intl/libintl.a'
134 INTLLIBS=$INTLDEPS
135 LIBS=`echo $LIBS | sed -e 's/-lintl//'`
136 nls_cv_header_intl=intl/libintl.h
137 nls_cv_header_libgt=intl/libgettext.h
138 fi
139
140 dnl Test whether we really found GNU xgettext.
141 if test "$XGETTEXT" != ":"; then
142 dnl If it is no GNU xgettext we define it as : so that the
143 dnl Makefiles still can work.
144 if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
145 : ;
146 else
147 AC_MSG_RESULT(
148 [found xgettext program is not GNU xgettext; ignore it])
149 XGETTEXT=":"
150 fi
151 fi
152
153 # We need to process the po/ directory.
154 POSUB=po
155 else
156 DATADIRNAME=share
157 nls_cv_header_intl=intl/libintl.h
158 nls_cv_header_libgt=intl/libgettext.h
159 fi
160 AC_LINK_FILES($nls_cv_header_libgt, $nls_cv_header_intl)
161 AC_OUTPUT_COMMANDS(
162 [case "$CONFIG_FILES" in *po/Makefile.in*)
163 sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
164 esac])
165
166
167 # If this is used in GNU gettext we have to set USE_NLS to `yes'
168 # because some of the sources are only built for this goal.
169 if test "$PACKAGE" = gettext; then
170 USE_NLS=yes
171 USE_INCLUDED_LIBINTL=yes
172 fi
173
174 dnl These rules are solely for the distribution goal. While doing this
175 dnl we only have to keep exactly one list of the available catalogs
176 dnl in configure.in.
177 for lang in $ALL_LINGUAS; do
178 GMOFILES="$GMOFILES $lang.gmo"
179 POFILES="$POFILES $lang.po"
180 done
181
182 dnl Make all variables we use known to autoconf.
183 AC_SUBST(USE_INCLUDED_LIBINTL)
184 AC_SUBST(CATALOGS)
185 AC_SUBST(CATOBJEXT)
186 AC_SUBST(DATADIRNAME)
187 AC_SUBST(GMOFILES)
188 AC_SUBST(INSTOBJEXT)
189 AC_SUBST(INTLDEPS)
190 AC_SUBST(INTLLIBS)
191 AC_SUBST(INTLOBJS)
192 AC_SUBST(POFILES)
193 AC_SUBST(POSUB)
194 ])
195
196AC_DEFUN(AM_GNU_GETTEXT,
197 [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
198 AC_REQUIRE([AC_PROG_CC])dnl
199 AC_REQUIRE([AC_PROG_RANLIB])dnl
200 AC_REQUIRE([AC_ISC_POSIX])dnl
201 AC_REQUIRE([AC_HEADER_STDC])dnl
202 AC_REQUIRE([AC_C_CONST])dnl
203 AC_REQUIRE([AC_C_INLINE])dnl
204 AC_REQUIRE([AC_TYPE_OFF_T])dnl
205 AC_REQUIRE([AC_TYPE_SIZE_T])dnl
206 AC_REQUIRE([AC_FUNC_ALLOCA])dnl
207 AC_REQUIRE([AC_FUNC_MMAP])dnl
208
209 AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
210unistd.h sys/param.h])
211 AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
212strdup __argz_count __argz_stringify __argz_next])
213
214 if test "${ac_cv_func_stpcpy+set}" != "set"; then
215 AC_CHECK_FUNCS(stpcpy)
216 fi
217 if test "${ac_cv_func_stpcpy}" = "yes"; then
218 AC_DEFINE(HAVE_STPCPY)
219 fi
220
221 AM_LC_MESSAGES
222 AM_WITH_NLS
223
224 if test "x$CATOBJEXT" != "x"; then
225 if test "x$ALL_LINGUAS" = "x"; then
226 LINGUAS=
227 else
228 AC_MSG_CHECKING(for catalogs to be installed)
229 NEW_LINGUAS=
230 for lang in ${LINGUAS=$ALL_LINGUAS}; do
231 case "$ALL_LINGUAS" in
232 *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
233 esac
234 done
235 LINGUAS=$NEW_LINGUAS
236 AC_MSG_RESULT($LINGUAS)
237 fi
238
239 dnl Construct list of names of catalog files to be constructed.
240 if test -n "$LINGUAS"; then
241 for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
242 fi
243 fi
244
245 dnl The reference to <locale.h> in the installed <libintl.h> file
246 dnl must be resolved because we cannot expect the users of this
247 dnl to define HAVE_LOCALE_H.
248 if test $ac_cv_header_locale_h = yes; then
249 INCLUDE_LOCALE_H="#include <locale.h>"
250 else
251 INCLUDE_LOCALE_H="\
252/* The system does not provide the header <locale.h>. Take care yourself. */"
253 fi
254 AC_SUBST(INCLUDE_LOCALE_H)
255
256 dnl Determine which catalog format we have (if any is needed)
257 dnl For now we know about two different formats:
258 dnl Linux libc-5 and the normal X/Open format
259 test -d intl || mkdir intl
260 if test "$CATOBJEXT" = ".cat"; then
261 AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
262
263 dnl Transform the SED scripts while copying because some dumb SEDs
264 dnl cannot handle comments.
265 sed -e '/^#/d' $srcdir/intl/$msgformat-msg.sed > intl/po2msg.sed
266 fi
267 dnl po2tbl.sed is always needed.
268 sed -e '/^#.*[^\\]$/d' -e '/^#$/d' \
269 $srcdir/intl/po2tbl.sed.in > intl/po2tbl.sed
270
271 dnl In the intl/Makefile.in we have a special dependency which makes
272 dnl only sense for gettext. We comment this out for non-gettext
273 dnl packages.
274 if test "$PACKAGE" = "gettext"; then
275 GT_NO="#NO#"
276 GT_YES=
277 else
278 GT_NO=
279 GT_YES="#YES#"
280 fi
281 AC_SUBST(GT_NO)
282 AC_SUBST(GT_YES)
283
284 dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
285 dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
286 dnl Try to locate is.
287 MKINSTALLDIRS=
288 if test -n "$ac_aux_dir"; then
289 MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
290 fi
291 if test -z "$MKINSTALLDIRS"; then
292 MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
293 fi
294 AC_SUBST(MKINSTALLDIRS)
295
296 dnl *** For now the libtool support in intl/Makefile is not for real.
297 l=
298 AC_SUBST(l)
299
300 dnl Generate list of files to be processed by xgettext which will
301 dnl be included in po/Makefile.
302 test -d po || mkdir po
303 if test "x$srcdir" != "x."; then
304 if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
305 posrcprefix="$srcdir/"
306 else
307 posrcprefix="../$srcdir/"
308 fi
309 else
310 posrcprefix="../"
311 fi
312 rm -f po/POTFILES
313 sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
314 < $srcdir/po/POTFILES.in > po/POTFILES
315 ])
316
317# Check whether LC_MESSAGES is available in <locale.h>.
318# Ulrich Drepper <drepper@cygnus.com>, 1995.
319#
320# This file can be copied and used freely without restrictions. It can
321# be used in projects which are not available under the GNU Public License
322# but which still want to provide support for the GNU gettext functionality.
323# Please note that the actual code is *not* freely available.
324
325# serial 1
326
327AC_DEFUN(AM_LC_MESSAGES,
328 [if test $ac_cv_header_locale_h = yes; then
329 AC_CACHE_CHECK([for LC_MESSAGES], am_cv_val_LC_MESSAGES,
330 [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES],
331 am_cv_val_LC_MESSAGES=yes, am_cv_val_LC_MESSAGES=no)])
332 if test $am_cv_val_LC_MESSAGES = yes; then
333 AC_DEFINE(HAVE_LC_MESSAGES)
334 fi
335 fi])
336
337# Search path for a program which passes the given test.
338# Ulrich Drepper <drepper@cygnus.com>, 1996.
339#
340# This file can be copied and used freely without restrictions. It can
341# be used in projects which are not available under the GNU Public License
342# but which still want to provide support for the GNU gettext functionality.
343# Please note that the actual code is *not* freely available.
344
345# serial 1
346
347dnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
348dnl TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
349AC_DEFUN(AM_PATH_PROG_WITH_TEST,
350[# Extract the first word of "$2", so it can be a program name with args.
351set dummy $2; ac_word=[$]2
352AC_MSG_CHECKING([for $ac_word])
353AC_CACHE_VAL(ac_cv_path_$1,
354[case "[$]$1" in
355 /*)
356 ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
357 ;;
358 *)
359 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
360 for ac_dir in ifelse([$5], , $PATH, [$5]); do
361 test -z "$ac_dir" && ac_dir=.
362 if test -f $ac_dir/$ac_word; then
363 if [$3]; then
364 ac_cv_path_$1="$ac_dir/$ac_word"
365 break
366 fi
367 fi
368 done
369 IFS="$ac_save_ifs"
370dnl If no 4th arg is given, leave the cache variable unset,
371dnl so AC_PATH_PROGS will keep looking.
372ifelse([$4], , , [ test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
373])dnl
374 ;;
375esac])dnl
376$1="$ac_cv_path_$1"
377if test -n "[$]$1"; then
378 AC_MSG_RESULT([$]$1)
379else
380 AC_MSG_RESULT(no)
381fi
382AC_SUBST($1)dnl
383])