]> git.ipfire.org Git - people/ms/suricata.git/blame - acsite.m4
yaml: group ICS protocols together
[people/ms/suricata.git] / acsite.m4
CommitLineData
58396a9a
WM
1#These defines are needed because CentOS5 uses a old version of autoconf
2#
3AC_DEFUN([AC_TYPE_INT8_T], [_AC_TYPE_INT(8)])
4AC_DEFUN([AC_TYPE_INT16_T], [_AC_TYPE_INT(16)])
5AC_DEFUN([AC_TYPE_INT32_T], [_AC_TYPE_INT(32)])
6AC_DEFUN([AC_TYPE_INT64_T], [_AC_TYPE_INT(64)])
7AC_DEFUN([AC_TYPE_UINT8_T], [_AC_TYPE_UNSIGNED_INT(8)])
8AC_DEFUN([AC_TYPE_UINT16_T], [_AC_TYPE_UNSIGNED_INT(16)])
9AC_DEFUN([AC_TYPE_UINT32_T], [_AC_TYPE_UNSIGNED_INT(32)])
10AC_DEFUN([AC_TYPE_UINT64_T], [_AC_TYPE_UNSIGNED_INT(64)])
11
12# _AC_TYPE_INT(NBITS)
13# -------------------
14AC_DEFUN([_AC_TYPE_INT],
15[
16 AC_CACHE_CHECK([for int$1_t], [ac_cv_c_int$1_t],
17 [ac_cv_c_int$1_t=no
18 for ac_type in 'int$1_t' 'int' 'long int' \
19 'long long int' 'short int' 'signed char'; do
20 AC_COMPILE_IFELSE(
21 [AC_LANG_BOOL_COMPILE_TRY(
22 [AC_INCLUDES_DEFAULT],
23 [[0 < ($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 1)]])],
24 [AC_COMPILE_IFELSE(
25 [AC_LANG_BOOL_COMPILE_TRY(
26 [AC_INCLUDES_DEFAULT],
27 [[($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 1)
28 < ($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 2)]])],
29 [],
30 [AS_CASE([$ac_type], [int$1_t],
31 [ac_cv_c_int$1_t=yes],
32 [ac_cv_c_int$1_t=$ac_type])])])
33 test "$ac_cv_c_int$1_t" != no && break
34 done])
35 case $ac_cv_c_int$1_t in #(
36 no|yes) ;; #(
37 *)
38 AC_DEFINE_UNQUOTED([int$1_t], [$ac_cv_c_int$1_t],
39 [Define to the type of a signed integer type of width exactly $1 bits
40 if such a type exists and the standard includes do not define it.]);;
41 esac
42])# _AC_TYPE_INT
43
44# _AC_TYPE_UNSIGNED_INT(NBITS)
45# ----------------------------
46AC_DEFUN([_AC_TYPE_UNSIGNED_INT],
47[
48 AC_CACHE_CHECK([for uint$1_t], [ac_cv_c_uint$1_t],
49 [ac_cv_c_uint$1_t=no
50 for ac_type in 'uint$1_t' 'unsigned int' 'unsigned long int' \
51 'unsigned long long int' 'unsigned short int' 'unsigned char'; do
52 AC_COMPILE_IFELSE(
53 [AC_LANG_BOOL_COMPILE_TRY(
54 [AC_INCLUDES_DEFAULT],
55 [[($ac_type) -1 >> ($1 - 1) == 1]])],
56 [AS_CASE([$ac_type], [uint$1_t],
57 [ac_cv_c_uint$1_t=yes],
58 [ac_cv_c_uint$1_t=$ac_type])])
59 test "$ac_cv_c_uint$1_t" != no && break
60 done])
61 case $ac_cv_c_uint$1_t in #(
62 no|yes) ;; #(
63 *)
64 m4_bmatch([$1], [^\(8\|32\|64\)$],
65 [AC_DEFINE([_UINT$1_T], 1,
66 [Define for Solaris 2.5.1 so the uint$1_t typedef from
67 <sys/synch.h>, <pthread.h>, or <semaphore.h> is not used.
68 If the typedef was allowed, the #define below would cause a
69 syntax error.])])
70 AC_DEFINE_UNQUOTED([uint$1_t], [$ac_cv_c_uint$1_t],
71 [Define to the type of an unsigned integer type of width exactly $1 bits
72 if such a type exists and the standard includes do not define it.]);;
73 esac
74])# _AC_TYPE_UNSIGNED_INT
75
76# AS_CASE(WORD, [PATTERN1], [IF-MATCHED1]...[DEFAULT])
77# ----------------------------------------------------
78# Expand into
79# | case WORD in
80# | PATTERN1) IF-MATCHED1 ;;
81# | ...
82# | *) DEFAULT ;;
83# | esac
84m4_define([_AS_CASE],
85[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
86 [$#], 1, [ *) $1 ;;],
87 [$#], 2, [ $1) m4_default([$2], [:]) ;;],
88 [ $1) m4_default([$2], [:]) ;;
89$0(m4_shiftn(2, $@))])dnl
90])
91m4_defun([AS_CASE],
92[m4_ifval([$2$3],
93[case $1 in
94_AS_CASE(m4_shift($@))
95esac
96])dnl
97])# AS_CASE
3e4d503e
WM
98
99# _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
100# ----------------------------------------------------------------
101# If the C compiler is not in ISO C99 mode by default, try to add an
102# option to output variable CC to make it so. This macro tries
103# various options that select ISO C99 on some system or another. It
104# considers the compiler to be in ISO C99 mode if it handles _Bool,
105# // comments, flexible array members, inline, long long int, mixed
106# code and declarations, named initialization of structs, restrict,
107# va_copy, varargs macros, variable declarations in for loops and
108# variable length arrays.
109AC_DEFUN([_AC_PROG_CC_C99],
110[_AC_C_STD_TRY([c99],
111[[#include <stdarg.h>
112#include <stdbool.h>
113#include <stdlib.h>
114#include <wchar.h>
115#include <stdio.h>
116
117// Check varargs macros. These examples are taken from C99 6.10.3.5.
118#define debug(...) fprintf (stderr, __VA_ARGS__)
119#define showlist(...) puts (#__VA_ARGS__)
120#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
121static void
122test_varargs_macros (void)
123{
124 int x = 1234;
125 int y = 5678;
126 debug ("Flag");
127 debug ("X = %d\n", x);
128 showlist (The first, second, and third items.);
129 report (x>y, "x is %d but y is %d", x, y);
130}
131
132// Check long long types.
133#define BIG64 18446744073709551615ull
134#define BIG32 4294967295ul
135#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
136#if !BIG_OK
137 your preprocessor is broken;
138#endif
139#if BIG_OK
140#else
141 your preprocessor is broken;
142#endif
143static long long int bignum = -9223372036854775807LL;
144static unsigned long long int ubignum = BIG64;
145
146struct incomplete_array
147{
148 int datasize;
149 double data[];
150};
151
152struct named_init {
153 int number;
154 const wchar_t *name;
155 double average;
156};
157
158typedef const char *ccp;
159
160static inline int
161test_restrict (ccp restrict text)
162{
163 // See if C++-style comments work.
164 // Iterate through items via the restricted pointer.
165 // Also check for declarations in for loops.
166 for (unsigned int i = 0; *(text+i) != '\0'; ++i)
167 continue;
168 return 0;
169}
170
171// Check varargs and va_copy.
172static void
173test_varargs (const char *format, ...)
174{
175 va_list args;
176 va_start (args, format);
177 va_list args_copy;
178 va_copy (args_copy, args);
179
180 const char *str;
181 int number;
182 float fnumber;
183
184 while (*format)
185 {
186 switch (*format++)
187 {
188 case 's': // string
189 str = va_arg (args_copy, const char *);
190 break;
191 case 'd': // int
192 number = va_arg (args_copy, int);
193 break;
194 case 'f': // float
195 fnumber = va_arg (args_copy, double);
196 break;
197 default:
198 break;
199 }
200 }
201 va_end (args_copy);
202 va_end (args);
203}
204]],
205[[
206 // Check bool.
207 _Bool success = false;
208
209 // Check restrict.
210 if (test_restrict ("String literal") == 0)
211 success = true;
212 char *restrict newvar = "Another string";
213
214 // Check varargs.
215 test_varargs ("s, d' f .", "string", 65, 34.234);
216 test_varargs_macros ();
217
218 // Check flexible array members.
219 struct incomplete_array *ia =
220 malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
221 ia->datasize = 10;
222 for (int i = 0; i < ia->datasize; ++i)
223 ia->data[i] = i * 1.234;
224
225 // Check named initializers.
226 struct named_init ni = {
227 .number = 34,
228 .name = L"Test wide string",
229 .average = 543.34343,
230 };
231
232 ni.number = 58;
233
234 int dynamic_array[ni.number];
235 dynamic_array[ni.number - 1] = 543;
236
237 // work around unused variable warnings
238 return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
239 || dynamic_array[ni.number - 1] != 543);
240]],
241dnl Try
242dnl GCC -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
243dnl AIX -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
244dnl HP cc -AC99
245dnl Intel ICC -std=c99, -c99 (deprecated)
246dnl IRIX -c99
247dnl Solaris -xc99=all (Forte Developer 7 C mishandles -xc99 on Solaris 9,
248dnl as it incorrectly assumes C99 semantics for library functions)
249dnl Tru64 -c99
250dnl with extended modes being tried first.
251[[-std=gnu99 -std=c99 -c99 -AC99 -xc99=all -qlanglvl=extc99]], [$1], [$2])[]dnl
252])# _AC_PROG_CC_C99
253
254
255# AC_PROG_CC_C89
256# --------------
257AC_DEFUN([AC_PROG_CC_C89],
258[ AC_REQUIRE([AC_PROG_CC])dnl
259 _AC_PROG_CC_C89
260])
261
262# AC_PROG_CC_C99
263# --------------
264AC_DEFUN([AC_PROG_CC_C99],
265[ AC_REQUIRE([AC_PROG_CC])dnl
266 _AC_PROG_CC_C99
267])
268
269
270# AC_PROG_CC_STDC
271# ---------------
272AC_DEFUN([AC_PROG_CC_STDC],
273[ AC_REQUIRE([AC_PROG_CC])dnl
274 AS_CASE([$ac_cv_prog_cc_stdc],
275 [no], [ac_cv_prog_cc_c99=no; ac_cv_prog_cc_c89=no],
276 [_AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
277 [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
278 [ac_cv_prog_cc_stdc=no])])])dnl
279 AC_MSG_CHECKING([for $CC option to accept ISO Standard C])
280 AC_CACHE_VAL([ac_cv_prog_cc_stdc], [])
281 AS_CASE([$ac_cv_prog_cc_stdc],
282 [no], [AC_MSG_RESULT([unsupported])],
283 [''], [AC_MSG_RESULT([none needed])],
284 [AC_MSG_RESULT([$ac_cv_prog_cc_stdc])])
285])
286
287# _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
288# ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
289# --------------------------------------------------------------
290# Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
291# by trying to compile a program of TEST-PROLOGUE and TEST-BODY. If this fails,
292# try again with each compiler option in the space-separated OPTION-LIST; if one
293# helps, append it to CC. If eventually successful, run ACTION-IF-AVAILABLE,
294# else ACTION-IF-UNAVAILABLE.
295AC_DEFUN([_AC_C_STD_TRY],
296[AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
297AC_CACHE_VAL(ac_cv_prog_cc_$1,
298[ac_cv_prog_cc_$1=no
299ac_save_CC=$CC
300AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
301for ac_arg in '' $4
302do
303 CC="$ac_save_CC $ac_arg"
304 _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
305 test "x$ac_cv_prog_cc_$1" != "xno" && break
306done
307rm -f conftest.$ac_ext
308CC=$ac_save_CC
309])# AC_CACHE_VAL
310case "x$ac_cv_prog_cc_$1" in
311 x)
312 AC_MSG_RESULT([none needed]) ;;
313 xno)
314 AC_MSG_RESULT([unsupported]) ;;
315 *)
316 CC="$CC $ac_cv_prog_cc_$1"
317 AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
318esac
319AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
320])# _AC_C_STD_TRY
321
322