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