diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index f651ee57d7487..34a951b88cf2e 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -204,14 +204,11 @@ fi test -n "$GCC" && CFLAGS="-Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-sign-compare $CFLAGS" dnl Check if compiler supports -Wno-clobbered (only GCC) -AX_CHECK_COMPILE_FLAG([-Wno-clobbered], CFLAGS="-Wno-clobbered $CFLAGS", , [-Werror]) +AX_APPEND_COMPILE_FLAGS([-Wno-clobbered],, [-Werror]) dnl Check for support for implicit fallthrough level 1, also add after previous CFLAGS as level 3 is enabled in -Wextra -AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough=1], CFLAGS="$CFLAGS -Wimplicit-fallthrough=1", , [-Werror]) -AX_CHECK_COMPILE_FLAG([-Wduplicated-cond], CFLAGS="-Wduplicated-cond $CFLAGS", , [-Werror]) -AX_CHECK_COMPILE_FLAG([-Wlogical-op], CFLAGS="-Wlogical-op $CFLAGS", , [-Werror]) -AX_CHECK_COMPILE_FLAG([-Wformat-truncation], CFLAGS="-Wformat-truncation $CFLAGS", , [-Werror]) -AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes], CFLAGS="-Wstrict-prototypes $CFLAGS", , [-Werror]) -AX_CHECK_COMPILE_FLAG([-fno-common], CFLAGS="-fno-common $CFLAGS", , [-Werror]) +AX_APPEND_COMPILE_FLAGS([-Wimplicit-fallthrough=1],, [-Werror]) +AX_APPEND_COMPILE_FLAGS([-Wduplicated-cond -Wlogical-op -Wformat-truncation -Wstrict-prototypes],, [-Werror]) +AX_APPEND_COMPILE_FLAGS([-fno-common],, [-Werror]) test -n "$DEBUG_CFLAGS" && CFLAGS="$CFLAGS $DEBUG_CFLAGS" diff --git a/build/ax_append_compile_flags.m4 b/build/ax_append_compile_flags.m4 new file mode 100644 index 0000000000000..9c856356c0cda --- /dev/null +++ b/build/ax_append_compile_flags.m4 @@ -0,0 +1,46 @@ +# ============================================================================ +# https://www.gnu.org/software/autoconf-archive/ax_append_compile_flags.html +# ============================================================================ +# +# SYNOPSIS +# +# AX_APPEND_COMPILE_FLAGS([FLAG1 FLAG2 ...], [FLAGS-VARIABLE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# For every FLAG1, FLAG2 it is checked whether the compiler works with the +# flag. If it does, the flag is added FLAGS-VARIABLE +# +# If FLAGS-VARIABLE is not specified, the current language's flags (e.g. +# CFLAGS) is used. During the check the flag is always added to the +# current language's flags. +# +# If EXTRA-FLAGS is defined, it is added to the current language's default +# flags (e.g. CFLAGS) when the check is done. The check is thus made with +# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to +# force the compiler to issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_COMPILE_IFELSE. +# +# NOTE: This macro depends on the AX_APPEND_FLAG and +# AX_CHECK_COMPILE_FLAG. Please keep this macro in sync with +# AX_APPEND_LINK_FLAGS. +# +# LICENSE +# +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 7 + +AC_DEFUN([AX_APPEND_COMPILE_FLAGS], +[AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG]) +AX_REQUIRE_DEFINED([AX_APPEND_FLAG]) +for flag in $1; do + AX_CHECK_COMPILE_FLAG([$flag], [AX_APPEND_FLAG([$flag], [$2])], [], [$3], [$4]) +done +])dnl AX_APPEND_COMPILE_FLAGS diff --git a/build/ax_append_flag.m4 b/build/ax_append_flag.m4 new file mode 100644 index 0000000000000..dd6d8b61406c3 --- /dev/null +++ b/build/ax_append_flag.m4 @@ -0,0 +1,50 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_append_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_APPEND_FLAG(FLAG, [FLAGS-VARIABLE]) +# +# DESCRIPTION +# +# FLAG is appended to the FLAGS-VARIABLE shell variable, with a space +# added in between. +# +# If FLAGS-VARIABLE is not specified, the current language's flags (e.g. +# CFLAGS) is used. FLAGS-VARIABLE is not changed if it already contains +# FLAG. If FLAGS-VARIABLE is unset in the shell, it is set to exactly +# FLAG. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 8 + +AC_DEFUN([AX_APPEND_FLAG], +[dnl +AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_SET_IF +AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])]) +AS_VAR_SET_IF(FLAGS,[ + AS_CASE([" AS_VAR_GET(FLAGS) "], + [*" $1 "*], [AC_RUN_LOG([: FLAGS already contains $1])], + [ + AS_VAR_APPEND(FLAGS,[" $1"]) + AC_RUN_LOG([: FLAGS="$FLAGS"]) + ]) + ], + [ + AS_VAR_SET(FLAGS,[$1]) + AC_RUN_LOG([: FLAGS="$FLAGS"]) + ]) +AS_VAR_POPDEF([FLAGS])dnl +])dnl AX_APPEND_FLAG diff --git a/build/ax_require_defined.m4 b/build/ax_require_defined.m4 new file mode 100644 index 0000000000000..17c3eab7dafde --- /dev/null +++ b/build/ax_require_defined.m4 @@ -0,0 +1,37 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_require_defined.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_REQUIRE_DEFINED(MACRO) +# +# DESCRIPTION +# +# AX_REQUIRE_DEFINED is a simple helper for making sure other macros have +# been defined and thus are available for use. This avoids random issues +# where a macro isn't expanded. Instead the configure script emits a +# non-fatal: +# +# ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found +# +# It's like AC_REQUIRE except it doesn't expand the required macro. +# +# Here's an example: +# +# AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) +# +# LICENSE +# +# Copyright (c) 2014 Mike Frysinger +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 2 + +AC_DEFUN([AX_REQUIRE_DEFINED], [dnl + m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])]) +])dnl AX_REQUIRE_DEFINED diff --git a/configure.ac b/configure.ac index 3970d6d77bd38..c2b44ebfebf27 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,10 @@ dnl Process this file with autoconf to produce a configure script. dnl Include external macro definitions before the AC_INIT to also remove dnl comments starting with # and empty newlines from the included files. dnl ---------------------------------------------------------------------------- +m4_include([build/ax_require_defined.m4]) m4_include([build/ax_check_compile_flag.m4]) +m4_include([build/ax_append_flag.m4]) +m4_include([build/ax_append_compile_flags.m4]) m4_include([build/ax_func_which_gethostbyname_r.m4]) m4_include([build/ax_gcc_func_attribute.m4]) m4_include([build/libtool.m4]) @@ -220,8 +223,7 @@ esac dnl Mark symbols hidden by default if the compiler (for example, gcc >= 4) dnl supports it. This can help reduce the binary size and startup time. -AX_CHECK_COMPILE_FLAG([-fvisibility=hidden], - [CFLAGS="$CFLAGS -fvisibility=hidden"]) +AX_APPEND_COMPILE_FLAGS([-fvisibility=hidden]) case $host_alias in *solaris*) diff --git a/ext/sodium/config.m4 b/ext/sodium/config.m4 index 05d9ebd5a13df..948dbc0c8f131 100644 --- a/ext/sodium/config.m4 +++ b/ext/sodium/config.m4 @@ -13,7 +13,7 @@ if test "$PHP_SODIUM" != "no"; then dnl Add -Wno-type-limits and -Wno-logical-op as this may arise on 32bits platforms SODIUM_COMPILER_FLAGS="$LIBSODIUM_CFLAGS -Wno-type-limits" - AX_CHECK_COMPILE_FLAG([-Wno-logical-op], SODIUM_COMPILER_FLAGS="$SODIUM_COMPILER_FLAGS -Wno-logical-op", , [-Werror]) + AX_APPEND_COMPILE_FLAGS([-Wno-logical-op], [SODIUM_COMPILER_FLAGS], [-Werror]) PHP_NEW_EXTENSION(sodium, libsodium.c sodium_pwhash.c, $ext_shared, , $SODIUM_COMPILER_FLAGS) PHP_SUBST(SODIUM_SHARED_LIBADD) fi diff --git a/scripts/Makefile.frag b/scripts/Makefile.frag index 104983214546f..f1f954f520d19 100644 --- a/scripts/Makefile.frag +++ b/scripts/Makefile.frag @@ -9,7 +9,10 @@ BUILD_FILES = \ scripts/phpize.m4 \ build/libtool.m4 \ build/ltmain.sh \ + build/ax_require_defined.m4 \ build/ax_check_compile_flag.m4 \ + build/ax_append_flag.m4 \ + build/ax_append_compile_flags.m4 \ build/ax_gcc_func_attribute.m4 \ build/php_cxx_compile_stdcxx.m4 \ build/pkg.m4 \ diff --git a/scripts/phpize.in b/scripts/phpize.in old mode 100644 new mode 100755 index 7d9c1df14c8ec..fd0825eef2a62 --- a/scripts/phpize.in +++ b/scripts/phpize.in @@ -10,6 +10,7 @@ builddir="`pwd`" SED="@SED@" FILES_BUILD="php.m4 shtool libtool.m4 ax_check_compile_flag.m4 ax_gcc_func_attribute.m4 php_cxx_compile_stdcxx.m4 pkg.m4 \ + ax_require_defined.m4 ax_append_flag.m4 ax_append_compile_flags.m4 \ config.guess config.sub ltmain.sh Makefile.global gen_stub.php" FILES="run-tests*.php" CLEAN_FILES="$FILES *.o *.lo *.la .libs/ build/ modules/ \