d372f5d037b81268d376bb349513176b77f4b9ee
[m6w6/ext-psi] / config.m4
1 PHP_ARG_ENABLE(psi, whether to enable PHP System Interface support,
2 [ --enable-psi Enable PHP System Interface support])
3 PHP_ARG_WITH(psi-libjit, where to find libjit,
4 [ --with-psi-libjit=DIR PSI: path to libjit], [], no)
5 PHP_ARG_WITH(psi-libffi, where to find libjit,
6 [ --with-psi-libffi=DIR PSI: path to libffi], [], no)
7
8 if test "$PHP_PSI" != "no"; then
9 AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
10 AC_PATH_PROG(LEMON, lemon, ./lemon)
11 PHP_SUBST(LEMON)
12
13 if test -z "$PKG_CONFIG"
14 then
15 AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
16 fi
17
18 export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
19
20 AC_CACHE_CHECK(for libffi through pkg-config, PSI_cv_LIBFFI, [
21 if $PKG_CONFIG --exists libffi
22 then
23 PSI_cv_LIBFFI=true
24 else
25 PSI_cv_LIBFFI=false
26 fi])
27 if $PSI_cv_LIBFFI
28 then
29 AC_MSG_CHECKING(for libffi)
30 PSI_cv_LIBFFI_DIR=`$PKG_CONFIG --variable=prefix libffi`
31 AC_MSG_RESULT($PSI_cv_LIBFFI_DIR)
32 PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
33 PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
34 else
35 AC_CACHE_CHECK(for libffi, PSI_cv_LIBFFI_DIR, [
36 for PSI_cv_LIBFFI_DIR in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
37 do
38 if test -e $PSI_cv_LIBFFI_DIR/include/ffi/ffi.h
39 then
40 break
41 fi
42 PSI_cv_LIBFFI_DIR=
43 done])
44 if test -n "$PSI_cv_LIBFFI_DIR"
45 then
46 PHP_ADD_INCLUDE($PSI_cv_LIBFFI_DIR/include/ffi)
47 PHP_ADD_LIBRARY_WITH_PATH(ffi, $PSI_cv_LIBFFI_DIR/$PHP_LIBDIR, PSI_SHARED_LIBADD)
48 else
49 AC_MSG_WARN([Could not find libffi, please provide the base install path])
50 fi
51 fi
52 PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
53 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
54 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
55 ], [], -L$PSI_cv_LIBFFI_DIR/$PHP_LIBDIR)
56 AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
57 ], [
58 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
59 AC_CHECK_HEADERS(sys/mman.h)
60 PHP_CHECK_FUNC(mmap)
61 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
62 ], [
63 ], -L$PSI_cv_LIBFFI_DIR/$PHP_LIBDIR)
64 ], -L$PSI_cv_LIBFFI_DIR/$PHP_LIBDIR)
65
66 AC_CACHE_CHECK(for libjit, PSI_cv_LIBJIT_DIR, [
67 for PSI_cv_LIBJIT_DIR in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
68 do
69 if test -e $PSI_cv_LIBJIT_DIR/include/jit/jit.h
70 then
71 break
72 fi
73 PSI_cv_LIBJIT_DIR=
74 done])
75 if test -n "$PSI_cv_LIBJIT_DIR"
76 then
77 PHP_ADD_INCLUDE($PSI_cv_LIBJIT_DIR/include)
78 PHP_ADD_LIBRARY_WITH_PATH(jit, $PSI_cv_LIBJIT_DIR/$PHP_LIBDIR, PSI_SHARED_LIBADD)
79 else
80 AC_MSG_WARN([Could not find libjit, please provide the base install path])
81 fi
82
83 PHP_SUBST(PSI_SHARED_LIBADD)
84
85 dnl PSI_INCLUDES_DEFAULT(include, defines)
86 AC_DEFUN(PSI_INCLUDES_DEFAULT, [
87 AC_INCLUDES_DEFAULT()
88 $2
89 m4_ifnblank($1,
90 m4_expand([#include <]$1[>])
91 )
92 ])
93
94 psi_type_pair() { # (type, size)
95 local psi_type_lower=`tr A-Z a-z <<<$1`
96 case $psi_type_lower in
97 int*|uint*)
98 local psi_type_upper=`tr a-z A-Z <<<$1`
99 local psi_type_bits=`expr $2 \* 8`
100 echo "PSI_T_${psi_type_upper}${psi_type_bits}, \"${psi_type_lower}${psi_type_bits}_t\""
101 ;;
102 struct*)
103 echo "PSI_T_STRUCT, \"$2\""
104 ;;
105 *)
106 echo "PSI_T_NAME, \"$1\""
107 ;;
108 esac
109 }
110
111 PSI_TYPES=""
112 dnl PSI_TYPE(type name, basic type, includes)
113 AC_DEFUN(PSI_TYPE, [
114 ifdef(AC_TYPE_[]patsubst(translit($1,a-z,A-Z),\W,_),AC_TYPE_[]patsubst(translit($1,a-z,A-Z),\W,_))
115 AC_CHECK_SIZEOF($1, [], PSI_INCLUDES_DEFAULT($3))
116 if test "$2" && test "$ac_cv_sizeof_[]$1" -gt 0; then
117 PSI_TYPES="{`psi_type_pair $2 $ac_cv_sizeof_[]$1`, \""$1"\"}, $PSI_TYPES"
118 fi
119 ])
120
121
122 PSI_CONSTS=""
123 dnl PSI_COMPUTE_STR(variable, string or expression, includes)
124 AC_DEFUN(PSI_COMPUTE_STR, [
125 AC_TRY_RUN([
126 $3
127 int main() {
128 return EOF == fputs($2, fopen("conftest.out", "w"));
129 }
130 ], [
131 eval $1=\\\"`cat conftest.out`\\\"
132 ])
133 ])
134
135 dnl PSI_CONST(const name, type, headers to include)
136 AC_DEFUN(PSI_CONST, [
137 AC_CACHE_CHECK(value of $1, psi_cv_const_$1, [
138 case $2 in
139 str*|quoted_str*)
140 if test "$cross_compiling" = "yes"
141 then
142 AC_TRY_CPP(PSI_INCLUDES_DEFAULT($3)$1, psi_const_val=`eval "$ac_try|tail -n1"`, psi_const_val=)
143 else
144 PSI_COMPUTE_STR(psi_const_val, $1, PSI_INCLUDES_DEFAULT($3))
145 fi
146 ;;
147 *)
148 AC_COMPUTE_INT(psi_const_val, $1, PSI_INCLUDES_DEFAULT($3))
149 ;;
150 esac
151 psi_cv_const_$1=$psi_const_val
152 ])
153 if test "$psi_cv_const_$1"
154 then
155 case $2 in
156 str*|quoted_str*)
157 PSI_CONSTS="{PSI_T_STRING, \"string\", \"$1\", $psi_cv_const_$1, PSI_T_QUOTED_STRING}, $PSI_CONSTS"
158 ;;
159 *)
160 PSI_CONSTS="{PSI_T_INT, \"int\", \"$1\", \"$psi_cv_const_$1\", PSI_T_NUMBER}, $PSI_CONSTS"
161 ;;
162 esac
163 fi
164 ])
165
166 AC_DEFUN([AX_CHECK_SIGN], [
167 typename=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g"`
168 AC_CACHE_CHECK([whether $1 is signed], ax_cv_decl_${typename}_signed, [
169 AC_TRY_COMPILE([$4],
170 [ int foo @<:@ 1 - 2 * !((($1) -1) < 0) @:>@ ],
171 [ eval "ax_cv_decl_${typename}_signed=\"yes\"" ],
172 [ eval "ax_cv_decl_${typename}_signed=\"no\"" ])])
173 symbolname=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g" | tr "a-z" "A-Z"`
174 if eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"yes\""; then
175 $2
176 elif eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"no\""; then
177 $3
178 fi
179 ])
180 dnl PSI_CHECK_OFFSETOF(struct, member, include)
181 dnl[AS_LITERAL_IF([$1], [], [m4_fatal([$0: requires literal arguments])])]dnl
182 dnl[AS_LITERAL_IF([$2], [], [m4_fatal([$0: requires literal arguments])])]dnl
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 [AC_INCLUDES_DEFAULT([$3])],
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 `$1' in `$2', as computed by offsetof.]
195 )
196 ])
197
198 dnl PSI_STRUCT(name, members, member type cases, includes)
199 PSI_STRUCTS=
200 AC_DEFUN(PSI_STRUCT, [
201 psi_struct_members=
202 m4_foreach(member, [$2], [
203 AC_CHECK_MEMBER(struct $1.member, [
204 case member in
205 $3
206 *) psi_member_type=int ;;
207 esac
208 AC_CHECK_SIZEOF(struct_$1[_]member, [], PSI_INCLUDES_DEFAULT($4,
209 [#define struct_$1_]member ((struct $1 *)0)->member
210 ))
211 PSI_CHECK_OFFSETOF(struct $1, member, PSI_INCLUDES_DEFAULT($4))
212 # pointer level
213 psi_struct_member_pl=`echo $psi_member_type | tr -cd '*' | wc -c`
214 # array size
215 psi_struct_member_as=`echo $psi_member_type | $AWK -F'\x5b\x5d\x5b\x5d' 'END {print 0} /\\x5b\x5b\x5b:digit:\x5d\x5d+\\x5d/ {print$[]2; exit}'`
216 if test $psi_struct_member_as -gt 0
217 then
218 psi_struct_member_pl=`expr $psi_struct_member_pl + 1`
219 fi
220 psi_struct_members="{`psi_type_pair $psi_member_type $ac_cv_sizeof_struct_$1[]_[]member`, \"[]member[]\", $ac_cv_offsetof_struct_$1[]_[]member, $ac_cv_sizeof_struct_$1[]_[]member, $psi_struct_member_pl, $psi_struct_member_as}, $psi_struct_members"
221 ], [], PSI_INCLUDES_DEFAULT($4))
222 ])
223 PSI_STRUCTS="{\"$1\", {$psi_struct_members}}, $PSI_STRUCTS"
224 ])
225
226 AC_TYPE_INT8_T
227 AC_CHECK_ALIGNOF(int8_t)
228 AC_TYPE_UINT8_T
229 AC_CHECK_ALIGNOF(uint8_t)
230 AC_TYPE_INT16_T
231 AC_CHECK_ALIGNOF(int16_t)
232 AC_TYPE_UINT16_T
233 AC_CHECK_ALIGNOF(uint16_t)
234 AC_TYPE_INT32_T
235 AC_CHECK_ALIGNOF(int32_t)
236 AC_TYPE_UINT32_T
237 AC_CHECK_ALIGNOF(uint32_t)
238 AC_TYPE_INT64_T
239 AC_CHECK_ALIGNOF(int64_t)
240 AC_TYPE_UINT64_T
241 AC_CHECK_ALIGNOF(uint64_t)
242
243 PSI_TYPE(char, int)
244 PSI_TYPE(short, int)
245 PSI_TYPE(int, int)
246 PSI_TYPE(long, int)
247 PSI_TYPE(float)
248 PSI_TYPE(double)
249 PSI_TYPE(void *)
250
251 dnl stdint.h
252 PSI_TYPE(int_least8_t, int)
253 PSI_TYPE(int_least16_t, int)
254 PSI_TYPE(int_least32_t, int)
255 PSI_TYPE(int_least64_t, int)
256 PSI_TYPE(uint_least8_t, uint)
257 PSI_TYPE(uint_least16_t, uint)
258 PSI_TYPE(uint_least32_t, uint)
259 PSI_TYPE(uint_least64_t, uint)
260 PSI_TYPE(int_fast8_t, int)
261 PSI_TYPE(int_fast16_t, int)
262 PSI_TYPE(int_fast32_t, int)
263 PSI_TYPE(int_fast64_t, int)
264 PSI_TYPE(uint_fast8_t, uint)
265 PSI_TYPE(uint_fast16_t, uint)
266 PSI_TYPE(uint_fast32_t, uint)
267 PSI_TYPE(uint_fast64_t, uint)
268 PSI_TYPE(intptr_t, int)
269 PSI_TYPE(uintptr_t, uint)
270 PSI_TYPE(intmax_t, int)
271 PSI_TYPE(uintmax_t, uint)
272
273 PSI_CONST(INT8_MIN, int)
274 PSI_CONST(INT8_MAX, int)
275 PSI_CONST(UINT8_MAX, int)
276 PSI_CONST(INT16_MIN, int)
277 PSI_CONST(INT16_MAX, int)
278 PSI_CONST(UINT16_MAX, int)
279 PSI_CONST(INT32_MIN, int)
280 PSI_CONST(INT32_MAX, int)
281 PSI_CONST(UINT32_MAX, int)
282 PSI_CONST(INT64_MIN, int)
283 PSI_CONST(INT64_MAX, int)
284 PSI_CONST(UINT64_MAX, int)
285
286 PSI_CONST(INT_LEAST8_MIN, int)
287 PSI_CONST(INT_LEAST8_MAX, int)
288 PSI_CONST(UINT_LEAST8_MAX, int)
289 PSI_CONST(INT_LEAST16_MIN, int)
290 PSI_CONST(INT_LEAST16_MAX, int)
291 PSI_CONST(UINT_LEAST16_MAX, int)
292 PSI_CONST(INT_LEAST32_MIN, int)
293 PSI_CONST(INT_LEAST32_MAX, int)
294 PSI_CONST(UINT_LEAST32_MAX, int)
295 PSI_CONST(INT_LEAST64_MIN, int)
296 PSI_CONST(INT_LEAST64_MAX, int)
297 PSI_CONST(UINT_LEAST64_MAX, int)
298
299 PSI_CONST(INT_FAST8_MIN, int)
300 PSI_CONST(INT_FAST8_MAX, int)
301 PSI_CONST(UINT_FAST8_MAX, int)
302 PSI_CONST(INT_FAST16_MIN, int)
303 PSI_CONST(INT_FAST16_MAX, int)
304 PSI_CONST(UINT_FAST16_MAX, int)
305 PSI_CONST(INT_FAST32_MIN, int)
306 PSI_CONST(INT_FAST32_MAX, int)
307 PSI_CONST(UINT_FAST32_MAX, int)
308 PSI_CONST(INT_FAST64_MIN, int)
309 PSI_CONST(INT_FAST64_MAX, int)
310 PSI_CONST(UINT_FAST64_MAX, int)
311
312 PSI_CONST(INTPTR_MIN, int)
313 PSI_CONST(INTPTR_MAX, int)
314 PSI_CONST(UINTPTR_MAX, int)
315 PSI_CONST(INTMAX_MIN, int)
316 PSI_CONST(INTMAX_MAX, int)
317 PSI_CONST(UINTMAX_MAX, int)
318
319 dnl stddef.h
320 PSI_TYPE(ptrdiff_t, int)
321 PSI_CONST(PTRDIFF_MIN, int)
322 PSI_CONST(PTRDIFF_MAX, int)
323 PSI_TYPE(size_t, uint)
324 PSI_CONST(SIZE_MAX, int)
325 AC_CHECK_TYPE(wchar_t, [
326 AX_CHECK_SIGN(wchar_t, psi_wchar_t=int, psi_wchar_t=uint)
327 PSI_TYPE(wchar_t, $psi_wchar_t)
328 PSI_CONST(WCHAR_MIN, int)
329 PSI_CONST(WCHAR_MAX, int)
330 ])
331
332 dnl stdio.h
333 PSI_CONST(BUFSIZ, int)
334 PSI_CONST(_IOFBF, int)
335 PSI_CONST(_IOLBF, int)
336 PSI_CONST(_IONBF, int)
337 PSI_CONST(SEEK_CUR, int)
338 PSI_CONST(SEEK_END, int)
339 PSI_CONST(SEEK_SET, int)
340 PSI_CONST(FILENAME_MAX, int)
341 PSI_CONST(FOPEN_MAX, int)
342 PSI_CONST(TMP_MAX, int)
343 PSI_CONST(EOF, int)
344 PSI_CONST(P_tmpdir, string)
345 PSI_CONST(L_ctermid, int)
346 PSI_CONST(L_tmpnam, int)
347 dnl stdlib.h
348 PSI_CONST(EXIT_FAILURE, int)
349 PSI_CONST(EXIT_SUCCESS, int)
350 PSI_CONST(RAND_MAX, int)
351 PSI_CONST(MB_CUR_MAX, int)
352 dnl sys/stat.h
353 PSI_STRUCT(stat, [
354 [st_dev],
355 [st_ino],
356 [st_mode],
357 [st_nlink],
358 [st_uid],
359 [st_gid],
360 [st_rdev],
361 [st_size],
362 [st_atim],
363 [st_mtim],
364 [st_ctim],
365 [st_blksize],
366 [st_blocks]], [
367 st_?tim) psi_member_type="struct timespec" ;;
368 ], sys/stat.h)
369 dnl sys/time.h
370 PSI_CONST(ITIMER_REAL, int, sys/time.h)
371 PSI_CONST(ITIMER_VIRTUAL, int, sys/time.h)
372 PSI_CONST(ITIMER_PROF, int, sys/time.h)
373 dnl sys/types.h
374 PSI_TYPE(blkcnt_t, int)
375 PSI_TYPE(blksize_t, int)
376 PSI_TYPE(clock_t, int)
377 PSI_TYPE(clockid_t, int)
378 PSI_TYPE(dev_t, int)
379 PSI_TYPE(fsblkcnt_t, uint)
380 PSI_TYPE(fsfilcnt_t, uint)
381 PSI_TYPE(gid_t, int)
382 PSI_TYPE(id_t, int)
383 PSI_TYPE(ino_t, uint)
384 PSI_TYPE(key_t, int)
385 PSI_TYPE(mode_t, int)
386 PSI_TYPE(nlink_t, int)
387 PSI_TYPE(off_t, int)
388 PSI_TYPE(pid_t, int)
389 PSI_TYPE(ssize_t, int)
390 PSI_TYPE(suseconds_t, int)
391 PSI_TYPE(time_t, int)
392 PSI_TYPE(timer_t, int)
393 PSI_TYPE(uid_t)
394
395 dnl wchar.h
396 AC_CHECK_TYPE(wint_t, [
397 AX_CHECK_SIGN(wint_t, psi_wint_t=int, psi_wint_t=uint)
398 PSI_TYPE(wint_t, $psi_wint_t, wchar.h)
399 PSI_CONST(WINT_MIN, int, wchar.h)
400 PSI_CONST(WINT_MAX, int, wchar.h)
401 PSI_CONST(WEOF, int, wchar.h)
402 ], [], [
403 AC_INCLUDES_DEFAULT()
404 #include <wchar.h>
405 ])
406
407
408 AC_DEFINE_UNQUOTED(PHP_PSI_TYPES, $PSI_TYPES, Predefined types)
409 AC_DEFINE_UNQUOTED(PHP_PSI_CONSTS, $PSI_CONSTS, Predefined constants)
410 AC_DEFINE_UNQUOTED(PHP_PSI_STRUCTS, $PSI_STRUCTS, Predefined structs)
411
412 PHP_PSI_SRCDIR=PHP_EXT_SRCDIR(psi)
413 PHP_PSI_BUILDDIR=PHP_EXT_BUILDDIR(psi)
414
415 PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src)
416 PHP_ADD_BUILD_DIR($PHP_PSI_BUILDDIR/src)
417
418 PHP_PSI_HEADERS=`(cd $PHP_PSI_SRCDIR/src && echo *.h)`
419 PHP_PSI_SOURCES="src/parser_proc.c src/parser.c src/validator.c src/module.c src/context.c"
420 PHP_PSI_SOURCES="$PHP_PSI_SOURCES src/libjit.c src/libffi.c"
421
422 PHP_NEW_EXTENSION(psi, $PHP_PSI_SOURCES, $ext_shared)
423 PHP_INSTALL_HEADERS(ext/psi, php_psi.h $PHP_PSI_HEADERS)
424
425 PHP_SUBST(PHP_PSI_HEADERS)
426 PHP_SUBST(PHP_PSI_SOURCES)
427
428 PHP_SUBST(PHP_PSI_SRCDIR)
429 PHP_SUBST(PHP_PSI_BUILDDIR)
430
431 PHP_ADD_MAKEFILE_FRAGMENT
432 fi