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