xref: /php-src/scripts/phpize.m4 (revision c6396143)
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
29PHP_INIT_BUILD_SYSTEM
30
31PKG_PROG_PKG_CONFIG
32AC_PROG_CC([cc gcc])
33PHP_DETECT_ICC
34PHP_DETECT_SUNCC
35
36dnl Support systems with system libraries in e.g. /usr/lib64.
37PHP_ARG_WITH([libdir],
38  [for system library directory],
39  [AS_HELP_STRING([--with-libdir=NAME],
40    [Look for libraries in .../NAME rather than .../lib])],
41  [lib],
42  [no])
43
44PHP_RUNPATH_SWITCH
45PHP_SHLIB_SUFFIX_NAMES
46
47dnl Find php-config script.
48PHP_ARG_WITH([php-config],,
49  [AS_HELP_STRING([--with-php-config=PATH],
50    [Path to php-config [php-config]])],
51  [php-config],
52  [no])
53
54dnl For BC.
55PHP_CONFIG=$PHP_PHP_CONFIG
56prefix=$($PHP_CONFIG --prefix 2>/dev/null)
57phpincludedir=$($PHP_CONFIG --include-dir 2>/dev/null)
58INCLUDES=$($PHP_CONFIG --includes 2>/dev/null)
59EXTENSION_DIR=$($PHP_CONFIG --extension-dir 2>/dev/null)
60PHP_EXECUTABLE=$($PHP_CONFIG --php-binary 2>/dev/null)
61
62AS_VAR_IF([prefix],,
63  [AC_MSG_ERROR([Cannot find php-config. Please use --with-php-config=PATH])])
64
65AC_MSG_CHECKING([for PHP prefix])
66AC_MSG_RESULT([$prefix])
67AC_MSG_CHECKING([for PHP includes])
68AC_MSG_RESULT([$INCLUDES])
69AC_MSG_CHECKING([for PHP extension directory])
70AC_MSG_RESULT([$EXTENSION_DIR])
71AC_MSG_CHECKING([for PHP installed headers prefix])
72AC_MSG_RESULT([$phpincludedir])
73
74dnl Checks for PHP_DEBUG / ZEND_DEBUG / ZTS.
75AC_MSG_CHECKING([if debugging is enabled])
76old_CPPFLAGS=$CPPFLAGS
77CPPFLAGS="-I$phpincludedir"
78AC_EGREP_CPP([php_debug_is_enabled], [
79#include <main/php_config.h>
80#if ZEND_DEBUG
81php_debug_is_enabled
82#endif
83],
84  [PHP_DEBUG=yes],
85  [PHP_DEBUG=no])
86CPPFLAGS=$old_CPPFLAGS
87AC_MSG_RESULT([$PHP_DEBUG])
88
89AC_MSG_CHECKING([if PHP is built with thread safety (ZTS)])
90old_CPPFLAGS=$CPPFLAGS
91CPPFLAGS="-I$phpincludedir"
92AC_EGREP_CPP([php_zts_is_enabled], [
93#include <main/php_config.h>
94#ifdef ZTS
95php_zts_is_enabled
96#endif
97],
98  [PHP_THREAD_SAFETY=yes],
99  [PHP_THREAD_SAFETY=no])
100CPPFLAGS=$old_CPPFLAGS
101AC_MSG_RESULT([$PHP_THREAD_SAFETY])
102
103dnl Discard optimization flags when debugging is enabled.
104AS_VAR_IF([PHP_DEBUG], [yes], [
105  PHP_DEBUG=1
106  ZEND_DEBUG=yes
107  PHP_REMOVE_OPTIMIZATION_FLAGS
108  dnl Add -O0 only if GCC or ICC is used.
109  if test "$GCC" = "yes" || test "$ICC" = "yes"; then
110    CFLAGS="$CFLAGS -O0"
111    CXXFLAGS="$CXXFLAGS -g -O0"
112  fi
113  if test "$SUNCC" = "yes"; then
114    if test -n "$auto_cflags"; then
115      CFLAGS="-g"
116      CXXFLAGS="-g"
117    else
118      CFLAGS="$CFLAGS -g"
119      CXXFLAGS="$CFLAGS -g"
120    fi
121  fi
122], [
123  PHP_DEBUG=0
124  ZEND_DEBUG=no
125])
126
127dnl Always shared.
128PHP_BUILD_SHARED
129
130PHP_HELP_SEPARATOR([Extension:])
131PHP_CONFIGURE_PART([Configuring extension])
132
133sinclude(config.m4)
134
135enable_static=no
136enable_shared=yes
137
138PHP_HELP_SEPARATOR([Libtool:])
139PHP_CONFIGURE_PART([Configuring libtool])
140
141dnl Only allow AC_PROG_CXX and AC_PROG_CXXCPP if they are explicitly called (by
142dnl PHP_REQUIRE_CXX). Otherwise AC_PROG_LIBTOOL fails if there is no working C++
143dnl compiler.
144AC_PROVIDE_IFELSE([PHP_REQUIRE_CXX], [], [
145  undefine([AC_PROG_CXX])
146  AC_DEFUN([AC_PROG_CXX], [])
147  undefine([AC_PROG_CXXCPP])
148  AC_DEFUN([AC_PROG_CXXCPP], [php_prog_cxxcpp=disabled])
149])
150AC_PROG_LIBTOOL
151
152all_targets='$(PHP_MODULES) $(PHP_ZEND_EX)'
153install_targets="install-modules install-headers"
154CPPFLAGS="$CPPFLAGS -DHAVE_CONFIG_H"
155CFLAGS_CLEAN='$(CFLAGS) -D_GNU_SOURCE'
156CXXFLAGS_CLEAN='$(CXXFLAGS)'
157
158AS_VAR_IF([prefix], [NONE], [prefix=/usr/local])
159AS_VAR_IF([exec_prefix], [NONE], [exec_prefix='$(prefix)'])
160
161AS_VAR_IF([cross_compiling], [yes],
162  [AC_CHECK_PROGS([BUILD_CC], [gcc clang c99 c89 cc cl], [none])
163    AC_MSG_CHECKING([for native build C compiler])
164    AC_MSG_RESULT([$BUILD_CC])],
165  [BUILD_CC=$CC])
166
167PHP_SUBST([PHP_MODULES])
168PHP_SUBST([PHP_ZEND_EX])
169PHP_SUBST([all_targets])
170PHP_SUBST([install_targets])
171PHP_SUBST([prefix])
172PHP_SUBST([exec_prefix])
173PHP_SUBST([libdir])
174PHP_SUBST([phpincludedir])
175PHP_SUBST([CC])
176PHP_SUBST([CFLAGS])
177PHP_SUBST([CFLAGS_CLEAN])
178PHP_SUBST([CPP])
179PHP_SUBST([CPPFLAGS])
180PHP_SUBST([CXX])
181PHP_SUBST([CXXFLAGS])
182PHP_SUBST([CXXFLAGS_CLEAN])
183PHP_SUBST([EXTENSION_DIR])
184PHP_SUBST([PHP_EXECUTABLE])
185PHP_SUBST([EXTRA_LDFLAGS])
186PHP_SUBST([EXTRA_LIBS])
187PHP_SUBST([INCLUDES])
188PHP_SUBST([LDFLAGS])
189PHP_SUBST([LIBTOOL])
190PHP_SUBST([SHELL])
191PHP_SUBST([INSTALL_HEADERS])
192PHP_SUBST([BUILD_CC])
193
194PHP_CONFIGURE_PART([Generating files])
195
196AC_CONFIG_HEADERS([config.h])
197
198AC_CONFIG_COMMANDS_PRE([PHP_PATCH_CONFIG_HEADERS([config.h.in])])
199
200AC_OUTPUT
201