1 |
# Copyright 1999-2004 Gentoo Foundation |
2 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
# $Header: /var/cvsroot/gentoo-x86/eclass/linux-mod.eclass,v 1.17 2005/01/09 19:10:55 johnm Exp $ |
4 |
|
5 |
# Description: This eclass is used to interface with linux-info in such a way |
6 |
# to provide the functionality required and initial functions |
7 |
# required to install external modules against a kernel source |
8 |
# tree. |
9 |
# |
10 |
# Maintainer: John Mylchreest <johnm@gentoo.org> |
11 |
# Copyright 2004 Gentoo Linux |
12 |
# |
13 |
# Please direct your bugs to the current eclass maintainer :) |
14 |
|
15 |
# A Couple of env vars are available to effect usage of this eclass |
16 |
# These are as follows: |
17 |
# |
18 |
# Env Var Option Default Description |
19 |
# KERNEL_DIR <string> /usr/src/linux The directory containing kernel |
20 |
# the target kernel sources. |
21 |
# ECONF_PARAMS <string> The parameters to pass to econf. |
22 |
# If this is not set, then econf isn't |
23 |
# run. |
24 |
# BUILD_PARAMS <string> The parameters to pass to emake. |
25 |
# BUILD_TARGETS <string> clean modules The build targets to pass to make. |
26 |
# MODULE_NAMES <string> This is the modules which are |
27 |
# to be built automatically using the |
28 |
# default pkg_compile/install. They |
29 |
# are explained properly below. |
30 |
# It will only make BUILD_TARGETS once |
31 |
# in any directory. |
32 |
# NO_MODULESD <string> Set this to something to prevent |
33 |
# modulesd file generation |
34 |
|
35 |
|
36 |
# MODULE_NAMES - Detailed Overview |
37 |
# |
38 |
# The structure of each MODULE_NAMES entry is as follows: |
39 |
# modulename(libmodulesdir:modulesourcedir) |
40 |
# for example: |
41 |
# MODULE_NAMES="module_pci(pci:${S}/pci) module_usb(usb:${S}/usb)" |
42 |
# |
43 |
# what this would do is |
44 |
# cd ${S}/pci |
45 |
# make ${BUILD_PARAMS} ${BUILD_TARGETS} |
46 |
# insinto /lib/modules/${KV_FULL}/pci |
47 |
# doins module_pci.${KV_OBJ} |
48 |
# |
49 |
# cd ${S}/usb |
50 |
# make ${BUILD_PARAMS} ${BUILD_TARGETS} |
51 |
# insinto /lib/modules/${KV_FULL}/usb |
52 |
# doins module_usb.${KV_OBJ} |
53 |
# |
54 |
# if the modulessourcedir isnt specified, it assumes ${S} |
55 |
# if the libmodulesdir isnt specified, it assumes misc. |
56 |
# if no seperator is defined ":" then it assumes the argument is modulesourcedir |
57 |
|
58 |
inherit linux-info |
59 |
ECLASS=linux-mod |
60 |
INHERITED="$INHERITED $ECLASS" |
61 |
EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst src_compile |
62 |
|
63 |
DESCRIPTION="Based on the $ECLASS eclass" |
64 |
SLOT=0 |
65 |
DEPEND="virtual/linux-sources |
66 |
sys-apps/sed |
67 |
virtual/modutils" |
68 |
|
69 |
# eclass utilities |
70 |
# ---------------------------------- |
71 |
|
72 |
use_m() { |
73 |
# if we haven't determined the version yet, we need too. |
74 |
get_version; |
75 |
|
76 |
# if the kernel version is greater than 2.6.6 then we should use |
77 |
# M= instead of SUBDIRS= |
78 |
[ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \ |
79 |
return 0 || return 1 |
80 |
} |
81 |
|
82 |
convert_to_m() { |
83 |
[ ! -f "${1}" ] && die "convert_to_m() requires a filename as an argument" |
84 |
if use_m |
85 |
then |
86 |
ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIRS=" |
87 |
sed -i 's:SUBDIRS=:M=:g' ${1} |
88 |
eend $? |
89 |
fi |
90 |
} |
91 |
|
92 |
update_depmod() { |
93 |
# if we haven't determined the version yet, we need too. |
94 |
get_version; |
95 |
|
96 |
ebegin "Updating module dependencies for ${KV_FULL}" |
97 |
if [ -r ${KV_OUT_DIR}/System.map ] |
98 |
then |
99 |
depmod -ae -F ${KV_OUT_DIR}/System.map -b ${ROOT} -r ${KV_FULL} |
100 |
eend $? |
101 |
else |
102 |
ewarn |
103 |
ewarn "${KV_OUT_DIR}/System.map not found." |
104 |
ewarn "You must manually update the kernel module dependencies using depmod." |
105 |
eend 1 |
106 |
ewarn |
107 |
fi |
108 |
} |
109 |
|
110 |
update_modules() { |
111 |
if [ -x /sbin/modules-update ] ; |
112 |
then |
113 |
ebegin "Updating modules.conf" |
114 |
/sbin/modules-update |
115 |
eend $? |
116 |
fi |
117 |
} |
118 |
|
119 |
set_kvobj() { |
120 |
if kernel_is 2 6 |
121 |
then |
122 |
KV_OBJ="ko" |
123 |
else |
124 |
KV_OBJ="o" |
125 |
fi |
126 |
einfo "Using KV_OBJ=${KV_OBJ}" |
127 |
} |
128 |
|
129 |
generate_modulesd() { |
130 |
# This function will generate the neccessary modules.d file from the |
131 |
# information contained in the modules exported parms |
132 |
|
133 |
local selectedmodule selectedmodule_full selectedmodulevars parameter modinfop arg xifs temp |
134 |
local module_docs module_opts module_aliases module_config |
135 |
|
136 |
for arg in ${@} |
137 |
do |
138 |
selectedmodule_full="${arg}" |
139 |
# strip the directory |
140 |
selectedmodule="${selectedmodule_full/*\//}" |
141 |
# convert the modulename to uppercase |
142 |
selectedmodule="$(echo ${selectedmodule} | tr '[:lower:]' '[:upper:]')" |
143 |
|
144 |
module_docs="MODULESD_${selectedmodule}_DOCS" |
145 |
module_aliases="$(eval echo \$\{#MODULESD_${selectedmodule}_ALIASES[*]\})" |
146 |
[ ${module_aliases} == 0 ] && unset module_aliases |
147 |
module_docs="${!module_docs}" |
148 |
modinfop="$(modinfo -p ${selectedmodule_full}.${KV_OBJ})" |
149 |
|
150 |
# By now we know if there is anything we can use to generate a file with |
151 |
# so unset empty vars and bail out if we find nothing. |
152 |
for parameter in ${!module_*} |
153 |
do |
154 |
[ -z "${!parameter}" ] && unset ${parameter} |
155 |
done |
156 |
[ -z "${!module_*}" -a -z "${modinfop}" ] && return |
157 |
|
158 |
#so now we can set the configfilevar |
159 |
module_config="${T}/modulesd-${selectedmodule}" |
160 |
|
161 |
# and being working on things. |
162 |
ebegin "Preparing file for modules.d" |
163 |
echo "# modules.d config file for ${selectedmodule}" >> ${module_config} |
164 |
echo "# this file was automatically generated from linux-mod.eclass" >> ${module_config} |
165 |
for temp in ${module_docs} |
166 |
do |
167 |
echo "# Please read ${temp/*\//} for more info" >> ${module_config} |
168 |
done |
169 |
|
170 |
if [ ${module_aliases} > 0 ]; |
171 |
then |
172 |
echo >> ${module_config} |
173 |
echo "# Internal Aliases - Do not edit" >> ${module_config} |
174 |
echo "# ------------------------------" >> ${module_config} |
175 |
|
176 |
(( module_aliases-- )) |
177 |
for temp in $(seq 0 ${module_aliases}) |
178 |
do |
179 |
echo "alias $(eval echo \$\{MODULESD_${selectedmodule}_ALIASES[$temp]\})" >> ${module_config} |
180 |
done |
181 |
fi |
182 |
|
183 |
# and then stating any module parameters defined from the module |
184 |
if [ -n "${modinfop}" ]; |
185 |
then |
186 |
echo >> ${module_config} |
187 |
echo "# Configurable module parameters" >> ${module_config} |
188 |
echo "# ------------------------------" >> ${module_config} |
189 |
|
190 |
xifs="${IFS}" |
191 |
IFS="$(echo -en "\n\b")" |
192 |
for parameter in ${modinfop} |
193 |
do |
194 |
temp="$(echo ${parameter#*:} | grep -e " [0-9][ =]" | sed "s:.*\([01][= ]\).*:\1:")" |
195 |
if [ -n "${temp}" ]; |
196 |
then |
197 |
module_opts="${module_opts} ${parameter%%:*}:${temp}" |
198 |
fi |
199 |
echo -e "# ${parameter%%:*}:\t${parameter#*:}" >> ${module_config} |
200 |
done |
201 |
IFS="${xifs}" |
202 |
fi |
203 |
|
204 |
# and any examples we can gather from them |
205 |
if [ -n "${module_opts}" ]; |
206 |
then |
207 |
echo >> ${module_config} |
208 |
echo "# For Example..." >> ${module_config} |
209 |
echo "# ------------------------------" >> ${module_config} |
210 |
for parameter in ${module_opts} |
211 |
do |
212 |
echo "# options ${selectedmodule_full/*\//} ${parameter//:*}=${parameter//*:}" >> ${module_config} |
213 |
done |
214 |
fi |
215 |
|
216 |
# then we install it |
217 |
insinto /etc/modules.d |
218 |
newins ${module_config} ${selectedmodule_full/*\//} |
219 |
|
220 |
# and install any documentation we might have. |
221 |
[ -n "${module_docs}" ] && dodoc ${module_docs} |
222 |
done |
223 |
eend 0 |
224 |
} |
225 |
|
226 |
display_postinst() { |
227 |
# if we haven't determined the version yet, we need too. |
228 |
get_version; |
229 |
|
230 |
local modulename moduledir sourcedir moduletemp file i |
231 |
|
232 |
file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR} |
233 |
file=${file/\/\///} |
234 |
|
235 |
for i in ${MODULE_IGNORE} |
236 |
do |
237 |
MODULE_NAMES=${MODULE_NAMES//${i}(*} |
238 |
done |
239 |
|
240 |
if [[ -n ${MODULE_NAMES} ]] |
241 |
then |
242 |
einfo "If you would like to load this module automatically upon boot" |
243 |
einfo "please type the following as root:" |
244 |
for i in ${MODULE_NAMES} |
245 |
do |
246 |
unset libdir srcdir objdir |
247 |
for n in $(find_module_params ${i}) |
248 |
do |
249 |
eval ${n/:*}=${n/*:/} |
250 |
done |
251 |
einfo " # echo \"${modulename}\" >> ${file}" |
252 |
done |
253 |
einfo |
254 |
fi |
255 |
} |
256 |
|
257 |
find_module_params() { |
258 |
local matched_offset=0 matched_opts=0 test="${@}" temp_var result |
259 |
local i=0 y=0 z=0 |
260 |
|
261 |
for((i=0; i<=${#test}; i++)) |
262 |
do |
263 |
case ${test:${i}:1} in |
264 |
\() matched_offset[0]=${i};; |
265 |
\:) matched_opts=$((${matched_opts} + 1)); |
266 |
matched_offset[${matched_opts}]="${i}";; |
267 |
\)) matched_opts=$((${matched_opts} + 1)); |
268 |
matched_offset[${matched_opts}]="${i}";; |
269 |
esac |
270 |
done |
271 |
|
272 |
for((i=0; i<=${matched_opts}; i++)) |
273 |
do |
274 |
# i = offset were working on |
275 |
# y = last offset |
276 |
# z = current offset - last offset |
277 |
# temp_var = temporary name |
278 |
case ${i} in |
279 |
0) tempvar=${test:0:${matched_offset[0]}};; |
280 |
*) y=$((${matched_offset[$((${i} - 1))]} + 1)) |
281 |
z=$((${matched_offset[${i}]} - ${matched_offset[$((${i} - 1))]})); |
282 |
z=$((${z} - 1)) |
283 |
tempvar=${test:${y}:${z}};; |
284 |
esac |
285 |
|
286 |
case ${i} in |
287 |
0) result="${result} modulename:${tempvar}";; |
288 |
1) result="${result} libdir:${tempvar}";; |
289 |
2) result="${result} srcdir:${tempvar}";; |
290 |
3) result="${result} objdir:${tempvar}";; |
291 |
esac |
292 |
done |
293 |
|
294 |
echo ${result} |
295 |
} |
296 |
|
297 |
# default ebuild functions |
298 |
# -------------------------------- |
299 |
|
300 |
linux-mod_pkg_setup() { |
301 |
linux-info_pkg_setup; |
302 |
check_kernel_built; |
303 |
check_modules_supported; |
304 |
set_kvobj; |
305 |
} |
306 |
|
307 |
linux-mod_src_compile() { |
308 |
local modulename libdir srcdir objdir i n myARCH=${ARCH} |
309 |
unset ARCH |
310 |
|
311 |
BUILD_TARGETS=${BUILD_TARGETS:-clean module} |
312 |
|
313 |
for i in ${MODULE_IGNORE} |
314 |
do |
315 |
MODULE_NAMES=${MODULE_NAMES//${i}(*} |
316 |
done |
317 |
|
318 |
for i in ${MODULE_NAMES} |
319 |
do |
320 |
unset libdir srcdir objdir |
321 |
for n in $(find_module_params ${i}) |
322 |
do |
323 |
eval ${n/:*}=${n/*:/} |
324 |
done |
325 |
libdir=${libdir:-misc} |
326 |
srcdir=${srcdir:-${S}} |
327 |
objdir=${objdir:-${srcdir}} |
328 |
|
329 |
if [ ! -f "${srcdir}/.built" ]; |
330 |
then |
331 |
cd ${srcdir} |
332 |
einfo "Preparing ${modulename} module" |
333 |
if [[ -n ${ECONF_PARAMS} ]] |
334 |
then |
335 |
econf ${ECONF_PARAMS} || \ |
336 |
die "Unable to run econf ${ECONF_PARAMS}" |
337 |
fi |
338 |
|
339 |
emake ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS} \ |
340 |
|| die "Unable to make \ |
341 |
${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}." |
342 |
touch ${srcdir}/.built |
343 |
cd ${OLDPWD} |
344 |
fi |
345 |
done |
346 |
|
347 |
ARCH=${myARCH} |
348 |
} |
349 |
|
350 |
linux-mod_src_install() { |
351 |
local modulename libdir srcdir objdir i n |
352 |
|
353 |
for i in ${MODULE_IGNORE} |
354 |
do |
355 |
MODULE_NAMES=${MODULE_NAMES//${i}(*} |
356 |
done |
357 |
|
358 |
for i in ${MODULE_NAMES} |
359 |
do |
360 |
unset libdir srcdir objdir |
361 |
for n in $(find_module_params ${i}) |
362 |
do |
363 |
eval ${n/:*}=${n/*:/} |
364 |
done |
365 |
libdir=${libdir:-misc} |
366 |
srcdir=${srcdir:-${S}} |
367 |
objdir=${objdir:-${srcdir}} |
368 |
|
369 |
einfo "Installing ${modulename} module" |
370 |
cd ${objdir} |
371 |
|
372 |
insinto /lib/modules/${KV_FULL}/${libdir} |
373 |
doins ${modulename}.${KV_OBJ} |
374 |
cd ${OLDPWD} |
375 |
|
376 |
[ -z "${NO_MODULESD}" ] && generate_modulesd ${objdir}/${modulename} |
377 |
done |
378 |
} |
379 |
|
380 |
linux-mod_pkg_postinst() { |
381 |
update_depmod; |
382 |
update_modules; |
383 |
display_postinst; |
384 |
} |