3853fa668374eb426bfe4879dcbdefcf71171c73
[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_TEST_SIZEOF(type)
168 dnl `if` condition to test if $ac_cv_sizeof_$1 is greater than 0.
169 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])
170
171 dnl PSI_CHECK_SIZEOF(type, special-includes)
172 dnl AC_CHECK_SIZEOF wrapper with PSI_INCLUDES
173 dnl Defines psi\\SIZEOF_<TYPE> pre-defined constant in $PSI_CONSTS.
174 AC_DEFUN(PSI_CHECK_SIZEOF, [
175 AC_CHECK_SIZEOF($1, [], PSI_INCLUDES
176 $2)
177 if PSI_SH_TEST_SIZEOF($1); then
178 psi_add_int_const "AS_TR_CPP([SIZEOF_]$1)" "$AS_TR_SH([ac_cv_sizeof_]$1)"
179 fi
180 ])
181
182 dnl PSI_CHECK_OFFSETOF(struct, element)
183 dnl Check the offset of a struct element, implemented in the similar manner
184 dnl like AC_CHECK_SIZEOF.
185 dnl AC_DEFINEs OFFSETOF_<STRUCT>_<ELEMENT>.
186 AC_DEFUN(PSI_CHECK_OFFSETOF, [
187 _AC_CACHE_CHECK_INT(
188 [offset of $2 in $1],
189 [AS_TR_SH([ac_cv_offsetof_$1_$2])],
190 [(long int) (offsetof ($1, $2))],
191 [PSI_INCLUDES],
192 [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
193 )
194 AC_DEFINE_UNQUOTED(
195 AS_TR_CPP(offsetof_$1_$2),
196 $AS_TR_SH([ac_cv_offsetof_$1_$2]),
197 [The offset of `$2' in `$1', as computed by offsetof.]
198 )
199 ])
200
201 dnl PSI_COMPUTE_STR(variable, string or expression)
202 dnl Compute a string constant value in a similar manner like AC_COMPUTE_INT.
203 AC_DEFUN(PSI_COMPUTE_STR, [
204 AC_TRY_RUN(
205 PSI_INCLUDES
206 [int main() {
207 return EOF == fputs($2, fopen("conftest.out", "w"));
208 }
209 ], [
210 eval $1=\\\"`cat conftest.out`\\\"
211 ])
212 ])
213
214 dnl PSI_CHECK_LIBJIT()
215 dnl Check for libjit in $PHP_PSI_LIBJIT or standard locations
216 dnl AC_DEFINEs HAVE_LIBJIT.
217 AC_DEFUN(PSI_CHECK_LIBJIT, [
218 AC_CACHE_CHECK(for libjit, psi_cv_libjit_dir, [
219 for psi_cv_libjit_dir in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
220 do
221 if test -e $psi_cv_libjit_dir/include/jit/jit.h
222 then
223 break
224 fi
225 psi_cv_libjit_dir=
226 done
227 ])
228 if test -n "$psi_cv_libjit_dir"
229 then
230 PHP_ADD_INCLUDE($psi_cv_libjit_dir/include)
231 PHP_ADD_LIBRARY_WITH_PATH(jit, $psi_cv_libjit_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
232 AC_DEFINE(HAVE_LIBJIT, 1, Have libjit)
233 else
234 AC_MSG_WARN([Could not find libjit, please provide the base install path])
235 fi
236 ])
237
238 dnl PSI_CHECK_LIBFFI()
239 dnl Check for libffi with `pkg-config`. If that fails, `configure` looks into
240 dnl $PHP_PSI_LIBFFI or standard locations to find libjit deps.
241 dnl Checks for availability of recent closure API:
242 dnl \ffi_closure_alloc and \ffi_prep_closure.
243 dnl Checks for availability of recent vararg API:
244 dnl \ffi_prep_cif_var.
245 dnl AC_DEFINEs HAVE_LIBFFI, PSI_HAVE_FFI_CLOSURE_ALLOC,
246 dnl PSI_HAVE_FFI_PREP_CLOSURE and PSI_HAVE_FFO_PREP_VIF_VAR.
247 AC_DEFUN(PSI_CHECK_LIBFFI, [
248 AC_REQUIRE([PSI_PKG_CONFIG])dnl
249
250 AC_CACHE_CHECK(for libffi through pkg-config, psi_cv_libffi, [
251 if $PKG_CONFIG --exists libffi
252 then
253 psi_cv_libffi=true
254 else
255 psi_cv_libffi=false
256 fi])
257
258 if $psi_cv_libffi
259 then
260 AC_MSG_CHECKING(for libffi)
261 psi_cv_libffi_dir=`$PKG_CONFIG --variable=prefix libffi`
262 AC_MSG_RESULT($psi_cv_libffi_dir)
263 PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
264 PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
265 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
266 else
267 AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
268 for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
269 do
270 if test -e $psi_cv_libffi_dir/include/ffi/ffi.h
271 then
272 break
273 fi
274 psi_cv_libffi_dir=
275 done])
276 if test -n "$psi_cv_libffi_dir"
277 then
278 PHP_ADD_INCLUDE($psi_cv_libffi_dir/include/ffi)
279 PHP_ADD_LIBRARY_WITH_PATH(ffi, $psi_cv_libffi_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
280 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
281 else
282 AC_MSG_WARN([Could not find libffi, please provide the base install path])
283 fi
284 fi
285 PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
286 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
287 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
288 ], [], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
289 AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
290 ], [
291 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
292 AC_CHECK_HEADERS(sys/mman.h)
293 PHP_CHECK_FUNC(mmap)
294 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
295 ], [
296 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
297 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
298 PHP_CHECK_LIBRARY(ffi, ffi_prep_cif_var, [
299 AC_DEFINE(PSI_HAVE_FFI_PREP_CIF_VAR, 1, [ ])
300 ], [
301 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
302 ])