41acc565fbdaf7ac31b22eb86ecc851efe96b53e
[m6w6/ext-psi] / m4 / psi.m4
1 dnl Generated headers with pre-defined types, structs, consts and decls.
2 PSI_STDINC=$PHP_PSI_SRCDIR/php_psi_stdinc.h
3 PSI_STDTYPES=$PHP_PSI_SRCDIR/php_psi_stdtypes.h
4 PSI_TYPES=$PHP_PSI_SRCDIR/php_psi_types.h
5 PSI_STRUCTS=$PHP_PSI_SRCDIR/php_psi_structs.h
6 PSI_UNIONS=$PHP_PSI_SRCDIR/php_psi_unions.h
7 PSI_CONSTS=$PHP_PSI_SRCDIR/php_psi_consts.h
8 PSI_REDIRS=$PHP_PSI_SRCDIR/php_psi_redirs.h
9 PSI_MACROS=$PHP_PSI_SRCDIR/php_psi_macros.h
10 PSI_DECLS=$PHP_PSI_SRCDIR/php_psi_decls.h
11 PSI_VA_DECLS=$PHP_PSI_SRCDIR/php_psi_va_decls.h
12
13 dnl PSI_CONFIG_INIT()
14 dnl Creates stubs of the headers with pre-defined types etc.
15 dnl These headers are included by src/context.c.
16 dnl This macro must be called prior any checks for a type, struct, decl etc.
17 AC_DEFUN(PSI_CONFIG_INIT, [
18 for i in $PSI_STDTYPES $PSI_TYPES $PSI_STRUCTS $PSI_UNIONS $PSI_CONSTS $PSI_REDIRS $PSI_MACROS $PSI_DECLS $PSI_VA_DECLS; do
19 cat >$i <<EOF
20 /* generated by configure */
21 #include "php_psi_stdinc.h"
22 EOF
23 done
24 cat >>$PSI_STDTYPES <<EOF
25 static struct psi_std_type {
26 token_t type_tag;
27 const char *type_name;
28 const char *alias;
29 } psi_std_types@<:@@:>@ = {
30 {PSI_T_INT8, "int8_t", NULL},
31 {PSI_T_INT16, "int16_t", NULL},
32 {PSI_T_INT32, "int32_t", NULL},
33 {PSI_T_INT64, "int64_t", NULL},
34 {PSI_T_UINT8, "uint8_t", NULL},
35 {PSI_T_UINT16, "uint16_t", NULL},
36 {PSI_T_UINT32, "uint32_t", NULL},
37 {PSI_T_UINT64, "uint64_t", NULL},
38 EOF
39 cat >>$PSI_TYPES <<EOF
40 static struct psi_predef_type {
41 token_t type_tag;
42 const char *type_name;
43 const char *alias;
44 } psi_predef_types@<:@@:>@ = {
45 EOF
46 cat >>$PSI_STRUCTS <<EOF
47 static struct psi_predef_struct {
48 token_t type_tag;
49 const char *type_name;
50 const char *var_name;
51 size_t offset;
52 size_t size;
53 size_t pointer_level;
54 size_t array_size;
55 } psi_predef_structs@<:@@:>@ = {
56 EOF
57 cat >>$PSI_UNIONS <<EOF
58 static struct psi_predef_union {
59 token_t type_tag;
60 const char *type_name;
61 const char *var_name;
62 size_t offset;
63 size_t size;
64 size_t pointer_level;
65 size_t array_size;
66 } psi_predef_unions@<:@@:>@ = {
67 EOF
68 cat >>$PSI_CONSTS <<EOF
69 static struct psi_predef_const {
70 token_t type_tag;
71 const char *type_name;
72 const char *var_name;
73 const char *val_text;
74 token_t val_type_tag;
75 } psi_predef_consts@<:@@:>@ = {
76 EOF
77 cat >>$PSI_REDIRS <<EOF
78 typedef void (*psi_func_ptr)();
79 static struct psi_func_redir {
80 const char *name;
81 psi_func_ptr func;
82 } psi_func_redirs@<:@@:>@ = {
83 EOF
84 cat >>$PSI_MACROS <<EOF
85 EOF
86 cat >>$PSI_DECLS <<EOF
87 static struct psi_predef_decl {
88 token_t type_tag;
89 const char *type_name;
90 const char *var_name;
91 size_t pointer_level;
92 size_t array_size;
93 } psi_predef_decls@<:@@:>@ = {
94 EOF
95 cat >>$PSI_VA_DECLS <<EOF
96 static struct psi_predef_decl psi_predef_vararg_decls@<:@@:>@ = {
97 EOF
98 ])
99
100 dnl PSI_CONFIG_DONE()
101 dnl Finish the headers with the pre-defined types etc.
102 AC_DEFUN(PSI_CONFIG_DONE, [
103 cat >$PSI_STDINC <<EOF
104 /* generated by configure */
105 #ifndef _PSI_STDINC
106 #define _PSI_STDINC
107 #ifndef _GNU_SOURCE
108 #define _GNU_SOURCE
109 #endif
110 #ifndef _XOPEN_SOURCE
111 #define _XOPEN_SOURCE
112 #endif
113 PSI_INCLUDES
114 #endif
115 EOF
116 for i in $PSI_STDTYPES $PSI_TYPES $PSI_STRUCTS $PSI_UNIONS $PSI_CONSTS $PSI_REDIRS $PSI_DECLS $PSI_VA_DECLS; do
117 cat >>$i <<EOF
118 {0}
119 };
120 EOF
121 done
122 ])
123
124 dnl PSI_SH_CONFIG_POSIX_ENABLED(section)
125 dnl Expand to $psi_config_posix_<section>
126 AC_DEFUN(PSI_SH_CONFIG_POSIX_ENABLED, [$AS_TR_SH([psi_config_posix_]$1)])
127
128 dnl PSI_CONFIG_POSIX_ENABLED(section, action-if-yes, action-if-not)
129 dnl Internal. Used to check if --enable-psi-posix=section was given.
130 AC_DEFUN(PSI_CONFIG_POSIX_ENABLED, [
131 AS_TR_SH([psi_config_posix_]$1)=false
132 case "$PHP_PSI_POSIX" in
133 yes|all)
134 AS_TR_SH([psi_config_posix_]$1)=true
135 ;;
136 *)
137 if expr "$PHP_PSI_POSIX" : '\b$1\b' >/dev/null; then
138 AS_TR_SH([psi_config_posix_]$1)=true
139 fi
140 ;;
141 esac
142 if $AS_TR_SH([psi_config_posix_]$1); then
143 ifelse([$2],,:,[$2])
144 else
145 ifelse([$3],,:,[$3])
146 fi
147 ])
148
149 dnl PSI_TEST_POSIX_ENABLED(section, action-if-yes, action-if-not)
150 dnl Shell-if test if PSI POSIX section was configured.
151 AC_DEFUN(PSI_SH_TEST_POSIX_ENABLED, [
152 if test "PSI_SH_CONFIG_POSIX_ENABLED([$1])" && $PSI_SH_CONFIG_POSIX_ENABLED([$1]); then
153 ifelse([$2],,:,[$2])
154 else
155 ifelse([$3],,:,[$3])
156 fi
157 ])
158
159 dnl PSI_CONFIG_POSIX(section, headers)
160 AC_DEFUN(PSI_CONFIG_POSIX, [
161 PSI_CONFIG_POSIX_ENABLED($1, [
162 PHP_CONFIGURE_PART(Configuring PSI POSIX: $1)
163 ifelse([$2],,:,[AC_CHECK_HEADERS($2)])
164 ], [
165 return 0
166 ])
167 ])
168
169 AC_DEFUN(PSI_PTHREAD_ONCE, [
170 AX_PTHREAD([
171 LIBS="$PTHREAD_LIBS $LIBS"
172 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
173 ])
174 ])
175 AC_DEFUN(PSI_PTHREAD, [
176 AC_REQUIRE([PSI_PTHREAD_ONCE])
177 ])
178
179 dnl PSI_INCLUDES()
180 dnl Expands to a complete list of include statements including
181 dnl AC_INCLUDES_DEFAULT().
182 AC_DEFUN(PSI_INCLUDES, [AC_INCLUDES_DEFAULT()
183 #ifdef HAVE_ERRNO_H
184 # include <errno.h>
185 #endif
186 #ifdef HAVE_GLOB_H
187 # include <glob.h>
188 #endif
189 #ifdef HAVE_LOCALE_H
190 # include <locale.h>
191 #endif
192 #ifdef HAVE_XLOCALE_H
193 # include <xlocale.h>
194 #endif
195 #ifdef HAVE_NETINET_IN_H
196 # include <netinet/in.h>
197 #endif
198 #ifdef HAVE_NETINET_TCP_H
199 # include <netinet/tcp.h>
200 #endif
201 #ifdef HAVE_ARPA_NAMESER_H
202 # include <arpa/nameser.h>
203 #endif
204 #ifdef HAVE_FCNTL_H
205 # include <fcntl.h>
206 #endif
207 #ifdef HAVE_NDBM_H
208 # include <ndbm.h>
209 #endif
210 #ifdef HAVE_NETDB_H
211 # include <netdb.h>
212 #endif
213 #ifdef HAVE_POLL_H
214 # include <poll.h>
215 #endif
216 #ifdef HAVE_RESOLV_H
217 # include <resolv.h>
218 #endif
219 #ifdef HAVE_SYS_SELECT_H
220 # include <sys/select.h>
221 #endif
222 #ifdef HAVE_SYS_SOCKET_H
223 # include <sys/socket.h>
224 #endif
225 #ifdef HAVE_SYS_TIME_H
226 # include <sys/time.h>
227 #endif
228 #ifdef HAVE_SYS_TIMES_H
229 # include <sys/times.h>
230 #endif
231 #ifdef HAVE_SYS_UIO_H
232 # include <sys/uio.h>
233 #endif
234 #ifdef HAVE_SYS_UTSNAME_H
235 # include <sys/utsname.h>
236 #endif
237 #ifdef HAVE_TIME_H
238 # include <time.h>
239 #endif
240 #ifdef HAVE_SIGNAL_H
241 # include <signal.h>
242 #endif
243 #ifdef HAVE_SYSLOG_H
244 # include <syslog.h>
245 #endif
246 #ifdef HAVE_WCHAR_H
247 # include <wchar.h>
248 #endif
249 #ifdef HAVE_WCTYPE_H
250 # include <wctype.h>
251 #endif
252 ])
253
254 dnl PSI_LEMON()
255 dnl Declare $LEMON precious, and check for a `lemon` in $PATH.
256 AC_DEFUN(PSI_LEMON, [
257 AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
258 AC_PATH_PROG(LEMON, lemon, ./lemon)
259 PHP_SUBST(LEMON)
260 ])
261
262 dnl PSI_PKG_CONFIG()
263 dnl Check for `pkg-config` and add possible libjit and libffi directories to
264 dnl $PKG_CONFIG_PATH, because those libs often ship with headers etc. in
265 dnl arch-dependent locations.
266 AC_DEFUN([PSI_PKG_CONFIG], [
267 if test -z "$PKG_CONFIG"
268 then
269 AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
270 fi
271 export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
272 ])
273
274 dnl PSI_SH_SIZEOF(type)
275 dnl expand to shell variable $ac_cv_sizeof_<TYPE>
276 AC_DEFUN([PSI_SH_SIZEOF], [$AS_TR_SH([ac_cv_sizeof_]$1)])
277
278 dnl PSI_SH_OFFSETOF(type)
279 dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
280 AC_DEFUN([PSI_SH_OFFSETOF], [$AS_TR_SH([ac_cv_offsetof_]$1)])
281
282 dnl PSI_SH_ALIGNOF(type)
283 dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
284 AC_DEFUN([PSI_SH_ALIGNOF], [$AS_TR_SH([ac_cv_alignof_]$1)])
285
286 dnl PSI_SH_TEST_SIZEOF(type)
287 dnl `if` condition to test if $ac_cv_sizeof_$1 is greater than 0.
288 AC_DEFUN([PSI_SH_TEST_SIZEOF], [test -n "$AS_TR_SH([ac_cv_sizeof_]$1)" && test "$AS_TR_SH([ac_cv_sizeof_]$1)" -gt 0])
289
290 dnl PSI_SH_TEST_ALIGNOF(type)
291 dnl `if` condition to test if $ac_cv_alignof_$1 is greater than 0.
292 AC_DEFUN([PSI_SH_TEST_ALIGNOF], [test -n "$AS_TR_SH([ac_cv_alignof_]$1)" && test "$AS_TR_SH([ac_cv_alignof_]$1)" -gt 0])
293
294 dnl PSI_CHECK_SIZEOF(type, special-includes)
295 dnl AC_CHECK_SIZEOF wrapper with PSI_INCLUDES
296 dnl Defines psi\\SIZEOF_<TYPE> pre-defined constant in $PSI_CONSTS.
297 AC_DEFUN(PSI_CHECK_SIZEOF, [
298 AC_CHECK_SIZEOF($1, [], PSI_INCLUDES
299 $2)
300 if PSI_SH_TEST_SIZEOF($1); then
301 psi_add_int_const "AS_TR_CPP([SIZEOF_]$1)" "$AS_TR_SH([ac_cv_sizeof_]$1)"
302 fi
303 ])
304
305 dnl PSI_CHECK_ALIGNOF(type, special-includes)
306 dnl AC_CHECK_ALIGNOF wrapper with PSI_INCLUDES
307 dnl Defines psi\\ALIGNOF_<TYPE> pre-defined constant in $PSI_CONSTS.
308 AC_DEFUN(PSI_CHECK_ALIGNOF, [
309 AC_CHECK_ALIGNOF($1, PSI_INCLUDES
310 $2)
311 if PSI_SH_TEST_ALIGNOF($1); then
312 psi_add_int_const "AS_TR_CPP([ALIGNOF_]$1)" "$AS_TR_SH([ac_cv_alignof_]$1)"
313 fi
314 ])
315
316 dnl PSI_CHECK_OFFSETOF(struct, element)
317 dnl Check the offset of a struct element, implemented in the similar manner
318 dnl like AC_CHECK_SIZEOF.
319 dnl AC_DEFINEs OFFSETOF_<STRUCT>_<ELEMENT>.
320 AC_DEFUN(PSI_CHECK_OFFSETOF, [
321 _AC_CACHE_CHECK_INT(
322 [offset of $2 in $1],
323 [AS_TR_SH([ac_cv_offsetof_$1_$2])],
324 [(long int) (offsetof ($1, $2))],
325 [PSI_INCLUDES],
326 [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
327 )
328 AC_DEFINE_UNQUOTED(
329 AS_TR_CPP(offsetof_$1_$2),
330 $AS_TR_SH([ac_cv_offsetof_$1_$2]),
331 [The offset of `$2' in `$1', as computed by offsetof.]
332 )
333 ])
334
335
336 dnl PSI_COMPUTE_STR(variable, string or expression)
337 dnl Compute a string constant value in a similar manner like AC_COMPUTE_INT.
338 AC_DEFUN(PSI_COMPUTE_STR, [
339 AC_TRY_RUN(
340 PSI_INCLUDES
341 [int main() {
342 return EOF == fputs($2, fopen("conftest.out", "w"));
343 }
344 ], [
345 eval $1=\\\"`cat conftest.out`\\\"
346 ])
347 ])
348
349 dnl PSI_CHECK_LIBJIT()
350 dnl Check for libjit in $PHP_PSI_LIBJIT or standard locations
351 dnl AC_DEFINEs HAVE_LIBJIT.
352 AC_DEFUN(PSI_CHECK_LIBJIT, [
353 AC_CACHE_CHECK(for libjit, psi_cv_libjit_dir, [
354 for psi_cv_libjit_dir in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
355 do
356 if test -e $psi_cv_libjit_dir/include/jit/jit.h
357 then
358 break
359 fi
360 psi_cv_libjit_dir=
361 done
362 ])
363 if test -n "$psi_cv_libjit_dir"
364 then
365 PHP_ADD_INCLUDE($psi_cv_libjit_dir/include)
366 PHP_ADD_LIBRARY_WITH_PATH(jit, $psi_cv_libjit_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
367 AC_DEFINE(HAVE_LIBJIT, 1, Have libjit)
368 else
369 AC_MSG_WARN([Could not find libjit, please provide the base install path])
370 fi
371 ])
372
373 dnl PSI_CHECK_LIBFFI()
374 dnl Check for libffi with `pkg-config`. If that fails, `configure` looks into
375 dnl $PHP_PSI_LIBFFI or standard locations to find libjit deps.
376 dnl Checks for availability of recent closure API:
377 dnl \ffi_closure_alloc and \ffi_prep_closure.
378 dnl Checks for availability of recent vararg API:
379 dnl \ffi_prep_cif_var.
380 dnl AC_DEFINEs HAVE_LIBFFI, PSI_HAVE_FFI_CLOSURE_ALLOC,
381 dnl PSI_HAVE_FFI_PREP_CLOSURE and PSI_HAVE_FFO_PREP_VIF_VAR.
382 AC_DEFUN(PSI_CHECK_LIBFFI, [
383 AC_REQUIRE([PSI_PKG_CONFIG])dnl
384
385 AC_CACHE_CHECK(for libffi through pkg-config, psi_cv_libffi, [
386 if $PKG_CONFIG --exists libffi
387 then
388 psi_cv_libffi=true
389 else
390 psi_cv_libffi=false
391 fi])
392
393 if $psi_cv_libffi
394 then
395 AC_MSG_CHECKING(for libffi)
396 psi_cv_libffi_dir=`$PKG_CONFIG --variable=prefix libffi`
397 AC_MSG_RESULT($psi_cv_libffi_dir)
398 PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
399 PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
400 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
401 else
402 AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
403 for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
404 do
405 if test -e $psi_cv_libffi_dir/include/ffi/ffi.h
406 then
407 break
408 fi
409 psi_cv_libffi_dir=
410 done])
411 if test -n "$psi_cv_libffi_dir"
412 then
413 PHP_ADD_INCLUDE($psi_cv_libffi_dir/include/ffi)
414 PHP_ADD_LIBRARY_WITH_PATH(ffi, $psi_cv_libffi_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
415 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
416 else
417 AC_MSG_WARN([Could not find libffi, please provide the base install path])
418 fi
419 fi
420 PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
421 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
422 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
423 ], [], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
424 AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
425 ], [
426 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
427 AC_CHECK_HEADERS(sys/mman.h)
428 PHP_CHECK_FUNC(mmap)
429 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
430 ], [
431 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
432 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
433 PHP_CHECK_LIBRARY(ffi, ffi_prep_cif_var, [
434 AC_DEFINE(PSI_HAVE_FFI_PREP_CIF_VAR, 1, [ ])
435 ], [
436 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
437 ])