1 |
# Copyright 1999-2004 Gentoo Foundation |
2 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
# $Header: $ |
4 |
|
5 |
# This eclass provides functions for compiling external kernel modules |
6 |
# from source. |
7 |
|
8 |
inherit linux-info |
9 |
ECLASS=linux-mod |
10 |
INHERITED="$INHERITED $ECLASS" |
11 |
EXPORT_FUNCTIONS pkg_setup pkg_postinst src_compile |
12 |
|
13 |
DESCRIPTION="Based on the $ECLASS eclass" |
14 |
SLOT=0 |
15 |
DEPEND="virtual/linux-sources |
16 |
sys-apps/sed" |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
# This eclass is designed to help ease the installation of external kernel |
22 |
# modules into the kernel tree. |
23 |
|
24 |
|
25 |
# eclass utilities |
26 |
# ---------------------------------- |
27 |
|
28 |
use_m() { |
29 |
# if we haven't determined the version yet, we need too. |
30 |
get_version; |
31 |
|
32 |
# if the kernel version is greater than 2.6.6 then we should use |
33 |
# M= instead of SUBDIR= |
34 |
[ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \ |
35 |
return 0 || return 1 |
36 |
} |
37 |
|
38 |
convert_to_m() { |
39 |
[ ! -f "${1}" ] && die "convert_to_m() requires a filename as an argument" |
40 |
if use_m |
41 |
then |
42 |
ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIR=" |
43 |
sed -i 's:SUBDIRS=:M=:g' ${1} |
44 |
eend $? |
45 |
fi |
46 |
} |
47 |
|
48 |
update_depmod() { |
49 |
# if we haven't determined the version yet, we need too. |
50 |
get_version; |
51 |
|
52 |
ebegin "Updating module dependencies for ${KV_FULL}" |
53 |
if [ -r ${KV_DIR}/System.map ] |
54 |
then |
55 |
depmod -ae -F ${KV_DIR}/System.map -b ${ROOT} -r ${KV_FULL} |
56 |
else |
57 |
ewarn |
58 |
ewarn "${KV_DIR}/System.map not found." |
59 |
ewarn "You must manually update the kernel module dependencies using depmod." |
60 |
ewarn |
61 |
fi |
62 |
eend $? |
63 |
} |
64 |
|
65 |
set_kvobj() { |
66 |
if kernel_is 2 6 |
67 |
then |
68 |
KV_OBJ="ko" |
69 |
else |
70 |
KV_OBJ="o" |
71 |
fi |
72 |
einfo "Using KV_OBJ=${KV_OBJ}" |
73 |
} |
74 |
|
75 |
display_postinst() { |
76 |
# if we haven't determined the version yet, we need too. |
77 |
get_version; |
78 |
|
79 |
local modulename moduledir sourcedir module_temp file i |
80 |
|
81 |
file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR} |
82 |
file=${file/\/\///} |
83 |
|
84 |
einfo "If you would like to load this module automatically upon boot" |
85 |
einfo "please type the following as root:" |
86 |
for i in ${MODULE_NAMES} |
87 |
do |
88 |
module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" |
89 |
modulename="${i/(*/}" |
90 |
moduledir="${module_temp/:*/}" |
91 |
moduledir="${moduledir:-misc}" |
92 |
sourcedir="${module_temp/*:/}" |
93 |
sourcedir="${sourcedir:-${S}}" |
94 |
|
95 |
einfo " # echo \"${modulename}\" >> ${file}" |
96 |
done |
97 |
echo |
98 |
} |
99 |
|
100 |
# default ebuild functions |
101 |
# -------------------------------- |
102 |
|
103 |
linux-mod_pkg_setup() { |
104 |
get_version; |
105 |
check_kernel_built |
106 |
check_modules_supported; |
107 |
set_kvobj; |
108 |
} |
109 |
|
110 |
linux-mod_src_compile() { |
111 |
local modulename moduledir sourcedir module_temp xarch i |
112 |
xarch="${ARCH}" |
113 |
unset ARCH |
114 |
|
115 |
for i in ${MODULE_NAMES} |
116 |
do |
117 |
module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" |
118 |
modulename="${i/(*/}" |
119 |
moduledir="${module_temp/:*/}" |
120 |
moduledir="${moduledir:-misc}" |
121 |
sourcedir="${module_temp/*:/}" |
122 |
sourcedir="${sourcedir:-${S}}" |
123 |
|
124 |
einfo "Preparing ${modulename} module" |
125 |
cd ${sourcedir} |
126 |
make clean |
127 |
make ${BUILD_PARAMS} module |
128 |
done |
129 |
ARCH="${xarch}" |
130 |
} |
131 |
|
132 |
linux-mod_src_install() { |
133 |
local modulename moduledir sourcedir module_temp i |
134 |
|
135 |
for i in "${MODULE_NAMES}" |
136 |
do |
137 |
module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" |
138 |
modulename="${i/(*/}" |
139 |
moduledir="${module_temp/:*/}" |
140 |
moduledir="${moduledir:-misc}" |
141 |
sourcedir="${module_temp/*:/}" |
142 |
sourcedir="${sourcedir:-${S}}" |
143 |
|
144 |
einfo "Installing ${modulename} module" |
145 |
cd ${sourcedir} |
146 |
insinto /lib/modules/${KV_FULL}/${moduledir} |
147 |
doins ${modulename}.${KV_OBJ} |
148 |
done |
149 |
} |
150 |
|
151 |
linux-mod_pkg_postinst() { |
152 |
update_depmod; |
153 |
display_postinst; |
154 |
} |