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