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