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