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.
7 -include $(INCLUDE_DIR)/modules-$(KERNEL).mk
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)
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)
20 $(TARGETS): $(PACKAGE_DIR)
28 $(DL_DIR)/$(LINUX_SOURCE):
30 $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
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) -
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
46 $(LINUX_DIR)/.depend_done: $(LINUX_DIR)/.configured
47 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(LINUX_KARCH) dep
50 $(LINUX_DIR)/vmlinux: $(LINUX_DIR)/.depend_done
52 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.patched
53 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(LINUX_KARCH) oldconfig prepare scripts
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/
67 rm -f $(BUILD_DIR)/root/init $(BUILD_DIR)/root/etc/init.d/S00initramfs
68 echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
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)
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)
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
84 modules: $(LINUX_DIR)/.modules_done
87 $(STAMP_DIR)/.linux-compile:
90 ln -sf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) $(BUILD_DIR)/linux
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; \
100 $(IPKG_BUILD) $(KERNEL_IDIR) $(KERNEL_BUILD_DIR)
102 $(TOPDIR)/.kernel.mk:
103 echo "BOARD:=$(BOARD)" > $@
104 echo "LINUX_VERSION:=$(LINUX_VERSION)" >> $@
105 echo "LINUX_RELEASE:=$(LINUX_RELEASE)" >> $@
108 @{ [ "$(INSTALL_TARGETS)" != "" ] && $(IPKG) install $(INSTALL_TARGETS) || true; }
110 source: $(DL_DIR)/$(LINUX_SOURCE)
111 prepare: $(LINUX_DIR)/.configured
112 @mkdir -p $(STAMP_DIR) $(PACKAGE_DIR)
114 compile: prepare $(STAMP_DIR)/.linux-compile
116 install: compile $(LINUX_KERNEL)
119 rm -f $(STAMP_DIR)/.linux-compile
120 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.modules_done
121 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.drivers-unpacked
122 $(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
123 rm -f $(LINUX_KERNEL)
127 if [ -f $(LINUX_KERNEL) ]; then \
130 $(MAKE) compile $(MAKE_TRACE)
133 rm -f $(STAMP_DIR)/.linux-compile
134 rm -rf $(KERNEL_BUILD_DIR)
139 add_module $(1) "$(2)";
142 define KernelPackage/Defaults
143 VERSION:=$(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE)
145 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
146 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
159 $(eval $(call KernelPackage/Defaults))
160 $(eval $(call KernelPackage/$(1)))
161 $(eval $(call KernelPackage/$(1)/$(KERNEL)))
163 PKG_$(1) := $(PACKAGE_DIR)/kmod-$(1)_$(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE)_$(ARCH).ipk
164 I_$(1) := $(KMOD_BUILD_DIR)/ipkg/$(1)
166 IDEPEND_$(1):='kernel ($(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE))' $(DEPENDS)
168 ifeq ($$(strip $(KCONFIG)),)
171 KDEPEND_$(1):=$($(KCONFIG))
173 ifeq ($$(KDEPEND_$(1)),m)
174 ifneq ($(CONFIG_PACKAGE_kmod-$(1)),)
175 packages: $$(PKG_$(1))
177 ifeq ($(CONFIG_PACKAGE_kmod-$(1)),y)
178 install-kmod-$(1): FORCE
179 $(IPKG) install $$(PKG_$(1))
180 pkg-install: install-kmod-$(1)
184 $$(PKG_$(1)): $(LINUX_DIR)/.modules_done
186 install -d -m0755 $$(I_$(1))/CONTROL
187 echo "Package: kmod-$(1)" > $$(I_$(1))/CONTROL/control
188 echo "Version: $(VERSION)" >> $$(I_$(1))/CONTROL/control
191 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
192 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
194 echo "Depends: $$$$DEPENDS" >> $$(I_$(1))/CONTROL/control; \
196 echo "Source: $(SOURCE)" >> $$(I_$(1))/CONTROL/control
197 echo "Section: kernel" >> $$(I_$(1))/CONTROL/control
198 echo "Priority: $(PRIORITY)" >> $$(I_$(1))/CONTROL/control
199 echo "Maintainer: $(MAINTAINER)" >> $$(I_$(1))/CONTROL/control
200 echo "Architecture: $(PKGARCH)" >> $$(I_$(1))/CONTROL/control
201 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(I_$(1))/CONTROL/control
202 ifneq ($(strip $(FILES)),)
203 mkdir -p $$(I_$(1))/lib/modules/$(LINUX_VERSION)
204 $(CP) $(FILES) $$(I_$(1))/lib/modules/$(LINUX_VERSION)/
209 mkdir -p $$(I_$(1))/etc/modules.d; \
210 echo "$$$$2" > $$(I_$(1))/etc/modules.d/$$$$1-$(1); \
211 modules="$$$${modules:+$$$$modules }$$$$1-$(1)"; \
214 mkdir -p $$(I_$(1))/etc/modules.d; \
215 echo "#!/bin/sh" >> $$(I_$(1))/CONTROL/postinst; \
216 echo "[ -z \"\$$$$IPKG_INSTROOT\" ] || exit" >> $$(I_$(1))/CONTROL/postinst; \
217 echo ". /etc/functions.sh" >> $$(I_$(1))/CONTROL/postinst; \
218 echo "load_modules $$$$modules" >> $$(I_$(1))/CONTROL/postinst; \
219 chmod 0755 $$(I_$(1))/CONTROL/postinst;
221 $(IPKG_BUILD) $$(I_$(1)) $(PACKAGE_DIR)
224 -include $(INCLUDE_DIR)/modules.mk