1130803Smarcel# This file is derived from `gettext.m4'.  The difference is that the
2130803Smarcel# included macros assume Cygnus-style source and build trees.
3130803Smarcel
4130803Smarcel# Macro to add for using GNU gettext.
5130803Smarcel# Ulrich Drepper <drepper@cygnus.com>, 1995.
6130803Smarcel#
7130803Smarcel# This file file be copied and used freely without restrictions.  It can
8130803Smarcel# be used in projects which are not available under the GNU Public License
9130803Smarcel# but which still want to provide support for the GNU gettext functionality.
10130803Smarcel# Please note that the actual code is *not* freely available.
11130803Smarcel
12130803Smarcel# serial 3
13130803Smarcel
14130803SmarcelAC_DEFUN([CY_WITH_NLS],
15130803Smarcel  [AC_MSG_CHECKING([whether NLS is requested])
16130803Smarcel    dnl Default is enabled NLS
17130803Smarcel    AC_ARG_ENABLE(nls,
18130803Smarcel      [  --disable-nls           do not use Native Language Support],
19130803Smarcel      USE_NLS=$enableval, USE_NLS=yes)
20130803Smarcel    AC_MSG_RESULT($USE_NLS)
21130803Smarcel    AC_SUBST(USE_NLS)
22130803Smarcel
23130803Smarcel    USE_INCLUDED_LIBINTL=no
24130803Smarcel
25130803Smarcel    dnl If we use NLS figure out what method
26130803Smarcel    if test "$USE_NLS" = "yes"; then
27130803Smarcel      AC_DEFINE(ENABLE_NLS, 1, [Define to 1 if NLS is requested])
28130803Smarcel      AC_MSG_CHECKING([whether included gettext is requested])
29130803Smarcel      AC_ARG_WITH(included-gettext,
30130803Smarcel        [  --with-included-gettext use the GNU gettext library included here],
31130803Smarcel        nls_cv_force_use_gnu_gettext=$withval,
32130803Smarcel        nls_cv_force_use_gnu_gettext=no)
33130803Smarcel      AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
34130803Smarcel
35130803Smarcel      nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
36130803Smarcel      if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
37130803Smarcel        dnl User does not insist on using GNU NLS library.  Figure out what
38130803Smarcel        dnl to use.  If gettext or catgets are available (in this order) we
39130803Smarcel        dnl use this.  Else we have to fall back to GNU NLS library.
40130803Smarcel	dnl catgets is only used if permitted by option --with-catgets.
41130803Smarcel	nls_cv_header_intl=
42130803Smarcel	nls_cv_header_libgt=
43130803Smarcel	CATOBJEXT=NONE
44130803Smarcel
45130803Smarcel	AC_CHECK_HEADER(libintl.h,
46130803Smarcel	  [AC_CACHE_CHECK([for gettext in libc], gt_cv_func_gettext_libc,
47130803Smarcel	    [AC_TRY_LINK([#include <libintl.h>], [return (int) gettext ("")],
48130803Smarcel	       gt_cv_func_gettext_libc=yes, gt_cv_func_gettext_libc=no)])
49130803Smarcel
50130803Smarcel	   if test "$gt_cv_func_gettext_libc" != "yes"; then
51130803Smarcel	     AC_CHECK_LIB(intl, bindtextdomain,
52130803Smarcel	       [AC_CACHE_CHECK([for gettext in libintl],
53130803Smarcel		 gt_cv_func_gettext_libintl,
54130803Smarcel		 [AC_TRY_LINK([], [return (int) gettext ("")],
55130803Smarcel		 gt_cv_func_gettext_libintl=yes,
56130803Smarcel		 gt_cv_func_gettext_libintl=no)])])
57130803Smarcel	   fi
58130803Smarcel
59130803Smarcel	   if test "$gt_cv_func_gettext_libc" = "yes" \
60130803Smarcel	      || test "$gt_cv_func_gettext_libintl" = "yes"; then
61130803Smarcel	      AC_DEFINE(HAVE_GETTEXT, 1,
62130803Smarcel			[Define as 1 if you have gettext and don't want to use GNU gettext.])
63130803Smarcel	      AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
64130803Smarcel		[test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
65130803Smarcel	      if test "$MSGFMT" != "no"; then
66130803Smarcel		AC_CHECK_FUNCS(dcgettext)
67130803Smarcel		AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
68130803Smarcel		AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
69130803Smarcel		  [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
70130803Smarcel		AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
71130803Smarcel			       return _nl_msg_cat_cntr],
72130803Smarcel		  [CATOBJEXT=.gmo
73130803Smarcel		   DATADIRNAME=share],
74130803Smarcel		  [CATOBJEXT=.mo
75130803Smarcel		   DATADIRNAME=lib])
76130803Smarcel		INSTOBJEXT=.mo
77130803Smarcel	      fi
78130803Smarcel	    fi
79130803Smarcel	])
80130803Smarcel
81130803Smarcel	dnl In the standard gettext, we would now check for catgets.
82130803Smarcel        dnl However, we never want to use catgets for our releases.
83130803Smarcel
84130803Smarcel        if test "$CATOBJEXT" = "NONE"; then
85130803Smarcel	  dnl Neither gettext nor catgets in included in the C library.
86130803Smarcel	  dnl Fall back on GNU gettext library.
87130803Smarcel	  nls_cv_use_gnu_gettext=yes
88130803Smarcel        fi
89130803Smarcel      fi
90130803Smarcel
91130803Smarcel      if test "$nls_cv_use_gnu_gettext" = "yes"; then
92130803Smarcel        dnl Mark actions used to generate GNU NLS library.
93130803Smarcel        INTLOBJS="\$(GETTOBJS)"
94130803Smarcel        AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
95130803Smarcel	  [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], msgfmt)
96130803Smarcel        AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
97130803Smarcel        AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
98130803Smarcel	  [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
99130803Smarcel        AC_SUBST(MSGFMT)
100130803Smarcel	USE_INCLUDED_LIBINTL=yes
101130803Smarcel        CATOBJEXT=.gmo
102130803Smarcel        INSTOBJEXT=.mo
103130803Smarcel        DATADIRNAME=share
104130803Smarcel	INTLDEPS='$(top_builddir)/../intl/libintl.a'
105130803Smarcel	INTLLIBS=$INTLDEPS
106130803Smarcel	LIBS=`echo $LIBS | sed -e 's/-lintl//'`
107130803Smarcel        nls_cv_header_intl=libintl.h
108130803Smarcel        nls_cv_header_libgt=libgettext.h
109130803Smarcel      fi
110130803Smarcel
111130803Smarcel      dnl Test whether we really found GNU xgettext.
112130803Smarcel      if test "$XGETTEXT" != ":"; then
113130803Smarcel	dnl If it is no GNU xgettext we define it as : so that the
114130803Smarcel	dnl Makefiles still can work.
115130803Smarcel	if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
116130803Smarcel	  : ;
117130803Smarcel	else
118130803Smarcel	  AC_MSG_RESULT(
119130803Smarcel	    [found xgettext programs is not GNU xgettext; ignore it])
120130803Smarcel	  XGETTEXT=":"
121130803Smarcel	fi
122130803Smarcel      fi
123130803Smarcel
124130803Smarcel      # We need to process the po/ directory.
125130803Smarcel      POSUB=po
126130803Smarcel    else
127130803Smarcel      DATADIRNAME=share
128130803Smarcel      nls_cv_header_intl=libintl.h
129130803Smarcel      nls_cv_header_libgt=libgettext.h
130130803Smarcel    fi
131130803Smarcel
132130803Smarcel    # If this is used in GNU gettext we have to set USE_NLS to `yes'
133130803Smarcel    # because some of the sources are only built for this goal.
134130803Smarcel    if test "$PACKAGE" = gettext; then
135130803Smarcel      USE_NLS=yes
136130803Smarcel      USE_INCLUDED_LIBINTL=yes
137130803Smarcel    fi
138130803Smarcel
139130803Smarcel    dnl These rules are solely for the distribution goal.  While doing this
140130803Smarcel    dnl we only have to keep exactly one list of the available catalogs
141130803Smarcel    dnl in configure.in.
142130803Smarcel    for lang in $ALL_LINGUAS; do
143130803Smarcel      GMOFILES="$GMOFILES $lang.gmo"
144130803Smarcel      POFILES="$POFILES $lang.po"
145130803Smarcel    done
146130803Smarcel
147130803Smarcel    dnl Make all variables we use known to autoconf.
148130803Smarcel    AC_SUBST(USE_INCLUDED_LIBINTL)
149130803Smarcel    AC_SUBST(CATALOGS)
150130803Smarcel    AC_SUBST(CATOBJEXT)
151130803Smarcel    AC_SUBST(DATADIRNAME)
152130803Smarcel    AC_SUBST(GMOFILES)
153130803Smarcel    AC_SUBST(INSTOBJEXT)
154130803Smarcel    AC_SUBST(INTLDEPS)
155130803Smarcel    AC_SUBST(INTLLIBS)
156130803Smarcel    AC_SUBST(INTLOBJS)
157130803Smarcel    AC_SUBST(POFILES)
158130803Smarcel    AC_SUBST(POSUB)
159130803Smarcel  ])
160130803Smarcel
161130803SmarcelAC_DEFUN([CY_GNU_GETTEXT],
162130803Smarcel  [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
163130803Smarcel   AC_REQUIRE([AC_PROG_CC])dnl
164130803Smarcel   AC_REQUIRE([AC_PROG_RANLIB])dnl
165130803Smarcel   AC_REQUIRE([AC_ISC_POSIX])dnl
166130803Smarcel   AC_REQUIRE([AC_HEADER_STDC])dnl
167130803Smarcel   AC_REQUIRE([AC_C_CONST])dnl
168130803Smarcel   AC_REQUIRE([AC_C_INLINE])dnl
169130803Smarcel   AC_REQUIRE([AC_TYPE_OFF_T])dnl
170130803Smarcel   AC_REQUIRE([AC_TYPE_SIZE_T])dnl
171130803Smarcel   AC_REQUIRE([AC_FUNC_ALLOCA])dnl
172130803Smarcel   AC_REQUIRE([AC_FUNC_MMAP])dnl
173130803Smarcel
174130803Smarcel   AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
175130803Smarcelunistd.h values.h sys/param.h])
176130803Smarcel   AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
177130803Smarcel__argz_count __argz_stringify __argz_next])
178130803Smarcel
179130803Smarcel   if test "${ac_cv_func_stpcpy+set}" != "set"; then
180130803Smarcel     AC_CHECK_FUNCS(stpcpy)
181130803Smarcel   fi
182130803Smarcel   if test "${ac_cv_func_stpcpy}" = "yes"; then
183130803Smarcel     AC_DEFINE(HAVE_STPCPY, 1, [Define if you have the stpcpy function])
184130803Smarcel   fi
185130803Smarcel
186130803Smarcel   AM_LC_MESSAGES
187130803Smarcel   CY_WITH_NLS
188130803Smarcel
189130803Smarcel   if test "x$CATOBJEXT" != "x"; then
190130803Smarcel     if test "x$ALL_LINGUAS" = "x"; then
191130803Smarcel       LINGUAS=
192130803Smarcel     else
193130803Smarcel       AC_MSG_CHECKING(for catalogs to be installed)
194130803Smarcel       NEW_LINGUAS=
195130803Smarcel       for lang in ${LINGUAS=$ALL_LINGUAS}; do
196130803Smarcel         case "$ALL_LINGUAS" in
197130803Smarcel          *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
198130803Smarcel         esac
199130803Smarcel       done
200130803Smarcel       LINGUAS=$NEW_LINGUAS
201130803Smarcel       AC_MSG_RESULT($LINGUAS)
202130803Smarcel     fi
203130803Smarcel
204130803Smarcel     dnl Construct list of names of catalog files to be constructed.
205130803Smarcel     if test -n "$LINGUAS"; then
206130803Smarcel       for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
207130803Smarcel     fi
208130803Smarcel   fi
209130803Smarcel
210130803Smarcel   dnl The reference to <locale.h> in the installed <libintl.h> file
211130803Smarcel   dnl must be resolved because we cannot expect the users of this
212130803Smarcel   dnl to define HAVE_LOCALE_H.
213130803Smarcel   if test $ac_cv_header_locale_h = yes; then
214130803Smarcel     INCLUDE_LOCALE_H="#include <locale.h>"
215130803Smarcel   else
216130803Smarcel     INCLUDE_LOCALE_H="\
217130803Smarcel/* The system does not provide the header <locale.h>.  Take care yourself.  */"
218130803Smarcel   fi
219130803Smarcel   AC_SUBST(INCLUDE_LOCALE_H)
220130803Smarcel
221130803Smarcel   dnl Determine which catalog format we have (if any is needed)
222130803Smarcel   dnl For now we know about two different formats:
223130803Smarcel   dnl   Linux libc-5 and the normal X/Open format
224130803Smarcel   if test -f $srcdir/po2tbl.sed.in; then
225130803Smarcel      if test "$CATOBJEXT" = ".cat"; then
226130803Smarcel	 AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
227130803Smarcel
228130803Smarcel	 dnl Transform the SED scripts while copying because some dumb SEDs
229130803Smarcel         dnl cannot handle comments.
230130803Smarcel	 sed -e '/^#/d' $srcdir/$msgformat-msg.sed > po2msg.sed
231130803Smarcel      fi
232130803Smarcel      dnl po2tbl.sed is always needed.
233130803Smarcel      sed -e '/^#.*[^\\]$/d' -e '/^#$/d' \
234130803Smarcel	 $srcdir/po2tbl.sed.in > po2tbl.sed
235130803Smarcel   fi
236130803Smarcel
237130803Smarcel   dnl In the intl/Makefile.in we have a special dependency which makes
238130803Smarcel   dnl only sense for gettext.  We comment this out for non-gettext
239130803Smarcel   dnl packages.
240130803Smarcel   if test "$PACKAGE" = "gettext"; then
241130803Smarcel     GT_NO="#NO#"
242130803Smarcel     GT_YES=
243130803Smarcel   else
244130803Smarcel     GT_NO=
245130803Smarcel     GT_YES="#YES#"
246130803Smarcel   fi
247130803Smarcel   AC_SUBST(GT_NO)
248130803Smarcel   AC_SUBST(GT_YES)
249130803Smarcel
250130803Smarcel   MKINSTALLDIRS="\$(srcdir)/../../mkinstalldirs"
251130803Smarcel   AC_SUBST(MKINSTALLDIRS)
252130803Smarcel
253130803Smarcel   dnl *** For now the libtool support in intl/Makefile is not for real.
254130803Smarcel   l=
255130803Smarcel   AC_SUBST(l)
256130803Smarcel
257130803Smarcel   dnl Generate list of files to be processed by xgettext which will
258130803Smarcel   dnl be included in po/Makefile.  But only do this if the po directory
259130803Smarcel   dnl exists in srcdir and contains POTFILES.in.
260130803Smarcel   if test -f $srcdir/po/POTFILES.in; then
261130803Smarcel      test -d po || mkdir po
262130803Smarcel      if test "x$srcdir" != "x."; then
263130803Smarcel	 if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
264130803Smarcel	    posrcprefix="$srcdir/"
265130803Smarcel	 else
266130803Smarcel	    posrcprefix="../$srcdir/"
267130803Smarcel	 fi
268130803Smarcel      else
269130803Smarcel	 posrcprefix="../"
270130803Smarcel      fi
271130803Smarcel      rm -f po/POTFILES
272130803Smarcel      sed -e "/^#/d" -e "/^\$/d" -e "s,.*,	$posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
273130803Smarcel	 < $srcdir/po/POTFILES.in > po/POTFILES
274130803Smarcel   fi
275130803Smarcel  ])
276130803Smarcel
277130803Smarcel# Search path for a program which passes the given test.
278130803Smarcel# Ulrich Drepper <drepper@cygnus.com>, 1996.
279130803Smarcel#
280130803Smarcel# This file file be copied and used freely without restrictions.  It can
281130803Smarcel# be used in projects which are not available under the GNU Public License
282130803Smarcel# but which still want to provide support for the GNU gettext functionality.
283130803Smarcel# Please note that the actual code is *not* freely available.
284130803Smarcel
285130803Smarcel# serial 1
286130803Smarcel
287130803Smarceldnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
288130803Smarceldnl   TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
289130803SmarcelAC_DEFUN([AM_PATH_PROG_WITH_TEST],
290130803Smarcel[# Extract the first word of "$2", so it can be a program name with args.
291130803Smarcelset dummy $2; ac_word=[$]2
292130803SmarcelAC_MSG_CHECKING([for $ac_word])
293130803SmarcelAC_CACHE_VAL(ac_cv_path_$1,
294130803Smarcel[case "[$]$1" in
295130803Smarcel  /*)
296130803Smarcel  ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
297130803Smarcel  ;;
298130803Smarcel  *)
299130803Smarcel  IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS="${IFS}:"
300130803Smarcel  for ac_dir in ifelse([$5], , $PATH, [$5]); do
301130803Smarcel    test -z "$ac_dir" && ac_dir=.
302130803Smarcel    if test -f $ac_dir/$ac_word; then
303130803Smarcel      if [$3]; then
304130803Smarcel	ac_cv_path_$1="$ac_dir/$ac_word"
305130803Smarcel	break
306130803Smarcel      fi
307130803Smarcel    fi
308130803Smarcel  done
309130803Smarcel  IFS="$ac_save_ifs"
310130803Smarceldnl If no 4th arg is given, leave the cache variable unset,
311130803Smarceldnl so AC_PATH_PROGS will keep looking.
312130803Smarcelifelse([$4], , , [  test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
313130803Smarcel])dnl
314130803Smarcel  ;;
315130803Smarcelesac])dnl
316130803Smarcel$1="$ac_cv_path_$1"
317130803Smarcelif test -n "[$]$1"; then
318130803Smarcel  AC_MSG_RESULT([$]$1)
319130803Smarcelelse
320130803Smarcel  AC_MSG_RESULT(no)
321130803Smarcelfi
322130803SmarcelAC_SUBST($1)dnl
323130803Smarcel])
324130803Smarcel
325130803Smarcel# Check whether LC_MESSAGES is available in <locale.h>.
326130803Smarcel# Ulrich Drepper <drepper@cygnus.com>, 1995.
327130803Smarcel#
328130803Smarcel# This file file be copied and used freely without restrictions.  It can
329130803Smarcel# be used in projects which are not available under the GNU Public License
330130803Smarcel# but which still want to provide support for the GNU gettext functionality.
331130803Smarcel# Please note that the actual code is *not* freely available.
332130803Smarcel
333130803Smarcel# serial 1
334130803Smarcel
335130803SmarcelAC_DEFUN([AM_LC_MESSAGES],
336130803Smarcel  [if test $ac_cv_header_locale_h = yes; then
337130803Smarcel    AC_CACHE_CHECK([for LC_MESSAGES], am_cv_val_LC_MESSAGES,
338130803Smarcel      [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES],
339130803Smarcel       am_cv_val_LC_MESSAGES=yes, am_cv_val_LC_MESSAGES=no)])
340130803Smarcel    if test $am_cv_val_LC_MESSAGES = yes; then
341130803Smarcel      AC_DEFINE(HAVE_LC_MESSAGES, 1,
342130803Smarcel		[Define if your locale.h file contains LC_MESSAGES.])
343130803Smarcel    fi
344130803Smarcel  fi])
345