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