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