d3b86ec0f4c907bee6920089bb8e96c030f8d7b7
[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_PROG_RANLIB])dnl
188    AC_REQUIRE([AC_HEADER_STDC])dnl
189    AC_REQUIRE([AC_C_CONST])dnl
190    AC_REQUIRE([AC_C_INLINE])dnl
191    AC_REQUIRE([AC_TYPE_OFF_T])dnl
192    AC_REQUIRE([AC_TYPE_SIZE_T])dnl
193    AC_REQUIRE([AC_FUNC_ALLOCA])dnl
194    AC_REQUIRE([AC_FUNC_MMAP])dnl
195
196    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
197 unistd.h values.h])
198    AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
199 __argz_count __argz_stringify __argz_next])
200
201    if test "${ac_cv_func_stpcpy+set}" != "set"; then
202      AC_CHECK_FUNCS(stpcpy)
203    fi
204    if test "${ac_cv_func_stpcpy}" = "yes"; then
205      AC_DEFINE(HAVE_STPCPY)
206    fi
207
208    AM_LC_MESSAGES
209    AM_WITH_NLS
210
211    if test "x$CATOBJEXT" != "x"; then
212      if test "x$ALL_LINGUAS" = "x"; then
213        LINGUAS=
214      else
215        AC_MSG_CHECKING(for catalogs to be installed)
216        NEW_LINGUAS=
217        for lang in ${LINGUAS=$ALL_LINGUAS}; do
218          case "$ALL_LINGUAS" in
219           *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
220          esac
221        done
222        LINGUAS=$NEW_LINGUAS
223        AC_MSG_RESULT($LINGUAS)
224      fi
225
226      dnl Construct list of names of catalog files to be constructed.
227      if test -n "$LINGUAS"; then
228        for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
229      fi
230    fi
231
232    dnl Determine which catalog format we have (if any is needed)
233    dnl For now we know about two different formats:
234    dnl   Linux libc-5 and the normal X/Open format
235    test -d intl || mkdir intl
236    if test "$CATOBJEXT" = ".cat"; then
237      AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
238
239      dnl Transform the SED scripts while copying because some dumb SEDs
240      dnl cannot handle comments.
241      sed -e '/^#/d' $srcdir/intl/$msgformat-msg.sed > intl/po2msg.sed
242    fi
243    dnl po2tbl.sed is always needed.
244    sed -e '/^#.*[^\\]$/d' -e '/^#$/d' \
245      $srcdir/intl/po2tbl.sed.in > intl/po2tbl.sed
246
247    dnl In the intl/Makefile.in we have a special dependency which makes
248    dnl only sense for gettext.  We comment this out for non-gettext
249    dnl packages.
250    if test "$PACKAGE" = "gettext"; then
251      GT_NO="#NO#"
252      GT_YES=
253    else
254      GT_NO=
255      GT_YES="#YES#"
256    fi
257    AC_SUBST(GT_NO)
258    AC_SUBST(GT_YES)
259
260    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
261    dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
262    dnl Try to locate is.
263    MKINSTALLDIRS=
264    if test $ac_aux_dir; then
265      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
266    fi
267    if test -z $MKINSTALLDIRS; then
268      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
269    fi
270    AC_SUBST(MKINSTALLDIRS)
271
272    dnl Generate list of files to be processed by xgettext which will
273    dnl be included in po/Makefile.
274    test -d po || mkdir po
275    if test "x$srcdir" != "x."; then
276      if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
277        posrcprefix="$srcdir/"
278      else
279        posrcprefix="../$srcdir/"
280      fi
281    else
282      posrcprefix="../"
283    fi
284    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
285         < $srcdir/po/POTFILES.in > po/POTFILES
286   ])