target/sdk: add support for building kernel module packages
target/sdk: add support for building kernel module packages

Signed-off-by: Felix Fietkau <nbd@openwrt.org>

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@39858 3c298f89-4303-0410-b956-a3cf2f4a3e73

--- a/target/sdk/Makefile
+++ b/target/sdk/Makefile
@@ -20,9 +20,35 @@
 	*/stamp \
 	*/stampfiles \
 	*/man \
-	*/info
+	*/info \
+
+SDK_DIRS = \
+		staging_dir/host \
+		staging_dir/target-$(ARCH)$(ARCH_SUFFIX)_$(LIBC)-$(LIBCV)$(if $(CONFIG_arm),_eabi) \
+		staging_dir/toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)_$(LIBC)-$(LIBCV)$(if $(CONFIG_arm),_eabi) \
 
 SVN_PACKAGE_URL=$(shell svn info ../../package | awk '/^URL:/ { print $$2; }')
+
+KDIR_BASE = $(patsubst $(TOPDIR)/%,%,$(LINUX_DIR))
+
+KERNEL_FILES_ARCH = \
+	Makefile* \
+	module.lds \
+	Kbuild.platforms \
+	*/Platform \
+	include \
+	scripts \
+	kernel/asm-offsets.s
+
+KERNEL_FILES_BASE := \
+	.config \
+	Makefile \
+	scripts \
+	include \
+	Module.symvers \
+	$(addprefix arch/$(LINUX_KARCH)/,$(KERNEL_FILES_ARCH))
+
+KERNEL_FILES := $(patsubst $(TOPDIR)/%,%,$(wildcard $(addprefix $(LINUX_DIR)/,$(KERNEL_FILES_BASE))))
 
 all: compile
 
@@ -32,8 +58,7 @@
 	$(TAR) -cf - -C $(TOPDIR) \
 		$(foreach exclude,$(EXCLUDE_DIRS),--exclude="$(exclude)") \
 		--exclude="staging_dir/$(ARCH)" \
-		staging_dir/host staging_dir/target-$(ARCH)$(ARCH_SUFFIX)_$(LIBC)-$(LIBCV)$(if $(CONFIG_arm),_eabi) \
-		staging_dir/toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)_$(LIBC)-$(LIBCV)$(if $(CONFIG_arm),_eabi) | \
+		$(SDK_DIRS) $(KERNEL_FILES) | \
 		$(TAR) -xf - -C $(SDK_BUILD_DIR)
 	mkdir -p $(SDK_BUILD_DIR)/target/linux
 	$(CP) $(GENERIC_PLATFORM_DIR) $(PLATFORM_DIR) $(SDK_BUILD_DIR)/target/linux/

comments