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