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