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