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