mac80211: fix reordering of buffered broadcast packets
[openwrt/openwrt.git] / include / kernel.mk
1 #
2 # Copyright (C) 2006-2015 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 ifneq ($(filter check,$(MAKECMDGOALS)),)
9 CHECK:=1
10 DUMP:=1
11 endif
12
13 ifneq ($(SOURCE_DATE_EPOCH),)
14 ifndef DUMP
15 KBUILD_BUILD_TIMESTAMP:=$(shell perl -e 'print scalar gmtime($(SOURCE_DATE_EPOCH))')
16 endif
17 endif
18
19 ifeq ($(__target_inc),)
20 ifndef CHECK
21 include $(INCLUDE_DIR)/target.mk
22 endif
23 endif
24
25 ifeq ($(DUMP),1)
26 KERNEL?=<KERNEL>
27 BOARD?=<BOARD>
28 LINUX_VERSION?=<LINUX_VERSION>
29 LINUX_VERMAGIC?=<LINUX_VERMAGIC>
30 else
31 ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
32 export GCC_HONOUR_COPTS=s
33 endif
34
35 LINUX_KMOD_SUFFIX=ko
36
37 ifneq (,$(findstring uml,$(BOARD)))
38 KERNEL_CC?=$(HOSTCC)
39 KERNEL_CROSS?=
40 else
41 KERNEL_CC?=$(TARGET_CC)
42 KERNEL_CROSS?=$(TARGET_CROSS)
43 endif
44
45 ifeq ($(TARGET_BUILD),1)
46 PATCH_DIR ?= $(CURDIR)/patches$(if $(wildcard ./patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
47 FILES_DIR ?= $(foreach dir,$(wildcard $(CURDIR)/files $(CURDIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
48 endif
49 KERNEL_BUILD_DIR ?= $(BUILD_DIR)/linux-$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET))
50 LINUX_DIR ?= $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)
51 LINUX_UAPI_DIR=uapi/
52 LINUX_VERMAGIC:=$(strip $(shell cat $(LINUX_DIR)/.vermagic 2>/dev/null))
53 LINUX_VERMAGIC:=$(if $(LINUX_VERMAGIC),$(LINUX_VERMAGIC),unknown)
54
55 LINUX_UNAME_VERSION:=$(KERNEL_BASE)
56 ifneq ($(findstring -rc,$(LINUX_VERSION)),)
57 LINUX_UNAME_VERSION:=$(LINUX_UNAME_VERSION)-$(strip $(lastword $(subst -, ,$(LINUX_VERSION))))
58 endif
59
60 LINUX_KERNEL:=$(KERNEL_BUILD_DIR)/vmlinux
61
62 LINUX_SOURCE:=linux-$(LINUX_VERSION).tar.xz
63 ifeq ($(call qstrip,$(CONFIG_EXTERNAL_KERNEL_TREE))$(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI)),)
64 LINUX_SITE:=@KERNEL/linux/kernel/v$(word 1,$(subst ., ,$(KERNEL_BASE))).x
65 else
66 LINUX_UNAME_VERSION:=$(strip $(shell cat $(LINUX_DIR)/include/config/kernel.release 2>/dev/null))
67 endif
68
69 MODULES_SUBDIR:=lib/modules/$(LINUX_UNAME_VERSION)
70 TARGET_MODULES_DIR:=$(LINUX_TARGET_DIR)/$(MODULES_SUBDIR)
71
72 ifneq ($(TARGET_BUILD),1)
73 PKG_BUILD_DIR ?= $(KERNEL_BUILD_DIR)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
74 endif
75 endif
76
77 ifneq (,$(findstring uml,$(BOARD)))
78 LINUX_KARCH=um
79 else ifneq (,$(findstring $(ARCH) , aarch64 aarch64_be ))
80 LINUX_KARCH := arm64
81 else ifneq (,$(findstring $(ARCH) , arceb ))
82 LINUX_KARCH := arc
83 else ifneq (,$(findstring $(ARCH) , armeb ))
84 LINUX_KARCH := arm
85 else ifneq (,$(findstring $(ARCH) , mipsel mips64 mips64el ))
86 LINUX_KARCH := mips
87 else ifneq (,$(findstring $(ARCH) , powerpc64 ))
88 LINUX_KARCH := powerpc
89 else ifneq (,$(findstring $(ARCH) , sh2 sh3 sh4 ))
90 LINUX_KARCH := sh
91 else ifneq (,$(findstring $(ARCH) , i386 x86_64 ))
92 LINUX_KARCH := x86
93 else
94 LINUX_KARCH := $(ARCH)
95 endif
96
97 KERNEL_MAKE = $(MAKE) $(KERNEL_MAKEOPTS)
98
99 KERNEL_MAKE_FLAGS = \
100 HOSTCFLAGS="$(HOST_CFLAGS) -Wall -Wmissing-prototypes -Wstrict-prototypes" \
101 CROSS_COMPILE="$(KERNEL_CROSS)" \
102 ARCH="$(LINUX_KARCH)" \
103 KBUILD_HAVE_NLS=no \
104 KBUILD_BUILD_USER="$(call qstrip,$(CONFIG_KERNEL_BUILD_USER))" \
105 KBUILD_BUILD_HOST="$(call qstrip,$(CONFIG_KERNEL_BUILD_DOMAIN))" \
106 KBUILD_BUILD_TIMESTAMP="$(KBUILD_BUILD_TIMESTAMP)" \
107 KBUILD_BUILD_VERSION="0" \
108 HOST_LOADLIBES="-L$(STAGING_DIR_HOST)/lib" \
109 CONFIG_SHELL="$(BASH)" \
110 $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='') \
111 $(if $(PKG_BUILD_ID),LDFLAGS_MODULE=--build-id=0x$(PKG_BUILD_ID)) \
112 cmd_syscalls=
113
114 ifeq ($(call qstrip,$(CONFIG_EXTERNAL_KERNEL_TREE))$(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI)),)
115 KERNEL_MAKE_FLAGS += \
116 KERNELRELEASE=$(LINUX_VERSION)
117 endif
118
119 KERNEL_MAKEOPTS := -C $(LINUX_DIR) $(KERNEL_MAKE_FLAGS)
120
121 ifdef CONFIG_USE_SPARSE
122 KERNEL_MAKEOPTS += C=1 CHECK=$(STAGING_DIR_HOST)/bin/sparse
123 endif
124
125 PKG_EXTMOD_SUBDIRS ?= .
126
127 define populate_module_symvers
128 @mkdir -p $(PKG_INFO_DIR)
129 cat /dev/null > $(PKG_INFO_DIR)/$(PKG_NAME).symvers; \
130 for subdir in $(PKG_EXTMOD_SUBDIRS); do \
131 cat $(PKG_INFO_DIR)/*.symvers 2>/dev/null > $(PKG_BUILD_DIR)/$$$$subdir/Module.symvers; \
132 done
133 endef
134
135 define collect_module_symvers
136 for subdir in $(PKG_EXTMOD_SUBDIRS); do \
137 grep -F $$$$(readlink -f $(PKG_BUILD_DIR)) $(PKG_BUILD_DIR)/$$$$subdir/Module.symvers >> $(PKG_BUILD_DIR)/Module.symvers.tmp; \
138 done; \
139 sort -u $(PKG_BUILD_DIR)/Module.symvers.tmp > $(PKG_BUILD_DIR)/Module.symvers; \
140 mv $(PKG_BUILD_DIR)/Module.symvers $(PKG_INFO_DIR)/$(PKG_NAME).symvers
141 endef
142
143 define KernelPackage/hooks
144 ifneq ($(PKG_NAME),kernel)
145 Hooks/Compile/Pre += populate_module_symvers
146 Hooks/Compile/Post += collect_module_symvers
147 endif
148 define KernelPackage/hooks
149 endef
150 endef
151
152 define KernelPackage/Defaults
153 FILES:=
154 AUTOLOAD:=
155 MODPARAMS:=
156 PKGFLAGS+=nonshared
157 endef
158
159 # 1: name
160 # 2: install prefix
161 # 3: module priority prefix
162 # 4: required for boot
163 # 5: module list
164 define ModuleAutoLoad
165 $(if $(5), \
166 mkdir -p $(2)/etc/modules.d; \
167 ($(foreach mod,$(5), \
168 echo "$(mod)$(if $(MODPARAMS.$(mod)), $(MODPARAMS.$(mod)),$(if $(MODPARAMS), $(MODPARAMS)))"; )) > $(2)/etc/modules.d/$(3)$(1); \
169 $(if $(4), \
170 mkdir -p $(2)/etc/modules-boot.d; \
171 ln -sf ../modules.d/$(3)$(1) $(2)/etc/modules-boot.d/;))
172 endef
173
174 ifeq ($(DUMP)$(TARGET_BUILD),)
175 -include $(LINUX_DIR)/.config
176 endif
177
178 define KernelPackage/depends
179 $(STAMP_BUILT): $(LINUX_DIR)/.config
180 define KernelPackage/depends
181 endef
182 endef
183
184 define KernelPackage
185 NAME:=$(1)
186 $(eval $(call Package/Default))
187 $(eval $(call KernelPackage/Defaults))
188 $(eval $(call KernelPackage/$(1)))
189 $(eval $(call KernelPackage/$(1)/$(BOARD)))
190 $(eval $(call KernelPackage/$(1)/$(BOARD)/$(if $(SUBTARGET),$(SUBTARGET),generic)))
191
192 define Package/kmod-$(1)
193 TITLE:=$(TITLE)
194 SECTION:=kernel
195 CATEGORY:=Kernel modules
196 DESCRIPTION:=$(DESCRIPTION)
197 EXTRA_DEPENDS:=kernel (=$(LINUX_VERSION)-$(LINUX_RELEASE)-$(LINUX_VERMAGIC))
198 VERSION:=$(LINUX_VERSION)$(if $(PKG_VERSION),+$(PKG_VERSION))-$(if $(PKG_RELEASE),$(PKG_RELEASE),$(LINUX_RELEASE))
199 PKGFLAGS:=$(PKGFLAGS)
200 $(call KernelPackage/$(1))
201 $(call KernelPackage/$(1)/$(BOARD))
202 $(call KernelPackage/$(1)/$(BOARD)/$(if $(SUBTARGET),$(SUBTARGET),generic))
203 endef
204
205 ifdef KernelPackage/$(1)/conffiles
206 define Package/kmod-$(1)/conffiles
207 $(call KernelPackage/$(1)/conffiles)
208 endef
209 endif
210
211 ifdef KernelPackage/$(1)/description
212 define Package/kmod-$(1)/description
213 $(call KernelPackage/$(1)/description)
214 endef
215 endif
216
217 ifdef KernelPackage/$(1)/config
218 define Package/kmod-$(1)/config
219 $(call KernelPackage/$(1)/config)
220 endef
221 endif
222
223 $(call KernelPackage/depends)
224 $(call KernelPackage/hooks)
225
226 ifneq ($(if $(filter-out %=y %=n %=m,$(KCONFIG)),$(filter m y,$(foreach c,$(filter-out %=y %=n %=m,$(KCONFIG)),$($(c)))),.),)
227 define Package/kmod-$(1)/install
228 @for mod in $$(call version_filter,$$(FILES)); do \
229 if grep -q "$$$$$$$${mod##$(LINUX_DIR)/}" "$(LINUX_DIR)/modules.builtin"; then \
230 echo "NOTICE: module '$$$$$$$$mod' is built-in."; \
231 elif [ -e $$$$$$$$mod ]; then \
232 mkdir -p $$(1)/$(MODULES_SUBDIR) ; \
233 $(CP) -L $$$$$$$$mod $$(1)/$(MODULES_SUBDIR)/ ; \
234 else \
235 echo "ERROR: module '$$$$$$$$mod' is missing." >&2; \
236 exit 1; \
237 fi; \
238 done;
239 $(call ModuleAutoLoad,$(1),$$(1),$(filter-out 0-,$(word 1,$(AUTOLOAD))-),$(filter-out 0,$(word 2,$(AUTOLOAD))),$(wordlist 3,99,$(AUTOLOAD)))
240 $(call KernelPackage/$(1)/install,$$(1))
241 endef
242 $(if $(CONFIG_PACKAGE_kmod-$(1)),
243 else
244 compile: $(1)-disabled
245 $(1)-disabled:
246 @echo "WARNING: kmod-$(1) is not available in the kernel config - generating empty package" >&2
247
248 define Package/kmod-$(1)/install
249 true
250 endef
251 )
252 endif
253 $$(eval $$(call BuildPackage,kmod-$(1)))
254
255 $$(IPKG_kmod-$(1)): $$(wildcard $$(FILES))
256
257 endef
258
259 version_filter=$(if $(findstring @,$(1)),$(shell $(SCRIPT_DIR)/package-metadata.pl version_filter $(KERNEL_PATCHVER) $(1)),$(1))
260
261 # 1: priority (optional)
262 # 2: module list
263 # 3: boot flag
264 define AutoLoad
265 $(if $(1),$(1),0) $(if $(3),1,0) $(call version_filter,$(2))
266 endef
267
268 # 1: module list
269 # 2: boot flag
270 define AutoProbe
271 $(call AutoLoad,,$(1),$(2))
272 endef
273
274 version_field=$(if $(word $(1),$(2)),$(word $(1),$(2)),0)
275 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)) ))
276
277 ifdef DUMP
278 kernel_version_cmp=
279 else
280 kernel_version_cmp=$(shell [ $(call kernel_version_merge,$(call split_version,$(2))) $(1) $(call kernel_version_merge,$(call split_version,$(3))) ] && echo 1 )
281 endif
282
283 CompareKernelPatchVer=$(if $(call kernel_version_cmp,-$(2),$(1),$(3)),1,0)
284
285 kernel_patchver_gt=$(call kernel_version_cmp,-gt,$(KERNEL_PATCHVER),$(1))
286 kernel_patchver_ge=$(call kernel_version_cmp,-ge,$(KERNEL_PATCHVER),$(1))
287 kernel_patchver_eq=$(call kernel_version_cmp,-eq,$(KERNEL_PATCHVER),$(1))
288 kernel_patchver_le=$(call kernel_version_cmp,-le,$(KERNEL_PATCHVER),$(1))
289 kernel_patchver_lt=$(call kernel_version_cmp,-lt,$(KERNEL_PATCHVER),$(1))
290