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