accept V= from the environment as well
[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)/modules-$(KERNEL).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 KERNEL_IDIR:=$(KERNEL_BUILD_DIR)/kernel-ipkg
16 KERNEL_IPKG:=$(KERNEL_BUILD_DIR)/kernel_$(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE)_$(ARCH).ipk
17 TARGETS += $(KERNEL_IPKG)
18 INSTALL_TARGETS += $(KERNEL_IPKG)
19
20 $(TARGETS): $(PACKAGE_DIR)
21
22 $(LINUX_DIR):
23 mkdir -p $@
24
25 $(PACKAGE_DIR):
26 mkdir -p $@
27
28 $(DL_DIR)/$(LINUX_SOURCE):
29 -mkdir -p $(DL_DIR)
30 $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
31
32 $(LINUX_DIR)/.unpacked: $(DL_DIR)/$(LINUX_SOURCE)
33 -mkdir -p $(KERNEL_BUILD_DIR)
34 bzcat $(DL_DIR)/$(LINUX_SOURCE) | tar -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS) -
35 touch $@
36
37 ifeq ($(KERNEL),2.4)
38 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.patched
39 $(SED) "s,^CROSS_COMPILE.*,CROSS_COMPILE=$(KERNEL_CROSS),g;" \
40 $(LINUX_DIR)/Makefile \
41 $(LINUX_DIR)/arch/*/Makefile
42 $(SED) "s,\-mcpu=,\-mtune=,g;" $(LINUX_DIR)/arch/mips/Makefile
43 $(MAKE) -C $(LINUX_DIR) ARCH=$(LINUX_KARCH) oldconfig include/linux/compile.h include/linux/version.h
44 touch $@
45
46 $(LINUX_DIR)/.depend_done: $(LINUX_DIR)/.configured
47 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(LINUX_KARCH) dep
48 touch $@
49
50 $(LINUX_DIR)/vmlinux: $(LINUX_DIR)/.depend_done
51 else
52 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.patched
53 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(LINUX_KARCH) oldconfig prepare scripts
54 touch $@
55 endif
56
57 ramdisk-config: $(LINUX_DIR)/.configured FORCE
58 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
59 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
60 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
61 echo 'CONFIG_INITRAMFS_SOURCE="../../root"' >> $(LINUX_DIR)/.config
62 echo 'CONFIG_INITRAMFS_ROOT_UID=0' >> $(LINUX_DIR)/.config
63 echo 'CONFIG_INITRAMFS_ROOT_GID=0' >> $(LINUX_DIR)/.config
64 mkdir -p $(BUILD_DIR)/root/etc/init.d
65 $(CP) ../generic-2.6/files/init $(BUILD_DIR)/root/
66 else
67 rm -f $(BUILD_DIR)/root/init $(BUILD_DIR)/root/etc/init.d/S00initramfs
68 echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
69 endif
70
71 $(LINUX_DIR)/vmlinux: $(STAMP_DIR)/.linux-compile pkg-install ramdisk-config
72 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(LINUX_KARCH) PATH=$(TARGET_PATH)
73
74 $(LINUX_KERNEL): $(LINUX_DIR)/vmlinux
75 $(TARGET_CROSS)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S $< $@
76 touch -c $(LINUX_KERNEL)
77
78 $(LINUX_DIR)/.modules_done:
79 rm -rf $(KERNEL_BUILD_DIR)/modules
80 $(MAKE) -C "$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(LINUX_KARCH) PATH="$(TARGET_PATH)" modules
81 $(MAKE) -C "$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" DEPMOD=true INSTALL_MOD_PATH=$(KERNEL_BUILD_DIR)/modules modules_install
82 touch $(LINUX_DIR)/.modules_done
83
84 modules: $(LINUX_DIR)/.modules_done
85 packages: $(TARGETS)
86
87 $(STAMP_DIR)/.linux-compile:
88 @$(MAKE) modules
89 @$(MAKE) packages
90 ln -sf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) $(BUILD_DIR)/linux
91 touch $@
92
93 $(KERNEL_IPKG):
94 rm -rf $(KERNEL_IDIR)
95 mkdir -p $(KERNEL_IDIR)/etc
96 $(SCRIPT_DIR)/make-ipkg-dir.sh $(KERNEL_IDIR) ../control/kernel.control $(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE) $(ARCH)
97 if [ -f ./config/$(BOARD).modules ]; then \
98 cp ./config/$(BOARD).modules $(KERNEL_IDIR)/etc/modules; \
99 fi
100 $(IPKG_BUILD) $(KERNEL_IDIR) $(KERNEL_BUILD_DIR)
101
102 $(TOPDIR)/.kernel.mk:
103 echo "BOARD:=$(BOARD)" > $@
104 echo "LINUX_VERSION:=$(LINUX_VERSION)" >> $@
105 echo "LINUX_RELEASE:=$(LINUX_RELEASE)" >> $@
106
107 pkg-install: FORCE
108 @for pkg in $(INSTALL_TARGETS); do \
109 $(IPKG) install $$pkg || echo; \
110 done
111
112 source: $(DL_DIR)/$(LINUX_SOURCE)
113 prepare: $(LINUX_DIR)/.configured
114 @mkdir -p $(STAMP_DIR) $(PACKAGE_DIR)
115
116 compile: prepare $(STAMP_DIR)/.linux-compile
117
118 install: compile $(LINUX_KERNEL)
119
120 mostlyclean: FORCE
121 rm -f $(STAMP_DIR)/.linux-compile
122 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.modules_done
123 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.drivers-unpacked
124 $(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
125 rm -f $(LINUX_KERNEL)
126
127 rebuild: FORCE
128 -$(MAKE) mostlyclean
129 if [ -f $(LINUX_KERNEL) ]; then \
130 $(MAKE) clean; \
131 fi
132 $(MAKE) compile $(MAKE_TRACE)
133
134 clean: FORCE
135 rm -f $(STAMP_DIR)/.linux-compile
136 rm -rf $(KERNEL_BUILD_DIR)
137 rm -f $(TARGETS)
138
This page took 0.053348 seconds and 5 git commands to generate.