more verbose context ops
[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
14 AC_MSG_CHECKING(for preprocessor defaults)
15 psi_cpp_predef=`$CPP -Wp,-dM $CPPFLAGS -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -U__BLOCKS__ - </dev/null`
16 psi_cpp_search=`$CPP -Wp,-v $CPPFLAGS -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 - </dev/null 2>&1 >/dev/null \
17 | $AWK '
18 /include.*search.*start/ {
19 capture = 1
20 next
21 }
22 /@<:@Ee@:>@nd.*search/ {
23 capture = 0
24 }
25 {
26 if (capture)
27 print $1
28 }
29 ' \
30 `
31 psi_cpp_predef_count=`printf %s "$psi_cpp_predef" | wc -l`
32 psi_cpp_search_count=`printf %s "$psi_cpp_search" | wc -l`
33 AC_MSG_RESULT([$psi_cpp_predef_count predefined macros, and $psi_cpp_search_count search paths])
34 PSI_CPP_PREDEF=`printf "%s\n" "$psi_cpp_predef" | \
35 $AWK '{
36 gsub(/"/, "\\\\\"");
37 printf "\"%s\\\n\"\n", $[]0
38 }' \
39 `
40 PSI_CPP_SEARCH=`printf %s "$psi_cpp_search" | \
41 $AWK '{
42 if (i) printf ":";
43 gsub(/^@<:@@<:@:space:@:>@@:>@+/,"");
44 gsub(/@<:@@<:@:space:@:>@@:>@+$/,"");
45 printf "%s", $[]0;
46 ++i
47 }' \
48 `
49
50 if test "$PHP_PSI_MAINTAINER_MODE" = "yes"; then
51 PSI_DEPS=true
52 PHP_SUBST(PSI_DEPS)
53 EXTRA_CFLAGS="-Wall -Wextra $EXTRA_CFLAGS"
54 else
55 PSI_DEPS=false
56 fi
57
58 PSI_STDTYPES=
59 PSI_CONSTS=
60
61 AC_CONFIG_FILES(
62 [$PHP_PSI_BUILDDIR/php_psi_stdinc.h:$PHP_PSI_SRCDIR/php_psi_stdinc.h.in]
63 [$PHP_PSI_BUILDDIR/php_psi_posix.h:$PHP_PSI_SRCDIR/php_psi_posix.h.in]
64 [$PHP_PSI_BUILDDIR/php_psi_cpp.h:$PHP_PSI_SRCDIR/php_psi_cpp.h.in]
65 )
66
67 ])
68
69 dnl PSI_CONFIG_DONE()
70 dnl Finish the headers with the pre-defined types etc.
71 AC_DEFUN(PSI_CONFIG_DONE, [
72 psi_eval_LIBS=$LIBS
73 LIBS=$psi_save_LIBS
74 PHP_EVAL_LIBLINE($psi_eval_LIBS, PSI_SHARED_LIBADD)
75
76 [PSI_INCLUDES]="PSI_INCLUDES"
77 AC_SUBST([PSI_INCLUDES])
78 AC_SUBST([PSI_STDTYPES])
79 AC_SUBST([PSI_CONSTS])
80 AC_SUBST([PSI_CPP_SEARCH])
81 AC_SUBST([PSI_CPP_PREDEF])
82 ])
83
84 AC_DEFUN(PSI_PTHREAD_ONCE, [
85 AX_PTHREAD([
86 LIBS="$PTHREAD_LIBS $LIBS"
87 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
88 ])
89 ])
90 AC_DEFUN(PSI_PTHREAD, [
91 AC_REQUIRE([PSI_PTHREAD_ONCE])
92 ])
93
94 dnl PSI_INCLUDES()
95 dnl Expands to a complete list of include statements including
96 dnl autoconf's defaults.
97 AC_DEFUN(PSI_INCLUDES, [
98 #ifndef _GNU_SOURCE
99 # define _GNU_SOURCE
100 #endif
101 #ifndef _REENTRANT
102 # define _REENTRANT
103 #endif
104 $ac_includes_default
105 #ifdef HAVE_STDBOOL_H
106 # include <stdbool.h>
107 #else
108 # ifndef HAVE__BOOL
109 # ifdef __cplusplus
110 typedef bool _Bool;
111 # else
112 # define _Bool signed char
113 # endif
114 # endif
115 # define bool _Bool
116 # define false 0
117 # define true 1
118 # define __bool_true_false_are_defined 1
119 #endif
120 #ifdef HAVE_ERRNO_H
121 # include <errno.h>
122 #endif
123 #ifdef HAVE_GLOB_H
124 # include <glob.h>
125 #endif
126 #ifdef HAVE_LOCALE_H
127 # include <locale.h>
128 #endif
129 #ifdef HAVE_XLOCALE_H
130 # include <xlocale.h>
131 #endif
132 #ifdef HAVE_NETINET_IN_H
133 # include <netinet/in.h>
134 #endif
135 #ifdef HAVE_NETINET_TCP_H
136 # include <netinet/tcp.h>
137 #endif
138 #ifdef HAVE_ARPA_NAMESER_H
139 # include <arpa/nameser.h>
140 #endif
141 #ifdef HAVE_ARPA_INET_H
142 # include <arpa/inet.h>
143 #endif
144 #ifdef HAVE_FCNTL_H
145 # include <fcntl.h>
146 #endif
147 #ifdef HAVE_RELIC_H
148 # include <relic.h>
149 #elif HAVE_NDBM_H
150 # include <ndbm.h>
151 #elif HAVE_GDBM_NDBM_H
152 # include <gdbm-ndbm.h>
153 #endif
154 #ifdef HAVE_NETDB_H
155 # include <netdb.h>
156 #endif
157 #ifdef HAVE_POLL_H
158 # include <poll.h>
159 #endif
160 #ifdef HAVE_RESOLV_H
161 # include <resolv.h>
162 #endif
163 #ifdef HAVE_SYS_SELECT_H
164 # include <sys/select.h>
165 #endif
166 #ifdef HAVE_SYS_SOCKET_H
167 # include <sys/socket.h>
168 #endif
169 #ifdef HAVE_SYS_TIME_H
170 # include <sys/time.h>
171 #endif
172 #ifdef HAVE_SYS_TIMES_H
173 # include <sys/times.h>
174 #endif
175 #ifdef HAVE_SYS_UIO_H
176 # include <sys/uio.h>
177 #endif
178 #ifdef HAVE_SYS_UTSNAME_H
179 # include <sys/utsname.h>
180 #endif
181 #ifdef HAVE_TIME_H
182 # include <time.h>
183 #endif
184 #ifdef HAVE_SIGNAL_H
185 # include <signal.h>
186 #endif
187 #ifdef HAVE_SYSLOG_H
188 # include <syslog.h>
189 #endif
190 #ifdef HAVE_WCHAR_H
191 # include <wchar.h>
192 #endif
193 #ifdef HAVE_WCTYPE_H
194 # include <wctype.h>
195 #endif
196 ])
197
198 dnl PSI_LEMON()
199 dnl Declare $LEMON precious, and check for a `lemon` in $PATH.
200 AC_DEFUN(PSI_LEMON, [
201 AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
202 if test -z "$LEMON"
203 then
204 AC_PATH_PROG(LEMON, lemon, $PHP_PSI_BUILDDIR/lemon)
205 if expr + "$LEMON" : "/" >/dev/null; then
206 LEMON_PATH=
207 else
208 LEMON_PATH=$abs_builddir/
209 fi
210 fi
211 PHP_SUBST(LEMON_PATH)
212 PHP_SUBST(LEMON)
213 ])
214
215 dnl PSI_PKG_CONFIG()
216 dnl Check for `pkg-config` and add possible libjit and libffi directories to
217 dnl $PKG_CONFIG_PATH, because those libs often ship with headers etc. in
218 dnl arch-dependent locations.
219 AC_DEFUN([PSI_PKG_CONFIG], [
220 if test -z "$PKG_CONFIG"
221 then
222 AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
223 fi
224 export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
225 ])
226
227 dnl PSI_SH_SIZEOF(type)
228 dnl expand to shell variable $ac_cv_sizeof_<TYPE>
229 AC_DEFUN([PSI_SH_SIZEOF], [$AS_TR_SH([ac_cv_sizeof_]$1)])
230
231 dnl PSI_SH_OFFSETOF(type)
232 dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
233 AC_DEFUN([PSI_SH_OFFSETOF], [$AS_TR_SH([ac_cv_offsetof_]$1)])
234
235 dnl PSI_SH_ALIGNOF(type)
236 dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
237 AC_DEFUN([PSI_SH_ALIGNOF], [$AS_TR_SH([ac_cv_alignof_]$1)])
238
239 dnl PSI_SH_TEST_SIZEOF(type)
240 dnl `if` condition to test if $ac_cv_sizeof_$1 is greater than 0.
241 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])
242
243 dnl PSI_SH_TEST_ALIGNOF(type)
244 dnl `if` condition to test if $ac_cv_alignof_$1 is greater than 0.
245 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])
246
247 dnl PSI_CHECK_SIZEOF(type, special-includes)
248 dnl AC_CHECK_SIZEOF wrapper with PSI_INCLUDES
249 dnl Defines psi\\SIZEOF_<TYPE> pre-defined constant in $PSI_CONSTS_H.
250 AC_DEFUN(PSI_CHECK_SIZEOF, [
251 AC_CHECK_SIZEOF($1, [], PSI_INCLUDES
252 $2)
253 if PSI_SH_TEST_SIZEOF($1); then
254 psi_add_int_const "AS_TR_CPP([SIZEOF_]$1)" "$AS_TR_SH([ac_cv_sizeof_]$1)"
255 fi
256 ])
257
258 dnl PSI_CHECK_ALIGNOF(type, special-includes)
259 dnl AC_CHECK_ALIGNOF wrapper with PSI_INCLUDES
260 dnl Defines psi\\ALIGNOF_<TYPE> pre-defined constant in $PSI_CONSTS_H.
261 AC_DEFUN(PSI_CHECK_ALIGNOF, [
262 AC_CHECK_ALIGNOF($1, PSI_INCLUDES
263 $2)
264 if PSI_SH_TEST_ALIGNOF($1); then
265 psi_add_int_const "AS_TR_CPP([ALIGNOF_]$1)" "$AS_TR_SH([ac_cv_alignof_]$1)"
266 fi
267 ])
268
269 dnl PSI_CHECK_OFFSETOF(struct, element)
270 dnl Check the offset of a struct element, implemented in the similar manner
271 dnl like AC_CHECK_SIZEOF.
272 dnl AC_DEFINEs OFFSETOF_<STRUCT>_<ELEMENT>.
273 AC_DEFUN(PSI_CHECK_OFFSETOF, [
274 _AC_CACHE_CHECK_INT(
275 [offset of $2 in $1],
276 [AS_TR_SH([ac_cv_offsetof_$1_$2])],
277 [(long int) (offsetof ($1, $2))],
278 PSI_INCLUDES,
279 [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
280 )
281 AC_DEFINE_UNQUOTED(
282 AS_TR_CPP(offsetof_$1_$2),
283 $AS_TR_SH([ac_cv_offsetof_$1_$2]),
284 [The offset of `$2' in `$1', as computed by offsetof.]
285 )
286 ])
287
288
289 dnl PSI_COMPUTE_STR(variable, string or expression)
290 dnl Compute a string constant value in a similar manner like AC_COMPUTE_INT.
291 AC_DEFUN(PSI_COMPUTE_STR, [
292 AC_TRY_RUN(
293 PSI_INCLUDES
294 [int main() {
295 return EOF == fputs($2, fopen("conftest.out", "w"));
296 }
297 ], [
298 eval $1=\\\"`cat conftest.out`\\\"
299 ])
300 ])
301
302 dnl PSI_CHECK_LIBJIT()
303 dnl Check for libjit in $PHP_PSI_LIBJIT or standard locations
304 dnl AC_DEFINEs HAVE_LIBJIT.
305 AC_DEFUN(PSI_CHECK_LIBJIT, [
306 AC_CACHE_CHECK(for libjit, psi_cv_libjit_dir, [
307 for psi_cv_libjit_dir in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
308 do
309 if test -e $psi_cv_libjit_dir/include/jit/jit.h
310 then
311 break
312 fi
313 psi_cv_libjit_dir=
314 done
315 ])
316 if test -n "$psi_cv_libjit_dir"
317 then
318 PHP_ADD_INCLUDE($psi_cv_libjit_dir/include)
319 PHP_ADD_LIBRARY_WITH_PATH(jit, $psi_cv_libjit_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
320 AC_DEFINE(HAVE_LIBJIT, 1, Have libjit)
321 else
322 AC_MSG_WARN([Could not find libjit, please provide the base install path])
323 fi
324 ])
325
326 dnl PSI_CHECK_LIBFFI()
327 dnl Check for libffi with `pkg-config`. If that fails, `configure` looks into
328 dnl $PHP_PSI_LIBFFI or standard locations to find libjit deps.
329 dnl Checks for availability of recent closure API:
330 dnl \ffi_closure_alloc and \ffi_prep_closure.
331 dnl Checks for availability of recent vararg API:
332 dnl \ffi_prep_cif_var.
333 dnl AC_DEFINEs HAVE_LIBFFI, PSI_HAVE_FFI_CLOSURE_ALLOC,
334 dnl PSI_HAVE_FFI_PREP_CLOSURE and PSI_HAVE_FFO_PREP_VIF_VAR.
335 AC_DEFUN(PSI_CHECK_LIBFFI, [
336 AC_REQUIRE([PSI_PKG_CONFIG])dnl
337
338 AC_CACHE_CHECK(for libffi through pkg-config, psi_cv_libffi, [
339 if $PKG_CONFIG --exists libffi
340 then
341 psi_cv_libffi=true
342 else
343 psi_cv_libffi=false
344 fi])
345
346 if $psi_cv_libffi
347 then
348 AC_MSG_CHECKING(for libffi)
349 psi_cv_libffi_dir=`$PKG_CONFIG --variable=prefix libffi`
350 AC_MSG_RESULT($psi_cv_libffi_dir)
351 PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
352 PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
353 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
354 AC_DEFINE_UNQUOTED([PHP_PSI_LIBFFI_VERSION], ["`$PKG_CONFIG --modversion libffi`"], [libffi version])
355 else
356 AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
357 for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
358 do
359 if test -e $psi_cv_libffi_dir/include/ffi/ffi.h
360 then
361 break
362 fi
363 psi_cv_libffi_dir=
364 done])
365 if test -n "$psi_cv_libffi_dir"
366 then
367 PHP_ADD_INCLUDE($psi_cv_libffi_dir/include/ffi)
368 PHP_ADD_LIBRARY_WITH_PATH(ffi, $psi_cv_libffi_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
369 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
370 else
371 AC_MSG_WARN([Could not find libffi, please provide the base install path])
372 fi
373 fi
374
375 save_CFLAGS=$CFLAGS
376 CFLAGS="$CFLAGS $INCLUDES"
377 AC_CHECK_DECL(FFI_STDCALL,[AC_DEFINE([HAVE_FFI_STDCALL],[1],[ ])],,[#include "ffi.h"])
378 AC_CHECK_DECL(FFI_FASTCALL,[AC_DEFINE([HAVE_FFI_FASTCALL],[1],[ ])],,[#include "ffi.h"])
379 CFLAGS=$save_CFLAGS
380
381 PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
382 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
383 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
384 ], [], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
385 AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
386 ], [
387 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
388 AC_CHECK_HEADERS(sys/mman.h)
389 PHP_CHECK_FUNC(mmap)
390 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
391 ], [
392 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
393 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
394 PHP_CHECK_LIBRARY(ffi, ffi_prep_cif_var, [
395 AC_DEFINE(PSI_HAVE_FFI_PREP_CIF_VAR, 1, [ ])
396 ], [
397 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
398 ])