make kernel module packaging code reusable and use it in madwifi
[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 LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
22 -e 's/mipsel/mips/' \
23 -e 's/mipseb/mips/' \
24 -e 's/powerpc/ppc/' \
25 -e 's/sh[234]/sh/' \
26 -e 's/armeb/arm/' \
27 )
28
29
30 $(TARGETS): $(PACKAGE_DIR)
31
32 $(PACKAGE_DIR):
33 mkdir -p $@
34
35 $(DL_DIR)/$(LINUX_SOURCE):
36 -mkdir -p $(DL_DIR)
37 $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
38
39 $(LINUX_DIR)/.unpacked: $(DL_DIR)/$(LINUX_SOURCE)
40 -mkdir -p $(KERNEL_BUILD_DIR)
41 bzcat $(DL_DIR)/$(LINUX_SOURCE) | tar -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
42 touch $@
43
44 ifeq ($(KERNEL),2.4)
45 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.patched
46 $(SED) "s,\-mcpu=,\-mtune=,g;" $(LINUX_DIR)/arch/mips/Makefile
47 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) oldconfig include/linux/compile.h include/linux/version.h
48 touch $@
49
50 $(LINUX_DIR)/.depend_done: $(LINUX_DIR)/.configured
51 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(LINUX_KARCH) dep
52 touch $@
53
54 $(LINUX_DIR)/vmlinux: $(LINUX_DIR)/.depend_done
55 else
56 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.patched
57 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) oldconfig prepare scripts
58 touch $@
59 endif
60
61 ramdisk-config: $(LINUX_DIR)/.configured FORCE
62 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
63 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
64 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
65 echo 'CONFIG_INITRAMFS_SOURCE="../../root"' >> $(LINUX_DIR)/.config
66 echo 'CONFIG_INITRAMFS_ROOT_UID=0' >> $(LINUX_DIR)/.config
67 echo 'CONFIG_INITRAMFS_ROOT_GID=0' >> $(LINUX_DIR)/.config
68 mkdir -p $(BUILD_DIR)/root/etc/init.d
69 $(CP) ../generic-2.6/files/init $(BUILD_DIR)/root/
70 else
71 rm -f $(BUILD_DIR)/root/init $(BUILD_DIR)/root/etc/init.d/S00initramfs
72 echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
73 endif
74
75 $(LINUX_DIR)/vmlinux: $(LINUX_DIR)/.linux-compile pkg-install ramdisk-config
76 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) $(KERNELNAME)
77
78 $(LINUX_KERNEL): $(LINUX_DIR)/vmlinux
79 $(KERNEL_CROSS)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S $< $@
80 touch -c $(LINUX_KERNEL)
81
82 $(LINUX_DIR)/.modules_done:
83 rm -rf $(KERNEL_BUILD_DIR)/modules
84 $(MAKE) -C "$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) modules
85 $(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
86 touch $(LINUX_DIR)/.modules_done
87
88 modules: $(LINUX_DIR)/.modules_done
89 packages: $(TARGETS)
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 $(KERNEL_IPKG):
98 rm -rf $(KERNEL_IDIR)
99 mkdir -p $(KERNEL_IDIR)/etc
100 $(SCRIPT_DIR)/make-ipkg-dir.sh $(KERNEL_IDIR) ../control/kernel.control $(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE) $(ARCH)
101 if [ -f ./config/$(BOARD).modules ]; then \
102 cp ./config/$(BOARD).modules $(KERNEL_IDIR)/etc/modules; \
103 fi
104 $(IPKG_BUILD) $(KERNEL_IDIR) $(KERNEL_BUILD_DIR)
105
106 $(TOPDIR)/.kernel.mk: $(TOPDIR)/target/linux/$(BOARD)-$(KERNEL)/Makefile
107 echo "CONFIG_BOARD:=$(BOARD)" > $@
108 echo "CONFIG_KERNEL:=$(KERNEL)" >> $@
109 echo "CONFIG_LINUX_VERSION:=$(LINUX_VERSION)" >> $@
110 echo "CONFIG_LINUX_RELEASE:=$(LINUX_RELEASE)" >> $@
111 echo "CONFIG_LINUX_KARCH:=$(LINUX_KARCH)" >> $@
112
113 pkg-install: FORCE
114 @for pkg in $(INSTALL_TARGETS); do \
115 $(IPKG) install $$pkg || echo; \
116 done
117
118 download: $(DL_DIR)/$(LINUX_SOURCE)
119 prepare: $(LINUX_DIR)/.configured
120 @mkdir -p $(LINUX_DIR) $(PACKAGE_DIR)
121
122 compile: prepare $(LINUX_DIR)/.linux-compile
123 @$(MAKE) packages
124
125 install: compile $(LINUX_KERNEL)
126
127 mostlyclean: FORCE
128 rm -f $(LINUX_DIR)/.linux-compile
129 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.modules_done
130 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.drivers-unpacked
131 $(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
132 rm -f $(LINUX_KERNEL)
133
134 rebuild: FORCE
135 -$(MAKE) mostlyclean
136 if [ -f $(LINUX_KERNEL) ]; then \
137 $(MAKE) clean; \
138 fi
139 $(MAKE) compile $(MAKE_TRACE)
140
141 clean: FORCE
142 rm -f $(STAMP_DIR)/.linux-compile
143 rm -rf $(KERNEL_BUILD_DIR)
144 rm -f $(TARGETS)
145
This page took 0.04774 seconds and 5 git commands to generate.