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