xref: /PHP-8.1/scripts/phpize.m4 (revision c2922658)
1dnl This file becomes configure.ac for self-contained extensions.
2
3dnl Include external macro definitions before the AC_INIT to also remove
4dnl comments starting with # and empty newlines from the included files.
5m4_include([build/ax_check_compile_flag.m4])
6m4_include([build/ax_gcc_func_attribute.m4])
7m4_include([build/libtool.m4])
8m4_include([build/php_cxx_compile_stdcxx.m4])
9m4_include([build/php.m4])
10m4_include([build/pkg.m4])
11
12AC_PREREQ([2.68])
13AC_INIT
14AC_CONFIG_SRCDIR([config.m4])
15AC_CONFIG_AUX_DIR([build])
16AC_PRESERVE_HELP_ORDER
17
18PHP_CONFIG_NICE(config.nice)
19
20AC_DEFUN([PHP_EXT_BUILDDIR],[.])dnl
21AC_DEFUN([PHP_EXT_DIR],[""])dnl
22AC_DEFUN([PHP_EXT_SRCDIR],[$abs_srcdir])dnl
23AC_DEFUN([PHP_ALWAYS_SHARED],[
24  ext_output="yes, shared"
25  ext_shared=yes
26  test "[$]$1" = "no" && $1=yes
27])dnl
28
29test -z "$CFLAGS" && auto_cflags=1
30
31abs_srcdir=`(cd $srcdir && pwd)`
32abs_builddir=`pwd`
33
34PKG_PROG_PKG_CONFIG
35AC_PROG_CC([cc gcc])
36PHP_DETECT_ICC
37PHP_DETECT_SUNCC
38
39dnl Support systems with system libraries in e.g. /usr/lib64.
40PHP_ARG_WITH([libdir],
41  [for system library directory],
42  [AS_HELP_STRING([--with-libdir=NAME],
43    [Look for libraries in .../NAME rather than .../lib])],
44  [lib],
45  [no])
46
47PHP_RUNPATH_SWITCH
48PHP_SHLIB_SUFFIX_NAMES
49
50dnl Find php-config script.
51PHP_ARG_WITH([php-config],,
52  [AS_HELP_STRING([--with-php-config=PATH],
53    [Path to php-config [php-config]])],
54  [php-config],
55  [no])
56
57dnl For BC.
58PHP_CONFIG=$PHP_PHP_CONFIG
59prefix=`$PHP_CONFIG --prefix 2>/dev/null`
60phpincludedir=`$PHP_CONFIG --include-dir 2>/dev/null`
61INCLUDES=`$PHP_CONFIG --includes 2>/dev/null`
62EXTENSION_DIR=`$PHP_CONFIG --extension-dir 2>/dev/null`
63PHP_EXECUTABLE=`$PHP_CONFIG --php-binary 2>/dev/null`
64
65if test -z "$prefix"; then
66  AC_MSG_ERROR([Cannot find php-config. Please use --with-php-config=PATH])
67fi
68
69php_shtool=$srcdir/build/shtool
70PHP_INIT_BUILD_SYSTEM
71
72AC_MSG_CHECKING([for PHP prefix])
73AC_MSG_RESULT([$prefix])
74AC_MSG_CHECKING([for PHP includes])
75AC_MSG_RESULT([$INCLUDES])
76AC_MSG_CHECKING([for PHP extension directory])
77AC_MSG_RESULT([$EXTENSION_DIR])
78AC_MSG_CHECKING([for PHP installed headers prefix])
79AC_MSG_RESULT([$phpincludedir])
80
81dnl Checks for PHP_DEBUG / ZEND_DEBUG / ZTS.
82AC_MSG_CHECKING([if debug is enabled])
83old_CPPFLAGS=$CPPFLAGS
84CPPFLAGS="-I$phpincludedir"
85AC_EGREP_CPP(php_debug_is_enabled,[
86#include <main/php_config.h>
87#if ZEND_DEBUG
88php_debug_is_enabled
89#endif
90],[
91  PHP_DEBUG=yes
92],[
93  PHP_DEBUG=no
94])
95CPPFLAGS=$old_CPPFLAGS
96AC_MSG_RESULT([$PHP_DEBUG])
97
98AC_MSG_CHECKING([if zts is enabled])
99old_CPPFLAGS=$CPPFLAGS
100CPPFLAGS="-I$phpincludedir"
101AC_EGREP_CPP(php_zts_is_enabled,[
102#include <main/php_config.h>
103#if ZTS
104php_zts_is_enabled
105#endif
106],[
107  PHP_THREAD_SAFETY=yes
108],[
109  PHP_THREAD_SAFETY=no
110])
111CPPFLAGS=$old_CPPFLAGS
112AC_MSG_RESULT([$PHP_THREAD_SAFETY])
113
114dnl Discard optimization flags when debugging is enabled.
115if test "$PHP_DEBUG" = "yes"; then
116  PHP_DEBUG=1
117  ZEND_DEBUG=yes
118  changequote({,})
119  CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9s]*//g'`
120  CXXFLAGS=`echo "$CXXFLAGS" | $SED -e 's/-O[0-9s]*//g'`
121  changequote([,])
122  dnl Add -O0 only if GCC or ICC is used.
123  if test "$GCC" = "yes" || test "$ICC" = "yes"; then
124    CFLAGS="$CFLAGS -O0"
125    CXXFLAGS="$CXXFLAGS -g -O0"
126  fi
127  if test "$SUNCC" = "yes"; then
128    if test -n "$auto_cflags"; then
129      CFLAGS="-g"
130      CXXFLAGS="-g"
131    else
132      CFLAGS="$CFLAGS -g"
133      CXXFLAGS="$CFLAGS -g"
134    fi
135  fi
136else
137  PHP_DEBUG=0
138  ZEND_DEBUG=no
139fi
140
141dnl Always shared.
142PHP_BUILD_SHARED
143
144dnl Required programs.
145PHP_PROG_AWK
146
147sinclude(config.m4)
148
149enable_static=no
150enable_shared=yes
151
152dnl Only allow AC_PROG_CXX and AC_PROG_CXXCPP if they are explicitly called (by
153dnl PHP_REQUIRE_CXX). Otherwise AC_PROG_LIBTOOL fails if there is no working C++
154dnl compiler.
155AC_PROVIDE_IFELSE([PHP_REQUIRE_CXX], [], [
156  undefine([AC_PROG_CXX])
157  AC_DEFUN([AC_PROG_CXX], [])
158  undefine([AC_PROG_CXXCPP])
159  AC_DEFUN([AC_PROG_CXXCPP], [php_prog_cxxcpp=disabled])
160])
161AC_PROG_LIBTOOL
162
163all_targets='$(PHP_MODULES) $(PHP_ZEND_EX)'
164install_targets="install-modules install-headers"
165phplibdir="`pwd`/modules"
166CPPFLAGS="$CPPFLAGS -DHAVE_CONFIG_H"
167CFLAGS_CLEAN='$(CFLAGS)'
168CXXFLAGS_CLEAN='$(CXXFLAGS)'
169
170test "$prefix" = "NONE" && prefix="/usr/local"
171test "$exec_prefix" = "NONE" && exec_prefix='$(prefix)'
172
173if test "$cross_compiling" = yes ; then
174  AC_MSG_CHECKING(for native build C compiler)
175  AC_CHECK_PROGS(BUILD_CC, [gcc clang c99 c89 cc cl],none)
176  AC_MSG_RESULT($BUILD_CC)
177else
178  BUILD_CC=$CC
179fi
180
181PHP_SUBST(PHP_MODULES)
182PHP_SUBST(PHP_ZEND_EX)
183
184PHP_SUBST(all_targets)
185PHP_SUBST(install_targets)
186
187PHP_SUBST(prefix)
188PHP_SUBST(exec_prefix)
189PHP_SUBST(libdir)
190PHP_SUBST(prefix)
191PHP_SUBST(phplibdir)
192PHP_SUBST(phpincludedir)
193
194PHP_SUBST(CC)
195PHP_SUBST(CFLAGS)
196PHP_SUBST(CFLAGS_CLEAN)
197PHP_SUBST(CPP)
198PHP_SUBST(CPPFLAGS)
199PHP_SUBST(CXX)
200PHP_SUBST(CXXFLAGS)
201PHP_SUBST(CXXFLAGS_CLEAN)
202PHP_SUBST(EXTENSION_DIR)
203PHP_SUBST(PHP_EXECUTABLE)
204PHP_SUBST(EXTRA_LDFLAGS)
205PHP_SUBST(EXTRA_LIBS)
206PHP_SUBST(INCLUDES)
207PHP_SUBST(LFLAGS)
208PHP_SUBST(LDFLAGS)
209PHP_SUBST(SHARED_LIBTOOL)
210PHP_SUBST(LIBTOOL)
211PHP_SUBST(SHELL)
212PHP_SUBST(INSTALL_HEADERS)
213PHP_SUBST(BUILD_CC)
214
215PHP_GEN_BUILD_DIRS
216PHP_GEN_GLOBAL_MAKEFILE
217
218test -d modules || $php_shtool mkdir modules
219
220AC_CONFIG_HEADERS([config.h])
221
222AC_CONFIG_COMMANDS_PRE([PHP_PATCH_CONFIG_HEADERS([config.h.in])])
223
224AC_OUTPUT
225