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 ifneq ($(SOURCE_DATE_EPOCH
),)
15 KBUILD_BUILD_TIMESTAMP
:=$(shell perl
-e
'print scalar gmtime($(SOURCE_DATE_EPOCH))')
19 ifeq ($(__target_inc
),)
21 include $(INCLUDE_DIR
)/target.mk
28 LINUX_VERSION?
=<LINUX_VERSION
>
29 LINUX_VERMAGIC?
=<LINUX_VERMAGIC
>
31 ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN
),)
32 export GCC_HONOUR_COPTS
=s
37 ifneq (,$(findstring uml
,$(BOARD
)))
41 KERNEL_CC?
=$(TARGET_CC
)
42 KERNEL_CROSS?
=$(TARGET_CROSS
)
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)")
49 KERNEL_BUILD_DIR ?
= $(BUILD_DIR
)/linux-
$(BOARD
)$(if
$(SUBTARGET
),_
$(SUBTARGET
))
50 LINUX_DIR ?
= $(KERNEL_BUILD_DIR
)/linux-
$(LINUX_VERSION
)
52 LINUX_VERMAGIC
:=$(strip $(shell cat
$(LINUX_DIR
)/.vermagic
2>/dev
/null
))
53 LINUX_VERMAGIC
:=$(if
$(LINUX_VERMAGIC
),$(LINUX_VERMAGIC
),unknown
)
55 LINUX_UNAME_VERSION
:=$(if
$(word 3,$(subst .
, ,$(KERNEL_BASE
))),$(KERNEL_BASE
),$(KERNEL_BASE
).0)
56 ifneq ($(findstring -rc
,$(LINUX_VERSION
)),)
57 LINUX_UNAME_VERSION
:=$(LINUX_UNAME_VERSION
)-$(strip $(lastword
$(subst -, ,$(LINUX_VERSION
))))
60 LINUX_KERNEL
:=$(KERNEL_BUILD_DIR
)/vmlinux
62 LINUX_SOURCE
:=linux-
$(LINUX_VERSION
).
tar.xz
63 TESTING
:=$(if
$(findstring -rc
,$(LINUX_VERSION
)),/testing
,)
64 ifeq ($(call qstrip
,$(CONFIG_EXTERNAL_KERNEL_TREE
))$(call qstrip
,$(CONFIG_KERNEL_GIT_CLONE_URI
)),)
65 LINUX_SITE
:=@KERNEL
/linux
/kernel
/v
$(word 1,$(subst .
, ,$(KERNEL_BASE
))).x
$(TESTING
)
67 LINUX_UNAME_VERSION
:=$(strip $(shell cat
$(LINUX_DIR
)/include/config
/kernel.release
))
70 MODULES_SUBDIR
:=lib
/modules
/$(LINUX_UNAME_VERSION
)
71 TARGET_MODULES_DIR
:=$(LINUX_TARGET_DIR
)/$(MODULES_SUBDIR
)
73 ifneq ($(TARGET_BUILD
),1)
74 PKG_BUILD_DIR ?
= $(KERNEL_BUILD_DIR
)/$(PKG_NAME
)$(if
$(PKG_VERSION
),-$(PKG_VERSION
))
78 ifneq (,$(findstring uml
,$(BOARD
)))
80 else ifneq (,$(findstring $(ARCH
) , aarch64 aarch64_be
))
82 else ifneq (,$(findstring $(ARCH
) , arceb
))
84 else ifneq (,$(findstring $(ARCH
) , armeb
))
86 else ifneq (,$(findstring $(ARCH
) , mipsel mips64 mips64el
))
88 else ifneq (,$(findstring $(ARCH
) , powerpc64
))
89 LINUX_KARCH
:= powerpc
90 else ifneq (,$(findstring $(ARCH
) , sh2 sh3 sh4
))
92 else ifneq (,$(findstring $(ARCH
) , i386 x86_64
))
95 LINUX_KARCH
:= $(ARCH
)
98 KERNEL_MAKE
= $(MAKE
) $(KERNEL_MAKEOPTS
)
100 KERNEL_MAKE_FLAGS
:= \
101 HOSTCFLAGS
="$(HOST_CFLAGS) -Wall -Wmissing-prototypes -Wstrict-prototypes" \
102 CROSS_COMPILE
="$(KERNEL_CROSS)" \
103 ARCH
="$(LINUX_KARCH)" \
105 KBUILD_BUILD_USER
="$(call qstrip,$(CONFIG_KERNEL_BUILD_USER))" \
106 KBUILD_BUILD_HOST
="$(call qstrip,$(CONFIG_KERNEL_BUILD_DOMAIN))" \
107 KBUILD_BUILD_TIMESTAMP
="$(KBUILD_BUILD_TIMESTAMP)" \
108 KBUILD_BUILD_VERSION
="0" \
109 HOST_LOADLIBES
="-L$(STAGING_DIR_HOST)/lib" \
110 CONFIG_SHELL
="$(BASH)" \
111 $(if
$(findstring c
,$(OPENWRT_VERBOSE
)),V
=1,V
='') \
112 $(if
$(PKG_BUILD_ID
),LDFLAGS_MODULE
=--build-id
=0x
$(PKG_BUILD_ID
)) \
115 ifeq ($(call qstrip
,$(CONFIG_EXTERNAL_KERNEL_TREE
))$(call qstrip
,$(CONFIG_KERNEL_GIT_CLONE_URI
)),)
116 KERNEL_MAKE_FLAGS
+= \
117 KERNELRELEASE
=$(LINUX_VERSION
)
120 KERNEL_MAKEOPTS
:= -C
$(LINUX_DIR
) $(KERNEL_MAKE_FLAGS
)
122 ifdef CONFIG_USE_SPARSE
123 KERNEL_MAKEOPTS
+= C
=1 CHECK
=$(STAGING_DIR_HOST
)/bin
/sparse
126 define KernelPackage
/Defaults
132 define ModuleAutoLoad
136 local mods
="$$$$$$$$1"; \
137 local boot
="$$$$$$$$2"; \
140 for mod in
$$$$$$$$mods; do \
141 mkdir
-p
$(2)/etc
/modules.d
; \
142 echo
"$$$$$$$$mod" >> $(2)/etc
/modules.d
/$(1); \
144 if
[ -e
$(2)/etc
/modules.d
/$(1) ]; then \
145 if
[ "$$$$$$$$boot" = "1" -a
! -e
$(2)/etc
/modules-boot.d
/$(1) ]; then \
146 mkdir
-p
$(2)/etc
/modules-boot.d
; \
147 ln
-s ..
/modules.d
/$(1) $(2)/etc
/modules-boot.d
/; \
149 modules
="$$$$$$$${modules:+$$$$$$$$modules }$$$$$$$$mods"; \
153 local priority
="$$$$$$$$1"; \
154 local mods
="$$$$$$$$2"; \
155 local boot
="$$$$$$$$3"; \
158 for mod in
$$$$$$$$mods; do \
159 mkdir
-p
$(2)/etc
/modules.d
; \
160 echo
"$$$$$$$$mod" >> $(2)/etc
/modules.d
/$$$$$$$$priority-$(1); \
162 if
[ -e
$(2)/etc
/modules.d
/$$$$$$$$priority-$(1) ]; then \
163 if
[ "$$$$$$$$boot" = "1" -a
! -e
$(2)/etc
/modules-boot.d
/$$$$$$$$priority-$(1) ]; then \
164 mkdir
-p
$(2)/etc
/modules-boot.d
; \
165 ln
-s ..
/modules.d
/$$$$$$$$priority-$(1) $(2)/etc
/modules-boot.d
/; \
167 modules
="$$$$$$$${modules:+$$$$$$$$modules }$$$$$$$$priority-$(1)"; \
171 if
[ -n
"$$$$$$$$modules" ]; then \
172 modules
="$$$$$$$$(echo "$$$$$$$$modules" | tr ' ' '\n' | sort | uniq | paste -s -d' ' -)"; \
173 mkdir
-p
$(2)/etc
/modules.d
; \
174 mkdir
-p
$(2)/CONTROL
; \
175 echo
"#!/bin/sh" > $(2)/CONTROL
/postinst-pkg
; \
176 echo
"[ -z \"\$$$$$$$$IPKG_INSTROOT\" ] || exit 0" >> $(2)/CONTROL
/postinst-pkg
; \
177 echo
". /lib/functions.sh" >> $(2)/CONTROL
/postinst-pkg
; \
178 echo
"insert_modules $$$$$$$$modules" >> $(2)/CONTROL
/postinst-pkg
; \
179 chmod
0755 $(2)/CONTROL
/postinst-pkg
; \
183 ifeq ($(DUMP
)$(TARGET_BUILD
),)
184 -include $(LINUX_DIR
)/.config
187 define KernelPackage
/depends
188 $(STAMP_BUILT
): $(LINUX_DIR
)/.config
189 define KernelPackage
/depends
195 $(eval
$(call Package
/Default
))
196 $(eval
$(call KernelPackage
/Defaults
))
197 $(eval
$(call KernelPackage
/$(1)))
198 $(eval
$(call KernelPackage
/$(1)/$(BOARD
)))
199 $(eval
$(call KernelPackage
/$(1)/$(BOARD
)/$(if
$(SUBTARGET
),$(SUBTARGET
),generic
)))
201 define Package
/kmod-
$(1)
204 CATEGORY
:=Kernel modules
205 DESCRIPTION
:=$(DESCRIPTION
)
206 EXTRA_DEPENDS
:=kernel
(=$(LINUX_VERSION
)-$(LINUX_RELEASE
)-$(LINUX_VERMAGIC
))
207 VERSION
:=$(LINUX_VERSION
)$(if
$(PKG_VERSION
),+$(PKG_VERSION
))-$(if
$(PKG_RELEASE
),$(PKG_RELEASE
),$(LINUX_RELEASE
))
208 PKGFLAGS
:=$(PKGFLAGS
)
209 $(call KernelPackage
/$(1))
210 $(call KernelPackage
/$(1)/$(BOARD
))
211 $(call KernelPackage
/$(1)/$(BOARD
)/$(if
$(SUBTARGET
),$(SUBTARGET
),generic
))
214 ifdef KernelPackage
/$(1)/conffiles
215 define Package
/kmod-
$(1)/conffiles
216 $(call KernelPackage
/$(1)/conffiles
)
220 ifdef KernelPackage
/$(1)/description
221 define Package
/kmod-
$(1)/description
222 $(call KernelPackage
/$(1)/description
)
226 ifdef KernelPackage
/$(1)/config
227 define Package
/kmod-
$(1)/config
228 $(call KernelPackage
/$(1)/config
)
232 $(call KernelPackage
/depends
)
234 ifneq ($(if
$(filter-out %=y
%=n
%=m
,$(KCONFIG
)),$(filter m y
,$(foreach c
,$(filter-out %=y
%=n
%=m
,$(KCONFIG
)),$($(c
)))),.
),)
235 ifneq ($(strip $(FILES
)),)
236 define Package
/kmod-
$(1)/install
237 @for mod in
$$(call version_filter
,$$(FILES
)); do \
238 if grep
-q
"$$$$$$$${mod##$(LINUX_DIR)/}" "$(LINUX_DIR)/modules.builtin"; then \
239 echo
"NOTICE: module '$$$$$$$$mod' is built-in."; \
240 elif
[ -e
$$$$$$$$mod ]; then \
241 mkdir
-p
$$(1)/$(MODULES_SUBDIR
) ; \
242 $(CP
) -L
$$$$$$$$mod $$(1)/$(MODULES_SUBDIR
)/ ; \
244 echo
"ERROR: module '$$$$$$$$mod' is missing." >&2; \
248 $(call ModuleAutoLoad
,$(1),$$(1),$(AUTOLOAD
))
249 $(call KernelPackage
/$(1)/install,$$(1))
252 $(if
$(CONFIG_PACKAGE_kmod-
$(1)),
254 compile
: $(1)-disabled
256 @echo
"WARNING: kmod-$(1) is not available in the kernel config - generating empty package" >&2
258 define Package
/kmod-
$(1)/install
263 $$(eval
$$(call BuildPackage
,kmod-
$(1)))
265 $$(IPKG_kmod-
$(1)): $$(wildcard $$(FILES
))
268 version_filter
=$(if
$(findstring @
,$(1)),$(shell $(SCRIPT_DIR
)/package-metadata.pl version_filter
$(KERNEL_PATCHVER
) $(1)),$(1))
271 add_module
"$(1)" "$(call version_filter,$(2))" "$(3)";
275 probe_module
"$(call version_filter,$(1))" "$(2)";
278 version_field
=$(if
$(word $(1),$(2)),$(word $(1),$(2)),0)
279 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)) ))
284 kernel_version_cmp
=$(shell [ $(call kernel_version_merge
,$(call split_version
,$(2))) $(1) $(call kernel_version_merge
,$(call split_version
,$(3))) ] && echo
1 )
287 CompareKernelPatchVer
=$(if
$(call kernel_version_cmp
,-$(2),$(1),$(3)),1,0)
289 kernel_patchver_gt
=$(call kernel_version_cmp
,-gt
,$(KERNEL_PATCHVER
),$(1))
290 kernel_patchver_ge
=$(call kernel_version_cmp
,-ge
,$(KERNEL_PATCHVER
),$(1))
291 kernel_patchver_eq
=$(call kernel_version_cmp
,-eq
,$(KERNEL_PATCHVER
),$(1))
292 kernel_patchver_le
=$(call kernel_version_cmp
,-le
,$(KERNEL_PATCHVER
),$(1))
293 kernel_patchver_lt
=$(call kernel_version_cmp
,-lt
,$(KERNEL_PATCHVER
),$(1))