xref: /php-src/scripts/phpize.m4 (revision 182fee14)
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  dnl Discard known '-O...' flags, including just '-O', but do not remove only '-O' in '-Ounknown'
120  CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O\([0-9gsz]\|fast\|\)\([\t ]\|$\)//g'`
121  CXXFLAGS=`echo "$CXXFLAGS" | $SED -e 's/-O\([0-9gsz]\|fast\|\)\([\t ]\|$\)//g'`
122  changequote([,])
123  dnl Add -O0 only if GCC or ICC is used.
124  if test "$GCC" = "yes" || test "$ICC" = "yes"; then
125    CFLAGS="$CFLAGS -O0"
126    CXXFLAGS="$CXXFLAGS -g -O0"
127  fi
128  if test "$SUNCC" = "yes"; then
129    if test -n "$auto_cflags"; then
130      CFLAGS="-g"
131      CXXFLAGS="-g"
132    else
133      CFLAGS="$CFLAGS -g"
134      CXXFLAGS="$CFLAGS -g"
135    fi
136  fi
137else
138  PHP_DEBUG=0
139  ZEND_DEBUG=no
140fi
141
142dnl Always shared.
143PHP_BUILD_SHARED
144
145dnl Required programs.
146PHP_PROG_AWK
147
148sinclude(config.m4)
149
150enable_static=no
151enable_shared=yes
152
153dnl Only allow AC_PROG_CXX and AC_PROG_CXXCPP if they are explicitly called (by
154dnl PHP_REQUIRE_CXX). Otherwise AC_PROG_LIBTOOL fails if there is no working C++
155dnl compiler.
156AC_PROVIDE_IFELSE([PHP_REQUIRE_CXX], [], [
157  undefine([AC_PROG_CXX])
158  AC_DEFUN([AC_PROG_CXX], [])
159  undefine([AC_PROG_CXXCPP])
160  AC_DEFUN([AC_PROG_CXXCPP], [php_prog_cxxcpp=disabled])
161])
162AC_PROG_LIBTOOL
163
164all_targets='$(PHP_MODULES) $(PHP_ZEND_EX)'
165install_targets="install-modules install-headers"
166CPPFLAGS="$CPPFLAGS -DHAVE_CONFIG_H"
167CFLAGS_CLEAN='$(CFLAGS) -D_GNU_SOURCE'
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(phpincludedir)
192
193PHP_SUBST(CC)
194PHP_SUBST(CFLAGS)
195PHP_SUBST(CFLAGS_CLEAN)
196PHP_SUBST(CPP)
197PHP_SUBST(CPPFLAGS)
198PHP_SUBST(CXX)
199PHP_SUBST(CXXFLAGS)
200PHP_SUBST(CXXFLAGS_CLEAN)
201PHP_SUBST(EXTENSION_DIR)
202PHP_SUBST(PHP_EXECUTABLE)
203PHP_SUBST(EXTRA_LDFLAGS)
204PHP_SUBST(EXTRA_LIBS)
205PHP_SUBST(INCLUDES)
206PHP_SUBST(LDFLAGS)
207PHP_SUBST(LIBTOOL)
208PHP_SUBST(SHELL)
209PHP_SUBST(INSTALL_HEADERS)
210PHP_SUBST(BUILD_CC)
211
212AC_CONFIG_HEADERS([config.h])
213
214AC_CONFIG_COMMANDS_PRE([PHP_PATCH_CONFIG_HEADERS([config.h.in])])
215
216AC_OUTPUT
217