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.45 2005/07/06 20:53:20 agriffis 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 |
23 |
# isn't run. |
24 |
# BUILD_PARAMS <string> The parameters to pass to emake. |
25 |
# BUILD_TARGETS <string> clean modules The build targets to pass to |
26 |
# make. |
27 |
# MODULE_NAMES <string> This is the modules which are |
28 |
# to be built automatically using |
29 |
# the default pkg_compile/install. |
30 |
# They are explained properly |
31 |
# below. It will only make |
32 |
# BUILD_TARGETS once in any |
33 |
# directory. |
34 |
|
35 |
# MODULE_NAMES - Detailed Overview |
36 |
# |
37 |
# The structure of each MODULE_NAMES entry is as follows: |
38 |
# modulename(libdir:srcdir:objdir) |
39 |
# for example: |
40 |
# MODULE_NAMES="module_pci(pci:${S}/pci:${S}) module_usb(usb:${S}/usb:${S})" |
41 |
# |
42 |
# what this would do is |
43 |
# cd ${S}/pci |
44 |
# make ${BUILD_PARAMS} ${BUILD_TARGETS} |
45 |
# cd ${S} |
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 |
# cd ${S} |
52 |
# insinto /lib/modules/${KV_FULL}/usb |
53 |
# doins module_usb.${KV_OBJ} |
54 |
# |
55 |
# if the srcdir isnt specified, it assumes ${S} |
56 |
# if the libdir isnt specified, it assumes misc. |
57 |
# if the objdir isnt specified, it assumes srcdir |
58 |
|
59 |
# There is also support for automatyed modules.d file generation. |
60 |
# This can be explicitly enabled by setting any of the following variables. |
61 |
# |
62 |
# |
63 |
# MODULESD_${modulename}_ENABLED This enables the modules.d file |
64 |
# generation even if we dont |
65 |
# specify any additional info. |
66 |
# MODULESD_${modulename}_EXAMPLES This is a bash array containing |
67 |
# a list of examples which should |
68 |
# be used. If you want us to try and |
69 |
# take a guess. Set this to "guess" |
70 |
# MODULESD_${modulename}_ALIASES This is a bash array containing |
71 |
# a list of associated aliases. |
72 |
# MODULESD_${modulename}_ADDITIONS This is a bash array containing |
73 |
# A list of additional things to |
74 |
# add to the bottom of the file. |
75 |
# This can be absolutely anything. |
76 |
# Each entry is a new line. |
77 |
# MODULES_${modulename}_DOCS This is a string list which contains |
78 |
# the full path to any associated |
79 |
# documents for $modulename |
80 |
|
81 |
|
82 |
inherit linux-info |
83 |
EXPORT_FUNCTIONS pkg_setup pkg_postinst src_install src_compile pkg_postrm |
84 |
|
85 |
IUSE="${IUSE} pcmcia" |
86 |
SLOT="0" |
87 |
DESCRIPTION="Based on the $ECLASS eclass" |
88 |
RDEPEND="virtual/modutils |
89 |
pcmcia? ( virtual/pcmcia )" |
90 |
DEPEND="${RDEPEND} |
91 |
virtual/linux-sources |
92 |
sys-apps/sed" |
93 |
|
94 |
# eclass utilities |
95 |
# ---------------------------------- |
96 |
|
97 |
unpack_pcmcia_sources() { |
98 |
# So while the two eclasses exist side-by-side and also the ebuilds inherit |
99 |
# both we need to check for PCMCIA_SOURCE_DIR, and if we find it, then we |
100 |
# bail out and assume pcmcia.eclass is working on it. |
101 |
[[ -n ${PCMCIA_SOURCE_DIR} ]] && return 1 |
102 |
|
103 |
if [[ -f "${1}" ]]; then |
104 |
PCMCIA_SOURCE_DIR="${WORKDIR}/pcmcia-cs/" |
105 |
|
106 |
ebegin "Decompressing pcmcia-cs sources" |
107 |
mkdir -p ${PCMCIA_SOURCE_DIR} |
108 |
tar -xjf ${1} -C ${PCMCIA_SOURCE_DIR} |
109 |
eend $? |
110 |
|
111 |
if [[ -f ${PCMCIA_SOURCE_DIR}/pcmcia-cs-version ]]; then |
112 |
PCMCIA_VERSION=$(cat ${PCMCIA_SOURCE_DIR}/pcmcia-cs-version) |
113 |
einfo "Found pcmcia-cs-${PCMCIA_VERSION}" |
114 |
fi |
115 |
fi |
116 |
} |
117 |
|
118 |
# Dummy function for compatibility. |
119 |
pcmcia_configure() { return 0; } |
120 |
|
121 |
pcmcia_src_unpack() { |
122 |
local pcmcia_tbz="${ROOT}/usr/src/pcmcia-cs/pcmcia-cs-build-env.tbz2" |
123 |
|
124 |
# if the kernel has pcmcia support built in, then we just ignore all this. |
125 |
if linux_chkconfig_present PCMCIA; then |
126 |
einfo "Kernel based PCMCIA support has been detected." |
127 |
else |
128 |
if kernel_is 2 4; then |
129 |
unpack_pcmcia_sources ${pcmcia_tbz}; |
130 |
else |
131 |
einfo "We have detected that you are running a 2.6 kernel" |
132 |
einfo "but you are not using the built-in PCMCIA support." |
133 |
einfo "We will assume you know what you are doing, but please" |
134 |
einfo "consider using the built in PCMCIA support instead." |
135 |
sleep 10 |
136 |
|
137 |
unpack_pcmcia_sources ${pcmcia_tbz}; |
138 |
fi |
139 |
fi |
140 |
} |
141 |
|
142 |
use_m() { |
143 |
# if we haven't determined the version yet, we need too. |
144 |
get_version; |
145 |
|
146 |
# if the kernel version is greater than 2.6.6 then we should use |
147 |
# M= instead of SUBDIRS= |
148 |
[ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \ |
149 |
return 0 || return 1 |
150 |
} |
151 |
|
152 |
convert_to_m() { |
153 |
if use_m |
154 |
then |
155 |
[ ! -f "${1}" ] && \ |
156 |
die "convert_to_m() requires a filename as an argument" |
157 |
ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIRS=" |
158 |
sed -i 's:SUBDIRS=:M=:g' ${1} |
159 |
eend $? |
160 |
fi |
161 |
} |
162 |
|
163 |
update_depmod() { |
164 |
# if we haven't determined the version yet, we need too. |
165 |
get_version; |
166 |
|
167 |
ebegin "Updating module dependencies for ${KV_FULL}" |
168 |
if [ -r ${KV_OUT_DIR}/System.map ] |
169 |
then |
170 |
depmod -ae -F ${KV_OUT_DIR}/System.map -b ${ROOT} -r ${KV_FULL} |
171 |
eend $? |
172 |
else |
173 |
ewarn |
174 |
ewarn "${KV_OUT_DIR}/System.map not found." |
175 |
ewarn "You must manually update the kernel module dependencies using depmod." |
176 |
eend 1 |
177 |
ewarn |
178 |
fi |
179 |
} |
180 |
|
181 |
update_modules() { |
182 |
if [ -x /sbin/modules-update ] && \ |
183 |
grep -v -e "^#" -e "^$" ${D}/etc/modules.d/* >/dev/null 2>&1; then |
184 |
ebegin "Updating modules.conf" |
185 |
/sbin/modules-update |
186 |
eend $? |
187 |
fi |
188 |
} |
189 |
|
190 |
move_old_moduledb() { |
191 |
local OLDDIR=${ROOT}/usr/share/module-rebuild/ |
192 |
local NEWDIR=${ROOT}/var/lib/module-rebuild/ |
193 |
|
194 |
if [[ -f ${OLDDIR}/moduledb ]]; then |
195 |
[[ ! -d ${NEWDIR} ]] && mkdir -p ${NEWDIR} |
196 |
[[ ! -f ${NEWDIR}/moduledb ]] && \ |
197 |
mv ${OLDDIR}/moduledb ${NEWDIR}/moduledb |
198 |
rm -f ${OLDDIR}/* |
199 |
rmdir ${OLDDIR} |
200 |
fi |
201 |
} |
202 |
|
203 |
update_moduledb() { |
204 |
local MODULEDB_DIR=${ROOT}/var/lib/module-rebuild/ |
205 |
move_old_moduledb |
206 |
|
207 |
if [[ ! -f ${MODULEDB_DIR}/moduledb ]]; then |
208 |
[[ ! -d ${MODULEDB_DIR} ]] && mkdir -p ${MODULEDB_DIR} |
209 |
touch ${MODULEDB_DIR}/moduledb |
210 |
fi |
211 |
if [[ -z $(grep ${CATEGORY}/${PN}-${PVR} ${MODULEDB_DIR}/moduledb) ]]; then |
212 |
einfo "Adding module to moduledb." |
213 |
echo "a:1:${CATEGORY}/${PN}-${PVR}" >> ${MODULEDB_DIR}/moduledb |
214 |
fi |
215 |
} |
216 |
|
217 |
remove_moduledb() { |
218 |
local MODULEDB_DIR=${ROOT}/var/lib/module-rebuild/ |
219 |
move_old_moduledb |
220 |
|
221 |
if [[ -n $(grep ${CATEGORY}/${PN}-${PVR} ${MODULEDB_DIR}/moduledb) ]]; then |
222 |
einfo "Removing ${CATEGORY}/${PN}-${PVR} from moduledb." |
223 |
sed -ie "/.*${CATEGORY}\/${P}.*/d" ${MODULEDB_DIR}/moduledb |
224 |
fi |
225 |
} |
226 |
|
227 |
set_kvobj() { |
228 |
if kernel_is 2 6 |
229 |
then |
230 |
KV_OBJ="ko" |
231 |
else |
232 |
KV_OBJ="o" |
233 |
fi |
234 |
# Do we really need to know this? |
235 |
# Lets silence it. |
236 |
# einfo "Using KV_OBJ=${KV_OBJ}" |
237 |
} |
238 |
|
239 |
generate_modulesd() { |
240 |
# This function will generate the neccessary modules.d file from the |
241 |
# information contained in the modules exported parms |
242 |
|
243 |
local currm_path currm t myIFS myVAR |
244 |
local module_docs module_enabled module_aliases \ |
245 |
module_additions module_examples module_modinfo module_opts |
246 |
|
247 |
for currm_path in ${@} |
248 |
do |
249 |
currm=${currm_path//*\/} |
250 |
currm=$(echo ${currm} | tr '[:lower:]' '[:upper:]') |
251 |
|
252 |
module_docs="$(eval echo \${MODULESD_${currm}_DOCS})" |
253 |
module_enabled="$(eval echo \${MODULESD_${currm}_ENABLED})" |
254 |
module_aliases="$(eval echo \${#MODULESD_${currm/-/_}_ALIASES[*]})" |
255 |
module_additions="$(eval echo \${#MODULESD_${currm/-/_}_ADDITIONS[*]})" |
256 |
module_examples="$(eval echo \${#MODULESD_${currm/-/_}_EXAMPLES[*]})" |
257 |
|
258 |
[[ ${module_aliases} -eq 0 ]] && unset module_aliases |
259 |
[[ ${module_additions} -eq 0 ]] && unset module_additions |
260 |
[[ ${module_examples} -eq 0 ]] && unset module_examples |
261 |
|
262 |
# If we specify we dont want it, then lets exit, otherwise we assume |
263 |
# that if its set, we do want it. |
264 |
[[ ${module_enabled} == no ]] && return 0 |
265 |
|
266 |
# unset any unwanted variables. |
267 |
for t in ${!module_*} |
268 |
do |
269 |
[[ -z ${!t} ]] && unset ${t} |
270 |
done |
271 |
|
272 |
[[ -z ${!module_*} ]] && return 0 |
273 |
|
274 |
# OK so now if we have got this far, then we know we want to continue |
275 |
# and generate the modules.d file. |
276 |
module_modinfo="$(modinfo -p ${currm_path}.${KV_OBJ})" |
277 |
module_config="${T}/modulesd-${currm}" |
278 |
|
279 |
ebegin "Preparing file for modules.d" |
280 |
#----------------------------------------------------------------------- |
281 |
echo "# modules.d configuration file for ${currm}" >> ${module_config} |
282 |
#----------------------------------------------------------------------- |
283 |
[[ -n ${module_docs} ]] && \ |
284 |
echo "# For more information please read:" >> ${module_config} |
285 |
for t in ${module_docs} |
286 |
do |
287 |
echo "# ${t//*\/}" >> ${module_config} |
288 |
done |
289 |
echo >> ${module_config} |
290 |
|
291 |
#----------------------------------------------------------------------- |
292 |
if [[ ${module_aliases} -gt 0 ]] |
293 |
then |
294 |
echo "# Internal Aliases - Do not edit" >> ${module_config} |
295 |
echo "# ------------------------------" >> ${module_config} |
296 |
|
297 |
for((t=0; t<${module_aliases}; t++)) |
298 |
do |
299 |
echo "alias $(eval echo \${MODULESD_${currm}_ALIASES[$t]})" \ |
300 |
>> ${module_config} |
301 |
done |
302 |
echo '' >> ${module_config} |
303 |
fi |
304 |
|
305 |
#----------------------------------------------------------------------- |
306 |
if [[ -n ${module_modinfo} ]] |
307 |
then |
308 |
echo >> ${module_config} |
309 |
echo "# Configurable module parameters" >> ${module_config} |
310 |
echo "# ------------------------------" >> ${module_config} |
311 |
myIFS="${IFS}" |
312 |
IFS="$(echo -en "\n\b")" |
313 |
|
314 |
for t in ${module_modinfo} |
315 |
do |
316 |
myVAR="$(echo ${t#*:} | grep -e " [0-9][ =]" | sed "s:.*\([01][= ]\).*:\1:")" |
317 |
if [[ -n ${myVAR} ]] |
318 |
then |
319 |
module_opts="${module_opts} ${t%%:*}:${myVAR}" |
320 |
fi |
321 |
echo -e "# ${t%%:*}:\t${t#*:}" >> ${module_config} |
322 |
done |
323 |
IFS="${myIFS}" |
324 |
echo '' >> ${module_config} |
325 |
fi |
326 |
|
327 |
#----------------------------------------------------------------------- |
328 |
if [[ $(eval echo \${MODULESD_${currm}_ALIASES[0]}) == guess ]] |
329 |
then |
330 |
# So lets do some guesswork eh? |
331 |
if [[ -n ${module_opts} ]] |
332 |
then |
333 |
echo "# For Example..." >> ${module_config} |
334 |
echo "# --------------" >> ${module_config} |
335 |
for t in ${module_opts} |
336 |
do |
337 |
echo "# options ${currm} ${t//:*}=${t//*:}" >> ${module_config} |
338 |
done |
339 |
echo '' >> ${module_config} |
340 |
fi |
341 |
elif [[ ${module_examples} -gt 0 ]] |
342 |
then |
343 |
echo "# For Example..." >> ${module_config} |
344 |
echo "# --------------" >> ${module_config} |
345 |
for((t=0; t<${module_examples}; t++)) |
346 |
do |
347 |
echo "options $(eval echo \${MODULESD_${currm}_EXAMPLES[$t]})" \ |
348 |
>> ${module_config} |
349 |
done |
350 |
echo '' >> ${module_config} |
351 |
fi |
352 |
|
353 |
#----------------------------------------------------------------------- |
354 |
if [[ ${module_additions} -gt 0 ]] |
355 |
then |
356 |
for((t=0; t<${module_additions}; t++)) |
357 |
do |
358 |
echo "$(eval echo \${MODULESD_${currm}_ADDITIONS[$t]})" \ |
359 |
>> ${module_config} |
360 |
done |
361 |
echo '' >> ${module_config} |
362 |
fi |
363 |
|
364 |
#----------------------------------------------------------------------- |
365 |
|
366 |
# then we install it |
367 |
insinto /etc/modules.d |
368 |
newins ${module_config} ${currm_path//*\/} |
369 |
|
370 |
# and install any documentation we might have. |
371 |
[[ -n ${module_docs} ]] && dodoc ${module_docs} |
372 |
done |
373 |
eend 0 |
374 |
return 0 |
375 |
} |
376 |
|
377 |
display_postinst() { |
378 |
# if we haven't determined the version yet, we need too. |
379 |
get_version; |
380 |
|
381 |
local modulename moduledir sourcedir moduletemp file i |
382 |
|
383 |
file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR} |
384 |
file=${file/\/\///} |
385 |
|
386 |
for i in ${MODULE_IGNORE} |
387 |
do |
388 |
MODULE_NAMES=${MODULE_NAMES//${i}(*} |
389 |
done |
390 |
|
391 |
if [[ -n ${MODULE_NAMES} ]] |
392 |
then |
393 |
einfo "If you would like to load this module automatically upon boot" |
394 |
einfo "please type the following as root:" |
395 |
for i in ${MODULE_NAMES} |
396 |
do |
397 |
unset libdir srcdir objdir |
398 |
for n in $(find_module_params ${i}) |
399 |
do |
400 |
eval ${n/:*}=${n/*:/} |
401 |
done |
402 |
einfo " # echo \"${modulename}\" >> ${file}" |
403 |
done |
404 |
einfo |
405 |
fi |
406 |
} |
407 |
|
408 |
find_module_params() { |
409 |
local matched_offset=0 matched_opts=0 test="${@}" temp_var result |
410 |
local i=0 y=0 z=0 |
411 |
|
412 |
for((i=0; i<=${#test}; i++)) |
413 |
do |
414 |
case ${test:${i}:1} in |
415 |
\() matched_offset[0]=${i};; |
416 |
\:) matched_opts=$((${matched_opts} + 1)); |
417 |
matched_offset[${matched_opts}]="${i}";; |
418 |
\)) matched_opts=$((${matched_opts} + 1)); |
419 |
matched_offset[${matched_opts}]="${i}";; |
420 |
esac |
421 |
done |
422 |
|
423 |
for((i=0; i<=${matched_opts}; i++)) |
424 |
do |
425 |
# i = offset were working on |
426 |
# y = last offset |
427 |
# z = current offset - last offset |
428 |
# temp_var = temporary name |
429 |
case ${i} in |
430 |
0) tempvar=${test:0:${matched_offset[0]}};; |
431 |
*) y=$((${matched_offset[$((${i} - 1))]} + 1)) |
432 |
z=$((${matched_offset[${i}]} - ${matched_offset[$((${i} - 1))]})); |
433 |
z=$((${z} - 1)) |
434 |
tempvar=${test:${y}:${z}};; |
435 |
esac |
436 |
|
437 |
case ${i} in |
438 |
0) result="${result} modulename:${tempvar}";; |
439 |
1) result="${result} libdir:${tempvar}";; |
440 |
2) result="${result} srcdir:${tempvar}";; |
441 |
3) result="${result} objdir:${tempvar}";; |
442 |
esac |
443 |
done |
444 |
|
445 |
echo ${result} |
446 |
} |
447 |
|
448 |
# default ebuild functions |
449 |
# -------------------------------- |
450 |
|
451 |
linux-mod_pkg_setup() { |
452 |
linux-info_pkg_setup; |
453 |
check_kernel_built; |
454 |
check_modules_supported; |
455 |
set_kvobj; |
456 |
} |
457 |
|
458 |
linux-mod_src_compile() { |
459 |
local modulename libdir srcdir objdir i n myARCH="${ARCH}" |
460 |
unset ARCH |
461 |
|
462 |
BUILD_TARGETS=${BUILD_TARGETS:-clean module} |
463 |
|
464 |
for i in ${MODULE_IGNORE} |
465 |
do |
466 |
MODULE_NAMES=${MODULE_NAMES//${i}(*} |
467 |
done |
468 |
|
469 |
for i in ${MODULE_NAMES} |
470 |
do |
471 |
unset libdir srcdir objdir |
472 |
for n in $(find_module_params ${i}) |
473 |
do |
474 |
eval ${n/:*}=${n/*:/} |
475 |
done |
476 |
libdir=${libdir:-misc} |
477 |
srcdir=${srcdir:-${S}} |
478 |
objdir=${objdir:-${srcdir}} |
479 |
|
480 |
if [ ! -f "${srcdir}/.built" ]; |
481 |
then |
482 |
cd ${srcdir} |
483 |
einfo "Preparing ${modulename} module" |
484 |
if [[ -n ${ECONF_PARAMS} ]] |
485 |
then |
486 |
econf ${ECONF_PARAMS} || \ |
487 |
die "Unable to run econf ${ECONF_PARAMS}" |
488 |
fi |
489 |
|
490 |
emake ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS} \ |
491 |
|| die "Unable to make \ |
492 |
${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}." |
493 |
touch ${srcdir}/.built |
494 |
cd ${OLDPWD} |
495 |
fi |
496 |
done |
497 |
|
498 |
ARCH="${myARCH}" |
499 |
} |
500 |
|
501 |
linux-mod_src_install() { |
502 |
local modulename libdir srcdir objdir i n |
503 |
|
504 |
for i in ${MODULE_IGNORE} |
505 |
do |
506 |
MODULE_NAMES=${MODULE_NAMES//${i}(*} |
507 |
done |
508 |
|
509 |
for i in ${MODULE_NAMES} |
510 |
do |
511 |
unset libdir srcdir objdir |
512 |
for n in $(find_module_params ${i}) |
513 |
do |
514 |
eval ${n/:*}=${n/*:/} |
515 |
done |
516 |
libdir=${libdir:-misc} |
517 |
srcdir=${srcdir:-${S}} |
518 |
objdir=${objdir:-${srcdir}} |
519 |
|
520 |
einfo "Installing ${modulename} module" |
521 |
cd ${objdir} |
522 |
insinto ${ROOT}lib/modules/${KV_FULL}/${libdir} |
523 |
doins ${modulename}.${KV_OBJ} |
524 |
cd ${OLDPWD} |
525 |
|
526 |
generate_modulesd ${objdir}/${modulename} |
527 |
done |
528 |
} |
529 |
|
530 |
linux-mod_pkg_postinst() { |
531 |
update_depmod; |
532 |
update_modules; |
533 |
update_moduledb; |
534 |
display_postinst; |
535 |
} |
536 |
|
537 |
linux-mod_pkg_postrm() { |
538 |
remove_moduledb; |
539 |
} |