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