fd75a3f79ffe542854a691e0a52629d3da7f3f88
[openwrt/openwrt.git] / include / kernel-defaults.mk
1 #
2 # Copyright (C) 2006-2011 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 KERNEL_MAKEOPTS := -C $(LINUX_DIR) \
9 HOSTCFLAGS="$(HOST_CFLAGS) -Wall -Wmissing-prototypes -Wstrict-prototypes" \
10 CROSS_COMPILE="$(KERNEL_CROSS)" \
11 ARCH="$(LINUX_KARCH)" \
12 KBUILD_HAVE_NLS=no \
13 CONFIG_SHELL="$(BASH)" \
14 $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='')
15
16 ifdef CONFIG_STRIP_KERNEL_EXPORTS
17 KERNEL_MAKEOPTS += \
18 EXTRA_LDSFLAGS="-I$(KERNEL_BUILD_DIR) -include symtab.h"
19 endif
20
21 INITRAMFS_EXTRA_FILES ?= $(GENERIC_PLATFORM_DIR)/image/initramfs-base-files.txt
22
23 ifneq (,$(KERNEL_CC))
24 KERNEL_MAKEOPTS += CC="$(KERNEL_CC)"
25 endif
26
27 ifdef CONFIG_USE_SPARSE
28 KERNEL_MAKEOPTS += C=1 CHECK=$(STAGING_DIR_HOST)/bin/sparse
29 endif
30
31 export HOST_EXTRACFLAGS=-I$(STAGING_DIR_HOST)/include
32
33 # defined in quilt.mk
34 Kernel/Patch:=$(Kernel/Patch/Default)
35
36 KERNEL_GIT_OPTS:=
37 ifneq ($(strip $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)),"")
38 KERNEL_GIT_OPTS+=--reference $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)
39 endif
40
41 ifeq ($(strip $(CONFIG_EXTERNAL_KERNEL_TREE)),"")
42 ifeq ($(strip $(CONFIG_KERNEL_GIT_CLONE_URI)),"")
43 define Kernel/Prepare/Default
44 xzcat $(DL_DIR)/$(LINUX_SOURCE) | $(TAR) -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
45 $(Kernel/Patch)
46 touch $(LINUX_DIR)/.quilt_used
47 endef
48 else
49 define Kernel/Prepare/Default
50 git clone $(KERNEL_GIT_OPTS) $(CONFIG_KERNEL_GIT_CLONE_URI) $(LINUX_DIR)
51 endef
52 endif
53 else
54 define Kernel/Prepare/Default
55 mkdir -p $(KERNEL_BUILD_DIR)
56 if [ -d $(LINUX_DIR) ]; then \
57 rmdir $(LINUX_DIR); \
58 fi
59 ln -s $(CONFIG_EXTERNAL_KERNEL_TREE) $(LINUX_DIR)
60 endef
61 endif
62
63 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
64 ifeq ($(strip $(CONFIG_EXTERNAL_CPIO)),"")
65 define Kernel/SetInitramfs/PreConfigure
66 grep -v -e INITRAMFS -e CONFIG_RD_ -e CONFIG_BLK_DEV_INITRD $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
67 echo 'CONFIG_BLK_DEV_INITRD=y' >> $(LINUX_DIR)/.config
68 echo 'CONFIG_INITRAMFS_SOURCE="$(strip $(TARGET_DIR) $(INITRAMFS_EXTRA_FILES))"' >> $(LINUX_DIR)/.config
69 endef
70 else
71 define Kernel/SetInitramfs/PreConfigure
72 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
73 echo 'CONFIG_INITRAMFS_SOURCE="$(call qstrip,$(CONFIG_EXTERNAL_CPIO))"' >> $(LINUX_DIR)/.config
74 endef
75 endif
76
77 define Kernel/SetInitramfs
78 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
79 $(call Kernel/SetInitramfs/PreConfigure)
80 echo 'CONFIG_INITRAMFS_ROOT_UID=$(shell id -u)' >> $(LINUX_DIR)/.config
81 echo 'CONFIG_INITRAMFS_ROOT_GID=$(shell id -g)' >> $(LINUX_DIR)/.config
82 echo "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE),CONFIG_INITRAMFS_COMPRESSION_NONE=y,# CONFIG_INITRAMFS_COMPRESSION_NONE is not set)" >> $(LINUX_DIR)/.config
83 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
84 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
85 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
86 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
87 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
88 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 endef
90 else
91 endif
92
93 define Kernel/SetNoInitramfs
94 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
95 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
96 echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
97 endef
98
99 define Kernel/Configure/Default
100 $(LINUX_CONF_CMD) > $(LINUX_DIR)/.config.target
101 # copy CONFIG_KERNEL_* settings over to .config.target
102 awk '/^(#[[:space:]]+)?CONFIG_KERNEL/{sub("CONFIG_KERNEL_","CONFIG_");print}' $(TOPDIR)/.config >> $(LINUX_DIR)/.config.target
103 echo "# CONFIG_KALLSYMS_EXTRA_PASS is not set" >> $(LINUX_DIR)/.config.target
104 echo "# CONFIG_KALLSYMS_ALL is not set" >> $(LINUX_DIR)/.config.target
105 echo "# CONFIG_KALLSYMS_UNCOMPRESSED is not set" >> $(LINUX_DIR)/.config.target
106 echo "# CONFIG_KPROBES is not set" >> $(LINUX_DIR)/.config.target
107 $(SCRIPT_DIR)/metadata.pl kconfig $(TMP_DIR)/.packageinfo $(TOPDIR)/.config > $(LINUX_DIR)/.config.override
108 $(SCRIPT_DIR)/kconfig.pl 'm+' '+' $(LINUX_DIR)/.config.target /dev/null $(LINUX_DIR)/.config.override > $(LINUX_DIR)/.config
109 $(call Kernel/SetNoInitramfs)
110 rm -rf $(KERNEL_BUILD_DIR)/modules
111 $(_SINGLE) [ -d $(LINUX_DIR)/user_headers ] || $(MAKE) $(KERNEL_MAKEOPTS) INSTALL_HDR_PATH=$(LINUX_DIR)/user_headers headers_install
112 $(SH_FUNC) grep '=[ym]' $(LINUX_DIR)/.config | LC_ALL=C sort | md5s > $(LINUX_DIR)/.vermagic
113 endef
114
115 define Kernel/Configure/Initramfs
116 $(call Kernel/SetInitramfs)
117 endef
118
119 define Kernel/CompileModules/Default
120 rm -f $(LINUX_DIR)/vmlinux $(LINUX_DIR)/System.map
121 +$(MAKE) $(KERNEL_MAKEOPTS) modules
122 endef
123
124 OBJCOPY_STRIP = -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id
125
126 # AVR32 uses a non-standard location
127 ifeq ($(LINUX_KARCH),avr32)
128 IMAGES_DIR:=images
129 endif
130
131 # AMD64 shares the location with x86
132 ifeq ($(LINUX_KARCH),x86_64)
133 IMAGES_DIR:=../../x86/boot
134 endif
135
136 define Kernel/CopyImage
137 $(KERNEL_CROSS)objcopy -O binary $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)$(1)
138 $(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).elf
139 ifneq ($(subst ",,$(KERNELNAME)),)
140 #")
141 $(foreach k,$(filter-out dtbs,$(subst ",,$(KERNELNAME))),$(CP) $(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/$(IMAGES_DIR)/$(k) $(KERNEL_BUILD_DIR)/$(k)$(1);)
142 #")
143 endif
144 endef
145
146 define Kernel/CompileImage/Default
147 rm -f $(TARGET_DIR)/init
148 +$(MAKE) $(KERNEL_MAKEOPTS) $(subst ",,$(KERNELNAME))
149 #")
150 $(call Kernel/CopyImage)
151 endef
152
153 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
154 define Kernel/CompileImage/Initramfs
155 $(call Kernel/Configure/Initramfs)
156 $(CP) $(GENERIC_PLATFORM_DIR)/base-files/init $(TARGET_DIR)/init
157 rm -rf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/usr/initramfs_data.cpio*
158 +$(MAKE) $(KERNEL_MAKEOPTS) $(subst ",,$(KERNELNAME))
159 #")
160 #")
161 $(call Kernel/CopyImage,-initramfs)
162 endef
163 else
164 define Kernel/CompileImage/Initramfs
165 endef
166 endif
167
168 define Kernel/Clean/Default
169 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.configured
170 rm -f $(LINUX_KERNEL)
171 $(_SINGLE)$(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
172 endef
173
174