flush
[m6w6/ext-psi] / m4 / psi.m4
1 PSI_STDINC=$PHP_PSI_SRCDIR/php_psi_stdinc.h
2 PSI_TYPES=$PHP_PSI_SRCDIR/php_psi_types.h
3 PSI_STRUCTS=$PHP_PSI_SRCDIR/php_psi_structs.h
4 PSI_CONSTS=$PHP_PSI_SRCDIR/php_psi_consts.h
5 PSI_REDIRS=$PHP_PSI_SRCDIR/php_psi_redirs.h
6 PSI_MACROS=$PHP_PSI_SRCDIR/php_psi_macros.h
7 PSI_DECLS=$PHP_PSI_SRCDIR/php_psi_decls.h
8 PSI_VA_DECLS=$PHP_PSI_SRCDIR/php_psi_va_decls.h
9
10 AC_DEFUN(PSI_CONFIG_INIT, [
11 cat >$PSI_TYPES <<EOF
12 static struct psi_predef_type {
13 token_t type_tag;
14 const char *type_name;
15 const char *alias;
16 } psi_predef_types@<:@@:>@ = {
17 EOF
18 cat >$PSI_STRUCTS <<EOF
19 static struct psi_predef_struct {
20 token_t type_tag;
21 const char *type_name;
22 const char *var_name;
23 size_t offset;
24 size_t size;
25 size_t pointer_level;
26 size_t array_size;
27 } psi_predef_structs@<:@@:>@ = {
28 EOF
29 cat >$PSI_CONSTS <<EOF
30 static struct psi_predef_const {
31 token_t type_tag;
32 const char *type_name;
33 const char *var_name;
34 const char *val_text;
35 token_t val_type_tag;
36 } psi_predef_consts@<:@@:>@ = {
37 EOF
38 cat >$PSI_REDIRS <<EOF
39 static struct psi_func_redir {
40 const char *name;
41 void (*func)(void);
42 } psi_func_redirs@<:@@:>@ = {
43 EOF
44 cat >$PSI_MACROS </dev/null
45 cat >$PSI_DECLS <<EOF
46 static struct psi_predef_decl {
47 token_t type_tag;
48 const char *type_name;
49 const char *var_name;
50 size_t pointer_level;
51 size_t array_size;
52 } psi_predef_decls@<:@@:>@ = {
53 EOF
54 cat >$PSI_VA_DECLS <<EOF
55 static struct psi_predef_decl psi_predef_vararg_decls@<:@@:>@ = {
56 EOF
57 ])
58
59 AC_DEFUN(PSI_CONFIG_DONE, [
60 cat >$PSI_STDINC <<EOF
61 PSI_INCLUDES
62 EOF
63 for i in $PSI_TYPES $PSI_STRUCTS $PSI_CONSTS $PSI_REDIRS $PSI_DECLS $PSI_VA_DECLS; do
64 cat >>$i <<EOF
65 {0}
66 };
67 EOF
68 done
69 ])
70
71 psi_includes() {
72 local have_
73 have_=`AS_ECHO($ac_header) | $as_tr_cpp`
74 cat <<EOF
75 #ifdef HAVE_$have_
76 # include <$ac_header>
77 #endif
78 EOF
79 }
80
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 AC_DEFUN(PSI_LEMON, [
145 AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
146 AC_PATH_PROG(LEMON, lemon, ./lemon)
147 PHP_SUBST(LEMON)
148 ])
149
150 AC_DEFUN([PSI_PKG_CONFIG], [
151 if test -z "$PKG_CONFIG"
152 then
153 AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
154 fi
155 export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
156 ])
157
158 AC_DEFUN(PSI_CHECK_SIZEOF, [
159 AC_CHECK_SIZEOF($1, [], $2)
160 if test "$AS_TR_SH([ac_cv_sizeof_]$1)"; then
161 add_int_const "AS_TR_CPP([SIZEOF_]$1)" "$AS_TR_SH([ac_cv_sizeof_]$1)"
162 fi
163 ])
164
165 AC_DEFUN(PSI_CHECK_OFFSETOF, [
166 _AC_CACHE_CHECK_INT(
167 [offset of $2 in $1],
168 [AS_TR_SH([ac_cv_offsetof_$1_$2])],
169 [(long int) (offsetof ($1, $2))],
170 [PSI_INCLUDES],
171 [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
172 )
173 AC_DEFINE_UNQUOTED(
174 AS_TR_CPP(offsetof_$1_$2),
175 $AS_TR_SH([ac_cv_offsetof_$1_$2]),
176 [The offset of `$2' in `$1', as computed by offsetof.]
177 )
178 ])
179
180 AC_DEFUN(PSI_CHECK_LIBJIT, [
181 PHP_ARG_WITH(psi-libjit, where to find libjit,
182 [ --with-psi-libjit=DIR PSI: path to libjit], [ ], [ ])
183 AC_CACHE_CHECK(for libjit, psi_cv_libjit_dir, [
184 for psi_cv_libjit_dir in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
185 do
186 if test -e $psi_cv_libjit_dir/include/jit/jit.h
187 then
188 break
189 fi
190 psi_cv_libjit_dir=
191 done
192 ])
193 if test -n "$psi_cv_libjit_dir"
194 then
195 PHP_ADD_INCLUDE($psi_cv_libjit_dir/include)
196 PHP_ADD_LIBRARY_WITH_PATH(jit, $psi_cv_libjit_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
197 AC_DEFINE(HAVE_LIBJIT, 1, Have libjit)
198 else
199 AC_MSG_WARN([Could not find libjit, please provide the base install path])
200 fi
201 ])
202
203 PHP_ARG_WITH(psi-libffi, where to find libffi,
204 [ --with-psi-libffi=DIR PSI: path to libffi], [ ], [ ])
205 AC_DEFUN(PSI_CHECK_LIBFFI, [
206 AC_REQUIRE([PSI_PKG_CONFIG])dnl
207
208 AC_CACHE_CHECK(for libffi through pkg-config, psi_cv_libffi, [
209 if $PKG_CONFIG --exists libffi
210 then
211 psi_cv_libffi=true
212 else
213 psi_cv_libffi=false
214 fi])
215 if $psi_cv_libffi
216 then
217 AC_MSG_CHECKING(for libffi)
218 psi_cv_libffi_dir=`$PKG_CONFIG --variable=prefix libffi`
219 AC_MSG_RESULT($psi_cv_libffi_dir)
220 PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
221 PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
222 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
223 else
224 AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
225 for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
226 do
227 if test -e $psi_cv_libffi_dir/include/ffi/ffi.h
228 then
229 break
230 fi
231 psi_cv_libffi_dir=
232 done])
233 if test -n "$psi_cv_libffi_dir"
234 then
235 PHP_ADD_INCLUDE($psi_cv_libffi_dir/include/ffi)
236 PHP_ADD_LIBRARY_WITH_PATH(ffi, $psi_cv_libffi_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
237 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
238 else
239 AC_MSG_WARN([Could not find libffi, please provide the base install path])
240 fi
241 fi
242 PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
243 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
244 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
245 ], [], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
246 AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
247 ], [
248 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
249 AC_CHECK_HEADERS(sys/mman.h)
250 PHP_CHECK_FUNC(mmap)
251 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
252 ], [
253 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
254 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
255 PHP_CHECK_LIBRARY(ffi, ffi_prep_cif_var, [
256 AC_DEFINE(PSI_HAVE_FFI_PREP_CIF_VAR, 1, [ ])
257 ], [
258 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
259 ])
260
261 dnl PSI_COMPUTE_STR(variable, string or expression)
262 AC_DEFUN(PSI_COMPUTE_STR, [
263 AC_TRY_RUN(
264 PSI_INCLUDES
265 [int main() {
266 return EOF == fputs($2, fopen("conftest.out", "w"));
267 }
268 ], [
269 eval $1=\\\"`cat conftest.out`\\\"
270 ])
271 ])