[RFC PATCH v2 2/2] kbuild: call check-atomics.sh only if prerequisites change

From: Vincent Mailhol
Date: Sat May 07 2022 - 09:13:07 EST


check-atomics.sh is executed unconditionally. Most developers will not
modify the files being checked by this script and thus do not need to
execute it again for each iterative make.

We first add an additional dependency to include/linux/atomic/* to
make sure that the script gets executed again if the headers are
modified. We then use the if_change macro instead of cmd. c.f. [1] and
create the dot file scripts/atomic/.check-atomics which is used for
the target timestamp. Finally, the dot file is added to the
CLEAN_FILES target.

[1] https://www.kernel.org/doc/html/latest/kbuild/makefiles.html#command-change-detection

Signed-off-by: Vincent Mailhol <mailhol.vincent@xxxxxxxxxx>
---
Kbuild | 7 ++++---
Makefile | 3 ++-
2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/Kbuild b/Kbuild
index fa441b98c9f6..c3cb76ebcbaf 100644
--- a/Kbuild
+++ b/Kbuild
@@ -50,10 +50,11 @@ missing-syscalls: scripts/checksyscalls.sh $(offsets-file) FORCE
#####
# Check atomic headers are up-to-date

-always-y += old-atomics
+always-y += scripts/atomic/.check-atomics

quiet_cmd_atomics = CALL $<
cmd_atomics = $(CONFIG_SHELL) $<

-old-atomics: scripts/atomic/check-atomics.sh FORCE
- $(call cmd,atomics)
+scripts/atomic/.check-atomics: scripts/atomic/check-atomics.sh $(wildcard include/linux/atomic/*) FORCE
+ $(call if_changed,atomics)
+ @touch $@
diff --git a/Makefile b/Makefile
index 9a820c525b86..9e815c8bb0b6 100644
--- a/Makefile
+++ b/Makefile
@@ -1483,7 +1483,8 @@ endif # CONFIG_MODULES
# Directories & files removed with 'make clean'
CLEAN_FILES += include/ksym vmlinux.symvers modules-only.symvers \
modules.builtin modules.builtin.modinfo modules.nsdeps \
- compile_commands.json .thinlto-cache
+ compile_commands.json .thinlto-cache \
+ scripts/atomic/.check-atomics

# Directories & files removed with 'make mrproper'
MRPROPER_FILES += include/config include/generated \
--
2.35.1