flush
[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_CONFIG_POSIX(section, headers)
103 AC_DEFUN(PSI_CONFIG_POSIX, [
104 case "$PHP_PSI_POSIX" in
105 yes|all) ;;
106 *) expr "$PHP_PSI_POSIX" : '\b$1\b' >/dev/null || return 0 ;;
107 esac
108 ifelse($2,,,AC_CHECK_HEADERS($2))
109 ])
110
111 dnl PSI_INCLUDES()
112 dnl Expands to a complete list of include statements including
113 dnl AC_INCLUDES_DEFAULT().
114 AC_DEFUN(PSI_INCLUDES, [AC_INCLUDES_DEFAULT()
115 #ifdef HAVE_ERRNO_H
116 # include <errno.h>
117 #endif
118 #ifdef HAVE_GLOB_H
119 # include <glob.h>
120 #endif
121 #ifdef HAVE_LOCALE_H
122 # include <locale.h>
123 #endif
124 #ifdef HAVE_XLOCALE_H
125 # include <xlocale.h>
126 #endif
127 #ifdef HAVE_NETINET_IN_H
128 # include <netinet/in.h>
129 #endif
130 #ifdef HAVE_NETINET_TCP_H
131 # include <netinet/tcp.h>
132 #endif
133 #ifdef HAVE_ARPA_NAMESER_H
134 # include <arpa/nameser.h>
135 #endif
136 #ifdef HAVE_FCNTL_H
137 # include <fcntl.h>
138 #endif
139 #ifdef HAVE_NDBM_H
140 # include <ndbm.h>
141 #endif
142 #ifdef HAVE_NETDB_H
143 # include <netdb.h>
144 #endif
145 #ifdef HAVE_POLL_H
146 # include <poll.h>
147 #endif
148 #ifdef HAVE_RESOLV_H
149 # include <resolv.h>
150 #endif
151 #ifdef HAVE_SYS_SELECT_H
152 # include <sys/select.h>
153 #endif
154 #ifdef HAVE_SYS_SOCKET_H
155 # include <sys/socket.h>
156 #endif
157 #ifdef HAVE_SYS_TIME_H
158 # include <sys/time.h>
159 #endif
160 #ifdef HAVE_SYS_TIMES_H
161 # include <sys/times.h>
162 #endif
163 #ifdef HAVE_SYS_UIO_H
164 # include <sys/uio.h>
165 #endif
166 #ifdef HAVE_SYS_UTSNAME_H
167 # include <sys/utsname.h>
168 #endif
169 #ifdef HAVE_TIME_H
170 # include <time.h>
171 #endif
172 #ifdef HAVE_SYSLOG_H
173 # include <syslog.h>
174 #endif
175 #ifdef HAVE_WCHAR_H
176 # include <wchar.h>
177 #endif
178 #ifdef HAVE_WCTYPE_H
179 # include <wctype.h>
180 #endif
181 ])
182
183 dnl PSI_LEMON()
184 dnl Declare $LEMON precious, and check for a `lemon` in $PATH.
185 AC_DEFUN(PSI_LEMON, [
186 AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
187 AC_PATH_PROG(LEMON, lemon, ./lemon)
188 PHP_SUBST(LEMON)
189 ])
190
191 dnl PSI_PKG_CONFIG()
192 dnl Check for `pkg-config` and add possible libjit and libffi directories to
193 dnl $PKG_CONFIG_PATH, because those libs often ship with headers etc. in
194 dnl arch-dependent locations.
195 AC_DEFUN([PSI_PKG_CONFIG], [
196 if test -z "$PKG_CONFIG"
197 then
198 AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
199 fi
200 export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
201 ])
202
203 dnl PSI_SH_SIZEOF(type)
204 dnl expand to shell variable $ac_cv_sizeof_<TYPE>
205 AC_DEFUN([PSI_SH_SIZEOF], [$AS_TR_SH([ac_cv_sizeof_]$1)])
206
207 dnl PSI_SH_TEST_SIZEOF(type)
208 dnl `if` condition to test if $ac_cv_sizeof_$1 is greater than 0.
209 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])
210
211 dnl PSI_CHECK_SIZEOF(type, special-includes)
212 dnl AC_CHECK_SIZEOF wrapper with PSI_INCLUDES
213 dnl Defines psi\\SIZEOF_<TYPE> pre-defined constant in $PSI_CONSTS.
214 AC_DEFUN(PSI_CHECK_SIZEOF, [
215 AC_CHECK_SIZEOF($1, [], PSI_INCLUDES
216 $2)
217 if PSI_SH_TEST_SIZEOF($1); then
218 psi_add_int_const "AS_TR_CPP([SIZEOF_]$1)" "$AS_TR_SH([ac_cv_sizeof_]$1)"
219 fi
220 ])
221
222 dnl PSI_CHECK_OFFSETOF(struct, element)
223 dnl Check the offset of a struct element, implemented in the similar manner
224 dnl like AC_CHECK_SIZEOF.
225 dnl AC_DEFINEs OFFSETOF_<STRUCT>_<ELEMENT>.
226 AC_DEFUN(PSI_CHECK_OFFSETOF, [
227 _AC_CACHE_CHECK_INT(
228 [offset of $2 in $1],
229 [AS_TR_SH([ac_cv_offsetof_$1_$2])],
230 [(long int) (offsetof ($1, $2))],
231 [PSI_INCLUDES],
232 [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
233 )
234 AC_DEFINE_UNQUOTED(
235 AS_TR_CPP(offsetof_$1_$2),
236 $AS_TR_SH([ac_cv_offsetof_$1_$2]),
237 [The offset of `$2' in `$1', as computed by offsetof.]
238 )
239 ])
240
241 dnl PSI_SH_OFFSETOF(type)
242 dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
243 AC_DEFUN([PSI_SH_OFFSETOF], [$AS_TR_SH([ac_cv_offsetof_]$1)])
244
245
246 dnl PSI_COMPUTE_STR(variable, string or expression)
247 dnl Compute a string constant value in a similar manner like AC_COMPUTE_INT.
248 AC_DEFUN(PSI_COMPUTE_STR, [
249 AC_TRY_RUN(
250 PSI_INCLUDES
251 [int main() {
252 return EOF == fputs($2, fopen("conftest.out", "w"));
253 }
254 ], [
255 eval $1=\\\"`cat conftest.out`\\\"
256 ])
257 ])
258
259 dnl PSI_CHECK_LIBJIT()
260 dnl Check for libjit in $PHP_PSI_LIBJIT or standard locations
261 dnl AC_DEFINEs HAVE_LIBJIT.
262 AC_DEFUN(PSI_CHECK_LIBJIT, [
263 AC_CACHE_CHECK(for libjit, psi_cv_libjit_dir, [
264 for psi_cv_libjit_dir in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
265 do
266 if test -e $psi_cv_libjit_dir/include/jit/jit.h
267 then
268 break
269 fi
270 psi_cv_libjit_dir=
271 done
272 ])
273 if test -n "$psi_cv_libjit_dir"
274 then
275 PHP_ADD_INCLUDE($psi_cv_libjit_dir/include)
276 PHP_ADD_LIBRARY_WITH_PATH(jit, $psi_cv_libjit_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
277 AC_DEFINE(HAVE_LIBJIT, 1, Have libjit)
278 else
279 AC_MSG_WARN([Could not find libjit, please provide the base install path])
280 fi
281 ])
282
283 dnl PSI_CHECK_LIBFFI()
284 dnl Check for libffi with `pkg-config`. If that fails, `configure` looks into
285 dnl $PHP_PSI_LIBFFI or standard locations to find libjit deps.
286 dnl Checks for availability of recent closure API:
287 dnl \ffi_closure_alloc and \ffi_prep_closure.
288 dnl Checks for availability of recent vararg API:
289 dnl \ffi_prep_cif_var.
290 dnl AC_DEFINEs HAVE_LIBFFI, PSI_HAVE_FFI_CLOSURE_ALLOC,
291 dnl PSI_HAVE_FFI_PREP_CLOSURE and PSI_HAVE_FFO_PREP_VIF_VAR.
292 AC_DEFUN(PSI_CHECK_LIBFFI, [
293 AC_REQUIRE([PSI_PKG_CONFIG])dnl
294
295 AC_CACHE_CHECK(for libffi through pkg-config, psi_cv_libffi, [
296 if $PKG_CONFIG --exists libffi
297 then
298 psi_cv_libffi=true
299 else
300 psi_cv_libffi=false
301 fi])
302
303 if $psi_cv_libffi
304 then
305 AC_MSG_CHECKING(for libffi)
306 psi_cv_libffi_dir=`$PKG_CONFIG --variable=prefix libffi`
307 AC_MSG_RESULT($psi_cv_libffi_dir)
308 PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
309 PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
310 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
311 else
312 AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
313 for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
314 do
315 if test -e $psi_cv_libffi_dir/include/ffi/ffi.h
316 then
317 break
318 fi
319 psi_cv_libffi_dir=
320 done])
321 if test -n "$psi_cv_libffi_dir"
322 then
323 PHP_ADD_INCLUDE($psi_cv_libffi_dir/include/ffi)
324 PHP_ADD_LIBRARY_WITH_PATH(ffi, $psi_cv_libffi_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
325 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
326 else
327 AC_MSG_WARN([Could not find libffi, please provide the base install path])
328 fi
329 fi
330 PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
331 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
332 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
333 ], [], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
334 AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
335 ], [
336 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
337 AC_CHECK_HEADERS(sys/mman.h)
338 PHP_CHECK_FUNC(mmap)
339 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
340 ], [
341 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
342 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
343 PHP_CHECK_LIBRARY(ffi, ffi_prep_cif_var, [
344 AC_DEFINE(PSI_HAVE_FFI_PREP_CIF_VAR, 1, [ ])
345 ], [
346 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
347 ])