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