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