2 # Copyright (C) 2006-2015 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
8 ifneq ($(filter check,$(MAKECMDGOALS)),)
13 ifeq ($(__target_inc),)
15 include $(INCLUDE_DIR)/target.mk
22 LINUX_VERSION?=<LINUX_VERSION>
23 LINUX_VERMAGIC?=<LINUX_VERMAGIC>
25 ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
26 export GCC_HONOUR_COPTS=s
31 ifneq (,$(findstring uml,$(BOARD)))
35 KERNEL_CC?=$(TARGET_CC)
36 KERNEL_CROSS?=$(TARGET_CROSS)
39 ifeq ($(TARGET_BUILD),1)
40 PATCH_DIR ?= $(CURDIR)/patches$(if $(wildcard ./patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
41 FILES_DIR ?= $(foreach dir,$(wildcard $(CURDIR)/files $(CURDIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
43 KERNEL_BUILD_DIR ?= $(BUILD_DIR)/linux-$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET))
44 LINUX_DIR ?= $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)
46 LINUX_VERMAGIC:=$(strip $(shell cat $(LINUX_DIR)/.vermagic 2>/dev/null))
47 LINUX_VERMAGIC:=$(if $(LINUX_VERMAGIC),$(LINUX_VERMAGIC),unknown)
49 LINUX_UNAME_VERSION:=$(if $(word 3,$(subst ., ,$(KERNEL_BASE))),$(KERNEL_BASE),$(KERNEL_BASE).0)
50 ifneq ($(findstring -rc,$(LINUX_VERSION)),)
51 LINUX_UNAME_VERSION:=$(LINUX_UNAME_VERSION)-$(strip $(lastword $(subst -, ,$(LINUX_VERSION))))
54 LINUX_KERNEL:=$(KERNEL_BUILD_DIR)/vmlinux
56 LINUX_SOURCE:=linux-$(LINUX_VERSION).tar.xz
57 TESTING:=$(if $(findstring -rc,$(LINUX_VERSION)),/testing,)
58 ifeq ($(call qstrip,$(CONFIG_EXTERNAL_KERNEL_TREE))$(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI)),)
59 LINUX_SITE:=@KERNEL/linux/kernel/v$(word 1,$(subst ., ,$(KERNEL_BASE))).x$(TESTING)
61 LINUX_UNAME_VERSION:=$(strip $(shell cat $(LINUX_DIR)/include/config/kernel.release))
64 MODULES_SUBDIR:=lib/modules/$(LINUX_UNAME_VERSION)
65 TARGET_MODULES_DIR:=$(LINUX_TARGET_DIR)/$(MODULES_SUBDIR)
67 ifneq ($(TARGET_BUILD),1)
68 PKG_BUILD_DIR ?= $(KERNEL_BUILD_DIR)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
72 ifneq (,$(findstring uml,$(BOARD)))
74 else ifneq (,$(findstring $(ARCH) , aarch64 aarch64_be ))
76 else ifneq (,$(findstring $(ARCH) , arceb ))
78 else ifneq (,$(findstring $(ARCH) , armeb ))
80 else ifneq (,$(findstring $(ARCH) , mipsel mips64 mips64el ))
82 else ifneq (,$(findstring $(ARCH) , sh2 sh3 sh4 ))
84 else ifneq (,$(findstring $(ARCH) , i386 x86_64 ))
87 LINUX_KARCH := $(ARCH)
90 define KernelPackage/Defaults
100 local mods="$$$$$$$$1"; \
101 local boot="$$$$$$$$2"; \
104 for mod in $$$$$$$$mods; do \
105 mkdir -p $(2)/etc/modules.d; \
106 echo "$$$$$$$$mod" >> $(2)/etc/modules.d/$(1); \
108 if [ -e $(2)/etc/modules.d/$(1) ]; then \
109 if [ "$$$$$$$$boot" = "1" -a ! -e $(2)/etc/modules-boot.d/$(1) ]; then \
110 mkdir -p $(2)/etc/modules-boot.d; \
111 ln -s ../modules.d/$(1) $(2)/etc/modules-boot.d/; \
113 modules="$$$$$$$${modules:+$$$$$$$$modules }$$$$$$$$mods"; \
117 local priority="$$$$$$$$1"; \
118 local mods="$$$$$$$$2"; \
119 local boot="$$$$$$$$3"; \
122 for mod in $$$$$$$$mods; do \
123 mkdir -p $(2)/etc/modules.d; \
124 echo "$$$$$$$$mod" >> $(2)/etc/modules.d/$$$$$$$$priority-$(1); \
126 if [ -e $(2)/etc/modules.d/$$$$$$$$priority-$(1) ]; then \
127 if [ "$$$$$$$$boot" = "1" -a ! -e $(2)/etc/modules-boot.d/$$$$$$$$priority-$(1) ]; then \
128 mkdir -p $(2)/etc/modules-boot.d; \
129 ln -s ../modules.d/$$$$$$$$priority-$(1) $(2)/etc/modules-boot.d/; \
131 modules="$$$$$$$${modules:+$$$$$$$$modules }$$$$$$$$priority-$(1)"; \
135 if [ -n "$$$$$$$$modules" ]; then \
136 modules="$$$$$$$$(echo "$$$$$$$$modules" | tr ' ' '\n' | sort | uniq | paste -s -d' ' -)"; \
137 mkdir -p $(2)/etc/modules.d; \
138 mkdir -p $(2)/CONTROL; \
139 echo "#!/bin/sh" > $(2)/CONTROL/postinst-pkg; \
140 echo "[ -z \"\$$$$$$$$IPKG_INSTROOT\" ] || exit 0" >> $(2)/CONTROL/postinst-pkg; \
141 echo ". /lib/functions.sh" >> $(2)/CONTROL/postinst-pkg; \
142 echo "insert_modules $$$$$$$$modules" >> $(2)/CONTROL/postinst-pkg; \
143 chmod 0755 $(2)/CONTROL/postinst-pkg; \
147 ifeq ($(DUMP)$(TARGET_BUILD),)
148 -include $(LINUX_DIR)/.config
151 define KernelPackage/depends
152 $(STAMP_BUILT): $(LINUX_DIR)/.config
153 define KernelPackage/depends
159 $(eval $(call Package/Default))
160 $(eval $(call KernelPackage/Defaults))
161 $(eval $(call KernelPackage/$(1)))
162 $(eval $(call KernelPackage/$(1)/$(BOARD)))
163 $(eval $(call KernelPackage/$(1)/$(BOARD)/$(if $(SUBTARGET),$(SUBTARGET),generic)))
165 define Package/kmod-$(1)
168 CATEGORY:=Kernel modules
169 DESCRIPTION:=$(DESCRIPTION)
170 EXTRA_DEPENDS:=kernel (=$(LINUX_VERSION)-$(LINUX_RELEASE)-$(LINUX_VERMAGIC))
171 VERSION:=$(LINUX_VERSION)$(if $(PKG_VERSION),+$(PKG_VERSION))-$(if $(PKG_RELEASE),$(PKG_RELEASE),$(LINUX_RELEASE))
172 PKGFLAGS:=$(PKGFLAGS)
173 $(call KernelPackage/$(1))
174 $(call KernelPackage/$(1)/$(BOARD))
175 $(call KernelPackage/$(1)/$(BOARD)/$(if $(SUBTARGET),$(SUBTARGET),generic))
178 ifdef KernelPackage/$(1)/conffiles
179 define Package/kmod-$(1)/conffiles
180 $(call KernelPackage/$(1)/conffiles)
184 ifdef KernelPackage/$(1)/description
185 define Package/kmod-$(1)/description
186 $(call KernelPackage/$(1)/description)
190 ifdef KernelPackage/$(1)/config
191 define Package/kmod-$(1)/config
192 $(call KernelPackage/$(1)/config)
196 $(call KernelPackage/depends)
198 ifneq ($(if $(filter-out %=y %=n %=m,$(KCONFIG)),$(filter m y,$(foreach c,$(filter-out %=y %=n %=m,$(KCONFIG)),$($(c)))),.),)
199 ifneq ($(strip $(FILES)),)
200 define Package/kmod-$(1)/install
201 @for mod in $$(call version_filter,$$(FILES)); do \
202 if grep -q "$$$$$$$${mod##$(LINUX_DIR)/}" "$(LINUX_DIR)/modules.builtin"; then \
203 echo "NOTICE: module '$$$$$$$$mod' is built-in."; \
204 elif [ -e $$$$$$$$mod ]; then \
205 mkdir -p $$(1)/$(MODULES_SUBDIR) ; \
206 $(CP) -L $$$$$$$$mod $$(1)/$(MODULES_SUBDIR)/ ; \
208 echo "ERROR: module '$$$$$$$$mod' is missing." >&2; \
212 $(call ModuleAutoLoad,$(1),$$(1),$(AUTOLOAD))
213 $(call KernelPackage/$(1)/install,$$(1))
216 $(if $(CONFIG_PACKAGE_kmod-$(1)),
218 compile: $(1)-disabled
220 @echo "WARNING: kmod-$(1) is not available in the kernel config - generating empty package" >&2
222 define Package/kmod-$(1)/install
227 $$(eval $$(call BuildPackage,kmod-$(1)))
229 $$(IPKG_kmod-$(1)): $$(wildcard $$(FILES))
232 version_filter=$(if $(findstring @,$(1)),$(shell $(SCRIPT_DIR)/package-metadata.pl version_filter $(KERNEL_PATCHVER) $(1)),$(1))
235 add_module "$(1)" "$(call version_filter,$(2))" "$(3)";
239 probe_module "$(call version_filter,$(1))" "$(2)";
242 version_field=$(if $(word $(1),$(2)),$(word $(1),$(2)),0)
243 kernel_version_merge=$$(( ($(call version_field,1,$(1)) << 24) + ($(call version_field,2,$(1)) << 16) + ($(call version_field,3,$(1)) << 8) + $(call version_field,4,$(1)) ))
248 kernel_version_cmp=$(shell [ $(call kernel_version_merge,$(call split_version,$(2))) $(1) $(call kernel_version_merge,$(call split_version,$(3))) ] && echo 1 )
251 CompareKernelPatchVer=$(if $(call kernel_version_cmp,-$(2),$(1),$(3)),1,0)
253 kernel_patchver_gt=$(call kernel_version_cmp,-gt,$(KERNEL_PATCHVER),$(1))
254 kernel_patchver_ge=$(call kernel_version_cmp,-ge,$(KERNEL_PATCHVER),$(1))
255 kernel_patchver_eq=$(call kernel_version_cmp,-eq,$(KERNEL_PATCHVER),$(1))
256 kernel_patchver_le=$(call kernel_version_cmp,-le,$(KERNEL_PATCHVER),$(1))
257 kernel_patchver_lt=$(call kernel_version_cmp,-lt,$(KERNEL_PATCHVER),$(1))