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

Contents of /eclass/linux-mod.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.115 - (hide annotations) (download)
Sun Dec 1 19:11:24 2013 UTC (12 months, 2 weeks ago) by robbat2
Branch: MAIN
Changes since 1.114: +2 -2 lines
Always ensure MODULES_OPTIONAL_USE is in IUSE.

1 robbat2 1.114 # Copyright 1999-2013 Gentoo Foundation
2 johnm 1.1 # Distributed under the terms of the GNU General Public License v2
3 robbat2 1.115 # $Header: /var/cvsroot/gentoo-x86/eclass/linux-mod.eclass,v 1.114 2013/12/01 19:06:19 robbat2 Exp $
4 johnm 1.10
5 dsd 1.86 # @ECLASS: linux-mod.eclass
6     # @MAINTAINER:
7     # kernel-misc@gentoo.org
8 vapier 1.104 # @AUTHOR:
9     # John Mylchreest <johnm@gentoo.org>,
10     # Stefan Schweizer <genstef@gentoo.org>
11 dsd 1.86 # @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 johnm 1.10 # A Couple of env vars are available to effect usage of this eclass
19     # These are as follows:
20    
21 robbat2 1.114 # @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 dsd 1.86 # @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 mpagano 1.107 # It's a string with the build targets to pass to make. The default value is "clean module"
43 dsd 1.86
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 swegener 1.49 #
49 johnm 1.10 # The structure of each MODULE_NAMES entry is as follows:
50 dsd 1.85 #
51 dsd 1.86 # modulename(libdir:srcdir:objdir)
52     #
53     # where:
54     #
55     # modulename = name of the module file excluding the .ko
56 dsd 1.91 # 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 dsd 1.85 #
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 ulm 1.100 #
63 dsd 1.85 # 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 dsd 1.86 # For example:
69     # MODULE_NAMES="module_pci(pci:${S}/pci:${S}) module_usb(usb:${S}/usb:${S})"
70 swegener 1.49 #
71 johnm 1.10 # what this would do is
72 dsd 1.86 #
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 johnm 1.26
85 ssuominen 1.109 # There is also support for automated modprobe.d file generation.
86 johnm 1.26 # This can be explicitly enabled by setting any of the following variables.
87 dsd 1.86
88     # @ECLASS-VARIABLE: MODULESD_<modulename>_ENABLED
89     # @DESCRIPTION:
90 ssuominen 1.109 # This is used to disable the modprobe.d file generation otherwise the file will be
91 dsd 1.86 # 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 ssuominen 1.109 # For each array_component it's added an options line in the modprobe.d file
100 dsd 1.86 #
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 ssuominen 1.109 # For each array_component it's added an alias line in the modprobe.d file
110 johnm 1.26 #
111 dsd 1.86 # alias array_component
112 johnm 1.26 #
113 dsd 1.86 # 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 johnm 1.26
130 blubb 1.62 inherit eutils linux-info multilib
131 genstef 1.65 EXPORT_FUNCTIONS pkg_setup pkg_preinst pkg_postinst src_install src_compile pkg_postrm
132 johnm 1.1
133 robbat2 1.115 IUSE="kernel_linux ${MODULES_OPTIONAL_USE}"
134 johnm 1.26 SLOT="0"
135 robbat2 1.114 RDEPEND="${MODULES_OPTIONAL_USE}${MODULES_OPTIONAL_USE:+? (} kernel_linux? ( virtual/modutils ) ${MODULES_OPTIONAL_USE:+)}"
136 ssuominen 1.113 DEPEND="${RDEPEND}
137 robbat2 1.114 ${MODULES_OPTIONAL_USE}${MODULES_OPTIONAL_USE:+? (}
138 ssuominen 1.113 sys-apps/sed
139 robbat2 1.114 kernel_linux? ( virtual/linux-sources )
140     ${MODULES_OPTIONAL_USE:+)}"
141 johnm 1.26
142 johnm 1.1 # eclass utilities
143     # ----------------------------------
144    
145 johnm 1.53 check_vermagic() {
146 genstef 1.69 debug-print-function ${FUNCNAME} $*
147    
148 johnm 1.53 local curr_gcc_ver=$(gcc -dumpversion)
149     local tmpfile old_chost old_gcc_ver result=0
150 robbat2 1.114 [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
151 johnm 1.53
152 robbat2 1.96 tmpfile=`find "${KV_DIR}/" -iname "*.o.cmd" -exec grep usr/lib/gcc {} \; -quit`
153 johnm 1.53 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 johnm 1.54 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 johnm 1.53 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 dsd 1.86 # @FUNCTION: use_m
186     # @RETURN: true or false
187     # @DESCRIPTION:
188     # It checks if the kernel version is greater than 2.6.5.
189 johnm 1.1 use_m() {
190 genstef 1.69 debug-print-function ${FUNCNAME} $*
191    
192 johnm 1.1 # if we haven't determined the version yet, we need too.
193     get_version;
194 swegener 1.49
195 johnm 1.1 # if the kernel version is greater than 2.6.6 then we should use
196 johnm 1.8 # M= instead of SUBDIRS=
197 robbat2 1.102 [ ${KV_MAJOR} -eq 3 ] && return 0
198 johnm 1.1 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \
199     return 0 || return 1
200     }
201    
202 dsd 1.86 # @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 johnm 1.1 convert_to_m() {
207 genstef 1.69 debug-print-function ${FUNCNAME} $*
208    
209 johnm 1.1 if use_m
210     then
211 johnm 1.32 [ ! -f "${1}" ] && \
212     die "convert_to_m() requires a filename as an argument"
213 johnm 1.8 ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIRS="
214 robbat2 1.96 sed -i 's:SUBDIRS=:M=:g' "${1}"
215 johnm 1.1 eend $?
216     fi
217     }
218    
219 dsd 1.86 # internal function
220     #
221     # FUNCTION: update_depmod
222     # DESCRIPTION:
223     # It updates the modules.dep file for the current kernel.
224 johnm 1.1 update_depmod() {
225 genstef 1.69 debug-print-function ${FUNCNAME} $*
226    
227 johnm 1.1 # if we haven't determined the version yet, we need too.
228     get_version;
229 swegener 1.49
230 johnm 1.1 ebegin "Updating module dependencies for ${KV_FULL}"
231 robbat2 1.96 if [ -r "${KV_OUT_DIR}"/System.map ]
232 johnm 1.1 then
233 mpagano 1.106 depmod -ae -F "${KV_OUT_DIR}"/System.map -b "${ROOT}" ${KV_FULL}
234 johnm 1.18 eend $?
235 johnm 1.1 else
236     ewarn
237 johnm 1.5 ewarn "${KV_OUT_DIR}/System.map not found."
238 johnm 1.1 ewarn "You must manually update the kernel module dependencies using depmod."
239 johnm 1.18 eend 1
240 johnm 1.1 ewarn
241     fi
242     }
243    
244 dsd 1.86 # 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 johnm 1.41 move_old_moduledb() {
250 genstef 1.69 debug-print-function ${FUNCNAME} $*
251    
252 robbat2 1.96 local OLDDIR="${ROOT}"/usr/share/module-rebuild/
253     local NEWDIR="${ROOT}"/var/lib/module-rebuild/
254 swegener 1.49
255 robbat2 1.96 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 johnm 1.41 fi
262     }
263    
264 dsd 1.86 # 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 johnm 1.37 update_moduledb() {
270 genstef 1.69 debug-print-function ${FUNCNAME} $*
271    
272 robbat2 1.96 local MODULEDB_DIR="${ROOT}"/var/lib/module-rebuild/
273 johnm 1.41 move_old_moduledb
274 johnm 1.40
275 robbat2 1.96 if [[ ! -f "${MODULEDB_DIR}"/moduledb ]]; then
276     [[ ! -d "${MODULEDB_DIR}" ]] && mkdir -p "${MODULEDB_DIR}"
277     touch "${MODULEDB_DIR}"/moduledb
278 johnm 1.37 fi
279 vapier 1.72
280 robbat2 1.96 if ! grep -qs ${CATEGORY}/${PN}-${PVR} "${MODULEDB_DIR}"/moduledb ; then
281 johnm 1.37 einfo "Adding module to moduledb."
282 robbat2 1.96 echo "a:1:${CATEGORY}/${PN}-${PVR}" >> "${MODULEDB_DIR}"/moduledb
283 swegener 1.49 fi
284 johnm 1.37 }
285    
286 dsd 1.86 # 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 johnm 1.37 remove_moduledb() {
293 genstef 1.69 debug-print-function ${FUNCNAME} $*
294    
295 robbat2 1.96 local MODULEDB_DIR="${ROOT}"/var/lib/module-rebuild/
296 johnm 1.41 move_old_moduledb
297 johnm 1.40
298 robbat2 1.96 if grep -qs ${CATEGORY}/${PN}-${PVR} "${MODULEDB_DIR}"/moduledb ; then
299 johnm 1.37 einfo "Removing ${CATEGORY}/${PN}-${PVR} from moduledb."
300 robbat2 1.96 sed -i -e "/.*${CATEGORY}\/${PN}-${PVR}.*/d" "${MODULEDB_DIR}"/moduledb
301 johnm 1.37 fi
302     }
303    
304 dsd 1.86 # @FUNCTION: set_kvobj
305     # @DESCRIPTION:
306     # It sets the KV_OBJ variable.
307 johnm 1.1 set_kvobj() {
308 genstef 1.69 debug-print-function ${FUNCNAME} $*
309    
310 robbat2 1.102 if kernel_is ge 2 6
311 johnm 1.1 then
312     KV_OBJ="ko"
313     else
314     KV_OBJ="o"
315     fi
316 johnm 1.26 # Do we really need to know this?
317     # Lets silence it.
318     # einfo "Using KV_OBJ=${KV_OBJ}"
319 johnm 1.1 }
320    
321 genstef 1.68 get-KERNEL_CC() {
322 genstef 1.69 debug-print-function ${FUNCNAME} $*
323    
324 vapier 1.82 if [[ -n ${KERNEL_CC} ]] ; then
325     echo "${KERNEL_CC}"
326     return
327     fi
328    
329 genstef 1.68 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 swegener 1.70 #[ -z "${kernel_cc}" ] &&
334 genstef 1.68 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 dsd 1.86 # internal function
342     #
343     # FUNCTION:
344     # USAGE: /path/to/the/modulename_without_extension
345 ssuominen 1.109 # RETURN: A file in /etc/modprobe.d
346 dsd 1.86 # DESCRIPTION:
347 ssuominen 1.109 # This function will generate and install the neccessary modprobe.d file from the
348 dsd 1.86 # 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 johnm 1.11 generate_modulesd() {
354 genstef 1.69 debug-print-function ${FUNCNAME} $*
355 robbat2 1.114 [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
356 genstef 1.69
357 johnm 1.54 local currm_path currm currm_t t myIFS myVAR
358 johnm 1.26 local module_docs module_enabled module_aliases \
359     module_additions module_examples module_modinfo module_opts
360    
361     for currm_path in ${@}
362 johnm 1.11 do
363 johnm 1.26 currm=${currm_path//*\/}
364     currm=$(echo ${currm} | tr '[:lower:]' '[:upper:]')
365 johnm 1.54 currm_t=${currm}
366     while [[ -z ${currm_t//*-*} ]]; do
367     currm_t=${currm_t/-/_}
368     done
369 johnm 1.26
370 johnm 1.54 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 johnm 1.26
376 johnm 1.27 [[ ${module_aliases} -eq 0 ]] && unset module_aliases
377     [[ ${module_additions} -eq 0 ]] && unset module_additions
378     [[ ${module_examples} -eq 0 ]] && unset module_examples
379 johnm 1.26
380 swegener 1.49 # If we specify we dont want it, then lets exit, otherwise we assume
381 johnm 1.26 # 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 johnm 1.11 do
387 johnm 1.26 [[ -z ${!t} ]] && unset ${t}
388 johnm 1.11 done
389    
390 johnm 1.26 [[ -z ${!module_*} ]] && return 0
391    
392     # OK so now if we have got this far, then we know we want to continue
393 ssuominen 1.109 # and generate the modprobe.d file.
394 johnm 1.26 module_modinfo="$(modinfo -p ${currm_path}.${KV_OBJ})"
395     module_config="${T}/modulesd-${currm}"
396    
397 ssuominen 1.109 ebegin "Preparing file for modprobe.d"
398 johnm 1.26 #-----------------------------------------------------------------------
399 ssuominen 1.109 echo "# modprobe.d configuration file for ${currm}" >> "${module_config}"
400 johnm 1.26 #-----------------------------------------------------------------------
401     [[ -n ${module_docs} ]] && \
402 robbat2 1.96 echo "# For more information please read:" >> "${module_config}"
403 johnm 1.26 for t in ${module_docs}
404 johnm 1.11 do
405 robbat2 1.96 echo "# ${t//*\/}" >> "${module_config}"
406 johnm 1.11 done
407 robbat2 1.96 echo >> "${module_config}"
408 johnm 1.11
409 johnm 1.26 #-----------------------------------------------------------------------
410 johnm 1.27 if [[ ${module_aliases} -gt 0 ]]
411 johnm 1.11 then
412 robbat2 1.96 echo "# Internal Aliases - Do not edit" >> "${module_config}"
413     echo "# ------------------------------" >> "${module_config}"
414 johnm 1.12
415 johnm 1.26 for((t=0; t<${module_aliases}; t++))
416 johnm 1.11 do
417 johnm 1.26 echo "alias $(eval echo \${MODULESD_${currm}_ALIASES[$t]})" \
418 robbat2 1.96 >> "${module_config}"
419 johnm 1.12 done
420 robbat2 1.96 echo '' >> "${module_config}"
421 johnm 1.11 fi
422    
423 johnm 1.26 #-----------------------------------------------------------------------
424     if [[ -n ${module_modinfo} ]]
425 johnm 1.11 then
426 robbat2 1.96 echo >> "${module_config}"
427     echo "# Configurable module parameters" >> "${module_config}"
428     echo "# ------------------------------" >> "${module_config}"
429 johnm 1.26 myIFS="${IFS}"
430 johnm 1.11 IFS="$(echo -en "\n\b")"
431 swegener 1.49
432 johnm 1.26 for t in ${module_modinfo}
433 johnm 1.11 do
434 johnm 1.26 myVAR="$(echo ${t#*:} | grep -e " [0-9][ =]" | sed "s:.*\([01][= ]\).*:\1:")"
435     if [[ -n ${myVAR} ]]
436 johnm 1.11 then
437 johnm 1.26 module_opts="${module_opts} ${t%%:*}:${myVAR}"
438 johnm 1.11 fi
439 robbat2 1.96 echo -e "# ${t%%:*}:\t${t#*:}" >> "${module_config}"
440 swegener 1.49 done
441 johnm 1.26 IFS="${myIFS}"
442 robbat2 1.96 echo '' >> "${module_config}"
443 johnm 1.26 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 robbat2 1.96 echo "# For Example..." >> "${module_config}"
452     echo "# --------------" >> "${module_config}"
453 johnm 1.26 for t in ${module_opts}
454     do
455 robbat2 1.96 echo "# options ${currm} ${t//:*}=${t//*:}" >> "${module_config}"
456 johnm 1.26 done
457 robbat2 1.96 echo '' >> "${module_config}"
458 johnm 1.26 fi
459 johnm 1.27 elif [[ ${module_examples} -gt 0 ]]
460 johnm 1.26 then
461 robbat2 1.96 echo "# For Example..." >> "${module_config}"
462     echo "# --------------" >> "${module_config}"
463 johnm 1.26 for((t=0; t<${module_examples}; t++))
464     do
465     echo "options $(eval echo \${MODULESD_${currm}_EXAMPLES[$t]})" \
466 robbat2 1.96 >> "${module_config}"
467 johnm 1.11 done
468 robbat2 1.96 echo '' >> "${module_config}"
469 johnm 1.11 fi
470 johnm 1.26
471     #-----------------------------------------------------------------------
472 johnm 1.27 if [[ ${module_additions} -gt 0 ]]
473 johnm 1.11 then
474 johnm 1.26 for((t=0; t<${module_additions}; t++))
475 johnm 1.11 do
476 johnm 1.26 echo "$(eval echo \${MODULESD_${currm}_ADDITIONS[$t]})" \
477 robbat2 1.96 >> "${module_config}"
478 johnm 1.11 done
479 robbat2 1.96 echo '' >> "${module_config}"
480 johnm 1.11 fi
481 swegener 1.49
482 johnm 1.26 #-----------------------------------------------------------------------
483    
484 johnm 1.12 # then we install it
485 ssuominen 1.109 insinto /etc/modprobe.d
486 robbat2 1.96 newins "${module_config}" "${currm_path//*\/}.conf"
487 johnm 1.27
488 johnm 1.12 # and install any documentation we might have.
489 johnm 1.26 [[ -n ${module_docs} ]] && dodoc ${module_docs}
490 johnm 1.11 done
491     eend 0
492 johnm 1.26 return 0
493 johnm 1.11 }
494    
495 dsd 1.86 # 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 johnm 1.18 find_module_params() {
503 genstef 1.69 debug-print-function ${FUNCNAME} $*
504    
505 johnm 1.18 local matched_offset=0 matched_opts=0 test="${@}" temp_var result
506     local i=0 y=0 z=0
507 swegener 1.49
508 johnm 1.18 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 swegener 1.49
519 johnm 1.18 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 swegener 1.49
533 johnm 1.18 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 swegener 1.49
541 johnm 1.18 echo ${result}
542     }
543    
544 johnm 1.1 # default ebuild functions
545     # --------------------------------
546    
547 dsd 1.86 # @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 johnm 1.1 linux-mod_pkg_setup() {
553 genstef 1.69 debug-print-function ${FUNCNAME} $*
554 robbat2 1.114 [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
555 genstef 1.69
556 ferringb 1.101 local is_bin="${MERGE_TYPE}"
557    
558 robbat2 1.97 # If we are installing a binpkg, take a different path.
559 ferringb 1.101 # 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 robbat2 1.97 linux-mod_pkg_setup_binary
566     return
567     fi
568    
569 johnm 1.6 linux-info_pkg_setup;
570 dsd 1.78 require_configured_kernel
571 johnm 1.6 check_kernel_built;
572 johnm 1.63 strip_modulenames;
573     [[ -n ${MODULE_NAMES} ]] && check_modules_supported
574 johnm 1.1 set_kvobj;
575 weeve 1.55 # 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 johnm 1.1 }
580    
581 robbat2 1.97 # @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 ulm 1.100 # ~ needs always to be quoted, else bash expands it.
590 robbat2 1.97 for config in $CONFIG_CHECK ; do
591 robbat2 1.99 optional='~'
592     [[ ${config:0:1} == "~" ]] && optional=''
593 robbat2 1.98 new_CONFIG_CHECK="${new_CONFIG_CHECK} ${optional}${config}"
594 robbat2 1.97 done
595     export CONFIG_CHECK="${new_CONFIG_CHECK}"
596     linux-info_pkg_setup;
597     }
598    
599 johnm 1.63 strip_modulenames() {
600 genstef 1.69 debug-print-function ${FUNCNAME} $*
601    
602 johnm 1.63 local i
603     for i in ${MODULE_IGNORE}; do
604     MODULE_NAMES=${MODULE_NAMES//${i}(*}
605     done
606     }
607    
608 dsd 1.86 # @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 johnm 1.1 linux-mod_src_compile() {
617 genstef 1.69 debug-print-function ${FUNCNAME} $*
618 robbat2 1.114 [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
619 genstef 1.69
620 vapier 1.84 local modulename libdir srcdir objdir i n myABI="${ABI}"
621     set_arch_to_kernel
622 blubb 1.62 ABI="${KERNEL_ABI}"
623 johnm 1.26
624 johnm 1.16 BUILD_TARGETS=${BUILD_TARGETS:-clean module}
625 johnm 1.63 strip_modulenames;
626 phreak 1.76 cd "${S}"
627 dsd 1.93 touch Module.symvers
628 johnm 1.9 for i in ${MODULE_NAMES}
629 johnm 1.1 do
630 johnm 1.23 unset libdir srcdir objdir
631 johnm 1.18 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 swegener 1.49
639 johnm 1.18 if [ ! -f "${srcdir}/.built" ];
640 johnm 1.16 then
641 robbat2 1.96 cd "${srcdir}"
642 dsd 1.93 ln -s "${S}"/Module.symvers Module.symvers
643 johnm 1.16 einfo "Preparing ${modulename} module"
644 johnm 1.22 if [[ -n ${ECONF_PARAMS} ]]
645     then
646     econf ${ECONF_PARAMS} || \
647     die "Unable to run econf ${ECONF_PARAMS}"
648     fi
649 vapier 1.83
650 robbat2 1.79 # 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 vapier 1.83 CROSS_COMPILE=${CHOST}- \
657 robbat2 1.79 LDFLAGS=\"$(get_abi_LDFLAGS)\" \
658     ${BUILD_FIXES} \
659     ${BUILD_PARAMS} \
660     ${BUILD_TARGETS} " \
661 vapier 1.83 || die "Unable to emake HOSTCC="$(tc-getBUILD_CC)" CROSS_COMPILE=${CHOST}- LDFLAGS="$(get_abi_LDFLAGS)" ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}"
662 robbat2 1.96 cd "${OLDPWD}"
663     touch "${srcdir}"/.built
664 johnm 1.16 fi
665 johnm 1.1 done
666 johnm 1.26
667 vapier 1.84 set_arch_to_portage
668 blubb 1.62 ABI="${myABI}"
669 johnm 1.1 }
670    
671 dsd 1.86 # @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 ssuominen 1.109 # The modprobe.d configuration file is automatically generated if the
677 dsd 1.86 # 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 johnm 1.1 linux-mod_src_install() {
683 genstef 1.69 debug-print-function ${FUNCNAME} $*
684 robbat2 1.114 [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
685 genstef 1.69
686 johnm 1.18 local modulename libdir srcdir objdir i n
687 swegener 1.49
688 johnm 1.63 strip_modulenames;
689 johnm 1.9 for i in ${MODULE_NAMES}
690 johnm 1.1 do
691 johnm 1.23 unset libdir srcdir objdir
692 johnm 1.18 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 johnm 1.1
700     einfo "Installing ${modulename} module"
701 robbat2 1.96 cd "${objdir}" || die "${objdir} does not exist"
702 brix 1.57 insinto /lib/modules/${KV_FULL}/${libdir}
703 vapier 1.56 doins ${modulename}.${KV_OBJ} || die "doins ${modulename}.${KV_OBJ} failed"
704 robbat2 1.96 cd "${OLDPWD}"
705 swegener 1.49
706 robbat2 1.96 generate_modulesd "${objdir}/${modulename}"
707 johnm 1.1 done
708     }
709    
710 dsd 1.86 # @FUNCTION: linux-mod_pkg_preinst
711     # @DESCRIPTION:
712     # It checks what to do after having merged the package.
713 genstef 1.65 linux-mod_pkg_preinst() {
714 genstef 1.69 debug-print-function ${FUNCNAME} $*
715 robbat2 1.114 [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
716 genstef 1.69
717 zmedico 1.77 [ -d "${D}lib/modules" ] && UPDATE_DEPMOD=true || UPDATE_DEPMOD=false
718     [ -d "${D}lib/modules" ] && UPDATE_MODULEDB=true || UPDATE_MODULEDB=false
719 genstef 1.65 }
720    
721 dsd 1.86 # @FUNCTION: linux-mod_pkg_postinst
722     # @DESCRIPTION:
723     # It executes /sbin/depmod and adds the package to the /var/lib/module-rebuild/moduledb
724 ssuominen 1.109 # database (if ${D}/lib/modules is created)"
725 johnm 1.1 linux-mod_pkg_postinst() {
726 genstef 1.69 debug-print-function ${FUNCNAME} $*
727 robbat2 1.114 [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
728 genstef 1.69
729 genstef 1.65 ${UPDATE_DEPMOD} && update_depmod;
730     ${UPDATE_MODULEDB} && update_moduledb;
731 johnm 1.1 }
732 johnm 1.37
733 dsd 1.86 # @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 ssuominen 1.109 # call /sbin/depmod because the modules are still installed.
737 johnm 1.37 linux-mod_pkg_postrm() {
738 swegener 1.70 debug-print-function ${FUNCNAME} $*
739 robbat2 1.114 [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
740 johnm 1.37 remove_moduledb;
741     }

  ViewVC Help
Powered by ViewVC 1.1.20