[source] kernel: make the kernel build auto-clean the build dir like package builds

LEDE Commits lede-commits at lists.infradead.org
Fri Aug 5 05:17:18 PDT 2016


nbd pushed a commit to source.git, branch master:
https://git.lede-project.org/?p=source.git;a=commitdiff;h=22ef1c83b35cd5633b0c58c9c38a43494a906a6a

commit 22ef1c83b35cd5633b0c58c9c38a43494a906a6a
Author: Felix Fietkau <nbd at nbd.name>
AuthorDate: Fri Aug 5 14:08:47 2016 +0200

    kernel: make the kernel build auto-clean the build dir like package builds
    
    Previous behavior can be restored by using QUILT=1 on target/prepare
    
    Signed-off-by: Felix Fietkau <nbd at nbd.name>
---
 include/kernel-build.mk    | 17 ++++++++++++++---
 include/kernel-defaults.mk |  2 +-
 include/kernel.mk          |  4 ++--
 include/quilt.mk           |  2 +-
 4 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/include/kernel-build.mk b/include/kernel-build.mk
index a52c90d..0ba6db8 100644
--- a/include/kernel-build.mk
+++ b/include/kernel-build.mk
@@ -6,13 +6,14 @@
 #
 include $(INCLUDE_DIR)/host.mk
 include $(INCLUDE_DIR)/prereq.mk
+include $(INCLUDE_DIR)/depends.mk
 
 ifneq ($(DUMP),1)
   all: compile
 endif
 
-export QUILT=1
-STAMP_PREPARED:=$(LINUX_DIR)/.prepared
+KERNEL_FILE_DEPENDS=$(GENERIC_PATCH_DIR) $(PATCH_DIR) $(GENERIC_FILES_DIR) $(FILES_DIR)
+STAMP_PREPARED=$(LINUX_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,$(KERNEL_FILE_DEPENDS),)))
 STAMP_CONFIGURED:=$(LINUX_DIR)/.configured
 include $(INCLUDE_DIR)/download.mk
 include $(INCLUDE_DIR)/quilt.mk
@@ -60,12 +61,22 @@ ifdef CONFIG_COLLECT_KERNEL_DEBUG
   endef
 endif
 
+ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
+  ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
+    define Kernel/Autoclean
+      $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
+      $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
+    endef
+  endif
+endif
+
 define BuildKernel
   $(if $(QUILT),$(Build/Quilt))
   $(if $(LINUX_SITE),$(call Download,kernel))
 
   .NOTPARALLEL:
 
+  $(Kernel/Autoclean)
   $(STAMP_PREPARED): $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
 	-rm -rf $(KERNEL_BUILD_DIR)
 	-mkdir -p $(KERNEL_BUILD_DIR)
@@ -102,7 +113,7 @@ define BuildKernel
 		echo; \
 	) > $$@
 
-  $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_KCONFIG_LIST) $(TOPDIR)/.config
+  $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_KCONFIG_LIST) $(TOPDIR)/.config FORCE
 	$(Kernel/Configure)
 	touch $$@
 
diff --git a/include/kernel-defaults.mk b/include/kernel-defaults.mk
index 3679dae..11dff75 100644
--- a/include/kernel-defaults.mk
+++ b/include/kernel-defaults.mk
@@ -50,7 +50,7 @@ ifeq ($(strip $(CONFIG_EXTERNAL_KERNEL_TREE)),"")
     define Kernel/Prepare/Default
 	xzcat $(DL_DIR)/$(LINUX_SOURCE) | $(TAR) -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
 	$(Kernel/Patch)
-	touch $(LINUX_DIR)/.quilt_used
+	$(if $(QUILT),touch $(LINUX_DIR)/.quilt_used)
     endef
   else
     define Kernel/Prepare/Default
diff --git a/include/kernel.mk b/include/kernel.mk
index 8ce4df8..2721c83 100644
--- a/include/kernel.mk
+++ b/include/kernel.mk
@@ -30,8 +30,8 @@ else
   endif
 
   ifeq ($(TARGET_BUILD),1)
-    PATCH_DIR ?= ./patches$(if $(wildcard ./patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
-    FILES_DIR ?= $(foreach dir,$(wildcard ./files ./files-$(KERNEL_PATCHVER)),"$(dir)")
+    PATCH_DIR ?= $(CURDIR)/patches$(if $(wildcard ./patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
+    FILES_DIR ?= $(foreach dir,$(wildcard $(CURDIR)/files $(CURDIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
   endif
   KERNEL_BUILD_DIR ?= $(BUILD_DIR)/linux-$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET))
   LINUX_DIR ?= $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)
diff --git a/include/quilt.mk b/include/quilt.mk
index b18b636..cd392a7 100644
--- a/include/quilt.mk
+++ b/include/quilt.mk
@@ -91,7 +91,7 @@ endef
 
 kernel_files=$(foreach fdir,$(GENERIC_FILES_DIR) $(FILES_DIR),$(fdir)/.)
 define Kernel/Patch/Default
-	rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches
+	$(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
 	$(if $(kernel_files),$(CP) $(kernel_files) $(LINUX_DIR)/)
 	find $(LINUX_DIR)/ -name \*.rej -or -name \*.orig | $(XARGS) rm -f
 	$(call PatchDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)



More information about the lede-commits mailing list