python-dataproperty: bump version to 0.17.0
[buildroot-gz.git] / linux / linux.mk
blob7f4432e7b16badbac281f75b333b1e9c8ca9a5ee
1 ################################################################################
3 # Linux kernel target
5 ################################################################################
7 LINUX_VERSION = $(call qstrip,$(BR2_LINUX_KERNEL_VERSION))
8 LINUX_LICENSE = GPLv2
9 LINUX_LICENSE_FILES = COPYING
11 define LINUX_HELP_CMDS
12 @echo ' linux-menuconfig - Run Linux kernel menuconfig'
13 @echo ' linux-savedefconfig - Run Linux kernel savedefconfig'
14 @echo ' linux-update-defconfig - Save the Linux configuration to the path specified'
15 @echo ' by BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE'
16 endef
18 # Compute LINUX_SOURCE and LINUX_SITE from the configuration
19 ifeq ($(BR2_LINUX_KERNEL_CUSTOM_TARBALL),y)
20 LINUX_TARBALL = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION))
21 LINUX_SITE = $(patsubst %/,%,$(dir $(LINUX_TARBALL)))
22 LINUX_SOURCE = $(notdir $(LINUX_TARBALL))
23 BR_NO_CHECK_HASH_FOR += $(LINUX_SOURCE)
24 else ifeq ($(BR2_LINUX_KERNEL_CUSTOM_GIT),y)
25 LINUX_SITE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_URL))
26 LINUX_SITE_METHOD = git
27 else ifeq ($(BR2_LINUX_KERNEL_CUSTOM_HG),y)
28 LINUX_SITE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_URL))
29 LINUX_SITE_METHOD = hg
30 else ifeq ($(BR2_LINUX_KERNEL_CUSTOM_SVN),y)
31 LINUX_SITE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_URL))
32 LINUX_SITE_METHOD = svn
33 else
34 LINUX_SOURCE = linux-$(LINUX_VERSION).tar.xz
35 ifeq ($(BR2_LINUX_KERNEL_CUSTOM_VERSION),y)
36 BR_NO_CHECK_HASH_FOR += $(LINUX_SOURCE)
37 endif
38 # In X.Y.Z, get X and Y. We replace dots and dashes by spaces in order
39 # to use the $(word) function. We support versions such as 4.0, 3.1,
40 # 2.6.32, 2.6.32-rc1, 3.0-rc6, etc.
41 ifeq ($(findstring x2.6.,x$(LINUX_VERSION)),x2.6.)
42 LINUX_SITE = $(BR2_KERNEL_MIRROR)/linux/kernel/v2.6
43 else ifeq ($(findstring x3.,x$(LINUX_VERSION)),x3.)
44 LINUX_SITE = $(BR2_KERNEL_MIRROR)/linux/kernel/v3.x
45 else ifeq ($(findstring x4.,x$(LINUX_VERSION)),x4.)
46 LINUX_SITE = $(BR2_KERNEL_MIRROR)/linux/kernel/v4.x
47 endif
48 # release candidates are in testing/ subdir
49 ifneq ($(findstring -rc,$(LINUX_VERSION)),)
50 LINUX_SITE := $(LINUX_SITE)/testing
51 endif # -rc
52 endif
54 LINUX_PATCHES = $(call qstrip,$(BR2_LINUX_KERNEL_PATCH))
56 # We rely on the generic package infrastructure to download and apply
57 # remote patches (downloaded from ftp, http or https). For local
58 # patches, we can't rely on that infrastructure, because there might
59 # be directories in the patch list (unlike for other packages).
60 LINUX_PATCH = $(filter ftp://% http://% https://%,$(LINUX_PATCHES))
62 LINUX_INSTALL_IMAGES = YES
63 LINUX_DEPENDENCIES += host-kmod
65 # host tools needed for kernel compression
66 ifeq ($(BR2_LINUX_KERNEL_LZ4),y)
67 LINUX_DEPENDENCIES += host-lz4
68 else ifeq ($(BR2_LINUX_KERNEL_LZMA),y)
69 LINUX_DEPENDENCIES += host-lzma
70 else ifeq ($(BR2_LINUX_KERNEL_LZO),y)
71 LINUX_DEPENDENCIES += host-lzop
72 else ifeq ($(BR2_LINUX_KERNEL_XZ),y)
73 LINUX_DEPENDENCIES += host-xz
74 endif
75 LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_GZIP) = CONFIG_KERNEL_GZIP
76 LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_LZ4) = CONFIG_KERNEL_LZ4
77 LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_LZMA) = CONFIG_KERNEL_LZMA
78 LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_LZO) = CONFIG_KERNEL_LZO
79 LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_XZ) = CONFIG_KERNEL_XZ
81 ifeq ($(BR2_LINUX_KERNEL_UBOOT_IMAGE),y)
82 LINUX_DEPENDENCIES += host-uboot-tools
83 endif
85 LINUX_MAKE_FLAGS = \
86 HOSTCC="$(HOSTCC)" \
87 HOSTCFLAGS="$(HOSTCFLAGS)" \
88 ARCH=$(KERNEL_ARCH) \
89 INSTALL_MOD_PATH=$(TARGET_DIR) \
90 CROSS_COMPILE="$(TARGET_CROSS)" \
91 DEPMOD=$(HOST_DIR)/sbin/depmod
93 LINUX_MAKE_ENV = \
94 $(TARGET_MAKE_ENV) \
95 BR_BINARIES_DIR=$(BINARIES_DIR)
97 ifeq ($(BR2_REPRODUCIBLE),y)
98 LINUX_MAKE_ENV += \
99 KBUILD_BUILD_VERSION=1 \
100 KBUILD_BUILD_USER=buildroot \
101 KBUILD_BUILD_HOST=buildroot \
102 KBUILD_BUILD_TIMESTAMP="$(shell LC_ALL=C date -d @$(SOURCE_DATE_EPOCH))"
103 endif
105 # Get the real Linux version, which tells us where kernel modules are
106 # going to be installed in the target filesystem.
107 LINUX_VERSION_PROBED = `$(MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_DIR) --no-print-directory -s kernelrelease 2>/dev/null`
109 ifeq ($(BR2_LINUX_KERNEL_USE_INTREE_DTS),y)
110 KERNEL_DTS_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTS_NAME))
111 else ifeq ($(BR2_LINUX_KERNEL_USE_CUSTOM_DTS),y)
112 # We keep only the .dts files, so that the user can specify both .dts
113 # and .dtsi files in BR2_LINUX_KERNEL_CUSTOM_DTS_PATH. Both will be
114 # copied to arch/<arch>/boot/dts, but only the .dts files will
115 # actually be generated as .dtb.
116 KERNEL_DTS_NAME = $(basename $(filter %.dts,$(notdir $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)))))
117 endif
119 KERNEL_DTBS = $(addsuffix .dtb,$(KERNEL_DTS_NAME))
121 ifeq ($(BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM),y)
122 LINUX_IMAGE_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_NAME))
123 LINUX_TARGET_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_TARGET_NAME))
124 ifeq ($(LINUX_IMAGE_NAME),)
125 LINUX_IMAGE_NAME = $(LINUX_TARGET_NAME)
126 endif
127 else
128 ifeq ($(BR2_LINUX_KERNEL_UIMAGE),y)
129 LINUX_IMAGE_NAME = uImage
130 else ifeq ($(BR2_LINUX_KERNEL_APPENDED_UIMAGE),y)
131 LINUX_IMAGE_NAME = uImage
132 else ifeq ($(BR2_LINUX_KERNEL_BZIMAGE),y)
133 LINUX_IMAGE_NAME = bzImage
134 else ifeq ($(BR2_LINUX_KERNEL_ZIMAGE),y)
135 LINUX_IMAGE_NAME = zImage
136 else ifeq ($(BR2_LINUX_KERNEL_ZIMAGE_EPAPR),y)
137 LINUX_IMAGE_NAME = zImage.epapr
138 else ifeq ($(BR2_LINUX_KERNEL_APPENDED_ZIMAGE),y)
139 LINUX_IMAGE_NAME = zImage
140 else ifeq ($(BR2_LINUX_KERNEL_CUIMAGE),y)
141 LINUX_IMAGE_NAME = cuImage.$(KERNEL_DTS_NAME)
142 else ifeq ($(BR2_LINUX_KERNEL_SIMPLEIMAGE),y)
143 LINUX_IMAGE_NAME = simpleImage.$(KERNEL_DTS_NAME)
144 else ifeq ($(BR2_LINUX_KERNEL_IMAGE),y)
145 LINUX_IMAGE_NAME = Image
146 else ifeq ($(BR2_LINUX_KERNEL_LINUX_BIN),y)
147 LINUX_IMAGE_NAME = linux.bin
148 else ifeq ($(BR2_LINUX_KERNEL_VMLINUX_BIN),y)
149 LINUX_IMAGE_NAME = vmlinux.bin
150 else ifeq ($(BR2_LINUX_KERNEL_VMLINUX),y)
151 LINUX_IMAGE_NAME = vmlinux
152 else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ),y)
153 LINUX_IMAGE_NAME = vmlinuz
154 else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ_BIN),y)
155 LINUX_IMAGE_NAME = vmlinuz.bin
156 endif
157 # The if-else blocks above are all the image types we know of, and all
158 # come from a Kconfig choice, so we know we have LINUX_IMAGE_NAME set
159 # to something
160 LINUX_TARGET_NAME = $(LINUX_IMAGE_NAME)
161 endif
163 LINUX_KERNEL_UIMAGE_LOADADDR = $(call qstrip,$(BR2_LINUX_KERNEL_UIMAGE_LOADADDR))
164 ifneq ($(LINUX_KERNEL_UIMAGE_LOADADDR),)
165 LINUX_MAKE_FLAGS += LOADADDR="$(LINUX_KERNEL_UIMAGE_LOADADDR)"
166 endif
168 # Compute the arch path, since i386 and x86_64 are in arch/x86 and not
169 # in arch/$(KERNEL_ARCH). Even if the kernel creates symbolic links
170 # for bzImage, arch/i386 and arch/x86_64 do not exist when copying the
171 # defconfig file.
172 ifeq ($(KERNEL_ARCH),i386)
173 KERNEL_ARCH_PATH = $(LINUX_DIR)/arch/x86
174 else ifeq ($(KERNEL_ARCH),x86_64)
175 KERNEL_ARCH_PATH = $(LINUX_DIR)/arch/x86
176 else
177 KERNEL_ARCH_PATH = $(LINUX_DIR)/arch/$(KERNEL_ARCH)
178 endif
180 ifeq ($(BR2_LINUX_KERNEL_VMLINUX),y)
181 LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)
182 else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ),y)
183 LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)
184 else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ_BIN),y)
185 LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)
186 else
187 LINUX_IMAGE_PATH = $(KERNEL_ARCH_PATH)/boot/$(LINUX_IMAGE_NAME)
188 endif # BR2_LINUX_KERNEL_VMLINUX
190 define LINUX_APPLY_LOCAL_PATCHES
191 for p in $(filter-out ftp://% http://% https://%,$(LINUX_PATCHES)) ; do \
192 if test -d $$p ; then \
193 $(APPLY_PATCHES) $(@D) $$p \*.patch || exit 1 ; \
194 else \
195 $(APPLY_PATCHES) $(@D) `dirname $$p` `basename $$p` || exit 1; \
196 fi \
197 done
198 endef
200 LINUX_POST_PATCH_HOOKS += LINUX_APPLY_LOCAL_PATCHES
202 # Older linux kernels use deprecated perl constructs in timeconst.pl
203 # that were removed for perl 5.22+ so it breaks on newer distributions
204 # Try a dry-run patch to see if this applies, if it does go ahead
205 define LINUX_TRY_PATCH_TIMECONST
206 @if patch -p1 --dry-run -f -s -d $(@D) <$(LINUX_PKGDIR)/0001-timeconst.pl-Eliminate-Perl-warning.patch.conditional >/dev/null ; then \
207 $(APPLY_PATCHES) $(@D) $(LINUX_PKGDIR) 0001-timeconst.pl-Eliminate-Perl-warning.patch.conditional ; \
209 endef
210 LINUX_POST_PATCH_HOOKS += LINUX_TRY_PATCH_TIMECONST
212 ifeq ($(BR2_LINUX_KERNEL_USE_DEFCONFIG),y)
213 LINUX_KCONFIG_DEFCONFIG = $(call qstrip,$(BR2_LINUX_KERNEL_DEFCONFIG))_defconfig
214 else ifeq ($(BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG),y)
215 LINUX_KCONFIG_DEFCONFIG = defconfig
216 else ifeq ($(BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG),y)
217 LINUX_KCONFIG_FILE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE))
218 endif
219 LINUX_KCONFIG_FRAGMENT_FILES = $(call qstrip,$(BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES))
220 LINUX_KCONFIG_EDITORS = menuconfig xconfig gconfig nconfig
221 LINUX_KCONFIG_OPTS = $(LINUX_MAKE_FLAGS)
223 # If no package has yet set it, set it from the Kconfig option
224 LINUX_NEEDS_MODULES ?= $(BR2_LINUX_NEEDS_MODULES)
226 # Make sure the Linux kernel is built with the right endianness. Not
227 # all architectures support
228 # CONFIG_CPU_BIG_ENDIAN/CONFIG_CPU_LITTLE_ENDIAN in Linux, but the
229 # option will be thrown away and ignored if it doesn't exist.
230 ifeq ($(BR2_ENDIAN),"BIG")
231 define LINUX_FIXUP_CONFIG_ENDIANNESS
232 $(call KCONFIG_ENABLE_OPT,CONFIG_CPU_BIG_ENDIAN,$(@D)/.config)
233 endef
234 else
235 define LINUX_FIXUP_CONFIG_ENDIANNESS
236 $(call KCONFIG_ENABLE_OPT,CONFIG_CPU_LITTLE_ENDIAN,$(@D)/.config)
237 endef
238 endif
240 define LINUX_KCONFIG_FIXUP_CMDS
241 $(if $(LINUX_NEEDS_MODULES),
242 $(call KCONFIG_ENABLE_OPT,CONFIG_MODULES,$(@D)/.config))
243 $(call KCONFIG_ENABLE_OPT,$(LINUX_COMPRESSION_OPT_y),$(@D)/.config)
244 $(foreach opt, $(LINUX_COMPRESSION_OPT_),
245 $(call KCONFIG_DISABLE_OPT,$(opt),$(@D)/.config)
247 $(LINUX_FIXUP_CONFIG_ENDIANNESS)
248 $(if $(BR2_arm)$(BR2_armeb),
249 $(call KCONFIG_ENABLE_OPT,CONFIG_AEABI,$(@D)/.config))
250 $(if $(BR2_TARGET_ROOTFS_CPIO),
251 $(call KCONFIG_ENABLE_OPT,CONFIG_BLK_DEV_INITRD,$(@D)/.config))
252 # As the kernel gets compiled before root filesystems are
253 # built, we create a fake cpio file. It'll be
254 # replaced later by the real cpio archive, and the kernel will be
255 # rebuilt using the linux-rebuild-with-initramfs target.
256 $(if $(BR2_TARGET_ROOTFS_INITRAMFS),
257 touch $(BINARIES_DIR)/rootfs.cpio
258 $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_SOURCE,"$${BR_BINARIES_DIR}/rootfs.cpio",$(@D)/.config)
259 $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_UID,0,$(@D)/.config)
260 $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_GID,0,$(@D)/.config))
261 $(if $(BR2_ROOTFS_DEVICE_CREATION_STATIC),,
262 $(call KCONFIG_ENABLE_OPT,CONFIG_DEVTMPFS,$(@D)/.config)
263 $(call KCONFIG_ENABLE_OPT,CONFIG_DEVTMPFS_MOUNT,$(@D)/.config))
264 $(if $(BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV),
265 $(call KCONFIG_ENABLE_OPT,CONFIG_INOTIFY_USER,$(@D)/.config))
266 $(if $(BR2_PACKAGE_KTAP),
267 $(call KCONFIG_ENABLE_OPT,CONFIG_DEBUG_FS,$(@D)/.config)
268 $(call KCONFIG_ENABLE_OPT,CONFIG_ENABLE_DEFAULT_TRACERS,$(@D)/.config)
269 $(call KCONFIG_ENABLE_OPT,CONFIG_PERF_EVENTS,$(@D)/.config)
270 $(call KCONFIG_ENABLE_OPT,CONFIG_FUNCTION_TRACER,$(@D)/.config))
271 $(if $(BR2_PACKAGE_SYSTEMD),
272 $(call KCONFIG_ENABLE_OPT,CONFIG_CGROUPS,$(@D)/.config)
273 $(call KCONFIG_ENABLE_OPT,CONFIG_INOTIFY_USER,$(@D)/.config)
274 $(call KCONFIG_ENABLE_OPT,CONFIG_FHANDLE,$(@D)/.config)
275 $(call KCONFIG_ENABLE_OPT,CONFIG_AUTOFS4_FS,$(@D)/.config)
276 $(call KCONFIG_ENABLE_OPT,CONFIG_TMPFS_POSIX_ACL,$(@D)/.config)
277 $(call KCONFIG_ENABLE_OPT,CONFIG_TMPFS_POSIX_XATTR,$(@D)/.config))
278 $(if $(BR2_PACKAGE_SMACK),
279 $(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY,$(@D)/.config)
280 $(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY_SMACK,$(@D)/.config)
281 $(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY_NETWORK,$(@D)/.config))
282 $(if $(BR2_PACKAGE_IPTABLES),
283 $(call KCONFIG_ENABLE_OPT,CONFIG_IP_NF_IPTABLES,$(@D)/.config)
284 $(call KCONFIG_ENABLE_OPT,CONFIG_IP_NF_FILTER,$(@D)/.config)
285 $(call KCONFIG_ENABLE_OPT,CONFIG_NETFILTER,$(@D)/.config)
286 $(call KCONFIG_ENABLE_OPT,CONFIG_NETFILTER_XTABLES,$(@D)/.config))
287 $(if $(BR2_PACKAGE_XTABLES_ADDONS),
288 $(call KCONFIG_ENABLE_OPT,CONFIG_NETFILTER_ADVANCED,$(@D)/.config)
289 $(call KCONFIG_ENABLE_OPT,CONFIG_NF_CONNTRACK,$(@D)/.config)
290 $(call KCONFIG_ENABLE_OPT,CONFIG_NF_CONNTRACK_MARK,$(@D)/.config))
291 $(if $(BR2_LINUX_KERNEL_APPENDED_DTB),
292 $(call KCONFIG_ENABLE_OPT,CONFIG_ARM_APPENDED_DTB,$(@D)/.config))
293 $(if $(BR2_PACKAGE_KERNEL_MODULE_IMX_GPU_VIV),
294 $(call KCONFIG_DISABLE_OPT,CONFIG_MXC_GPU_VIV,$(@D)/.config))
295 endef
297 ifeq ($(BR2_LINUX_KERNEL_DTS_SUPPORT),y)
298 ifeq ($(BR2_LINUX_KERNEL_DTB_IS_SELF_BUILT),)
299 define LINUX_BUILD_DTB
300 $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(KERNEL_DTBS)
301 endef
302 ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),)
303 define LINUX_INSTALL_DTB
304 # dtbs moved from arch/<ARCH>/boot to arch/<ARCH>/boot/dts since 3.8-rc1
305 cp $(addprefix \
306 $(KERNEL_ARCH_PATH)/boot/$(if $(wildcard \
307 $(addprefix $(KERNEL_ARCH_PATH)/boot/dts/,$(KERNEL_DTBS))),dts/),$(KERNEL_DTBS)) \
308 $(1)
309 endef
310 endif # BR2_LINUX_KERNEL_APPENDED_DTB
311 endif # BR2_LINUX_KERNEL_DTB_IS_SELF_BUILT
312 endif # BR2_LINUX_KERNEL_DTS_SUPPORT
314 ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),y)
315 # dtbs moved from arch/$ARCH/boot to arch/$ARCH/boot/dts since 3.8-rc1
316 define LINUX_APPEND_DTB
317 (cd $(KERNEL_ARCH_PATH)/boot; \
318 for dtb in $(KERNEL_DTS_NAME); do \
319 if test -e $${dtb}.dtb ; then \
320 dtbpath=$${dtb}.dtb ; \
321 else \
322 dtbpath=dts/$${dtb}.dtb ; \
323 fi ; \
324 cat zImage $${dtbpath} > zImage.$${dtb} || exit 1; \
325 done)
326 endef
327 ifeq ($(BR2_LINUX_KERNEL_APPENDED_UIMAGE),y)
328 # We need to generate a new u-boot image that takes into
329 # account the extra-size added by the device tree at the end
330 # of the image. To do so, we first need to retrieve both load
331 # address and entry point for the kernel from the already
332 # generate uboot image before using mkimage -l.
333 LINUX_APPEND_DTB += ; \
334 MKIMAGE_ARGS=`$(MKIMAGE) -l $(LINUX_IMAGE_PATH) |\
335 sed -n -e 's/Image Name:[ ]*\(.*\)/-n \1/p' -e 's/Load Address:/-a/p' -e 's/Entry Point:/-e/p'`; \
336 for dtb in $(KERNEL_DTS_NAME); do \
337 $(MKIMAGE) -A $(MKIMAGE_ARCH) -O linux \
338 -T kernel -C none $${MKIMAGE_ARGS} \
339 -d $(KERNEL_ARCH_PATH)/boot/zImage.$${dtb} $(LINUX_IMAGE_PATH).$${dtb}; \
340 done
341 endif
342 endif
344 # Compilation. We make sure the kernel gets rebuilt when the
345 # configuration has changed.
346 define LINUX_BUILD_CMDS
347 $(if $(BR2_LINUX_KERNEL_USE_CUSTOM_DTS),
348 cp -f $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)) $(KERNEL_ARCH_PATH)/boot/dts/)
349 $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(LINUX_TARGET_NAME)
350 @if grep -q "CONFIG_MODULES=y" $(@D)/.config; then \
351 $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) modules ; \
353 $(LINUX_BUILD_DTB)
354 $(LINUX_APPEND_DTB)
355 endef
357 ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),y)
358 # When a DTB was appended, install the potential several images with
359 # appended DTBs.
360 define LINUX_INSTALL_IMAGE
361 mkdir -p $(1)
362 cp $(KERNEL_ARCH_PATH)/boot/$(LINUX_IMAGE_NAME).* $(1)
363 endef
364 else
365 # Otherwise, just install the unique image generated by the kernel
366 # build process.
367 define LINUX_INSTALL_IMAGE
368 $(INSTALL) -m 0644 -D $(LINUX_IMAGE_PATH) $(1)/$(LINUX_IMAGE_NAME)
369 endef
370 endif
372 ifeq ($(BR2_LINUX_KERNEL_INSTALL_TARGET),y)
373 define LINUX_INSTALL_KERNEL_IMAGE_TO_TARGET
374 $(call LINUX_INSTALL_IMAGE,$(TARGET_DIR)/boot)
375 $(call LINUX_INSTALL_DTB,$(TARGET_DIR)/boot)
376 endef
377 endif
379 define LINUX_INSTALL_HOST_TOOLS
380 # Installing dtc (device tree compiler) as host tool, if selected
381 if grep -q "CONFIG_DTC=y" $(@D)/.config; then \
382 $(INSTALL) -D -m 0755 $(@D)/scripts/dtc/dtc $(HOST_DIR)/usr/bin/linux-dtc ; \
383 if [ ! -e $(HOST_DIR)/usr/bin/dtc ]; then \
384 ln -sf linux-dtc $(HOST_DIR)/usr/bin/dtc ; \
385 fi \
387 endef
390 define LINUX_INSTALL_IMAGES_CMDS
391 $(call LINUX_INSTALL_IMAGE,$(BINARIES_DIR))
392 $(call LINUX_INSTALL_DTB,$(BINARIES_DIR))
393 endef
395 ifeq ($(BR2_STRIP_strip),y)
396 LINUX_MAKE_FLAGS += INSTALL_MOD_STRIP=1
397 endif
399 define LINUX_INSTALL_TARGET_CMDS
400 $(LINUX_INSTALL_KERNEL_IMAGE_TO_TARGET)
401 # Install modules and remove symbolic links pointing to build
402 # directories, not relevant on the target
403 @if grep -q "CONFIG_MODULES=y" $(@D)/.config; then \
404 $(LINUX_MAKE_ENV) $(MAKE1) $(LINUX_MAKE_FLAGS) -C $(@D) modules_install; \
405 rm -f $(TARGET_DIR)/lib/modules/$(LINUX_VERSION_PROBED)/build ; \
406 rm -f $(TARGET_DIR)/lib/modules/$(LINUX_VERSION_PROBED)/source ; \
408 $(LINUX_INSTALL_HOST_TOOLS)
409 endef
411 # Include all our extensions.
413 # Note: our package infrastructure uses the full-path of the last-scanned
414 # Makefile to determine what package we're currently defining, using the
415 # last directory component in the path. As such, including other Makefile,
416 # like below, before we call one of the *-package macro is usally not
417 # working.
418 # However, since the files we include here are in the same directory as
419 # the current Makefile, we are OK. But this is a hard requirement: files
420 # included here *must* be in the same directory!
421 include $(sort $(wildcard linux/linux-ext-*.mk))
423 LINUX_PATCH_DEPENDENCIES += $(foreach ext,$(LINUX_EXTENSIONS),\
424 $(if $(BR2_LINUX_KERNEL_EXT_$(call UPPERCASE,$(ext))),$(ext)))
426 LINUX_PRE_PATCH_HOOKS += $(foreach ext,$(LINUX_EXTENSIONS),\
427 $(if $(BR2_LINUX_KERNEL_EXT_$(call UPPERCASE,$(ext))),\
428 $(call UPPERCASE,$(ext))_PREPARE_KERNEL))
430 # Checks to give errors that the user can understand
432 # When a custom repository has been set, check for the repository version
433 ifeq ($(BR2_LINUX_KERNEL_CUSTOM_SVN)$(BR2_LINUX_KERNEL_CUSTOM_GIT)$(BR2_LINUX_KERNEL_CUSTOM_HG),y)
434 ifeq ($(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION)),)
435 $(error No custom repository version set. Check your BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION setting)
436 endif
437 ifeq ($(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_URL)),)
438 $(error No custom repo URL set. Check your BR2_LINUX_KERNEL_CUSTOM_REPO_URL setting)
439 endif
440 endif
442 ifeq ($(BR_BUILDING),y)
444 ifeq ($(BR2_LINUX_KERNEL_USE_DEFCONFIG),y)
445 # We must use the user-supplied kconfig value, because
446 # LINUX_KCONFIG_DEFCONFIG will at least contain the
447 # trailing _defconfig
448 ifeq ($(call qstrip,$(BR2_LINUX_KERNEL_DEFCONFIG)),)
449 $(error No kernel defconfig name specified, check your BR2_LINUX_KERNEL_DEFCONFIG setting)
450 endif
451 endif
453 ifeq ($(BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG),y)
454 ifeq ($(LINUX_KCONFIG_FILE),)
455 $(error No kernel configuration file specified, check your BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE setting)
456 endif
457 endif
459 ifeq ($(BR2_LINUX_KERNEL_DTS_SUPPORT)$(KERNEL_DTS_NAME),y)
460 $(error No kernel device tree source specified, check your \
461 BR2_LINUX_KERNEL_USE_INTREE_DTS / BR2_LINUX_KERNEL_USE_CUSTOM_DTS settings)
462 endif
464 endif # BR_BUILDING
466 $(eval $(kconfig-package))
468 # Support for rebuilding the kernel after the cpio archive has
469 # been generated in $(BINARIES_DIR)/rootfs.cpio.
470 $(LINUX_DIR)/.stamp_initramfs_rebuilt: $(LINUX_DIR)/.stamp_target_installed $(LINUX_DIR)/.stamp_images_installed $(BINARIES_DIR)/rootfs.cpio
471 @$(call MESSAGE,"Rebuilding kernel with initramfs")
472 # Build the kernel.
473 $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(LINUX_TARGET_NAME)
474 $(LINUX_APPEND_DTB)
475 # Copy the kernel image(s) to its(their) final destination
476 $(call LINUX_INSTALL_IMAGE,$(BINARIES_DIR))
477 # If there is a .ub file copy it to the final destination
478 test ! -f $(LINUX_IMAGE_PATH).ub || cp $(LINUX_IMAGE_PATH).ub $(BINARIES_DIR)
479 $(Q)touch $@
481 # The initramfs building code must make sure this target gets called
482 # after it generated the initramfs list of files.
483 linux-rebuild-with-initramfs: $(LINUX_DIR)/.stamp_initramfs_rebuilt