blob: 981304727c52c99b3e6c3d7179cab78e91d9ff92 [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
Jeff King55391832020-10-15 15:30:29 -040040DEVELOPER_CFLAGS += -fno-common
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000041
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000042ifneq ($(filter clang4,$(COMPILER_FEATURES)),)
Ævar Arnfjörð Bjarmason6d5d4b42019-02-22 15:41:27 +010043DEVELOPER_CFLAGS += -Wtautological-constant-out-of-range-compare
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000044endif
45
46ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter clang4,$(COMPILER_FEATURES))),)
Ævar Arnfjörð Bjarmason6d5d4b42019-02-22 15:41:27 +010047DEVELOPER_CFLAGS += -Wextra
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000048# if a function is public, there should be a prototype and the right
49# header file should be included. If not, it should be static.
Ævar Arnfjörð Bjarmason6d5d4b42019-02-22 15:41:27 +010050DEVELOPER_CFLAGS += -Wmissing-prototypes
Ævar Arnfjörð Bjarmason26d2e4f2018-04-14 19:19:46 +000051ifeq ($(filter extra-all,$(DEVOPTS)),)
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000052# These are disabled because we have these all over the place.
Ævar Arnfjörð Bjarmason6d5d4b42019-02-22 15:41:27 +010053DEVELOPER_CFLAGS += -Wno-empty-body
54DEVELOPER_CFLAGS += -Wno-missing-field-initializers
55DEVELOPER_CFLAGS += -Wno-sign-compare
56DEVELOPER_CFLAGS += -Wno-unused-parameter
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000057endif
Ævar Arnfjörð Bjarmason26d2e4f2018-04-14 19:19:46 +000058endif
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000059
60# uninitialized warnings on gcc 4.9.2 in xdiff/xdiffi.c and config.c
61# not worth fixing since newer compilers correctly stop complaining
Jeff Kingb53a5f22022-07-29 15:53:53 -040062#
63# Likewise, gcc older than 4.9 complains about initializing a
64# struct-within-a-struct using just "{ 0 }"
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000065ifneq ($(filter gcc4,$(COMPILER_FEATURES)),)
66ifeq ($(filter gcc5,$(COMPILER_FEATURES)),)
Ævar Arnfjörð Bjarmason6d5d4b42019-02-22 15:41:27 +010067DEVELOPER_CFLAGS += -Wno-uninitialized
Jeff Kingb53a5f22022-07-29 15:53:53 -040068DEVELOPER_CFLAGS += -Wno-missing-braces
Nguyễn Thái Ngọc Duy1da15802018-04-14 19:19:44 +000069endif
70endif
Jeff King5338ed22020-10-21 23:24:00 -040071
Jeff Hostetler54795d32022-10-10 15:39:00 +000072# Old versions of clang complain about initializaing a
73# struct-within-a-struct using just "{0}" rather than "{{0}}". This
74# error is considered a false-positive and not worth fixing, because
75# new clang versions do not, so just disable it.
76#
77# The "bug" was fixed in upstream clang 9.
78#
79# Complicating this is that versions of clang released by Apple have
80# their own version numbers (associated with the corresponding version
81# of XCode) unrelated to the official clang version numbers.
82#
83# The bug was fixed in Apple clang 12.
84#
85ifneq ($(filter clang1,$(COMPILER_FEATURES)),) # if we are using clang
86ifeq ($(uname_S),Darwin) # if we are on darwin
87ifeq ($(filter clang12,$(COMPILER_FEATURES)),) # if version < 12
88DEVELOPER_CFLAGS += -Wno-missing-braces
89endif
90else # not darwin
91ifeq ($(filter clang9,$(COMPILER_FEATURES)),) # if version < 9
92DEVELOPER_CFLAGS += -Wno-missing-braces
93endif
94endif
95endif
96
Carlo Marcelo Arenas Belón846a29a2022-04-15 16:13:41 -070097# https://bugzilla.redhat.com/show_bug.cgi?id=2075786
98ifneq ($(filter gcc12,$(COMPILER_FEATURES)),)
99DEVELOPER_CFLAGS += -Wno-error=stringop-overread
100endif
101
Jeff King5338ed22020-10-21 23:24:00 -0400102GIT_TEST_PERL_FATAL_WARNINGS = YesPlease