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