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