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