source: trunk/samba-3.0.25pre1/source/lib/replace/autoconf-2.60.m4@ 1

Last change on this file since 1 was 1, checked in by Paul Smedley, 19 years ago

Initial code import

File size: 5.2 KB
Line 
1# _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
2# ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
3# --------------------------------------------------------------
4# Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
5# by trying to compile a program of TEST-PROLOGUE and TEST-BODY. If this fails,
6# try again with each compiler option in the space-separated OPTION-LIST; if one
7# helps, append it to CC. If eventually successful, run ACTION-IF-AVAILABLE,
8# else ACTION-IF-UNAVAILABLE.
9AC_DEFUN([_AC_C_STD_TRY],
10[AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
11AC_CACHE_VAL(ac_cv_prog_cc_$1,
12[ac_cv_prog_cc_$1=no
13ac_save_CC=$CC
14AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
15for ac_arg in '' $4
16do
17 CC="$ac_save_CC $ac_arg"
18 _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
19 test "x$ac_cv_prog_cc_$1" != "xno" && break
20done
21rm -f conftest.$ac_ext
22CC=$ac_save_CC
23])# AC_CACHE_VAL
24case "x$ac_cv_prog_cc_$1" in
25 x)
26 AC_MSG_RESULT([none needed]) ;;
27 xno)
28 AC_MSG_RESULT([unsupported]) ;;
29 *)
30 CC="$CC $ac_cv_prog_cc_$1"
31 AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
32esac
33AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
34])# _AC_C_STD_TRY
35
36# _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
37# ----------------------------------------------------------------
38# If the C compiler is not in ISO C99 mode by default, try to add an
39# option to output variable CC to make it so. This macro tries
40# various options that select ISO C99 on some system or another. It
41# considers the compiler to be in ISO C99 mode if it handles mixed
42# code and declarations, _Bool, inline and restrict.
43AC_DEFUN([_AC_PROG_CC_C99],
44[_AC_C_STD_TRY([c99],
45[[#include <stdarg.h>
46#include <stdbool.h>
47#include <stdlib.h>
48#include <wchar.h>
49#include <stdio.h>
50
51struct incomplete_array
52{
53 int datasize;
54 double data[];
55};
56
57struct named_init {
58 int number;
59 const wchar_t *name;
60 double average;
61};
62
63typedef const char *ccp;
64
65static inline int
66test_restrict(ccp restrict text)
67{
68 // See if C++-style comments work.
69 // Iterate through items via the restricted pointer.
70 // Also check for declarations in for loops.
71 for (unsigned int i = 0; *(text+i) != '\0'; ++i)
72 continue;
73 return 0;
74}
75
76// Check varargs and va_copy work.
77static void
78test_varargs(const char *format, ...)
79{
80 va_list args;
81 va_start(args, format);
82 va_list args_copy;
83 va_copy(args_copy, args);
84
85 const char *str;
86 int number;
87 float fnumber;
88
89 while (*format)
90 {
91 switch (*format++)
92 {
93 case 's': // string
94 str = va_arg(args_copy, const char *);
95 break;
96 case 'd': // int
97 number = va_arg(args_copy, int);
98 break;
99 case 'f': // float
100 fnumber = (float) va_arg(args_copy, double);
101 break;
102 default:
103 break;
104 }
105 }
106 va_end(args_copy);
107 va_end(args);
108}
109]],
110[[
111 // Check bool and long long datatypes.
112 _Bool success = false;
113 long long int bignum = -1234567890LL;
114 unsigned long long int ubignum = 1234567890uLL;
115
116 // Check restrict.
117 if (test_restrict("String literal") != 0)
118 success = true;
119 char *restrict newvar = "Another string";
120
121 // Check varargs.
122 test_varargs("s, d' f .", "string", 65, 34.234);
123
124 // Check incomplete arrays work.
125 struct incomplete_array *ia =
126 malloc(sizeof(struct incomplete_array) + (sizeof(double) * 10));
127 ia->datasize = 10;
128 for (int i = 0; i < ia->datasize; ++i)
129 ia->data[i] = (double) i * 1.234;
130
131 // Check named initialisers.
132 struct named_init ni = {
133 .number = 34,
134 .name = L"Test wide string",
135 .average = 543.34343,
136 };
137
138 ni.number = 58;
139
140 int dynamic_array[ni.number];
141 dynamic_array[43] = 543;
142
143 // work around unused variable warnings
144 return bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x';
145]],
146dnl Try
147dnl GCC -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
148dnl AIX -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
149dnl Intel ICC -c99
150dnl IRIX -c99
151dnl Solaris (unused because it causes the compiler to assume C99 semantics for
152dnl library functions, and this is invalid before Solaris 10: -xc99)
153dnl Tru64 -c99
154dnl with extended modes being tried first.
155[[-std=gnu99 -c99 -qlanglvl=extc99]], [$1], [$2])[]dnl
156])# _AC_PROG_CC_C99
157
158# AC_PROG_CC_C99
159# --------------
160AC_DEFUN([AC_PROG_CC_C99],
161[ AC_REQUIRE([AC_PROG_CC])dnl
162 _AC_PROG_CC_C99
163])
164
165# AC_USE_SYSTEM_EXTENSIONS
166# ------------------------
167# Enable extensions on systems that normally disable them,
168# typically due to standards-conformance issues.
169AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS],
170[
171 AC_BEFORE([$0], [AC_COMPILE_IFELSE])
172 AC_BEFORE([$0], [AC_RUN_IFELSE])
173
174 AC_REQUIRE([AC_GNU_SOURCE])
175 AC_REQUIRE([AC_AIX])
176 AC_REQUIRE([AC_MINIX])
177
178 AH_VERBATIM([__EXTENSIONS__],
179[/* Enable extensions on Solaris. */
180#ifndef __EXTENSIONS__
181# undef __EXTENSIONS__
182#endif
183#ifndef _POSIX_PTHREAD_SEMANTICS
184# undef _POSIX_PTHREAD_SEMANTICS
185#endif])
186 AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
187 [ac_cv_safe_to_define___extensions__],
188 [AC_COMPILE_IFELSE(
189 [AC_LANG_PROGRAM([
190# define __EXTENSIONS__ 1
191 AC_INCLUDES_DEFAULT])],
192 [ac_cv_safe_to_define___extensions__=yes],
193 [ac_cv_safe_to_define___extensions__=no])])
194 test $ac_cv_safe_to_define___extensions__ = yes &&
195 AC_DEFINE([__EXTENSIONS__])
196 AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
197])
Note: See TracBrowser for help on using the repository browser.