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