Changes the location of bison.simple after running bison on local
[findutils.git] / m4 / gettext.m4
blob05358c480c9d1645edf3add9e8417a31bdfdcddf
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.
9 # serial 9
11 dnl Usage: AM_WITH_NLS([TOOLSYMBOL], [NEEDSYMBOL], [LIBDIR]).
12 dnl If TOOLSYMBOL is specified and is 'use-libtool', then a libtool library
13 dnl    $(top_builddir)/intl/libintl.la will be created (shared and/or static,
14 dnl    depending on --{enable,disable}-{shared,static} and on the presence of
15 dnl    AM-DISABLE-SHARED). Otherwise, a static library
16 dnl    $(top_builddir)/intl/libintl.a will be created.
17 dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
18 dnl    implementations (in libc or libintl) without the ngettext() function
19 dnl    will be ignored.
20 dnl LIBDIR is used to find the intl libraries.  If empty,
21 dnl    the value `$(top_builddir)/intl/' is used.
22 dnl
23 dnl The result of the configuration is one of three cases:
24 dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled
25 dnl    and used.
26 dnl    Catalog format: GNU --> install in $(datadir)
27 dnl    Catalog extension: .mo after installation, .gmo in source tree
28 dnl 2) GNU gettext has been found in the system's C library.
29 dnl    Catalog format: GNU --> install in $(datadir)
30 dnl    Catalog extension: .mo after installation, .gmo in source tree
31 dnl 3) No internationalization, always use English msgid.
32 dnl    Catalog format: none
33 dnl    Catalog extension: none
34 dnl The use of .gmo is historical (it was needed to avoid overwriting the
35 dnl GNU format catalogs when building on a platform with an X/Open gettext),
36 dnl but we keep it in order not to force irrelevant filename changes on the
37 dnl maintainers.
38 dnl
39 AC_DEFUN([AM_WITH_NLS],
40   [AC_MSG_CHECKING([whether NLS is requested])
41     dnl Default is enabled NLS
42     AC_ARG_ENABLE(nls,
43       [  --disable-nls           do not use Native Language Support],
44       USE_NLS=$enableval, USE_NLS=yes)
45     AC_MSG_RESULT($USE_NLS)
46     AC_SUBST(USE_NLS)
48     BUILD_INCLUDED_LIBINTL=no
49     USE_INCLUDED_LIBINTL=no
50     INTLLIBS=
52     dnl If we use NLS figure out what method
53     if test "$USE_NLS" = "yes"; then
54       AC_DEFINE(ENABLE_NLS, 1,
55         [Define to 1 if translation of program messages to the user's native language
56    is requested.])
57       AC_MSG_CHECKING([whether included gettext is requested])
58       AC_ARG_WITH(included-gettext,
59         [  --with-included-gettext use the GNU gettext library included here],
60         nls_cv_force_use_gnu_gettext=$withval,
61         nls_cv_force_use_gnu_gettext=no)
62       AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
64       nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
65       if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
66         dnl User does not insist on using GNU NLS library.  Figure out what
67         dnl to use.  If GNU gettext is available we use this.  Else we have
68         dnl to fall back to GNU NLS library.
69         CATOBJEXT=NONE
71         dnl Add a version number to the cache macros.
72         define(gt_cv_func_gnugettext_libc, [gt_cv_func_gnugettext]ifelse([$2], need-ngettext, 2, 1)[_libc])
73         define(gt_cv_func_gnugettext_libintl, [gt_cv_func_gnugettext]ifelse([$2], need-ngettext, 2, 1)[_libintl])
75         AC_CHECK_HEADER(libintl.h,
76           [AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc,
77             [AC_TRY_LINK([#include <libintl.h>
78 extern int _nl_msg_cat_cntr;],
79                [bindtextdomain ("", "");
80 return (int) gettext ("")]ifelse([$2], need-ngettext, [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr],
81                gt_cv_func_gnugettext_libc=yes,
82                gt_cv_func_gnugettext_libc=no)])
84            if test "$gt_cv_func_gnugettext_libc" != "yes"; then
85              AC_CACHE_CHECK([for GNU gettext in libintl],
86                gt_cv_func_gnugettext_libintl,
87                [gt_save_LIBS="$LIBS"
88                 LIBS="$LIBS -lintl $LIBICONV"
89                 AC_TRY_LINK([#include <libintl.h>
90 extern int _nl_msg_cat_cntr;],
91                   [bindtextdomain ("", "");
92 return (int) gettext ("")]ifelse([$2], need-ngettext, [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr],
93                   gt_cv_func_gnugettext_libintl=yes,
94                   gt_cv_func_gnugettext_libintl=no)
95                 LIBS="$gt_save_LIBS"])
96            fi
98            dnl If an already present or preinstalled GNU gettext() is found,
99            dnl use it.  But if this macro is used in GNU gettext, and GNU
100            dnl gettext is already preinstalled in libintl, we update this
101            dnl libintl.  (Cf. the install rule in intl/Makefile.in.)
102            if test "$gt_cv_func_gnugettext_libc" = "yes" \
103               || { test "$gt_cv_func_gnugettext_libintl" = "yes" \
104                    && test "$PACKAGE" != gettext; }; then
105              AC_DEFINE(HAVE_GETTEXT, 1,
106                [Define if the GNU gettext() function is already present or preinstalled.])
108              if test "$gt_cv_func_gnugettext_libintl" = "yes"; then
109                dnl If iconv() is in a separate libiconv library, then anyone
110                dnl linking with libintl{.a,.so} also needs to link with
111                dnl libiconv.
112                INTLLIBS="-lintl $LIBICONV"
113              fi
115              gt_save_LIBS="$LIBS"
116              LIBS="$LIBS $INTLLIBS"
117              AC_CHECK_FUNCS(dcgettext)
118              LIBS="$gt_save_LIBS"
120              AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
121                [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
122              if test "$MSGFMT" != "no"; then
123                AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
124              fi
126              AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
127                [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
129              CATOBJEXT=.gmo
130            fi
131         ])
133         if test "$CATOBJEXT" = "NONE"; then
134           dnl GNU gettext is not found in the C library.
135           dnl Fall back on GNU gettext library.
136           nls_cv_use_gnu_gettext=yes
137         fi
138       fi
140       if test "$nls_cv_use_gnu_gettext" = "yes"; then
141         dnl Mark actions used to generate GNU NLS library.
142         INTLOBJS="\$(GETTOBJS)"
143         AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
144           [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], msgfmt)
145         AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
146         AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
147           [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
148         AC_SUBST(MSGFMT)
149         BUILD_INCLUDED_LIBINTL=yes
150         USE_INCLUDED_LIBINTL=yes
151         CATOBJEXT=.gmo
152         INTLLIBS="ifelse([$3],[],\$(top_builddir)/intl,[$3])/libintl.ifelse([$1], use-libtool, [l], [])a $LIBICONV"
153         LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
154       fi
156       dnl Test whether we really found GNU xgettext.
157       if test "$XGETTEXT" != ":"; then
158         dnl If it is no GNU xgettext we define it as : so that the
159         dnl Makefiles still can work.
160         if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
161           : ;
162         else
163           AC_MSG_RESULT(
164             [found xgettext program is not GNU xgettext; ignore it])
165           XGETTEXT=":"
166         fi
167       fi
169       dnl We need to process the po/ directory.
170       POSUB=po
171     fi
172     AC_OUTPUT_COMMANDS(
173      [for ac_file in $CONFIG_FILES; do
174         # Support "outfile[:infile[:infile...]]"
175         case "$ac_file" in
176           *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
177         esac
178         # PO directories have a Makefile.in generated from Makefile.in.in.
179         case "$ac_file" in */Makefile.in)
180           # Adjust a relative srcdir.
181           ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
182           ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
183           ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
184           case "$ac_given_srcdir" in
185             .)  top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
186             /*) top_srcdir="$ac_given_srcdir" ;;
187             *)  top_srcdir="$ac_dots$ac_given_srcdir" ;;
188           esac
189           if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then
190             rm -f "$ac_dir/POTFILES"
191             echo creating "$ac_dir/POTFILES"
192             sed -e "/^#/d" -e "/^[      ]*\$/d" -e "s,.*,     $top_srcdir/& \\\\," -e "\$s/\(.*\) \\\\/\1/" < "$ac_given_srcdir/$ac_dir/POTFILES.in" > "$ac_dir/POTFILES"
193             echo creating "$ac_dir/Makefile"
194             sed -e "/POTFILES =/r $ac_dir/POTFILES" "$ac_dir/Makefile.in" > "$ac_dir/Makefile"
195           fi
196           ;;
197         esac
198       done])
201     dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL
202     dnl to 'yes' because some of the testsuite requires it.
203     if test "$PACKAGE" = gettext; then
204       BUILD_INCLUDED_LIBINTL=yes
205     fi
207     dnl intl/plural.c is generated from intl/plural.y. It requires bison,
208     dnl because plural.y uses bison specific features. It requires at least
209     dnl bison-1.26 because earlier versions generate a plural.c that doesn't
210     dnl compile.
211     dnl bison is only needed for the maintainer (who touches plural.y). But in
212     dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put
213     dnl the rule in general Makefile. Now, some people carelessly touch the
214     dnl files or have a broken "make" program, hence the plural.c rule will
215     dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not
216     dnl present or too old.
217     AC_CHECK_PROGS([INTLBISON], [bison])
218     if test -z "$INTLBISON"; then
219       ac_verc_fail=yes
220     else
221       dnl Found it, now check the version.
222       AC_MSG_CHECKING([version of bison])
223 changequote(<<,>>)dnl
224       ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison .* \([0-9]*\.[0-9.]*\).*$/\1/p'`
225       case $ac_prog_version in
226         '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
227         1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*)
228 changequote([,])dnl
229            ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
230         *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
231       esac
232       AC_MSG_RESULT([$ac_prog_version])
233     fi
234     if test $ac_verc_fail = yes; then
235       INTLBISON=:
236     fi
238     dnl These rules are solely for the distribution goal.  While doing this
239     dnl we only have to keep exactly one list of the available catalogs
240     dnl in configure.in.
241     for lang in $ALL_LINGUAS; do
242       GMOFILES="$GMOFILES $lang.gmo"
243       POFILES="$POFILES $lang.po"
244     done
246     dnl Make all variables we use known to autoconf.
247     AC_SUBST(BUILD_INCLUDED_LIBINTL)
248     AC_SUBST(USE_INCLUDED_LIBINTL)
249     AC_SUBST(CATALOGS)
250     AC_SUBST(CATOBJEXT)
251     AC_SUBST(GMOFILES)
252     AC_SUBST(INTLLIBS)
253     AC_SUBST(INTLOBJS)
254     AC_SUBST(POFILES)
255     AC_SUBST(POSUB)
257     dnl For backward compatibility. Some configure.ins may be using this.
258     nls_cv_header_intl=
259     nls_cv_header_libgt=
261     dnl For backward compatibility. Some Makefiles may be using this.
262     DATADIRNAME=share
263     AC_SUBST(DATADIRNAME)
265     dnl For backward compatibility. Some Makefiles may be using this.
266     INSTOBJEXT=.mo
267     AC_SUBST(INSTOBJEXT)
269     dnl For backward compatibility. Some Makefiles may be using this.
270     GENCAT=gencat
271     AC_SUBST(GENCAT)
272   ])
274 dnl Usage: Just like AM_WITH_NLS, which see.
275 AC_DEFUN([AM_GNU_GETTEXT],
276   [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
277    AC_REQUIRE([AC_PROG_CC])dnl
278    AC_REQUIRE([AC_CANONICAL_HOST])dnl
279    AC_REQUIRE([AC_PROG_RANLIB])dnl
280    AC_REQUIRE([AC_ISC_POSIX])dnl
281    AC_REQUIRE([AC_HEADER_STDC])dnl
282    AC_REQUIRE([AC_C_CONST])dnl
283    AC_REQUIRE([AC_C_INLINE])dnl
284    AC_REQUIRE([AC_TYPE_OFF_T])dnl
285    AC_REQUIRE([AC_TYPE_SIZE_T])dnl
286    AC_REQUIRE([AC_FUNC_ALLOCA])dnl
287    AC_REQUIRE([AC_FUNC_MMAP])dnl
288    AC_REQUIRE([jm_GLIBC21])dnl
290    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \
291 stdlib.h string.h unistd.h sys/param.h])
292    AC_CHECK_FUNCS([feof_unlocked fgets_unlocked getcwd getegid geteuid \
293 getgid getuid mempcpy munmap putenv setenv setlocale stpcpy strchr strcasecmp \
294 strdup strtoul tsearch __argz_count __argz_stringify __argz_next])
296    AM_ICONV
297    AM_LANGINFO_CODESET
298    AM_LC_MESSAGES
299    AM_WITH_NLS([$1],[$2],[$3])
301    if test "x$CATOBJEXT" != "x"; then
302      if test "x$ALL_LINGUAS" = "x"; then
303        LINGUAS=
304      else
305        AC_MSG_CHECKING(for catalogs to be installed)
306        NEW_LINGUAS=
307        for presentlang in $ALL_LINGUAS; do
308          useit=no
309          for desiredlang in ${LINGUAS-$ALL_LINGUAS}; do
310            # Use the presentlang catalog if desiredlang is
311            #   a. equal to presentlang, or
312            #   b. a variant of presentlang (because in this case,
313            #      presentlang can be used as a fallback for messages
314            #      which are not translated in the desiredlang catalog).
315            case "$desiredlang" in
316              "$presentlang"*) useit=yes;;
317            esac
318          done
319          if test $useit = yes; then
320            NEW_LINGUAS="$NEW_LINGUAS $presentlang"
321          fi
322        done
323        LINGUAS=$NEW_LINGUAS
324        AC_MSG_RESULT($LINGUAS)
325      fi
327      dnl Construct list of names of catalog files to be constructed.
328      if test -n "$LINGUAS"; then
329        for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
330      fi
331    fi
333    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
334    dnl find the mkinstalldirs script in another subdir but $(top_srcdir).
335    dnl Try to locate is.
336    MKINSTALLDIRS=
337    if test -n "$ac_aux_dir"; then
338      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
339    fi
340    if test -z "$MKINSTALLDIRS"; then
341      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
342    fi
343    AC_SUBST(MKINSTALLDIRS)
345    dnl Enable libtool support if the surrounding package wishes it.
346    INTL_LIBTOOL_SUFFIX_PREFIX=ifelse([$1], use-libtool, [l], [])
347    AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX)
348   ])