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