/[gentoo-x86]/eclass/linux-mod.eclass
Gentoo

Contents of /eclass/linux-mod.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.85 - (show annotations) (download)
Fri Oct 31 21:25:56 2008 UTC (6 years, 1 month ago) by dsd
Branch: MAIN
Changes since 1.84: +15 -1 lines
add some documentation, patch from Eric Brown in bug #190934

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.84 2008/10/27 05:22:13 vapier 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 # Author(s): John Mylchreest <johnm@gentoo.org>,
11 # Stefan Schweizer <genstef@gentoo.org>
12 # Maintainer: kernel-misc@gentoo.org
13 #
14 # Please direct your bugs to the current eclass maintainer :)
15
16 # A Couple of env vars are available to effect usage of this eclass
17 # These are as follows:
18 #
19 # Env Var Option Default Description
20 # KERNEL_DIR <string> /usr/src/linux The directory containing kernel
21 # the target kernel sources.
22 # ECONF_PARAMS <string> The parameters to pass to econf.
23 # If this is not set, then econf
24 # isn't run.
25 # BUILD_PARAMS <string> The parameters to pass to emake.
26 # BUILD_TARGETS <string> clean modules The build targets to pass to
27 # make.
28 # MODULE_NAMES <string> This is the modules which are
29 # to be built automatically using
30 # the default pkg_compile/install.
31 # They are explained properly
32 # below. It will only make
33 # BUILD_TARGETS once in any
34 # directory.
35
36 # MODULE_NAMES - Detailed Overview
37 #
38 # The structure of each MODULE_NAMES entry is as follows:
39 # modulename(libdir:srcdir:objdir)
40 #
41 # modulename = name of the module file excluding the .ko
42 # libdir = place in system modules directory where module is installed:
43 # srcdir = place for ebuild to cd to before running make
44 # objdir = place the .ko and objects are located after make runs
45 #
46 # To get an idea of how these variables are used, here's a few lines
47 # of code from around line 540 in this eclass:
48 #
49 # einfo "Installing ${modulename} module"
50 # cd ${objdir} || die "${objdir} does not exist"
51 # insinto /lib/modules/${KV_FULL}/${libdir}
52 # doins ${modulename}.${KV_OBJ} || die "doins ${modulename}.${KV_OBJ} failed"
53 #
54 # for example:
55 # MODULE_NAMES="module_pci(pci:${S}/pci:${S}) module_usb(usb:${S}/usb:${S})"
56 #
57 # what this would do is
58 # cd ${S}/pci
59 # make ${BUILD_PARAMS} ${BUILD_TARGETS}
60 # cd ${S}
61 # insinto /lib/modules/${KV_FULL}/pci
62 # doins module_pci.${KV_OBJ}
63 #
64 # cd ${S}/usb
65 # make ${BUILD_PARAMS} ${BUILD_TARGETS}
66 # cd ${S}
67 # insinto /lib/modules/${KV_FULL}/usb
68 # doins module_usb.${KV_OBJ}
69 #
70 # if the srcdir isnt specified, it assumes ${S}
71 # if the libdir isnt specified, it assumes misc.
72 # if the objdir isnt specified, it assumes srcdir
73
74 # There is also support for automated modprobe.d/modules.d(2.4) file generation.
75 # This can be explicitly enabled by setting any of the following variables.
76 #
77 #
78 # MODULESD_${modulename}_ENABLED This enables the modules.d file
79 # generation even if we dont
80 # specify any additional info.
81 # MODULESD_${modulename}_EXAMPLES This is a bash array containing
82 # a list of examples which should
83 # be used. If you want us to try and
84 # take a guess. Set this to "guess"
85 # MODULESD_${modulename}_ALIASES This is a bash array containing
86 # a list of associated aliases.
87 # MODULESD_${modulename}_ADDITIONS This is a bash array containing
88 # A list of additional things to
89 # add to the bottom of the file.
90 # This can be absolutely anything.
91 # Each entry is a new line.
92 # MODULES_${modulename}_DOCS This is a string list which contains
93 # the full path to any associated
94 # documents for $modulename
95
96 # The order of these is important as both of linux-info and eutils contain
97 # set_arch_to_kernel and set_arch_to_portage functions and the ones in eutils
98 # are deprecated in favor of the ones in linux-info.
99 # See http://bugs.gentoo.org/show_bug.cgi?id=127506
100
101 inherit eutils linux-info multilib
102 EXPORT_FUNCTIONS pkg_setup pkg_preinst pkg_postinst src_install src_compile pkg_postrm
103
104 IUSE="kernel_linux"
105 SLOT="0"
106 DESCRIPTION="Based on the $ECLASS eclass"
107 RDEPEND="kernel_linux? ( virtual/modutils )"
108 DEPEND="${RDEPEND}
109 sys-apps/sed"
110
111 # eclass utilities
112 # ----------------------------------
113
114 check_vermagic() {
115 debug-print-function ${FUNCNAME} $*
116
117 local curr_gcc_ver=$(gcc -dumpversion)
118 local tmpfile old_chost old_gcc_ver result=0
119
120 tmpfile=`find ${KV_DIR}/ -iname "*.o.cmd" -exec grep usr/lib/gcc {} \; -quit`
121 tmpfile=${tmpfile//*usr/lib}
122 tmpfile=${tmpfile//\/include*}
123 old_chost=${tmpfile//*gcc\/}
124 old_chost=${old_chost//\/*}
125 old_gcc_ver=${tmpfile//*\/}
126
127 if [[ -z ${old_gcc_ver} || -z ${old_chost} ]]; then
128 ewarn ""
129 ewarn "Unable to detect what version of GCC was used to compile"
130 ewarn "the kernel. Build will continue, but you may experience problems."
131 elif [[ ${curr_gcc_ver} != ${old_gcc_ver} ]]; then
132 ewarn ""
133 ewarn "The version of GCC you are using (${curr_gcc_ver}) does"
134 ewarn "not match the version of GCC used to compile the"
135 ewarn "kernel (${old_gcc_ver})."
136 result=1
137 elif [[ ${CHOST} != ${old_chost} ]]; then
138 ewarn ""
139 ewarn "The current CHOST (${CHOST}) does not match the chost"
140 ewarn "used when compiling the kernel (${old_chost})."
141 result=1
142 fi
143
144 if [[ ${result} -gt 0 ]]; then
145 ewarn ""
146 ewarn "Build will not continue, because you will experience problems."
147 ewarn "To fix this either change the version of GCC you wish to use"
148 ewarn "to match the kernel, or recompile the kernel first."
149 die "GCC Version Mismatch."
150 fi
151 }
152
153 use_m() {
154 debug-print-function ${FUNCNAME} $*
155
156 # if we haven't determined the version yet, we need too.
157 get_version;
158
159 # if the kernel version is greater than 2.6.6 then we should use
160 # M= instead of SUBDIRS=
161 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \
162 return 0 || return 1
163 }
164
165 convert_to_m() {
166 debug-print-function ${FUNCNAME} $*
167
168 if use_m
169 then
170 [ ! -f "${1}" ] && \
171 die "convert_to_m() requires a filename as an argument"
172 ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIRS="
173 sed -i 's:SUBDIRS=:M=:g' ${1}
174 eend $?
175 fi
176 }
177
178 update_depmod() {
179 debug-print-function ${FUNCNAME} $*
180
181 # if we haven't determined the version yet, we need too.
182 get_version;
183
184 ebegin "Updating module dependencies for ${KV_FULL}"
185 if [ -r ${KV_OUT_DIR}/System.map ]
186 then
187 depmod -ae -F ${KV_OUT_DIR}/System.map -b ${ROOT} -r ${KV_FULL}
188 eend $?
189 else
190 ewarn
191 ewarn "${KV_OUT_DIR}/System.map not found."
192 ewarn "You must manually update the kernel module dependencies using depmod."
193 eend 1
194 ewarn
195 fi
196 }
197
198 update_modules() {
199 debug-print-function ${FUNCNAME} $*
200
201 if [ -x /sbin/update-modules ] && \
202 grep -v -e "^#" -e "^$" ${D}/etc/modules.d/* >/dev/null 2>&1; then
203 ebegin "Updating modules.conf"
204 /sbin/update-modules
205 eend $?
206 elif [ -x /sbin/update-modules ] && \
207 grep -v -e "^#" -e "^$" ${D}/etc/modules.d/* >/dev/null 2>&1; then
208 ebegin "Updating modules.conf"
209 /sbin/update-modules
210 eend $?
211 fi
212 }
213
214 move_old_moduledb() {
215 debug-print-function ${FUNCNAME} $*
216
217 local OLDDIR=${ROOT}/usr/share/module-rebuild/
218 local NEWDIR=${ROOT}/var/lib/module-rebuild/
219
220 if [[ -f ${OLDDIR}/moduledb ]]; then
221 [[ ! -d ${NEWDIR} ]] && mkdir -p ${NEWDIR}
222 [[ ! -f ${NEWDIR}/moduledb ]] && \
223 mv ${OLDDIR}/moduledb ${NEWDIR}/moduledb
224 rm -f ${OLDDIR}/*
225 rmdir ${OLDDIR}
226 fi
227 }
228
229 update_moduledb() {
230 debug-print-function ${FUNCNAME} $*
231
232 local MODULEDB_DIR=${ROOT}/var/lib/module-rebuild/
233 move_old_moduledb
234
235 if [[ ! -f ${MODULEDB_DIR}/moduledb ]]; then
236 [[ ! -d ${MODULEDB_DIR} ]] && mkdir -p ${MODULEDB_DIR}
237 touch ${MODULEDB_DIR}/moduledb
238 fi
239
240 if ! grep -qs ${CATEGORY}/${PN}-${PVR} ${MODULEDB_DIR}/moduledb ; then
241 einfo "Adding module to moduledb."
242 echo "a:1:${CATEGORY}/${PN}-${PVR}" >> ${MODULEDB_DIR}/moduledb
243 fi
244 }
245
246 remove_moduledb() {
247 debug-print-function ${FUNCNAME} $*
248
249 local MODULEDB_DIR=${ROOT}/var/lib/module-rebuild/
250 move_old_moduledb
251
252 if grep -qs ${CATEGORY}/${PN}-${PVR} ${MODULEDB_DIR}/moduledb ; then
253 einfo "Removing ${CATEGORY}/${PN}-${PVR} from moduledb."
254 sed -i -e "/.*${CATEGORY}\/${PN}-${PVR}.*/d" ${MODULEDB_DIR}/moduledb
255 fi
256 }
257
258 set_kvobj() {
259 debug-print-function ${FUNCNAME} $*
260
261 if kernel_is 2 6
262 then
263 KV_OBJ="ko"
264 else
265 KV_OBJ="o"
266 fi
267 # Do we really need to know this?
268 # Lets silence it.
269 # einfo "Using KV_OBJ=${KV_OBJ}"
270 }
271
272 get-KERNEL_CC() {
273 debug-print-function ${FUNCNAME} $*
274
275 if [[ -n ${KERNEL_CC} ]] ; then
276 echo "${KERNEL_CC}"
277 return
278 fi
279
280 local kernel_cc
281 if [ -n "${KERNEL_ABI}" ]; then
282 # In future, an arch might want to define CC_$ABI
283 #kernel_cc="$(get_abi_CC)"
284 #[ -z "${kernel_cc}" ] &&
285 kernel_cc="$(tc-getCC $(ABI=${KERNEL_ABI} get_abi_CHOST))"
286 else
287 kernel_cc=$(tc-getCC)
288 fi
289 echo "${kernel_cc}"
290 }
291
292 generate_modulesd() {
293 debug-print-function ${FUNCNAME} $*
294
295 # This function will generate the neccessary modules.d file from the
296 # information contained in the modules exported parms
297
298 local currm_path currm currm_t t myIFS myVAR
299 local module_docs module_enabled module_aliases \
300 module_additions module_examples module_modinfo module_opts
301
302 for currm_path in ${@}
303 do
304 currm=${currm_path//*\/}
305 currm=$(echo ${currm} | tr '[:lower:]' '[:upper:]')
306 currm_t=${currm}
307 while [[ -z ${currm_t//*-*} ]]; do
308 currm_t=${currm_t/-/_}
309 done
310
311 module_docs="$(eval echo \${MODULESD_${currm_t}_DOCS})"
312 module_enabled="$(eval echo \${MODULESD_${currm_t}_ENABLED})"
313 module_aliases="$(eval echo \${#MODULESD_${currm_t}_ALIASES[*]})"
314 module_additions="$(eval echo \${#MODULESD_${currm_t}_ADDITIONS[*]})"
315 module_examples="$(eval echo \${#MODULESD_${currm_t}_EXAMPLES[*]})"
316
317 [[ ${module_aliases} -eq 0 ]] && unset module_aliases
318 [[ ${module_additions} -eq 0 ]] && unset module_additions
319 [[ ${module_examples} -eq 0 ]] && unset module_examples
320
321 # If we specify we dont want it, then lets exit, otherwise we assume
322 # that if its set, we do want it.
323 [[ ${module_enabled} == no ]] && return 0
324
325 # unset any unwanted variables.
326 for t in ${!module_*}
327 do
328 [[ -z ${!t} ]] && unset ${t}
329 done
330
331 [[ -z ${!module_*} ]] && return 0
332
333 # OK so now if we have got this far, then we know we want to continue
334 # and generate the modules.d file.
335 module_modinfo="$(modinfo -p ${currm_path}.${KV_OBJ})"
336 module_config="${T}/modulesd-${currm}"
337
338 ebegin "Preparing file for modules.d"
339 #-----------------------------------------------------------------------
340 echo "# modules.d configuration file for ${currm}" >> ${module_config}
341 #-----------------------------------------------------------------------
342 [[ -n ${module_docs} ]] && \
343 echo "# For more information please read:" >> ${module_config}
344 for t in ${module_docs}
345 do
346 echo "# ${t//*\/}" >> ${module_config}
347 done
348 echo >> ${module_config}
349
350 #-----------------------------------------------------------------------
351 if [[ ${module_aliases} -gt 0 ]]
352 then
353 echo "# Internal Aliases - Do not edit" >> ${module_config}
354 echo "# ------------------------------" >> ${module_config}
355
356 for((t=0; t<${module_aliases}; t++))
357 do
358 echo "alias $(eval echo \${MODULESD_${currm}_ALIASES[$t]})" \
359 >> ${module_config}
360 done
361 echo '' >> ${module_config}
362 fi
363
364 #-----------------------------------------------------------------------
365 if [[ -n ${module_modinfo} ]]
366 then
367 echo >> ${module_config}
368 echo "# Configurable module parameters" >> ${module_config}
369 echo "# ------------------------------" >> ${module_config}
370 myIFS="${IFS}"
371 IFS="$(echo -en "\n\b")"
372
373 for t in ${module_modinfo}
374 do
375 myVAR="$(echo ${t#*:} | grep -e " [0-9][ =]" | sed "s:.*\([01][= ]\).*:\1:")"
376 if [[ -n ${myVAR} ]]
377 then
378 module_opts="${module_opts} ${t%%:*}:${myVAR}"
379 fi
380 echo -e "# ${t%%:*}:\t${t#*:}" >> ${module_config}
381 done
382 IFS="${myIFS}"
383 echo '' >> ${module_config}
384 fi
385
386 #-----------------------------------------------------------------------
387 if [[ $(eval echo \${MODULESD_${currm}_ALIASES[0]}) == guess ]]
388 then
389 # So lets do some guesswork eh?
390 if [[ -n ${module_opts} ]]
391 then
392 echo "# For Example..." >> ${module_config}
393 echo "# --------------" >> ${module_config}
394 for t in ${module_opts}
395 do
396 echo "# options ${currm} ${t//:*}=${t//*:}" >> ${module_config}
397 done
398 echo '' >> ${module_config}
399 fi
400 elif [[ ${module_examples} -gt 0 ]]
401 then
402 echo "# For Example..." >> ${module_config}
403 echo "# --------------" >> ${module_config}
404 for((t=0; t<${module_examples}; t++))
405 do
406 echo "options $(eval echo \${MODULESD_${currm}_EXAMPLES[$t]})" \
407 >> ${module_config}
408 done
409 echo '' >> ${module_config}
410 fi
411
412 #-----------------------------------------------------------------------
413 if [[ ${module_additions} -gt 0 ]]
414 then
415 for((t=0; t<${module_additions}; t++))
416 do
417 echo "$(eval echo \${MODULESD_${currm}_ADDITIONS[$t]})" \
418 >> ${module_config}
419 done
420 echo '' >> ${module_config}
421 fi
422
423 #-----------------------------------------------------------------------
424
425 # then we install it
426 if kernel_is ge 2 6; then
427 insinto /etc/modprobe.d
428 else
429 insinto /etc/modules.d
430 fi
431 newins ${module_config} ${currm_path//*\/}
432
433 # and install any documentation we might have.
434 [[ -n ${module_docs} ]] && dodoc ${module_docs}
435 done
436 eend 0
437 return 0
438 }
439
440 find_module_params() {
441 debug-print-function ${FUNCNAME} $*
442
443 local matched_offset=0 matched_opts=0 test="${@}" temp_var result
444 local i=0 y=0 z=0
445
446 for((i=0; i<=${#test}; i++))
447 do
448 case ${test:${i}:1} in
449 \() matched_offset[0]=${i};;
450 \:) matched_opts=$((${matched_opts} + 1));
451 matched_offset[${matched_opts}]="${i}";;
452 \)) matched_opts=$((${matched_opts} + 1));
453 matched_offset[${matched_opts}]="${i}";;
454 esac
455 done
456
457 for((i=0; i<=${matched_opts}; i++))
458 do
459 # i = offset were working on
460 # y = last offset
461 # z = current offset - last offset
462 # temp_var = temporary name
463 case ${i} in
464 0) tempvar=${test:0:${matched_offset[0]}};;
465 *) y=$((${matched_offset[$((${i} - 1))]} + 1))
466 z=$((${matched_offset[${i}]} - ${matched_offset[$((${i} - 1))]}));
467 z=$((${z} - 1))
468 tempvar=${test:${y}:${z}};;
469 esac
470
471 case ${i} in
472 0) result="${result} modulename:${tempvar}";;
473 1) result="${result} libdir:${tempvar}";;
474 2) result="${result} srcdir:${tempvar}";;
475 3) result="${result} objdir:${tempvar}";;
476 esac
477 done
478
479 echo ${result}
480 }
481
482 # default ebuild functions
483 # --------------------------------
484
485 linux-mod_pkg_setup() {
486 debug-print-function ${FUNCNAME} $*
487
488 linux-info_pkg_setup;
489 require_configured_kernel
490 check_kernel_built;
491 strip_modulenames;
492 [[ -n ${MODULE_NAMES} ]] && check_modules_supported
493 set_kvobj;
494 # Commented out with permission from johnm until a fixed version for arches
495 # who intentionally use different kernel and userland compilers can be
496 # introduced - Jason Wever <weeve@gentoo.org>, 23 Oct 2005
497 #check_vermagic;
498 }
499
500 strip_modulenames() {
501 debug-print-function ${FUNCNAME} $*
502
503 local i
504 for i in ${MODULE_IGNORE}; do
505 MODULE_NAMES=${MODULE_NAMES//${i}(*}
506 done
507 }
508
509 linux-mod_src_compile() {
510 debug-print-function ${FUNCNAME} $*
511
512 local modulename libdir srcdir objdir i n myABI="${ABI}"
513 set_arch_to_kernel
514 ABI="${KERNEL_ABI}"
515
516 BUILD_TARGETS=${BUILD_TARGETS:-clean module}
517 strip_modulenames;
518 cd "${S}"
519 for i in ${MODULE_NAMES}
520 do
521 unset libdir srcdir objdir
522 for n in $(find_module_params ${i})
523 do
524 eval ${n/:*}=${n/*:/}
525 done
526 libdir=${libdir:-misc}
527 srcdir=${srcdir:-${S}}
528 objdir=${objdir:-${srcdir}}
529
530 if [ ! -f "${srcdir}/.built" ];
531 then
532 cd ${srcdir}
533 einfo "Preparing ${modulename} module"
534 if [[ -n ${ECONF_PARAMS} ]]
535 then
536 econf ${ECONF_PARAMS} || \
537 die "Unable to run econf ${ECONF_PARAMS}"
538 fi
539
540 # This looks messy, but it is needed to handle multiple variables
541 # being passed in the BUILD_* stuff where the variables also have
542 # spaces that must be preserved. If don't do this, then the stuff
543 # inside the variables gets used as targets for Make, which then
544 # fails.
545 eval "emake HOSTCC=\"$(tc-getBUILD_CC)\" \
546 CROSS_COMPILE=${CHOST}- \
547 LDFLAGS=\"$(get_abi_LDFLAGS)\" \
548 ${BUILD_FIXES} \
549 ${BUILD_PARAMS} \
550 ${BUILD_TARGETS} " \
551 || die "Unable to emake HOSTCC="$(tc-getBUILD_CC)" CROSS_COMPILE=${CHOST}- LDFLAGS="$(get_abi_LDFLAGS)" ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}"
552 touch ${srcdir}/.built
553 cd ${OLDPWD}
554 fi
555 done
556
557 set_arch_to_portage
558 ABI="${myABI}"
559 }
560
561 linux-mod_src_install() {
562 debug-print-function ${FUNCNAME} $*
563
564 local modulename libdir srcdir objdir i n
565
566 strip_modulenames;
567 for i in ${MODULE_NAMES}
568 do
569 unset libdir srcdir objdir
570 for n in $(find_module_params ${i})
571 do
572 eval ${n/:*}=${n/*:/}
573 done
574 libdir=${libdir:-misc}
575 srcdir=${srcdir:-${S}}
576 objdir=${objdir:-${srcdir}}
577
578 einfo "Installing ${modulename} module"
579 cd ${objdir} || die "${objdir} does not exist"
580 insinto /lib/modules/${KV_FULL}/${libdir}
581 doins ${modulename}.${KV_OBJ} || die "doins ${modulename}.${KV_OBJ} failed"
582 cd ${OLDPWD}
583
584 generate_modulesd ${objdir}/${modulename}
585 done
586 }
587
588 linux-mod_pkg_preinst() {
589 debug-print-function ${FUNCNAME} $*
590
591 [ -d "${D}lib/modules" ] && UPDATE_DEPMOD=true || UPDATE_DEPMOD=false
592 [ -d "${D}etc/modules.d" ] && UPDATE_MODULES=true || UPDATE_MODULES=false
593 [ -d "${D}lib/modules" ] && UPDATE_MODULEDB=true || UPDATE_MODULEDB=false
594 }
595
596 linux-mod_pkg_postinst() {
597 debug-print-function ${FUNCNAME} $*
598
599 ${UPDATE_DEPMOD} && update_depmod;
600 ${UPDATE_MODULES} && update_modules;
601 ${UPDATE_MODULEDB} && update_moduledb;
602 }
603
604 linux-mod_pkg_postrm() {
605 debug-print-function ${FUNCNAME} $*
606 remove_moduledb;
607 }

  ViewVC Help
Powered by ViewVC 1.1.20