e4b70de97fa9067727ac2556eb10f60fdf8698a6
[platform/upstream/glib.git] / acinclude.m4
1 # Macro to add for using GNU gettext.
2 # Ulrich Drepper <drepper@cygnus.com>, 1995, 1996
3 #
4 # Modified to never use included libintl. 
5 # Owen Taylor <otaylor@redhat.com>, 12/15/1998
6 #
7 #
8 # This file can be copied and used freely without restrictions.  It can
9 # be used in projects which are not available under the GNU Public License
10 # but which still want to provide support for the GNU gettext functionality.
11 # Please note that the actual code is *not* freely available.
12 #
13 #
14 # If you make changes to this file, you MUST update the copy in
15 # acinclude.m4. [ aclocal dies on duplicate macros, so if
16 # we run 'aclocal -I macros/' then we'll run into problems
17 # once we've installed glib-gettext.m4 :-( ]
18 #
19
20 AC_DEFUN([AM_GLIB_LC_MESSAGES],
21   [if test $ac_cv_header_locale_h = yes; then
22     AC_CACHE_CHECK([for LC_MESSAGES], am_cv_val_LC_MESSAGES,
23       [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES],
24        am_cv_val_LC_MESSAGES=yes, am_cv_val_LC_MESSAGES=no)])
25     if test $am_cv_val_LC_MESSAGES = yes; then
26       AC_DEFINE(HAVE_LC_MESSAGES, 1,
27         [Define if your <locale.h> file defines LC_MESSAGES.])
28     fi
29   fi])
30
31 dnl AM_GLIB_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
32 dnl   TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
33 AC_DEFUN([AM_GLIB_PATH_PROG_WITH_TEST],
34 [# Extract the first word of "$2", so it can be a program name with args.
35 set dummy $2; ac_word=[$]2
36 AC_MSG_CHECKING([for $ac_word])
37 AC_CACHE_VAL(ac_cv_path_$1,
38 [case "[$]$1" in
39   /*)
40   ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
41   ;;
42   *)
43   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
44   for ac_dir in ifelse([$5], , $PATH, [$5]); do
45     test -z "$ac_dir" && ac_dir=.
46     if test -f $ac_dir/$ac_word; then
47       if [$3]; then
48         ac_cv_path_$1="$ac_dir/$ac_word"
49         break
50       fi
51     fi
52   done
53   IFS="$ac_save_ifs"
54 dnl If no 4th arg is given, leave the cache variable unset,
55 dnl so AC_PATH_PROGS will keep looking.
56 ifelse([$4], , , [  test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
57 ])dnl
58   ;;
59 esac])dnl
60 $1="$ac_cv_path_$1"
61 if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then
62   AC_MSG_RESULT([$]$1)
63 else
64   AC_MSG_RESULT(no)
65 fi
66 AC_SUBST($1)dnl
67 ])
68
69 # serial 5
70
71 AC_DEFUN(AM_GLIB_WITH_NLS,
72   dnl NLS is obligatory
73   [USE_NLS=yes
74     AC_SUBST(USE_NLS)
75
76     dnl Figure out what method
77     nls_cv_force_use_gnu_gettext="no"
78
79     nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
80     if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
81       dnl User does not insist on using GNU NLS library.  Figure out what
82       dnl to use.  If gettext or catgets are available (in this order) we
83       dnl use this.  Else we have to fall back to GNU NLS library.
84       dnl catgets is only used if permitted by option --with-catgets.
85       nls_cv_header_intl=
86       nls_cv_header_libgt=
87       CATOBJEXT=NONE
88
89       AC_CHECK_HEADER(libintl.h,
90         [AC_CACHE_CHECK([for dgettext in libc], gt_cv_func_dgettext_libc,
91           [AC_TRY_LINK([#include <libintl.h>], [return (int) dgettext ("","")],
92             gt_cv_func_dgettext_libc=yes, gt_cv_func_dgettext_libc=no)])
93
94           if test "$gt_cv_func_dgettext_libc" != "yes"; then
95             AC_CHECK_LIB(intl, bindtextdomain,
96               [AC_CACHE_CHECK([for dgettext in libintl],
97                 gt_cv_func_dgettext_libintl,
98                 [AC_CHECK_LIB(intl, dgettext,
99                   gt_cv_func_dgettext_libintl=yes,
100                   gt_cv_func_dgettext_libintl=no)],
101                 gt_cv_func_dgettext_libintl=no)])
102           fi
103
104           if test "$gt_cv_func_dgettext_libintl" = "yes"; then
105             LIBS="$LIBS -lintl";
106           fi
107
108           if test "$gt_cv_func_dgettext_libc" = "yes" \
109             || test "$gt_cv_func_dgettext_libintl" = "yes"; then
110             AC_DEFINE(HAVE_GETTEXT)
111             AM_GLIB_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
112               [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
113             if test "$MSGFMT" != "no"; then
114               AC_CHECK_FUNCS(dcgettext)
115               AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
116               AM_GLIB_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
117                 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
118               AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
119                              return _nl_msg_cat_cntr],
120                 [CATOBJEXT=.gmo
121                  DATADIRNAME=share],
122                 [CATOBJEXT=.mo
123                  DATADIRNAME=lib])
124               INSTOBJEXT=.mo
125             fi
126           fi
127
128           # Added by Martin Baulig 12/15/98 for libc5 systems
129           if test "$gt_cv_func_dgettext_libc" != "yes" \
130             && test "$gt_cv_func_dgettext_libintl" = "yes"; then
131             INTLLIBS=-lintl
132             LIBS=`echo $LIBS | sed -e 's/-lintl//'`
133           fi
134       ])
135
136       if test "$CATOBJEXT" = "NONE"; then
137         dnl Neither gettext nor catgets in included in the C library.
138         dnl Fall back on GNU gettext library.
139         nls_cv_use_gnu_gettext=yes
140       fi
141     fi
142
143     if test "$nls_cv_use_gnu_gettext" != "yes"; then
144       AC_DEFINE(ENABLE_NLS)
145     else
146       dnl Unset this variable since we use the non-zero value as a flag.
147       CATOBJEXT=
148     fi
149
150     dnl Test whether we really found GNU xgettext.
151     if test "$XGETTEXT" != ":"; then
152       dnl If it is no GNU xgettext we define it as : so that the
153       dnl Makefiles still can work.
154       if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
155         : ;
156       else
157         AC_MSG_RESULT(
158           [found xgettext program is not GNU xgettext; ignore it])
159         XGETTEXT=":"
160       fi
161     fi
162
163     # We need to process the po/ directory.
164     POSUB=po
165
166     AC_OUTPUT_COMMANDS(
167       [case "$CONFIG_FILES" in *po/Makefile.in*)
168         sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
169       esac])
170
171     dnl These rules are solely for the distribution goal.  While doing this
172     dnl we only have to keep exactly one list of the available catalogs
173     dnl in configure.in.
174     for lang in $ALL_LINGUAS; do
175       GMOFILES="$GMOFILES $lang.gmo"
176       POFILES="$POFILES $lang.po"
177     done
178
179     dnl Make all variables we use known to autoconf.
180     AC_SUBST(CATALOGS)
181     AC_SUBST(CATOBJEXT)
182     AC_SUBST(DATADIRNAME)
183     AC_SUBST(GMOFILES)
184     AC_SUBST(INSTOBJEXT)
185     AC_SUBST(INTLDEPS)
186     AC_SUBST(INTLLIBS)
187     AC_SUBST(INTLOBJS)
188     AC_SUBST(POFILES)
189     AC_SUBST(POSUB)
190   ])
191
192 AC_DEFUN(AM_GLIB_GNU_GETTEXT,
193   [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
194    AC_REQUIRE([AC_PROG_CC])dnl
195    AC_REQUIRE([AC_PROG_RANLIB])dnl
196    AC_REQUIRE([AC_HEADER_STDC])dnl
197    AC_REQUIRE([AC_C_CONST])dnl
198    AC_REQUIRE([AC_C_INLINE])dnl
199    AC_REQUIRE([AC_TYPE_OFF_T])dnl
200    AC_REQUIRE([AC_TYPE_SIZE_T])dnl
201    AC_REQUIRE([AC_FUNC_ALLOCA])dnl
202    AC_REQUIRE([AC_FUNC_MMAP])dnl
203
204    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
205 unistd.h sys/param.h])
206    AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
207 strdup __argz_count __argz_stringify __argz_next])
208
209    AM_GLIB_LC_MESSAGES
210    AM_GLIB_WITH_NLS
211
212    if test "x$CATOBJEXT" != "x"; then
213      if test "x$ALL_LINGUAS" = "x"; then
214        LINGUAS=
215      else
216        AC_MSG_CHECKING(for catalogs to be installed)
217        NEW_LINGUAS=
218        for lang in ${LINGUAS=$ALL_LINGUAS}; do
219          case "$ALL_LINGUAS" in
220           *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
221          esac
222        done
223        LINGUAS=$NEW_LINGUAS
224        AC_MSG_RESULT($LINGUAS)
225      fi
226
227      dnl Construct list of names of catalog files to be constructed.
228      if test -n "$LINGUAS"; then
229        for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
230      fi
231    fi
232
233    dnl Determine which catalog format we have (if any is needed)
234    dnl For now we know about two different formats:
235    dnl   Linux libc-5 and the normal X/Open format
236    test -d po || mkdir po
237    if test "$CATOBJEXT" = ".cat"; then
238      AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
239
240      dnl Transform the SED scripts while copying because some dumb SEDs
241      dnl cannot handle comments.
242      sed -e '/^#/d' $srcdir/po/$msgformat-msg.sed > po/po2msg.sed
243    fi
244    dnl po2tbl.sed is always needed.
245    sed -e '/^#.*[^\\]$/d' -e '/^#$/d' \
246      $srcdir/po/po2tbl.sed.in > po/po2tbl.sed
247
248    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
249    dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
250    dnl Try to locate is.
251    MKINSTALLDIRS=
252    if test -n "$ac_aux_dir"; then
253      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
254    fi
255    if test -z "$MKINSTALLDIRS"; then
256      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
257    fi
258    AC_SUBST(MKINSTALLDIRS)
259
260    dnl Generate list of files to be processed by xgettext which will
261    dnl be included in po/Makefile.
262    test -d po || mkdir po
263    if test "x$srcdir" != "x."; then
264      if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
265        posrcprefix="$srcdir/"
266      else
267        posrcprefix="../$srcdir/"
268      fi
269    else
270      posrcprefix="../"
271    fi
272    rm -f po/POTFILES
273    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
274         < $srcdir/po/POTFILES.in > po/POTFILES
275   ])
276
277
278 dnl @synopsis AC_FUNC_VSNPRINTF_C99
279 dnl
280 dnl Check whether there is a vsnprintf() function with C99 semantics installed.
281 dnl
282 AC_DEFUN([AC_FUNC_VSNPRINTF_C99],
283 [AC_CACHE_CHECK(for C99 vsnprintf,
284   ac_cv_func_vsnprintf_c99,
285 [AC_TRY_RUN(
286 [#include <stdio.h>
287 #include <stdarg.h>
288
289 int
290 doit(char * s, ...)
291 {
292   char buffer[32];
293   va_list args;
294   int r;
295
296   va_start(args, s);
297   r = vsnprintf(buffer, 5, s, args);
298   va_end(args);
299
300   if (r != 7)
301     exit(1);
302
303   exit(0);
304 }
305
306 int
307 main(void)
308 {
309   doit("1234567");
310   exit(1);
311 }], ac_cv_func_vsnprintf_c99=yes, ac_cv_func_vsnprintf_c99=no, ac_cv_func_vsnprintf_c99=no)])
312 dnl Note that the default is to be pessimistic in the case of cross compilation.
313 dnl If you know that the target has a C99 vsnprintf(), you can get around this
314 dnl by setting ac_func_vsnprintf_c99 to yes, as described in the Autoconf manual.
315 if test $ac_cv_func_vsnprintf_c99 = yes; then
316   AC_DEFINE(HAVE_C99_VSNPRINTF, 1,
317             [Define if you have a version of the vsnprintf function
318              with semantics as specified by the ISO C99 standard.])
319 fi
320 ])# AC_FUNC_VSNPRINTF_C99
321