build: PHP<7.2 compatibility
[m6w6/ext-psi] / m4 / psi / psi.m4
1
2 dnl PSI_CONFIG_INIT()
3 dnl Creates stubs of the headers with pre-defined types etc.
4 dnl These headers are included by src/context.c.
5 dnl This macro must be called prior any checks for a type, struct, decl etc.
6 AC_DEFUN(PSI_CONFIG_INIT, [
7 psi_save_LIBS=$LIBS
8 LIBS=
9
10 AC_PROG_AWK
11 AC_PATH_PROG(NM, nm)
12 AC_CACHE_CHECK(for libc start main symbol, psi_cv_libc_main, [
13 psi_libc_main=
14 AC_TRY_LINK(PSI_INCLUDES, [(void)0;], [
15 psi_libc_main=`nm -g conftest$ac_exeext | $AWK -F ' *|@' '/^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
16 ])
17 psi_cv_libc_main=$psi_libc_main
18 ])
19
20 if test "$PHP_PSI_MAINTAINER_MODE" = "yes"; then
21 PSI_FAST_CONFIG=true
22 PSI_DEPS=true
23 PSI_EXTRA_REDIRS=true
24
25 PHP_SUBST(PSI_DEPS)
26
27 PSI_CONFIG_TMP=$(mktemp -d)
28 else
29 PSI_FAST_CONFIG=false
30 PSI_DEPS=false
31 if test "$PHP_DEBUG" = "1"; then
32 PSI_EXTRA_REDIRS=true
33 else
34 PSI_EXTRA_REDIRS=false
35 fi
36 fi
37
38 PSI_STDTYPES=
39 PSI_TYPES=
40 PSI_COMPOSITES=
41 PSI_CONSTS=
42 PSI_REDIRS=
43 PSI_MACROS=
44 PSI_DECLS=
45
46 AC_CONFIG_FILES(
47 [$PHP_PSI_BUILDDIR/php_psi_stdinc.h:$PHP_PSI_SRCDIR/php_psi_stdinc.h.in]
48 [$PHP_PSI_BUILDDIR/php_psi_posix.h:$PHP_PSI_SRCDIR/php_psi_posix.h.in]
49 )
50
51 ])
52
53 dnl PSI_CONFIG_WAIT()
54 dnl Internal: waits for sub configures in maintainer mode
55 AC_DEFUN(PSI_CONFIG_WAIT, [
56 wait
57 if test $? -gt 0; then
58 cat $PSI_CONFIG_TMP/*/stderr.log >&2
59 exit 1
60 fi
61 ])
62
63 dnl PSI_CONFIG_DONE()
64 dnl Finish the headers with the pre-defined types etc.
65 AC_DEFUN(PSI_CONFIG_DONE, [
66 PSI_CONFIG_WAIT
67
68 if $PSI_FAST_CONFIG; then
69 for conf_env in $PSI_CONFIG_TMP/*/conf.env; do
70 source $conf_env
71 done
72 fi
73
74 psi_eval_LIBS=$LIBS
75 LIBS=$psi_save_LIBS
76 PHP_EVAL_LIBLINE($psi_eval_LIBS, PSI_SHARED_LIBADD)
77
78 [PSI_INCLUDES]="PSI_INCLUDES"
79 AC_SUBST([PSI_INCLUDES])
80 AC_SUBST([PSI_STDTYPES])
81 AC_SUBST([PSI_TYPES])
82 AC_SUBST([PSI_COMPOSITES])
83 AC_SUBST([PSI_CONSTS])
84 AC_SUBST([PSI_REDIRS])
85 AC_SUBST([PSI_MACROS])
86 AC_SUBST([PSI_DECLS])
87 ])
88
89 dnl PSI_SH_CONFIG_POSIX_ENABLED(section)
90 dnl Expand to $psi_config_posix_<section>
91 AC_DEFUN(PSI_SH_CONFIG_POSIX_ENABLED, [$AS_TR_SH([psi_config_posix_]$1)])
92
93 dnl PSI_CONFIG_POSIX_ENABLED(section, action-if-yes, action-if-not)
94 dnl Internal. Used to check if --enable-psi-posix=section was given.
95 AC_DEFUN(PSI_CONFIG_POSIX_ENABLED, [
96 AS_TR_SH([psi_config_posix_]$1)=false
97 case "$PHP_PSI_POSIX" in
98 yes|all)
99 AS_TR_SH([psi_config_posix_]$1)=true
100 ;;
101 *)
102 if expr "$PHP_PSI_POSIX" : '.*\b$1\b' >/dev/null; then
103 AS_TR_SH([psi_config_posix_]$1)=true
104 fi
105 ;;
106 esac
107 if $AS_TR_SH([psi_config_posix_]$1); then
108 ifelse([$2],,:,[$2])
109 else
110 ifelse([$3],,:,[$3])
111 fi
112 ])
113
114 dnl PSI_TEST_POSIX_ENABLED(section, action-if-yes, action-if-not)
115 dnl Shell-if test if PSI POSIX section was configured.
116 AC_DEFUN(PSI_SH_TEST_POSIX_ENABLED, [
117 if test "PSI_SH_CONFIG_POSIX_ENABLED([$1])" && $PSI_SH_CONFIG_POSIX_ENABLED([$1]); then
118 ifelse([$2],,:,[$2])
119 else
120 ifelse([$3],,:,[$3])
121 fi
122 ])
123
124 dnl PSI_CONFIG_POSIX(section, headers, dependents)
125 AC_DEFUN(PSI_CONFIG_POSIX, [
126 PSI_CONFIG_POSIX_ENABLED($1, [
127 if $PSI_FAST_CONFIG; then
128 PSI_CONFIG_POSIX_PARALLEL($1, $2, [$3])
129 else
130 ifelse([$2],,:,[AC_CHECK_HEADERS($2)])
131 AS_TR_CPP([PSI_CHECK_$1])
132 $3
133 fi
134 ])
135 ])
136
137 AC_DEFUN([PSI_CONFIG_POSIX_PARALLEL], [
138 (
139 dnl chaway
140 mkdir $PSI_CONFIG_TMP/AS_TR_SH([$1])
141 cd $PSI_CONFIG_TMP/AS_TR_SH([$1])
142
143 dnl AC_DEFINEs
144 ln -s $abs_builddir/confdefs.h confdefs.h
145
146 dnl STDOUT, STDERR
147 exec {PSI_MESSAGE_FD}>&AS_MESSAGE_FD {PSI_ERROR_FD}>&2
148 exec AS_MESSAGE_FD>stdout.log 2>stderr.log
149
150 dnl check for headers?
151 ifelse([$2],,:,[AC_CHECK_HEADERS($2)])
152
153 dnl run checks
154 PSI_TYPES=
155 PSI_CONSTS=
156 PSI_COMPOSITES=
157 PSI_REDIRS=
158 PSI_MACROS=
159 PSI_DECLS=
160 AS_TR_CPP([PSI_CHECK_$1])
161
162 dnl save env
163 cat >conf.env <<EOF
164 LIBS="$LIBS \$LIBS"
165 EOF
166 for env in TYPES CONSTS COMPOSITES MACROS REDIRS DECLS; do
167 eval var=\$PSI_$env
168 if test -n "$var"; then
169 cat >>conf.env <<EOF
170 PSI_$env='$var'"
171 \$PSI_$env"
172 EOF
173 fi
174 done
175
176 _AC_CACHE_DUMP >>conf.env
177 dnl restore STDOUT,STDERR
178 exec AS_MESSAGE_FD>&$PSI_MESSAGE_FD 2>&$PSI_ERROR_FD
179
180 dnl done
181 AS_ECHO_N(["$1 "])
182 cd - >/dev/null
183
184 dnl run dependents
185 $3
186
187 PSI_CONFIG_WAIT
188 ) &
189 ])
190
191 AC_DEFUN(PSI_PTHREAD_ONCE, [
192 AX_PTHREAD([
193 LIBS="$PTHREAD_LIBS $LIBS"
194 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
195 ])
196 ])
197 AC_DEFUN(PSI_PTHREAD, [
198 AC_REQUIRE([PSI_PTHREAD_ONCE])
199 ])
200
201 dnl PSI_INCLUDES()
202 dnl Expands to a complete list of include statements including
203 dnl AC_INCLUDES_DEFAULT().
204 AC_DEFUN(PSI_INCLUDES, [dnl
205 #define PSI_INCLUDES
206 #ifndef _GNU_SOURCE
207 # define _GNU_SOURCE
208 #endif
209 #ifndef _REENTRANT
210 # define _REENTRANT
211 #endif
212 AC_INCLUDES_DEFAULT()
213 #ifdef HAVE_STDBOOL_H
214 # include <stdbool.h>
215 #else
216 # ifndef HAVE__BOOL
217 # ifdef __cplusplus
218 typedef bool _Bool;
219 # else
220 # define _Bool signed char
221 # endif
222 # endif
223 # define bool _Bool
224 # define false 0
225 # define true 1
226 # define __bool_true_false_are_defined 1
227 #endif
228 #ifdef HAVE_ERRNO_H
229 # include <errno.h>
230 #endif
231 #ifdef HAVE_GLOB_H
232 # include <glob.h>
233 #endif
234 #ifdef HAVE_LOCALE_H
235 # include <locale.h>
236 #endif
237 #ifdef HAVE_XLOCALE_H
238 # include <xlocale.h>
239 #endif
240 #ifdef HAVE_NETINET_IN_H
241 # include <netinet/in.h>
242 #endif
243 #ifdef HAVE_NETINET_TCP_H
244 # include <netinet/tcp.h>
245 #endif
246 #ifdef HAVE_ARPA_NAMESER_H
247 # include <arpa/nameser.h>
248 #endif
249 #ifdef HAVE_ARPA_INET_H
250 # include <arpa/inet.h>
251 #endif
252 #ifdef HAVE_FCNTL_H
253 # include <fcntl.h>
254 #endif
255 #ifdef HAVE_RELIC_H
256 # include <relic.h>
257 #elif HAVE_NDBM_H
258 # include <ndbm.h>
259 #elif HAVE_GDBM_NDBM_H
260 # include <gdbm-ndbm.h>
261 #endif
262 #ifdef HAVE_NETDB_H
263 # include <netdb.h>
264 #endif
265 #ifdef HAVE_POLL_H
266 # include <poll.h>
267 #endif
268 #ifdef HAVE_RESOLV_H
269 # include <resolv.h>
270 #endif
271 #ifdef HAVE_SYS_SELECT_H
272 # include <sys/select.h>
273 #endif
274 #ifdef HAVE_SYS_SOCKET_H
275 # include <sys/socket.h>
276 #endif
277 #ifdef HAVE_SYS_TIME_H
278 # include <sys/time.h>
279 #endif
280 #ifdef HAVE_SYS_TIMES_H
281 # include <sys/times.h>
282 #endif
283 #ifdef HAVE_SYS_UIO_H
284 # include <sys/uio.h>
285 #endif
286 #ifdef HAVE_SYS_UTSNAME_H
287 # include <sys/utsname.h>
288 #endif
289 #ifdef HAVE_TIME_H
290 # include <time.h>
291 #endif
292 #ifdef HAVE_SIGNAL_H
293 # include <signal.h>
294 #endif
295 #ifdef HAVE_SYSLOG_H
296 # include <syslog.h>
297 #endif
298 #ifdef HAVE_WCHAR_H
299 # include <wchar.h>
300 #endif
301 #ifdef HAVE_WCTYPE_H
302 # include <wctype.h>
303 #endif
304 ])
305
306 dnl PSI_LEMON()
307 dnl Declare $LEMON precious, and check for a `lemon` in $PATH.
308 AC_DEFUN(PSI_LEMON, [
309 AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
310 if test -z "$LEMON"
311 then
312 AC_PATH_PROG(LEMON, lemon, $PHP_PSI_BUILDDIR/lemon)
313 if expr + "$LEMON" : "/" >/dev/null; then
314 LEMON_PATH=
315 else
316 LEMON_PATH=$abs_builddir/
317 fi
318 fi
319 PHP_SUBST(LEMON_PATH)
320 PHP_SUBST(LEMON)
321 ])
322
323 dnl PSI_PKG_CONFIG()
324 dnl Check for `pkg-config` and add possible libjit and libffi directories to
325 dnl $PKG_CONFIG_PATH, because those libs often ship with headers etc. in
326 dnl arch-dependent locations.
327 AC_DEFUN([PSI_PKG_CONFIG], [
328 if test -z "$PKG_CONFIG"
329 then
330 AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
331 fi
332 export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
333 ])
334
335 dnl PSI_SH_SIZEOF(type)
336 dnl expand to shell variable $ac_cv_sizeof_<TYPE>
337 AC_DEFUN([PSI_SH_SIZEOF], [$AS_TR_SH([ac_cv_sizeof_]$1)])
338
339 dnl PSI_SH_OFFSETOF(type)
340 dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
341 AC_DEFUN([PSI_SH_OFFSETOF], [$AS_TR_SH([ac_cv_offsetof_]$1)])
342
343 dnl PSI_SH_ALIGNOF(type)
344 dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
345 AC_DEFUN([PSI_SH_ALIGNOF], [$AS_TR_SH([ac_cv_alignof_]$1)])
346
347 dnl PSI_SH_TEST_SIZEOF(type)
348 dnl `if` condition to test if $ac_cv_sizeof_$1 is greater than 0.
349 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])
350
351 dnl PSI_SH_TEST_ALIGNOF(type)
352 dnl `if` condition to test if $ac_cv_alignof_$1 is greater than 0.
353 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])
354
355 dnl PSI_CHECK_SIZEOF(type, special-includes)
356 dnl AC_CHECK_SIZEOF wrapper with PSI_INCLUDES
357 dnl Defines psi\\SIZEOF_<TYPE> pre-defined constant in $PSI_CONSTS_H.
358 AC_DEFUN(PSI_CHECK_SIZEOF, [
359 AC_CHECK_SIZEOF($1, [], PSI_INCLUDES
360 $2)
361 if PSI_SH_TEST_SIZEOF($1); then
362 psi_add_int_const "AS_TR_CPP([SIZEOF_]$1)" "$AS_TR_SH([ac_cv_sizeof_]$1)"
363 fi
364 ])
365
366 dnl PSI_CHECK_ALIGNOF(type, special-includes)
367 dnl AC_CHECK_ALIGNOF wrapper with PSI_INCLUDES
368 dnl Defines psi\\ALIGNOF_<TYPE> pre-defined constant in $PSI_CONSTS_H.
369 AC_DEFUN(PSI_CHECK_ALIGNOF, [
370 AC_CHECK_ALIGNOF($1, PSI_INCLUDES
371 $2)
372 if PSI_SH_TEST_ALIGNOF($1); then
373 psi_add_int_const "AS_TR_CPP([ALIGNOF_]$1)" "$AS_TR_SH([ac_cv_alignof_]$1)"
374 fi
375 ])
376
377 dnl PSI_CHECK_OFFSETOF(struct, element)
378 dnl Check the offset of a struct element, implemented in the similar manner
379 dnl like AC_CHECK_SIZEOF.
380 dnl AC_DEFINEs OFFSETOF_<STRUCT>_<ELEMENT>.
381 AC_DEFUN(PSI_CHECK_OFFSETOF, [
382 _AC_CACHE_CHECK_INT(
383 [offset of $2 in $1],
384 [AS_TR_SH([ac_cv_offsetof_$1_$2])],
385 [(long int) (offsetof ($1, $2))],
386 [PSI_INCLUDES],
387 [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
388 )
389 AC_DEFINE_UNQUOTED(
390 AS_TR_CPP(offsetof_$1_$2),
391 $AS_TR_SH([ac_cv_offsetof_$1_$2]),
392 [The offset of `$2' in `$1', as computed by offsetof.]
393 )
394 ])
395
396
397 dnl PSI_COMPUTE_STR(variable, string or expression)
398 dnl Compute a string constant value in a similar manner like AC_COMPUTE_INT.
399 AC_DEFUN(PSI_COMPUTE_STR, [
400 AC_TRY_RUN(
401 PSI_INCLUDES
402 [int main() {
403 return EOF == fputs($2, fopen("conftest.out", "w"));
404 }
405 ], [
406 eval $1=\\\"`cat conftest.out`\\\"
407 ])
408 ])
409
410 dnl PSI_CHECK_LIBJIT()
411 dnl Check for libjit in $PHP_PSI_LIBJIT or standard locations
412 dnl AC_DEFINEs HAVE_LIBJIT.
413 AC_DEFUN(PSI_CHECK_LIBJIT, [
414 AC_CACHE_CHECK(for libjit, psi_cv_libjit_dir, [
415 for psi_cv_libjit_dir in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
416 do
417 if test -e $psi_cv_libjit_dir/include/jit/jit.h
418 then
419 break
420 fi
421 psi_cv_libjit_dir=
422 done
423 ])
424 if test -n "$psi_cv_libjit_dir"
425 then
426 PHP_ADD_INCLUDE($psi_cv_libjit_dir/include)
427 PHP_ADD_LIBRARY_WITH_PATH(jit, $psi_cv_libjit_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
428 AC_DEFINE(HAVE_LIBJIT, 1, Have libjit)
429 else
430 AC_MSG_WARN([Could not find libjit, please provide the base install path])
431 fi
432 ])
433
434 dnl PSI_CHECK_LIBFFI()
435 dnl Check for libffi with `pkg-config`. If that fails, `configure` looks into
436 dnl $PHP_PSI_LIBFFI or standard locations to find libjit deps.
437 dnl Checks for availability of recent closure API:
438 dnl \ffi_closure_alloc and \ffi_prep_closure.
439 dnl Checks for availability of recent vararg API:
440 dnl \ffi_prep_cif_var.
441 dnl AC_DEFINEs HAVE_LIBFFI, PSI_HAVE_FFI_CLOSURE_ALLOC,
442 dnl PSI_HAVE_FFI_PREP_CLOSURE and PSI_HAVE_FFO_PREP_VIF_VAR.
443 AC_DEFUN(PSI_CHECK_LIBFFI, [
444 AC_REQUIRE([PSI_PKG_CONFIG])dnl
445
446 AC_CACHE_CHECK(for libffi through pkg-config, psi_cv_libffi, [
447 if $PKG_CONFIG --exists libffi
448 then
449 psi_cv_libffi=true
450 else
451 psi_cv_libffi=false
452 fi])
453
454 if $psi_cv_libffi
455 then
456 AC_MSG_CHECKING(for libffi)
457 psi_cv_libffi_dir=`$PKG_CONFIG --variable=prefix libffi`
458 AC_MSG_RESULT($psi_cv_libffi_dir)
459 PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
460 PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
461 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
462 AC_DEFINE_UNQUOTED([PHP_PSI_LIBFFI_VERSION], ["`$PKG_CONFIG --modversion libffi`"], [libffi version])
463 else
464 AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
465 for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
466 do
467 if test -e $psi_cv_libffi_dir/include/ffi/ffi.h
468 then
469 break
470 fi
471 psi_cv_libffi_dir=
472 done])
473 if test -n "$psi_cv_libffi_dir"
474 then
475 PHP_ADD_INCLUDE($psi_cv_libffi_dir/include/ffi)
476 PHP_ADD_LIBRARY_WITH_PATH(ffi, $psi_cv_libffi_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
477 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
478 else
479 AC_MSG_WARN([Could not find libffi, please provide the base install path])
480 fi
481 fi
482
483 save_CFLAGS=$CFLAGS
484 CFLAGS="$CFLAGS $INCLUDES"
485 AC_CHECK_DECL(FFI_STDCALL,[AC_DEFINE([HAVE_FFI_STDCALL],[1],[ ])],,[#include "ffi.h"])
486 AC_CHECK_DECL(FFI_FASTCALL,[AC_DEFINE([HAVE_FFI_FASTCALL],[1],[ ])],,[#include "ffi.h"])
487 CFLAGS=$save_CFLAGS
488
489 PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
490 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
491 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
492 ], [], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
493 AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
494 ], [
495 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
496 AC_CHECK_HEADERS(sys/mman.h)
497 PHP_CHECK_FUNC(mmap)
498 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
499 ], [
500 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
501 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
502 PHP_CHECK_LIBRARY(ffi, ffi_prep_cif_var, [
503 AC_DEFINE(PSI_HAVE_FFI_PREP_CIF_VAR, 1, [ ])
504 ], [
505 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
506 ])