xref: /PHP-8.0/scripts/phpize.m4 (revision a6daded1)
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
173PHP_SUBST(PHP_MODULES)
174PHP_SUBST(PHP_ZEND_EX)
175
176PHP_SUBST(all_targets)
177PHP_SUBST(install_targets)
178
179PHP_SUBST(prefix)
180PHP_SUBST(exec_prefix)
181PHP_SUBST(libdir)
182PHP_SUBST(prefix)
183PHP_SUBST(phplibdir)
184PHP_SUBST(phpincludedir)
185
186PHP_SUBST(CC)
187PHP_SUBST(CFLAGS)
188PHP_SUBST(CFLAGS_CLEAN)
189PHP_SUBST(CPP)
190PHP_SUBST(CPPFLAGS)
191PHP_SUBST(CXX)
192PHP_SUBST(CXXFLAGS)
193PHP_SUBST(CXXFLAGS_CLEAN)
194PHP_SUBST(EXTENSION_DIR)
195PHP_SUBST(PHP_EXECUTABLE)
196PHP_SUBST(EXTRA_LDFLAGS)
197PHP_SUBST(EXTRA_LIBS)
198PHP_SUBST(INCLUDES)
199PHP_SUBST(LFLAGS)
200PHP_SUBST(LDFLAGS)
201PHP_SUBST(SHARED_LIBTOOL)
202PHP_SUBST(LIBTOOL)
203PHP_SUBST(SHELL)
204PHP_SUBST(INSTALL_HEADERS)
205
206PHP_GEN_BUILD_DIRS
207PHP_GEN_GLOBAL_MAKEFILE
208
209test -d modules || $php_shtool mkdir modules
210
211AC_CONFIG_HEADERS([config.h])
212
213AC_CONFIG_COMMANDS_PRE([PHP_PATCH_CONFIG_HEADERS([config.h.in])])
214
215AC_OUTPUT
216