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