Skip to content

Commit 1114354

Browse files
committed
Add more compiler warnings
You'd think GNOME_COMPILE_WARNINGS([maximum]) would be good enough but apparently not. I hate build systems. Signed-off-by: David Zeuthen <[email protected]>
1 parent 5207c93 commit 1114354

15 files changed

+436
-91
lines changed

acinclude.m4

+319
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
dnl Macros to check the presence of generic (non-typed) symbols.
2+
dnl Copyright (c) 2006-2008 Diego Pettenò <[email protected]>
3+
dnl Copyright (c) 2006-2008 xine project
4+
dnl
5+
dnl This program is free software; you can redistribute it and/or modify
6+
dnl it under the terms of the GNU General Public License as published by
7+
dnl the Free Software Foundation; either version 3, or (at your option)
8+
dnl any later version.
9+
dnl
10+
dnl This program is distributed in the hope that it will be useful,
11+
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
dnl GNU General Public License for more details.
14+
dnl
15+
dnl You should have received a copy of the GNU General Public License
16+
dnl along with this program; if not, write to the Free Software
17+
dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18+
dnl 02110-1301, USA.
19+
dnl
20+
dnl As a special exception, the copyright owners of the
21+
dnl macro gives unlimited permission to copy, distribute and modify the
22+
dnl configure scripts that are the output of Autoconf when processing the
23+
dnl Macro. You need not follow the terms of the GNU General Public
24+
dnl License when using or distributing such scripts, even though portions
25+
dnl of the text of the Macro appear in them. The GNU General Public
26+
dnl License (GPL) does govern all other use of the material that
27+
dnl constitutes the Autoconf Macro.
28+
dnl
29+
dnl This special exception to the GPL applies to versions of the
30+
dnl Autoconf Macro released by this project. When you make and
31+
dnl distribute a modified version of the Autoconf Macro, you may extend
32+
dnl this special exception to the GPL to apply to your modified version as
33+
dnl well.
34+
35+
dnl Check if the flag is supported by compiler
36+
dnl CC_CHECK_CFLAGS_SILENT([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
37+
38+
AC_DEFUN([CC_CHECK_CFLAGS_SILENT], [
39+
AC_CACHE_VAL(AS_TR_SH([cc_cv_cflags_$1]),
40+
[ac_save_CFLAGS="$CFLAGS"
41+
CFLAGS="$CFLAGS $1"
42+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([int a;])],
43+
[eval "AS_TR_SH([cc_cv_cflags_$1])='yes'"],
44+
[eval "AS_TR_SH([cc_cv_cflags_$1])='no'"])
45+
CFLAGS="$ac_save_CFLAGS"
46+
])
47+
48+
AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes],
49+
[$2], [$3])
50+
])
51+
52+
dnl Check if the flag is supported by compiler (cacheable)
53+
dnl CC_CHECK_CFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
54+
55+
AC_DEFUN([CC_CHECK_CFLAGS], [
56+
AC_CACHE_CHECK([if $CC supports $1 flag],
57+
AS_TR_SH([cc_cv_cflags_$1]),
58+
CC_CHECK_CFLAGS_SILENT([$1]) dnl Don't execute actions here!
59+
)
60+
61+
AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes],
62+
[$2], [$3])
63+
])
64+
65+
dnl CC_CHECK_CFLAG_APPEND(FLAG, [action-if-found], [action-if-not-found])
66+
dnl Check for CFLAG and appends them to CFLAGS if supported
67+
AC_DEFUN([CC_CHECK_CFLAG_APPEND], [
68+
AC_CACHE_CHECK([if $CC supports $1 flag],
69+
AS_TR_SH([cc_cv_cflags_$1]),
70+
CC_CHECK_CFLAGS_SILENT([$1]) dnl Don't execute actions here!
71+
)
72+
73+
AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes],
74+
[CFLAGS="$CFLAGS $1"; DEBUG_CFLAGS="$DEBUG_CFLAGS $1"; $2], [$3])
75+
])
76+
77+
dnl CC_CHECK_CFLAGS_APPEND([FLAG1 FLAG2], [action-if-found], [action-if-not])
78+
AC_DEFUN([CC_CHECK_CFLAGS_APPEND], [
79+
for flag in $1; do
80+
CC_CHECK_CFLAG_APPEND($flag, [$2], [$3])
81+
done
82+
])
83+
84+
dnl Check if the flag is supported by linker (cacheable)
85+
dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
86+
87+
AC_DEFUN([CC_CHECK_LDFLAGS], [
88+
AC_CACHE_CHECK([if $CC supports $1 flag],
89+
AS_TR_SH([cc_cv_ldflags_$1]),
90+
[ac_save_LDFLAGS="$LDFLAGS"
91+
LDFLAGS="$LDFLAGS $1"
92+
AC_LANG_PUSH([C])
93+
AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 1; }])],
94+
[eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"],
95+
[eval "AS_TR_SH([cc_cv_ldflags_$1])="])
96+
AC_LANG_POP([C])
97+
LDFLAGS="$ac_save_LDFLAGS"
98+
])
99+
100+
AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes],
101+
[$2], [$3])
102+
])
103+
104+
dnl define the LDFLAGS_NOUNDEFINED variable with the correct value for
105+
dnl the current linker to avoid undefined references in a shared object.
106+
AC_DEFUN([CC_NOUNDEFINED], [
107+
dnl We check $host for which systems to enable this for.
108+
AC_REQUIRE([AC_CANONICAL_HOST])
109+
110+
case $host in
111+
dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads
112+
dnl are requested, as different implementations are present; to avoid problems
113+
dnl use -Wl,-z,defs only for those platform not behaving this way.
114+
*-freebsd* | *-openbsd*) ;;
115+
*)
116+
dnl First of all check for the --no-undefined variant of GNU ld. This allows
117+
dnl for a much more readable commandline, so that people can understand what
118+
dnl it does without going to look for what the heck -z defs does.
119+
for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do
120+
CC_CHECK_LDFLAGS([$possible_flags], [LDFLAGS_NOUNDEFINED="$possible_flags"])
121+
break
122+
done
123+
;;
124+
esac
125+
126+
AC_SUBST([LDFLAGS_NOUNDEFINED])
127+
])
128+
129+
dnl Check for a -Werror flag or equivalent. -Werror is the GCC
130+
dnl and ICC flag that tells the compiler to treat all the warnings
131+
dnl as fatal. We usually need this option to make sure that some
132+
dnl constructs (like attributes) are not simply ignored.
133+
dnl
134+
dnl Other compilers don't support -Werror per se, but they support
135+
dnl an equivalent flag:
136+
dnl - Sun Studio compiler supports -errwarn=%all
137+
AC_DEFUN([CC_CHECK_WERROR], [
138+
AC_CACHE_CHECK(
139+
[for $CC way to treat warnings as errors],
140+
[cc_cv_werror],
141+
[CC_CHECK_CFLAGS_SILENT([-Werror], [cc_cv_werror=-Werror],
142+
[CC_CHECK_CFLAGS_SILENT([-errwarn=%all], [cc_cv_werror=-errwarn=%all])])
143+
])
144+
])
145+
146+
AC_DEFUN([CC_CHECK_ATTRIBUTE], [
147+
AC_REQUIRE([CC_CHECK_WERROR])
148+
AC_CACHE_CHECK([if $CC supports __attribute__(( ifelse([$2], , [$1], [$2]) ))],
149+
AS_TR_SH([cc_cv_attribute_$1]),
150+
[ac_save_CFLAGS="$CFLAGS"
151+
CFLAGS="$CFLAGS $cc_cv_werror"
152+
AC_LANG_PUSH([C])
153+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([$3])],
154+
[eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"],
155+
[eval "AS_TR_SH([cc_cv_attribute_$1])='no'"])
156+
AC_LANG_POP([C])
157+
CFLAGS="$ac_save_CFLAGS"
158+
])
159+
160+
AS_IF([eval test x$]AS_TR_SH([cc_cv_attribute_$1])[ = xyes],
161+
[AC_DEFINE(
162+
AS_TR_CPP([SUPPORT_ATTRIBUTE_$1]), 1,
163+
[Define this if the compiler supports __attribute__(( ifelse([$2], , [$1], [$2]) ))]
164+
)
165+
$4],
166+
[$5])
167+
])
168+
169+
AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [
170+
CC_CHECK_ATTRIBUTE(
171+
[constructor],,
172+
[void __attribute__((constructor)) ctor() { int a; }],
173+
[$1], [$2])
174+
])
175+
176+
AC_DEFUN([CC_ATTRIBUTE_FORMAT], [
177+
CC_CHECK_ATTRIBUTE(
178+
[format], [format(printf, n, n)],
179+
[void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { fmt = (void *)0; }],
180+
[$1], [$2])
181+
])
182+
183+
AC_DEFUN([CC_ATTRIBUTE_FORMAT_ARG], [
184+
CC_CHECK_ATTRIBUTE(
185+
[format_arg], [format_arg(printf)],
186+
[char *__attribute__((format_arg(1))) gettextlike(const char *fmt) { fmt = (void *)0; }],
187+
[$1], [$2])
188+
])
189+
190+
AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [
191+
CC_CHECK_ATTRIBUTE(
192+
[visibility_$1], [visibility("$1")],
193+
[void __attribute__((visibility("$1"))) $1_function() { }],
194+
[$2], [$3])
195+
])
196+
197+
AC_DEFUN([CC_ATTRIBUTE_NONNULL], [
198+
CC_CHECK_ATTRIBUTE(
199+
[nonnull], [nonnull()],
200+
[void __attribute__((nonnull())) some_function(void *foo, void *bar) { foo = (void*)0; bar = (void*)0; }],
201+
[$1], [$2])
202+
])
203+
204+
AC_DEFUN([CC_ATTRIBUTE_UNUSED], [
205+
CC_CHECK_ATTRIBUTE(
206+
[unused], ,
207+
[void some_function(void *foo, __attribute__((unused)) void *bar);],
208+
[$1], [$2])
209+
])
210+
211+
AC_DEFUN([CC_ATTRIBUTE_SENTINEL], [
212+
CC_CHECK_ATTRIBUTE(
213+
[sentinel], ,
214+
[void some_function(void *foo, ...) __attribute__((sentinel));],
215+
[$1], [$2])
216+
])
217+
218+
AC_DEFUN([CC_ATTRIBUTE_DEPRECATED], [
219+
CC_CHECK_ATTRIBUTE(
220+
[deprecated], ,
221+
[void some_function(void *foo, ...) __attribute__((deprecated));],
222+
[$1], [$2])
223+
])
224+
225+
AC_DEFUN([CC_ATTRIBUTE_ALIAS], [
226+
CC_CHECK_ATTRIBUTE(
227+
[alias], [weak, alias],
228+
[void other_function(void *foo) { }
229+
void some_function(void *foo) __attribute__((weak, alias("other_function")));],
230+
[$1], [$2])
231+
])
232+
233+
AC_DEFUN([CC_ATTRIBUTE_MALLOC], [
234+
CC_CHECK_ATTRIBUTE(
235+
[malloc], ,
236+
[void * __attribute__((malloc)) my_alloc(int n);],
237+
[$1], [$2])
238+
])
239+
240+
AC_DEFUN([CC_ATTRIBUTE_PACKED], [
241+
CC_CHECK_ATTRIBUTE(
242+
[packed], ,
243+
[struct astructure { char a; int b; long c; void *d; } __attribute__((packed));],
244+
[$1], [$2])
245+
])
246+
247+
AC_DEFUN([CC_ATTRIBUTE_CONST], [
248+
CC_CHECK_ATTRIBUTE(
249+
[const], ,
250+
[int __attribute__((const)) twopow(int n) { return 1 << n; } ],
251+
[$1], [$2])
252+
])
253+
254+
AC_DEFUN([CC_FLAG_VISIBILITY], [
255+
AC_REQUIRE([CC_CHECK_WERROR])
256+
AC_CACHE_CHECK([if $CC supports -fvisibility=hidden],
257+
[cc_cv_flag_visibility],
258+
[cc_flag_visibility_save_CFLAGS="$CFLAGS"
259+
CFLAGS="$CFLAGS $cc_cv_werror"
260+
CC_CHECK_CFLAGS_SILENT([-fvisibility=hidden],
261+
cc_cv_flag_visibility='yes',
262+
cc_cv_flag_visibility='no')
263+
CFLAGS="$cc_flag_visibility_save_CFLAGS"])
264+
265+
AS_IF([test "x$cc_cv_flag_visibility" = "xyes"],
266+
[AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1,
267+
[Define this if the compiler supports the -fvisibility flag])
268+
$1],
269+
[$2])
270+
])
271+
272+
AC_DEFUN([CC_FUNC_EXPECT], [
273+
AC_REQUIRE([CC_CHECK_WERROR])
274+
AC_CACHE_CHECK([if compiler has __builtin_expect function],
275+
[cc_cv_func_expect],
276+
[ac_save_CFLAGS="$CFLAGS"
277+
CFLAGS="$CFLAGS $cc_cv_werror"
278+
AC_LANG_PUSH([C])
279+
AC_COMPILE_IFELSE([AC_LANG_SOURCE(
280+
[int some_function() {
281+
int a = 3;
282+
return (int)__builtin_expect(a, 3);
283+
}])],
284+
[cc_cv_func_expect=yes],
285+
[cc_cv_func_expect=no])
286+
AC_LANG_POP([C])
287+
CFLAGS="$ac_save_CFLAGS"
288+
])
289+
290+
AS_IF([test "x$cc_cv_func_expect" = "xyes"],
291+
[AC_DEFINE([SUPPORT__BUILTIN_EXPECT], 1,
292+
[Define this if the compiler supports __builtin_expect() function])
293+
$1],
294+
[$2])
295+
])
296+
297+
AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [
298+
AC_REQUIRE([CC_CHECK_WERROR])
299+
AC_CACHE_CHECK([highest __attribute__ ((aligned ())) supported],
300+
[cc_cv_attribute_aligned],
301+
[ac_save_CFLAGS="$CFLAGS"
302+
CFLAGS="$CFLAGS $cc_cv_werror"
303+
AC_LANG_PUSH([C])
304+
for cc_attribute_align_try in 64 32 16 8 4 2; do
305+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
306+
int main() {
307+
static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0;
308+
return c;
309+
}])], [cc_cv_attribute_aligned=$cc_attribute_align_try; break])
310+
done
311+
AC_LANG_POP([C])
312+
CFLAGS="$ac_save_CFLAGS"
313+
])
314+
315+
if test "x$cc_cv_attribute_aligned" != "x"; then
316+
AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned],
317+
[Define the highest alignment supported])
318+
fi
319+
])

configure.ac

+16
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ GNOME_DEBUG_CHECK
3737
GNOME_COMPILE_WARNINGS([maximum])
3838
GNOME_MAINTAINER_MODE_DEFINES
3939

40+
# Compilation
41+
#
42+
43+
CC_CHECK_CFLAGS_APPEND([ \
44+
-Wall -Wextra \
45+
-Wformat-nonliteral -Werror=format-security \
46+
-Wsign-compare -Werror=implicit-function-declaration \
47+
-Wpointer-arith -Wwrite-strings -Wstrict-prototypes \
48+
-Waggregate-return -Wcast-align -Wimplicit -Wuninitialized \
49+
-Wmissing-prototypes -Wmissing-declarations -Wnested-externs \
50+
-Wpacked -Wmissing-format-attribute -Wshadow \
51+
-Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations \
52+
-Wdeclaration-after-statement -Wold-style-definition \
53+
-Wno-missing-field-initializers -Wno-unused-parameter \
54+
-fno-common -Wno-switch-enum])
55+
4056
AC_PATH_PROG([XSLTPROC], [xsltproc])
4157
if test -z "$XSLTPROC"; then
4258
AC_MSG_ERROR([xsltproc is needed])

po/POTFILES.in

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# List of source files containing translatable strings.
33
# Please keep this file sorted alphabetically.
44
data/org.freedesktop.udisks2.policy.in
5+
src/udisksbasejob.c
56
src/udiskslinuxblock.c
67
src/udiskslinuxdrive.c
78
src/udiskslinuxdriveata.c

0 commit comments

Comments
 (0)