Skip to content

Commit 88b61e3

Browse files
nickdesaulniersmasahir0y
authored andcommitted
Makefile.compiler: replace cc-ifversion with compiler-specific macros
cc-ifversion is GCC specific. Replace it with compiler specific variants. Update the users of cc-ifversion to use these new macros. Link: ClangBuiltLinux/linux#350 Link: https://lore.kernel.org/llvm/CAGG=3QWSAUakO42kubrCap8fp-gm1ERJJAYXTnP1iHk_wrH=BQ@mail.gmail.com/ Suggested-by: Bill Wendling <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Signed-off-by: Nick Desaulniers <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 2e07005 commit 88b61e3

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

Documentation/kbuild/makefiles.rst

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -682,22 +682,27 @@ more details, with real examples.
682682
In the above example, -Wno-unused-but-set-variable will be added to
683683
KBUILD_CFLAGS only if gcc really accepts it.
684684

685-
cc-ifversion
686-
cc-ifversion tests the version of $(CC) and equals the fourth parameter
687-
if version expression is true, or the fifth (if given) if the version
688-
expression is false.
685+
gcc-min-version
686+
gcc-min-version tests if the value of $(CONFIG_GCC_VERSION) is greater than
687+
or equal to the provided value and evaluates to y if so.
689688

690689
Example::
691690

692-
#fs/reiserfs/Makefile
693-
ccflags-y := $(call cc-ifversion, -lt, 0402, -O1)
691+
cflags-$(call gcc-min-version, 70100) := -foo
694692

695-
In this example, ccflags-y will be assigned the value -O1 if the
696-
$(CC) version is less than 4.2.
697-
cc-ifversion takes all the shell operators:
698-
-eq, -ne, -lt, -le, -gt, and -ge
699-
The third parameter may be a text as in this example, but it may also
700-
be an expanded variable or a macro.
693+
In this example, cflags-y will be assigned the value -foo if $(CC) is gcc and
694+
$(CONFIG_GCC_VERSION) is >= 7.1.
695+
696+
clang-min-version
697+
clang-min-version tests if the value of $(CONFIG_CLANG_VERSION) is greater
698+
than or equal to the provided value and evaluates to y if so.
699+
700+
Example::
701+
702+
cflags-$(call clang-min-version, 110000) := -foo
703+
704+
In this example, cflags-y will be assigned the value -foo if $(CC) is clang
705+
and $(CONFIG_CLANG_VERSION) is >= 11.0.0.
701706

702707
cc-cross-prefix
703708
cc-cross-prefix is used to check if there exists a $(CC) in path with

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,6 @@ KBUILD_CFLAGS += $(stackp-flags-y)
790790

791791
KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
792792
KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
793-
KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
794793

795794
ifdef CONFIG_CC_IS_CLANG
796795
KBUILD_CPPFLAGS += -Qunused-arguments
@@ -972,7 +971,6 @@ ifdef CONFIG_CC_IS_GCC
972971
KBUILD_CFLAGS += -Wno-maybe-uninitialized
973972
endif
974973

975-
ifdef CONFIG_CC_IS_GCC
976974
# The allocators already balk at large sizes, so silence the compiler
977975
# warnings for bounds checks involving those possible values. While
978976
# -Wno-alloc-size-larger-than would normally be used here, earlier versions
@@ -984,8 +982,8 @@ ifdef CONFIG_CC_IS_GCC
984982
# ignored, continuing to default to PTRDIFF_MAX. So, left with no other
985983
# choice, we must perform a versioned check to disable this warning.
986984
# https://lore.kernel.org/lkml/[email protected]
987-
KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0901, -Wno-alloc-size-larger-than)
988-
endif
985+
KBUILD_CFLAGS-$(call gcc-min-version, 90100) += -Wno-alloc-size-larger-than
986+
KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
989987

990988
# disable invalid "can't wrap" optimizations for signed / pointers
991989
KBUILD_CFLAGS += -fno-strict-overflow

drivers/gpu/drm/amd/display/dc/dml/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dml_ccflags := -mhard-float -maltivec
3434
endif
3535

3636
ifdef CONFIG_CC_IS_GCC
37-
ifeq ($(call cc-ifversion, -lt, 0701, y), y)
37+
ifneq ($(call gcc-min-version, 70100),y)
3838
IS_OLD_GCC = 1
3939
endif
4040
endif

scripts/Makefile.compiler

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ cc-option-yn = $(call try-run,\
6161
cc-disable-warning = $(call try-run,\
6262
$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
6363

64-
# cc-ifversion
65-
# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
66-
cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4))
64+
# gcc-min-version
65+
# Usage: cflags-$(call gcc-min-version, 70100) += -foo
66+
gcc-min-version = $(shell [ $(CONFIG_GCC_VERSION)0 -ge $(1)0 ] && echo y)
67+
68+
# clang-min-version
69+
# Usage: cflags-$(call clang-min-version, 110000) += -foo
70+
clang-min-version = $(shell [ $(CONFIG_CLANG_VERSION)0 -ge $(1)0 ] && echo y)
6771

6872
# ld-option
6973
# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)

scripts/Makefile.extrawarn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ else
4848
ifdef CONFIG_CC_IS_CLANG
4949
KBUILD_CFLAGS += -Wno-initializer-overrides
5050
# Clang before clang-16 would warn on default argument promotions.
51-
ifeq ($(shell [ $(CONFIG_CLANG_VERSION) -lt 160000 ] && echo y),y)
51+
ifneq ($(call clang-min-version, 160000),y)
5252
# Disable -Wformat
5353
KBUILD_CFLAGS += -Wno-format
5454
# Then re-enable flags that were part of the -Wformat group that aren't
5555
# problematic.
5656
KBUILD_CFLAGS += -Wformat-extra-args -Wformat-invalid-specifier
5757
KBUILD_CFLAGS += -Wformat-zero-length -Wnonnull
5858
# Requires clang-12+.
59-
ifeq ($(shell [ $(CONFIG_CLANG_VERSION) -ge 120000 ] && echo y),y)
59+
ifeq ($(call clang-min-version, 120000),y)
6060
KBUILD_CFLAGS += -Wformat-insufficient-args
6161
endif
6262
endif

0 commit comments

Comments
 (0)