Skip to content

Commit b704efe

Browse files
committed
build: move warning checks to configure
This allows us to only add the warning flag if the compiler supports it, improving the compatibility with clang.
1 parent 05b27e8 commit b704efe

File tree

3 files changed

+132
-65
lines changed

3 files changed

+132
-65
lines changed

Makefile.am

+4-65
Original file line numberDiff line numberDiff line change
@@ -45,82 +45,21 @@ AM_CPPFLAGS = \
4545

4646
AM_CFLAGS = \
4747
-pipe \
48-
-Wall \
49-
-W \
50-
-Wextra \
51-
-Wno-inline \
52-
-Wundef \
53-
-Wformat=2 \
54-
-Wlogical-op \
55-
-Wsign-compare \
56-
-Wformat-security \
57-
-Wmissing-include-dirs \
58-
-Wformat-nonliteral \
59-
-Wold-style-definition \
60-
-Wpointer-arith \
61-
-Winit-self \
62-
-Wdeclaration-after-statement \
63-
-Wfloat-equal \
64-
-Wmissing-prototypes \
65-
-Wstrict-prototypes \
66-
-Wredundant-decls \
67-
-Wmissing-declarations \
68-
-Wmissing-noreturn \
69-
-Wshadow \
70-
-Wendif-labels \
71-
-Wstrict-aliasing=3 \
72-
-Wwrite-strings \
73-
-Wno-long-long \
74-
-Wno-overlength-strings \
75-
-Wno-unused-parameter \
76-
-Wno-missing-field-initializers \
77-
-Wno-unused-result \
78-
-Wnested-externs \
79-
-Wchar-subscripts \
80-
-Wtype-limits \
81-
-Wuninitialized \
8248
-fno-common \
8349
-fdiagnostics-show-option \
8450
-fvisibility=hidden \
8551
-ffunction-sections \
86-
-fdata-sections
52+
-fdata-sections \
53+
$(OUR_CFLAGS)
8754

8855
AM_CXXFLAGS = \
8956
-pipe \
90-
-Wall \
91-
-W \
92-
-Wextra \
93-
-Wno-inline \
94-
-Wundef \
95-
-Wformat=2 \
96-
-Wlogical-op \
97-
-Wsign-compare \
98-
-Wformat-security \
99-
-Wmissing-include-dirs \
100-
-Wformat-nonliteral \
101-
-Wpointer-arith \
102-
-Winit-self \
103-
-Wfloat-equal \
104-
-Wredundant-decls \
105-
-Wmissing-declarations \
106-
-Wmissing-noreturn \
107-
-Wshadow \
108-
-Wendif-labels \
109-
-Wstrict-aliasing=3 \
110-
-Wwrite-strings \
111-
-Wno-long-long \
112-
-Wno-overlength-strings \
113-
-Wno-unused-parameter \
114-
-Wno-missing-field-initializers \
115-
-Wno-unused-result \
116-
-Wchar-subscripts \
117-
-Wtype-limits \
118-
-Wuninitialized \
11957
-fno-common \
12058
-fdiagnostics-show-option \
12159
-fvisibility=hidden \
12260
-ffunction-sections \
123-
-fdata-sections
61+
-fdata-sections \
62+
$(OUR_CXXFLAGS)
12463

12564
AM_LDFLAGS = \
12665
-Wl,--as-needed \

configure.ac

+75
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,81 @@ AM_CONDITIONAL(SYSTEMD, test "${enable_systemd}" != "no")
9595
# Default CFLAGS and LDFLAGS
9696
#####################################################################
9797

98+
# Check C compiler flag
99+
AC_LANG_PUSH([C])
100+
CC_CHECK_FLAGS_APPEND(with_cflags, [CFLAGS], [ \
101+
-Wall \
102+
-W \
103+
-Wextra \
104+
-Wno-inline \
105+
-Wundef \
106+
-Wformat=2 \
107+
-Wlogical-op \
108+
-Wsign-compare \
109+
-Wformat-security \
110+
-Wmissing-include-dirs \
111+
-Wformat-nonliteral \
112+
-Wold-style-definition \
113+
-Wpointer-arith \
114+
-Winit-self \
115+
-Wdeclaration-after-statement \
116+
-Wfloat-equal \
117+
-Wmissing-prototypes \
118+
-Wstrict-prototypes \
119+
-Wredundant-decls \
120+
-Wmissing-declarations \
121+
-Wmissing-noreturn \
122+
-Wshadow \
123+
-Wendif-labels \
124+
-Wstrict-aliasing=3 \
125+
-Wwrite-strings \
126+
-Wno-long-long \
127+
-Wno-overlength-strings \
128+
-Wno-unused-parameter \
129+
-Wno-missing-field-initializers \
130+
-Wno-unused-result \
131+
-Wnested-externs \
132+
-Wchar-subscripts \
133+
-Wtype-limits \
134+
-Wuninitialized])
135+
AC_SUBST([OUR_CFLAGS], "$with_cflags")
136+
AC_LANG_POP([C])
137+
138+
# Check C++ compiler flags
139+
AC_LANG_PUSH([C++])
140+
CC_CHECK_FLAGS_APPEND(with_cxxflags, [CXXFLAGS], [ \
141+
-Wall \
142+
-W \
143+
-Wextra \
144+
-Wno-inline \
145+
-Wundef \
146+
-Wformat=2 \
147+
-Wlogical-op \
148+
-Wsign-compare \
149+
-Wformat-security \
150+
-Wmissing-include-dirs \
151+
-Wformat-nonliteral \
152+
-Wpointer-arith \
153+
-Winit-self \
154+
-Wfloat-equal \
155+
-Wredundant-decls \
156+
-Wmissing-declarations \
157+
-Wmissing-noreturn \
158+
-Wshadow \
159+
-Wendif-labels \
160+
-Wstrict-aliasing=3 \
161+
-Wwrite-strings \
162+
-Wno-long-long \
163+
-Wno-overlength-strings \
164+
-Wno-unused-parameter \
165+
-Wno-missing-field-initializers \
166+
-Wno-unused-result \
167+
-Wchar-subscripts \
168+
-Wtype-limits \
169+
-Wuninitialized])
170+
AC_LANG_POP([C++])
171+
AC_SUBST([OUR_CXXFLAGS], "$with_cxxflags")
172+
98173
#####################################################################
99174
# Generate files from *.in
100175
#####################################################################

m4/ax_check_compile_flag.m4

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# ===========================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
8+
#
9+
# DESCRIPTION
10+
#
11+
# Check whether the given FLAG works with the current language's compiler
12+
# or gives an error. (Warnings, however, are ignored)
13+
#
14+
# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
15+
# success/failure.
16+
#
17+
# If EXTRA-FLAGS is defined, it is added to the current language's default
18+
# flags (e.g. CFLAGS) when the check is done. The check is thus made with
19+
# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
20+
# force the compiler to issue an error when a bad flag is given.
21+
#
22+
# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
23+
#
24+
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
25+
# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
26+
#
27+
# LICENSE
28+
#
29+
# Copyright (c) 2008 Guido U. Draheim <[email protected]>
30+
# Copyright (c) 2011 Maarten Bosmans <[email protected]>
31+
#
32+
# Copying and distribution of this file, with or without modification, are
33+
# permitted in any medium without royalty provided the copyright notice
34+
# and this notice are preserved. This file is offered as-is, without any
35+
# warranty.
36+
37+
#serial 6
38+
39+
AC_DEFUN([AX_CHECK_COMPILE_FLAG],
40+
[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
41+
AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
42+
AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
43+
ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
44+
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
45+
AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
46+
[AS_VAR_SET(CACHEVAR,[yes])],
47+
[AS_VAR_SET(CACHEVAR,[no])])
48+
_AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
49+
AS_VAR_IF(CACHEVAR,yes,
50+
[m4_default([$2], :)],
51+
[m4_default([$3], :)])
52+
AS_VAR_POPDEF([CACHEVAR])dnl
53+
])dnl AX_CHECK_COMPILE_FLAGS

0 commit comments

Comments
 (0)