4fe1e02fba3e455e83fd57b3a1b11f011a6ede70
[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       XGETTEXT=:
89
90       AC_CHECK_HEADER(libintl.h,
91         [AC_CACHE_CHECK([for dgettext in libc], gt_cv_func_dgettext_libc,
92           [AC_TRY_LINK([#include <libintl.h>], [return (int) dgettext ("","")],
93             gt_cv_func_dgettext_libc=yes, gt_cv_func_dgettext_libc=no)])
94
95           gt_cv_func_dgettext_libintl="no"
96           libintl_extra_libs=""
97
98           if test "$gt_cv_func_dgettext_libc" != "yes" ; then
99             AC_CHECK_LIB(intl, bindtextdomain,
100               [AC_CHECK_LIB(intl, dgettext,
101                             gt_cv_func_dgettext_libintl=yes)])
102
103             if test "$gt_cv_func_dgettext_libc" != "yes" ; then
104               AC_MSG_CHECKING([if -liconv is needed to use gettext])
105               AC_MSG_RESULT([])
106               AC_CHECK_LIB(intl, dcgettext,
107                            [gt_cv_func_dgettext_libintl=yes
108                             libintl_extra_libs=-liconv],
109                            :,-liconv)
110             fi
111           fi
112
113           if test "$gt_cv_func_dgettext_libintl" = "yes"; then
114             LIBS="$LIBS -lintl $libintl_extra_libs";
115           fi
116
117           if test "$gt_cv_func_dgettext_libc" = "yes" \
118             || test "$gt_cv_func_dgettext_libintl" = "yes"; then
119             AC_DEFINE(HAVE_GETTEXT,1,
120               [Define if the GNU gettext() function is already present or preinstalled.])
121             AM_GLIB_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
122               [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
123             if test "$MSGFMT" != "no"; then
124               AC_CHECK_FUNCS(dcgettext)
125               AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
126               AM_GLIB_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
127                 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
128               AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
129                              return _nl_msg_cat_cntr],
130                 [CATOBJEXT=.gmo
131                  DATADIRNAME=share],
132                 [CATOBJEXT=.mo
133                  DATADIRNAME=lib])
134               INSTOBJEXT=.mo
135             fi
136           fi
137
138           # Added by Martin Baulig 12/15/98 for libc5 systems
139           if test "$gt_cv_func_dgettext_libc" != "yes" \
140             && test "$gt_cv_func_dgettext_libintl" = "yes"; then
141             INTLLIBS="-lintl $libintl_extra_libs"
142             LIBS=`echo $LIBS | sed -e 's/-lintl//'`
143           fi
144       ])
145
146       if test "$CATOBJEXT" = "NONE"; then
147         dnl Neither gettext nor catgets in included in the C library.
148         dnl Fall back on GNU gettext library.
149         nls_cv_use_gnu_gettext=yes
150       fi
151     fi
152
153     if test "$nls_cv_use_gnu_gettext" != "yes"; then
154       AC_DEFINE(ENABLE_NLS, 1,
155         [always defined to indicate that i18n is enabled])
156     else
157       dnl Unset this variable since we use the non-zero value as a flag.
158       CATOBJEXT=
159     fi
160
161     dnl Test whether we really found GNU xgettext.
162     if test "$XGETTEXT" != ":"; then
163       dnl If it is no GNU xgettext we define it as : so that the
164       dnl Makefiles still can work.
165       if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
166         : ;
167       else
168         AC_MSG_RESULT(
169           [found xgettext program is not GNU xgettext; ignore it])
170         XGETTEXT=":"
171       fi
172     fi
173
174     # We need to process the po/ directory.
175     POSUB=po
176
177     AC_OUTPUT_COMMANDS(
178       [case "$CONFIG_FILES" in *po/Makefile.in*)
179         sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
180       esac])
181
182     dnl These rules are solely for the distribution goal.  While doing this
183     dnl we only have to keep exactly one list of the available catalogs
184     dnl in configure.in.
185     for lang in $ALL_LINGUAS; do
186       GMOFILES="$GMOFILES $lang.gmo"
187       POFILES="$POFILES $lang.po"
188     done
189
190     dnl Make all variables we use known to autoconf.
191     AC_SUBST(CATALOGS)
192     AC_SUBST(CATOBJEXT)
193     AC_SUBST(DATADIRNAME)
194     AC_SUBST(GMOFILES)
195     AC_SUBST(INSTOBJEXT)
196     AC_SUBST(INTLDEPS)
197     AC_SUBST(INTLLIBS)
198     AC_SUBST(INTLOBJS)
199     AC_SUBST(POFILES)
200     AC_SUBST(POSUB)
201   ])
202
203 AC_DEFUN(AM_GLIB_GNU_GETTEXT,
204   [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
205    AC_REQUIRE([AC_PROG_CC])dnl
206    AC_REQUIRE([AC_PROG_RANLIB])dnl
207    AC_REQUIRE([AC_HEADER_STDC])dnl
208    AC_REQUIRE([AC_C_CONST])dnl
209    AC_REQUIRE([AC_C_INLINE])dnl
210    AC_REQUIRE([AC_TYPE_OFF_T])dnl
211    AC_REQUIRE([AC_TYPE_SIZE_T])dnl
212    AC_REQUIRE([AC_FUNC_ALLOCA])dnl
213    AC_REQUIRE([AC_FUNC_MMAP])dnl
214
215    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
216 unistd.h sys/param.h])
217    AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
218 strdup __argz_count __argz_stringify __argz_next])
219
220    AM_GLIB_LC_MESSAGES
221    AM_GLIB_WITH_NLS
222
223    if test "x$CATOBJEXT" != "x"; then
224      if test "x$ALL_LINGUAS" = "x"; then
225        LINGUAS=
226      else
227        AC_MSG_CHECKING(for catalogs to be installed)
228        NEW_LINGUAS=
229        for lang in ${LINGUAS=$ALL_LINGUAS}; do
230          case "$ALL_LINGUAS" in
231           *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
232          esac
233        done
234        LINGUAS=$NEW_LINGUAS
235        AC_MSG_RESULT($LINGUAS)
236      fi
237
238      dnl Construct list of names of catalog files to be constructed.
239      if test -n "$LINGUAS"; then
240        for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
241      fi
242    fi
243
244    dnl Determine which catalog format we have (if any is needed)
245    dnl For now we know about two different formats:
246    dnl   Linux libc-5 and the normal X/Open format
247    test -d po || mkdir po
248    if test "$CATOBJEXT" = ".cat"; then
249      AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
250
251      dnl Transform the SED scripts while copying because some dumb SEDs
252      dnl cannot handle comments.
253      sed -e '/^#/d' $srcdir/po/$msgformat-msg.sed > po/po2msg.sed
254    fi
255
256    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
257    dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
258    dnl Try to locate is.
259    MKINSTALLDIRS=
260    if test -n "$ac_aux_dir"; then
261      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
262    fi
263    if test -z "$MKINSTALLDIRS"; then
264      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
265    fi
266    AC_SUBST(MKINSTALLDIRS)
267
268    dnl Generate list of files to be processed by xgettext which will
269    dnl be included in po/Makefile.
270    test -d po || mkdir po
271    if test "x$srcdir" != "x."; then
272      if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
273        posrcprefix="$srcdir/"
274      else
275        posrcprefix="../$srcdir/"
276      fi
277    else
278      posrcprefix="../"
279    fi
280    rm -f po/POTFILES
281    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
282         < $srcdir/po/POTFILES.in > po/POTFILES
283   ])
284
285
286 dnl @synopsis AC_FUNC_VSNPRINTF_C99
287 dnl
288 dnl Check whether there is a vsnprintf() function with C99 semantics installed.
289 dnl
290 AC_DEFUN([AC_FUNC_VSNPRINTF_C99],
291 [AC_CACHE_CHECK(for C99 vsnprintf,
292   ac_cv_func_vsnprintf_c99,
293 [AC_TRY_RUN(
294 [#include <stdio.h>
295 #include <stdarg.h>
296
297 int
298 doit(char * s, ...)
299 {
300   char buffer[32];
301   va_list args;
302   int r;
303
304   va_start(args, s);
305   r = vsnprintf(buffer, 5, s, args);
306   va_end(args);
307
308   if (r != 7)
309     exit(1);
310
311   exit(0);
312 }
313
314 int
315 main(void)
316 {
317   doit("1234567");
318   exit(1);
319 }], ac_cv_func_vsnprintf_c99=yes, ac_cv_func_vsnprintf_c99=no, ac_cv_func_vsnprintf_c99=no)])
320 dnl Note that the default is to be pessimistic in the case of cross compilation.
321 dnl If you know that the target has a C99 vsnprintf(), you can get around this
322 dnl by setting ac_func_vsnprintf_c99 to yes, as described in the Autoconf manual.
323 if test $ac_cv_func_vsnprintf_c99 = yes; then
324   AC_DEFINE(HAVE_C99_VSNPRINTF, 1,
325             [Define if you have a version of the vsnprintf function
326              with semantics as specified by the ISO C99 standard.])
327 fi
328 ])# AC_FUNC_VSNPRINTF_C99
329