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