Skip to content

Commit fccb3d3

Browse files
committed
kbuild: add test-{ge,gt,le,lt} macros
GNU Make 4.4 introduced $(intcmp ...), which is useful to compare two integers without forking a new process. Add test-{ge,gt,le,lt} macros, which work more efficiently with GNU Make >= 4.4. For older Make versions, they fall back to the 'test' shell command. The first two parameters to $(intcmp ...) must not be empty. To avoid the syntax error, I appended '0' to them. Fortunately, '00' is treated as '0'. This is needed because CONFIG options may expand to an empty string when the kernel configuration is not included. Signed-off-by: Masahiro Yamada <[email protected]> Acked-by: Palmer Dabbelt <[email protected]> # RISC-V Reviewed-by: Nathan Chancellor <[email protected]> Reviewed-by: Nicolas Schier <[email protected]>
1 parent e441273 commit fccb3d3

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ KBUILD_LDFLAGS += -mllvm -import-instr-limit=5
994994
# Check for frame size exceeding threshold during prolog/epilog insertion
995995
# when using lld < 13.0.0.
996996
ifneq ($(CONFIG_FRAME_WARN),0)
997-
ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0)
997+
ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y)
998998
KBUILD_LDFLAGS += -plugin-opt=-warn-stack-size=$(CONFIG_FRAME_WARN)
999999
endif
10001000
endif

arch/riscv/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ else
3737
endif
3838

3939
ifeq ($(CONFIG_LD_IS_LLD),y)
40-
ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 150000; echo $$?),0)
40+
ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 150000),y)
4141
KBUILD_CFLAGS += -mno-relax
4242
KBUILD_AFLAGS += -mno-relax
4343
ifndef CONFIG_AS_IS_LLVM

arch/x86/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ endif
211211
KBUILD_LDFLAGS += -m elf_$(UTS_MACHINE)
212212

213213
ifdef CONFIG_LTO_CLANG
214-
ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0)
214+
ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y)
215215
KBUILD_LDFLAGS += -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8)
216216
endif
217217
endif

scripts/Kbuild.include

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ space := $(empty) $(empty)
1111
space_escape := _-_SPACE_-_
1212
pound := \#
1313

14+
###
15+
# Comparison macros.
16+
# Usage: $(call test-lt, $(CONFIG_LLD_VERSION), 150000)
17+
#
18+
# Use $(intcmp ...) if supported. (Make >= 4.4)
19+
# Otherwise, fall back to the 'test' shell command.
20+
ifeq ($(intcmp 1,0,,,y),y)
21+
test-ge = $(intcmp $(strip $1)0, $(strip $2)0,,y,y)
22+
test-gt = $(intcmp $(strip $1)0, $(strip $2)0,,,y)
23+
else
24+
test-ge = $(shell test $(strip $1)0 -ge $(strip $2)0 && echo y)
25+
test-gt = $(shell test $(strip $1)0 -gt $(strip $2)0 && echo y)
26+
endif
27+
test-le = $(call test-ge, $2, $1)
28+
test-lt = $(call test-gt, $2, $1)
29+
1430
###
1531
# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
1632
dot-target = $(dir $@).$(notdir $@)

scripts/Makefile.compiler

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ cc-disable-warning = $(call try-run,\
6363

6464
# gcc-min-version
6565
# Usage: cflags-$(call gcc-min-version, 70100) += -foo
66-
gcc-min-version = $(shell [ $(CONFIG_GCC_VERSION)0 -ge $(1)0 ] && echo y)
66+
gcc-min-version = $(call test-ge, $(CONFIG_GCC_VERSION), $1)
6767

6868
# clang-min-version
6969
# Usage: cflags-$(call clang-min-version, 110000) += -foo
70-
clang-min-version = $(shell [ $(CONFIG_CLANG_VERSION)0 -ge $(1)0 ] && echo y)
70+
clang-min-version = $(call test-ge, $(CONFIG_CLANG_VERSION), $1)
7171

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

0 commit comments

Comments
 (0)