fix inclusion of kernel modules selected for install in images (closes: #598).
[openwrt/svn-archive/archive.git] / openwrt / target / linux / rules.mk
1 KERNEL:=unknown
2 ifneq (,$(findstring 2.4.,$(LINUX_VERSION)))
3 KERNEL:=2.4
4 endif
5 ifneq (,$(findstring 2.6.,$(LINUX_VERSION)))
6 KERNEL:=2.6
7 endif
8
9 MODULES_SUBDIR:=lib/modules/$(LINUX_VERSION)
10
11 LINUX_BUILD_DIR:=$(BUILD_DIR)/linux-$(KERNEL)-$(BOARD)
12 LINUX_DIR := $(LINUX_BUILD_DIR)/linux-$(LINUX_VERSION)
13 LINUX_KERNEL:=$(LINUX_BUILD_DIR)/vmlinux
14
15 LINUX_TARGET_DIR:=$(LINUX_BUILD_DIR)/root
16 IPKG_KERNEL:=IPKG_TMP=$(BUILD_DIR)/tmp IPKG_INSTROOT=$(LINUX_TARGET_DIR) IPKG_CONF_DIR=$(LINUX_BUILD_DIR) $(SCRIPT_DIR)/ipkg -force-defaults -force-depends
17
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
26 KPKG_MAKEOPTS:= IPKG="$(IPKG_KERNEL)" \
27 BOARD="$(BOARD)" \
28 KERNEL="$(KERNEL)" \
29 TARGET_DIR="$(LINUX_TARGET_DIR)" \
30 LINUX_BUILD_DIR="$(LINUX_BUILD_DIR)" \
31 LINUX_DIR="$(LINUX_DIR)" \
32 LINUX_VERSION="$(LINUX_VERSION)" \
33 LINUX_RELEASE="$(LINUX_RELEASE)"
34
35 KMOD_BUILD_DIR := $(LINUX_BUILD_DIR)/linux-modules
36 MODULES_DIR := $(LINUX_BUILD_DIR)/modules/$(MODULES_SUBDIR)
37 TARGET_MODULES_DIR := $(LINUX_TARGET_DIR)/$(MODULES_SUBDIR)
38
39 ifeq ($(KERNEL),2.6)
40 LINUX_KMOD_SUFFIX=ko
41 else
42 LINUX_KMOD_SUFFIX=o
43 endif
44
45 define KMOD_template
46 ifeq ($$(strip $(4)),)
47 KDEPEND_$(1):=m
48 else
49 KDEPEND_$(1):=$($(4))
50 endif
51
52 IDEPEND_$(1):=kernel ($(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE)) $(foreach pkg,$(5),", $(pkg)")
53
54 PKG_$(1) := $(PACKAGE_DIR)/kmod-$(2)_$(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE)_$(ARCH).ipk
55 I_$(1) := $(KMOD_BUILD_DIR)/ipkg/$(2)
56
57 ifeq ($$(KDEPEND_$(1)),m)
58 ifneq ($$(BR2_PACKAGE_KMOD_$(1)),)
59 TARGETS += $$(PKG_$(1))
60 endif
61 ifeq ($$(BR2_PACKAGE_KMOD_$(1)),y)
62 INSTALL_TARGETS += $$(PKG_$(1))
63 endif
64 endif
65
66 $$(PKG_$(1)): $(LINUX_DIR)/.modules_done
67 rm -rf $$(I_$(1))
68 $(SCRIPT_DIR)/make-ipkg-dir.sh $$(I_$(1)) ../control/kmod-$(2).control $(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE) $(ARCH)
69 echo "Depends: $$(IDEPEND_$(1))" >> $$(I_$(1))/CONTROL/control
70 ifneq ($(strip $(3)),)
71 mkdir -p $$(I_$(1))/lib/modules/$(LINUX_VERSION)
72 $(CP) $(3) $$(I_$(1))/lib/modules/$(LINUX_VERSION)
73 endif
74 ifneq ($(6),)
75 mkdir -p $$(I_$(1))/etc/modules.d
76 for module in $(7); do \
77 echo $$$$module >> $$(I_$(1))/etc/modules.d/$(6)-$(2); \
78 done
79 echo "#!/bin/sh" >> $$(I_$(1))/CONTROL/postinst
80 echo "[ -z \"\$$$$IPKG_INSTROOT\" ] || exit" >> $$(I_$(1))/CONTROL/postinst
81 echo ". /etc/functions.sh" >> $$(I_$(1))/CONTROL/postinst
82 echo "load_modules /etc/modules.d/$(6)-$(2)" >> $$(I_$(1))/CONTROL/postinst
83 chmod 0755 $$(I_$(1))/CONTROL/postinst
84 endif
85 $(8)
86 $(IPKG_BUILD) $$(I_$(1)) $(PACKAGE_DIR) $(MAKE_TRACE)
87
88 endef
89
90 KERNEL_IPKG:=$(LINUX_BUILD_DIR)/kernel_$(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE)_$(ARCH).ipk
91 INSTALL_TARGETS := $(KERNEL_IPKG)
92 TARGETS :=
93