(AM_GNU_GETTEXT): Do `changequote' around use of brackets
[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 106
10
11 AC_PREREQ(2.13)               dnl Minimum Autoconf version required.
12
13 AC_DEFUN(AM_WITH_NLS,
14   [AC_MSG_CHECKING([whether NLS is requested])
15     dnl Default is enabled NLS
16     AC_ARG_ENABLE(nls,
17       [  --disable-nls           do not use Native Language Support],
18       USE_NLS=$enableval, USE_NLS=yes)
19     AC_MSG_RESULT($USE_NLS)
20     AC_SUBST(USE_NLS)
21
22     USE_INCLUDED_LIBINTL=no
23
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)
33
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.
40         nls_cv_header_intl=
41         nls_cv_header_libgt=
42         CATOBJEXT=NONE
43
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)])
48
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)])
57
58              if test "$gt_cv_func_gettext_libintl" = yes; then
59                LIBS="$LIBS -lintl"
60              fi
61
62            fi
63
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],
77                   [CATOBJEXT=.gmo
78                    DATADIRNAME=share],
79                   [CATOBJEXT=.mo
80                    DATADIRNAME=lib])
81                 INSTOBJEXT=.mo
82               fi
83             fi
84         ])
85
86         if test "$CATOBJEXT" = "NONE"; then
87           AC_MSG_CHECKING([whether catgets can be used])
88           AC_ARG_WITH(catgets,
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)
92
93           if test "$nls_cv_use_catgets" = "yes"; then
94             dnl No gettext in C library.  Try catgets next.
95             AC_CHECK_LIB(i, main)
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)
106                  fi
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
110                  CATOBJEXT=.cat
111                  INSTOBJEXT=.cat
112                  DATADIRNAME=lib
113                  INTLDEPS='$(top_builddir)/intl/libintl.a'
114                  INTLLIBS=$INTLDEPS
115                  LIBS=`echo $LIBS | sed -e 's/-lintl//'`
116                  nls_cv_header_intl=intl/libintl.h
117                  nls_cv_header_libgt=intl/libgettext.h
118                fi])
119           fi
120         fi
121
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
126         fi
127       fi
128
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)'`"], :)
137         AC_SUBST(MSGFMT)
138         USE_INCLUDED_LIBINTL=yes
139         CATOBJEXT=.gmo
140         INSTOBJEXT=.mo
141         DATADIRNAME=share
142         INTLDEPS='$(top_builddir)/intl/libintl.a'
143         INTLLIBS=$INTLDEPS
144         LIBS=`echo $LIBS | sed -e 's/-lintl//'`
145         nls_cv_header_intl=intl/libintl.h
146         nls_cv_header_libgt=intl/libgettext.h
147       fi
148
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
154           : ;
155         else
156           AC_MSG_RESULT(
157             [found xgettext program is not GNU xgettext; ignore it])
158           XGETTEXT=":"
159         fi
160       fi
161
162       # We need to process the po/ directory.
163       POSUB=po
164     else
165       DATADIRNAME=share
166       nls_cv_header_intl=intl/libintl.h
167       nls_cv_header_libgt=intl/libgettext.h
168     fi
169     if test -z "$nsl_cv_header_intl"; then
170       # Clean out junk possibly left behind by a previous configuration.
171       rm -f intl/libintl.h
172     fi
173     AC_LINK_FILES($nls_cv_header_libgt, $nls_cv_header_intl)
174     AC_OUTPUT_COMMANDS(
175      [case "$CONFIG_FILES" in *po/Makefile.in*)
176         sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
177       esac])
178
179
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
183       USE_NLS=yes
184       USE_INCLUDED_LIBINTL=yes
185     fi
186
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
189     dnl in configure.in.
190     for lang in $ALL_LINGUAS; do
191       GMOFILES="$GMOFILES $lang.gmo"
192       POFILES="$POFILES $lang.po"
193     done
194
195     dnl Make all variables we use known to autoconf.
196     AC_SUBST(USE_INCLUDED_LIBINTL)
197     AC_SUBST(CATALOGS)
198     AC_SUBST(CATOBJEXT)
199     AC_SUBST(DATADIRNAME)
200     AC_SUBST(GMOFILES)
201     AC_SUBST(INSTOBJEXT)
202     AC_SUBST(INTLDEPS)
203     AC_SUBST(INTLLIBS)
204     AC_SUBST(INTLOBJS)
205     AC_SUBST(POFILES)
206     AC_SUBST(POSUB)
207   ])
208
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
221
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])
226
227    if test "${ac_cv_func_stpcpy+set}" != "set"; then
228      AC_CHECK_FUNCS(stpcpy)
229    fi
230    if test "${ac_cv_func_stpcpy}" = "yes"; then
231      AC_DEFINE(HAVE_STPCPY, 1, [Define to 1 if you have the stpcpy function.])
232    fi
233
234    AM_LC_MESSAGES
235    AM_WITH_NLS
236
237    if test "x$CATOBJEXT" != "x"; then
238      if test "x$ALL_LINGUAS" = "x"; then
239        LINGUAS=
240      else
241        AC_MSG_CHECKING(for catalogs to be installed)
242        NEW_LINGUAS=
243        for lang in ${LINGUAS=$ALL_LINGUAS}; do
244          case "$ALL_LINGUAS" in
245           *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
246          esac
247        done
248        LINGUAS=$NEW_LINGUAS
249        AC_MSG_RESULT($LINGUAS)
250      fi
251
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
255      fi
256    fi
257
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>"
263    else
264      INCLUDE_LOCALE_H="\
265 /* The system does not provide the header <locale.h>.  Take care yourself.  */"
266    fi
267    AC_SUBST(INCLUDE_LOCALE_H)
268
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)
275
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
279    fi
280    dnl po2tbl.sed is always needed.
281    sed -e '/^#.*[^\\]$/d' -e '/^#$/d' \
282      $srcdir/intl/po2tbl.sed.in > intl/po2tbl.sed
283
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
286    dnl packages.
287    if test "$PACKAGE" = "gettext"; then
288      GT_NO="#NO#"
289      GT_YES=
290    else
291      GT_NO=
292      GT_YES="#YES#"
293    fi
294    AC_SUBST(GT_NO)
295    AC_SUBST(GT_YES)
296
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.
300    MKINSTALLDIRS=
301    if test -n "$ac_aux_dir"; then
302      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
303    fi
304    if test -z "$MKINSTALLDIRS"; then
305      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
306    fi
307    AC_SUBST(MKINSTALLDIRS)
308
309    dnl *** For now the libtool support in intl/Makefile is not for real.
310    l=
311    AC_SUBST(l)
312
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
317      changequote(, )dnl
318      if test "x`echo $srcdir | sed -e 's@^[A-z]:@@' -e 's@/.*@@'`" = "x"; then
319        posrcprefix="$srcdir/"
320      else
321        posrcprefix="../$srcdir/"
322      fi
323      changequote([, ])dnl
324    else
325      posrcprefix="../"
326    fi
327    rm -f po/POTFILES
328    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
329         < $srcdir/po/POTFILES.in > po/POTFILES
330   ])