kbuild: add test-{le,ge,lt,gt} macros
PATCH v2 1/5 kbuild: add test-{le,ge,lt,gt} macros
Because GNU Make is only able to handle strings, it is very hard to perform arighmetic in Makefiles.
When we compare two integers, we invokes shell. One example is in the top Makefile:
ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0)
This is more expensive than using built-in functions since it forks a process.
If we know the two have the same number of digits, we can do better.
This commit adds four macros, test-le, test-ge, test-lt, test-gt.
$(call test-lt, A, B) is evaluated to 'y' if A is less than B, or empty otherwise. This will replace $(call shell test A -lt B).
Again, the limitation is that A and B must have the same number of digits because these macros are based on $(sort ) function.
$(call test-lt, 1, 9) --> y (Works!) $(call test-lt, 10, 9) --> y (Not work...)
To make the latter work, you need to add '0' prefix to align the number of digits:
$(call test-lt, 10, 09) --> empty (Works!)
Actually, we can live with this limitation in many places. As for the example above, we know $(CONFIG_LLD_VERSION) is 6-digits because the minimal supported version of LLVM is 11.0.0.
So, the shell invocation can be replaced with more efficient code:
ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y)
Of course, this assumption will break when LLVM 100 is released, but it will be far in the future.
---
(no changes since v1)
Makefile | 2 +- arch/riscv/Makefile | 2 +- arch/x86/Makefile | 2 +- scripts/Kbuild.include | 10 ++++++++++ 4 files changed, 13 insertions(+), 3 deletions(-)
Makefile +1 -1
@@ -986,7 +986,7 @@ KBUILD_LDFLAGS += -mllvm -import-instr-limit=5 # Check for frame size exceeding threshold during prolog/epilog insertion # when using lld < 13.0.0. ifneq ($(CONFIG_FRAME_WARN),0) -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y) KBUILD_LDFLAGS += -plugin-opt=-warn-stack-size=$(CONFIG_FRAME_WARN) endif endif
arch/riscv/Makefile +1 -1
@@ -37,7 +37,7 @@ else endif ifeq ($(CONFIG_LD_IS_LLD),y) -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 150000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 150000),y) KBUILD_CFLAGS += -mno-relax KBUILD_AFLAGS += -mno-relax ifndef CONFIG_AS_IS_LLVM
arch/x86/Makefile +1 -1
@@ -211,7 +211,7 @@ endif KBUILD_LDFLAGS += -m elf_$(UTS_MACHINE) ifdef CONFIG_LTO_CLANG -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y) KBUILD_LDFLAGS += -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8) endif endif
scripts/Kbuild.include +10 -0
@@ -11,6 +11,16 @@ space := $(empty) $(empty) space_escape := _-_SPACE_-_ pound := \# +### +# Comparison macros. +# Usage: $(call test-le, A, B) +# works like shell's "test A -le B", but A and B must have the same number of +# digits since it is just ASCII sort. +test-le = $(if $(filter $1, $(firstword $(sort $1 $2))),y) +test-ge = $(call test-le, $2, $1) +test-lt = $(if $(filter-out $2, $(firstword $(sort $1 $2))),y) +test-gt = $(call test-lt, $2, $1) + ### # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o dot-target = $(dir $@).$(notdir $@)
Signature · 1 line
2.34.1
PATCH v2 2/5 kbuild: implement {gcc,clang}-min-version only with built-in functions
Converting clang-min-version is straightforward because the versions are always 6-digit.
gcc-min-version is somewhat tricky because the minimal GCC version is GCC 5.2; prepend '0' to the version that is less than 10 so that test-ge is always passed with 6-digit versions.
---
Changes in v2:
- Covert gcc-min-version in a different way
scripts/Makefile.compiler | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/Makefile.compiler +6 -2
@@ -63,11 +63,15 @@ cc-disable-warning = $(call try-run,\ # gcc-min-version # Usage: cflags-$(call gcc-min-version, 70100) += -foo -gcc-min-version = $(shell [ $(CONFIG_GCC_VERSION)0 -ge $(1)0 ] && echo y) + +# Preprend 0 to the version that is less than 10 so test-ge works. +gcc-min-version = $(call test-ge, \ + $(or $(filter 1%, $(CONFIG_GCC_VERSION)), 0$(CONFIG_GCC_VERSION)), \ + $(or $(filter 1%, $1), 0$(strip $1))) # clang-min-version # Usage: cflags-$(call clang-min-version, 110000) += -foo -clang-min-version = $(shell [ $(CONFIG_CLANG_VERSION)0 -ge $(1)0 ] && echo y) +clang-min-version = $(call test-ge, $(CONFIG_CLANG_VERSION), $1) # ld-option # Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
Signature · 1 line
2.34.1
Re: [PATCH v2 2/5] kbuild: implement {gcc,clang}-min-version only with built-in functions
Quoted 21 lines · Masahiro Yamada
Converting clang-min-version is straightforward because the versions are always 6-digit.
gcc-min-version is somewhat tricky because the minimal GCC version is GCC 5.2; prepend '0' to the version that is less than 10 so that test-ge is always passed with 6-digit versions.
Signed-off-by Masahiro Yamada <[email protected]>---
Changes in v2:
- Covert gcc-min-version in a different wayscripts/Makefile.compiler | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)scripts/Makefile.compiler +0
-0
scripts/Makefile.compiler cc-disable-warning = $(call try-run,\ · line 70
Quoted 9 lines
scripts/Makefile.compiler +5
-1@@ -63,11 +63,15 @@ cc-disable-warning = $(call try-run,\ # gcc-min-version # Usage: cflags-$(call gcc-min-version, 70100) += -foo -gcc-min-version = $(shell [ $(CONFIG_GCC_VERSION)0 -ge $(1)0 ] && echo y) + +# Preprend 0 to the version that is less than 10 so test-ge works. +gcc-min-version = $(call test-ge, \ + $(or $(filter 1%, $(CONFIG_GCC_VERSION)), 0$(CONFIG_GCC_VERSION)), \ + $(or $(filter 1%, $1), 0$(strip $1)))
Hm, this silently expects a gcc version < 20, which we should expect in
about seven-eight years [1]. I am thinking about the possibility of
silent (but unlikely) breaks when someone in far future uses a gcc 20 against a kernel with this line. Probably we should not care about that today, yet, right?
Quoted 10 lines
scripts/Makefile.compiler +1
-1# clang-min-version # Usage: cflags-$(call clang-min-version, 110000) += -foo -clang-min-version = $(shell [ $(CONFIG_CLANG_VERSION)0 -ge $(1)0 ] && echo y) +clang-min-version = $(call test-ge, $(CONFIG_CLANG_VERSION), $1) # ld-option # Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)Signature · 1 line
2.34.1
Signature · 3 lines
epost|xmpp: [email protected] irc://oftc.net/nsc ↳ gpg: 18ed 52db e34f 860e e9fb c82b 7d97 0932 55a0 ce7f -- frykten for herren er opphav til kunnskap --
Re: [PATCH v2 2/5] kbuild: implement {gcc,clang}-min-version only with built-in functions
Quoted 24 lines · Nicolas Schier
Quoted 22 lines · Masahiro Yamada
Converting clang-min-version is straightforward because the versions are always 6-digit.
gcc-min-version is somewhat tricky because the minimal GCC version is GCC 5.2; prepend '0' to the version that is less than 10 so that test-ge is always passed with 6-digit versions.
Signed-off-by Masahiro Yamada <[email protected]>---
Changes in v2:
- Covert gcc-min-version in a different wayscripts/Makefile.compiler | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)scripts/Makefile.compiler +0
-0@@ -63,11 +63,15 @@ cc-disable-warning = $(call try-run,\
Quoted 14 lines
scripts/Makefile.compiler cc-disable-warning = $(call try-run,\ · line 70
Quoted 8 lines
scripts/Makefile.compiler +5
-1# gcc-min-version # Usage: cflags-$(call gcc-min-version, 70100) += -foo -gcc-min-version = $(shell [ $(CONFIG_GCC_VERSION)0 -ge $(1)0 ] && echo y) + +# Preprend 0 to the version that is less than 10 so test-ge works. +gcc-min-version = $(call test-ge, \ + $(or $(filter 1%, $(CONFIG_GCC_VERSION)), 0$(CONFIG_GCC_VERSION)), \ + $(or $(filter 1%, $1), 0$(strip $1)))Hm, this silently expects a gcc version < 20, which we should expect in
about seven-eight years [1]. I am thinking about the possibility of
silent (but unlikely) breaks when someone in far future uses a gcc 20 against a kernel with this line. Probably we should not care about that today, yet, right?
Yeah, I thought of it.
It depends on which of the following two will happen first.
(a) We raise the min gcc version to 10.0.0 and remove this hack
(b) GCC 20 is released
I am guessing (a) will occur first, so we do not need to care about (b).
If (b) happens first, we will need to add "2%".
It means that the window of supported GCC versions will get larger than 10. Presumably, we do not want to support such a wide range of compiler versions.
GCC 5.1 was released in 2015.
So, the current window of GCC versions is 7 years. I hope it will not get even larger...
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH v2 3/5 kbuild: add read-file macro
In reply to Masahiro YamadaSince GMU Make 4.2, $(file ...) supports the read operater '<', which is useful to read a file without forking any process. No warning is shown even if the input file is missing.
For older Make versions, it falls back to the cat command.
---
(no changes since v1)
Makefile | 2 +- scripts/Kbuild.include | 12 ++++++++++++ scripts/Makefile.modfinal | 2 +- scripts/Makefile.modinst | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-)
Makefile +1 -1
@@ -369,7 +369,7 @@ else # !mixed-build include $(srctree)/scripts/Kbuild.include # Read KERNELRELEASE from include/config/kernel.release (if it exists) -KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null) +KERNELRELEASE = $(call read-file, include/config/kernel.release) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
scripts/Kbuild.include +12 -0
@@ -10,6 +10,10 @@ empty := space := $(empty) $(empty) space_escape := _-_SPACE_-_ pound := \# +define newline + + +endef ### # Comparison macros.
@@ -55,6 +59,14 @@ stringify = $(squote)$(quote)$1$(quote)$(squote) kbuild-dir = $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) kbuild-file = $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile) +### +# Read a file, replacing newlines with spaces +ifeq ($(call test-ge, $(MAKE_VERSION), 4.2),y) +read-file = $(subst $(newline),$(space),$(file < $1)) +else +read-file = $(shell cat $1 2>/dev/null) +endif + ### # Easy method for doing a status message kecho := :
scripts/Makefile.modfinal +1 -1
@@ -13,7 +13,7 @@ include $(srctree)/scripts/Kbuild.include include $(srctree)/scripts/Makefile.lib # find all modules listed in modules.order -modules := $(sort $(shell cat $(MODORDER))) +modules := $(sort $(call read-file, $(MODORDER))) __modfinal: $(modules) @:
scripts/Makefile.modinst +1 -1
@@ -9,7 +9,7 @@ __modinst: include include/config/auto.conf include $(srctree)/scripts/Kbuild.include -modules := $(sort $(shell cat $(MODORDER))) +modules := $(sort $(call read-file, $(MODORDER))) ifeq ($(KBUILD_EXTMOD),) dst := $(MODLIB)/kernel
Signature · 1 line
2.34.1
Re: [PATCH v2 3/5] kbuild: add read-file macro
Quoted 47 lines · Masahiro Yamada
Since GMU Make 4.2, $(file ...) supports the read operater '<', which is useful to read a file without forking any process. No warning is shown even if the input file is missing.
For older Make versions, it falls back to the cat command.
Signed-off-by Masahiro Yamada <[email protected]>---
(no changes since v1)
Makefile | 2 +- scripts/Kbuild.include | 12 ++++++++++++ scripts/Makefile.modfinal | 2 +- scripts/Makefile.modinst | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-)Makefile +1
-1@@ -369,7 +369,7 @@ else # !mixed-build include $(srctree)/scripts/Kbuild.include # Read KERNELRELEASE from include/config/kernel.release (if it exists) -KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null) +KERNELRELEASE = $(call read-file, include/config/kernel.release) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSIONscripts/Kbuild.include +4
-0@@ -10,6 +10,10 @@ empty := space := $(empty) $(empty) space_escape := _-_SPACE_-_ pound := \# +define newline + + +endef ### # Comparison macros.@@ -55,6 +59,14 @@ stringify = $(squote)$(quote)$1$(quote)$(squote) kbuild-dir = $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
scripts/Kbuild.include stringify = $(squote)$(quote)$1$(quote)$(squote) · line 69
Quoted 10 lines
scripts/Kbuild.include +8
-0kbuild-file = $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile) +### +# Read a file, replacing newlines with spaces +ifeq ($(call test-ge, $(MAKE_VERSION), 4.2),y) +read-file = $(subst $(newline),$(space),$(file < $1)) +else +read-file = $(shell cat $1 2>/dev/null) +endif +
I like the implementation of read-file, but I am afraid that the MAKE_VERSION comparison breaks all make versions w/ a minor version
number: 3.99.9x, 4.2.x, 4.3.x.
Not beautiful, but this might possibly work:
ifneq ($(filter 3.% 4.0 4.0.% 4.1 4.1.%,$(MAKE_VERSION)),) read-file = ...
Kind regards,
Nicolas
Quoted 31 lines
scripts/Kbuild.include +0
-0### # Easy method for doing a status message kecho := :scripts/Makefile.modfinal +1
-1@@ -13,7 +13,7 @@ include $(srctree)/scripts/Kbuild.include include $(srctree)/scripts/Makefile.lib # find all modules listed in modules.order -modules := $(sort $(shell cat $(MODORDER))) +modules := $(sort $(call read-file, $(MODORDER))) __modfinal: $(modules) @:scripts/Makefile.modinst +1
-1@@ -9,7 +9,7 @@ __modinst: include include/config/auto.conf include $(srctree)/scripts/Kbuild.include -modules := $(sort $(shell cat $(MODORDER))) +modules := $(sort $(call read-file, $(MODORDER))) ifeq ($(KBUILD_EXTMOD),) dst := $(MODLIB)/kernelSignature · 1 line
2.34.1
Signature · 3 lines
epost|xmpp: [email protected] irc://oftc.net/nsc ↳ gpg: 18ed 52db e34f 860e e9fb c82b 7d97 0932 55a0 ce7f -- frykten for herren er opphav til kunnskap --
Re: [PATCH v2 3/5] kbuild: add read-file macro
Quoted 51 lines · Nicolas Schier
Quoted 49 lines · Masahiro Yamada
Since GMU Make 4.2, $(file ...) supports the read operater '<', which is useful to read a file without forking any process. No warning is shown even if the input file is missing.
For older Make versions, it falls back to the cat command.
Signed-off-by Masahiro Yamada <[email protected]>---
(no changes since v1)
Makefile | 2 +- scripts/Kbuild.include | 12 ++++++++++++ scripts/Makefile.modfinal | 2 +- scripts/Makefile.modinst | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-)Makefile +1
-1@@ -369,7 +369,7 @@ else # !mixed-build include $(srctree)/scripts/Kbuild.include # Read KERNELRELEASE from include/config/kernel.release (if it exists) -KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null) +KERNELRELEASE = $(call read-file, include/config/kernel.release) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSIONscripts/Kbuild.include +4
-0@@ -10,6 +10,10 @@ empty := space := $(empty) $(empty) space_escape := _-_SPACE_-_ pound := \# +define newline + + +endef ### # Comparison macros.@@ -55,6 +59,14 @@ stringify = $(squote)$(quote)$1$(quote)$(squote) kbuild-dir = $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) kbuild-file = $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile)
Quoted 12 lines
scripts/Kbuild.include stringify = $(squote)$(quote)$1$(quote)$(squote) · line 69
Quoted 8 lines
scripts/Kbuild.include +8
-0+### +# Read a file, replacing newlines with spaces +ifeq ($(call test-ge, $(MAKE_VERSION), 4.2),y) +read-file = $(subst $(newline),$(space),$(file < $1)) +else +read-file = $(shell cat $1 2>/dev/null) +endif +I like the implementation of read-file, but I am afraid that the
MAKE_VERSIONcomparison breaks all make versions w/ a minor version
number: 3.99.9x, 4.2.x, 4.3.x.
I think these should work correctly
unless I missed something terribly.
In the ASCII-sorting, they are sorted like this:
3.99.9x 4.2 4.2.x 4.3.x
The bad scenarios I came up with is GNU Make 4.10 and GNU Make 10.0 because $(sort ) will sort
10 4.10 4.2
GNU Make 4.3 was released in Jan 2020
GNU Make 4.4 was released in Oct 2022
If the current release pace continues,
we will have about 10 years until GNU Make hits 4.10
Until then, we can remove this ifeq.
Signature · 2 lines
Best Regards Masahiro Yamada
Nicolas Schier
Reviewed-byRe: [PATCH v2 3/5] kbuild: add read-file macro
Quoted 92 lines · Masahiro Yamada
Quoted 51 lines · Nicolas Schier
Quoted 49 lines · Masahiro Yamada
Since GMU Make 4.2, $(file ...) supports the read operater '<', which is useful to read a file without forking any process. No warning is shown even if the input file is missing.
For older Make versions, it falls back to the cat command.
Signed-off-by Masahiro Yamada <[email protected]>---
(no changes since v1)
Makefile | 2 +- scripts/Kbuild.include | 12 ++++++++++++ scripts/Makefile.modfinal | 2 +- scripts/Makefile.modinst | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-)Makefile +1
-1@@ -369,7 +369,7 @@ else # !mixed-build include $(srctree)/scripts/Kbuild.include # Read KERNELRELEASE from include/config/kernel.release (if it exists) -KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null) +KERNELRELEASE = $(call read-file, include/config/kernel.release) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSIONscripts/Kbuild.include +4
-0@@ -10,6 +10,10 @@ empty := space := $(empty) $(empty) space_escape := _-_SPACE_-_ pound := \# +define newline + + +endef ### # Comparison macros.@@ -55,6 +59,14 @@ stringify = $(squote)$(quote)$1$(quote)$(squote) kbuild-dir = $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) kbuild-file = $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile)Quoted 12 lines
scripts/Kbuild.include stringify = $(squote)$(quote)$1$(quote)$(squote) · line 69
Quoted 8 lines
scripts/Kbuild.include +8
-0+### +# Read a file, replacing newlines with spaces +ifeq ($(call test-ge, $(MAKE_VERSION), 4.2),y) +read-file = $(subst $(newline),$(space),$(file < $1)) +else +read-file = $(shell cat $1 2>/dev/null) +endif +I like the implementation of read-file, but I am afraid that the
MAKE_VERSIONcomparison breaks all make versions w/ a minor version
number: 3.99.9x, 4.2.x, 4.3.x.I think these should work correctly
unless I missed something terribly.In the ASCII-sorting, they are sorted like this:
3.99.9x 4.2 4.2.x 4.3.x
The bad scenarios I came up with is GNU Make 4.10 and GNU Make 10.0 because $(sort ) will sort
10 4.10 4.2
GNU Make 4.3 was released in Jan 2020
GNU Make 4.4 was released in Oct 2022
Quoted 5 lines
If the current release pace continues,
we will have about 10 years until GNU Make hits 4.10Until then, we can remove this ifeq.
yes, you're right. I should have checked my assumption before bothering you with it.
Quoted 5 lines
Signature · 3 lines
-- Best Regards Masahiro Yamada
Signature · 3 lines
epost|xmpp: [email protected] irc://oftc.net/nsc ↳ gpg: 18ed 52db e34f 860e e9fb c82b 7d97 0932 55a0 ce7f -- frykten for herren er opphav til kunnskap --
PATCH v2 4/5 kconfig: refactor Makefile to reduce process forks
In reply to Masahiro YamadaRefactor Makefile and use read-file macro. For Make >= 4.2, it can read out a file by using the built-in function.
---
(no changes since v1)
scripts/kconfig/.gitignore | 4 +++- scripts/kconfig/Makefile | 43 +++++++++++++++++++----------------- scripts/kconfig/gconf-cfg.sh | 7 ++++-- scripts/kconfig/mconf-cfg.sh | 25 ++++++++++++--------- scripts/kconfig/nconf-cfg.sh | 23 ++++++++++--------- scripts/kconfig/qconf-cfg.sh | 10 ++++++--- scripts/remove-stale-files | 2 ++ 7 files changed, 67 insertions(+), 47 deletions(-)
scripts/kconfig/.gitignore +3 -1
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only /conf /[gmnq]conf -/[gmnq]conf-cfg +/[gmnq]conf-cflags +/[gmnq]conf-libs +/qconf-bin /qconf-moc.cc
scripts/kconfig/Makefile +23 -20
76 lines not on this page · raw message
scripts/kconfig/gconf-cfg.sh +5 -2
@@ -1,6 +1,9 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 +cflags=$1 +libs=$2 + PKG="gtk+-2.0 gmodule-2.0 libglade-2.0" if [ -z "$(command -v ${HOSTPKG_CONFIG})" ]; then
@@ -26,5 +29,5 @@ if ! ${HOSTPKG_CONFIG} --atleast-version=2.0.0 gtk+-2.0; then exit 1 fi -echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG)\" -echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\" +${HOSTPKG_CONFIG} --cflags ${PKG} > ${cflags} +${HOSTPKG_CONFIG} --libs ${PKG} > ${libs}
scripts/kconfig/mconf-cfg.sh +14 -11
@@ -1,19 +1,22 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 +cflags=$1 +libs=$2 + PKG="ncursesw" PKG2="ncurses" if [ -n "$(command -v ${HOSTPKG_CONFIG})" ]; then if ${HOSTPKG_CONFIG} --exists $PKG; then - echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG)\" - echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\" + ${HOSTPKG_CONFIG} --cflags ${PKG} > ${cflags} + ${HOSTPKG_CONFIG} --libs ${PKG} > ${libs} exit 0 fi - if ${HOSTPKG_CONFIG} --exists $PKG2; then - echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG2)\" - echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG2)\" + if ${HOSTPKG_CONFIG} --exists ${PKG2}; then + ${HOSTPKG_CONFIG} --cflags ${PKG2} > ${cflags} + ${HOSTPKG_CONFIG} --libs ${PKG2} > ${libs} exit 0 fi fi
@@ -22,22 +25,22 @@ fi # (Even if it is installed, some distributions such as openSUSE cannot # find ncurses by pkg-config.) if [ -f /usr/include/ncursesw/ncurses.h ]; then - echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncursesw\" - echo libs=\"-lncursesw\" + echo -D_GNU_SOURCE -I/usr/include/ncursesw > ${cflags} + echo -lncursesw > ${libs} exit 0 fi if [ -f /usr/include/ncurses/ncurses.h ]; then - echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncurses\" - echo libs=\"-lncurses\" + echo -D_GNU_SOURCE -I/usr/include/ncurses > ${cflags} + echo -lncurses > ${libs} exit 0 fi # As a final fallback before giving up, check if $HOSTCC knows of a default # ncurses installation (e.g. from a vendor-specific sysroot). if echo '#include <ncurses.h>' | ${HOSTCC} -E - >/dev/null 2>&1; then - echo cflags=\"-D_GNU_SOURCE\" - echo libs=\"-lncurses\" + echo -D_GNU_SOURCE > ${cflags} + echo -lncurses > ${libs} exit 0 fi
scripts/kconfig/nconf-cfg.sh +13 -10
@@ -1,19 +1,22 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 +cflags=$1 +libs=$2 + PKG="ncursesw menuw panelw" PKG2="ncurses menu panel" if [ -n "$(command -v ${HOSTPKG_CONFIG})" ]; then if ${HOSTPKG_CONFIG} --exists $PKG; then - echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG)\" - echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\" + ${HOSTPKG_CONFIG} --cflags ${PKG} > ${cflags} + ${HOSTPKG_CONFIG} --libs ${PKG} > ${libs} exit 0 fi if ${HOSTPKG_CONFIG} --exists $PKG2; then - echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG2)\" - echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG2)\" + ${HOSTPKG_CONFIG} --cflags ${PKG2} > ${cflags} + ${HOSTPKG_CONFIG} --libs ${PKG2} > ${libs} exit 0 fi fi
@@ -22,20 +25,20 @@ fi # (Even if it is installed, some distributions such as openSUSE cannot # find ncurses by pkg-config.) if [ -f /usr/include/ncursesw/ncurses.h ]; then - echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncursesw\" - echo libs=\"-lncursesw -lmenuw -lpanelw\" + echo -D_GNU_SOURCE -I/usr/include/ncursesw > ${cflags} + echo -lncursesw -lmenuw -lpanelw > ${libs} exit 0 fi if [ -f /usr/include/ncurses/ncurses.h ]; then - echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncurses\" - echo libs=\"-lncurses -lmenu -lpanel\" + echo -D_GNU_SOURCE -I/usr/include/ncurses > ${cflags} + echo -lncurses -lmenu -lpanel > ${libs} exit 0 fi if [ -f /usr/include/ncurses.h ]; then - echo cflags=\"-D_GNU_SOURCE\" - echo libs=\"-lncurses -lmenu -lpanel\" + echo -D_GNU_SOURCE > ${cflags} + echo -lncurses -lmenu -lpanel > ${libs} exit 0 fi
scripts/kconfig/qconf-cfg.sh +7 -3
@@ -1,6 +1,10 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 +cflags=$1 +libs=$2 +bin=$3 + PKG="Qt5Core Qt5Gui Qt5Widgets" if [ -z "$(command -v ${HOSTPKG_CONFIG})" ]; then
@@ -11,9 +15,9 @@ if [ -z "$(command -v ${HOSTPKG_CONFIG})" ]; then fi if ${HOSTPKG_CONFIG} --exists $PKG; then - echo cflags=\"-std=c++11 -fPIC $(${HOSTPKG_CONFIG} --cflags $PKG)\" - echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\" - echo moc=\"$(${HOSTPKG_CONFIG} --variable=host_bins Qt5Core)/moc\" + ${HOSTPKG_CONFIG} --cflags ${PKG} > ${cflags} + ${HOSTPKG_CONFIG} --libs ${PKG} > ${libs} + ${HOSTPKG_CONFIG} --variable=host_bins Qt5Core > ${bin} exit 0 fi
scripts/remove-stale-files +2 -0
@@ -47,3 +47,5 @@ rm -f arch/riscv/purgatory/kexec-purgatory.c rm -f scripts/extract-cert rm -f arch/x86/purgatory/kexec-purgatory.c + +rm -f scripts/kconfig/[gmnq]conf-cfg
Signature · 1 line
2.34.1
Re: [PATCH v2 4/5] kconfig: refactor Makefile to reduce process forks
Quoted 6 lines · Masahiro Yamada
Refactor
Makefileand use read-file macro. For Make >= 4.2, it can read
out a file by using the built-in function.Signed-off-by Masahiro Yamada <[email protected]>---
Quoted 289 lines
(no changes since v1)
scripts/kconfig/.gitignore | 4 +++- scripts/kconfig/Makefile | 43 +++++++++++++++++++----------------- scripts/kconfig/gconf-cfg.sh | 7 ++++-- scripts/kconfig/mconf-cfg.sh | 25 ++++++++++++--------- scripts/kconfig/nconf-cfg.sh | 23 ++++++++++--------- scripts/kconfig/qconf-cfg.sh | 10 ++++++--- scripts/remove-stale-files | 2 ++ 7 files changed, 67 insertions(+), 47 deletions(-)scripts/kconfig/.gitignore +3
-1@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only /conf /[gmnq]conf -/[gmnq]conf-cfg +/[gmnq]conf-cflags +/[gmnq]conf-libs +/qconf-bin /qconf-moc.ccscripts/kconfig/Makefile +23
-20@@ -159,11 +159,12 @@ conf-objs := conf.o $(common-objs) hostprogs += nconf nconf-objs := nconf.o nconf.gui.o $(common-objs) -HOSTLDLIBS_nconf = $(shell . $(obj)/nconf-cfg && echo $$libs) -HOSTCFLAGS_nconf.o = $(shell . $(obj)/nconf-cfg && echo $$cflags) -HOSTCFLAGS_nconf.gui.o = $(shell . $(obj)/nconf-cfg && echo $$cflags) +HOSTLDLIBS_nconf = $(call read-file, $(obj)/nconf-libs) +HOSTCFLAGS_nconf.o = $(call read-file, $(obj)/nconf-cflags) +HOSTCFLAGS_nconf.gui.o = $(call read-file, $(obj)/nconf-cflags) -$(obj)/nconf.o $(obj)/nconf.gui.o: $(obj)/nconf-cfg +$(obj)/nconf: | $(obj)/nconf-libs +$(obj)/nconf.o $(obj)/nconf.gui.o: | $(obj)/nconf-cflags # mconf: Used for the menuconfig target based on lxdialog hostprogs += mconf@@ -171,27 +172,28 @@ lxdialog := $(addprefix lxdialog/, \ checklist.o inputbox.o menubox.o textbox.o util.o yesno.o) mconf-objs := mconf.o $(lxdialog) $(common-objs) -HOSTLDLIBS_mconf = $(shell . $(obj)/mconf-cfg && echo $$libs) +HOSTLDLIBS_mconf = $(call read-file, $(obj)/mconf-libs) $(foreach f, mconf.o $(lxdialog), \ - $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/mconf-cfg && echo $$$$cflags))) + $(eval HOSTCFLAGS_$f = $$(call read-file, $(obj)/mconf-cflags))) -$(addprefix $(obj)/, mconf.o $(lxdialog)): $(obj)/mconf-cfg +$(obj)/mconf: | $(obj)/mconf-libs +$(addprefix $(obj)/, mconf.o $(lxdialog)): | $(obj)/mconf-cflags # qconf: Used for the xconfig target based on Qt hostprogs += qconf qconf-cxxobjs := qconf.o qconf-moc.o qconf-objs := images.o $(common-objs) -HOSTLDLIBS_qconf = $(shell . $(obj)/qconf-cfg && echo $$libs) -HOSTCXXFLAGS_qconf.o = $(shell . $(obj)/qconf-cfg && echo $$cflags) -HOSTCXXFLAGS_qconf-moc.o = $(shell . $(obj)/qconf-cfg && echo $$cflags) - -$(obj)/qconf.o: $(obj)/qconf-cfg +HOSTLDLIBS_qconf = $(call read-file, $(obj)/qconf-libs) +HOSTCXXFLAGS_qconf.o = -std=c++11 -fPIC $(call read-file, $(obj)/qconf-cflags) +HOSTCXXFLAGS_qconf-moc.o = -std=c++11 -fPIC $(call read-file, $(obj)/qconf-cflags) +$(obj)/qconf: | $(obj)/qconf-libs +$(obj)/qconf.o $(obj)/qconf-moc.o: | $(obj)/qconf-cflags quiet_cmd_moc = MOC $@ - cmd_moc = $(shell . $(obj)/qconf-cfg && echo $$moc) $< -o $@ + cmd_moc = $(call read-file, $(obj)/qconf-bin)/moc $< -o $@ -$(obj)/qconf-moc.cc: $(src)/qconf.h $(obj)/qconf-cfg FORCE +$(obj)/qconf-moc.cc: $(src)/qconf.h FORCE | $(obj)/qconf-bin $(call if_changed,moc) targets += qconf-moc.cc@@ -200,15 +202,16 @@ targets += qconf-moc.cc hostprogs += gconf gconf-objs := gconf.o images.o $(common-objs) -HOSTLDLIBS_gconf = $(shell . $(obj)/gconf-cfg && echo $$libs) -HOSTCFLAGS_gconf.o = $(shell . $(obj)/gconf-cfg && echo $$cflags) +HOSTLDLIBS_gconf = $(call read-file, $(obj)/gconf-libs) +HOSTCFLAGS_gconf.o = $(call read-file, $(obj)/gconf-cflags) -$(obj)/gconf.o: $(obj)/gconf-cfg +$(obj)/gconf: | $(obj)/gconf-libs +$(obj)/gconf.o: | $(obj)/gconf-cflags # check if necessary packages are available, and configure build flags -filechk_conf_cfg = $(CONFIG_SHELL) $< +cmd_conf_cfg = $< $(addprefix $(obj)/$*conf-, cflags libs bin) -$(obj)/%conf-cfg: $(src)/%conf-cfg.sh FORCE - $(call filechk,conf_cfg) +$(obj)/%conf-cflags $(obj)/%conf-libs $(obj)/%conf-bin: $(src)/%conf-cfg.sh + $(call cmd,conf_cfg) clean-files += *conf-cfgscripts/kconfig/gconf-cfg.sh +5
-2@@ -1,6 +1,9 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 +cflags=$1 +libs=$2 + PKG="gtk+-2.0 gmodule-2.0 libglade-2.0" if [ -z "$(command -v ${HOSTPKG_CONFIG})" ]; then@@ -26,5 +29,5 @@ if ! ${HOSTPKG_CONFIG} --atleast-version=2.0.0 gtk+-2.0; then exit 1 fi -echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG)\" -echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\" +${HOSTPKG_CONFIG} --cflags ${PKG} > ${cflags} +${HOSTPKG_CONFIG} --libs ${PKG} > ${libs}scripts/kconfig/mconf-cfg.sh +14
-11@@ -1,19 +1,22 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 +cflags=$1 +libs=$2 + PKG="ncursesw" PKG2="ncurses" if [ -n "$(command -v ${HOSTPKG_CONFIG})" ]; then if ${HOSTPKG_CONFIG} --exists $PKG; then - echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG)\" - echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\" + ${HOSTPKG_CONFIG} --cflags ${PKG} > ${cflags} + ${HOSTPKG_CONFIG} --libs ${PKG} > ${libs} exit 0 fi - if ${HOSTPKG_CONFIG} --exists $PKG2; then - echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG2)\" - echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG2)\" + if ${HOSTPKG_CONFIG} --exists ${PKG2}; then + ${HOSTPKG_CONFIG} --cflags ${PKG2} > ${cflags} + ${HOSTPKG_CONFIG} --libs ${PKG2} > ${libs} exit 0 fi fi@@ -22,22 +25,22 @@ fi # (Even if it is installed, some distributions such as openSUSE cannot # find ncurses by pkg-config.) if [ -f /usr/include/ncursesw/ncurses.h ]; then - echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncursesw\" - echo libs=\"-lncursesw\" + echo -D_GNU_SOURCE -I/usr/include/ncursesw > ${cflags} + echo -lncursesw > ${libs} exit 0 fi if [ -f /usr/include/ncurses/ncurses.h ]; then - echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncurses\" - echo libs=\"-lncurses\" + echo -D_GNU_SOURCE -I/usr/include/ncurses > ${cflags} + echo -lncurses > ${libs} exit 0 fi # As a final fallback before giving up, check if $HOSTCC knows of a default # ncurses installation (e.g. from a vendor-specific sysroot). if echo '#include <ncurses.h>' | ${HOSTCC} -E - >/dev/null 2>&1; then - echo cflags=\"-D_GNU_SOURCE\" - echo libs=\"-lncurses\" + echo -D_GNU_SOURCE > ${cflags} + echo -lncurses > ${libs} exit 0 fiscripts/kconfig/nconf-cfg.sh +13
-10@@ -1,19 +1,22 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 +cflags=$1 +libs=$2 + PKG="ncursesw menuw panelw" PKG2="ncurses menu panel" if [ -n "$(command -v ${HOSTPKG_CONFIG})" ]; then if ${HOSTPKG_CONFIG} --exists $PKG; then - echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG)\" - echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\" + ${HOSTPKG_CONFIG} --cflags ${PKG} > ${cflags} + ${HOSTPKG_CONFIG} --libs ${PKG} > ${libs} exit 0 fi if ${HOSTPKG_CONFIG} --exists $PKG2; then - echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG2)\" - echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG2)\" + ${HOSTPKG_CONFIG} --cflags ${PKG2} > ${cflags} + ${HOSTPKG_CONFIG} --libs ${PKG2} > ${libs} exit 0 fi fi@@ -22,20 +25,20 @@ fi # (Even if it is installed, some distributions such as openSUSE cannot # find ncurses by pkg-config.) if [ -f /usr/include/ncursesw/ncurses.h ]; then - echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncursesw\" - echo libs=\"-lncursesw -lmenuw -lpanelw\" + echo -D_GNU_SOURCE -I/usr/include/ncursesw > ${cflags} + echo -lncursesw -lmenuw -lpanelw > ${libs} exit 0 fi if [ -f /usr/include/ncurses/ncurses.h ]; then - echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncurses\" - echo libs=\"-lncurses -lmenu -lpanel\" + echo -D_GNU_SOURCE -I/usr/include/ncurses > ${cflags} + echo -lncurses -lmenu -lpanel > ${libs} exit 0 fi if [ -f /usr/include/ncurses.h ]; then - echo cflags=\"-D_GNU_SOURCE\" - echo libs=\"-lncurses -lmenu -lpanel\" + echo -D_GNU_SOURCE > ${cflags} + echo -lncurses -lmenu -lpanel > ${libs} exit 0 fiscripts/kconfig/qconf-cfg.sh +7
-3@@ -1,6 +1,10 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 +cflags=$1 +libs=$2 +bin=$3 + PKG="Qt5Core Qt5Gui Qt5Widgets" if [ -z "$(command -v ${HOSTPKG_CONFIG})" ]; then@@ -11,9 +15,9 @@ if [ -z "$(command -v ${HOSTPKG_CONFIG})" ]; then fi if ${HOSTPKG_CONFIG} --exists $PKG; then - echo cflags=\"-std=c++11 -fPIC $(${HOSTPKG_CONFIG} --cflags $PKG)\" - echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\" - echo moc=\"$(${HOSTPKG_CONFIG} --variable=host_bins Qt5Core)/moc\" + ${HOSTPKG_CONFIG} --cflags ${PKG} > ${cflags} + ${HOSTPKG_CONFIG} --libs ${PKG} > ${libs} + ${HOSTPKG_CONFIG} --variable=host_bins Qt5Core > ${bin} exit 0 fiscripts/remove-stale-files +2
-0@@ -47,3 +47,5 @@ rm -f arch/riscv/purgatory/kexec-purgatory.c rm -f scripts/extract-cert rm -f arch/x86/purgatory/kexec-purgatory.c + +rm -f scripts/kconfig/[gmnq]conf-cfgSignature · 1 line
2.34.1
Signature · 3 lines
epost|xmpp: [email protected] irc://oftc.net/nsc ↳ gpg: 18ed 52db e34f 860e e9fb c82b 7d97 0932 55a0 ce7f -- frykten for herren er opphav til kunnskap --
PATCH v2 5/5 kbuild: check Make version
In reply to Masahiro YamadaThis is implemented based on test-le. It will work until GNU Make 10 is released.
---
(no changes since v1)
Makefile | 3 +++ 1 file changed, 3 insertions(+)
Makefile +3 -0
@@ -368,6 +368,9 @@ else # !mixed-build include $(srctree)/scripts/Kbuild.include +# Check for the minimal Make version +$(if $(call test-lt, $(MAKE_VERSION), 3.82), $(error Make $(MAKE_VERSION) is too old)) + # Read KERNELRELEASE from include/config/kernel.release (if it exists) KERNELRELEASE = $(call read-file, include/config/kernel.release) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
Signature · 1 line
2.34.1
Re: [PATCH v2 5/5] kbuild: check Make version
Quoted 2 lines · Masahiro Yamada
This is implemented based on test-le. It will work until GNU Make 10 is released.
... and as long as nobody uses make versions w/ minor version numbers, cp. patch 3/5.
Kind regards,
Nicolas
Quoted 25 lines
Signed-off-by Masahiro Yamada <[email protected]>---
(no changes since v1)
Makefile | 3 +++ 1 file changed, 3 insertions(+)Makefile +3
-0@@ -368,6 +368,9 @@ else # !mixed-build include $(srctree)/scripts/Kbuild.include +# Check for the minimal Make version +$(if $(call test-lt, $(MAKE_VERSION), 3.82), $(error Make $(MAKE_VERSION) is too old)) + # Read KERNELRELEASE from include/config/kernel.release (if it exists) KERNELRELEASE = $(call read-file, include/config/kernel.release) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)Signature · 1 line
2.34.1
Signature · 3 lines
epost|xmpp: [email protected] irc://oftc.net/nsc ↳ gpg: 18ed 52db e34f 860e e9fb c82b 7d97 0932 55a0 ce7f -- frykten for herren er opphav til kunnskap --
Nicolas Schier
Reviewed-byRe: [PATCH v2 5/5] kbuild: check Make version
Quoted 7 lines · Nicolas Schier
Quoted 2 lines · Masahiro Yamada
This is implemented based on test-le. It will work until GNU Make 10 is released.
... and as long as nobody uses make versions w/ minor version numbers, cp. patch 3/5.
I had a wrong understanding of the ASCII sort and forgot to re-check my own assumptions.
Thanks for that whole patch set!
Quoted 31 lines
Quoted 26 lines
Signed-off-by Masahiro Yamada <[email protected]>---
(no changes since v1)
Makefile | 3 +++ 1 file changed, 3 insertions(+)Makefile +3
-0@@ -368,6 +368,9 @@ else # !mixed-build include $(srctree)/scripts/Kbuild.include +# Check for the minimal Make version +$(if $(call test-lt, $(MAKE_VERSION), 3.82), $(error Make $(MAKE_VERSION) is too old)) + # Read KERNELRELEASE from include/config/kernel.release (if it exists) KERNELRELEASE = $(call read-file, include/config/kernel.release) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)Signature · 1 line
2.34.1Signature · 3 lines
epost|xmpp: [email protected] irc://oftc.net/nsc ↳ gpg: 18ed 52db e34f 860e e9fb c82b 7d97 0932 55a0 ce7f -- frykten for herren er opphav til kunnskap --
Signature · 3 lines
epost|xmpp: [email protected] irc://oftc.net/nsc ↳ gpg: 18ed 52db e34f 860e e9fb c82b 7d97 0932 55a0 ce7f -- frykten for herren er opphav til kunnskap --
Quoted 98 lines · Masahiro Yamada
Because GNU Make is only able to handle strings, it is very hard to perform arighmetic in Makefiles.
When we compare two integers, we invokes shell. One example is in the top
Makefile:ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0)This is more expensive than using built-in functions since it forks a process.
If we know the two have the same number of digits, we can do better.
This commit adds four macros, test-le, test-ge, test-lt, test-gt.
$(call test-lt, A, B) is evaluated to 'y' if A is less than B, or empty otherwise. This will replace $(call shell test A -lt B).
Again, the limitation is that A and B must have the same number of digits because these macros are based on $(sort ) function.
$(call test-lt, 1, 9) --> y (Works!) $(call test-lt, 10, 9) --> y (Not work...)To make the latter work, you need to add '0' prefix to align the number of digits:
$(call test-lt, 10, 09) --> empty (Works!)Actually, we can live with this limitation in many places. As for the example above, we know $(CONFIG_LLD_VERSION) is 6-digits because the minimal supported version of LLVM is 11.0.0.
So, the shell invocation can be replaced with more efficient code:
ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y)Of course, this assumption will break when LLVM 100 is released, but it will be far in the future.
Signed-off-by Masahiro Yamada <[email protected]>---
(no changes since v1)
Makefile | 2 +- arch/riscv/Makefile | 2 +- arch/x86/Makefile | 2 +- scripts/Kbuild.include | 10 ++++++++++ 4 files changed, 13 insertions(+), 3 deletions(-)Makefile +1
-1@@ -986,7 +986,7 @@ KBUILD_LDFLAGS += -mllvm -import-instr-limit=5 # Check for frame size exceeding threshold during prolog/epilog insertion # when using lld < 13.0.0. ifneq ($(CONFIG_FRAME_WARN),0) -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y) KBUILD_LDFLAGS += -plugin-opt=-warn-stack-size=$(CONFIG_FRAME_WARN) endif endifarch/riscv/Makefile +1
-1@@ -37,7 +37,7 @@ else endif ifeq ($(CONFIG_LD_IS_LLD),y) -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 150000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 150000),y) KBUILD_CFLAGS += -mno-relax KBUILD_AFLAGS += -mno-relax ifndef CONFIG_AS_IS_LLVMarch/x86/Makefile +1
-1@@ -211,7 +211,7 @@ endif KBUILD_LDFLAGS += -m elf_$(UTS_MACHINE) ifdef CONFIG_LTO_CLANG -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y) KBUILD_LDFLAGS += -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8) endif endifscripts/Kbuild.include +0
-0@@ -11,6 +11,16 @@ space := $(empty) $(empty) space_escape := _-_SPACE_-_ pound := \#
scripts/Kbuild.include space := $(empty) $(empty) · line 23
Quoted 10 lines
scripts/Kbuild.include +10
-0+### +# Comparison macros. +# Usage: $(call test-le, A, B) +# works like shell's "test A -le B", but A and B must have the same number of +# digits since it is just ASCII sort. +test-le = $(if $(filter $1, $(firstword $(sort $1 $2))),y) +test-ge = $(call test-le, $2, $1) +test-lt = $(if $(filter-out $2, $(firstword $(sort $1 $2))),y) +test-gt = $(call test-lt, $2, $1) +
I like that whole patch set, thanks! A cherry on the cake would be a sanity check for equal length of A and B ...
Quoted 5 lines
scripts/Kbuild.include +0
-0### # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o dot-target = $(dir $@).$(notdir $@)Signature · 1 line
2.34.1
Signature · 3 lines
epost|xmpp: [email protected] irc://oftc.net/nsc ↳ gpg: 18ed 52db e34f 860e e9fb c82b 7d97 0932 55a0 ce7f -- frykten for herren er opphav til kunnskap --
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 69 lines · On Wed, 23 Nov 2022 07:18:24 PST (-0800), [email protected] wrote:
Because GNU Make is only able to handle strings, it is very hard to perform arighmetic in Makefiles.
When we compare two integers, we invokes shell. One example is in the top
Makefile:ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0)This is more expensive than using built-in functions since it forks a process.
If we know the two have the same number of digits, we can do better.
This commit adds four macros, test-le, test-ge, test-lt, test-gt.
$(call test-lt, A, B) is evaluated to 'y' if A is less than B, or empty otherwise. This will replace $(call shell test A -lt B).
Again, the limitation is that A and B must have the same number of digits because these macros are based on $(sort ) function.
$(call test-lt, 1, 9) --> y (Works!) $(call test-lt, 10, 9) --> y (Not work...)To make the latter work, you need to add '0' prefix to align the number of digits:
$(call test-lt, 10, 09) --> empty (Works!)Actually, we can live with this limitation in many places. As for the example above, we know $(CONFIG_LLD_VERSION) is 6-digits because the minimal supported version of LLVM is 11.0.0.
So, the shell invocation can be replaced with more efficient code:
ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y)Of course, this assumption will break when LLVM 100 is released, but it will be far in the future.
Signed-off-by Masahiro Yamada <[email protected]>---
(no changes since v1)
Makefile | 2 +- arch/riscv/Makefile | 2 +- arch/x86/Makefile | 2 +- scripts/Kbuild.include | 10 ++++++++++ 4 files changed, 13 insertions(+), 3 deletions(-)Makefile +1
-1@@ -986,7 +986,7 @@ KBUILD_LDFLAGS += -mllvm -import-instr-limit=5 # Check for frame size exceeding threshold during prolog/epilog insertion # when using lld < 13.0.0. ifneq ($(CONFIG_FRAME_WARN),0) -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y) KBUILD_LDFLAGS += -plugin-opt=-warn-stack-size=$(CONFIG_FRAME_WARN) endif endifarch/riscv/Makefile +0
-0
arch/riscv/Makefile else · line 43
Quoted 8 lines
arch/riscv/Makefile +1
-1@@ -37,7 +37,7 @@ else endif ifeq ($(CONFIG_LD_IS_LLD),y) -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 150000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 150000),y) KBUILD_CFLAGS += -mno-relax KBUILD_AFLAGS += -mno-relax ifndef CONFIG_AS_IS_LLVM
Quoted 34 lines
arch/x86/Makefile +1
-1@@ -211,7 +211,7 @@ endif KBUILD_LDFLAGS += -m elf_$(UTS_MACHINE) ifdef CONFIG_LTO_CLANG -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y) KBUILD_LDFLAGS += -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8) endif endifscripts/Kbuild.include +10
-0@@ -11,6 +11,16 @@ space := $(empty) $(empty) space_escape := _-_SPACE_-_ pound := \# +### +# Comparison macros. +# Usage: $(call test-le, A, B) +# works like shell's "test A -le B", but A and B must have the same number of +# digits since it is just ASCII sort. +test-le = $(if $(filter $1, $(firstword $(sort $1 $2))),y) +test-ge = $(call test-le, $2, $1) +test-lt = $(if $(filter-out $2, $(firstword $(sort $1 $2))),y) +test-gt = $(call test-lt, $2, $1) + ### # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o dot-target = $(dir $@).$(notdir $@)
Quoted 3 lines · Masahiro Yamada
Because GNU Make is only able to handle strings, it is very hard to perform arighmetic in Makefiles.
I terribly missed that GNU Make 4.4
introduced the $(intcmp ...) function.
https://www.gnu.org/software/make/manual/make.html#Conditional-Functions
I am thinking if we can do better by using it.
Quoted 112 lines
When we compare two integers, we invokes shell. One example is in the top
Makefile:ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0)This is more expensive than using built-in functions since it forks a process.
If we know the two have the same number of digits, we can do better.
This commit adds four macros, test-le, test-ge, test-lt, test-gt.
$(call test-lt, A, B) is evaluated to 'y' if A is less than B, or empty otherwise. This will replace $(call shell test A -lt B).
Again, the limitation is that A and B must have the same number of digits because these macros are based on $(sort ) function.
$(call test-lt, 1, 9) --> y (Works!) $(call test-lt, 10, 9) --> y (Not work...)To make the latter work, you need to add '0' prefix to align the number of digits:
$(call test-lt, 10, 09) --> empty (Works!)Actually, we can live with this limitation in many places. As for the example above, we know $(CONFIG_LLD_VERSION) is 6-digits because the minimal supported version of LLVM is 11.0.0.
So, the shell invocation can be replaced with more efficient code:
ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y)Of course, this assumption will break when LLVM 100 is released, but it will be far in the future.
Signed-off-by Masahiro Yamada <[email protected]>---
(no changes since v1)
Makefile | 2 +- arch/riscv/Makefile | 2 +- arch/x86/Makefile | 2 +- scripts/Kbuild.include | 10 ++++++++++ 4 files changed, 13 insertions(+), 3 deletions(-)Makefile +1
-1@@ -986,7 +986,7 @@ KBUILD_LDFLAGS += -mllvm -import-instr-limit=5 # Check for frame size exceeding threshold during prolog/epilog insertion # when using lld < 13.0.0. ifneq ($(CONFIG_FRAME_WARN),0) -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y) KBUILD_LDFLAGS += -plugin-opt=-warn-stack-size=$(CONFIG_FRAME_WARN) endif endifarch/riscv/Makefile +1
-1@@ -37,7 +37,7 @@ else endif ifeq ($(CONFIG_LD_IS_LLD),y) -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 150000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 150000),y) KBUILD_CFLAGS += -mno-relax KBUILD_AFLAGS += -mno-relax ifndef CONFIG_AS_IS_LLVMarch/x86/Makefile +1
-1@@ -211,7 +211,7 @@ endif KBUILD_LDFLAGS += -m elf_$(UTS_MACHINE) ifdef CONFIG_LTO_CLANG -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y) KBUILD_LDFLAGS += -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8) endif endifscripts/Kbuild.include +10
-1@@ -11,6 +11,16 @@ space := $(empty) $(empty) space_escape := _-_SPACE_-_ pound := \# +### +# Comparison macros. +# Usage: $(call test-le, A, B) +# works like shell's "test A -le B", but A and B must have the same number of +# digits since it is just ASCII sort. +test-le = $(if $(filter $1, $(firstword $(sort $1 $2))),y) +test-ge = $(call test-le, $2, $1) +test-lt = $(if $(filter-out $2, $(firstword $(sort $1 $2))),y) +test-gt = $(call test-lt, $2, $1) + ### # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o dot-target = $(dir $@).$(notdir $@) --2.34.1
Signature · 2 lines
Best Regards Masahiro Yamada