+KERNEL_MAKE = $(MAKE) $(KERNEL_MAKEOPTS)
+
+KERNEL_MAKE_FLAGS = \
+ KCFLAGS="$(call iremap,$(BUILD_DIR),$(notdir $(BUILD_DIR)))" \
+ HOSTCFLAGS="$(HOST_CFLAGS) -Wall -Wmissing-prototypes -Wstrict-prototypes" \
+ CROSS_COMPILE="$(KERNEL_CROSS)" \
+ ARCH="$(LINUX_KARCH)" \
+ KBUILD_HAVE_NLS=no \
+ KBUILD_BUILD_USER="$(call qstrip,$(CONFIG_KERNEL_BUILD_USER))" \
+ KBUILD_BUILD_HOST="$(call qstrip,$(CONFIG_KERNEL_BUILD_DOMAIN))" \
+ KBUILD_BUILD_TIMESTAMP="$(KBUILD_BUILD_TIMESTAMP)" \
+ KBUILD_BUILD_VERSION="0" \
+ HOST_LOADLIBES="-L$(STAGING_DIR_HOST)/lib" \
+ KBUILD_HOSTLDLIBS="-L$(STAGING_DIR_HOST)/lib" \
+ CONFIG_SHELL="$(BASH)" \
+ $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='') \
+ $(if $(PKG_BUILD_ID),LDFLAGS_MODULE=--build-id=0x$(PKG_BUILD_ID)) \
+ cmd_syscalls= \
+ $(if $(__package_mk),KBUILD_EXTRA_SYMBOLS="$(wildcard $(PKG_SYMVERS_DIR)/*.symvers)")
+
+KERNEL_NOSTDINC_FLAGS = \
+ -nostdinc $(if $(DUMP),, -isystem $(shell $(TARGET_CC) -print-file-name=include))
+
+ifeq ($(call qstrip,$(CONFIG_EXTERNAL_KERNEL_TREE))$(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI)),)
+ KERNEL_MAKE_FLAGS += \
+ KERNELRELEASE=$(LINUX_VERSION)
+endif
+
+KERNEL_MAKEOPTS := -C $(LINUX_DIR) $(KERNEL_MAKE_FLAGS)
+
+ifdef CONFIG_USE_SPARSE
+ KERNEL_MAKEOPTS += C=1 CHECK=$(STAGING_DIR_HOST)/bin/sparse
+endif
+
+ifneq ($(HOST_OS),Linux)
+ KERNEL_MAKEOPTS += CONFIG_STACK_VALIDATION=
+ export SKIP_STACK_VALIDATION:=1
+endif
+
+PKG_EXTMOD_SUBDIRS ?= .
+
+PKG_SYMVERS_DIR = $(KERNEL_BUILD_DIR)/symvers
+
+define collect_module_symvers
+ for subdir in $(PKG_EXTMOD_SUBDIRS); do \
+ realdir=$$$$(readlink -f $(PKG_BUILD_DIR)); \
+ grep -F $(PKG_BUILD_DIR) $(PKG_BUILD_DIR)/$$$$subdir/Module.symvers >> $(PKG_BUILD_DIR)/Module.symvers.tmp; \
+ [ "$(PKG_BUILD_DIR)" = "$$$$realdir" ] || \
+ grep -F $$$$realdir $(PKG_BUILD_DIR)/$$$$subdir/Module.symvers >> $(PKG_BUILD_DIR)/Module.symvers.tmp; \
+ done; \
+ sort -u $(PKG_BUILD_DIR)/Module.symvers.tmp > $(PKG_BUILD_DIR)/Module.symvers; \
+ mkdir -p $(PKG_SYMVERS_DIR); \
+ mv $(PKG_BUILD_DIR)/Module.symvers $(PKG_SYMVERS_DIR)/$(PKG_NAME).symvers
+endef
+
+define KernelPackage/hooks
+ ifneq ($(PKG_NAME),kernel)
+ Hooks/Compile/Post += collect_module_symvers
+ endif
+ define KernelPackage/hooks
+ endef
+endef
+