1 # Macro to add for using GNU gettext.
2 # Ulrich Drepper <drepper@cygnus.com>, 1995.
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.
11 AC_PREREQ(2.13) dnl Minimum Autoconf version required.
14 [AC_MSG_CHECKING([whether NLS is requested])
15 dnl Default is enabled NLS
17 [ --disable-nls do not use Native Language Support],
18 USE_NLS=$enableval, USE_NLS=yes)
19 AC_MSG_RESULT($USE_NLS)
22 USE_INCLUDED_LIBINTL=no
24 dnl If we use NLS figure out what method
25 if test "$USE_NLS" = "yes"; then
26 AC_DEFINE(ENABLE_NLS, 1, [Define to 1 if NLS is requested.])
27 AC_MSG_CHECKING([whether included gettext is requested])
28 AC_ARG_WITH(included-gettext,
29 [ --with-included-gettext use the GNU gettext library included here],
30 nls_cv_force_use_gnu_gettext=$withval,
31 nls_cv_force_use_gnu_gettext=no)
32 AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
34 nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
35 if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
36 dnl User does not insist on using GNU NLS library. Figure out what
37 dnl to use. If gettext or catgets are available (in this order) we
38 dnl use this. Else we have to fall back to GNU NLS library.
39 dnl catgets is only used if permitted by option --with-catgets.
44 AC_CHECK_HEADER(libintl.h,
45 [AC_CACHE_CHECK([for gettext in libc], gt_cv_func_gettext_libc,
46 [AC_TRY_LINK([#include <libintl.h>], [return (int) gettext ("")],
47 gt_cv_func_gettext_libc=yes, gt_cv_func_gettext_libc=no)])
49 if test "$gt_cv_func_gettext_libc" != "yes"; then
50 AC_CHECK_LIB(intl, bindtextdomain,
51 [AC_CACHE_CHECK([for gettext in libintl],
52 gt_cv_func_gettext_libintl,
53 [AC_CHECK_LIB(intl, gettext,
54 gt_cv_func_gettext_libintl=yes,
55 gt_cv_func_gettext_libintl=no)],
56 gt_cv_func_gettext_libintl=no)])
58 if test "$gt_cv_func_gettext_libintl" = yes; then
64 if test "$gt_cv_func_gettext_libc" = "yes" \
65 || test "$gt_cv_func_gettext_libintl" = "yes"; then
66 AC_DEFINE(HAVE_GETTEXT, 1,
67 [Define to 1 if you have gettext and don't want to use GNU gettext.])
68 AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
69 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
70 if test "$MSGFMT" != "no"; then
71 AC_CHECK_FUNCS(dcgettext)
72 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
73 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
74 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
75 AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
76 return _nl_msg_cat_cntr],
86 if test "$CATOBJEXT" = "NONE"; then
87 AC_MSG_CHECKING([whether catgets can be used])
89 [ --with-catgets use catgets functions if available],
90 nls_cv_use_catgets=$withval, nls_cv_use_catgets=no)
91 AC_MSG_RESULT($nls_cv_use_catgets)
93 if test "$nls_cv_use_catgets" = "yes"; then
94 dnl No gettext in C library. Try catgets next.
96 AC_CHECK_FUNC(catgets,
97 [AC_DEFINE(HAVE_CATGETS, 1,
98 [Define as 1 if you have catgets and don't want to use GNU gettext.])
99 INTLOBJS="\$(CATOBJS)"
100 AC_PATH_PROG(GENCAT, gencat, no)dnl
101 if test "$GENCAT" != "no"; then
102 AC_PATH_PROG(GMSGFMT, gmsgfmt, no)
103 if test "$GMSGFMT" = "no"; then
104 AM_PATH_PROG_WITH_TEST(GMSGFMT, msgfmt,
105 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)
107 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
108 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
109 USE_INCLUDED_LIBINTL=yes
113 INTLDEPS='$(top_builddir)/intl/libintl.a'
115 LIBS=`echo $LIBS | sed -e 's/-lintl//'`
116 nls_cv_header_intl=intl/libintl.h
117 nls_cv_header_libgt=intl/libgettext.h
122 if test "$CATOBJEXT" = "NONE"; then
123 dnl Neither gettext nor catgets in included in the C library.
124 dnl Fall back on GNU gettext library.
125 nls_cv_use_gnu_gettext=yes
129 if test "$nls_cv_use_gnu_gettext" = "yes"; then
130 dnl Mark actions used to generate GNU NLS library.
131 INTLOBJS="\$(GETTOBJS)"
132 AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
133 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], msgfmt)
134 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
135 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
136 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
138 USE_INCLUDED_LIBINTL=yes
142 INTLDEPS='$(top_builddir)/intl/libintl.a'
144 LIBS=`echo $LIBS | sed -e 's/-lintl//'`
145 nls_cv_header_intl=intl/libintl.h
146 nls_cv_header_libgt=intl/libgettext.h
149 dnl Test whether we really found GNU xgettext.
150 if test "$XGETTEXT" != ":"; then
151 dnl If it is no GNU xgettext we define it as : so that the
152 dnl Makefiles still can work.
153 if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
157 [found xgettext program is not GNU xgettext; ignore it])
162 # We need to process the po/ directory.
166 nls_cv_header_intl=intl/libintl.h
167 nls_cv_header_libgt=intl/libgettext.h
169 if test -z "$nsl_cv_header_intl"; then
170 # Clean out junk possibly left behind by a previous configuration.
173 AC_LINK_FILES($nls_cv_header_libgt, $nls_cv_header_intl)
175 [case "$CONFIG_FILES" in *po/Makefile.in*)
176 sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
180 # If this is used in GNU gettext we have to set USE_NLS to `yes'
181 # because some of the sources are only built for this goal.
182 if test "$PACKAGE" = gettext; then
184 USE_INCLUDED_LIBINTL=yes
187 dnl These rules are solely for the distribution goal. While doing this
188 dnl we only have to keep exactly one list of the available catalogs
190 for lang in $ALL_LINGUAS; do
191 GMOFILES="$GMOFILES $lang.gmo"
192 POFILES="$POFILES $lang.po"
195 dnl Make all variables we use known to autoconf.
196 AC_SUBST(USE_INCLUDED_LIBINTL)
199 AC_SUBST(DATADIRNAME)
209 AC_DEFUN(AM_GNU_GETTEXT,
210 [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
211 AC_REQUIRE([AC_PROG_CC])dnl
212 AC_REQUIRE([AC_PROG_RANLIB])dnl
213 AC_REQUIRE([AC_ISC_POSIX])dnl
214 AC_REQUIRE([AC_HEADER_STDC])dnl
215 AC_REQUIRE([AC_C_CONST])dnl
216 AC_REQUIRE([AC_C_INLINE])dnl
217 AC_REQUIRE([AC_TYPE_OFF_T])dnl
218 AC_REQUIRE([AC_TYPE_SIZE_T])dnl
219 AC_REQUIRE([AC_FUNC_ALLOCA])dnl
220 AC_REQUIRE([AC_FUNC_MMAP])dnl
222 AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
223 unistd.h sys/param.h])
224 AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
225 strdup __argz_count __argz_stringify __argz_next])
227 if test "${ac_cv_func_stpcpy+set}" != "set"; then
228 AC_CHECK_FUNCS(stpcpy)
230 if test "${ac_cv_func_stpcpy}" = "yes"; then
231 AC_DEFINE(HAVE_STPCPY, 1, [Define to 1 if you have the stpcpy function.])
237 if test "x$CATOBJEXT" != "x"; then
238 if test "x$ALL_LINGUAS" = "x"; then
241 AC_MSG_CHECKING(for catalogs to be installed)
243 for lang in ${LINGUAS=$ALL_LINGUAS}; do
244 case "$ALL_LINGUAS" in
245 *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
249 AC_MSG_RESULT($LINGUAS)
252 dnl Construct list of names of catalog files to be constructed.
253 if test -n "$LINGUAS"; then
254 for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
258 dnl The reference to <locale.h> in the installed <libintl.h> file
259 dnl must be resolved because we cannot expect the users of this
260 dnl to define HAVE_LOCALE_H.
261 if test $ac_cv_header_locale_h = yes; then
262 INCLUDE_LOCALE_H="#include <locale.h>"
265 /* The system does not provide the header <locale.h>. Take care yourself. */"
267 AC_SUBST(INCLUDE_LOCALE_H)
269 dnl Determine which catalog format we have (if any is needed)
270 dnl For now we know about two different formats:
271 dnl Linux libc-5 and the normal X/Open format
272 test -d intl || mkdir intl
273 if test "$CATOBJEXT" = ".cat"; then
274 AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
276 dnl Transform the SED scripts while copying because some dumb SEDs
277 dnl cannot handle comments.
278 sed -e '/^#/d' $srcdir/intl/$msgformat-msg.sed > intl/po2msg.sed
280 dnl po2tbl.sed is always needed.
281 sed -e '/^#.*[^\\]$/d' -e '/^#$/d' \
282 $srcdir/intl/po2tbl.sed.in > intl/po2tbl.sed
284 dnl In the intl/Makefile.in we have a special dependency which makes
285 dnl only sense for gettext. We comment this out for non-gettext
287 if test "$PACKAGE" = "gettext"; then
297 dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
298 dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
299 dnl Try to locate is.
301 if test -n "$ac_aux_dir"; then
302 MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
304 if test -z "$MKINSTALLDIRS"; then
305 MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
307 AC_SUBST(MKINSTALLDIRS)
309 dnl *** For now the libtool support in intl/Makefile is not for real.
313 dnl Generate list of files to be processed by xgettext which will
314 dnl be included in po/Makefile.
315 test -d po || mkdir po
316 if test "x$srcdir" != "x."; then
318 if test "x`echo $srcdir | sed -e 's@^[A-z]:@@' -e 's@/.*@@'`" = "x"; then
319 posrcprefix="$srcdir/"
321 posrcprefix="../$srcdir/"
328 sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
329 < $srcdir/po/POTFILES.in > po/POTFILES