Skip to content

Commit e998e7a

Browse files
committed
Merge branch 'nd/warn-more-for-devs'
The build procedure "make DEVELOPER=YesPlease" learned to enable a bit more warning options depending on the compiler used to help developers more. There also is "make DEVOPTS=tokens" knob available now, for those who want to help fixing warnings we usually ignore, for example. * nd/warn-more-for-devs: Makefile: add a DEVOPTS to get all of -Wextra Makefile: add a DEVOPTS to suppress -Werror under DEVELOPER Makefile: detect compiler and enable more warnings in DEVELOPER=1 connect.c: mark die_initial_contact() NORETURN
2 parents 174774c + 26d2e4f commit e998e7a

File tree

4 files changed

+117
-11
lines changed

4 files changed

+117
-11
lines changed

Makefile

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,26 @@ all::
464464
# When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
465465
# the global variable _wpgmptr containing the absolute path of the current
466466
# executable (this is the case on Windows).
467+
#
468+
# Define DEVELOPER to enable more compiler warnings. Compiler version
469+
# and family are auto detected, but could be overridden by defining
470+
# COMPILER_FEATURES (see config.mak.dev)
471+
#
472+
# When DEVELOPER is set, DEVOPTS can be used to control compiler
473+
# options. This variable contains keywords separated by
474+
# whitespace. The following keywords are are recognized:
475+
#
476+
# no-error:
477+
#
478+
# suppresses the -Werror that implicitly comes with
479+
# DEVELOPER=1. Useful for getting the full set of errors
480+
# without immediately dying, or for logging them.
481+
#
482+
# extra-all:
483+
#
484+
# The DEVELOPER mode enables -Wextra with a few exceptions. By
485+
# setting this flag the exceptions are removed, and all of
486+
# -Wextra is used.
467487

468488
GIT-VERSION-FILE: FORCE
469489
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -472,15 +492,6 @@ GIT-VERSION-FILE: FORCE
472492
# CFLAGS and LDFLAGS are for the users to override from the command line.
473493

474494
CFLAGS = -g -O2 -Wall
475-
DEVELOPER_CFLAGS = -Werror \
476-
-Wdeclaration-after-statement \
477-
-Wno-format-zero-length \
478-
-Wold-style-definition \
479-
-Woverflow \
480-
-Wpointer-arith \
481-
-Wstrict-prototypes \
482-
-Wunused \
483-
-Wvla
484495
LDFLAGS =
485496
ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)
486497
ALL_LDFLAGS = $(LDFLAGS)
@@ -1098,7 +1109,7 @@ include config.mak.uname
10981109
-include config.mak
10991110

11001111
ifdef DEVELOPER
1101-
CFLAGS += $(DEVELOPER_CFLAGS)
1112+
include config.mak.dev
11021113
endif
11031114

11041115
comma := ,

config.mak.dev

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
ifeq ($(filter no-error,$(DEVOPTS)),)
2+
CFLAGS += -Werror
3+
endif
4+
CFLAGS += -Wdeclaration-after-statement
5+
CFLAGS += -Wno-format-zero-length
6+
CFLAGS += -Wold-style-definition
7+
CFLAGS += -Woverflow
8+
CFLAGS += -Wpointer-arith
9+
CFLAGS += -Wstrict-prototypes
10+
CFLAGS += -Wunused
11+
CFLAGS += -Wvla
12+
13+
ifndef COMPILER_FEATURES
14+
COMPILER_FEATURES := $(shell ./detect-compiler $(CC))
15+
endif
16+
17+
ifneq ($(filter clang4,$(COMPILER_FEATURES)),)
18+
CFLAGS += -Wtautological-constant-out-of-range-compare
19+
endif
20+
21+
ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter clang4,$(COMPILER_FEATURES))),)
22+
CFLAGS += -Wextra
23+
# if a function is public, there should be a prototype and the right
24+
# header file should be included. If not, it should be static.
25+
CFLAGS += -Wmissing-prototypes
26+
ifeq ($(filter extra-all,$(DEVOPTS)),)
27+
# These are disabled because we have these all over the place.
28+
CFLAGS += -Wno-empty-body
29+
CFLAGS += -Wno-missing-field-initializers
30+
CFLAGS += -Wno-sign-compare
31+
CFLAGS += -Wno-unused-function
32+
CFLAGS += -Wno-unused-parameter
33+
endif
34+
endif
35+
36+
# uninitialized warnings on gcc 4.9.2 in xdiff/xdiffi.c and config.c
37+
# not worth fixing since newer compilers correctly stop complaining
38+
ifneq ($(filter gcc4,$(COMPILER_FEATURES)),)
39+
ifeq ($(filter gcc5,$(COMPILER_FEATURES)),)
40+
CFLAGS += -Wno-uninitialized
41+
endif
42+
endif

connect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int check_ref_type(const struct ref *ref, int flags)
4848
return check_ref(ref->name, flags);
4949
}
5050

51-
static void die_initial_contact(int unexpected)
51+
static NORETURN void die_initial_contact(int unexpected)
5252
{
5353
/*
5454
* A hang-up after seeing some response from the other end

detect-compiler

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh
2+
#
3+
# Probe the compiler for vintage, version, etc. This is used for setting
4+
# optional make knobs under the DEVELOPER knob.
5+
6+
CC="$*"
7+
8+
# we get something like (this is at least true for gcc and clang)
9+
#
10+
# FreeBSD clang version 3.4.1 (tags/RELEASE...)
11+
get_version_line() {
12+
$CC -v 2>&1 | grep ' version '
13+
}
14+
15+
get_family() {
16+
get_version_line | sed 's/^\(.*\) version [0-9][^ ]* .*/\1/'
17+
}
18+
19+
get_version() {
20+
get_version_line | sed 's/^.* version \([0-9][^ ]*\) .*/\1/'
21+
}
22+
23+
print_flags() {
24+
family=$1
25+
version=$(get_version | cut -f 1 -d .)
26+
27+
# Print a feature flag not only for the current version, but also
28+
# for any prior versions we encompass. This avoids needing to do
29+
# numeric comparisons in make, which are awkward.
30+
while test "$version" -gt 0
31+
do
32+
echo $family$version
33+
version=$((version - 1))
34+
done
35+
}
36+
37+
case "$(get_family)" in
38+
gcc)
39+
print_flags gcc
40+
;;
41+
clang)
42+
print_flags clang
43+
;;
44+
"FreeBSD clang")
45+
print_flags clang
46+
;;
47+
"Apple LLVM")
48+
print_flags clang
49+
;;
50+
*)
51+
: unknown compiler family
52+
;;
53+
esac

0 commit comments

Comments
 (0)