The following patch corrects some function attributes. (#61780)
[platform/upstream/glib.git] / acinclude.m4
1 # Macro to add for using GNU gettext.
2 # Ulrich Drepper <drepper@cygnus.com>, 1995.
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 # serial 5
21
22 AC_DEFUN(AM_GLIB_WITH_NLS,
23   [AC_MSG_CHECKING([whether NLS is requested])
24     dnl Default is enabled NLS
25     AC_ARG_ENABLE(nls,
26       [  --disable-nls           do not use Native Language Support],
27       USE_NLS=$enableval, USE_NLS=yes)
28     AC_MSG_RESULT($USE_NLS)
29     AC_SUBST(USE_NLS)
30
31     USE_INCLUDED_LIBINTL=no
32
33     dnl If we use NLS figure out what method
34     if test "$USE_NLS" = "yes"; then
35       nls_cv_force_use_gnu_gettext="no"
36
37       nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
38       if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
39         dnl User does not insist on using GNU NLS library.  Figure out what
40         dnl to use.  If gettext or catgets are available (in this order) we
41         dnl use this.  Else we have to fall back to GNU NLS library.
42         dnl catgets is only used if permitted by option --with-catgets.
43         nls_cv_header_intl=
44         nls_cv_header_libgt=
45         CATOBJEXT=NONE
46
47         AC_CHECK_HEADER(libintl.h,
48           [AC_CACHE_CHECK([for dgettext in libc], gt_cv_func_dgettext_libc,
49             [AC_TRY_LINK([#include <libintl.h>], [return (int) dgettext ("","")],
50                gt_cv_func_dgettext_libc=yes, gt_cv_func_dgettext_libc=no)])
51
52            if test "$gt_cv_func_dgettext_libc" != "yes"; then
53              AC_CHECK_LIB(intl, bindtextdomain,
54                [AC_CACHE_CHECK([for dgettext in libintl],
55                  gt_cv_func_dgettext_libintl,
56                  [AC_CHECK_LIB(intl, dgettext,
57                   gt_cv_func_dgettext_libintl=yes,
58                   gt_cv_func_dgettext_libintl=no)],
59                  gt_cv_func_dgettext_libintl=no)])
60            fi
61
62            if test "$gt_cv_func_dgettext_libintl" = "yes"; then
63              LIBS="$LIBS -lintl";
64            fi
65
66            if test "$gt_cv_func_dgettext_libc" = "yes" \
67               || test "$gt_cv_func_dgettext_libintl" = "yes"; then
68               AC_DEFINE(HAVE_GETTEXT)
69               AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
70                 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
71               if test "$MSGFMT" != "no"; then
72                 AC_CHECK_FUNCS(dcgettext)
73                 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
74                 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
75                   [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
76                 AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
77                                return _nl_msg_cat_cntr],
78                   [CATOBJEXT=.gmo
79                    DATADIRNAME=share],
80                   [CATOBJEXT=.mo
81                    DATADIRNAME=lib])
82                 INSTOBJEXT=.mo
83               fi
84             fi
85
86             # Added by Martin Baulig 12/15/98 for libc5 systems
87             if test "$gt_cv_func_dgettext_libc" != "yes" \
88                && test "$gt_cv_func_dgettext_libintl" = "yes"; then
89                INTLLIBS=-lintl
90                LIBS=`echo $LIBS | sed -e 's/-lintl//'`
91             fi
92         ])
93
94         if test "$CATOBJEXT" = "NONE"; then
95           dnl Neither gettext nor catgets in included in the C library.
96           dnl Fall back on GNU gettext library.
97           nls_cv_use_gnu_gettext=yes
98         fi
99       fi
100
101       if test "$nls_cv_use_gnu_gettext" != "yes"; then
102         AC_DEFINE(ENABLE_NLS)
103       else
104          dnl Unset this variable since we use the non-zero value as a flag.
105          CATOBJEXT=
106       fi
107
108       dnl Test whether we really found GNU xgettext.
109       if test "$XGETTEXT" != ":"; then
110         dnl If it is no GNU xgettext we define it as : so that the
111         dnl Makefiles still can work.
112         if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
113           : ;
114         else
115           AC_MSG_RESULT(
116             [found xgettext program is not GNU xgettext; ignore it])
117           XGETTEXT=":"
118         fi
119       fi
120
121       # We need to process the po/ directory.
122       POSUB=po
123     else
124       DATADIRNAME=share
125     fi
126     AC_OUTPUT_COMMANDS(
127      [case "$CONFIG_FILES" in *po/Makefile.in*)
128         sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
129       esac])
130
131     dnl These rules are solely for the distribution goal.  While doing this
132     dnl we only have to keep exactly one list of the available catalogs
133     dnl in configure.in.
134     for lang in $ALL_LINGUAS; do
135       GMOFILES="$GMOFILES $lang.gmo"
136       POFILES="$POFILES $lang.po"
137     done
138
139     dnl Make all variables we use known to autoconf.
140     AC_SUBST(USE_INCLUDED_LIBINTL)
141     AC_SUBST(CATALOGS)
142     AC_SUBST(CATOBJEXT)
143     AC_SUBST(DATADIRNAME)
144     AC_SUBST(GMOFILES)
145     AC_SUBST(INSTOBJEXT)
146     AC_SUBST(INTLDEPS)
147     AC_SUBST(INTLLIBS)
148     AC_SUBST(INTLOBJS)
149     AC_SUBST(POFILES)
150     AC_SUBST(POSUB)
151   ])
152
153 AC_DEFUN(AM_GLIB_GNU_GETTEXT,
154   [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
155    AC_REQUIRE([AC_PROG_CC])dnl
156    AC_REQUIRE([AC_PROG_RANLIB])dnl
157    AC_REQUIRE([AC_HEADER_STDC])dnl
158    AC_REQUIRE([AC_C_CONST])dnl
159    AC_REQUIRE([AC_C_INLINE])dnl
160    AC_REQUIRE([AC_TYPE_OFF_T])dnl
161    AC_REQUIRE([AC_TYPE_SIZE_T])dnl
162    AC_REQUIRE([AC_FUNC_ALLOCA])dnl
163    AC_REQUIRE([AC_FUNC_MMAP])dnl
164
165    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
166 unistd.h sys/param.h])
167    AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
168 strdup __argz_count __argz_stringify __argz_next])
169
170    AM_LC_MESSAGES
171    AM_GLIB_WITH_NLS
172
173    if test "x$CATOBJEXT" != "x"; then
174      if test "x$ALL_LINGUAS" = "x"; then
175        LINGUAS=
176      else
177        AC_MSG_CHECKING(for catalogs to be installed)
178        NEW_LINGUAS=
179        for lang in ${LINGUAS=$ALL_LINGUAS}; do
180          case "$ALL_LINGUAS" in
181           *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
182          esac
183        done
184        LINGUAS=$NEW_LINGUAS
185        AC_MSG_RESULT($LINGUAS)
186      fi
187
188      dnl Construct list of names of catalog files to be constructed.
189      if test -n "$LINGUAS"; then
190        for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
191      fi
192    fi
193
194    dnl Determine which catalog format we have (if any is needed)
195    dnl For now we know about two different formats:
196    dnl   Linux libc-5 and the normal X/Open format
197    test -d po || mkdir po
198    if test "$CATOBJEXT" = ".cat"; then
199      AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
200
201      dnl Transform the SED scripts while copying because some dumb SEDs
202      dnl cannot handle comments.
203      sed -e '/^#/d' $srcdir/po/$msgformat-msg.sed > po/po2msg.sed
204    fi
205    dnl po2tbl.sed is always needed.
206    sed -e '/^#.*[^\\]$/d' -e '/^#$/d' \
207      $srcdir/po/po2tbl.sed.in > po/po2tbl.sed
208
209    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
210    dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
211    dnl Try to locate is.
212    MKINSTALLDIRS=
213    if test -n "$ac_aux_dir"; then
214      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
215    fi
216    if test -z "$MKINSTALLDIRS"; then
217      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
218    fi
219    AC_SUBST(MKINSTALLDIRS)
220
221    dnl Generate list of files to be processed by xgettext which will
222    dnl be included in po/Makefile.
223    test -d po || mkdir po
224    if test "x$srcdir" != "x."; then
225      if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
226        posrcprefix="$srcdir/"
227      else
228        posrcprefix="../$srcdir/"
229      fi
230    else
231      posrcprefix="../"
232    fi
233    rm -f po/POTFILES
234    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
235         < $srcdir/po/POTFILES.in > po/POTFILES
236   ])
237
238 dnl @synopsis AC_FUNC_VSNPRINTF_C99
239 dnl
240 dnl Check whether there is a vsnprintf() function with C99 semantics installed.
241 dnl
242 AC_DEFUN([AC_FUNC_VSNPRINTF_C99],
243 [AC_CACHE_CHECK(for C99 vsnprintf,
244   ac_cv_func_vsnprintf_c99,
245 [AC_TRY_RUN(
246 [#include <stdio.h>
247 #include <stdarg.h>
248
249 int
250 doit(char * s, ...)
251 {
252   char buffer[32];
253   va_list args;
254   int r;
255
256   va_start(args, s);
257   r = vsnprintf(buffer, 5, s, args);
258   va_end(args);
259
260   if (r != 7)
261     exit(1);
262
263   exit(0);
264 }
265
266 int
267 main(void)
268 {
269   doit("1234567");
270   exit(1);
271 }], ac_cv_func_vsnprintf_c99=yes, ac_cv_func_vsnprintf_c99=no, ac_cv_func_vsnprintf_c99=no)])
272 dnl Note that the default is to be pessimistic in the case of cross compilation.
273 dnl If you know that the target has a C99 vsnprintf(), you can get around this
274 dnl by setting ac_func_vsnprintf_c99 to yes, as described in the Autoconf manual.
275 if test $ac_cv_func_vsnprintf_c99 = yes; then
276   AC_DEFINE(HAVE_C99_VSNPRINTF, 1,
277             [Define if you have a version of the vsnprintf function
278              with semantics as specified by the ISO C99 standard.])
279 fi
280 ])# AC_FUNC_VSNPRINTF_C99
281