www-client/google-chrome-beta: automated update (84.0.4147.30)
[gentoo.git] / eclass / linux-info.eclass
index 51be89dbcf3439a08f944df4cb9360b892d9770d..405ef5571e1c917b0927b8050be0d4b303296588 100644 (file)
 # KBUILD_OUTPUT is used. This should be used for referencing .config.
 
 # And to ensure all the weirdness with crosscompile
-inherit toolchain-funcs versionator
+inherit toolchain-funcs
+[[ ${EAPI:-0} == [0123456] ]] && inherit eapi7-ver
 
 EXPORT_FUNCTIONS pkg_setup
 
@@ -114,7 +115,7 @@ IUSE="kernel_linux"
 
 # Overwritable environment Var's
 # ---------------------------------------
-KERNEL_DIR="${KERNEL_DIR:-${ROOT}usr/src/linux}"
+KERNEL_DIR="${KERNEL_DIR:-${ROOT%/}/usr/src/linux}"
 
 
 # Bug fixes
@@ -158,7 +159,7 @@ qeerror() { qout eerror "${@}" ; }
 # ---------------------------------------
 
 # @FUNCTION: getfilevar
-# @USAGE: variable configfile
+# @USAGE: <variable> <configfile>
 # @RETURN: the value of the variable
 # @DESCRIPTION:
 # It detects the value of the variable defined in the file configfile. This is
@@ -194,7 +195,7 @@ getfilevar() {
 }
 
 # @FUNCTION: getfilevar_noexec
-# @USAGE: variable configfile
+# @USAGE: <variable> <configfile>
 # @RETURN: the value of the variable
 # @DESCRIPTION:
 # It detects the value of the variable defined in the file configfile.
@@ -240,6 +241,10 @@ linux_config_qa_check() {
                ewarn "QA: You called $f before any linux_config_exists!"
                ewarn "QA: The return value of $f will NOT guaranteed later!"
        fi
+
+       if ! use kernel_linux; then
+               die "$f called on non-Linux system, please fix the ebuild"
+       fi
 }
 
 # @FUNCTION: linux_config_src_exists
@@ -248,7 +253,7 @@ linux_config_qa_check() {
 # It returns true if .config exists in a build directory otherwise false
 linux_config_src_exists() {
        export _LINUX_CONFIG_EXISTS_DONE=1
-       [[ -n ${KV_OUT_DIR} && -s ${KV_OUT_DIR}/.config ]]
+       use kernel_linux && [[ -n ${KV_OUT_DIR} && -s ${KV_OUT_DIR}/.config ]]
 }
 
 # @FUNCTION: linux_config_bin_exists
@@ -257,7 +262,7 @@ linux_config_src_exists() {
 # It returns true if .config exists in /proc, otherwise false
 linux_config_bin_exists() {
        export _LINUX_CONFIG_EXISTS_DONE=1
-       [[ -s /proc/config.gz ]]
+       use kernel_linux && [[ -s /proc/config.gz ]]
 }
 
 # @FUNCTION: linux_config_exists
@@ -290,6 +295,10 @@ linux_config_path() {
 # This function verifies that the current kernel is configured (it checks against the existence of .config)
 # otherwise it dies.
 require_configured_kernel() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        if ! linux_config_src_exists; then
                qeerror "Could not find a usable .config in the kernel source directory."
                qeerror "Please ensure that ${KERNEL_DIR} points to a configured set of Linux sources."
@@ -301,7 +310,7 @@ require_configured_kernel() {
 }
 
 # @FUNCTION: linux_chkconfig_present
-# @USAGE: option
+# @USAGE: <option>
 # @RETURN: true or false
 # @DESCRIPTION:
 # It checks that CONFIG_<option>=y or CONFIG_<option>=m is present in the current kernel .config
@@ -313,7 +322,7 @@ linux_chkconfig_present() {
 }
 
 # @FUNCTION: linux_chkconfig_module
-# @USAGE: option
+# @USAGE: <option>
 # @RETURN: true or false
 # @DESCRIPTION:
 # It checks that CONFIG_<option>=m is present in the current kernel .config
@@ -325,7 +334,7 @@ linux_chkconfig_module() {
 }
 
 # @FUNCTION: linux_chkconfig_builtin
-# @USAGE: option
+# @USAGE: <option>
 # @RETURN: true or false
 # @DESCRIPTION:
 # It checks that CONFIG_<option>=y is present in the current kernel .config
@@ -337,7 +346,7 @@ linux_chkconfig_builtin() {
 }
 
 # @FUNCTION: linux_chkconfig_string
-# @USAGE: option
+# @USAGE: <option>
 # @RETURN: CONFIG_<option>
 # @DESCRIPTION:
 # It prints the CONFIG_<option> value of the current kernel .config (it requires a configured kernel).
@@ -352,7 +361,7 @@ linux_chkconfig_string() {
 # ---------------------------------------
 
 # @FUNCTION: kernel_is
-# @USAGE: [-lt -gt -le -ge -eq] major_number [minor_number patch_number]
+# @USAGE: [-lt -gt -le -ge -eq] <major_number> [minor_number patch_number]
 # @RETURN: true or false
 # @DESCRIPTION:
 # It returns true when the current kernel version satisfies the comparison against the passed version.
@@ -369,6 +378,10 @@ linux_chkconfig_string() {
 
 # Note: duplicated in kernel-2.eclass
 kernel_is() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        # if we haven't determined the version yet, we need to.
        linux-info_get_any_version
 
@@ -439,6 +452,10 @@ get_version_warning_done=
 # KBUILD_OUTPUT (in a decreasing priority list, we look for the env var, makefile var or the
 # symlink /lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build).
 get_version() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        local tmplocal
 
        # no need to execute this twice assuming KV_FULL is populated.
@@ -531,20 +548,6 @@ get_version() {
                return 1
        fi
 
-       # and in newer versions we can also pull LOCALVERSION if it is set.
-       # but before we do this, we need to find if we use a different object directory.
-       # This *WILL* break if the user is using localversions, but we assume it was
-       # caught before this if they are.
-       if [[ -z ${OUTPUT_DIR} ]] ; then
-               # Try to locate a kernel that is most relevant for us.
-               for OUTPUT_DIR in "${SYSROOT}" "${ROOT}" "" ; do
-                       OUTPUT_DIR+="/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build"
-                       if [[ -e ${OUTPUT_DIR} ]] ; then
-                               break
-                       fi
-               done
-       fi
-
        [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}"
        if [ -n "${KV_OUT_DIR}" ];
        then
@@ -578,6 +581,20 @@ get_version() {
                KV_LOCAL=$tmplocal
        fi
 
+       # and in newer versions we can also pull LOCALVERSION if it is set.
+       # but before we do this, we need to find if we use a different object directory.
+       # This *WILL* break if the user is using localversions, but we assume it was
+       # caught before this if they are.
+       if [[ -z ${OUTPUT_DIR} ]] ; then
+               # Try to locate a kernel that is most relevant for us.
+               for OUTPUT_DIR in "${SYSROOT}" "${ROOT%/}" "" ; do
+                       OUTPUT_DIR+="/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}/build"
+                       if [[ -e ${OUTPUT_DIR} ]] ; then
+                               break
+                       fi
+               done
+       fi
+
        # And we should set KV_FULL to the full expanded version
        KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}"
 
@@ -592,21 +609,25 @@ get_version() {
 # It gets the version of the current running kernel and the result is the same as get_version() if the
 # function can find the sources.
 get_running_version() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        KV_FULL=$(uname -r)
 
-       if [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile && -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
-               KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
-               KBUILD_OUTPUT=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
+       if [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/source/Makefile && -f ${ROOT%/}/lib/modules/${KV_FULL}/build/Makefile ]]; then
+               KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/source)
+               KBUILD_OUTPUT=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/build)
                unset KV_FULL
                get_version
                return $?
-       elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile ]]; then
-               KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
+       elif [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/source/Makefile ]]; then
+               KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/source)
                unset KV_FULL
                get_version
                return $?
-       elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
-               KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
+       elif [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/build/Makefile ]]; then
+               KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/build)
                unset KV_FULL
                get_version
                return $?
@@ -614,9 +635,9 @@ get_running_version() {
                # This handles a variety of weird kernel versions.  Make sure to update
                # tests/linux-info_get_running_version.sh if you want to change this.
                local kv_full=${KV_FULL//[-+_]*}
-               KV_MAJOR=$(get_version_component_range 1 ${kv_full})
-               KV_MINOR=$(get_version_component_range 2 ${kv_full})
-               KV_PATCH=$(get_version_component_range 3 ${kv_full})
+               KV_MAJOR=$(ver_cut 1 ${kv_full})
+               KV_MINOR=$(ver_cut 2 ${kv_full})
+               KV_PATCH=$(ver_cut 3 ${kv_full})
                KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}${KV_PATCH:+.${KV_PATCH}}}"
                : ${KV_PATCH:=0}
        fi
@@ -631,6 +652,10 @@ get_running_version() {
 # This attempts to find the version of the sources, and otherwise falls back to
 # the version of the running kernel.
 linux-info_get_any_version() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        if ! get_version; then
                ewarn "Unable to calculate Linux Kernel version for build, attempting to use running version"
                if ! get_running_version; then
@@ -647,6 +672,10 @@ linux-info_get_any_version() {
 # @DESCRIPTION:
 # This function verifies that the current kernel sources have been already prepared otherwise it dies.
 check_kernel_built() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        # if we haven't determined the version yet, we need to
        require_configured_kernel
 
@@ -676,6 +705,10 @@ check_kernel_built() {
 # @DESCRIPTION:
 # This function verifies that the current kernel support modules (it checks CONFIG_MODULES=y) otherwise it dies.
 check_modules_supported() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        # if we haven't determined the version yet, we need too.
        require_configured_kernel
 
@@ -780,7 +813,7 @@ check_extra_config() {
                        linux_chkconfig_present ${config} || error=1
                fi
 
-               if [[ ${error} > 0 ]]; then
+               if [[ ${error} -gt 0 ]]; then
                        local report_func="eerror" local_error
                        local_error="ERROR_${config}"
                        local_error="${!local_error}"
@@ -815,14 +848,14 @@ check_extra_config() {
                fi
        done
 
-       if [[ ${hard_errors_count} > 0 ]]; then
+       if [[ ${hard_errors_count} -gt 0 ]]; then
                eerror "Please check to make sure these options are set correctly."
                eerror "Failure to do so may cause unexpected problems."
                eerror "Once you have satisfied these options, please try merging"
                eerror "this package again."
                export LINUX_CONFIG_EXISTS_DONE="${old_LINUX_CONFIG_EXISTS_DONE}"
                die "Incorrect kernel configuration options"
-       elif [[ ${soft_errors_count} > 0 ]]; then
+       elif [[ ${soft_errors_count} -gt 0 ]]; then
                ewarn "Please check to make sure these options are set correctly."
                ewarn "Failure to do so may cause unexpected problems."
        else
@@ -832,6 +865,10 @@ check_extra_config() {
 }
 
 check_zlibinflate() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        # if we haven't determined the version yet, we need to
        require_configured_kernel