blob: 1ce4c7061379113201e195a267e3ec0ed596debb [file] [log] [blame]
Carlo Marcelo Arenas Belón27e0c3c2021-09-03 10:02:31 -07001ifndef COMPILER_FEATURES
2COMPILER_FEATURES := $(shell ./detect-compiler $(CC))
3endif
4
Ævar Arnfjörð Bjarmason99f763b2018-04-14 19:19:45 +00005ifeq ($(filter no-error,$(DEVOPTS)),)
Ævar Arnfjörð Bjarmason6d5d4b42019-02-22 15:41:27 +01006DEVELOPER_CFLAGS += -Werror
Junio C Hamano521dc562020-10-31 15:22:08 -07007SPARSE_FLAGS += -Wsparse-error
Ævar Arnfjörð Bjarmason99f763b2018-04-14 19:19:45 +00008endif
Carlo Marcelo Arenas Belónebd2e4a2021-09-28 20:19:40 -07009
Carlo Marcelo Arenas Belón27e0c3c2021-09-03 10:02:31 -070010DEVELOPER_CFLAGS += -Wall
Carlo Marcelo Arenas Belón6a8cbc42021-09-03 10:02:32 -070011ifeq ($(filter no-pedantic,$(DEVOPTS)),)
Ævar Arnfjörð Bjarmason6d5d4b42019-02-22 15:41:27 +010012DEVELOPER_CFLAGS += -pedantic
Carlo Marcelo Arenas Belónebd2e4a2021-09-28 20:19:40 -070013ifneq (($or $(filter gcc5,$(COMPILER_FEATURES)),$(filter clang4,$(COMPILER_FEATURES))),)
Carlo Marcelo Arenas Belón6a8cbc42021-09-03 10:02:32 -070014DEVELOPER_CFLAGS += -Wpedantic
Carlo Marcelo Arenas Belónebd2e4a2021-09-28 20:19:40 -070015ifneq ($(filter gcc10,$(COMPILER_FEATURES)),)
16ifeq ($(uname_S),MINGW)
Carlo Marcelo Arenas Belón6a8cbc42021-09-03 10:02:32 -070017DEVELOPER_CFLAGS += -Wno-pedantic-ms-format
Beat Bolli729b3922018-07-24 21:26:43 +020018endif
Carlo Marcelo Arenas Belón27e0c3c2021-09-03 10:02:31 -070019endif
Carlo Marcelo Arenas Belónebd2e4a2021-09-28 20:19:40 -070020endif
21endif
Jeff King5f463852021-12-08 14:50:54 -050022
Junio C Hamano2b95d942022-01-18 09:47:39 -080023ifneq ($(uname_S),FreeBSD)
Jeff King5f463852021-12-08 14:50:54 -050024ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter clang7,$(COMPILER_FEATURES))),)
25DEVELOPER_CFLAGS += -std=gnu99
26endif
Junio C Hamano2b95d942022-01-18 09:47:39 -080027else
28# FreeBSD cannot limit to C99 because its system headers unconditionally
29# rely on C11 features.
30endif
Jeff King5f463852021-12-08 14:50:54 -050031
Ævar Arnfjörð Bjarmason6d5d4b42019-02-22 15:41:27 +010032DEVELOPER_CFLAGS += -Wdeclaration-after-statement
33DEVELOPER_CFLAGS += -Wformat-security
Ævar Arnfjörð Bjarmason6d5d4b42019-02-22 15:41:27 +010034DEVELOPER_CFLAGS += -Wold-style-definition
35DEVELOPER_CFLAGS += -Woverflow
36DEVELOPER_CFLAGS += -Wpointer-arith
37DEVELOPER_CFLAGS += -Wstrict-prototypes
38DEVELOPER_CFLAGS += -Wunused
39DEVELOPER_CFLAGS += -Wvla
Patrick Steinhardtd66fe072024-06-07 08:39:40 +020040DEVELOPER_CFLAGS += -Wwrite-strings
Jeff King55391832020-10-15 15:30:29 -040041DEVELOPER_CFLAGS += -fno-common
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000042
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000043ifneq ($(filter clang4,$(COMPILER_FEATURES)),)
Ævar Arnfjörð Bjarmason6d5d4b42019-02-22 15:41:27 +010044DEVELOPER_CFLAGS += -Wtautological-constant-out-of-range-compare
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000045endif
46
47ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter clang4,$(COMPILER_FEATURES))),)
Ævar Arnfjörð Bjarmason6d5d4b42019-02-22 15:41:27 +010048DEVELOPER_CFLAGS += -Wextra
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000049# if a function is public, there should be a prototype and the right
50# header file should be included. If not, it should be static.
Ævar Arnfjörð Bjarmason6d5d4b42019-02-22 15:41:27 +010051DEVELOPER_CFLAGS += -Wmissing-prototypes
Ævar Arnfjörð Bjarmason26d2e4f2018-04-14 19:19:46 +000052ifeq ($(filter extra-all,$(DEVOPTS)),)
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000053# These are disabled because we have these all over the place.
Ævar Arnfjörð Bjarmason6d5d4b42019-02-22 15:41:27 +010054DEVELOPER_CFLAGS += -Wno-empty-body
55DEVELOPER_CFLAGS += -Wno-missing-field-initializers
56DEVELOPER_CFLAGS += -Wno-sign-compare
57DEVELOPER_CFLAGS += -Wno-unused-parameter
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000058endif
Ævar Arnfjörð Bjarmason26d2e4f2018-04-14 19:19:46 +000059endif
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000060
61# uninitialized warnings on gcc 4.9.2 in xdiff/xdiffi.c and config.c
62# not worth fixing since newer compilers correctly stop complaining
Jeff Kingb53a5f22022-07-29 15:53:53 -040063#
64# Likewise, gcc older than 4.9 complains about initializing a
65# struct-within-a-struct using just "{ 0 }"
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000066ifneq ($(filter gcc4,$(COMPILER_FEATURES)),)
67ifeq ($(filter gcc5,$(COMPILER_FEATURES)),)
Ævar Arnfjörð Bjarmason6d5d4b42019-02-22 15:41:27 +010068DEVELOPER_CFLAGS += -Wno-uninitialized
Jeff Kingb53a5f22022-07-29 15:53:53 -040069DEVELOPER_CFLAGS += -Wno-missing-braces
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000070endif
71endif
Jeff King5338ed22020-10-21 23:24:00 -040072
Jeff Hostetler54795d32022-10-10 15:39:00 +000073# Old versions of clang complain about initializaing a
74# struct-within-a-struct using just "{0}" rather than "{{0}}". This
75# error is considered a false-positive and not worth fixing, because
76# new clang versions do not, so just disable it.
77#
78# The "bug" was fixed in upstream clang 9.
79#
80# Complicating this is that versions of clang released by Apple have
81# their own version numbers (associated with the corresponding version
82# of XCode) unrelated to the official clang version numbers.
83#
84# The bug was fixed in Apple clang 12.
85#
86ifneq ($(filter clang1,$(COMPILER_FEATURES)),) # if we are using clang
87ifeq ($(uname_S),Darwin) # if we are on darwin
88ifeq ($(filter clang12,$(COMPILER_FEATURES)),) # if version < 12
89DEVELOPER_CFLAGS += -Wno-missing-braces
90endif
91else # not darwin
92ifeq ($(filter clang9,$(COMPILER_FEATURES)),) # if version < 9
93DEVELOPER_CFLAGS += -Wno-missing-braces
94endif
95endif
96endif
97
Carlo Marcelo Arenas Belón846a29a2022-04-15 16:13:41 -070098# https://bugzilla.redhat.com/show_bug.cgi?id=2075786
99ifneq ($(filter gcc12,$(COMPILER_FEATURES)),)
100DEVELOPER_CFLAGS += -Wno-error=stringop-overread
101endif
102
Jeff King5338ed22020-10-21 23:24:00 -0400103GIT_TEST_PERL_FATAL_WARNINGS = YesPlease