finally kill KMOD_template - removes a big chunk of legacy build code
[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 include $(INCLUDE_DIR)/host.mk
8
9 LINUX_SOURCE:=linux-$(LINUX_VERSION).tar.bz2
10 LINUX_SITE=http://www.us.kernel.org/pub/linux/kernel/v$(KERNEL) \
11 http://www.us.kernel.org/pub/linux/kernel/v$(KERNEL) \
12 http://www.kernel.org/pub/linux/kernel/v$(KERNEL) \
13 http://www.de.kernel.org/pub/linux/kernel/v$(KERNEL)
14
15 ifneq (,$(findstring uml,$(BOARD)))
16 LINUX_KARCH:=um
17 else
18 LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
19 -e 's/mipsel/mips/' \
20 -e 's/mipseb/mips/' \
21 -e 's/powerpc/ppc/' \
22 -e 's/sh[234]/sh/' \
23 -e 's/armeb/arm/' \
24 )
25 endif
26
27 KERNELNAME=
28 ifneq (,$(findstring x86,$(BOARD)))
29 KERNELNAME="bzImage"
30 endif
31 ifneq (,$(findstring ppc,$(BOARD)))
32 KERNELNAME="uImage"
33 endif
34
35
36 $(DL_DIR)/$(LINUX_SOURCE):
37 -mkdir -p $(DL_DIR)
38 $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
39
40 $(LINUX_DIR)/.unpacked: $(DL_DIR)/$(LINUX_SOURCE)
41 -mkdir -p $(KERNEL_BUILD_DIR)
42 bzcat $(DL_DIR)/$(LINUX_SOURCE) | tar -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
43 touch $@
44
45 ifeq ($(KERNEL),2.4)
46 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.patched
47 $(SED) "s,\-mcpu=,\-mtune=,g;" $(LINUX_DIR)/arch/mips/Makefile
48 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) oldconfig include/linux/compile.h include/linux/version.h
49 touch $@
50
51 $(LINUX_DIR)/.depend_done: $(LINUX_DIR)/.configured
52 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(LINUX_KARCH) dep
53 touch $@
54
55 $(LINUX_DIR)/vmlinux: $(LINUX_DIR)/.depend_done
56 else
57 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.patched
58 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) oldconfig prepare scripts
59 touch $@
60 endif
61
62 ramdisk-config: $(LINUX_DIR)/.configured FORCE
63 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
64 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
65 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
66 echo 'CONFIG_INITRAMFS_SOURCE="../../root"' >> $(LINUX_DIR)/.config
67 echo 'CONFIG_INITRAMFS_ROOT_UID=0' >> $(LINUX_DIR)/.config
68 echo 'CONFIG_INITRAMFS_ROOT_GID=0' >> $(LINUX_DIR)/.config
69 mkdir -p $(BUILD_DIR)/root/etc/init.d
70 $(CP) ../generic-2.6/files/init $(BUILD_DIR)/root/
71 else
72 rm -f $(BUILD_DIR)/root/init $(BUILD_DIR)/root/etc/init.d/S00initramfs
73 echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
74 endif
75
76 $(LINUX_DIR)/vmlinux: $(LINUX_DIR)/.linux-compile ramdisk-config
77 $(MAKE) -j$(CONFIG_JLEVEL) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) $(KERNELNAME)
78
79 $(LINUX_KERNEL): $(LINUX_DIR)/vmlinux
80 $(KERNEL_CROSS)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S $< $@
81 touch -c $(LINUX_KERNEL)
82
83 $(LINUX_DIR)/.modules_done:
84 rm -rf $(KERNEL_BUILD_DIR)/modules
85 $(MAKE) -j$(CONFIG_JLEVEL) -C "$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) modules
86 $(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
87 touch $(LINUX_DIR)/.modules_done
88
89 modules: $(LINUX_DIR)/.modules_done
90
91 $(LINUX_DIR)/.linux-compile:
92 @rm -f $(BUILD_DIR)/linux
93 ln -sf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) $(BUILD_DIR)/linux
94 @$(MAKE) modules
95 touch $@
96
97 $(TOPDIR)/.kernel.mk: $(TOPDIR)/target/linux/$(BOARD)-$(KERNEL)/Makefile
98 echo "CONFIG_BOARD:=$(BOARD)" > $@
99 echo "CONFIG_KERNEL:=$(KERNEL)" >> $@
100 echo "CONFIG_LINUX_VERSION:=$(LINUX_VERSION)" >> $@
101 echo "CONFIG_LINUX_RELEASE:=$(LINUX_RELEASE)" >> $@
102 echo "CONFIG_LINUX_KARCH:=$(LINUX_KARCH)" >> $@
103
104 download: $(DL_DIR)/$(LINUX_SOURCE)
105 prepare: $(LINUX_DIR)/.configured
106 @mkdir -p $(LINUX_DIR)
107
108 compile: prepare $(LINUX_DIR)/.linux-compile
109
110 install: compile $(LINUX_KERNEL)
111
112 mostlyclean: FORCE
113 rm -f $(LINUX_DIR)/.linux-compile
114 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.modules_done
115 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.drivers-unpacked
116 $(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
117 rm -f $(LINUX_KERNEL)
118
119 rebuild: FORCE
120 -$(MAKE) mostlyclean
121 if [ -f $(LINUX_KERNEL) ]; then \
122 $(MAKE) clean; \
123 fi
124 $(MAKE) compile $(MAKE_TRACE)
125
126 clean: FORCE
127 rm -f $(STAMP_DIR)/.linux-compile
128 rm -rf $(KERNEL_BUILD_DIR)
129