1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# ============================================================================
# http://www.gnu.org/software/autoconf-archive/ax_compiler_flags_cflags.html
# ============================================================================
#
# SYNOPSIS
#
# AX_COMPILER_FLAGS_CFLAGS([VARIABLE], [IS-RELEASE], [EXTRA-BASE-FLAGS], [EXTRA-MINIMUM-FLAGS], [EXTRA-YES-FLAGS], [EXTRA-MAXIMUM-FLAGS], [EXTRA-ERROR-FLAGS])
#
# DESCRIPTION
#
# Add warning flags for the C compiler to VARIABLE, which defaults to
# WARN_CFLAGS. VARIABLE is AC_SUBST-ed by this macro, but must be
# manually added to the CFLAGS variable for each target in the code base.
#
# This macro depends on the environment set up by AX_COMPILER_FLAGS.
# Specifically, it uses the value of $ax_enable_compile_warnings to decide
# which flags to enable.
#
# LICENSE
#
# Copyright (c) 2014, 2015 Philip Withnall <philip@tecnocode.co.uk>
#
# 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 3
AC_DEFUN([AX_COMPILER_FLAGS_CFLAGS],[
AX_REQUIRE_DEFINED([AX_APPEND_COMPILE_FLAGS])
AX_REQUIRE_DEFINED([AX_APPEND_FLAG])
AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
# Variable names
m4_define(ax_warn_cflags_variable,
[m4_normalize(ifelse([$1],,[WARN_CFLAGS],[$1]))])
# Always pass -Werror=unknown-warning-option to get Clang to fail on bad
# flags, otherwise they are always appended to the warn_cflags variable, and
# Clang warns on them for every compilation unit.
# If this is passed to GCC, it will explode, so the flag must be enabled
# conditionally.
AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],[
ax_compiler_flags_test="-Werror=unknown-warning-option"
],[
ax_compiler_flags_test=""
])
# Base flags
AX_APPEND_COMPILE_FLAGS([ dnl
-fno-strict-aliasing dnl
$3 dnl
],ax_warn_cflags_variable,[$ax_compiler_flags_test])
AS_IF([test "$ax_enable_compile_warnings" != "no"],[
# "minimum" flags
AX_APPEND_COMPILE_FLAGS([ dnl
-Wall dnl
$4 dnl
],ax_warn_cflags_variable,[$ax_compiler_flags_test])
])
AS_IF([test "$ax_enable_compile_warnings" != "no" -a \
"$ax_enable_compile_warnings" != "minimum"],[
# "yes" flags
AX_APPEND_COMPILE_FLAGS([ dnl
-Wextra dnl
-Wundef dnl
-Wnested-externs dnl
-Wwrite-strings dnl
-Wpointer-arith dnl
-Wmissing-declarations dnl
-Wmissing-prototypes dnl
-Wstrict-prototypes dnl
-Wredundant-decls dnl
-Wno-unused-parameter dnl
-Wno-missing-field-initializers dnl
-Wdeclaration-after-statement dnl
-Wformat=2 dnl
-Wold-style-definition dnl
-Wcast-align dnl
-Wformat-nonliteral dnl
-Wformat-security dnl
-Wsign-compare dnl
-Wstrict-aliasing dnl
-Wshadow dnl
-Winline dnl
-Wpacked dnl
-Wmissing-format-attribute dnl
-Wmissing-noreturn dnl
-Winit-self dnl
-Wredundant-decls dnl
-Wmissing-include-dirs dnl
-Wunused-but-set-variable dnl
-Warray-bounds dnl
-Wimplicit-function-declaration dnl
-Wreturn-type dnl
$5 dnl
],ax_warn_cflags_variable,[$ax_compiler_flags_test])
])
AS_IF([test "$ax_enable_compile_warnings" = "maximum" -o \
"$ax_enable_compile_warnings" = "error"],[
# "maximum" flags
AX_APPEND_COMPILE_FLAGS([ dnl
-Wswitch-enum dnl
-Wswitch-default dnl
-Waggregate-return dnl
$6 dnl
],ax_warn_cflags_variable,[$ax_compiler_flags_test])
])
AS_IF([test "$ax_enable_compile_warnings" = "error"],[
# "error" flags; -Werror has to be appended unconditionally because
# it’s not possible to test for
#
# suggest-attribute=format is disabled because it gives too many false
# positives
AX_APPEND_FLAG([-Werror],ax_warn_cflags_variable)
AX_APPEND_COMPILE_FLAGS([ dnl
-Wno-suggest-attribute=format dnl
$7 dnl
],ax_warn_cflags_variable,[$ax_compiler_flags_test])
])
# Substitute the variables
AC_SUBST(ax_warn_cflags_variable)
])dnl AX_COMPILER_FLAGS
|