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