extend tmp/.target.mk to include target profile information - preparation for the...
[openwrt.git] / include / kernel-build.mk
1 #
2 # Copyright (C) 2006 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7 KERNEL_BUILD:=1
8
9 include $(INCLUDE_DIR)/prereq.mk
10
11 -include ./config
12 ifneq ($(CONFIG_ATM),)
13 FEATURES += atm
14 endif
15 ifneq ($(CONFIG_PCI),)
16 FEATURES += pci
17 endif
18 ifneq ($(CONFIG_USB),)
19 FEATURES += usb
20 endif
21 ifneq ($(CONFIG_PCMCIA),)
22 FEATURES += pcmcia
23 endif
24
25 # remove duplicates
26 FEATURES:=$(sort $(FEATURES))
27
28 # For target profile selection - the default set
29 DEFAULT_PACKAGES:=base-files libgcc uclibc bridge busybox dnsmasq dropbear iptables mtd ppp ppp-mod-pppoe mtd
30
31 ifeq ($(DUMP),1)
32 all: dumpinfo
33 else
34 all: compile
35 endif
36
37 include $(INCLUDE_DIR)/kernel-version.mk
38 include $(INCLUDE_DIR)/host.mk
39 include $(INCLUDE_DIR)/kernel.mk
40
41 LINUX_CONFIG:=./config
42
43 ifneq (,$(findstring uml,$(BOARD)))
44 LINUX_KARCH:=um
45 else
46 LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
47 -e 's/mipsel/mips/' \
48 -e 's/mipseb/mips/' \
49 -e 's/powerpc/ppc/' \
50 -e 's/sh[234]/sh/' \
51 -e 's/armeb/arm/' \
52 )
53 endif
54
55 KERNELNAME=
56 ifneq (,$(findstring x86,$(BOARD)))
57 KERNELNAME="bzImage"
58 endif
59 ifneq (,$(findstring rdc,$(BOARD)))
60 KERNELNAME="bzImage"
61 endif
62 ifneq (,$(findstring ppc,$(BOARD)))
63 KERNELNAME="uImage"
64 endif
65
66
67 define Kernel/Prepare/Default
68 bzcat $(DL_DIR)/$(LINUX_SOURCE) | tar -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
69 [ -d $(GENERIC_PLATFORM_DIR)/patches ] && $(PATCH) $(LINUX_DIR) $(GENERIC_PLATFORM_DIR)/patches
70 [ -d ./patches ] && $(PATCH) $(LINUX_DIR) ./patches
71 endef
72 define Kernel/Prepare
73 $(call Kernel/Prepare/Default)
74 endef
75
76 KERNEL_MAKEOPTS := -C $(LINUX_DIR) \
77 CROSS_COMPILE="$(KERNEL_CROSS)" \
78 ARCH="$(LINUX_KARCH)" \
79 CONFIG_SHELL="$(BASH)"
80
81 define Kernel/Configure/2.4
82 $(SED) "s,\-mcpu=,\-mtune=,g;" $(LINUX_DIR)/arch/mips/Makefile
83 $(MAKE) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" oldconfig include/linux/compile.h include/linux/version.h
84 $(MAKE) $(KERNEL_MAKEOPTS) dep
85 endef
86 define Kernel/Configure/2.6
87 $(MAKE) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" oldconfig prepare scripts
88 endef
89 define Kernel/Configure/Default
90 @$(CP) $(LINUX_CONFIG) $(LINUX_DIR)/.config
91 $(call Kernel/Configure/$(KERNEL))
92 endef
93 define Kernel/Configure
94 $(call Kernel/Configure/Default)
95 endef
96
97
98 define Kernel/CompileModules/Default
99 $(MAKE) -j$(CONFIG_JLEVEL) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" modules
100 $(MAKE) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" DEPMOD=true INSTALL_MOD_PATH=$(KERNEL_BUILD_DIR)/modules modules_install
101 endef
102 define Kernel/CompileModules
103 $(call Kernel/CompileModules/Default)
104 endef
105
106
107 ifeq ($(KERNEL),2.6)
108 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
109 define Kernel/SetInitramfs
110 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
111 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
112 echo 'CONFIG_INITRAMFS_SOURCE="../../root"' >> $(LINUX_DIR)/.config
113 echo 'CONFIG_INITRAMFS_ROOT_UID=0' >> $(LINUX_DIR)/.config
114 echo 'CONFIG_INITRAMFS_ROOT_GID=0' >> $(LINUX_DIR)/.config
115 mkdir -p $(BUILD_DIR)/root/etc/init.d
116 $(CP) $(GENERIC_PLATFORM_DIR)/files/init $(BUILD_DIR)/root/
117 endef
118 else
119 define Kernel/SetInitramfs
120 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
121 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
122 rm -f $(BUILD_DIR)/root/init $(BUILD_DIR)/root/etc/init.d/S00initramfs
123 echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
124 endef
125 endif
126 endif
127 define Kernel/CompileImage/Default
128 $(call Kernel/SetInitramfs)
129 $(MAKE) -j$(CONFIG_JLEVEL) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" $(KERNELNAME)
130 $(KERNEL_CROSS)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)
131 endef
132 define Kernel/CompileImage
133 $(call Kernel/CompileImage/Default)
134 endef
135
136 define Kernel/Clean/Default
137 rm -f $(LINUX_DIR)/.linux-compile
138 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.configured
139 rm -f $(LINUX_KERNEL)
140 $(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
141 endef
142
143 define Kernel/Clean
144 $(call Kernel/Clean/Default)
145 endef
146
147 define BuildKernel
148 ifneq ($(LINUX_SITE),)
149 $(DL_DIR)/$(LINUX_SOURCE):
150 -mkdir -p $(DL_DIR)
151 $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
152 endif
153
154 $(LINUX_DIR)/.prepared: $(DL_DIR)/$(LINUX_SOURCE)
155 -rm -rf $(KERNEL_BUILD_DIR)
156 -mkdir -p $(KERNEL_BUILD_DIR)
157 $(call Kernel/Prepare)
158 touch $$@
159
160 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.prepared $(LINUX_CONFIG)
161 $(call Kernel/Configure)
162 touch $$@
163
164 $(LINUX_DIR)/.modules: $(LINUX_DIR)/.configured
165 rm -rf $(KERNEL_BUILD_DIR)/modules
166 @rm -f $(BUILD_DIR)/linux
167 ln -sf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) $(BUILD_DIR)/linux
168 $(call Kernel/CompileModules)
169 touch $$@
170
171 $(LINUX_DIR)/.image: $(LINUX_DIR)/.configured FORCE
172 $(call Kernel/CompileImage)
173 touch $$@
174
175 mostlyclean: FORCE
176 $(call Kernel/Clean)
177
178 ifeq ($(DUMP),1)
179 dumpinfo:
180 @echo 'Target: $(BOARD)-$(KERNEL)'
181 @echo 'Target-Name: $(BOARDNAME) [$(KERNEL)]'
182 @echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'
183 @echo 'Target-Arch: $(ARCH)'
184 @echo 'Target-Features: $(FEATURES)'
185 @echo 'Linux-Version: $(LINUX_VERSION)'
186 @echo 'Linux-Release: $(LINUX_RELEASE)'
187 @echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'
188 @echo 'Target-Description:'
189 @getvar $(call shvar,Target/Description)
190 @echo '@@'
191 @echo 'Default-Packages: $(DEFAULT_PACKAGES)'
192 ifneq ($(DUMPINFO),)
193 @$(DUMPINFO)
194 endif
195 endif
196
197 define BuildKernel
198 endef
199 endef
200
201 define Profile/Default
202 NAME:=
203 PACKAGES:=
204 endef
205
206 define Profile
207 $(eval $(call Profile/Default))
208 $(eval $(call Profile/$(1)))
209 DUMPINFO += \
210 echo "Target-Profile: $(1)"; \
211 echo "Target-Profile-Name: $(NAME)"; \
212 echo "Target-Profile-Packages: $(PACKAGES)";
213 endef
214
215 $(eval $(call shexport,Target/Description))
216
217 download: $(DL_DIR)/$(LINUX_SOURCE)
218 prepare: $(LINUX_DIR)/.configured $(TMP_DIR)/.kernel.mk
219 compile: $(LINUX_DIR)/.modules
220 install: $(LINUX_DIR)/.image
221
222 clean: FORCE
223 rm -f $(STAMP_DIR)/.linux-compile
224 rm -rf $(KERNEL_BUILD_DIR)
225
226 rebuild: FORCE
227 @$(MAKE) mostlyclean
228 @if [ -f $(LINUX_KERNEL) ]; then \
229 $(MAKE) clean; \
230 fi
231 @$(MAKE) compile
232
233
This page took 0.057733 seconds and 5 git commands to generate.