1dnl +----------------------------------------------------------------------+
2dnl | PHP Version 8                                                        |
3dnl +----------------------------------------------------------------------+
4dnl | Copyrght (C) 1997-2021 The PHP Group                                 |
5dnl +----------------------------------------------------------------------+
6dnl | This source file is subject to version 3.01 of the PHP license,      |
7dnl | that is bundled with this package in the file LICENSE, and is        |
8dnl | available through the world-wide-web at the following url:           |
9dnl | http://www.php.net/license/3_01.txt                                  |
10dnl | If you did not receive a copy of the PHP license and are unable to   |
11dnl | obtain it through the world-wide-web, please send a note to          |
12dnl | license@php.net so we can mail you a copy immediately.               |
13dnl +----------------------------------------------------------------------+
14dnl | Author: Ruslan Osmanov <osmanov@php.net>                             |
15dnl +----------------------------------------------------------------------+
16
17PHP_ARG_ENABLE(ev, whether to enable ev,
18[  --enable-ev         Enable ev support], no)
19
20PHP_ARG_ENABLE(ev-debug, for ev debug support,
21[  --enable-ev-debug       Enable ev debug support], no, no)
22
23if test "$PHP_EV" != "no"; then
24  AC_MSG_CHECKING(whether Ev supports the current PHP version)
25  tmp_php_version=$PHP_VERSION
26  if test -z "$tmp_php_version"; then
27    if test -z "$PHP_CONFIG"; then
28      AC_MSG_ERROR([php-config not found])
29    fi
30    PHP_EV_VERSION_ORIG=`$PHP_CONFIG --version`;
31  else
32    PHP_EV_VERSION_ORIG=$tmp_php_version
33  fi
34
35  if test -z $PHP_EV_VERSION_ORIG; then
36    AC_MSG_ERROR([failed to detect PHP version, please file a bug])
37  fi
38
39  PHP_EV_VERSION_MASK=`echo ${PHP_EV_VERSION_ORIG} | $AWK 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
40  if test $PHP_EV_VERSION_MASK -lt 5004000; then
41    AC_MSG_ERROR([need at least PHP 5.4.0])
42  else
43    AC_MSG_RESULT([ok])
44  fi
45
46  AC_MSG_CHECKING(PHP version)
47  if test -d $abs_srcdir/php7; then
48    dnl # only for PECL, not for PHP
49    export OLD_CPPFLAGS="$CPPFLAGS"
50    export CPPFLAGS="$CPPFLAGS $INCLUDES"
51    AC_TRY_COMPILE([#include <php_version.h>], [
52      #if PHP_MAJOR_VERSION > 5
53      # error PHP > 5
54      #endif
55    ], [
56      subdir=php5
57      AC_MSG_RESULT([PHP 5.x])
58    ], [
59      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <php_version.h>]], [[
60      #if PHP_MAJOR_VERSION > 7
61      # error PHP > 7
62      #endif
63      ]])],[
64        subdir=php7
65        AC_MSG_RESULT([PHP 7.x])
66      ],[
67        subdir=php8
68        AC_MSG_RESULT([PHP 8.x])
69      ])
70    ])
71    export CPPFLAGS="$OLD_CPPFLAGS"
72    if test "$subdir" = "php8"; then
73      PHP_EV_SOURCES="$subdir/evwrap.c $subdir/util.c $subdir/ev.c $subdir/watcher.c $subdir/pe.c"
74    else
75      PHP_EV_SOURCES="$subdir/evwrap.c $subdir/util.c $subdir/ev.c $subdir/watcher.c $subdir/fe.c $subdir/pe.c"
76    fi
77  else
78    AC_MSG_ERROR([unknown])
79  fi
80
81  AC_DEFINE(HAVE_EV, 1, [ ])
82
83  if test "$PHP_EV_DEBUG" != "no"; then
84    PHP_EV_CFLAGS="$PHP_EV_CFLAGS -Wall -g -ggdb -O0"
85    AC_DEFINE(PHP_EV_DEBUG, 1, [Enable ev debug support])
86  else
87    AC_DEFINE(NDEBUG, 1, [With NDEBUG defined assert generates no code])
88  fi
89
90  PHP_ADD_EXTENSION_DEP(ev, sockets, true)
91
92  if test "$ext_shared" != "yes" && test "$ext_shared" != "shared"; then
93    PHP_EV_CONFIG_H='\"main/php_config.h\"'
94    AC_DEFINE(EV_CONFIG_H, "main/php_config.h", [Overide config.h included in libev/ev.c])
95    PHP_EV_CFLAGS="$PHP_EV_CFLAGS -DEV_CONFIG_H="$PHP_EV_CONFIG_H
96    define('PHP_EV_STATIC', 1)
97  fi
98
99  m4_include(ifdef('PHP_EV_STATIC',PHP_EXT_BUILDDIR(ev)[/],)[libev/libev.m4])
100
101  PHP_EV_CFLAGS="-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I@ext_srcdir@/libev $PHP_EV_CFLAGS"
102
103  PHP_NEW_EXTENSION(ev, $PHP_EV_SOURCES, $ext_shared, cli, $PHP_EV_CFLAGS)
104
105  PHP_ADD_BUILD_DIR($ext_builddir/libev)
106
107  if test -n "$subdir"; then
108    PHP_ADD_BUILD_DIR($abs_builddir/$subdir, 1)
109    PHP_ADD_INCLUDE([$ext_srcdir/$subdir])
110  fi
111
112  PHP_ADD_MAKEFILE_FRAGMENT
113fi
114
115dnl vim: ft=m4.sh fdm=marker cms=dnl\ %s
116dnl vim: et ts=2 sts=2 sw=2
117