manual: download: remove trailing slash from package FOO_SITE
[buildroot-gz.git] / linux / linux.mk
blob672ce485c7a806e9a2004f7aa214832d590392e8
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 # Compute LINUX_SOURCE and LINUX_SITE from the configuration
12 ifeq ($(BR2_LINUX_KERNEL_CUSTOM_TARBALL),y)
13 LINUX_TARBALL = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION))
14 LINUX_SITE = $(patsubst %/,%,$(dir $(LINUX_TARBALL)))
15 LINUX_SOURCE = $(notdir $(LINUX_TARBALL))
16 else ifeq ($(BR2_LINUX_KERNEL_CUSTOM_LOCAL),y)
17 LINUX_SITE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_LOCAL_PATH))
18 LINUX_SITE_METHOD = local
19 else ifeq ($(BR2_LINUX_KERNEL_CUSTOM_GIT),y)
20 LINUX_SITE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_URL))
21 LINUX_SITE_METHOD = git
22 else ifeq ($(BR2_LINUX_KERNEL_CUSTOM_HG),y)
23 LINUX_SITE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_URL))
24 LINUX_SITE_METHOD = hg
25 else
26 LINUX_SOURCE = linux-$(LINUX_VERSION).tar.xz
27 # In X.Y.Z, get X and Y. We replace dots and dashes by spaces in order
28 # to use the $(word) function. We support versions such as 4.0, 3.1,
29 # 2.6.32, 2.6.32-rc1, 3.0-rc6, etc.
30 ifeq ($(findstring x2.6.,x$(LINUX_VERSION)),x2.6.)
31 LINUX_SITE = $(BR2_KERNEL_MIRROR)/linux/kernel/v2.6
32 else ifeq ($(findstring x3.,x$(LINUX_VERSION)),x3.)
33 LINUX_SITE = $(BR2_KERNEL_MIRROR)/linux/kernel/v3.x
34 else ifeq ($(findstring x4.,x$(LINUX_VERSION)),x4.)
35 LINUX_SITE = $(BR2_KERNEL_MIRROR)/linux/kernel/v4.x
36 endif
37 # release candidates are in testing/ subdir
38 ifneq ($(findstring -rc,$(LINUX_VERSION)),)
39 LINUX_SITE := $(LINUX_SITE)/testing/
40 endif # -rc
41 endif
43 LINUX_PATCHES = $(call qstrip,$(BR2_LINUX_KERNEL_PATCH))
45 LINUX_INSTALL_IMAGES = YES
46 LINUX_DEPENDENCIES += host-kmod host-lzop
48 ifeq ($(BR2_LINUX_KERNEL_UBOOT_IMAGE),y)
49 LINUX_DEPENDENCIES += host-uboot-tools
50 endif
52 LINUX_MAKE_FLAGS = \
53 HOSTCC="$(HOSTCC)" \
54 HOSTCFLAGS="$(HOSTCFLAGS)" \
55 ARCH=$(KERNEL_ARCH) \
56 INSTALL_MOD_PATH=$(TARGET_DIR) \
57 CROSS_COMPILE="$(CCACHE) $(TARGET_CROSS)" \
58 DEPMOD=$(HOST_DIR)/sbin/depmod
60 LINUX_MAKE_ENV = \
61 $(TARGET_MAKE_ENV) \
62 BR_BINARIES_DIR=$(BINARIES_DIR)
64 # Get the real Linux version, which tells us where kernel modules are
65 # going to be installed in the target filesystem.
66 LINUX_VERSION_PROBED = $(shell $(MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_DIR) --no-print-directory -s kernelrelease)
68 ifeq ($(BR2_LINUX_KERNEL_USE_INTREE_DTS),y)
69 KERNEL_DTS_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTS_NAME))
70 else ifeq ($(BR2_LINUX_KERNEL_USE_CUSTOM_DTS),y)
71 # We keep only the .dts files, so that the user can specify both .dts
72 # and .dtsi files in BR2_LINUX_KERNEL_CUSTOM_DTS_PATH. Both will be
73 # copied to arch/<arch>/boot/dts, but only the .dts files will
74 # actually be generated as .dtb.
75 KERNEL_DTS_NAME = $(basename $(filter %.dts,$(notdir $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)))))
76 endif
78 ifeq ($(BR2_LINUX_KERNEL_DTS_SUPPORT)$(KERNEL_DTS_NAME),y)
79 $(error No kernel device tree source specified, check your \
80 BR2_LINUX_KERNEL_USE_INTREE_DTS / BR2_LINUX_KERNEL_USE_CUSTOM_DTS settings)
81 endif
83 ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),y)
84 ifneq ($(words $(KERNEL_DTS_NAME)),1)
85 $(error Kernel with appended device tree needs exactly one DTS source. \
86 Check BR2_LINUX_KERNEL_INTREE_DTS_NAME or BR2_LINUX_KERNEL_CUSTOM_DTS_PATH.)
87 endif
88 endif
90 KERNEL_DTBS = $(addsuffix .dtb,$(KERNEL_DTS_NAME))
92 ifeq ($(BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM),y)
93 LINUX_IMAGE_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_NAME))
94 LINUX_TARGET_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_TARGET_NAME))
95 ifeq ($(LINUX_IMAGE_NAME),)
96 LINUX_IMAGE_NAME = $(LINUX_TARGET_NAME)
97 endif
98 else
99 ifeq ($(BR2_LINUX_KERNEL_UIMAGE),y)
100 LINUX_IMAGE_NAME = uImage
101 else ifeq ($(BR2_LINUX_KERNEL_APPENDED_UIMAGE),y)
102 LINUX_IMAGE_NAME = uImage
103 else ifeq ($(BR2_LINUX_KERNEL_BZIMAGE),y)
104 LINUX_IMAGE_NAME = bzImage
105 else ifeq ($(BR2_LINUX_KERNEL_ZIMAGE),y)
106 LINUX_IMAGE_NAME = zImage
107 else ifeq ($(BR2_LINUX_KERNEL_APPENDED_ZIMAGE),y)
108 LINUX_IMAGE_NAME = zImage
109 else ifeq ($(BR2_LINUX_KERNEL_CUIMAGE),y)
110 LINUX_IMAGE_NAME = cuImage.$(KERNEL_DTS_NAME)
111 else ifeq ($(BR2_LINUX_KERNEL_SIMPLEIMAGE),y)
112 LINUX_IMAGE_NAME = simpleImage.$(KERNEL_DTS_NAME)
113 else ifeq ($(BR2_LINUX_KERNEL_LINUX_BIN),y)
114 LINUX_IMAGE_NAME = linux.bin
115 else ifeq ($(BR2_LINUX_KERNEL_VMLINUX_BIN),y)
116 LINUX_IMAGE_NAME = vmlinux.bin
117 else ifeq ($(BR2_LINUX_KERNEL_VMLINUX),y)
118 LINUX_IMAGE_NAME = vmlinux
119 else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ),y)
120 LINUX_IMAGE_NAME = vmlinuz
121 endif
122 # The if-else blocks above are all the image types we know of, and all
123 # come from a Kconfig choice, so we know we have LINUX_IMAGE_NAME set
124 # to something
125 LINUX_TARGET_NAME = $(LINUX_IMAGE_NAME)
126 endif
128 LINUX_KERNEL_UIMAGE_LOADADDR = $(call qstrip,$(BR2_LINUX_KERNEL_UIMAGE_LOADADDR))
129 ifneq ($(LINUX_KERNEL_UIMAGE_LOADADDR),)
130 LINUX_MAKE_FLAGS += LOADADDR="$(LINUX_KERNEL_UIMAGE_LOADADDR)"
131 endif
133 # Compute the arch path, since i386 and x86_64 are in arch/x86 and not
134 # in arch/$(KERNEL_ARCH). Even if the kernel creates symbolic links
135 # for bzImage, arch/i386 and arch/x86_64 do not exist when copying the
136 # defconfig file.
137 ifeq ($(KERNEL_ARCH),i386)
138 KERNEL_ARCH_PATH = $(LINUX_DIR)/arch/x86
139 else ifeq ($(KERNEL_ARCH),x86_64)
140 KERNEL_ARCH_PATH = $(LINUX_DIR)/arch/x86
141 else
142 KERNEL_ARCH_PATH = $(LINUX_DIR)/arch/$(KERNEL_ARCH)
143 endif
145 ifeq ($(BR2_LINUX_KERNEL_VMLINUX),y)
146 LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)
147 else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ),y)
148 LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)
149 else
150 LINUX_IMAGE_PATH = $(KERNEL_ARCH_PATH)/boot/$(LINUX_IMAGE_NAME)
151 endif # BR2_LINUX_KERNEL_VMLINUX
153 define LINUX_DOWNLOAD_PATCHES
154 $(if $(LINUX_PATCHES),
155 @$(call MESSAGE,"Download additional patches"))
156 $(foreach patch,$(filter ftp://% http://% https://%,$(LINUX_PATCHES)),\
157 $(call DOWNLOAD_WGET,$(patch),$(notdir $(patch)))$(sep))
158 endef
160 LINUX_POST_DOWNLOAD_HOOKS += LINUX_DOWNLOAD_PATCHES
162 define LINUX_APPLY_PATCHES
163 for p in $(LINUX_PATCHES) ; do \
164 if echo $$p | grep -q -E "^ftp://|^http://|^https://" ; then \
165 $(APPLY_PATCHES) $(@D) $(DL_DIR) `basename $$p` ; \
166 elif test -d $$p ; then \
167 $(APPLY_PATCHES) $(@D) $$p linux-\*.patch ; \
168 else \
169 $(APPLY_PATCHES) $(@D) `dirname $$p` `basename $$p` ; \
170 fi \
171 done
172 endef
174 LINUX_POST_PATCH_HOOKS += LINUX_APPLY_PATCHES
177 ifeq ($(BR2_LINUX_KERNEL_USE_DEFCONFIG),y)
178 KERNEL_SOURCE_CONFIG = $(KERNEL_ARCH_PATH)/configs/$(call qstrip,$(BR2_LINUX_KERNEL_DEFCONFIG))_defconfig
179 else ifeq ($(BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG),y)
180 KERNEL_SOURCE_CONFIG = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE))
181 endif
183 LINUX_KCONFIG_FILE = $(KERNEL_SOURCE_CONFIG)
184 LINUX_KCONFIG_EDITORS = menuconfig xconfig gconfig nconfig
185 LINUX_KCONFIG_OPTS = $(LINUX_MAKE_FLAGS)
187 define LINUX_KCONFIG_FIXUP_CMDS
188 $(if $(BR2_arm)$(BR2_armeb),
189 $(call KCONFIG_ENABLE_OPT,CONFIG_AEABI,$(@D)/.config))
190 $(if $(BR2_TARGET_ROOTFS_CPIO),
191 $(call KCONFIG_ENABLE_OPT,CONFIG_BLK_DEV_INITRD,$(@D)/.config))
192 # As the kernel gets compiled before root filesystems are
193 # built, we create a fake cpio file. It'll be
194 # replaced later by the real cpio archive, and the kernel will be
195 # rebuilt using the linux-rebuild-with-initramfs target.
196 $(if $(BR2_TARGET_ROOTFS_INITRAMFS),
197 touch $(BINARIES_DIR)/rootfs.cpio
198 $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_SOURCE,"$${BR_BINARIES_DIR}/rootfs.cpio",$(@D)/.config)
199 $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_UID,0,$(@D)/.config)
200 $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_GID,0,$(@D)/.config))
201 $(if $(BR2_ROOTFS_DEVICE_CREATION_STATIC),,
202 $(call KCONFIG_ENABLE_OPT,CONFIG_DEVTMPFS,$(@D)/.config)
203 $(call KCONFIG_ENABLE_OPT,CONFIG_DEVTMPFS_MOUNT,$(@D)/.config))
204 $(if $(BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV),
205 $(call KCONFIG_ENABLE_OPT,CONFIG_INOTIFY_USER,$(@D)/.config))
206 $(if $(BR2_PACKAGE_KTAP),
207 $(call KCONFIG_ENABLE_OPT,CONFIG_DEBUG_FS,$(@D)/.config)
208 $(call KCONFIG_ENABLE_OPT,CONFIG_EVENT_TRACING,$(@D)/.config)
209 $(call KCONFIG_ENABLE_OPT,CONFIG_PERF_EVENTS,$(@D)/.config)
210 $(call KCONFIG_ENABLE_OPT,CONFIG_FUNCTION_TRACER,$(@D)/.config))
211 $(if $(BR2_PACKAGE_SYSTEMD),
212 $(call KCONFIG_ENABLE_OPT,CONFIG_CGROUPS,$(@D)/.config)
213 $(call KCONFIG_ENABLE_OPT,CONFIG_INOTIFY_USER,$(@D)/.config)
214 $(call KCONFIG_ENABLE_OPT,CONFIG_FHANDLE,$(@D)/.config)
215 $(call KCONFIG_ENABLE_OPT,CONFIG_AUTOFS4_FS,$(@D)/.config)
216 $(call KCONFIG_ENABLE_OPT,CONFIG_TMPFS_POSIX_ACL,$(@D)/.config)
217 $(call KCONFIG_ENABLE_OPT,CONFIG_TMPFS_POSIX_XATTR,$(@D)/.config))
218 $(if $(BR2_PACKAGE_SMACK),
219 $(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY,$(@D)/.config)
220 $(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY_SMACK,$(@D)/.config)
221 $(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY_NETWORK,$(@D)/.config))
222 $(if $(BR2_PACKAGE_IPTABLES),
223 $(call KCONFIG_ENABLE_OPT,CONFIG_IP_NF_IPTABLES,$(@D)/.config)
224 $(call KCONFIG_ENABLE_OPT,CONFIG_IP_NF_FILTER,$(@D)/.config)
225 $(call KCONFIG_ENABLE_OPT,CONFIG_NETFILTER,$(@D)/.config)
226 $(call KCONFIG_ENABLE_OPT,CONFIG_NETFILTER_XTABLES,$(@D)/.config))
227 $(if $(BR2_PACKAGE_XTABLES_ADDONS),
228 $(call KCONFIG_ENABLE_OPT,CONFIG_NF_CONNTRACK,$(@D)/.config)
229 $(call KCONFIG_ENABLE_OPT,CONFIG_NF_CONNTRACK_MARK,$(@D)/.config))
230 $(if $(BR2_LINUX_KERNEL_APPENDED_DTB),
231 $(call KCONFIG_ENABLE_OPT,CONFIG_ARM_APPENDED_DTB,$(@D)/.config))
232 endef
234 ifeq ($(BR2_LINUX_KERNEL_DTS_SUPPORT),y)
235 ifeq ($(BR2_LINUX_KERNEL_DTB_IS_SELF_BUILT),)
236 define LINUX_BUILD_DTB
237 $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(KERNEL_DTBS)
238 endef
239 define LINUX_INSTALL_DTB
240 # dtbs moved from arch/<ARCH>/boot to arch/<ARCH>/boot/dts since 3.8-rc1
241 cp $(addprefix \
242 $(KERNEL_ARCH_PATH)/boot/$(if $(wildcard \
243 $(addprefix $(KERNEL_ARCH_PATH)/boot/dts/,$(KERNEL_DTBS))),dts/),$(KERNEL_DTBS)) \
244 $(BINARIES_DIR)/
245 endef
246 define LINUX_INSTALL_DTB_TARGET
247 # dtbs moved from arch/<ARCH>/boot to arch/<ARCH>/boot/dts since 3.8-rc1
248 cp $(addprefix \
249 $(KERNEL_ARCH_PATH)/boot/$(if $(wildcard \
250 $(addprefix $(KERNEL_ARCH_PATH)/boot/dts/,$(KERNEL_DTBS))),dts/),$(KERNEL_DTBS)) \
251 $(TARGET_DIR)/boot/
252 endef
253 endif
254 endif
256 ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),y)
257 # dtbs moved from arch/$ARCH/boot to arch/$ARCH/boot/dts since 3.8-rc1
258 define LINUX_APPEND_DTB
259 if [ -e $(KERNEL_ARCH_PATH)/boot/$(KERNEL_DTS_NAME).dtb ]; then \
260 cat $(KERNEL_ARCH_PATH)/boot/$(KERNEL_DTS_NAME).dtb; \
261 else \
262 cat $(KERNEL_ARCH_PATH)/boot/dts/$(KERNEL_DTS_NAME).dtb; \
263 fi >> $(KERNEL_ARCH_PATH)/boot/zImage
264 endef
265 ifeq ($(BR2_LINUX_KERNEL_APPENDED_UIMAGE),y)
266 # We need to generate a new u-boot image that takes into
267 # account the extra-size added by the device tree at the end
268 # of the image. To do so, we first need to retrieve both load
269 # address and entry point for the kernel from the already
270 # generate uboot image before using mkimage -l.
271 LINUX_APPEND_DTB += $(sep) MKIMAGE_ARGS=`$(MKIMAGE) -l $(LINUX_IMAGE_PATH) |\
272 sed -n -e 's/Image Name:[ ]*\(.*\)/-n \1/p' -e 's/Load Address:/-a/p' -e 's/Entry Point:/-e/p'`; \
273 $(MKIMAGE) -A $(MKIMAGE_ARCH) -O linux \
274 -T kernel -C none $${MKIMAGE_ARGS} \
275 -d $(KERNEL_ARCH_PATH)/boot/zImage $(LINUX_IMAGE_PATH);
276 endif
277 endif
279 # Compilation. We make sure the kernel gets rebuilt when the
280 # configuration has changed.
281 define LINUX_BUILD_CMDS
282 $(if $(BR2_LINUX_KERNEL_USE_CUSTOM_DTS),
283 cp $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)) $(KERNEL_ARCH_PATH)/boot/dts/)
284 $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(LINUX_TARGET_NAME)
285 @if grep -q "CONFIG_MODULES=y" $(@D)/.config; then \
286 $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) modules ; \
288 $(LINUX_BUILD_DTB)
289 $(LINUX_APPEND_DTB)
290 endef
293 ifeq ($(BR2_LINUX_KERNEL_INSTALL_TARGET),y)
294 define LINUX_INSTALL_KERNEL_IMAGE_TO_TARGET
295 install -m 0644 -D $(LINUX_IMAGE_PATH) $(TARGET_DIR)/boot/$(LINUX_IMAGE_NAME)
296 $(LINUX_INSTALL_DTB_TARGET)
297 endef
298 endif
301 define LINUX_INSTALL_HOST_TOOLS
302 # Installing dtc (device tree compiler) as host tool, if selected
303 if grep -q "CONFIG_DTC=y" $(@D)/.config; then \
304 $(INSTALL) -D -m 0755 $(@D)/scripts/dtc/dtc $(HOST_DIR)/usr/bin/dtc ; \
306 endef
309 define LINUX_INSTALL_IMAGES_CMDS
310 cp $(LINUX_IMAGE_PATH) $(BINARIES_DIR)
311 $(LINUX_INSTALL_DTB)
312 endef
314 define LINUX_INSTALL_TARGET_CMDS
315 $(LINUX_INSTALL_KERNEL_IMAGE_TO_TARGET)
316 # Install modules and remove symbolic links pointing to build
317 # directories, not relevant on the target
318 @if grep -q "CONFIG_MODULES=y" $(@D)/.config; then \
319 $(LINUX_MAKE_ENV) $(MAKE1) $(LINUX_MAKE_FLAGS) -C $(@D) modules_install; \
320 rm -f $(TARGET_DIR)/lib/modules/$(LINUX_VERSION_PROBED)/build ; \
321 rm -f $(TARGET_DIR)/lib/modules/$(LINUX_VERSION_PROBED)/source ; \
323 $(LINUX_INSTALL_HOST_TOOLS)
324 endef
326 include $(sort $(wildcard linux/linux-ext-*.mk))
328 $(eval $(kconfig-package))
330 # Support for rebuilding the kernel after the cpio archive has
331 # been generated in $(BINARIES_DIR)/rootfs.cpio.
332 $(LINUX_DIR)/.stamp_initramfs_rebuilt: $(LINUX_DIR)/.stamp_target_installed $(LINUX_DIR)/.stamp_images_installed $(BINARIES_DIR)/rootfs.cpio
333 @$(call MESSAGE,"Rebuilding kernel with initramfs")
334 # Build the kernel.
335 $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(LINUX_TARGET_NAME)
336 $(LINUX_APPEND_DTB)
337 # Copy the kernel image to its final destination
338 cp $(LINUX_IMAGE_PATH) $(BINARIES_DIR)
339 # If there is a .ub file copy it to the final destination
340 test ! -f $(LINUX_IMAGE_PATH).ub || cp $(LINUX_IMAGE_PATH).ub $(BINARIES_DIR)
341 $(Q)touch $@
343 # The initramfs building code must make sure this target gets called
344 # after it generated the initramfs list of files.
345 linux-rebuild-with-initramfs: $(LINUX_DIR)/.stamp_initramfs_rebuilt
347 # Checks to give errors that the user can understand
348 ifeq ($(filter source,$(MAKECMDGOALS)),)
349 ifeq ($(BR2_LINUX_KERNEL_USE_DEFCONFIG),y)
350 ifeq ($(call qstrip,$(BR2_LINUX_KERNEL_DEFCONFIG)),)
351 $(error No kernel defconfig name specified, check your BR2_LINUX_KERNEL_DEFCONFIG setting)
352 endif
353 endif
355 ifeq ($(BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG),y)
356 ifeq ($(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE)),)
357 $(error No kernel configuration file specified, check your BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE setting)
358 endif
359 endif
361 endif