configure improvements
[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_ARPA_NAMESER_H
98 # include <arpa/nameser.h>
99 #endif
100 #ifdef HAVE_NETDB_H
101 # include <netdb.h>
102 #endif
103 #ifdef HAVE_RESOLV_H
104 # include <resolv.h>
105 #endif
106 #ifdef HAVE_SYS_SELECT_H
107 # include <sys/select.h>
108 #endif
109 #ifdef HAVE_SYS_SOCKET_H
110 # include <sys/socket.h>
111 #endif
112 #ifdef HAVE_SYS_TIME_H
113 # include <sys/time.h>
114 #endif
115 #ifdef HAVE_SYS_TIMES_H
116 # include <sys/times.h>
117 #endif
118 #ifdef HAVE_SYS_UIO_H
119 # include <sys/uio.h>
120 #endif
121 #ifdef HAVE_SYS_UTSNAME_H
122 # include <sys/utsname.h>
123 #endif
124 #ifdef HAVE_TIME_H
125 # include <time.h>
126 #endif
127 #ifdef HAVE_SYSLOG_H
128 # include <syslog.h>
129 #endif
130 #ifdef HAVE_WCHAR_H
131 # include <wchar.h>
132 #endif
133 #ifdef HAVE_WCTYPE_H
134 # include <wctype.h>
135 #endif
136 ])
137
138 AC_DEFUN(PSI_LEMON, [
139 AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
140 AC_PATH_PROG(LEMON, lemon, ./lemon)
141 PHP_SUBST(LEMON)
142 ])
143
144 AC_DEFUN([PSI_PKG_CONFIG], [
145 if test -z "$PKG_CONFIG"
146 then
147 AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
148 fi
149 export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
150 ])
151
152 AC_DEFUN(PSI_CHECK_SIZEOF, [
153 AC_CHECK_SIZEOF($1, [], $2)
154 if test "$AS_TR_SH([ac_cv_sizeof_]$1)"; then
155 add_int_const "AS_TR_CPP([SIZEOF_]$1)" "$AS_TR_SH([ac_cv_sizeof_]$1)"
156 fi
157 ])
158
159 AC_DEFUN(PSI_CHECK_OFFSETOF, [
160 _AC_CACHE_CHECK_INT(
161 [offset of $2 in $1],
162 [AS_TR_SH([ac_cv_offsetof_$1_$2])],
163 [(long int) (offsetof ($1, $2))],
164 [PSI_INCLUDES],
165 [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
166 )
167 AC_DEFINE_UNQUOTED(
168 AS_TR_CPP(offsetof_$1_$2),
169 $AS_TR_SH([ac_cv_offsetof_$1_$2]),
170 [The offset of `$2' in `$1', as computed by offsetof.]
171 )
172 ])
173
174 AC_DEFUN(PSI_CHECK_LIBJIT, [
175 PHP_ARG_WITH(psi-libjit, where to find libjit,
176 [ --with-psi-libjit=DIR PSI: path to libjit], [ ], [ ])
177 AC_CACHE_CHECK(for libjit, psi_cv_libjit_dir, [
178 for psi_cv_libjit_dir in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
179 do
180 if test -e $psi_cv_libjit_dir/include/jit/jit.h
181 then
182 break
183 fi
184 psi_cv_libjit_dir=
185 done
186 ])
187 if test -n "$psi_cv_libjit_dir"
188 then
189 PHP_ADD_INCLUDE($psi_cv_libjit_dir/include)
190 PHP_ADD_LIBRARY_WITH_PATH(jit, $psi_cv_libjit_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
191 AC_DEFINE(HAVE_LIBJIT, 1, Have libjit)
192 else
193 AC_MSG_WARN([Could not find libjit, please provide the base install path])
194 fi
195 ])
196
197 PHP_ARG_WITH(psi-libffi, where to find libffi,
198 [ --with-psi-libffi=DIR PSI: path to libffi], [ ], [ ])
199 AC_DEFUN(PSI_CHECK_LIBFFI, [
200 AC_REQUIRE([PSI_PKG_CONFIG])dnl
201
202 AC_CACHE_CHECK(for libffi through pkg-config, psi_cv_libffi, [
203 if $PKG_CONFIG --exists libffi
204 then
205 psi_cv_libffi=true
206 else
207 psi_cv_libffi=false
208 fi])
209 if $psi_cv_libffi
210 then
211 AC_MSG_CHECKING(for libffi)
212 psi_cv_libffi_dir=`$PKG_CONFIG --variable=prefix libffi`
213 AC_MSG_RESULT($psi_cv_libffi_dir)
214 PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
215 PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
216 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
217 else
218 AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
219 for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
220 do
221 if test -e $psi_cv_libffi_dir/include/ffi/ffi.h
222 then
223 break
224 fi
225 psi_cv_libffi_dir=
226 done])
227 if test -n "$psi_cv_libffi_dir"
228 then
229 PHP_ADD_INCLUDE($psi_cv_libffi_dir/include/ffi)
230 PHP_ADD_LIBRARY_WITH_PATH(ffi, $psi_cv_libffi_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
231 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
232 else
233 AC_MSG_WARN([Could not find libffi, please provide the base install path])
234 fi
235 fi
236 PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
237 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
238 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
239 ], [], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
240 AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
241 ], [
242 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
243 AC_CHECK_HEADERS(sys/mman.h)
244 PHP_CHECK_FUNC(mmap)
245 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
246 ], [
247 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
248 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
249 PHP_CHECK_LIBRARY(ffi, ffi_prep_cif_var, [
250 AC_DEFINE(PSI_HAVE_FFI_PREP_CIF_VAR, 1, [ ])
251 ], [
252 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
253 ])
254
255 dnl PSI_COMPUTE_STR(variable, string or expression)
256 AC_DEFUN(PSI_COMPUTE_STR, [
257 AC_TRY_RUN(
258 PSI_INCLUDES
259 [int main() {
260 return EOF == fputs($2, fopen("conftest.out", "w"));
261 }
262 ], [
263 eval $1=\\\"`cat conftest.out`\\\"
264 ])
265 ])