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