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