2 # Copyright (C) 2006-2011 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
8 KERNEL_MAKEOPTS := -C $(LINUX_DIR) \
9 HOSTCFLAGS="$(HOST_CFLAGS) -Wall -Wmissing-prototypes -Wstrict-prototypes" \
10 CROSS_COMPILE="$(KERNEL_CROSS)" \
11 ARCH="$(LINUX_KARCH)" \
13 CONFIG_SHELL="$(BASH)" \
14 $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='')
16 ifdef CONFIG_STRIP_KERNEL_EXPORTS
18 EXTRA_LDSFLAGS="-I$(KERNEL_BUILD_DIR) -include symtab.h"
21 INITRAMFS_EXTRA_FILES ?= $(GENERIC_PLATFORM_DIR)/image/initramfs-base-files.txt
24 KERNEL_MAKEOPTS += CC="$(KERNEL_CC)"
27 export HOST_EXTRACFLAGS=-I$(STAGING_DIR_HOST)/include
30 Kernel/Patch:=$(Kernel/Patch/Default)
31 ifeq ($(strip $(CONFIG_EXTERNAL_KERNEL_TREE)),"")
32 ifeq ($(strip $(CONFIG_KERNEL_GIT_CLONE_URI)),"")
33 define Kernel/Prepare/Default
34 xzcat $(DL_DIR)/$(LINUX_SOURCE) | $(TAR) -C $(KERNEL_BUILD_DIR) -xf -
36 touch $(LINUX_DIR)/.quilt_used
39 ifeq ($(strip $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)),"")
40 define Kernel/Prepare/Default
41 git clone $(CONFIG_KERNEL_GIT_CLONE_URI) $(LINUX_DIR)
44 define Kernel/Prepare/Default
45 git clone --reference $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY) $(CONFIG_KERNEL_GIT_CLONE_URI) $(LINUX_DIR)
50 define Kernel/Prepare/Default
51 mkdir -p $(KERNEL_BUILD_DIR)
52 if [ -d $(LINUX_DIR) ]; then \
55 ln -s $(CONFIG_EXTERNAL_KERNEL_TREE) $(LINUX_DIR)
59 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
60 ifeq ($(strip $(CONFIG_EXTERNAL_CPIO)),"")
61 define Kernel/SetInitramfs/PreConfigure
62 grep -v -e INITRAMFS -e CONFIG_RD_ -e CONFIG_BLK_DEV_INITRD $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
63 echo 'CONFIG_BLK_DEV_INITRD=y' >> $(LINUX_DIR)/.config
64 echo 'CONFIG_INITRAMFS_SOURCE="$(strip $(TARGET_DIR) $(INITRAMFS_EXTRA_FILES))"' >> $(LINUX_DIR)/.config
67 define Kernel/SetInitramfs/PreConfigure
68 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
69 echo 'CONFIG_INITRAMFS_SOURCE="$(call qstrip,$(CONFIG_EXTERNAL_CPIO))"' >> $(LINUX_DIR)/.config
73 define Kernel/SetInitramfs
74 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
75 $(call Kernel/SetInitramfs/PreConfigure)
76 echo 'CONFIG_INITRAMFS_ROOT_UID=$(shell id -u)' >> $(LINUX_DIR)/.config
77 echo 'CONFIG_INITRAMFS_ROOT_GID=$(shell id -g)' >> $(LINUX_DIR)/.config
78 echo "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE),CONFIG_INITRAMFS_COMPRESSION_NONE=y,# CONFIG_INITRAMFS_COMPRESSION_NONE is not set)" >> $(LINUX_DIR)/.config
79 echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP),CONFIG_INITRAMFS_COMPRESSION_GZIP=y\nCONFIG_RD_GZIP=y,# CONFIG_INITRAMFS_COMPRESSION_GZIP is not set\n# CONFIG_RD_GZIP is not set)" >> $(LINUX_DIR)/.config
80 echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2),CONFIG_INITRAMFS_COMPRESSION_BZIP2=y\nCONFIG_RD_BZIP2=y,# CONFIG_INITRAMFS_COMPRESSION_BZIP2 is not set\n# CONFIG_RD_BZIP2 is not set)" >> $(LINUX_DIR)/.config
81 echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA),CONFIG_INITRAMFS_COMPRESSION_LZMA=y\nCONFIG_RD_LZMA=y,# CONFIG_INITRAMFS_COMPRESSION_LZMA is not set\n# CONFIG_RD_LZMA is not set)" >> $(LINUX_DIR)/.config
82 echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO),CONFIG_INITRAMFS_COMPRESSION_LZO=y\nCONFIG_RD_LZO=y,# CONFIG_INITRAMFS_COMPRESSION_LZO is not set\n# CONFIG_RD_LZO is not set)" >> $(LINUX_DIR)/.config
83 echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ),CONFIG_INITRAMFS_COMPRESSION_XZ=y\nCONFIG_RD_XZ=y,# CONFIG_INITRAMFS_COMPRESSION_XZ is not set\n# CONFIG_RD_XZ is not set)" >> $(LINUX_DIR)/.config
84 echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4),CONFIG_INITRAMFS_COMPRESSION_LZ4=y\nCONFIG_RD_LZ4=y,# CONFIG_INITRAMFS_COMPRESSION_LZ4 is not set\n# CONFIG_RD_LZ4 is not set)" >> $(LINUX_DIR)/.config
89 define Kernel/SetNoInitramfs
90 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
91 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
92 echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
95 define Kernel/Configure/Default
96 $(LINUX_CONF_CMD) > $(LINUX_DIR)/.config.target
97 # copy CONFIG_KERNEL_* settings over to .config.target
98 awk '/^(#[[:space:]]+)?CONFIG_KERNEL/{sub("CONFIG_KERNEL_","CONFIG_");print}' $(TOPDIR)/.config >> $(LINUX_DIR)/.config.target
99 echo "# CONFIG_KALLSYMS_EXTRA_PASS is not set" >> $(LINUX_DIR)/.config.target
100 echo "# CONFIG_KALLSYMS_ALL is not set" >> $(LINUX_DIR)/.config.target
101 echo "# CONFIG_KALLSYMS_UNCOMPRESSED is not set" >> $(LINUX_DIR)/.config.target
102 echo "# CONFIG_KPROBES is not set" >> $(LINUX_DIR)/.config.target
103 $(SCRIPT_DIR)/metadata.pl kconfig $(TMP_DIR)/.packageinfo $(TOPDIR)/.config > $(LINUX_DIR)/.config.override
104 $(SCRIPT_DIR)/kconfig.pl 'm+' '+' $(LINUX_DIR)/.config.target /dev/null $(LINUX_DIR)/.config.override > $(LINUX_DIR)/.config
105 $(call Kernel/SetNoInitramfs)
106 rm -rf $(KERNEL_BUILD_DIR)/modules
107 $(_SINGLE) [ -d $(LINUX_DIR)/user_headers ] || $(MAKE) $(KERNEL_MAKEOPTS) INSTALL_HDR_PATH=$(LINUX_DIR)/user_headers headers_install
108 $(SH_FUNC) grep '=[ym]' $(LINUX_DIR)/.config | LC_ALL=C sort | md5s > $(LINUX_DIR)/.vermagic
111 define Kernel/Configure/Initramfs
112 $(call Kernel/SetInitramfs)
115 define Kernel/CompileModules/Default
116 rm -f $(LINUX_DIR)/vmlinux $(LINUX_DIR)/System.map
117 +$(MAKE) $(KERNEL_MAKEOPTS) modules
120 OBJCOPY_STRIP = -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id
122 # AVR32 uses a non-standard location
123 ifeq ($(LINUX_KARCH),avr32)
127 # AMD64 shares the location with x86
128 ifeq ($(LINUX_KARCH),x86_64)
129 IMAGES_DIR:=../../x86/boot
132 define Kernel/CopyImage
133 $(KERNEL_CROSS)objcopy -O binary $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)$(1)
134 $(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).elf
135 ifneq ($(subst ",,$(KERNELNAME)),)
137 $(foreach k,$(filter-out dtbs,$(subst ",,$(KERNELNAME))),$(CP) $(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/$(IMAGES_DIR)/$(k) $(KERNEL_BUILD_DIR)/$(k)$(1);)
142 define Kernel/CompileImage/Default
143 rm -f $(TARGET_DIR)/init
144 +$(MAKE) $(KERNEL_MAKEOPTS) $(subst ",,$(KERNELNAME))
146 $(call Kernel/CopyImage)
149 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
150 define Kernel/CompileImage/Initramfs
151 $(call Kernel/Configure/Initramfs)
152 $(CP) $(GENERIC_PLATFORM_DIR)/base-files/init $(TARGET_DIR)/init
153 rm -rf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/usr/initramfs_data.cpio*
154 +$(MAKE) $(KERNEL_MAKEOPTS) $(subst ",,$(KERNELNAME))
157 $(call Kernel/CopyImage,-initramfs)
160 define Kernel/CompileImage/Initramfs
164 define Kernel/Clean/Default
165 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.configured
166 rm -f $(LINUX_KERNEL)
167 $(_SINGLE)$(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean