diff options
author | Junio C Hamano <gitster@pobox.com> | 2018-03-31 22:02:22 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-03-31 22:02:22 -0700 |
commit | b3c4d6317fd731ed3dc0f565207b976621315a25 (patch) | |
tree | 072ba6a43da0eeb5df7998edbdca72e6336d796a | |
parent | f1c7e1ecb38a2c7293e71e3380ba3b4f6ed485bc (diff) | |
parent | 86fc3ff3bd4c7f66f23ee3328e964470d0a8dbb7 (diff) | |
download | git-b3c4d6317fd731ed3dc0f565207b976621315a25.tar.gz |
Merge branch 'nd/warn-more-for-devs' into jch
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 EAGER_DEVELOPER=YesPlease"
available now, for those who want to help fixing warnings we
usually ignore.
* nd/warn-more-for-devs:
Makefile: add EAGER_DEVELOPER mode
Makefile: detect compiler and enable more warnings in DEVELOPER=1
connect.c: mark die_initial_contact() NORETURN
-rw-r--r-- | Makefile | 20 | ||||
-rw-r--r-- | config.mak.dev | 42 | ||||
-rw-r--r-- | connect.c | 2 | ||||
-rwxr-xr-x | detect-compiler | 53 |
4 files changed, 106 insertions, 11 deletions
@@ -464,6 +464,12 @@ all:: # When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers # the global variable _wpgmptr containing the absolute path of the current # executable (this is the case on Windows). +# +# Define DEVELOPER to enable more compiler warnings. Compiler version +# and faimily are auto detected, but could be overridden by defining +# COMPILER_FEATURES (see config.mak.dev). +# Define EAGER_DEVELOPER keeps compiler warnings non-fatal, but no warning +# class is suppressed anymore. GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -472,15 +478,6 @@ GIT-VERSION-FILE: FORCE # CFLAGS and LDFLAGS are for the users to override from the command line. CFLAGS = -g -O2 -Wall -DEVELOPER_CFLAGS = -Werror \ - -Wdeclaration-after-statement \ - -Wno-format-zero-length \ - -Wold-style-definition \ - -Woverflow \ - -Wpointer-arith \ - -Wstrict-prototypes \ - -Wunused \ - -Wvla LDFLAGS = ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS) ALL_LDFLAGS = $(LDFLAGS) @@ -1096,8 +1093,11 @@ include config.mak.uname -include config.mak.autogen -include config.mak +ifdef EAGER_DEVELOPER +DEVELOPER = Yes +endif ifdef DEVELOPER -CFLAGS += $(DEVELOPER_CFLAGS) +include config.mak.dev endif comma := , diff --git a/config.mak.dev b/config.mak.dev new file mode 100644 index 0000000000..13883410b3 --- /dev/null +++ b/config.mak.dev @@ -0,0 +1,42 @@ +ifndef EAGER_DEVELOPER +CFLAGS += -Werror +endif +CFLAGS += -Wdeclaration-after-statement +CFLAGS += -Wno-format-zero-length +CFLAGS += -Wold-style-definition +CFLAGS += -Woverflow +CFLAGS += -Wpointer-arith +CFLAGS += -Wstrict-prototypes +CFLAGS += -Wunused +CFLAGS += -Wvla + +ifndef COMPILER_FEATURES +COMPILER_FEATURES := $(shell ./detect-compiler $(CC)) +endif + +ifneq ($(filter clang4,$(COMPILER_FEATURES)),) +CFLAGS += -Wtautological-constant-out-of-range-compare +endif + +ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter clang4,$(COMPILER_FEATURES))),) +CFLAGS += -Wextra +# if a function is public, there should be a prototype and the right +# header file should be included. If not, it should be static. +CFLAGS += -Wmissing-prototypes +ifndef EAGER_DEVELOPER +# These are disabled because we have these all over the place. +CFLAGS += -Wno-empty-body +CFLAGS += -Wno-missing-field-initializers +CFLAGS += -Wno-sign-compare +CFLAGS += -Wno-unused-function +CFLAGS += -Wno-unused-parameter +endif +endif + +# uninitialized warnings on gcc 4.9.2 in xdiff/xdiffi.c and config.c +# not worth fixing since newer compilers correctly stop complaining +ifneq ($(filter gcc4,$(COMPILER_FEATURES)),) +ifeq ($(filter gcc5,$(COMPILER_FEATURES)),) +CFLAGS += -Wno-uninitialized +endif +endif @@ -48,7 +48,7 @@ int check_ref_type(const struct ref *ref, int flags) return check_ref(ref->name, flags); } -static void die_initial_contact(int unexpected) +static NORETURN void die_initial_contact(int unexpected) { /* * A hang-up after seeing some response from the other end diff --git a/detect-compiler b/detect-compiler new file mode 100755 index 0000000000..70b754481c --- /dev/null +++ b/detect-compiler @@ -0,0 +1,53 @@ +#!/bin/sh +# +# Probe the compiler for vintage, version, etc. This is used for setting +# optional make knobs under the DEVELOPER knob. + +CC="$*" + +# we get something like (this is at least true for gcc and clang) +# +# FreeBSD clang version 3.4.1 (tags/RELEASE...) +get_version_line() { + $CC -v 2>&1 | grep ' version ' +} + +get_family() { + get_version_line | sed 's/^\(.*\) version [0-9][^ ]* .*/\1/' +} + +get_version() { + get_version_line | sed 's/^.* version \([0-9][^ ]*\) .*/\1/' +} + +print_flags() { + family=$1 + version=$(get_version | cut -f 1 -d .) + + # Print a feature flag not only for the current version, but also + # for any prior versions we encompass. This avoids needing to do + # numeric comparisons in make, which are awkward. + while test "$version" -gt 0 + do + echo $family$version + version=$((version - 1)) + done +} + +case "$(get_family)" in +gcc) + print_flags gcc + ;; +clang) + print_flags clang + ;; +"FreeBSD clang") + print_flags clang + ;; +"Apple LLVM") + print_flags clang + ;; +*) + : unknown compiler family + ;; +esac |