37864d0db6075fec164956fcaf47e02b9746dcb4
[m6w6/ext-psi] / m4 / psi.m4
1 dnl Generated headers with pre-defined types, structs, consts and decls.
2 PSI_STDINC=$PHP_PSI_SRCDIR/php_psi_stdinc.h
3 PSI_TYPES=$PHP_PSI_SRCDIR/php_psi_types.h
4 PSI_STRUCTS=$PHP_PSI_SRCDIR/php_psi_structs.h
5 PSI_CONSTS=$PHP_PSI_SRCDIR/php_psi_consts.h
6 PSI_REDIRS=$PHP_PSI_SRCDIR/php_psi_redirs.h
7 PSI_MACROS=$PHP_PSI_SRCDIR/php_psi_macros.h
8 PSI_DECLS=$PHP_PSI_SRCDIR/php_psi_decls.h
9 PSI_VA_DECLS=$PHP_PSI_SRCDIR/php_psi_va_decls.h
10
11 dnl PSI_CONFIG_INIT()
12 dnl Creates stubs of the headers with pre-defined types etc.
13 dnl These headers are included by src/context.c.
14 dnl This macro must be called prior any checks for a type, struct, decl etc.
15 AC_DEFUN(PSI_CONFIG_INIT, [
16 cat >$PSI_TYPES <<EOF
17 static struct psi_predef_type {
18 token_t type_tag;
19 const char *type_name;
20 const char *alias;
21 } psi_predef_types@<:@@:>@ = {
22 EOF
23 cat >$PSI_STRUCTS <<EOF
24 static struct psi_predef_struct {
25 token_t type_tag;
26 const char *type_name;
27 const char *var_name;
28 size_t offset;
29 size_t size;
30 size_t pointer_level;
31 size_t array_size;
32 } psi_predef_structs@<:@@:>@ = {
33 EOF
34 cat >$PSI_CONSTS <<EOF
35 static struct psi_predef_const {
36 token_t type_tag;
37 const char *type_name;
38 const char *var_name;
39 const char *val_text;
40 token_t val_type_tag;
41 } psi_predef_consts@<:@@:>@ = {
42 EOF
43 cat >$PSI_REDIRS <<EOF
44 static struct psi_func_redir {
45 const char *name;
46 void (*func)(void);
47 } psi_func_redirs@<:@@:>@ = {
48 EOF
49 cat >$PSI_MACROS </dev/null
50 cat >$PSI_DECLS <<EOF
51 static struct psi_predef_decl {
52 token_t type_tag;
53 const char *type_name;
54 const char *var_name;
55 size_t pointer_level;
56 size_t array_size;
57 } psi_predef_decls@<:@@:>@ = {
58 EOF
59 cat >$PSI_VA_DECLS <<EOF
60 static struct psi_predef_decl psi_predef_vararg_decls@<:@@:>@ = {
61 EOF
62 ])
63
64 dnl PSI_CONFIG_DONE()
65 dnl Finish the headers with the pre-defined types etc.
66 AC_DEFUN(PSI_CONFIG_DONE, [
67 cat >$PSI_STDINC <<EOF
68 PSI_INCLUDES
69 EOF
70 for i in $PSI_TYPES $PSI_STRUCTS $PSI_CONSTS $PSI_REDIRS $PSI_DECLS $PSI_VA_DECLS; do
71 cat >>$i <<EOF
72 {0}
73 };
74 EOF
75 done
76 ])
77
78 dnl PSI_INCLUDES()
79 dnl Expands to a complete list of include statements including
80 dnl AC_INCLUDES_DEFAULT().
81 AC_DEFUN(PSI_INCLUDES, [AC_INCLUDES_DEFAULT()
82 #ifdef HAVE_ERRNO_H
83 # include <errno.h>
84 #endif
85 #ifdef HAVE_GLOB_H
86 # include <glob.h>
87 #endif
88 #ifdef HAVE_LOCALE_H
89 # include <locale.h>
90 #endif
91 #ifdef HAVE_XLOCALE_H
92 # include <xlocale.h>
93 #endif
94 #ifdef HAVE_NETINET_IN_H
95 # include <netinet/in.h>
96 #endif
97 #ifdef HAVE_NETINET_TCP_H
98 # include <netinet/tcp.h>
99 #endif
100 #ifdef HAVE_ARPA_NAMESER_H
101 # include <arpa/nameser.h>
102 #endif
103 #ifdef HAVE_NDBM_H
104 # include <ndbm.h>
105 #endif
106 #ifdef HAVE_NETDB_H
107 # include <netdb.h>
108 #endif
109 #ifdef HAVE_POLL_H
110 # include <poll.h>
111 #endif
112 #ifdef HAVE_RESOLV_H
113 # include <resolv.h>
114 #endif
115 #ifdef HAVE_SYS_SELECT_H
116 # include <sys/select.h>
117 #endif
118 #ifdef HAVE_SYS_SOCKET_H
119 # include <sys/socket.h>
120 #endif
121 #ifdef HAVE_SYS_TIME_H
122 # include <sys/time.h>
123 #endif
124 #ifdef HAVE_SYS_TIMES_H
125 # include <sys/times.h>
126 #endif
127 #ifdef HAVE_SYS_UIO_H
128 # include <sys/uio.h>
129 #endif
130 #ifdef HAVE_SYS_UTSNAME_H
131 # include <sys/utsname.h>
132 #endif
133 #ifdef HAVE_TIME_H
134 # include <time.h>
135 #endif
136 #ifdef HAVE_SYSLOG_H
137 # include <syslog.h>
138 #endif
139 #ifdef HAVE_WCHAR_H
140 # include <wchar.h>
141 #endif
142 #ifdef HAVE_WCTYPE_H
143 # include <wctype.h>
144 #endif
145 ])
146
147 dnl PSI_LEMON()
148 dnl Declare $LEMON precious, and check for a `lemon` in $PATH.
149 AC_DEFUN(PSI_LEMON, [
150 AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
151 AC_PATH_PROG(LEMON, lemon, ./lemon)
152 PHP_SUBST(LEMON)
153 ])
154
155 dnl PSI_PKG_CONFIG()
156 dnl Check for `pkg-config` and add possible libjit and libffi directories to
157 dnl $PKG_CONFIG_PATH, because those libs often ship with headers etc. in
158 dnl arch-dependent locations.
159 AC_DEFUN([PSI_PKG_CONFIG], [
160 if test -z "$PKG_CONFIG"
161 then
162 AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
163 fi
164 export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
165 ])
166
167 dnl PSI_SH_SIZEOF(type)
168 dnl expand to shell variable $ac_cv_sizeof_<TYPE>
169 AC_DEFUN([PSI_SH_SIZEOF], [$AS_TR_SH([ac_cv_sizeof_]$1)])
170
171 dnl PSI_SH_TEST_SIZEOF(type)
172 dnl `if` condition to test if $ac_cv_sizeof_$1 is greater than 0.
173 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])
174
175 dnl PSI_CHECK_SIZEOF(type, special-includes)
176 dnl AC_CHECK_SIZEOF wrapper with PSI_INCLUDES
177 dnl Defines psi\\SIZEOF_<TYPE> pre-defined constant in $PSI_CONSTS.
178 AC_DEFUN(PSI_CHECK_SIZEOF, [
179 AC_CHECK_SIZEOF($1, [], PSI_INCLUDES
180 $2)
181 if PSI_SH_TEST_SIZEOF($1); then
182 psi_add_int_const "AS_TR_CPP([SIZEOF_]$1)" "$AS_TR_SH([ac_cv_sizeof_]$1)"
183 fi
184 ])
185
186 dnl PSI_CHECK_OFFSETOF(struct, element)
187 dnl Check the offset of a struct element, implemented in the similar manner
188 dnl like AC_CHECK_SIZEOF.
189 dnl AC_DEFINEs OFFSETOF_<STRUCT>_<ELEMENT>.
190 AC_DEFUN(PSI_CHECK_OFFSETOF, [
191 _AC_CACHE_CHECK_INT(
192 [offset of $2 in $1],
193 [AS_TR_SH([ac_cv_offsetof_$1_$2])],
194 [(long int) (offsetof ($1, $2))],
195 [PSI_INCLUDES],
196 [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
197 )
198 AC_DEFINE_UNQUOTED(
199 AS_TR_CPP(offsetof_$1_$2),
200 $AS_TR_SH([ac_cv_offsetof_$1_$2]),
201 [The offset of `$2' in `$1', as computed by offsetof.]
202 )
203 ])
204
205 dnl PSI_SH_OFFSETOF(type)
206 dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
207 AC_DEFUN([PSI_SH_OFFSETOF], [$AS_TR_SH([ac_cv_offsetof_]$1)])
208
209
210 dnl PSI_COMPUTE_STR(variable, string or expression)
211 dnl Compute a string constant value in a similar manner like AC_COMPUTE_INT.
212 AC_DEFUN(PSI_COMPUTE_STR, [
213 AC_TRY_RUN(
214 PSI_INCLUDES
215 [int main() {
216 return EOF == fputs($2, fopen("conftest.out", "w"));
217 }
218 ], [
219 eval $1=\\\"`cat conftest.out`\\\"
220 ])
221 ])
222
223 dnl PSI_CHECK_LIBJIT()
224 dnl Check for libjit in $PHP_PSI_LIBJIT or standard locations
225 dnl AC_DEFINEs HAVE_LIBJIT.
226 AC_DEFUN(PSI_CHECK_LIBJIT, [
227 AC_CACHE_CHECK(for libjit, psi_cv_libjit_dir, [
228 for psi_cv_libjit_dir in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
229 do
230 if test -e $psi_cv_libjit_dir/include/jit/jit.h
231 then
232 break
233 fi
234 psi_cv_libjit_dir=
235 done
236 ])
237 if test -n "$psi_cv_libjit_dir"
238 then
239 PHP_ADD_INCLUDE($psi_cv_libjit_dir/include)
240 PHP_ADD_LIBRARY_WITH_PATH(jit, $psi_cv_libjit_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
241 AC_DEFINE(HAVE_LIBJIT, 1, Have libjit)
242 else
243 AC_MSG_WARN([Could not find libjit, please provide the base install path])
244 fi
245 ])
246
247 dnl PSI_CHECK_LIBFFI()
248 dnl Check for libffi with `pkg-config`. If that fails, `configure` looks into
249 dnl $PHP_PSI_LIBFFI or standard locations to find libjit deps.
250 dnl Checks for availability of recent closure API:
251 dnl \ffi_closure_alloc and \ffi_prep_closure.
252 dnl Checks for availability of recent vararg API:
253 dnl \ffi_prep_cif_var.
254 dnl AC_DEFINEs HAVE_LIBFFI, PSI_HAVE_FFI_CLOSURE_ALLOC,
255 dnl PSI_HAVE_FFI_PREP_CLOSURE and PSI_HAVE_FFO_PREP_VIF_VAR.
256 AC_DEFUN(PSI_CHECK_LIBFFI, [
257 AC_REQUIRE([PSI_PKG_CONFIG])dnl
258
259 AC_CACHE_CHECK(for libffi through pkg-config, psi_cv_libffi, [
260 if $PKG_CONFIG --exists libffi
261 then
262 psi_cv_libffi=true
263 else
264 psi_cv_libffi=false
265 fi])
266
267 if $psi_cv_libffi
268 then
269 AC_MSG_CHECKING(for libffi)
270 psi_cv_libffi_dir=`$PKG_CONFIG --variable=prefix libffi`
271 AC_MSG_RESULT($psi_cv_libffi_dir)
272 PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
273 PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
274 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
275 else
276 AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
277 for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
278 do
279 if test -e $psi_cv_libffi_dir/include/ffi/ffi.h
280 then
281 break
282 fi
283 psi_cv_libffi_dir=
284 done])
285 if test -n "$psi_cv_libffi_dir"
286 then
287 PHP_ADD_INCLUDE($psi_cv_libffi_dir/include/ffi)
288 PHP_ADD_LIBRARY_WITH_PATH(ffi, $psi_cv_libffi_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
289 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
290 else
291 AC_MSG_WARN([Could not find libffi, please provide the base install path])
292 fi
293 fi
294 PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
295 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
296 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
297 ], [], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
298 AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
299 ], [
300 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
301 AC_CHECK_HEADERS(sys/mman.h)
302 PHP_CHECK_FUNC(mmap)
303 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
304 ], [
305 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
306 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
307 PHP_CHECK_LIBRARY(ffi, ffi_prep_cif_var, [
308 AC_DEFINE(PSI_HAVE_FFI_PREP_CIF_VAR, 1, [ ])
309 ], [
310 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
311 ])