Integrate gnulib vasnprintf().
[platform/upstream/glib.git] / acinclude.m4
1 dnl @synopsis AC_FUNC_VSNPRINTF_C99
2 dnl
3 dnl Check whether there is a vsnprintf() function with C99 semantics installed.
4 dnl
5 AC_DEFUN([AC_FUNC_VSNPRINTF_C99],
6 [AC_CACHE_CHECK(for C99 vsnprintf,
7   ac_cv_func_vsnprintf_c99,
8 [AC_TRY_RUN(
9 [#include <stdio.h>
10 #include <stdarg.h>
11
12 int
13 doit(char * s, ...)
14 {
15   char buffer[32];
16   va_list args;
17   int r;
18
19   va_start(args, s);
20   r = vsnprintf(buffer, 5, s, args);
21   va_end(args);
22
23   if (r != 7)
24     exit(1);
25
26   exit(0);
27 }
28
29 int
30 main(void)
31 {
32   doit("1234567");
33   exit(1);
34 }], ac_cv_func_vsnprintf_c99=yes, ac_cv_func_vsnprintf_c99=no, ac_cv_func_vsnprintf_c99=no)])
35 dnl Note that the default is to be pessimistic in the case of cross compilation.
36 dnl If you know that the target has a C99 vsnprintf(), you can get around this
37 dnl by setting ac_func_vsnprintf_c99 to yes, as described in the Autoconf manual.
38 if test $ac_cv_func_vsnprintf_c99 = yes; then
39   AC_DEFINE(HAVE_C99_VSNPRINTF, 1,
40             [Define if you have a version of the vsnprintf function
41              with semantics as specified by the ISO C99 standard.])
42 fi
43 ])# AC_FUNC_VSNPRINTF_C99
44
45
46 dnl @synopsis AC_FUNC_SNPRINTF_C99
47 dnl
48 dnl Check whether there is a snprintf() function with C99 semantics installed.
49 dnl
50 AC_DEFUN([AC_FUNC_SNPRINTF_C99],
51 [AC_CACHE_CHECK(for C99 snprintf,
52   ac_cv_func_snprintf_c99,
53 [AC_TRY_RUN(
54 [#include <stdio.h>
55 #include <stdarg.h>
56
57 int
58 doit()
59 {
60   char buffer[32];
61   va_list args;
62   int r;
63
64   r = snprintf(buffer, 5, "1234567");
65
66   if (r != 7)
67     exit(1);
68
69   exit(0);
70 }
71
72 int
73 main(void)
74 {
75   doit();
76   exit(1);
77 }], ac_cv_func_snprintf_c99=yes, ac_cv_func_snprintf_c99=no, ac_cv_func_snprintf_c99=no)])
78 dnl Note that the default is to be pessimistic in the case of cross compilation.
79 dnl If you know that the target has a C99 snprintf(), you can get around this
80 dnl by setting ac_func_snprintf_c99 to yes, as described in the Autoconf manual.
81 if test $ac_cv_func_snprintf_c99 = yes; then
82   AC_DEFINE(HAVE_C99_SNPRINTF, 1,
83             [Define if you have a version of the snprintf function
84              with semantics as specified by the ISO C99 standard.])
85 fi
86 ])# AC_FUNC_SNPRINTF_C99
87
88
89 dnl @synopsis AC_FUNC_PRINTF_UNIX98
90 dnl
91 dnl Check whether the printf() family supports Unix98 %n$ positional parameters 
92 dnl
93 AC_DEFUN([AC_FUNC_PRINTF_UNIX98],
94 [AC_CACHE_CHECK(whether printf supports positional parameters,
95   ac_cv_func_printf_unix98,
96 [AC_TRY_RUN(
97 [#include <stdio.h>
98
99 int
100 main (void)
101 {
102   char buffer[128];
103
104   sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3);
105   if (strcmp ("2 3 1", buffer) == 0)
106     exit (0);
107   exit (1);
108 }], ac_cv_func_printf_unix98=yes, ac_cv_func_printf_unix98=no, ac_cv_func_printf_unix98=no)])
109 dnl Note that the default is to be pessimistic in the case of cross compilation.
110 dnl If you know that the target printf() supports positional parameters, you can get around 
111 dnl this by setting ac_func_printf_unix98 to yes, as described in the Autoconf manual.
112 if test $ac_cv_func_printf_unix98 = yes; then
113   AC_DEFINE(HAVE_UNIX98_PRINTF, 1,
114             [Define if your printf function family supports positional parameters
115              as specified by Unix98.])
116 fi
117 ])# AC_FUNC_PRINTF_UNIX98
118
119 # Checks the location of the XML Catalog
120 # Usage:
121 #   JH_PATH_XML_CATALOG
122 # Defines XMLCATALOG and XML_CATALOG_FILE substitutions
123 AC_DEFUN([JH_PATH_XML_CATALOG],
124 [
125   # check for the presence of the XML catalog
126   AC_ARG_WITH([xml-catalog],
127               AC_HELP_STRING([--with-xml-catalog=CATALOG],
128                              [path to xml catalog to use]),,
129               [with_xml_catalog=/etc/xml/catalog])
130   XML_CATALOG_FILE="$with_xml_catalog"
131   AC_MSG_CHECKING([for XML catalog ($XML_CATALOG_FILE)])
132   if test -f "$XML_CATALOG_FILE"; then
133     AC_MSG_RESULT([found])
134   else
135     AC_MSG_RESULT([not found])
136     AC_MSG_ERROR([XML catalog not found])
137   fi
138   AC_SUBST([XML_CATALOG_FILE])
139
140   # check for the xmlcatalog program
141   AC_PATH_PROG(XMLCATALOG, xmlcatalog, no)
142   if test "x$XMLCATALOG" = xno; then
143     AC_MSG_ERROR([could not find xmlcatalog program])
144   fi
145 ])
146
147 # Checks if a particular URI appears in the XML catalog
148 # Usage:
149 #   JH_CHECK_XML_CATALOG(URI, [FRIENDLY-NAME], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
150 AC_DEFUN([JH_CHECK_XML_CATALOG],
151 [
152   AC_REQUIRE([JH_PATH_XML_CATALOG])dnl
153   AC_MSG_CHECKING([for ifelse([$2],,[$1],[$2]) in XML catalog])
154   if AC_RUN_LOG([$XMLCATALOG --noout "$XML_CATALOG_FILE" "$1" >&2]); then
155     AC_MSG_RESULT([found])
156     ifelse([$3],,,[$3
157 ])dnl
158   else
159     AC_MSG_RESULT([not found])
160     ifelse([$4],,
161        [AC_MSG_ERROR([could not find ifelse([$2],,[$1],[$2]) in XML catalog])],
162        [$4])
163   fi
164 ])
165
166
167 # signed.m4 serial 1 (gettext-0.10.40)
168 dnl Copyright (C) 2001-2002 Free Software Foundation, Inc.
169 dnl This file is free software, distributed under the terms of the GNU
170 dnl General Public License.  As a special exception to the GNU General
171 dnl Public License, this file may be distributed as part of a program
172 dnl that contains a configuration script generated by Autoconf, under
173 dnl the same distribution terms as the rest of that program.
174
175 dnl From Bruno Haible.
176
177 AC_DEFUN([bh_C_SIGNED],
178 [
179   AC_CACHE_CHECK([for signed], bh_cv_c_signed,
180    [AC_TRY_COMPILE(, [signed char x;], bh_cv_c_signed=yes, bh_cv_c_signed=no)])
181   if test $bh_cv_c_signed = no; then
182     AC_DEFINE(signed, ,
183               [Define to empty if the C compiler doesn't support this keyword.])
184   fi
185 ])
186
187
188 # longlong.m4 serial 4
189 dnl Copyright (C) 1999-2003 Free Software Foundation, Inc.
190 dnl This file is free software, distributed under the terms of the GNU
191 dnl General Public License.  As a special exception to the GNU General
192 dnl Public License, this file may be distributed as part of a program
193 dnl that contains a configuration script generated by Autoconf, under
194 dnl the same distribution terms as the rest of that program.
195
196 dnl From Paul Eggert.
197
198 # Define HAVE_LONG_LONG if 'long long' works.
199
200 AC_DEFUN([jm_AC_TYPE_LONG_LONG],
201 [
202   AC_CACHE_CHECK([for long long], ac_cv_type_long_long,
203   [AC_TRY_LINK([long long ll = 1LL; int i = 63;],
204     [long long llmax = (long long) -1;
205      return ll << i | ll >> i | llmax / ll | llmax % ll;],
206     ac_cv_type_long_long=yes,
207     ac_cv_type_long_long=no)])
208   if test $ac_cv_type_long_long = yes; then
209     AC_DEFINE(HAVE_LONG_LONG, 1,
210       [Define if you have the 'long long' type.])
211   fi
212 ])
213
214
215 # longdouble.m4 serial 1 (gettext-0.11.6)
216 dnl Copyright (C) 2002 Free Software Foundation, Inc.
217 dnl This file is free software, distributed under the terms of the GNU
218 dnl General Public License.  As a special exception to the GNU General
219 dnl Public License, this file may be distributed as part of a program
220 dnl that contains a configuration script generated by Autoconf, under
221 dnl the same distribution terms as the rest of that program.
222
223 dnl From Bruno Haible.
224 dnl Test whether the compiler supports the 'long double' type.
225 dnl Prerequisite: AC_PROG_CC
226
227 AC_DEFUN([gt_TYPE_LONGDOUBLE],
228 [
229   AC_CACHE_CHECK([for long double], gt_cv_c_long_double,
230     [if test "$GCC" = yes; then
231        gt_cv_c_long_double=yes
232      else
233        AC_TRY_COMPILE([
234          /* The Stardent Vistra knows sizeof(long double), but does not support it.  */
235          long double foo = 0.0;
236          /* On Ultrix 4.3 cc, long double is 4 and double is 8.  */
237          int array [2*(sizeof(long double) >= sizeof(double)) - 1];
238          ], ,
239          gt_cv_c_long_double=yes, gt_cv_c_long_double=no)
240      fi])
241   if test $gt_cv_c_long_double = yes; then
242     AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the 'long double' type.])
243   fi
244 ])
245
246
247
248 # wchar_t.m4 serial 1 (gettext-0.11.6)
249 dnl Copyright (C) 2002 Free Software Foundation, Inc.
250 dnl This file is free software, distributed under the terms of the GNU
251 dnl General Public License.  As a special exception to the GNU General
252 dnl Public License, this file may be distributed as part of a program
253 dnl that contains a configuration script generated by Autoconf, under
254 dnl the same distribution terms as the rest of that program.
255
256 dnl From Bruno Haible.
257 dnl Test whether <stddef.h> has the 'wchar_t' type.
258 dnl Prerequisite: AC_PROG_CC
259
260 AC_DEFUN([gt_TYPE_WCHAR_T],
261 [
262   AC_CACHE_CHECK([for wchar_t], gt_cv_c_wchar_t,
263     [AC_TRY_COMPILE([#include <stddef.h>
264        wchar_t foo = (wchar_t)'\0';], ,
265        gt_cv_c_wchar_t=yes, gt_cv_c_wchar_t=no)])
266   if test $gt_cv_c_wchar_t = yes; then
267     AC_DEFINE(HAVE_WCHAR_T, 1, [Define if you have the 'wchar_t' type.])
268   fi
269 ])
270
271
272 # wint_t.m4 serial 1
273 dnl Copyright (C) 2003 Free Software Foundation, Inc.
274 dnl This file is free software, distributed under the terms of the GNU
275 dnl General Public License.  As a special exception to the GNU General
276 dnl Public License, this file may be distributed as part of a program
277 dnl that contains a configuration script generated by Autoconf, under
278 dnl the same distribution terms as the rest of that program.
279
280 dnl From Bruno Haible.
281 dnl Test whether <wchar.h> has the 'wint_t' type.
282 dnl Prerequisite: AC_PROG_CC
283
284 AC_DEFUN([gt_TYPE_WINT_T],
285 [
286   AC_CACHE_CHECK([for wint_t], gt_cv_c_wint_t,
287     [AC_TRY_COMPILE([#include <wchar.h>
288        wint_t foo = (wchar_t)'\0';], ,
289        gt_cv_c_wint_t=yes, gt_cv_c_wint_t=no)])
290   if test $gt_cv_c_wint_t = yes; then
291     AC_DEFINE(HAVE_WINT_T, 1, [Define if you have the 'wint_t' type.])
292   fi
293 ])
294
295
296 # intmax_t.m4 serial 1
297 dnl Copyright (C) 1997-2002 Free Software Foundation, Inc.
298 dnl This file is free software, distributed under the terms of the GNU
299 dnl General Public License.  As a special exception to the GNU General
300 dnl Public License, this file may be distributed as part of a program
301 dnl that contains a configuration script generated by Autoconf, under
302 dnl the same distribution terms as the rest of that program.
303
304 dnl From Paul Eggert.
305
306 AC_PREREQ(2.13)
307
308 # Define intmax_t to 'long' or 'long long'
309 # if it is not already defined in <stdint.h> or <inttypes.h>.
310
311 AC_DEFUN([jm_AC_TYPE_INTMAX_T],
312 [
313   dnl For simplicity, we assume that a header file defines 'intmax_t' if and
314   dnl only if it defines 'uintmax_t'.
315   AC_REQUIRE([jm_AC_HEADER_INTTYPES_H])
316   AC_REQUIRE([jm_AC_HEADER_STDINT_H])
317   if test $jm_ac_cv_header_inttypes_h = no && test $jm_ac_cv_header_stdint_h = no; then
318     AC_REQUIRE([jm_AC_TYPE_LONG_LONG])
319     test $ac_cv_type_long_long = yes \
320       && ac_type='long long' \
321       || ac_type='long'
322     AC_DEFINE_UNQUOTED(intmax_t, $ac_type,
323      [Define to long or long long if <inttypes.h> and <stdint.h> don't define.])
324   else
325     AC_DEFINE(HAVE_INTMAX_T, 1,
326       [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
327   fi
328 ])
329
330 dnl An alternative would be to explicitly test for 'intmax_t'.
331
332 AC_DEFUN([gt_AC_TYPE_INTMAX_T],
333 [
334   AC_REQUIRE([jm_AC_HEADER_INTTYPES_H])
335   AC_REQUIRE([jm_AC_HEADER_STDINT_H])
336   AC_CACHE_CHECK(for intmax_t, gt_cv_c_intmax_t,
337     [AC_TRY_COMPILE([
338 #include <stddef.h> 
339 #include <stdlib.h>
340 #if HAVE_STDINT_H_WITH_UINTMAX
341 #include <stdint.h>
342 #endif
343 #if HAVE_INTTYPES_H_WITH_UINTMAX
344 #include <inttypes.h>
345 #endif
346 ], [intmax_t x = -1;], gt_cv_c_intmax_t=yes, gt_cv_c_intmax_t=no)])
347   if test $gt_cv_c_intmax_t = yes; then
348     AC_DEFINE(HAVE_INTMAX_T, 1,
349       [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
350   else
351     AC_REQUIRE([jm_AC_TYPE_LONG_LONG])
352     test $ac_cv_type_long_long = yes \
353       && ac_type='long long' \
354       || ac_type='long'
355     AC_DEFINE_UNQUOTED(intmax_t, $ac_type,
356      [Define to long or long long if <stdint.h> and <inttypes.h> don't define.])
357   fi
358 ])
359
360
361 # stdint_h.m4 serial 3 (gettext-0.11.6)
362 dnl Copyright (C) 1997-2002 Free Software Foundation, Inc.
363 dnl This file is free software, distributed under the terms of the GNU
364 dnl General Public License.  As a special exception to the GNU General
365 dnl Public License, this file may be distributed as part of a program
366 dnl that contains a configuration script generated by Autoconf, under
367 dnl the same distribution terms as the rest of that program.
368
369 dnl From Paul Eggert.
370
371 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
372 # doesn't clash with <sys/types.h>, and declares uintmax_t.
373
374 AC_DEFUN([jm_AC_HEADER_STDINT_H],
375 [
376   AC_CACHE_CHECK([for stdint.h], jm_ac_cv_header_stdint_h,
377   [AC_TRY_COMPILE(
378     [#include <sys/types.h>
379 #include <stdint.h>],
380     [uintmax_t i = (uintmax_t) -1;],
381     jm_ac_cv_header_stdint_h=yes,
382     jm_ac_cv_header_stdint_h=no)])
383   if test $jm_ac_cv_header_stdint_h = yes; then
384     AC_DEFINE_UNQUOTED(HAVE_STDINT_H_WITH_UINTMAX, 1,
385       [Define if <stdint.h> exists, doesn't clash with <sys/types.h>,
386        and declares uintmax_t. ])
387   fi
388 ])
389
390
391 # inttypes_h.m4 serial 5 (gettext-0.11.6)
392 dnl Copyright (C) 1997-2002 Free Software Foundation, Inc.
393 dnl This file is free software, distributed under the terms of the GNU
394 dnl General Public License.  As a special exception to the GNU General
395 dnl Public License, this file may be distributed as part of a program
396 dnl that contains a configuration script generated by Autoconf, under
397 dnl the same distribution terms as the rest of that program.
398
399 dnl From Paul Eggert.
400
401 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
402 # doesn't clash with <sys/types.h>, and declares uintmax_t.
403
404 AC_DEFUN([jm_AC_HEADER_INTTYPES_H],
405 [
406   AC_CACHE_CHECK([for inttypes.h], jm_ac_cv_header_inttypes_h,
407   [AC_TRY_COMPILE(
408     [#include <sys/types.h>
409 #include <inttypes.h>],
410     [uintmax_t i = (uintmax_t) -1;],
411     jm_ac_cv_header_inttypes_h=yes,
412     jm_ac_cv_header_inttypes_h=no)])
413   if test $jm_ac_cv_header_inttypes_h = yes; then
414     AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H_WITH_UINTMAX, 1,
415       [Define if <inttypes.h> exists, doesn't clash with <sys/types.h>,
416        and declares uintmax_t. ])
417   fi
418 ])
419
420