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