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