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