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