db02ea2160e5727156d99da7e2fceeaf00b74f90
[openwrt.git] / include / kernel.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 ifeq ($(DUMP),1)
8 KERNEL:=<KERNEL>
9 BOARD:=<BOARD>
10 LINUX_VERSION:=<LINUX_VERSION>
11 else
12 -include $(TOPDIR)/.kernel.mk
13
14 ifneq (,$(findstring 2.4.,$(LINUX_VERSION)))
15 KERNEL:=2.4
16 LINUX_KMOD_SUFFIX=o
17 endif
18 ifneq (,$(findstring 2.6.,$(LINUX_VERSION)))
19 KERNEL:=2.6
20 LINUX_KMOD_SUFFIX=ko
21 endif
22
23 LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
24 -e 's/mipsel/mips/' \
25 -e 's/mipseb/mips/' \
26 -e 's/powerpc/ppc/' \
27 -e 's/sh[234]/sh/' \
28 -e 's/armeb/arm/' \
29 )
30
31 ifneq (,$(findstring uml,$(BOARD)))
32 LINUX_KARCH:=um
33 KERNEL_CC:=$(HOSTCC)
34 KERNEL_CROSS:=
35 else
36 KERNEL_CC:=$(TARGET_CC)
37 KERNEL_CROSS:=$(TARGET_CROSS)
38 endif
39
40 KERNEL_BUILD_DIR:=$(BUILD_DIR)/linux-$(KERNEL)-$(BOARD)
41 LINUX_DIR := $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)
42
43 MODULES_SUBDIR:=lib/modules/$(LINUX_VERSION)
44 MODULES_DIR := $(KERNEL_BUILD_DIR)/modules/$(MODULES_SUBDIR)
45 TARGET_MODULES_DIR := $(LINUX_TARGET_DIR)/$(MODULES_SUBDIR)
46 KMOD_BUILD_DIR := $(KERNEL_BUILD_DIR)/linux-modules
47
48 LINUX_KERNEL:=$(KERNEL_BUILD_DIR)/vmlinux
49 endif
50
51 # FIXME: remove this crap
52 define KMOD_template
53 ifeq ($$(strip $(4)),)
54 KDEPEND_$(1):=m
55 else
56 KDEPEND_$(1):=$($(4))
57 endif
58
59 IDEPEND_$(1):=kernel ($(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE)) $(foreach pkg,$(5),", $(pkg)")
60
61 PKG_$(1) := $(PACKAGE_DIR)/kmod-$(2)_$(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE)_$(ARCH).ipk
62 I_$(1) := $(KMOD_BUILD_DIR)/ipkg/$(2)
63
64 ifeq ($$(KDEPEND_$(1)),m)
65 ifneq ($$(CONFIG_PACKAGE_KMOD_$(1)),)
66 TARGETS += $$(PKG_$(1))
67 endif
68 ifeq ($$(CONFIG_PACKAGE_KMOD_$(1)),y)
69 INSTALL_TARGETS += $$(PKG_$(1))
70 endif
71 endif
72
73 $$(PKG_$(1)): $(LINUX_DIR)/.modules_done
74 rm -rf $$(I_$(1))
75 $(SCRIPT_DIR)/make-ipkg-dir.sh $$(I_$(1)) ../control/kmod-$(2).control $(LINUX_VERSION)-$(BOARD)-$(LINUX_RELEASE) $(ARCH)
76 echo "Depends: $$(IDEPEND_$(1))" >> $$(I_$(1))/CONTROL/control
77 ifneq ($(strip $(3)),)
78 mkdir -p $$(I_$(1))/lib/modules/$(LINUX_VERSION)
79 $(CP) $(3) $$(I_$(1))/lib/modules/$(LINUX_VERSION)
80 endif
81 ifneq ($(6),)
82 mkdir -p $$(I_$(1))/etc/modules.d
83 for module in $(7); do \
84 echo $$$$module >> $$(I_$(1))/etc/modules.d/$(6)-$(2); \
85 done
86 echo "#!/bin/sh" >> $$(I_$(1))/CONTROL/postinst
87 echo "[ -z \"\$$$$IPKG_INSTROOT\" ] || exit" >> $$(I_$(1))/CONTROL/postinst
88 echo ". /etc/functions.sh" >> $$(I_$(1))/CONTROL/postinst
89 echo "load_modules /etc/modules.d/$(6)-$(2)" >> $$(I_$(1))/CONTROL/postinst
90 chmod 0755 $$(I_$(1))/CONTROL/postinst
91 endif
92 $(8)
93 $(IPKG_BUILD) $$(I_$(1)) $(PACKAGE_DIR)
94 endef
95
This page took 0.040618 seconds and 3 git commands to generate.