toolchain: add a version that can be bumped to force toolchain/target rebuild
authorFelix Fietkau <nbd@nbd.name>
Tue, 16 Nov 2021 20:46:21 +0000 (12:46 -0800)
committerFelix Fietkau <nbd@nbd.name>
Tue, 16 Nov 2021 21:02:45 +0000 (22:02 +0100)
This can be used to ensure that the compiled code is up to date, when
something important changes in the toolchain.
A recent example of this is the gcc 11 fix for a code miscompilation issue

Signed-off-by: Felix Fietkau <nbd@nbd.name>
.gitignore
Makefile
scripts/check-toolchain-clean.sh [new file with mode: 0755]
toolchain/build_version [new file with mode: 0644]

index 11f280d0aa46322e85588c7095d1b11b25738845..91e257f5a96a3ca19f46f421b4a5380711d1aeb1 100644 (file)
@@ -5,6 +5,7 @@
 /dl
 /.config
 /.config.old
+/.toolchain_build_ver
 /bin
 /build_dir
 /staging_dir
index e18bc18608a171158aa268a90553804fa088cc22..39ab3ae4a52e5626dd45a3cd53903cebab05e34f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -38,7 +38,7 @@ else
   include tools/Makefile
   include toolchain/Makefile
 
-$(toolchain/stamp-compile): $(tools/stamp-compile)
+$(toolchain/stamp-compile): $(tools/stamp-compile) $(if $(CONFIG_BUILDBOT),toolchain_rebuild_check)
 $(target/stamp-compile): $(toolchain/stamp-compile) $(tools/stamp-compile) $(BUILD_DIR)/.prepared
 $(package/stamp-compile): $(target/stamp-compile) $(package/stamp-cleanup)
 $(package/stamp-install): $(package/stamp-compile)
@@ -50,14 +50,23 @@ printdb:
 
 prepare: $(target/stamp-compile)
 
-clean: FORCE
+_clean: FORCE
        rm -rf $(BUILD_DIR) $(STAGING_DIR) $(BIN_DIR) $(OUTPUT_DIR)/packages/$(ARCH_PACKAGES) $(BUILD_LOG_DIR) $(TOPDIR)/staging_dir/packages
 
-dirclean: clean
-       rm -rf $(STAGING_DIR_HOST) $(STAGING_DIR_HOSTPKG) $(TOOLCHAIN_DIR) $(BUILD_DIR_BASE)/host $(BUILD_DIR_BASE)/hostpkg $(BUILD_DIR_TOOLCHAIN)
+clean: _clean
+       rm -rf $(BUILD_LOG_DIR)
+
+targetclean: _clean
+       rm -rf $(TOOLCHAIN_DIR) $(BUILD_DIR_BASE)/hostpkg $(BUILD_DIR_TOOLCHAIN)
+
+dirclean: targetclean clean
+       rm -rf $(STAGING_DIR_HOST) $(STAGING_DIR_HOSTPKG) $(BUILD_DIR_BASE)/host
        rm -rf $(TMP_DIR)
        $(MAKE) -C $(TOPDIR)/scripts/config clean
 
+toolchain_rebuild_check:
+       $(SCRIPT_DIR)/check-toolchain-clean.sh
+
 cacheclean:
 ifneq ($(CONFIG_CCACHE),)
        $(STAGING_DIR_HOST)/bin/ccache -C
diff --git a/scripts/check-toolchain-clean.sh b/scripts/check-toolchain-clean.sh
new file mode 100755 (executable)
index 0000000..af24e74
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+eval `grep CONFIG_GCC_VERSION .config`
+CONFIG_TOOLCHAIN_BUILD_VER="$CONFIG_GCC_VERSION-$(cat toolchain/build_version)"
+touch .toolchain_build_ver
+[ "$CONFIG_TOOLCHAIN_BUILD_VER" = "$(cat .toolchain_build_ver)" ] && exit 0
+echo "Toolchain build version changed, running make targetclean"
+make targetclean
+echo "$CONFIG_TOOLCHAIN_BUILD_VER" > .toolchain_build_ver
+exit 0
diff --git a/toolchain/build_version b/toolchain/build_version
new file mode 100644 (file)
index 0000000..d00491f
--- /dev/null
@@ -0,0 +1 @@
+1