1 |
# Copyright 1999-2013 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.113 2013/08/24 11:07:23 ssuominen Exp $ |
4 |
|
5 |
# @ECLASS: linux-mod.eclass |
6 |
# @MAINTAINER: |
7 |
# kernel-misc@gentoo.org |
8 |
# @AUTHOR: |
9 |
# John Mylchreest <johnm@gentoo.org>, |
10 |
# Stefan Schweizer <genstef@gentoo.org> |
11 |
# @BLURB: It provides the functionality required to install external modules against a kernel source tree. |
12 |
# @DESCRIPTION: |
13 |
# This eclass is used to interface with linux-info.eclass in such a way |
14 |
# to provide the functionality and initial functions |
15 |
# required to install external modules against a kernel source |
16 |
# tree. |
17 |
|
18 |
# A Couple of env vars are available to effect usage of this eclass |
19 |
# These are as follows: |
20 |
|
21 |
# @ECLASS-VARIABLE: MODULES_OPTIONAL_USE |
22 |
# @DESCRIPTION: |
23 |
# A string containing the USE flag to use for making this eclass optional |
24 |
# The recommended non-empty value is 'modules' |
25 |
|
26 |
# @ECLASS-VARIABLE: KERNEL_DIR |
27 |
# @DESCRIPTION: |
28 |
# A string containing the directory of the target kernel sources. The default value is |
29 |
# "/usr/src/linux" |
30 |
|
31 |
# @ECLASS-VARIABLE: ECONF_PARAMS |
32 |
# @DESCRIPTION: |
33 |
# It's a string containing the parameters to pass to econf. |
34 |
# If this is not set, then econf isn't run. |
35 |
|
36 |
# @ECLASS-VARIABLE: BUILD_PARAMS |
37 |
# @DESCRIPTION: |
38 |
# It's a string with the parameters to pass to emake. |
39 |
|
40 |
# @ECLASS-VARIABLE: BUILD_TARGETS |
41 |
# @DESCRIPTION: |
42 |
# It's a string with the build targets to pass to make. The default value is "clean module" |
43 |
|
44 |
# @ECLASS-VARIABLE: MODULE_NAMES |
45 |
# @DESCRIPTION: |
46 |
# It's a string containing the modules to be built automatically using the default |
47 |
# src_compile/src_install. It will only make ${BUILD_TARGETS} once in any directory. |
48 |
# |
49 |
# The structure of each MODULE_NAMES entry is as follows: |
50 |
# |
51 |
# modulename(libdir:srcdir:objdir) |
52 |
# |
53 |
# where: |
54 |
# |
55 |
# modulename = name of the module file excluding the .ko |
56 |
# libdir = place in system modules directory where module is installed (by default it's misc) |
57 |
# srcdir = place for ebuild to cd to before running make (by default it's ${S}) |
58 |
# objdir = place the .ko and objects are located after make runs (by default it's set to srcdir) |
59 |
# |
60 |
# To get an idea of how these variables are used, here's a few lines |
61 |
# of code from around line 540 in this eclass: |
62 |
# |
63 |
# einfo "Installing ${modulename} module" |
64 |
# cd ${objdir} || die "${objdir} does not exist" |
65 |
# insinto /lib/modules/${KV_FULL}/${libdir} |
66 |
# doins ${modulename}.${KV_OBJ} || die "doins ${modulename}.${KV_OBJ} failed" |
67 |
# |
68 |
# For example: |
69 |
# MODULE_NAMES="module_pci(pci:${S}/pci:${S}) module_usb(usb:${S}/usb:${S})" |
70 |
# |
71 |
# what this would do is |
72 |
# |
73 |
# cd "${S}"/pci |
74 |
# make ${BUILD_PARAMS} ${BUILD_TARGETS} |
75 |
# cd "${S}" |
76 |
# insinto /lib/modules/${KV_FULL}/pci |
77 |
# doins module_pci.${KV_OBJ} |
78 |
# |
79 |
# cd "${S}"/usb |
80 |
# make ${BUILD_PARAMS} ${BUILD_TARGETS} |
81 |
# cd "${S}" |
82 |
# insinto /lib/modules/${KV_FULL}/usb |
83 |
# doins module_usb.${KV_OBJ} |
84 |
|
85 |
# There is also support for automated modprobe.d file generation. |
86 |
# This can be explicitly enabled by setting any of the following variables. |
87 |
|
88 |
# @ECLASS-VARIABLE: MODULESD_<modulename>_ENABLED |
89 |
# @DESCRIPTION: |
90 |
# This is used to disable the modprobe.d file generation otherwise the file will be |
91 |
# always generated (unless no MODULESD_<modulename>_* variable is provided). Set to "no" to disable |
92 |
# the generation of the file and the installation of the documentation. |
93 |
|
94 |
# @ECLASS-VARIABLE: MODULESD_<modulename>_EXAMPLES |
95 |
# @DESCRIPTION: |
96 |
# This is a bash array containing a list of examples which should |
97 |
# be used. If you want us to try and take a guess set this to "guess". |
98 |
# |
99 |
# For each array_component it's added an options line in the modprobe.d file |
100 |
# |
101 |
# options array_component |
102 |
# |
103 |
# where array_component is "<modulename> options" (see modprobe.conf(5)) |
104 |
|
105 |
# @ECLASS-VARIABLE: MODULESD_<modulename>_ALIASES |
106 |
# @DESCRIPTION: |
107 |
# This is a bash array containing a list of associated aliases. |
108 |
# |
109 |
# For each array_component it's added an alias line in the modprobe.d file |
110 |
# |
111 |
# alias array_component |
112 |
# |
113 |
# where array_component is "wildcard <modulename>" (see modprobe.conf(5)) |
114 |
|
115 |
# @ECLASS-VARIABLE: MODULESD_<modulename>_ADDITIONS |
116 |
# @DESCRIPTION: |
117 |
# This is a bash array containing a list of additional things to |
118 |
# add to the bottom of the file. This can be absolutely anything. |
119 |
# Each entry is a new line. |
120 |
|
121 |
# @ECLASS-VARIABLE: MODULESD_<modulename>_DOCS |
122 |
# @DESCRIPTION: |
123 |
# This is a string list which contains the full path to any associated |
124 |
# documents for <modulename>. These files are installed in the live tree. |
125 |
|
126 |
# @ECLASS-VARIABLE: KV_OBJ |
127 |
# @DESCRIPTION: |
128 |
# It's a read-only variable. It contains the extension of the kernel modules. |
129 |
|
130 |
inherit eutils linux-info multilib |
131 |
EXPORT_FUNCTIONS pkg_setup pkg_preinst pkg_postinst src_install src_compile pkg_postrm |
132 |
|
133 |
IUSE="kernel_linux" |
134 |
SLOT="0" |
135 |
RDEPEND="${MODULES_OPTIONAL_USE}${MODULES_OPTIONAL_USE:+? (} kernel_linux? ( virtual/modutils ) ${MODULES_OPTIONAL_USE:+)}" |
136 |
DEPEND="${RDEPEND} |
137 |
${MODULES_OPTIONAL_USE}${MODULES_OPTIONAL_USE:+? (} |
138 |
sys-apps/sed |
139 |
kernel_linux? ( virtual/linux-sources ) |
140 |
${MODULES_OPTIONAL_USE:+)}" |
141 |
|
142 |
# eclass utilities |
143 |
# ---------------------------------- |
144 |
|
145 |
check_vermagic() { |
146 |
debug-print-function ${FUNCNAME} $* |
147 |
|
148 |
local curr_gcc_ver=$(gcc -dumpversion) |
149 |
local tmpfile old_chost old_gcc_ver result=0 |
150 |
[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return |
151 |
|
152 |
tmpfile=`find "${KV_DIR}/" -iname "*.o.cmd" -exec grep usr/lib/gcc {} \; -quit` |
153 |
tmpfile=${tmpfile//*usr/lib} |
154 |
tmpfile=${tmpfile//\/include*} |
155 |
old_chost=${tmpfile//*gcc\/} |
156 |
old_chost=${old_chost//\/*} |
157 |
old_gcc_ver=${tmpfile//*\/} |
158 |
|
159 |
if [[ -z ${old_gcc_ver} || -z ${old_chost} ]]; then |
160 |
ewarn "" |
161 |
ewarn "Unable to detect what version of GCC was used to compile" |
162 |
ewarn "the kernel. Build will continue, but you may experience problems." |
163 |
elif [[ ${curr_gcc_ver} != ${old_gcc_ver} ]]; then |
164 |
ewarn "" |
165 |
ewarn "The version of GCC you are using (${curr_gcc_ver}) does" |
166 |
ewarn "not match the version of GCC used to compile the" |
167 |
ewarn "kernel (${old_gcc_ver})." |
168 |
result=1 |
169 |
elif [[ ${CHOST} != ${old_chost} ]]; then |
170 |
ewarn "" |
171 |
ewarn "The current CHOST (${CHOST}) does not match the chost" |
172 |
ewarn "used when compiling the kernel (${old_chost})." |
173 |
result=1 |
174 |
fi |
175 |
|
176 |
if [[ ${result} -gt 0 ]]; then |
177 |
ewarn "" |
178 |
ewarn "Build will not continue, because you will experience problems." |
179 |
ewarn "To fix this either change the version of GCC you wish to use" |
180 |
ewarn "to match the kernel, or recompile the kernel first." |
181 |
die "GCC Version Mismatch." |
182 |
fi |
183 |
} |
184 |
|
185 |
# @FUNCTION: use_m |
186 |
# @RETURN: true or false |
187 |
# @DESCRIPTION: |
188 |
# It checks if the kernel version is greater than 2.6.5. |
189 |
use_m() { |
190 |
debug-print-function ${FUNCNAME} $* |
191 |
|
192 |
# if we haven't determined the version yet, we need too. |
193 |
get_version; |
194 |
|
195 |
# if the kernel version is greater than 2.6.6 then we should use |
196 |
# M= instead of SUBDIRS= |
197 |
[ ${KV_MAJOR} -eq 3 ] && return 0 |
198 |
[ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \ |
199 |
return 0 || return 1 |
200 |
} |
201 |
|
202 |
# @FUNCTION: convert_to_m |
203 |
# @USAGE: /path/to/the/file |
204 |
# @DESCRIPTION: |
205 |
# It converts a file (e.g. a makefile) to use M= instead of SUBDIRS= |
206 |
convert_to_m() { |
207 |
debug-print-function ${FUNCNAME} $* |
208 |
|
209 |
if use_m |
210 |
then |
211 |
[ ! -f "${1}" ] && \ |
212 |
die "convert_to_m() requires a filename as an argument" |
213 |
ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIRS=" |
214 |
sed -i 's:SUBDIRS=:M=:g' "${1}" |
215 |
eend $? |
216 |
fi |
217 |
} |
218 |
|
219 |
# internal function |
220 |
# |
221 |
# FUNCTION: update_depmod |
222 |
# DESCRIPTION: |
223 |
# It updates the modules.dep file for the current kernel. |
224 |
update_depmod() { |
225 |
debug-print-function ${FUNCNAME} $* |
226 |
|
227 |
# if we haven't determined the version yet, we need too. |
228 |
get_version; |
229 |
|
230 |
ebegin "Updating module dependencies for ${KV_FULL}" |
231 |
if [ -r "${KV_OUT_DIR}"/System.map ] |
232 |
then |
233 |
depmod -ae -F "${KV_OUT_DIR}"/System.map -b "${ROOT}" ${KV_FULL} |
234 |
eend $? |
235 |
else |
236 |
ewarn |
237 |
ewarn "${KV_OUT_DIR}/System.map not found." |
238 |
ewarn "You must manually update the kernel module dependencies using depmod." |
239 |
eend 1 |
240 |
ewarn |
241 |
fi |
242 |
} |
243 |
|
244 |
# internal function |
245 |
# |
246 |
# FUNCTION: move_old_moduledb |
247 |
# DESCRIPTION: |
248 |
# It updates the location of the database used by the module-rebuild utility. |
249 |
move_old_moduledb() { |
250 |
debug-print-function ${FUNCNAME} $* |
251 |
|
252 |
local OLDDIR="${ROOT}"/usr/share/module-rebuild/ |
253 |
local NEWDIR="${ROOT}"/var/lib/module-rebuild/ |
254 |
|
255 |
if [[ -f "${OLDDIR}"/moduledb ]]; then |
256 |
[[ ! -d "${NEWDIR}" ]] && mkdir -p "${NEWDIR}" |
257 |
[[ ! -f "${NEWDIR}"/moduledb ]] && \ |
258 |
mv "${OLDDIR}"/moduledb "${NEWDIR}"/moduledb |
259 |
rm -f "${OLDDIR}"/* |
260 |
rmdir "${OLDDIR}" |
261 |
fi |
262 |
} |
263 |
|
264 |
# internal function |
265 |
# |
266 |
# FUNCTION: update_moduledb |
267 |
# DESCRIPTION: |
268 |
# It adds the package to the /var/lib/module-rebuild/moduledb database used by the module-rebuild utility. |
269 |
update_moduledb() { |
270 |
debug-print-function ${FUNCNAME} $* |
271 |
|
272 |
local MODULEDB_DIR="${ROOT}"/var/lib/module-rebuild/ |
273 |
move_old_moduledb |
274 |
|
275 |
if [[ ! -f "${MODULEDB_DIR}"/moduledb ]]; then |
276 |
[[ ! -d "${MODULEDB_DIR}" ]] && mkdir -p "${MODULEDB_DIR}" |
277 |
touch "${MODULEDB_DIR}"/moduledb |
278 |
fi |
279 |
|
280 |
if ! grep -qs ${CATEGORY}/${PN}-${PVR} "${MODULEDB_DIR}"/moduledb ; then |
281 |
einfo "Adding module to moduledb." |
282 |
echo "a:1:${CATEGORY}/${PN}-${PVR}" >> "${MODULEDB_DIR}"/moduledb |
283 |
fi |
284 |
} |
285 |
|
286 |
# internal function |
287 |
# |
288 |
# FUNCTION: remove_moduledb |
289 |
# DESCRIPTION: |
290 |
# It removes the package from the /var/lib/module-rebuild/moduledb database used by |
291 |
# the module-rebuild utility. |
292 |
remove_moduledb() { |
293 |
debug-print-function ${FUNCNAME} $* |
294 |
|
295 |
local MODULEDB_DIR="${ROOT}"/var/lib/module-rebuild/ |
296 |
move_old_moduledb |
297 |
|
298 |
if grep -qs ${CATEGORY}/${PN}-${PVR} "${MODULEDB_DIR}"/moduledb ; then |
299 |
einfo "Removing ${CATEGORY}/${PN}-${PVR} from moduledb." |
300 |
sed -i -e "/.*${CATEGORY}\/${PN}-${PVR}.*/d" "${MODULEDB_DIR}"/moduledb |
301 |
fi |
302 |
} |
303 |
|
304 |
# @FUNCTION: set_kvobj |
305 |
# @DESCRIPTION: |
306 |
# It sets the KV_OBJ variable. |
307 |
set_kvobj() { |
308 |
debug-print-function ${FUNCNAME} $* |
309 |
|
310 |
if kernel_is ge 2 6 |
311 |
then |
312 |
KV_OBJ="ko" |
313 |
else |
314 |
KV_OBJ="o" |
315 |
fi |
316 |
# Do we really need to know this? |
317 |
# Lets silence it. |
318 |
# einfo "Using KV_OBJ=${KV_OBJ}" |
319 |
} |
320 |
|
321 |
get-KERNEL_CC() { |
322 |
debug-print-function ${FUNCNAME} $* |
323 |
|
324 |
if [[ -n ${KERNEL_CC} ]] ; then |
325 |
echo "${KERNEL_CC}" |
326 |
return |
327 |
fi |
328 |
|
329 |
local kernel_cc |
330 |
if [ -n "${KERNEL_ABI}" ]; then |
331 |
# In future, an arch might want to define CC_$ABI |
332 |
#kernel_cc="$(get_abi_CC)" |
333 |
#[ -z "${kernel_cc}" ] && |
334 |
kernel_cc="$(tc-getCC $(ABI=${KERNEL_ABI} get_abi_CHOST))" |
335 |
else |
336 |
kernel_cc=$(tc-getCC) |
337 |
fi |
338 |
echo "${kernel_cc}" |
339 |
} |
340 |
|
341 |
# internal function |
342 |
# |
343 |
# FUNCTION: |
344 |
# USAGE: /path/to/the/modulename_without_extension |
345 |
# RETURN: A file in /etc/modprobe.d |
346 |
# DESCRIPTION: |
347 |
# This function will generate and install the neccessary modprobe.d file from the |
348 |
# information contained in the modules exported parms. |
349 |
# (see the variables MODULESD_<modulename>_ENABLED, MODULESD_<modulename>_EXAMPLES, |
350 |
# MODULESD_<modulename>_ALIASES, MODULESD_<modulename>_ADDITION and MODULESD_<modulename>_DOCS). |
351 |
# |
352 |
# At the end the documentation specified with MODULESD_<modulename>_DOCS is installed. |
353 |
generate_modulesd() { |
354 |
debug-print-function ${FUNCNAME} $* |
355 |
[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return |
356 |
|
357 |
local currm_path currm currm_t t myIFS myVAR |
358 |
local module_docs module_enabled module_aliases \ |
359 |
module_additions module_examples module_modinfo module_opts |
360 |
|
361 |
for currm_path in ${@} |
362 |
do |
363 |
currm=${currm_path//*\/} |
364 |
currm=$(echo ${currm} | tr '[:lower:]' '[:upper:]') |
365 |
currm_t=${currm} |
366 |
while [[ -z ${currm_t//*-*} ]]; do |
367 |
currm_t=${currm_t/-/_} |
368 |
done |
369 |
|
370 |
module_docs="$(eval echo \${MODULESD_${currm_t}_DOCS})" |
371 |
module_enabled="$(eval echo \${MODULESD_${currm_t}_ENABLED})" |
372 |
module_aliases="$(eval echo \${#MODULESD_${currm_t}_ALIASES[*]})" |
373 |
module_additions="$(eval echo \${#MODULESD_${currm_t}_ADDITIONS[*]})" |
374 |
module_examples="$(eval echo \${#MODULESD_${currm_t}_EXAMPLES[*]})" |
375 |
|
376 |
[[ ${module_aliases} -eq 0 ]] && unset module_aliases |
377 |
[[ ${module_additions} -eq 0 ]] && unset module_additions |
378 |
[[ ${module_examples} -eq 0 ]] && unset module_examples |
379 |
|
380 |
# If we specify we dont want it, then lets exit, otherwise we assume |
381 |
# that if its set, we do want it. |
382 |
[[ ${module_enabled} == no ]] && return 0 |
383 |
|
384 |
# unset any unwanted variables. |
385 |
for t in ${!module_*} |
386 |
do |
387 |
[[ -z ${!t} ]] && unset ${t} |
388 |
done |
389 |
|
390 |
[[ -z ${!module_*} ]] && return 0 |
391 |
|
392 |
# OK so now if we have got this far, then we know we want to continue |
393 |
# and generate the modprobe.d file. |
394 |
module_modinfo="$(modinfo -p ${currm_path}.${KV_OBJ})" |
395 |
module_config="${T}/modulesd-${currm}" |
396 |
|
397 |
ebegin "Preparing file for modprobe.d" |
398 |
#----------------------------------------------------------------------- |
399 |
echo "# modprobe.d configuration file for ${currm}" >> "${module_config}" |
400 |
#----------------------------------------------------------------------- |
401 |
[[ -n ${module_docs} ]] && \ |
402 |
echo "# For more information please read:" >> "${module_config}" |
403 |
for t in ${module_docs} |
404 |
do |
405 |
echo "# ${t//*\/}" >> "${module_config}" |
406 |
done |
407 |
echo >> "${module_config}" |
408 |
|
409 |
#----------------------------------------------------------------------- |
410 |
if [[ ${module_aliases} -gt 0 ]] |
411 |
then |
412 |
echo "# Internal Aliases - Do not edit" >> "${module_config}" |
413 |
echo "# ------------------------------" >> "${module_config}" |
414 |
|
415 |
for((t=0; t<${module_aliases}; t++)) |
416 |
do |
417 |
echo "alias $(eval echo \${MODULESD_${currm}_ALIASES[$t]})" \ |
418 |
>> "${module_config}" |
419 |
done |
420 |
echo '' >> "${module_config}" |
421 |
fi |
422 |
|
423 |
#----------------------------------------------------------------------- |
424 |
if [[ -n ${module_modinfo} ]] |
425 |
then |
426 |
echo >> "${module_config}" |
427 |
echo "# Configurable module parameters" >> "${module_config}" |
428 |
echo "# ------------------------------" >> "${module_config}" |
429 |
myIFS="${IFS}" |
430 |
IFS="$(echo -en "\n\b")" |
431 |
|
432 |
for t in ${module_modinfo} |
433 |
do |
434 |
myVAR="$(echo ${t#*:} | grep -e " [0-9][ =]" | sed "s:.*\([01][= ]\).*:\1:")" |
435 |
if [[ -n ${myVAR} ]] |
436 |
then |
437 |
module_opts="${module_opts} ${t%%:*}:${myVAR}" |
438 |
fi |
439 |
echo -e "# ${t%%:*}:\t${t#*:}" >> "${module_config}" |
440 |
done |
441 |
IFS="${myIFS}" |
442 |
echo '' >> "${module_config}" |
443 |
fi |
444 |
|
445 |
#----------------------------------------------------------------------- |
446 |
if [[ $(eval echo \${MODULESD_${currm}_ALIASES[0]}) == guess ]] |
447 |
then |
448 |
# So lets do some guesswork eh? |
449 |
if [[ -n ${module_opts} ]] |
450 |
then |
451 |
echo "# For Example..." >> "${module_config}" |
452 |
echo "# --------------" >> "${module_config}" |
453 |
for t in ${module_opts} |
454 |
do |
455 |
echo "# options ${currm} ${t//:*}=${t//*:}" >> "${module_config}" |
456 |
done |
457 |
echo '' >> "${module_config}" |
458 |
fi |
459 |
elif [[ ${module_examples} -gt 0 ]] |
460 |
then |
461 |
echo "# For Example..." >> "${module_config}" |
462 |
echo "# --------------" >> "${module_config}" |
463 |
for((t=0; t<${module_examples}; t++)) |
464 |
do |
465 |
echo "options $(eval echo \${MODULESD_${currm}_EXAMPLES[$t]})" \ |
466 |
>> "${module_config}" |
467 |
done |
468 |
echo '' >> "${module_config}" |
469 |
fi |
470 |
|
471 |
#----------------------------------------------------------------------- |
472 |
if [[ ${module_additions} -gt 0 ]] |
473 |
then |
474 |
for((t=0; t<${module_additions}; t++)) |
475 |
do |
476 |
echo "$(eval echo \${MODULESD_${currm}_ADDITIONS[$t]})" \ |
477 |
>> "${module_config}" |
478 |
done |
479 |
echo '' >> "${module_config}" |
480 |
fi |
481 |
|
482 |
#----------------------------------------------------------------------- |
483 |
|
484 |
# then we install it |
485 |
insinto /etc/modprobe.d |
486 |
newins "${module_config}" "${currm_path//*\/}.conf" |
487 |
|
488 |
# and install any documentation we might have. |
489 |
[[ -n ${module_docs} ]] && dodoc ${module_docs} |
490 |
done |
491 |
eend 0 |
492 |
return 0 |
493 |
} |
494 |
|
495 |
# internal function |
496 |
# |
497 |
# FUNCTION: find_module_params |
498 |
# USAGE: A string "NAME(LIBDIR:SRCDIR:OBJDIR)" |
499 |
# RETURN: The string "modulename:NAME libdir:LIBDIR srcdir:SRCDIR objdir:OBJDIR" |
500 |
# DESCRIPTION: |
501 |
# Analyze the specification NAME(LIBDIR:SRCDIR:OBJDIR) of one module as described in MODULE_NAMES. |
502 |
find_module_params() { |
503 |
debug-print-function ${FUNCNAME} $* |
504 |
|
505 |
local matched_offset=0 matched_opts=0 test="${@}" temp_var result |
506 |
local i=0 y=0 z=0 |
507 |
|
508 |
for((i=0; i<=${#test}; i++)) |
509 |
do |
510 |
case ${test:${i}:1} in |
511 |
\() matched_offset[0]=${i};; |
512 |
\:) matched_opts=$((${matched_opts} + 1)); |
513 |
matched_offset[${matched_opts}]="${i}";; |
514 |
\)) matched_opts=$((${matched_opts} + 1)); |
515 |
matched_offset[${matched_opts}]="${i}";; |
516 |
esac |
517 |
done |
518 |
|
519 |
for((i=0; i<=${matched_opts}; i++)) |
520 |
do |
521 |
# i = offset were working on |
522 |
# y = last offset |
523 |
# z = current offset - last offset |
524 |
# temp_var = temporary name |
525 |
case ${i} in |
526 |
0) tempvar=${test:0:${matched_offset[0]}};; |
527 |
*) y=$((${matched_offset[$((${i} - 1))]} + 1)) |
528 |
z=$((${matched_offset[${i}]} - ${matched_offset[$((${i} - 1))]})); |
529 |
z=$((${z} - 1)) |
530 |
tempvar=${test:${y}:${z}};; |
531 |
esac |
532 |
|
533 |
case ${i} in |
534 |
0) result="${result} modulename:${tempvar}";; |
535 |
1) result="${result} libdir:${tempvar}";; |
536 |
2) result="${result} srcdir:${tempvar}";; |
537 |
3) result="${result} objdir:${tempvar}";; |
538 |
esac |
539 |
done |
540 |
|
541 |
echo ${result} |
542 |
} |
543 |
|
544 |
# default ebuild functions |
545 |
# -------------------------------- |
546 |
|
547 |
# @FUNCTION: linux-mod_pkg_setup |
548 |
# @DESCRIPTION: |
549 |
# It checks the CONFIG_CHECK options (see linux-info.eclass(5)), verifies that the kernel is |
550 |
# configured, verifies that the sources are prepared, verifies that the modules support is builtin |
551 |
# in the kernel and sets the object extension KV_OBJ. |
552 |
linux-mod_pkg_setup() { |
553 |
debug-print-function ${FUNCNAME} $* |
554 |
[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return |
555 |
|
556 |
local is_bin="${MERGE_TYPE}" |
557 |
|
558 |
# If we are installing a binpkg, take a different path. |
559 |
# use MERGE_TYPE if available (eapi>=4); else use non-PMS EMERGE_FROM (eapi<4) |
560 |
if has ${EAPI} 0 1 2 3; then |
561 |
is_bin=${EMERGE_FROM} |
562 |
fi |
563 |
|
564 |
if [[ ${is_bin} == binary ]]; then |
565 |
linux-mod_pkg_setup_binary |
566 |
return |
567 |
fi |
568 |
|
569 |
linux-info_pkg_setup; |
570 |
require_configured_kernel |
571 |
check_kernel_built; |
572 |
strip_modulenames; |
573 |
[[ -n ${MODULE_NAMES} ]] && check_modules_supported |
574 |
set_kvobj; |
575 |
# Commented out with permission from johnm until a fixed version for arches |
576 |
# who intentionally use different kernel and userland compilers can be |
577 |
# introduced - Jason Wever <weeve@gentoo.org>, 23 Oct 2005 |
578 |
#check_vermagic; |
579 |
} |
580 |
|
581 |
# @FUNCTION: linux-mod_pkg_setup_binary |
582 |
# @DESCRIPTION: |
583 |
# Perform all kernel option checks non-fatally, as the .config and |
584 |
# /proc/config.gz might not be present. Do not do anything that requires kernel |
585 |
# sources. |
586 |
linux-mod_pkg_setup_binary() { |
587 |
debug-print-function ${FUNCNAME} $* |
588 |
local new_CONFIG_CHECK |
589 |
# ~ needs always to be quoted, else bash expands it. |
590 |
for config in $CONFIG_CHECK ; do |
591 |
optional='~' |
592 |
[[ ${config:0:1} == "~" ]] && optional='' |
593 |
new_CONFIG_CHECK="${new_CONFIG_CHECK} ${optional}${config}" |
594 |
done |
595 |
export CONFIG_CHECK="${new_CONFIG_CHECK}" |
596 |
linux-info_pkg_setup; |
597 |
} |
598 |
|
599 |
strip_modulenames() { |
600 |
debug-print-function ${FUNCNAME} $* |
601 |
|
602 |
local i |
603 |
for i in ${MODULE_IGNORE}; do |
604 |
MODULE_NAMES=${MODULE_NAMES//${i}(*} |
605 |
done |
606 |
} |
607 |
|
608 |
# @FUNCTION: linux-mod_src_compile |
609 |
# @DESCRIPTION: |
610 |
# It compiles all the modules specified in MODULE_NAMES. For each module the econf command is |
611 |
# executed only if ECONF_PARAMS is defined, the name of the target is specified by BUILD_TARGETS |
612 |
# while the options are in BUILD_PARAMS (all the modules share these variables). The compilation |
613 |
# happens inside ${srcdir}. |
614 |
# |
615 |
# Look at the description of these variables for more details. |
616 |
linux-mod_src_compile() { |
617 |
debug-print-function ${FUNCNAME} $* |
618 |
[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return |
619 |
|
620 |
local modulename libdir srcdir objdir i n myABI="${ABI}" |
621 |
set_arch_to_kernel |
622 |
ABI="${KERNEL_ABI}" |
623 |
|
624 |
BUILD_TARGETS=${BUILD_TARGETS:-clean module} |
625 |
strip_modulenames; |
626 |
cd "${S}" |
627 |
touch Module.symvers |
628 |
for i in ${MODULE_NAMES} |
629 |
do |
630 |
unset libdir srcdir objdir |
631 |
for n in $(find_module_params ${i}) |
632 |
do |
633 |
eval ${n/:*}=${n/*:/} |
634 |
done |
635 |
libdir=${libdir:-misc} |
636 |
srcdir=${srcdir:-${S}} |
637 |
objdir=${objdir:-${srcdir}} |
638 |
|
639 |
if [ ! -f "${srcdir}/.built" ]; |
640 |
then |
641 |
cd "${srcdir}" |
642 |
ln -s "${S}"/Module.symvers Module.symvers |
643 |
einfo "Preparing ${modulename} module" |
644 |
if [[ -n ${ECONF_PARAMS} ]] |
645 |
then |
646 |
econf ${ECONF_PARAMS} || \ |
647 |
die "Unable to run econf ${ECONF_PARAMS}" |
648 |
fi |
649 |
|
650 |
# This looks messy, but it is needed to handle multiple variables |
651 |
# being passed in the BUILD_* stuff where the variables also have |
652 |
# spaces that must be preserved. If don't do this, then the stuff |
653 |
# inside the variables gets used as targets for Make, which then |
654 |
# fails. |
655 |
eval "emake HOSTCC=\"$(tc-getBUILD_CC)\" \ |
656 |
CROSS_COMPILE=${CHOST}- \ |
657 |
LDFLAGS=\"$(get_abi_LDFLAGS)\" \ |
658 |
${BUILD_FIXES} \ |
659 |
${BUILD_PARAMS} \ |
660 |
${BUILD_TARGETS} " \ |
661 |
|| die "Unable to emake HOSTCC="$(tc-getBUILD_CC)" CROSS_COMPILE=${CHOST}- LDFLAGS="$(get_abi_LDFLAGS)" ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}" |
662 |
cd "${OLDPWD}" |
663 |
touch "${srcdir}"/.built |
664 |
fi |
665 |
done |
666 |
|
667 |
set_arch_to_portage |
668 |
ABI="${myABI}" |
669 |
} |
670 |
|
671 |
# @FUNCTION: linux-mod_src_install |
672 |
# @DESCRIPTION: |
673 |
# It install the modules specified in MODULES_NAME. The modules should be inside the ${objdir} |
674 |
# directory and they are installed inside /lib/modules/${KV_FULL}/${libdir}. |
675 |
# |
676 |
# The modprobe.d configuration file is automatically generated if the |
677 |
# MODULESD_<modulename>_* variables are defined. The only way to stop this process is by |
678 |
# setting MODULESD_<modulename>_ENABLED=no. At the end the documentation specified via |
679 |
# MODULESD_<modulename>_DOCS is also installed. |
680 |
# |
681 |
# Look at the description of these variables for more details. |
682 |
linux-mod_src_install() { |
683 |
debug-print-function ${FUNCNAME} $* |
684 |
[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return |
685 |
|
686 |
local modulename libdir srcdir objdir i n |
687 |
|
688 |
strip_modulenames; |
689 |
for i in ${MODULE_NAMES} |
690 |
do |
691 |
unset libdir srcdir objdir |
692 |
for n in $(find_module_params ${i}) |
693 |
do |
694 |
eval ${n/:*}=${n/*:/} |
695 |
done |
696 |
libdir=${libdir:-misc} |
697 |
srcdir=${srcdir:-${S}} |
698 |
objdir=${objdir:-${srcdir}} |
699 |
|
700 |
einfo "Installing ${modulename} module" |
701 |
cd "${objdir}" || die "${objdir} does not exist" |
702 |
insinto /lib/modules/${KV_FULL}/${libdir} |
703 |
doins ${modulename}.${KV_OBJ} || die "doins ${modulename}.${KV_OBJ} failed" |
704 |
cd "${OLDPWD}" |
705 |
|
706 |
generate_modulesd "${objdir}/${modulename}" |
707 |
done |
708 |
} |
709 |
|
710 |
# @FUNCTION: linux-mod_pkg_preinst |
711 |
# @DESCRIPTION: |
712 |
# It checks what to do after having merged the package. |
713 |
linux-mod_pkg_preinst() { |
714 |
debug-print-function ${FUNCNAME} $* |
715 |
[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return |
716 |
|
717 |
[ -d "${D}lib/modules" ] && UPDATE_DEPMOD=true || UPDATE_DEPMOD=false |
718 |
[ -d "${D}lib/modules" ] && UPDATE_MODULEDB=true || UPDATE_MODULEDB=false |
719 |
} |
720 |
|
721 |
# @FUNCTION: linux-mod_pkg_postinst |
722 |
# @DESCRIPTION: |
723 |
# It executes /sbin/depmod and adds the package to the /var/lib/module-rebuild/moduledb |
724 |
# database (if ${D}/lib/modules is created)" |
725 |
linux-mod_pkg_postinst() { |
726 |
debug-print-function ${FUNCNAME} $* |
727 |
[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return |
728 |
|
729 |
${UPDATE_DEPMOD} && update_depmod; |
730 |
${UPDATE_MODULEDB} && update_moduledb; |
731 |
} |
732 |
|
733 |
# @FUNCTION: linux-mod_pkg_postrm |
734 |
# @DESCRIPTION: |
735 |
# It removes the package from the /var/lib/module-rebuild/moduledb database but it doens't |
736 |
# call /sbin/depmod because the modules are still installed. |
737 |
linux-mod_pkg_postrm() { |
738 |
debug-print-function ${FUNCNAME} $* |
739 |
[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return |
740 |
remove_moduledb; |
741 |
} |