1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: linux-info.eclass
8 # Original author: John Mylchreest <johnm@gentoo.org>
9 # @BLURB: eclass used for accessing kernel related information
11 # This eclass is used as a central eclass for accessing kernel
12 # related information for source or binary already installed.
13 # It is vital for linux-mod.eclass to function correctly, and is split
14 # out so that any ebuild behaviour "templates" are abstracted out
15 # using additional eclasses.
17 # "kernel config" in this file means:
18 # The .config of the currently installed sources is used as the first
19 # preference, with a fall-back to bundled config (/proc/config.gz) if available.
21 # Before using any of the config-handling functions in this eclass, you must
22 # ensure that one of the following functions has been called (in order of
23 # preference), otherwise you will get bugs like #364041):
24 # linux-info_pkg_setup
25 # linux-info_get_any_version
29 # A Couple of env vars are available to effect usage of this eclass
30 # These are as follows:
32 # @ECLASS-VARIABLE: KERNEL_DIR
34 # A string containing the directory of the target kernel sources. The default value is
37 # @ECLASS-VARIABLE: CONFIG_CHECK
39 # A string containing a list of .config options to check for before
40 # proceeding with the install.
42 # e.g.: CONFIG_CHECK="MTRR"
44 # You can also check that an option doesn't exist by
45 # prepending it with an exclamation mark (!).
47 # e.g.: CONFIG_CHECK="!MTRR"
49 # To simply warn about a missing option, prepend a '~'.
50 # It may be combined with '!'.
52 # In general, most checks should be non-fatal. The only time fatal checks should
53 # be used is for building kernel modules or cases that a compile will fail
56 # This is to allow usage of binary kernels, and minimal systems without kernel
59 # @ECLASS-VARIABLE: ERROR_<CFG>
61 # A string containing the error message to display when the check against CONFIG_CHECK
62 # fails. <CFG> should reference the appropriate option used in CONFIG_CHECK.
64 # e.g.: ERROR_MTRR="MTRR exists in the .config but shouldn't!!"
66 # @ECLASS-VARIABLE: KBUILD_OUTPUT
68 # A string passed on commandline, or set from the kernel makefile. It contains the directory
69 # which is to be used as the kernel object directory.
71 # There are also a couple of variables which are set by this, and shouldn't be
72 # set by hand. These are as follows:
74 # @ECLASS-VARIABLE: KV_FULL
76 # A read-only variable. It's a string containing the full kernel version. ie: 2.6.9-gentoo-johnm-r1
78 # @ECLASS-VARIABLE: KV_MAJOR
80 # A read-only variable. It's an integer containing the kernel major version. ie: 2
82 # @ECLASS-VARIABLE: KV_MINOR
84 # A read-only variable. It's an integer containing the kernel minor version. ie: 6
86 # @ECLASS-VARIABLE: KV_PATCH
88 # A read-only variable. It's an integer containing the kernel patch version. ie: 9
90 # @ECLASS-VARIABLE: KV_EXTRA
92 # A read-only variable. It's a string containing the kernel EXTRAVERSION. ie: -gentoo
94 # @ECLASS-VARIABLE: KV_LOCAL
96 # A read-only variable. It's a string containing the kernel LOCALVERSION concatenation. ie: -johnm
98 # @ECLASS-VARIABLE: KV_DIR
100 # A read-only variable. It's a string containing the kernel source directory, will be null if
101 # KERNEL_DIR is invalid.
103 # @ECLASS-VARIABLE: KV_OUT_DIR
105 # A read-only variable. It's a string containing the kernel object directory, will be KV_DIR unless
106 # KBUILD_OUTPUT is used. This should be used for referencing .config.
108 # And to ensure all the weirdness with crosscompile
109 inherit toolchain-funcs versionator
111 EXPORT_FUNCTIONS pkg_setup
115 # Overwritable environment Var's
116 # ---------------------------------------
117 KERNEL_DIR="${KERNEL_DIR:-${ROOT}usr/src/linux}"
123 ppc) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";;
124 ppc64) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";;
127 # @FUNCTION: set_arch_to_kernel
129 # Set the env ARCH to match what the kernel expects.
130 set_arch_to_kernel() { export ARCH=$(tc-arch-kernel); }
131 # @FUNCTION: set_arch_to_portage
133 # Set the env ARCH to match what portage expects.
134 set_arch_to_portage() { export ARCH=$(tc-arch); }
137 # -------------------
138 # qeinfo is a quiet einfo call when EBUILD_PHASE
139 # should not have visible output.
145 case "${EBUILD_PHASE}" in
146 depend) unset outputmsg;;
147 clean) unset outputmsg;;
148 preinst) unset outputmsg;;
150 [ -n "${outputmsg}" ] && ${type} "${outputmsg}"
153 qeinfo() { qout einfo "${@}" ; }
154 qewarn() { qout ewarn "${@}" ; }
155 qeerror() { qout eerror "${@}" ; }
158 # ---------------------------------------
160 # @FUNCTION: getfilevar
161 # @USAGE: variable configfile
162 # @RETURN: the value of the variable
164 # It detects the value of the variable defined in the file configfile. This is
165 # done by including the configfile, and printing the variable with Make.
166 # It WILL break if your makefile has missing dependencies!
168 local ERROR basefname basedname myARCH="${ARCH}" M="${S}"
171 [ -z "${1}" ] && ERROR=1
172 [ ! -f "${2}" ] && ERROR=1
174 if [ "${ERROR}" = 1 ]
177 eerror "getfilevar requires 2 variables, with the second a valid file."
178 eerror " getfilevar <VARIABLE> <CONFIGFILE>"
180 basefname="$(basename ${2})"
181 basedname="$(dirname ${2})"
184 # We use nonfatal because we want the caller to take care of things #373151
185 [[ ${EAPI:-0} == [0123] ]] && nonfatal() { "$@"; }
186 case ${EBUILD_PHASE_FUNC} in
187 pkg_info|pkg_nofetch|pkg_pretend) M="${T}" ;;
189 echo -e "e:\\n\\t@echo \$(${1})\\ninclude ${basefname}" | \
190 nonfatal emake -C "${basedname}" M="${M}" ${BUILD_FIXES} -s -f - 2>/dev/null
196 # @FUNCTION: getfilevar_noexec
197 # @USAGE: variable configfile
198 # @RETURN: the value of the variable
200 # It detects the value of the variable defined in the file configfile.
201 # This is done with sed matching an expression only. If the variable is defined,
202 # you will run into problems. See getfilevar for those cases.
203 getfilevar_noexec() {
204 local ERROR basefname basedname mycat myARCH="${ARCH}"
208 [ -z "${1}" ] && ERROR=1
209 [ ! -f "${2}" ] && ERROR=1
210 [ "${2%.gz}" != "${2}" ] && mycat='zcat'
212 if [ "${ERROR}" = 1 ]
215 eerror "getfilevar_noexec requires 2 variables, with the second a valid file."
216 eerror " getfilevar_noexec <VARIABLE> <CONFIGFILE>"
220 -e "/^[[:space:]]*${1}[[:space:]]*:\\?=[[:space:]]*\(.*\)\$/{
221 s,^[^=]*[[:space:]]*=[[:space:]]*,,g ;
222 s,[[:space:]]*\$,,g ;
228 # @ECLASS-VARIABLE: _LINUX_CONFIG_EXISTS_DONE
231 # This is only set if one of the linux_config_*exists functions has been called.
232 # We use it for a QA warning that the check for a config has not been performed,
233 # as linux_chkconfig* in non-legacy mode WILL return an undefined value if no
234 # config is available at all.
235 _LINUX_CONFIG_EXISTS_DONE=
237 linux_config_qa_check() {
239 if [ -z "${_LINUX_CONFIG_EXISTS_DONE}" ]; then
240 ewarn "QA: You called $f before any linux_config_exists!"
241 ewarn "QA: The return value of $f will NOT guaranteed later!"
244 if ! use kernel_linux; then
245 die "$f called on non-Linux system, please fix the ebuild"
249 # @FUNCTION: linux_config_src_exists
250 # @RETURN: true or false
252 # It returns true if .config exists in a build directory otherwise false
253 linux_config_src_exists() {
254 export _LINUX_CONFIG_EXISTS_DONE=1
255 [[ -n ${KV_OUT_DIR} && -s ${KV_OUT_DIR}/.config ]]
258 # @FUNCTION: linux_config_bin_exists
259 # @RETURN: true or false
261 # It returns true if .config exists in /proc, otherwise false
262 linux_config_bin_exists() {
263 export _LINUX_CONFIG_EXISTS_DONE=1
264 [[ -s /proc/config.gz ]]
267 # @FUNCTION: linux_config_exists
268 # @RETURN: true or false
270 # It returns true if .config exists otherwise false
272 # This function MUST be checked before using any of the linux_chkconfig_*
274 linux_config_exists() {
275 linux_config_src_exists || linux_config_bin_exists
278 # @FUNCTION: linux_config_path
280 # Echo the name of the config file to use. If none are found,
282 linux_config_path() {
283 if linux_config_src_exists; then
284 echo "${KV_OUT_DIR}/.config"
285 elif linux_config_bin_exists; then
286 echo "/proc/config.gz"
292 # @FUNCTION: require_configured_kernel
294 # This function verifies that the current kernel is configured (it checks against the existence of .config)
296 require_configured_kernel() {
297 if ! use kernel_linux; then
298 die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
301 if ! linux_config_src_exists; then
302 qeerror "Could not find a usable .config in the kernel source directory."
303 qeerror "Please ensure that ${KERNEL_DIR} points to a configured set of Linux sources."
304 qeerror "If you are using KBUILD_OUTPUT, please set the environment var so that"
305 qeerror "it points to the necessary object directory so that it might find .config."
306 die "Kernel not configured; no .config found in ${KV_OUT_DIR}"
308 get_version || die "Unable to determine configured kernel version"
311 # @FUNCTION: linux_chkconfig_present
313 # @RETURN: true or false
315 # It checks that CONFIG_<option>=y or CONFIG_<option>=m is present in the current kernel .config
316 # If linux_config_exists returns false, the results of this are UNDEFINED. You
317 # MUST call linux_config_exists first.
318 linux_chkconfig_present() {
319 linux_config_qa_check linux_chkconfig_present
320 [[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == [my] ]]
323 # @FUNCTION: linux_chkconfig_module
325 # @RETURN: true or false
327 # It checks that CONFIG_<option>=m is present in the current kernel .config
328 # If linux_config_exists returns false, the results of this are UNDEFINED. You
329 # MUST call linux_config_exists first.
330 linux_chkconfig_module() {
331 linux_config_qa_check linux_chkconfig_module
332 [[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == m ]]
335 # @FUNCTION: linux_chkconfig_builtin
337 # @RETURN: true or false
339 # It checks that CONFIG_<option>=y is present in the current kernel .config
340 # If linux_config_exists returns false, the results of this are UNDEFINED. You
341 # MUST call linux_config_exists first.
342 linux_chkconfig_builtin() {
343 linux_config_qa_check linux_chkconfig_builtin
344 [[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == y ]]
347 # @FUNCTION: linux_chkconfig_string
349 # @RETURN: CONFIG_<option>
351 # It prints the CONFIG_<option> value of the current kernel .config (it requires a configured kernel).
352 # If linux_config_exists returns false, the results of this are UNDEFINED. You
353 # MUST call linux_config_exists first.
354 linux_chkconfig_string() {
355 linux_config_qa_check linux_chkconfig_string
356 getfilevar_noexec "CONFIG_$1" "$(linux_config_path)"
359 # Versioning Functions
360 # ---------------------------------------
362 # @FUNCTION: kernel_is
363 # @USAGE: [-lt -gt -le -ge -eq] major_number [minor_number patch_number]
364 # @RETURN: true or false
366 # It returns true when the current kernel version satisfies the comparison against the passed version.
367 # -eq is the default comparison.
370 # For Example where KV = 2.6.9
371 # kernel_is 2 4 returns false
372 # kernel_is 2 returns true
373 # kernel_is 2 6 returns true
374 # kernel_is 2 6 8 returns false
375 # kernel_is 2 6 9 returns true
378 # Note: duplicated in kernel-2.eclass
380 if ! use kernel_linux; then
381 die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
384 # if we haven't determined the version yet, we need to.
385 linux-info_get_any_version
387 # Now we can continue
388 local operator test value
391 lt) operator="-lt"; shift;;
392 gt) operator="-gt"; shift;;
393 le) operator="-le"; shift;;
394 ge) operator="-ge"; shift;;
395 eq) operator="-eq"; shift;;
398 [[ $# -gt 3 ]] && die "Error in kernel-2_kernel_is(): too many parameters"
400 : $(( test = (KV_MAJOR << 16) + (KV_MINOR << 8) + KV_PATCH ))
401 : $(( value = (${1:-${KV_MAJOR}} << 16) + (${2:-${KV_MINOR}} << 8) + ${3:-${KV_PATCH}} ))
402 [ ${test} ${operator} ${value} ]
408 local shopt_save=$(shopt -p nullglob)
410 local files=( ${1}/localversion* )
413 # ignore files with ~ in it.
414 for i in "${files[@]}"; do
415 [[ -n ${i//*~*} ]] && lv_list="${lv_list} ${i}"
418 for i in ${lv_list}; do
425 # Check if the Makefile is valid for direct parsing.
426 # Check status results:
427 # - PASS, use 'getfilevar' to extract values
428 # - FAIL, use 'getfilevar_noexec' to extract values
429 # The check may fail if:
430 # - make is not present
431 # - corruption exists in the kernel makefile
432 get_makefile_extract_function() {
433 local a='' b='' mkfunc='getfilevar'
434 a="$(getfilevar VERSION ${KERNEL_MAKEFILE})"
435 b="$(getfilevar_noexec VERSION ${KERNEL_MAKEFILE})"
436 [[ "${a}" != "${b}" ]] && mkfunc='getfilevar_noexec'
440 # internal variable, so we know to only print the warning once
441 get_version_warning_done=
443 # @FUNCTION: get_version
445 # It gets the version of the kernel inside KERNEL_DIR and populates the KV_FULL variable
446 # (if KV_FULL is already set it does nothing).
448 # The kernel version variables (KV_MAJOR, KV_MINOR, KV_PATCH, KV_EXTRA and KV_LOCAL) are also set.
450 # The KV_DIR is set using the KERNEL_DIR env var, the KV_DIR_OUT is set using a valid
451 # KBUILD_OUTPUT (in a decreasing priority list, we look for the env var, makefile var or the
452 # symlink /lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build).
454 if ! use kernel_linux; then
455 die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
460 # no need to execute this twice assuming KV_FULL is populated.
461 # we can force by unsetting KV_FULL
462 [ -n "${KV_FULL}" ] && return 0
464 # if we dont know KV_FULL, then we need too.
465 # make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR
468 # KV_DIR will contain the full path to the sources directory we should use
469 [ -z "${get_version_warning_done}" ] && \
470 qeinfo "Determining the location of the kernel source code"
471 [ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}"
473 if [ -z "${KV_DIR}" ]
475 if [ -z "${get_version_warning_done}" ]; then
476 get_version_warning_done=1
477 qewarn "Unable to find kernel sources at ${KERNEL_DIR}"
478 #qeinfo "This package requires Linux sources."
479 if [ "${KERNEL_DIR}" == "/usr/src/linux" ] ; then
480 qeinfo "Please make sure that ${KERNEL_DIR} points at your running kernel, "
481 qeinfo "(or the kernel you wish to build against)."
482 qeinfo "Alternatively, set the KERNEL_DIR environment variable to the kernel sources location"
484 qeinfo "Please ensure that the KERNEL_DIR environment variable points at full Linux sources of the kernel you wish to compile against."
490 # See if the kernel dir is actually an output dir. #454294
491 if [ -z "${KBUILD_OUTPUT}" -a -L "${KERNEL_DIR}/source" ]; then
492 KBUILD_OUTPUT=${KERNEL_DIR}
493 KERNEL_DIR=$(readlink -f "${KERNEL_DIR}/source")
497 if [ -z "${get_version_warning_done}" ]; then
498 qeinfo "Found kernel source directory:"
502 if [ ! -s "${KV_DIR}/Makefile" ]
504 if [ -z "${get_version_warning_done}" ]; then
505 get_version_warning_done=1
506 qeerror "Could not find a Makefile in the kernel source directory."
507 qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources"
512 # OK so now we know our sources directory, but they might be using
513 # KBUILD_OUTPUT, and we need this for .config and localversions-*
514 # so we better find it eh?
515 # do we pass KBUILD_OUTPUT on the CLI?
516 local OUTPUT_DIR=${KBUILD_OUTPUT}
519 KERNEL_MAKEFILE="${KV_DIR}/Makefile"
521 if [[ -z ${OUTPUT_DIR} ]]; then
522 # Decide the function used to extract makefile variables.
523 local mkfunc=$(get_makefile_extract_function "${KERNEL_MAKEFILE}")
525 # And if we didn't pass it, we can take a nosey in the Makefile.
526 OUTPUT_DIR=$(${mkfunc} KBUILD_OUTPUT "${KERNEL_MAKEFILE}")
529 # And contrary to existing functions I feel we shouldn't trust the
530 # directory name to find version information as this seems insane.
531 # So we parse ${KERNEL_MAKEFILE}. We should be able to trust that
532 # the Makefile is simple enough to use the noexec extract function.
533 # This has been true for every release thus far, and it's faster
534 # than using make to evaluate the Makefile every time.
535 KV_MAJOR=$(getfilevar_noexec VERSION "${KERNEL_MAKEFILE}")
536 KV_MINOR=$(getfilevar_noexec PATCHLEVEL "${KERNEL_MAKEFILE}")
537 KV_PATCH=$(getfilevar_noexec SUBLEVEL "${KERNEL_MAKEFILE}")
538 KV_EXTRA=$(getfilevar_noexec EXTRAVERSION "${KERNEL_MAKEFILE}")
540 if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ]
542 if [ -z "${get_version_warning_done}" ]; then
543 get_version_warning_done=1
544 qeerror "Could not detect kernel version."
545 qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources."
550 # and in newer versions we can also pull LOCALVERSION if it is set.
551 # but before we do this, we need to find if we use a different object directory.
552 # This *WILL* break if the user is using localversions, but we assume it was
553 # caught before this if they are.
554 if [[ -z ${OUTPUT_DIR} ]] ; then
555 # Try to locate a kernel that is most relevant for us.
556 for OUTPUT_DIR in "${SYSROOT}" "${ROOT}" "" ; do
557 OUTPUT_DIR+="/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build"
558 if [[ -e ${OUTPUT_DIR} ]] ; then
564 [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}"
565 if [ -n "${KV_OUT_DIR}" ];
567 qeinfo "Found kernel object directory:"
568 qeinfo " ${KV_OUT_DIR}"
570 # and if we STILL have not got it, then we better just set it to KV_DIR
571 KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}"
573 # Grab the kernel release from the output directory.
574 # TODO: we MUST detect kernel.release being out of date, and 'return 1' from
576 if [ -s "${KV_OUT_DIR}"/include/config/kernel.release ]; then
577 KV_LOCAL=$(<"${KV_OUT_DIR}"/include/config/kernel.release)
578 elif [ -s "${KV_OUT_DIR}"/.kernelrelease ]; then
579 KV_LOCAL=$(<"${KV_OUT_DIR}"/.kernelrelease)
584 # KV_LOCAL currently contains the full release; discard the first bits.
585 tmplocal=${KV_LOCAL#${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}}
587 # If the updated local version was not changed, the tree is not prepared.
588 # Clear out KV_LOCAL in that case.
589 # TODO: this does not detect a change in the localversion part between
590 # kernel.release and the value that would be generated.
591 if [ "$KV_LOCAL" = "$tmplocal" ]; then
597 # And we should set KV_FULL to the full expanded version
598 KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}"
600 qeinfo "Found sources for kernel version:"
606 # @FUNCTION: get_running_version
608 # It gets the version of the current running kernel and the result is the same as get_version() if the
609 # function can find the sources.
610 get_running_version() {
611 if ! use kernel_linux; then
612 die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
617 if [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile && -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
618 KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
619 KBUILD_OUTPUT=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
623 elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile ]]; then
624 KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
628 elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
629 KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
634 # This handles a variety of weird kernel versions. Make sure to update
635 # tests/linux-info_get_running_version.sh if you want to change this.
636 local kv_full=${KV_FULL//[-+_]*}
637 KV_MAJOR=$(get_version_component_range 1 ${kv_full})
638 KV_MINOR=$(get_version_component_range 2 ${kv_full})
639 KV_PATCH=$(get_version_component_range 3 ${kv_full})
640 KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}${KV_PATCH:+.${KV_PATCH}}}"
646 # This next function is named with the eclass prefix to avoid conflicts with
647 # some old versionator-like eclass functions.
649 # @FUNCTION: linux-info_get_any_version
651 # This attempts to find the version of the sources, and otherwise falls back to
652 # the version of the running kernel.
653 linux-info_get_any_version() {
654 if ! use kernel_linux; then
655 die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
658 if ! get_version; then
659 ewarn "Unable to calculate Linux Kernel version for build, attempting to use running version"
660 if ! get_running_version; then
661 die "Unable to determine any Linux Kernel version, please report a bug"
667 # ebuild check functions
668 # ---------------------------------------
670 # @FUNCTION: check_kernel_built
672 # This function verifies that the current kernel sources have been already prepared otherwise it dies.
673 check_kernel_built() {
674 if ! use kernel_linux; then
675 die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
678 # if we haven't determined the version yet, we need to
679 require_configured_kernel
682 if kernel_is -ge 3 7; then
683 versionh_path="include/generated/uapi/linux/version.h"
685 versionh_path="include/linux/version.h"
688 if [ ! -f "${KV_OUT_DIR}/${versionh_path}" ]
690 eerror "These sources have not yet been prepared."
691 eerror "We cannot build against an unprepared tree."
692 eerror "To resolve this, please type the following:"
694 eerror "# cd ${KV_DIR}"
695 eerror "# make oldconfig"
696 eerror "# make modules_prepare"
698 eerror "Then please try merging this module again."
699 die "Kernel sources need compiling first"
703 # @FUNCTION: check_modules_supported
705 # This function verifies that the current kernel support modules (it checks CONFIG_MODULES=y) otherwise it dies.
706 check_modules_supported() {
707 if ! use kernel_linux; then
708 die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
711 # if we haven't determined the version yet, we need too.
712 require_configured_kernel
714 if ! linux_chkconfig_builtin "MODULES"; then
715 eerror "These sources do not support loading external modules."
716 eerror "to be able to use this module please enable \"Loadable modules support\""
717 eerror "in your kernel, recompile and then try merging this module again."
718 die "No support for external modules in ${KV_FULL} config"
722 # @FUNCTION: check_extra_config
724 # It checks the kernel config options specified by CONFIG_CHECK. It dies only when a required config option (i.e.
725 # the prefix ~ is not used) doesn't satisfy the directive. Ignored on non-Linux systems.
726 check_extra_config() {
727 use kernel_linux || return
729 local config negate die error reworkmodulenames
730 local soft_errors_count=0 hard_errors_count=0 config_required=0
731 # store the value of the QA check, because otherwise we won't catch usages
732 # after if check_extra_config is called AND other direct calls are done
734 local old_LINUX_CONFIG_EXISTS_DONE="${_LINUX_CONFIG_EXISTS_DONE}"
736 # if we haven't determined the version yet, we need to
737 linux-info_get_any_version
739 # Determine if we really need a .config. The only time when we don't need
740 # one is when all of the CONFIG_CHECK options are prefixed with "~".
741 for config in ${CONFIG_CHECK}; do
742 if [[ "${config:0:1}" != "~" ]]; then
748 if [[ ${config_required} == 0 ]]; then
749 # In the case where we don't require a .config, we can now bail out
750 # if the user has no .config as there is nothing to do. Otherwise
751 # code later will cause a failure due to missing .config.
752 if ! linux_config_exists; then
753 ewarn "Unable to check for the following kernel config options due"
754 ewarn "to absence of any configured kernel sources or compiled"
756 for config in ${CONFIG_CHECK}; do
759 local_error="ERROR_${config}"
760 msg="${!local_error}"
761 if [[ -z ${msg} ]]; then
762 local_error="WARNING_${config}"
763 msg="${!local_error}"
765 ewarn " - ${config}${msg:+ - }${msg}"
767 ewarn "You're on your own to make sure they are set if needed."
768 export LINUX_CONFIG_EXISTS_DONE="${old_LINUX_CONFIG_EXISTS_DONE}"
772 require_configured_kernel
775 einfo "Checking for suitable kernel configuration options..."
777 for config in ${CONFIG_CHECK}
779 # if we specify any fatal, ensure we honor them
785 if [[ ${config:0:1} == "~" ]]; then
788 elif [[ ${config:0:1} == "@" ]]; then
793 if [[ ${config:0:1} == "!" ]]; then
798 if [[ ${negate} == 1 ]]; then
799 linux_chkconfig_present ${config} && error=2
800 elif [[ ${reworkmodulenames} == 1 ]]; then
801 local temp_config="${config//*:}" i n
802 config="${config//:*}"
803 if linux_chkconfig_present ${config}; then
804 for i in ${MODULE_NAMES}; do
805 n="${i//${temp_config}}"
806 [[ -z ${n//\(*} ]] && \
807 MODULE_IGNORE="${MODULE_IGNORE} ${temp_config}"
812 linux_chkconfig_present ${config} || error=1
815 if [[ ${error} > 0 ]]; then
816 local report_func="eerror" local_error
817 local_error="ERROR_${config}"
818 local_error="${!local_error}"
820 if [[ -z "${local_error}" ]]; then
821 # using old, deprecated format.
822 local_error="${config}_ERROR"
823 local_error="${!local_error}"
825 if [[ ${die} == 0 && -z "${local_error}" ]]; then
826 #soft errors can be warnings
827 local_error="WARNING_${config}"
828 local_error="${!local_error}"
829 if [[ -n "${local_error}" ]] ; then
834 if [[ -z "${local_error}" ]]; then
835 [[ ${error} == 1 ]] \
836 && local_error="is not set when it should be." \
837 || local_error="should not be set. But it is."
838 local_error="CONFIG_${config}:\t ${local_error}"
840 if [[ ${die} == 0 ]]; then
841 ${report_func} " ${local_error}"
842 soft_errors_count=$[soft_errors_count + 1]
844 ${report_func} " ${local_error}"
845 hard_errors_count=$[hard_errors_count + 1]
850 if [[ ${hard_errors_count} > 0 ]]; then
851 eerror "Please check to make sure these options are set correctly."
852 eerror "Failure to do so may cause unexpected problems."
853 eerror "Once you have satisfied these options, please try merging"
854 eerror "this package again."
855 export LINUX_CONFIG_EXISTS_DONE="${old_LINUX_CONFIG_EXISTS_DONE}"
856 die "Incorrect kernel configuration options"
857 elif [[ ${soft_errors_count} > 0 ]]; then
858 ewarn "Please check to make sure these options are set correctly."
859 ewarn "Failure to do so may cause unexpected problems."
863 export LINUX_CONFIG_EXISTS_DONE="${old_LINUX_CONFIG_EXISTS_DONE}"
866 check_zlibinflate() {
867 if ! use kernel_linux; then
868 die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
871 # if we haven't determined the version yet, we need to
872 require_configured_kernel
874 # although I restructured this code - I really really really dont support it!
876 # bug #27882 - zlib routines are only linked into the kernel
877 # if something compiled into the kernel calls them
879 # plus, for the cloop module, it appears that there's no way
880 # to get cloop.o to include a static zlib if CONFIG_MODVERSIONS
886 einfo "Determining the usability of ZLIB_INFLATE support in your kernel"
888 ebegin "checking ZLIB_INFLATE"
889 linux_chkconfig_builtin CONFIG_ZLIB_INFLATE
892 ebegin "checking ZLIB_DEFLATE"
893 linux_chkconfig_builtin CONFIG_ZLIB_DEFLATE
901 LINENO_END="$(grep -n 'CONFIG_ZLIB_INFLATE y' ${KV_DIR}/lib/Config.in | cut -d : -f 1)"
902 LINENO_START="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | grep -n 'if \[' | tail -n 1 | cut -d : -f 1)"
903 (( LINENO_AMOUNT = $LINENO_END - $LINENO_START ))
904 (( LINENO_END = $LINENO_END - 1 ))
905 SYMBOLS="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;')"
907 # okay, now we have a list of symbols
908 # we need to check each one in turn, to see whether it is set or not
909 for x in $SYMBOLS ; do
910 if [ "${!x}" = "y" ]; then
912 einfo "${x} ensures zlib is linked into your kernel - excellent"
918 eerror "This kernel module requires ZLIB library support."
919 eerror "You have enabled zlib support in your kernel, but haven't enabled"
920 eerror "enabled any option that will ensure that zlib is linked into your"
923 eerror "Please ensure that you enable at least one of these options:"
926 for x in $SYMBOLS ; do
931 eerror "Please remember to recompile and install your kernel, and reboot"
932 eerror "into your new kernel before attempting to load this kernel module."
934 die "Kernel doesn't include zlib support"
937 ################################
939 # Also used when inheriting linux-mod to force a get_version call
940 # @FUNCTION: linux-info_pkg_setup
942 # Force a get_version() call when inherited from linux-mod.eclass and then check if the kernel is configured
943 # to support the options specified in CONFIG_CHECK (if not null)
944 linux-info_pkg_setup() {
945 use kernel_linux || return
947 linux-info_get_any_version
949 if kernel_is 2 4; then
950 if [ "$( gcc-major-version )" -eq "4" ] ; then
952 ewarn "Be warned !! >=sys-devel/gcc-4.0.0 isn't supported with"
953 ewarn "linux-2.4 (or modules building against a linux-2.4 kernel)!"
955 ewarn "Either switch to another gcc-version (via gcc-config) or use a"
956 ewarn "newer kernel that supports gcc-4."
958 ewarn "Also be aware that bugreports about gcc-4 not working"
959 ewarn "with linux-2.4 based ebuilds will be closed as INVALID!"
964 [ -n "${CONFIG_CHECK}" ] && check_extra_config;