configure: add -lgdbm if needed for ndbm support
[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 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 $PSI_FN_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, [#define PSI_INCLUDES
183 #define _GNU_SOURCE 1
184 #define _POSIX_C_SOURCE 200809L
185 #define _XOPEN_SOURCE 700
186 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 #elif HAVE_GDBM_NDBM_H
214 # include <gdbm-ndbm.h>
215 #endif
216 #ifdef HAVE_NETDB_H
217 # include <netdb.h>
218 #endif
219 #ifdef HAVE_POLL_H
220 # include <poll.h>
221 #endif
222 #ifdef HAVE_RESOLV_H
223 # include <resolv.h>
224 #endif
225 #ifdef HAVE_SYS_SELECT_H
226 # include <sys/select.h>
227 #endif
228 #ifdef HAVE_SYS_SOCKET_H
229 # include <sys/socket.h>
230 #endif
231 #ifdef HAVE_SYS_TIME_H
232 # include <sys/time.h>
233 #endif
234 #ifdef HAVE_SYS_TIMES_H
235 # include <sys/times.h>
236 #endif
237 #ifdef HAVE_SYS_UIO_H
238 # include <sys/uio.h>
239 #endif
240 #ifdef HAVE_SYS_UTSNAME_H
241 # include <sys/utsname.h>
242 #endif
243 #ifdef HAVE_TIME_H
244 # include <time.h>
245 #endif
246 #ifdef HAVE_SIGNAL_H
247 # include <signal.h>
248 #endif
249 #ifdef HAVE_SYSLOG_H
250 # include <syslog.h>
251 #endif
252 #ifdef HAVE_WCHAR_H
253 # include <wchar.h>
254 #endif
255 #ifdef HAVE_WCTYPE_H
256 # include <wctype.h>
257 #endif
258 ])
259
260 dnl PSI_LEMON()
261 dnl Declare $LEMON precious, and check for a `lemon` in $PATH.
262 AC_DEFUN(PSI_LEMON, [
263 AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
264 AC_PATH_PROG(LEMON, lemon, ./lemon)
265 PHP_SUBST(LEMON)
266 ])
267
268 dnl PSI_PKG_CONFIG()
269 dnl Check for `pkg-config` and add possible libjit and libffi directories to
270 dnl $PKG_CONFIG_PATH, because those libs often ship with headers etc. in
271 dnl arch-dependent locations.
272 AC_DEFUN([PSI_PKG_CONFIG], [
273 if test -z "$PKG_CONFIG"
274 then
275 AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
276 fi
277 export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
278 ])
279
280 dnl PSI_SH_SIZEOF(type)
281 dnl expand to shell variable $ac_cv_sizeof_<TYPE>
282 AC_DEFUN([PSI_SH_SIZEOF], [$AS_TR_SH([ac_cv_sizeof_]$1)])
283
284 dnl PSI_SH_OFFSETOF(type)
285 dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
286 AC_DEFUN([PSI_SH_OFFSETOF], [$AS_TR_SH([ac_cv_offsetof_]$1)])
287
288 dnl PSI_SH_ALIGNOF(type)
289 dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
290 AC_DEFUN([PSI_SH_ALIGNOF], [$AS_TR_SH([ac_cv_alignof_]$1)])
291
292 dnl PSI_SH_TEST_SIZEOF(type)
293 dnl `if` condition to test if $ac_cv_sizeof_$1 is greater than 0.
294 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])
295
296 dnl PSI_SH_TEST_ALIGNOF(type)
297 dnl `if` condition to test if $ac_cv_alignof_$1 is greater than 0.
298 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])
299
300 dnl PSI_CHECK_SIZEOF(type, special-includes)
301 dnl AC_CHECK_SIZEOF wrapper with PSI_INCLUDES
302 dnl Defines psi\\SIZEOF_<TYPE> pre-defined constant in $PSI_CONSTS.
303 AC_DEFUN(PSI_CHECK_SIZEOF, [
304 AC_CHECK_SIZEOF($1, [], PSI_INCLUDES
305 $2)
306 if PSI_SH_TEST_SIZEOF($1); then
307 psi_add_int_const "AS_TR_CPP([SIZEOF_]$1)" "$AS_TR_SH([ac_cv_sizeof_]$1)"
308 fi
309 ])
310
311 dnl PSI_CHECK_ALIGNOF(type, special-includes)
312 dnl AC_CHECK_ALIGNOF wrapper with PSI_INCLUDES
313 dnl Defines psi\\ALIGNOF_<TYPE> pre-defined constant in $PSI_CONSTS.
314 AC_DEFUN(PSI_CHECK_ALIGNOF, [
315 AC_CHECK_ALIGNOF($1, PSI_INCLUDES
316 $2)
317 if PSI_SH_TEST_ALIGNOF($1); then
318 psi_add_int_const "AS_TR_CPP([ALIGNOF_]$1)" "$AS_TR_SH([ac_cv_alignof_]$1)"
319 fi
320 ])
321
322 dnl PSI_CHECK_OFFSETOF(struct, element)
323 dnl Check the offset of a struct element, implemented in the similar manner
324 dnl like AC_CHECK_SIZEOF.
325 dnl AC_DEFINEs OFFSETOF_<STRUCT>_<ELEMENT>.
326 AC_DEFUN(PSI_CHECK_OFFSETOF, [
327 _AC_CACHE_CHECK_INT(
328 [offset of $2 in $1],
329 [AS_TR_SH([ac_cv_offsetof_$1_$2])],
330 [(long int) (offsetof ($1, $2))],
331 [PSI_INCLUDES],
332 [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
333 )
334 AC_DEFINE_UNQUOTED(
335 AS_TR_CPP(offsetof_$1_$2),
336 $AS_TR_SH([ac_cv_offsetof_$1_$2]),
337 [The offset of `$2' in `$1', as computed by offsetof.]
338 )
339 ])
340
341
342 dnl PSI_COMPUTE_STR(variable, string or expression)
343 dnl Compute a string constant value in a similar manner like AC_COMPUTE_INT.
344 AC_DEFUN(PSI_COMPUTE_STR, [
345 AC_TRY_RUN(
346 PSI_INCLUDES
347 [int main() {
348 return EOF == fputs($2, fopen("conftest.out", "w"));
349 }
350 ], [
351 eval $1=\\\"`cat conftest.out`\\\"
352 ])
353 ])
354
355 dnl PSI_CHECK_LIBJIT()
356 dnl Check for libjit in $PHP_PSI_LIBJIT or standard locations
357 dnl AC_DEFINEs HAVE_LIBJIT.
358 AC_DEFUN(PSI_CHECK_LIBJIT, [
359 AC_CACHE_CHECK(for libjit, psi_cv_libjit_dir, [
360 for psi_cv_libjit_dir in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
361 do
362 if test -e $psi_cv_libjit_dir/include/jit/jit.h
363 then
364 break
365 fi
366 psi_cv_libjit_dir=
367 done
368 ])
369 if test -n "$psi_cv_libjit_dir"
370 then
371 PHP_ADD_INCLUDE($psi_cv_libjit_dir/include)
372 PHP_ADD_LIBRARY_WITH_PATH(jit, $psi_cv_libjit_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
373 AC_DEFINE(HAVE_LIBJIT, 1, Have libjit)
374 else
375 AC_MSG_WARN([Could not find libjit, please provide the base install path])
376 fi
377 ])
378
379 dnl PSI_CHECK_LIBFFI()
380 dnl Check for libffi with `pkg-config`. If that fails, `configure` looks into
381 dnl $PHP_PSI_LIBFFI or standard locations to find libjit deps.
382 dnl Checks for availability of recent closure API:
383 dnl \ffi_closure_alloc and \ffi_prep_closure.
384 dnl Checks for availability of recent vararg API:
385 dnl \ffi_prep_cif_var.
386 dnl AC_DEFINEs HAVE_LIBFFI, PSI_HAVE_FFI_CLOSURE_ALLOC,
387 dnl PSI_HAVE_FFI_PREP_CLOSURE and PSI_HAVE_FFO_PREP_VIF_VAR.
388 AC_DEFUN(PSI_CHECK_LIBFFI, [
389 AC_REQUIRE([PSI_PKG_CONFIG])dnl
390
391 AC_CACHE_CHECK(for libffi through pkg-config, psi_cv_libffi, [
392 if $PKG_CONFIG --exists libffi
393 then
394 psi_cv_libffi=true
395 else
396 psi_cv_libffi=false
397 fi])
398
399 if $psi_cv_libffi
400 then
401 AC_MSG_CHECKING(for libffi)
402 psi_cv_libffi_dir=`$PKG_CONFIG --variable=prefix libffi`
403 AC_MSG_RESULT($psi_cv_libffi_dir)
404 PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
405 PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
406 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
407 else
408 AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
409 for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
410 do
411 if test -e $psi_cv_libffi_dir/include/ffi/ffi.h
412 then
413 break
414 fi
415 psi_cv_libffi_dir=
416 done])
417 if test -n "$psi_cv_libffi_dir"
418 then
419 PHP_ADD_INCLUDE($psi_cv_libffi_dir/include/ffi)
420 PHP_ADD_LIBRARY_WITH_PATH(ffi, $psi_cv_libffi_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
421 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
422 else
423 AC_MSG_WARN([Could not find libffi, please provide the base install path])
424 fi
425 fi
426 PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
427 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
428 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
429 ], [], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
430 AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
431 ], [
432 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
433 AC_CHECK_HEADERS(sys/mman.h)
434 PHP_CHECK_FUNC(mmap)
435 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
436 ], [
437 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
438 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
439 PHP_CHECK_LIBRARY(ffi, ffi_prep_cif_var, [
440 AC_DEFINE(PSI_HAVE_FFI_PREP_CIF_VAR, 1, [ ])
441 ], [
442 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
443 ])