.
[gnulib.git] / m4 / gettext.m4
1 # 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
11 AC_DEFUN(AM_WITH_NLS,
12   [AC_MSG_CHECKING([whether NLS is requested])
13     dnl Default is enabled NLS
14     AC_ARG_ENABLE(nls,
15       [  --disable-nls           do not use Native Language Support],
16       USE_NLS=$enableval, USE_NLS=yes)
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
56              if test "$gt_cv_func_gettext_libintl" = yes; then
57                LIBS="$LIBS -lintl"
58              fi
59
60            fi
61
62            if test "$gt_cv_func_gettext_libc" = "yes" \
63               || test "$gt_cv_func_gettext_libintl" = "yes"; then
64               AC_DEFINE(HAVE_GETTEXT)
65               AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
66                 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
67               if test "$MSGFMT" != "no"; then
68                 AC_CHECK_FUNCS(dcgettext)
69                 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
70                 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
71                   [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
72                 AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
73                                return _nl_msg_cat_cntr],
74                   [CATOBJEXT=.gmo
75                    DATADIRNAME=share],
76                   [CATOBJEXT=.mo
77                    DATADIRNAME=lib])
78                 INSTOBJEXT=.mo
79               fi
80             fi
81         ])
82
83         if test "$CATOBJEXT" = "NONE"; then
84           AC_MSG_CHECKING([whether catgets can be used])
85           AC_ARG_WITH(catgets,
86             [  --with-catgets          use catgets functions if available],
87             nls_cv_use_catgets=$withval, nls_cv_use_catgets=no)
88           AC_MSG_RESULT($nls_cv_use_catgets)
89
90           if test "$nls_cv_use_catgets" = "yes"; then
91             dnl No gettext in C library.  Try catgets next.
92             AC_CHECK_LIB(i, main)
93             AC_CHECK_FUNC(catgets,
94               [AC_DEFINE(HAVE_CATGETS)
95                INTLOBJS="\$(CATOBJS)"
96                AC_PATH_PROG(GENCAT, gencat, no)dnl
97                if test "$GENCAT" != "no"; then
98                  AC_PATH_PROG(GMSGFMT, gmsgfmt, no)
99                  if test "$GMSGFMT" = "no"; then
100                    AM_PATH_PROG_WITH_TEST(GMSGFMT, msgfmt,
101                     [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)
102                  fi
103                  AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
104                    [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
105                  USE_INCLUDED_LIBINTL=yes
106                  CATOBJEXT=.cat
107                  INSTOBJEXT=.cat
108                  DATADIRNAME=lib
109                  INTLDEPS='$(top_builddir)/intl/libintl.a'
110                  INTLLIBS=$INTLDEPS
111                  LIBS=`echo $LIBS | sed -e 's/-lintl//'`
112                  nls_cv_header_intl=intl/libintl.h
113                  nls_cv_header_libgt=intl/libgettext.h
114                fi])
115           fi
116         fi
117
118         if test "$CATOBJEXT" = "NONE"; then
119           dnl Neither gettext nor catgets in included in the C library.
120           dnl Fall back on GNU gettext library.
121           nls_cv_use_gnu_gettext=yes
122         fi
123       fi
124
125       if test "$nls_cv_use_gnu_gettext" = "yes"; then
126         dnl Mark actions used to generate GNU NLS library.
127         INTLOBJS="\$(GETTOBJS)"
128         AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
129           [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], msgfmt)
130         AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
131         AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
132           [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
133         AC_SUBST(MSGFMT)
134         USE_INCLUDED_LIBINTL=yes
135         CATOBJEXT=.gmo
136         INSTOBJEXT=.mo
137         DATADIRNAME=share
138         INTLDEPS='$(top_builddir)/intl/libintl.a'
139         INTLLIBS=$INTLDEPS
140         LIBS=`echo $LIBS | sed -e 's/-lintl//'`
141         nls_cv_header_intl=intl/libintl.h
142         nls_cv_header_libgt=intl/libgettext.h
143       fi
144
145       dnl Test whether we really found GNU xgettext.
146       if test "$XGETTEXT" != ":"; then
147         dnl If it is no GNU xgettext we define it as : so that the
148         dnl Makefiles still can work.
149         if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
150           : ;
151         else
152           AC_MSG_RESULT(
153             [found xgettext program is not GNU xgettext; ignore it])
154           XGETTEXT=":"
155         fi
156       fi
157
158       # We need to process the po/ directory.
159       POSUB=po
160     else
161       DATADIRNAME=share
162       nls_cv_header_intl=intl/libintl.h
163       nls_cv_header_libgt=intl/libgettext.h
164     fi
165     AC_LINK_FILES($nls_cv_header_libgt, $nls_cv_header_intl)
166     AC_OUTPUT_COMMANDS(
167      [case "$CONFIG_FILES" in *po/Makefile.in*)
168         sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
169       esac])
170
171
172     # If this is used in GNU gettext we have to set USE_NLS to `yes'
173     # because some of the sources are only built for this goal.
174     if test "$PACKAGE" = gettext; then
175       USE_NLS=yes
176       USE_INCLUDED_LIBINTL=yes
177     fi
178
179     dnl These rules are solely for the distribution goal.  While doing this
180     dnl we only have to keep exactly one list of the available catalogs
181     dnl in configure.in.
182     for lang in $ALL_LINGUAS; do
183       GMOFILES="$GMOFILES $lang.gmo"
184       POFILES="$POFILES $lang.po"
185     done
186
187     dnl Make all variables we use known to autoconf.
188     AC_SUBST(USE_INCLUDED_LIBINTL)
189     AC_SUBST(CATALOGS)
190     AC_SUBST(CATOBJEXT)
191     AC_SUBST(DATADIRNAME)
192     AC_SUBST(GMOFILES)
193     AC_SUBST(INSTOBJEXT)
194     AC_SUBST(INTLDEPS)
195     AC_SUBST(INTLLIBS)
196     AC_SUBST(INTLOBJS)
197     AC_SUBST(POFILES)
198     AC_SUBST(POSUB)
199   ])
200
201 AC_DEFUN(AM_GNU_GETTEXT,
202   [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
203    AC_REQUIRE([AC_PROG_CC])dnl
204    AC_REQUIRE([AC_PROG_RANLIB])dnl
205    AC_REQUIRE([AC_ISC_POSIX])dnl
206    AC_REQUIRE([AC_HEADER_STDC])dnl
207    AC_REQUIRE([AC_C_CONST])dnl
208    AC_REQUIRE([AC_C_INLINE])dnl
209    AC_REQUIRE([AC_TYPE_OFF_T])dnl
210    AC_REQUIRE([AC_TYPE_SIZE_T])dnl
211    AC_REQUIRE([AC_FUNC_ALLOCA])dnl
212    AC_REQUIRE([AC_FUNC_MMAP])dnl
213
214    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
215 unistd.h sys/param.h])
216    AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
217 strdup __argz_count __argz_stringify __argz_next])
218
219    if test "${ac_cv_func_stpcpy+set}" != "set"; then
220      AC_CHECK_FUNCS(stpcpy)
221    fi
222    if test "${ac_cv_func_stpcpy}" = "yes"; then
223      AC_DEFINE(HAVE_STPCPY)
224    fi
225
226    AM_LC_MESSAGES
227    AM_WITH_NLS
228
229    if test "x$CATOBJEXT" != "x"; then
230      if test "x$ALL_LINGUAS" = "x"; then
231        LINGUAS=
232      else
233        AC_MSG_CHECKING(for catalogs to be installed)
234        NEW_LINGUAS=
235        for lang in ${LINGUAS=$ALL_LINGUAS}; do
236          case "$ALL_LINGUAS" in
237           *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
238          esac
239        done
240        LINGUAS=$NEW_LINGUAS
241        AC_MSG_RESULT($LINGUAS)
242      fi
243
244      dnl Construct list of names of catalog files to be constructed.
245      if test -n "$LINGUAS"; then
246        for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
247      fi
248    fi
249
250    dnl The reference to <locale.h> in the installed <libintl.h> file
251    dnl must be resolved because we cannot expect the users of this
252    dnl to define HAVE_LOCALE_H.
253    if test $ac_cv_header_locale_h = yes; then
254      INCLUDE_LOCALE_H="#include <locale.h>"
255    else
256      INCLUDE_LOCALE_H="\
257 /* The system does not provide the header <locale.h>.  Take care yourself.  */"
258    fi
259    AC_SUBST(INCLUDE_LOCALE_H)
260
261    dnl Determine which catalog format we have (if any is needed)
262    dnl For now we know about two different formats:
263    dnl   Linux libc-5 and the normal X/Open format
264    test -d intl || mkdir intl
265    if test "$CATOBJEXT" = ".cat"; then
266      AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
267
268      dnl Transform the SED scripts while copying because some dumb SEDs
269      dnl cannot handle comments.
270      sed -e '/^#/d' $srcdir/intl/$msgformat-msg.sed > intl/po2msg.sed
271    fi
272    dnl po2tbl.sed is always needed.
273    sed -e '/^#.*[^\\]$/d' -e '/^#$/d' \
274      $srcdir/intl/po2tbl.sed.in > intl/po2tbl.sed
275
276    dnl In the intl/Makefile.in we have a special dependency which makes
277    dnl only sense for gettext.  We comment this out for non-gettext
278    dnl packages.
279    if test "$PACKAGE" = "gettext"; then
280      GT_NO="#NO#"
281      GT_YES=
282    else
283      GT_NO=
284      GT_YES="#YES#"
285    fi
286    AC_SUBST(GT_NO)
287    AC_SUBST(GT_YES)
288
289    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
290    dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
291    dnl Try to locate is.
292    MKINSTALLDIRS=
293    if test -n "$ac_aux_dir"; then
294      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
295    fi
296    if test -z "$MKINSTALLDIRS"; then
297      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
298    fi
299    AC_SUBST(MKINSTALLDIRS)
300
301    dnl *** For now the libtool support in intl/Makefile is not for real.
302    l=
303    AC_SUBST(l)
304
305    dnl Generate list of files to be processed by xgettext which will
306    dnl be included in po/Makefile.
307    test -d po || mkdir po
308    if test "x$srcdir" != "x."; then
309      if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
310        posrcprefix="$srcdir/"
311      else
312        posrcprefix="../$srcdir/"
313      fi
314    else
315      posrcprefix="../"
316    fi
317    rm -f po/POTFILES
318    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
319         < $srcdir/po/POTFILES.in > po/POTFILES
320   ])