Skip to content

Commit 762a0d0

Browse files
committed
Zend/Zend.m4: use AX_APPEND_COMPILE_FLAGS
1 parent 2f65da0 commit 762a0d0

File tree

7 files changed

+145
-10
lines changed

7 files changed

+145
-10
lines changed

Zend/Zend.m4

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,11 @@ fi
204204
205205
test -n "$GCC" && CFLAGS="-Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-sign-compare $CFLAGS"
206206
dnl Check if compiler supports -Wno-clobbered (only GCC)
207-
AX_CHECK_COMPILE_FLAG([-Wno-clobbered], CFLAGS="-Wno-clobbered $CFLAGS", , [-Werror])
207+
AX_APPEND_COMPILE_FLAGS([-Wno-clobbered],, [-Werror])
208208
dnl Check for support for implicit fallthrough level 1, also add after previous CFLAGS as level 3 is enabled in -Wextra
209-
AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough=1], CFLAGS="$CFLAGS -Wimplicit-fallthrough=1", , [-Werror])
210-
AX_CHECK_COMPILE_FLAG([-Wduplicated-cond], CFLAGS="-Wduplicated-cond $CFLAGS", , [-Werror])
211-
AX_CHECK_COMPILE_FLAG([-Wlogical-op], CFLAGS="-Wlogical-op $CFLAGS", , [-Werror])
212-
AX_CHECK_COMPILE_FLAG([-Wformat-truncation], CFLAGS="-Wformat-truncation $CFLAGS", , [-Werror])
213-
AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes], CFLAGS="-Wstrict-prototypes $CFLAGS", , [-Werror])
214-
AX_CHECK_COMPILE_FLAG([-fno-common], CFLAGS="-fno-common $CFLAGS", , [-Werror])
209+
AX_APPEND_COMPILE_FLAGS([-Wimplicit-fallthrough=1],, [-Werror])
210+
AX_APPEND_COMPILE_FLAGS([-Wduplicated-cond -Wlogical-op -Wformat-truncation -Wstrict-prototypes],, [-Werror])
211+
AX_APPEND_COMPILE_FLAGS([-fno-common],, [-Werror])
215212
216213
test -n "$DEBUG_CFLAGS" && CFLAGS="$CFLAGS $DEBUG_CFLAGS"
217214

build/ax_append_compile_flags.m4

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# ============================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_append_compile_flags.html
3+
# ============================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_APPEND_COMPILE_FLAGS([FLAG1 FLAG2 ...], [FLAGS-VARIABLE], [EXTRA-FLAGS], [INPUT])
8+
#
9+
# DESCRIPTION
10+
#
11+
# For every FLAG1, FLAG2 it is checked whether the compiler works with the
12+
# flag. If it does, the flag is added FLAGS-VARIABLE
13+
#
14+
# If FLAGS-VARIABLE is not specified, the current language's flags (e.g.
15+
# CFLAGS) is used. During the check the flag is always added to the
16+
# current language's flags.
17+
#
18+
# If EXTRA-FLAGS is defined, it is added to the current language's default
19+
# flags (e.g. CFLAGS) when the check is done. The check is thus made with
20+
# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
21+
# force the compiler to issue an error when a bad flag is given.
22+
#
23+
# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
24+
#
25+
# NOTE: This macro depends on the AX_APPEND_FLAG and
26+
# AX_CHECK_COMPILE_FLAG. Please keep this macro in sync with
27+
# AX_APPEND_LINK_FLAGS.
28+
#
29+
# LICENSE
30+
#
31+
# Copyright (c) 2011 Maarten Bosmans <[email protected]>
32+
#
33+
# Copying and distribution of this file, with or without modification, are
34+
# permitted in any medium without royalty provided the copyright notice
35+
# and this notice are preserved. This file is offered as-is, without any
36+
# warranty.
37+
38+
#serial 7
39+
40+
AC_DEFUN([AX_APPEND_COMPILE_FLAGS],
41+
[AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
42+
AX_REQUIRE_DEFINED([AX_APPEND_FLAG])
43+
for flag in $1; do
44+
AX_CHECK_COMPILE_FLAG([$flag], [AX_APPEND_FLAG([$flag], [$2])], [], [$3], [$4])
45+
done
46+
])dnl AX_APPEND_COMPILE_FLAGS

build/ax_append_flag.m4

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# ===========================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_append_flag.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_APPEND_FLAG(FLAG, [FLAGS-VARIABLE])
8+
#
9+
# DESCRIPTION
10+
#
11+
# FLAG is appended to the FLAGS-VARIABLE shell variable, with a space
12+
# added in between.
13+
#
14+
# If FLAGS-VARIABLE is not specified, the current language's flags (e.g.
15+
# CFLAGS) is used. FLAGS-VARIABLE is not changed if it already contains
16+
# FLAG. If FLAGS-VARIABLE is unset in the shell, it is set to exactly
17+
# FLAG.
18+
#
19+
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION.
20+
#
21+
# LICENSE
22+
#
23+
# Copyright (c) 2008 Guido U. Draheim <[email protected]>
24+
# Copyright (c) 2011 Maarten Bosmans <[email protected]>
25+
#
26+
# Copying and distribution of this file, with or without modification, are
27+
# permitted in any medium without royalty provided the copyright notice
28+
# and this notice are preserved. This file is offered as-is, without any
29+
# warranty.
30+
31+
#serial 8
32+
33+
AC_DEFUN([AX_APPEND_FLAG],
34+
[dnl
35+
AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_SET_IF
36+
AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])])
37+
AS_VAR_SET_IF(FLAGS,[
38+
AS_CASE([" AS_VAR_GET(FLAGS) "],
39+
[*" $1 "*], [AC_RUN_LOG([: FLAGS already contains $1])],
40+
[
41+
AS_VAR_APPEND(FLAGS,[" $1"])
42+
AC_RUN_LOG([: FLAGS="$FLAGS"])
43+
])
44+
],
45+
[
46+
AS_VAR_SET(FLAGS,[$1])
47+
AC_RUN_LOG([: FLAGS="$FLAGS"])
48+
])
49+
AS_VAR_POPDEF([FLAGS])dnl
50+
])dnl AX_APPEND_FLAG

build/ax_require_defined.m4

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# ===========================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_require_defined.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_REQUIRE_DEFINED(MACRO)
8+
#
9+
# DESCRIPTION
10+
#
11+
# AX_REQUIRE_DEFINED is a simple helper for making sure other macros have
12+
# been defined and thus are available for use. This avoids random issues
13+
# where a macro isn't expanded. Instead the configure script emits a
14+
# non-fatal:
15+
#
16+
# ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found
17+
#
18+
# It's like AC_REQUIRE except it doesn't expand the required macro.
19+
#
20+
# Here's an example:
21+
#
22+
# AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG])
23+
#
24+
# LICENSE
25+
#
26+
# Copyright (c) 2014 Mike Frysinger <[email protected]>
27+
#
28+
# Copying and distribution of this file, with or without modification, are
29+
# permitted in any medium without royalty provided the copyright notice
30+
# and this notice are preserved. This file is offered as-is, without any
31+
# warranty.
32+
33+
#serial 2
34+
35+
AC_DEFUN([AX_REQUIRE_DEFINED], [dnl
36+
m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])])
37+
])dnl AX_REQUIRE_DEFINED

configure.ac

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ dnl Process this file with autoconf to produce a configure script.
33
dnl Include external macro definitions before the AC_INIT to also remove
44
dnl comments starting with # and empty newlines from the included files.
55
dnl ----------------------------------------------------------------------------
6+
m4_include([build/ax_require_defined.m4])
67
m4_include([build/ax_check_compile_flag.m4])
8+
m4_include([build/ax_append_flag.m4])
9+
m4_include([build/ax_append_compile_flags.m4])
710
m4_include([build/ax_func_which_gethostbyname_r.m4])
811
m4_include([build/ax_gcc_func_attribute.m4])
912
m4_include([build/libtool.m4])
@@ -220,8 +223,7 @@ esac
220223

221224
dnl Mark symbols hidden by default if the compiler (for example, gcc >= 4)
222225
dnl supports it. This can help reduce the binary size and startup time.
223-
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
224-
[CFLAGS="$CFLAGS -fvisibility=hidden"])
226+
AX_APPEND_COMPILE_FLAGS([-fvisibility=hidden])
225227

226228
case $host_alias in
227229
*solaris*)

ext/sodium/config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if test "$PHP_SODIUM" != "no"; then
1313

1414
dnl Add -Wno-type-limits and -Wno-logical-op as this may arise on 32bits platforms
1515
SODIUM_COMPILER_FLAGS="$LIBSODIUM_CFLAGS -Wno-type-limits"
16-
AX_CHECK_COMPILE_FLAG([-Wno-logical-op], SODIUM_COMPILER_FLAGS="$SODIUM_COMPILER_FLAGS -Wno-logical-op", , [-Werror])
16+
AX_APPEND_COMPILE_FLAGS([-Wno-logical-op], [SODIUM_COMPILER_FLAGS], [-Werror])
1717
PHP_NEW_EXTENSION(sodium, libsodium.c sodium_pwhash.c, $ext_shared, , $SODIUM_COMPILER_FLAGS)
1818
PHP_SUBST(SODIUM_SHARED_LIBADD)
1919
fi

scripts/Makefile.frag

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ BUILD_FILES = \
99
scripts/phpize.m4 \
1010
build/libtool.m4 \
1111
build/ltmain.sh \
12+
build/ax_require_defined.m4 \
1213
build/ax_check_compile_flag.m4 \
14+
build/ax_append_flag.m4 \
15+
build/ax_append_compile_flags.m4 \
1316
build/ax_gcc_func_attribute.m4 \
1417
build/php_cxx_compile_stdcxx.m4 \
1518
build/pkg.m4 \

0 commit comments

Comments
 (0)