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