2 # Copyright (C) 2006 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
14 KERNEL:=2.$(word 2,$(subst ., ,$(strip $(LINUX_VERSION))))
16 include $(INCLUDE_DIR)/host.mk
17 include $(INCLUDE_DIR)/kernel.mk
19 LINUX_CONFIG:=./config
21 ifneq (,$(findstring uml,$(BOARD)))
24 LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
34 ifneq (,$(findstring x86,$(BOARD)))
37 ifneq (,$(findstring ppc,$(BOARD)))
42 define Kernel/Prepare/Default
43 bzcat $(DL_DIR)/$(LINUX_SOURCE) | tar -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
44 [ -d ../generic-$(KERNEL)/patches ] && $(PATCH) $(LINUX_DIR) ../generic-$(KERNEL)/patches
45 [ -d ./patches ] && $(PATCH) $(LINUX_DIR) ./patches
48 $(call Kernel/Prepare/Default)
52 define Kernel/Configure/2.4
53 $(SED) "s,\-mcpu=,\-mtune=,g;" $(LINUX_DIR)/arch/mips/Makefile
54 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) oldconfig include/linux/compile.h include/linux/version.h
55 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(LINUX_KARCH) dep
57 define Kernel/Configure/2.6
58 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) oldconfig prepare scripts
60 define Kernel/Configure/Default
61 @$(CP) $(LINUX_CONFIG) $(LINUX_DIR)/.config
62 $(call Kernel/Configure/$(KERNEL))
64 define Kernel/Configure
65 $(call Kernel/Configure/Default)
69 define Kernel/CompileModules/Default
70 $(MAKE) -j$(CONFIG_JLEVEL) -C "$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) modules
71 $(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
73 define Kernel/CompileModules
74 $(call Kernel/CompileModules/Default)
79 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
80 define Kernel/SetInitramfs
81 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
82 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
83 echo 'CONFIG_INITRAMFS_SOURCE="../../root"' >> $(LINUX_DIR)/.config
84 echo 'CONFIG_INITRAMFS_ROOT_UID=0' >> $(LINUX_DIR)/.config
85 echo 'CONFIG_INITRAMFS_ROOT_GID=0' >> $(LINUX_DIR)/.config
86 mkdir -p $(BUILD_DIR)/root/etc/init.d
87 $(CP) ../generic-2.6/files/init $(BUILD_DIR)/root/
90 define Kernel/SetInitramfs
91 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
92 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
93 rm -f $(BUILD_DIR)/root/init $(BUILD_DIR)/root/etc/init.d/S00initramfs
94 echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
98 define Kernel/CompileImage/Default
99 $(call Kernel/SetInitramfs)
100 $(MAKE) -j$(CONFIG_JLEVEL) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) $(KERNELNAME)
101 $(KERNEL_CROSS)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)
103 define Kernel/CompileImage
104 $(call Kernel/CompileImage/Default)
107 define Kernel/Clean/Default
108 rm -f $(LINUX_DIR)/.linux-compile
109 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.configured
110 rm -f $(LINUX_KERNEL)
111 $(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
115 $(call Kernel/Clean/Default)
119 ifneq ($(LINUX_SITE),)
120 $(DL_DIR)/$(LINUX_SOURCE):
122 $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
125 $(LINUX_DIR)/.prepared: $(DL_DIR)/$(LINUX_SOURCE)
126 -rm -rf $(KERNEL_BUILD_DIR)
127 -mkdir -p $(KERNEL_BUILD_DIR)
128 $(call Kernel/Prepare)
131 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.prepared $(LINUX_CONFIG)
132 $(call Kernel/Configure)
135 $(LINUX_DIR)/.modules: $(LINUX_DIR)/.configured
136 rm -rf $(KERNEL_BUILD_DIR)/modules
137 @rm -f $(BUILD_DIR)/linux
138 ln -sf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) $(BUILD_DIR)/linux
139 $(call Kernel/CompileModules)
142 $(LINUX_DIR)/.image: $(LINUX_DIR)/.configured FORCE
143 $(call Kernel/CompileImage)
153 $(eval $(call shexport,Target/Description))
157 @echo 'Target: $(BOARD)-$(KERNEL)'
158 @echo 'Target-Name: $(BOARDNAME) [$(KERNEL)]'
159 @echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'
160 @echo 'Target-Arch: $(ARCH)'
161 @echo 'Target-Features: $(FEATURES)'
162 @echo 'Linux-Version: $(LINUX_VERSION)'
163 @echo 'Linux-Release: $(LINUX_RELEASE)'
164 @echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'
165 @echo 'Target-Description:'
166 @echo "$$$(call shvar,Target/Description)"
169 download: $(DL_DIR)/$(LINUX_SOURCE)
170 prepare: $(LINUX_DIR)/.configured $(TMP_DIR)/.kernel.mk
171 compile: $(LINUX_DIR)/.modules
172 install: $(LINUX_DIR)/.image
175 rm -f $(STAMP_DIR)/.linux-compile
176 rm -rf $(KERNEL_BUILD_DIR)
180 @if [ -f $(LINUX_KERNEL) ]; then \