Carlo Marcelo Arenas Belón | 27e0c3c | 2021-09-03 10:02:31 -0700 | [diff] [blame] | 1 | ifndef COMPILER_FEATURES |
| 2 | COMPILER_FEATURES := $(shell ./detect-compiler $(CC)) |
| 3 | endif |
| 4 | |
Ævar Arnfjörð Bjarmason | 99f763b | 2018-04-14 19:19:45 +0000 | [diff] [blame] | 5 | ifeq ($(filter no-error,$(DEVOPTS)),) |
Ævar Arnfjörð Bjarmason | 6d5d4b4 | 2019-02-22 15:41:27 +0100 | [diff] [blame] | 6 | DEVELOPER_CFLAGS += -Werror |
Junio C Hamano | 521dc56 | 2020-10-31 15:22:08 -0700 | [diff] [blame] | 7 | SPARSE_FLAGS += -Wsparse-error |
Ævar Arnfjörð Bjarmason | 99f763b | 2018-04-14 19:19:45 +0000 | [diff] [blame] | 8 | endif |
Carlo Marcelo Arenas Belón | ebd2e4a | 2021-09-28 20:19:40 -0700 | [diff] [blame] | 9 | |
Carlo Marcelo Arenas Belón | 27e0c3c | 2021-09-03 10:02:31 -0700 | [diff] [blame] | 10 | DEVELOPER_CFLAGS += -Wall |
Carlo Marcelo Arenas Belón | 6a8cbc4 | 2021-09-03 10:02:32 -0700 | [diff] [blame] | 11 | ifeq ($(filter no-pedantic,$(DEVOPTS)),) |
Ævar Arnfjörð Bjarmason | 6d5d4b4 | 2019-02-22 15:41:27 +0100 | [diff] [blame] | 12 | DEVELOPER_CFLAGS += -pedantic |
Carlo Marcelo Arenas Belón | ebd2e4a | 2021-09-28 20:19:40 -0700 | [diff] [blame] | 13 | ifneq (($or $(filter gcc5,$(COMPILER_FEATURES)),$(filter clang4,$(COMPILER_FEATURES))),) |
Carlo Marcelo Arenas Belón | 6a8cbc4 | 2021-09-03 10:02:32 -0700 | [diff] [blame] | 14 | DEVELOPER_CFLAGS += -Wpedantic |
Carlo Marcelo Arenas Belón | ebd2e4a | 2021-09-28 20:19:40 -0700 | [diff] [blame] | 15 | ifneq ($(filter gcc10,$(COMPILER_FEATURES)),) |
| 16 | ifeq ($(uname_S),MINGW) |
Carlo Marcelo Arenas Belón | 6a8cbc4 | 2021-09-03 10:02:32 -0700 | [diff] [blame] | 17 | DEVELOPER_CFLAGS += -Wno-pedantic-ms-format |
Beat Bolli | 729b392 | 2018-07-24 21:26:43 +0200 | [diff] [blame] | 18 | endif |
Carlo Marcelo Arenas Belón | 27e0c3c | 2021-09-03 10:02:31 -0700 | [diff] [blame] | 19 | endif |
Carlo Marcelo Arenas Belón | ebd2e4a | 2021-09-28 20:19:40 -0700 | [diff] [blame] | 20 | endif |
| 21 | endif |
Jeff King | 5f46385 | 2021-12-08 14:50:54 -0500 | [diff] [blame] | 22 | |
Junio C Hamano | 2b95d94 | 2022-01-18 09:47:39 -0800 | [diff] [blame] | 23 | ifneq ($(uname_S),FreeBSD) |
Jeff King | 5f46385 | 2021-12-08 14:50:54 -0500 | [diff] [blame] | 24 | ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter clang7,$(COMPILER_FEATURES))),) |
| 25 | DEVELOPER_CFLAGS += -std=gnu99 |
| 26 | endif |
Junio C Hamano | 2b95d94 | 2022-01-18 09:47:39 -0800 | [diff] [blame] | 27 | else |
| 28 | # FreeBSD cannot limit to C99 because its system headers unconditionally |
| 29 | # rely on C11 features. |
| 30 | endif |
Jeff King | 5f46385 | 2021-12-08 14:50:54 -0500 | [diff] [blame] | 31 | |
Ævar Arnfjörð Bjarmason | 6d5d4b4 | 2019-02-22 15:41:27 +0100 | [diff] [blame] | 32 | DEVELOPER_CFLAGS += -Wdeclaration-after-statement |
| 33 | DEVELOPER_CFLAGS += -Wformat-security |
Ævar Arnfjörð Bjarmason | 6d5d4b4 | 2019-02-22 15:41:27 +0100 | [diff] [blame] | 34 | DEVELOPER_CFLAGS += -Wold-style-definition |
| 35 | DEVELOPER_CFLAGS += -Woverflow |
| 36 | DEVELOPER_CFLAGS += -Wpointer-arith |
| 37 | DEVELOPER_CFLAGS += -Wstrict-prototypes |
| 38 | DEVELOPER_CFLAGS += -Wunused |
| 39 | DEVELOPER_CFLAGS += -Wvla |
Jeff King | 5539183 | 2020-10-15 15:30:29 -0400 | [diff] [blame] | 40 | DEVELOPER_CFLAGS += -fno-common |
Nguyễn Thái Ngọc Duy | 1da1580 | 2018-04-14 19:19:44 +0000 | [diff] [blame] | 41 | |
Nguyễn Thái Ngọc Duy | 1da1580 | 2018-04-14 19:19:44 +0000 | [diff] [blame] | 42 | ifneq ($(filter clang4,$(COMPILER_FEATURES)),) |
Ævar Arnfjörð Bjarmason | 6d5d4b4 | 2019-02-22 15:41:27 +0100 | [diff] [blame] | 43 | DEVELOPER_CFLAGS += -Wtautological-constant-out-of-range-compare |
Nguyễn Thái Ngọc Duy | 1da1580 | 2018-04-14 19:19:44 +0000 | [diff] [blame] | 44 | endif |
| 45 | |
| 46 | ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter clang4,$(COMPILER_FEATURES))),) |
Ævar Arnfjörð Bjarmason | 6d5d4b4 | 2019-02-22 15:41:27 +0100 | [diff] [blame] | 47 | DEVELOPER_CFLAGS += -Wextra |
Nguyễn Thái Ngọc Duy | 1da1580 | 2018-04-14 19:19:44 +0000 | [diff] [blame] | 48 | # 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ð Bjarmason | 6d5d4b4 | 2019-02-22 15:41:27 +0100 | [diff] [blame] | 50 | DEVELOPER_CFLAGS += -Wmissing-prototypes |
Ævar Arnfjörð Bjarmason | 26d2e4f | 2018-04-14 19:19:46 +0000 | [diff] [blame] | 51 | ifeq ($(filter extra-all,$(DEVOPTS)),) |
Nguyễn Thái Ngọc Duy | 1da1580 | 2018-04-14 19:19:44 +0000 | [diff] [blame] | 52 | # These are disabled because we have these all over the place. |
Ævar Arnfjörð Bjarmason | 6d5d4b4 | 2019-02-22 15:41:27 +0100 | [diff] [blame] | 53 | DEVELOPER_CFLAGS += -Wno-empty-body |
| 54 | DEVELOPER_CFLAGS += -Wno-missing-field-initializers |
| 55 | DEVELOPER_CFLAGS += -Wno-sign-compare |
| 56 | DEVELOPER_CFLAGS += -Wno-unused-parameter |
Nguyễn Thái Ngọc Duy | 1da1580 | 2018-04-14 19:19:44 +0000 | [diff] [blame] | 57 | endif |
Ævar Arnfjörð Bjarmason | 26d2e4f | 2018-04-14 19:19:46 +0000 | [diff] [blame] | 58 | endif |
Nguyễn Thái Ngọc Duy | 1da1580 | 2018-04-14 19:19:44 +0000 | [diff] [blame] | 59 | |
| 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 King | b53a5f2 | 2022-07-29 15:53:53 -0400 | [diff] [blame] | 62 | # |
| 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 Duy | 1da1580 | 2018-04-14 19:19:44 +0000 | [diff] [blame] | 65 | ifneq ($(filter gcc4,$(COMPILER_FEATURES)),) |
| 66 | ifeq ($(filter gcc5,$(COMPILER_FEATURES)),) |
Ævar Arnfjörð Bjarmason | 6d5d4b4 | 2019-02-22 15:41:27 +0100 | [diff] [blame] | 67 | DEVELOPER_CFLAGS += -Wno-uninitialized |
Jeff King | b53a5f2 | 2022-07-29 15:53:53 -0400 | [diff] [blame] | 68 | DEVELOPER_CFLAGS += -Wno-missing-braces |
Nguyễn Thái Ngọc Duy | 1da1580 | 2018-04-14 19:19:44 +0000 | [diff] [blame] | 69 | endif |
| 70 | endif |
Jeff King | 5338ed2 | 2020-10-21 23:24:00 -0400 | [diff] [blame] | 71 | |
Jeff Hostetler | 54795d3 | 2022-10-10 15:39:00 +0000 | [diff] [blame] | 72 | # 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 | # |
| 85 | ifneq ($(filter clang1,$(COMPILER_FEATURES)),) # if we are using clang |
| 86 | ifeq ($(uname_S),Darwin) # if we are on darwin |
| 87 | ifeq ($(filter clang12,$(COMPILER_FEATURES)),) # if version < 12 |
| 88 | DEVELOPER_CFLAGS += -Wno-missing-braces |
| 89 | endif |
| 90 | else # not darwin |
| 91 | ifeq ($(filter clang9,$(COMPILER_FEATURES)),) # if version < 9 |
| 92 | DEVELOPER_CFLAGS += -Wno-missing-braces |
| 93 | endif |
| 94 | endif |
| 95 | endif |
| 96 | |
Carlo Marcelo Arenas Belón | 846a29a | 2022-04-15 16:13:41 -0700 | [diff] [blame] | 97 | # https://bugzilla.redhat.com/show_bug.cgi?id=2075786 |
| 98 | ifneq ($(filter gcc12,$(COMPILER_FEATURES)),) |
| 99 | DEVELOPER_CFLAGS += -Wno-error=stringop-overread |
| 100 | endif |
| 101 | |
Jeff King | 5338ed2 | 2020-10-21 23:24:00 -0400 | [diff] [blame] | 102 | GIT_TEST_PERL_FATAL_WARNINGS = YesPlease |