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