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