c534ed4a850820593e77d08556f45953cbdc8516
[m6w6/ext-psi] / m4 / psi / psi.m4
1 dnl PSI_CONFIG_INIT()
2 dnl Creates stubs of the headers with pre-defined types etc.
3 AC_DEFUN(PSI_CONFIG_INIT, [
4 psi_save_LIBS=$LIBS
5 LIBS=
6
7 ac_includes_default="AC_INCLUDES_DEFAULT"
8
9 AC_MSG_CHECKING([psi source dir])
10 PHP_PSI_SRCDIR=PHP_EXT_SRCDIR(psi)
11 AC_MSG_RESULT([$PHP_PSI_SRCDIR])
12
13 AC_MSG_CHECKING([psi build dir])
14 case "PHP_EXT_BUILDDIR(psi)" in
15 ""|.) PHP_PSI_BUILDDIR=$PHP_PSI_SRCDIR
16 ;;
17 *) PHP_PSI_BUILDDIR=PHP_EXT_BUILDDIR(psi)
18 ;;
19 esac
20 AC_MSG_RESULT([$PHP_PSI_BUILDDIR])
21
22 PSI_STDTYPES=
23 PSI_CONSTS=
24
25 AC_CONFIG_FILES(
26 [$PHP_PSI_BUILDDIR/php_psi_stdinc.h:$PHP_PSI_SRCDIR/php_psi_stdinc.h.in]
27 [$PHP_PSI_BUILDDIR/php_psi_posix.h:$PHP_PSI_SRCDIR/php_psi_posix.h.in]
28 [$PHP_PSI_BUILDDIR/php_psi_cpp.h:$PHP_PSI_SRCDIR/php_psi_cpp.h.in]
29 )
30
31 ])
32
33 dnl PSI_CONFIG_DONE()
34 dnl Finish the headers with the pre-defined types etc.
35 AC_DEFUN(PSI_CONFIG_DONE, [
36 psi_eval_LIBS=$LIBS
37 LIBS=$psi_save_LIBS
38 PHP_EVAL_LIBLINE($psi_eval_LIBS, PSI_SHARED_LIBADD)
39
40 [PSI_INCLUDES]="PSI_INCLUDES"
41 AC_SUBST([PSI_INCLUDES])
42 AC_SUBST([PSI_STDTYPES])
43 AC_SUBST([PSI_CONSTS])
44 AC_SUBST([PSI_CPP_SEARCH])
45 AC_SUBST([PSI_CPP_PREDEF])
46
47 PHP_ADD_INCLUDE($PHP_PSI_SRCDIR)
48 PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src)
49 PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src/calc)
50 PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src/types)
51 PHP_ADD_INCLUDE($PHP_PSI_BUILDDIR)
52 PHP_ADD_BUILD_DIR($PHP_PSI_BUILDDIR/src)
53 PHP_ADD_BUILD_DIR($PHP_PSI_BUILDDIR/src/types)
54
55 PHP_PSI_HEADERS=" \
56 src/calc/basic.h src/calc/bin.h src/calc/bool.h src/calc/cast.h \
57 src/calc/unary.h src/calc/cmp.h src/calc/oper.h \
58 `(cd $PHP_PSI_SRCDIR/src && ls *.h types/*.h)` \
59 "
60 # parser_* should come first
61 PHP_PSI_SOURCES=" \
62 src/parser_proc.c src/parser_scan.c \
63 `(cd $PHP_PSI_SRCDIR && ls src/*.c src/types/*.c \
64 | $EGREP -v '^src/parser_' \
65 )` \
66 "
67 PHP_PSI_GENERATED=" \
68 src/parser_proc.c src/parser_scan.c \
69 src/calc/basic.h src/calc/bin.h src/calc/bool.h src/calc/cast.h \
70 src/calc/unary.h src/calc/cmp.h src/calc/oper.h \
71 "
72
73 PHP_SUBST(PHP_PSI_GENERATED)
74 PHP_SUBST(PHP_PSI_HEADERS)
75 PHP_SUBST(PHP_PSI_SOURCES)
76
77 PHP_SUBST(PHP_PSI_SRCDIR)
78 PHP_SUBST(PHP_PSI_BUILDDIR)
79 ])
80
81 dnl PSI_CHECK_GNU_SOURCE
82 dnl Check whether _GNU_SOURCE is already defined.
83 AC_DEFUN([PSI_CHECK_GNU_SOURCE], [
84 AC_MSG_CHECKING([for _GNU_SOURCE])
85 AC_EGREP_CPP([gnu_source_not_defined], [
86 #ifndef _GNU_SOURCE
87 gnu_source_not_defined
88 #endif
89 ], [
90 AC_MSG_RESULT([needs define])
91 AC_DEFINE([_GNU_SOURCE], [1], [ ])
92 ], [
93 AC_MSG_RESULT([already defined])
94 ])
95 ])
96
97 dnl PSI_CHECK_CPP
98 dnl Queries the preprocessor about predefined macros and include search paths
99 AC_DEFUN([PSI_CHECK_CPP], [
100 AC_PROG_AWK
101
102 AC_MSG_CHECKING(for preprocessor defaults)
103 psi_cpp_predef=`$CPP -Wp,-dM $CPPFLAGS -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -U__BLOCKS__ - </dev/null`
104 psi_cpp_search=`$CPP -Wp,-v $CPPFLAGS -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 - </dev/null 2>&1 >/dev/null \
105 | $AWK '
106 /include.*search.*start/ {
107 capture = 1
108 next
109 }
110 /@<:@Ee@:>@nd.*search/ {
111 capture = 0
112 }
113 {
114 if (capture)
115 print $1
116 }
117 ' \
118 `
119 psi_cpp_predef_count=`printf %s "$psi_cpp_predef" | wc -l`
120 psi_cpp_search_count=`printf %s "$psi_cpp_search" | wc -l`
121
122 AC_MSG_RESULT([$psi_cpp_predef_count predefined macros, and $psi_cpp_search_count search paths])
123
124 PSI_CPP_PREDEF=`printf "%s\n" "$psi_cpp_predef" | \
125 $AWK '{
126 gsub(/"/, "\\\\\"");
127 printf "\"%s\\\n\"\n", $[]0
128 }' \
129 `
130 PSI_CPP_SEARCH=`printf %s "$psi_cpp_search" | \
131 $AWK '
132 {
133 if (i) printf "\":\" ";
134 else printf " ";
135 gsub(/^@<:@@<:@:space:@:>@@:>@+/,"");
136 gsub(/@<:@@<:@:space:@:>@@:>@+$/,"");
137 printf "\"%s\"\n", $[]0;
138 ++i
139 }' \
140 `
141 ])
142
143 dnl PSI_CHECK_MAINTAINER_MODE
144 dnl Check for --enable-psi-maintainer-mode
145 dnl Enables Makefile dependencies and extra compile warnings
146 AC_DEFUN([PSI_CHECK_MAINTAINER_MODE], [
147 if test "$PHP_PSI_MAINTAINER_MODE" = "yes"; then
148 PSI_DEPS=true
149 PHP_SUBST(PSI_DEPS)
150 CFLAGS="$CFLAGS -Wall -Wextra"
151 else
152 PSI_DEPS=false
153 fi
154 ])
155
156 dnl PSI_CHECK_THREADED_PARSER
157 dnl Check for --enable-psi-threaded-parser
158 dnl Enables threaded parser if HAVE_PTHREAD && HAVE_ASPRINTF
159 AC_DEFUN([PSI_CHECK_THREADED_PARSER], [
160 if test "$PHP_PSI_THREADED_PARSER" = "yes"; then
161 AC_DEFINE([PSI_THREADED_PARSER], [HAVE_PTHREAD && HAVE_ASPRINTF],
162 [whether to enable the threaded parser])
163 fi
164 ])
165
166 AC_DEFUN(PSI_PTHREAD_ONCE, [
167 AX_PTHREAD([
168 LIBS="$PTHREAD_LIBS $LIBS"
169 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
170 AC_DEFINE([HAVE_PTHREAD],[1],
171 [Define if you have POSIX threads libraries and header files.])
172 ])
173 ])
174 AC_DEFUN(PSI_CHECK_PTHREAD, [
175 AC_REQUIRE([PSI_PTHREAD_ONCE])
176 ])
177
178 dnl PSI_INCLUDES()
179 dnl Expands to a complete list of include statements including
180 dnl autoconf defaults.
181 AC_DEFUN(PSI_INCLUDES, [
182 #ifndef _GNU_SOURCE
183 # define _GNU_SOURCE
184 #endif
185 #ifndef _REENTRANT
186 # define _REENTRANT
187 #endif
188 $ac_includes_default
189 #ifdef HAVE_STDBOOL_H
190 # include <stdbool.h>
191 #else
192 # ifndef HAVE__BOOL
193 # ifdef __cplusplus
194 typedef bool _Bool;
195 # else
196 # define _Bool signed char
197 # endif
198 # endif
199 # define bool _Bool
200 # define false 0
201 # define true 1
202 # define __bool_true_false_are_defined 1
203 #endif
204 #ifdef HAVE_ERRNO_H
205 # include <errno.h>
206 #endif
207 #ifdef HAVE_GLOB_H
208 # include <glob.h>
209 #endif
210 #ifdef HAVE_LOCALE_H
211 # include <locale.h>
212 #endif
213 #ifdef HAVE_XLOCALE_H
214 # include <xlocale.h>
215 #endif
216 #ifdef HAVE_NETINET_IN_H
217 # include <netinet/in.h>
218 #endif
219 #ifdef HAVE_NETINET_TCP_H
220 # include <netinet/tcp.h>
221 #endif
222 #ifdef HAVE_ARPA_NAMESER_H
223 # include <arpa/nameser.h>
224 #endif
225 #ifdef HAVE_ARPA_INET_H
226 # include <arpa/inet.h>
227 #endif
228 #ifdef HAVE_FCNTL_H
229 # include <fcntl.h>
230 #endif
231 #ifdef HAVE_RELIC_H
232 # include <relic.h>
233 #elif HAVE_NDBM_H
234 # include <ndbm.h>
235 #elif HAVE_GDBM_NDBM_H
236 # include <gdbm-ndbm.h>
237 #endif
238 #ifdef HAVE_NETDB_H
239 # include <netdb.h>
240 #endif
241 #ifdef HAVE_POLL_H
242 # include <poll.h>
243 #endif
244 #ifdef HAVE_RESOLV_H
245 # include <resolv.h>
246 #endif
247 #ifdef HAVE_SYS_SELECT_H
248 # include <sys/select.h>
249 #endif
250 #ifdef HAVE_SYS_SOCKET_H
251 # include <sys/socket.h>
252 #endif
253 #ifdef HAVE_SYS_TIME_H
254 # include <sys/time.h>
255 #endif
256 #ifdef HAVE_SYS_TIMES_H
257 # include <sys/times.h>
258 #endif
259 #ifdef HAVE_SYS_UIO_H
260 # include <sys/uio.h>
261 #endif
262 #ifdef HAVE_SYS_UTSNAME_H
263 # include <sys/utsname.h>
264 #endif
265 #ifdef HAVE_TIME_H
266 # include <time.h>
267 #endif
268 #ifdef HAVE_SIGNAL_H
269 # include <signal.h>
270 #endif
271 #ifdef HAVE_SYSLOG_H
272 # include <syslog.h>
273 #endif
274 #ifdef HAVE_WCHAR_H
275 # include <wchar.h>
276 #endif
277 #ifdef HAVE_WCTYPE_H
278 # include <wctype.h>
279 #endif
280 ])
281
282 dnl PSI_PKG_CONFIG()
283 dnl Check for `pkg-config` and add possible libjit and libffi directories to
284 dnl $PKG_CONFIG_PATH, because those libs often ship with headers etc. in
285 dnl arch-dependent locations.
286 AC_DEFUN([PSI_PKG_CONFIG], [
287 if test -z "$PKG_CONFIG"
288 then
289 AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
290 fi
291 export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
292 ])
293
294 dnl PSI_SH_SIZEOF(type)
295 dnl expand to shell variable $ac_cv_sizeof_<TYPE>
296 AC_DEFUN([PSI_SH_SIZEOF], [$AS_TR_SH([ac_cv_sizeof_]$1)])
297
298 dnl PSI_SH_TEST_SIZEOF(type)
299 dnl `if` condition to test if $ac_cv_sizeof_$1 is greater than 0.
300 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])
301
302 dnl PSI_CHECK_SIZEOF(type, special-includes)
303 dnl AC_CHECK_SIZEOF wrapper with PSI_INCLUDES
304 dnl Defines psi\\SIZEOF_<TYPE> pre-defined constant in $PSI_CONSTS_H.
305 AC_DEFUN(PSI_CHECK_SIZEOF, [
306 AC_CHECK_SIZEOF($1, [], PSI_INCLUDES
307 $2)
308 if PSI_SH_TEST_SIZEOF($1); then
309 psi_add_int_const "AS_TR_CPP([SIZEOF_]$1)" "$AS_TR_SH([ac_cv_sizeof_]$1)"
310 fi
311 ])
312
313 dnl PSI_CHECK_LIBJIT()
314 dnl Check for libjit in $PHP_PSI_LIBJIT or standard locations
315 dnl AC_DEFINEs HAVE_LIBJIT.
316 AC_DEFUN(PSI_CHECK_LIBJIT, [
317 AC_CACHE_CHECK(for libjit, psi_cv_libjit_dir, [
318 for psi_cv_libjit_dir in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
319 do
320 if test -e $psi_cv_libjit_dir/include/jit/jit.h
321 then
322 break
323 fi
324 psi_cv_libjit_dir=
325 done
326 ])
327 if test -n "$psi_cv_libjit_dir"
328 then
329 PHP_ADD_INCLUDE($psi_cv_libjit_dir/include)
330 PHP_ADD_LIBRARY_WITH_PATH(jit, $psi_cv_libjit_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
331 AC_DEFINE(HAVE_LIBJIT, 1, Have libjit)
332 else
333 AC_MSG_WARN([Could not find libjit, please provide the base install path])
334 fi
335 ])
336
337 dnl PSI_CHECK_LIBFFI()
338 dnl Check for libffi with `pkg-config`. If that fails, `configure` looks into
339 dnl $PHP_PSI_LIBFFI or standard locations to find libjit deps.
340 dnl Checks for availability of recent closure API:
341 dnl \ffi_closure_alloc and \ffi_prep_closure.
342 dnl Checks for availability of recent vararg API:
343 dnl \ffi_prep_cif_var.
344 dnl AC_DEFINEs HAVE_LIBFFI, PSI_HAVE_FFI_CLOSURE_ALLOC,
345 dnl PSI_HAVE_FFI_PREP_CLOSURE and PSI_HAVE_FFO_PREP_VIF_VAR.
346 AC_DEFUN(PSI_CHECK_LIBFFI, [
347 AC_REQUIRE([PSI_PKG_CONFIG])dnl
348
349 AC_CACHE_CHECK(for libffi through pkg-config, psi_cv_libffi, [
350 if $PKG_CONFIG --exists libffi
351 then
352 psi_cv_libffi=true
353 else
354 psi_cv_libffi=false
355 fi])
356
357 if $psi_cv_libffi
358 then
359 AC_MSG_CHECKING(for libffi)
360 psi_cv_libffi_dir=`$PKG_CONFIG --variable=prefix libffi`
361 AC_MSG_RESULT($psi_cv_libffi_dir)
362 PHP_EVAL_INCLINE([`$PKG_CONFIG --cflags libffi`])
363 PHP_EVAL_LIBLINE([`$PKG_CONFIG --libs libffi`], PSI_SHARED_LIBADD) dnl `
364 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
365 AC_DEFINE_UNQUOTED([PHP_PSI_LIBFFI_VERSION], ["`$PKG_CONFIG --modversion libffi`"], [libffi version])
366 else
367 AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
368 for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
369 do
370 if test -e $psi_cv_libffi_dir/include/ffi/ffi.h
371 then
372 break
373 fi
374 psi_cv_libffi_dir=
375 done])
376 if test -n "$psi_cv_libffi_dir"
377 then
378 PHP_ADD_INCLUDE($psi_cv_libffi_dir/include/ffi)
379 PHP_ADD_LIBRARY_WITH_PATH(ffi, $psi_cv_libffi_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
380 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
381 else
382 AC_MSG_WARN([Could not find libffi, please provide the base install path])
383 fi
384 fi
385
386 save_CFLAGS=$CFLAGS
387 CFLAGS="$CFLAGS $INCLUDES"
388 AC_CHECK_DECL(FFI_STDCALL,[AC_DEFINE([HAVE_FFI_STDCALL],[1],[ ])],,[#include "ffi.h"])
389 AC_CHECK_DECL(FFI_FASTCALL,[AC_DEFINE([HAVE_FFI_FASTCALL],[1],[ ])],,[#include "ffi.h"])
390 CFLAGS=$save_CFLAGS
391
392 PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
393 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
394 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
395 ], [], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
396 AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
397 ], [
398 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
399 AC_CHECK_HEADERS(sys/mman.h)
400 PHP_CHECK_FUNC(mmap)
401 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
402 ], [
403 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
404 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
405 PHP_CHECK_LIBRARY(ffi, ffi_prep_cif_var, [
406 AC_DEFINE(PSI_HAVE_FFI_PREP_CIF_VAR, 1, [ ])
407 ], [
408 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
409 ])