# 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
+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
# ---------------------------------------
# @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
}
# @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.
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
# 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
# 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
# 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."
qeerror "it points to the necessary object directory so that it might find .config."
die "Kernel not configured; no .config found in ${KV_OUT_DIR}"
fi
+ get_version || die "Unable to determine configured kernel version"
}
# @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
}
# @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
}
# @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
}
# @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).
# ---------------------------------------
# @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.
# 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
# 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.
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
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}"
# 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 $?
# 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
# 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() {
- get_version
- if [[ $? -ne 0 ]]; then
+ 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"
- get_running_version
+ if ! get_running_version; then
+ die "Unable to determine any Linux Kernel version, please report a bug"
+ fi
fi
}
# @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
- get_version
local versionh_path
if kernel_is -ge 3 7; then
# @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
- get_version
if ! linux_chkconfig_builtin "MODULES"; then
eerror "These sources do not support loading external modules."
# @FUNCTION: check_extra_config
# @DESCRIPTION:
# It checks the kernel config options specified by CONFIG_CHECK. It dies only when a required config option (i.e.
-# the prefix ~ is not used) doesn't satisfy the directive.
+# the prefix ~ is not used) doesn't satisfy the directive. Ignored on non-Linux systems.
check_extra_config() {
+ use kernel_linux || return
+
local config negate die error reworkmodulenames
local soft_errors_count=0 hard_errors_count=0 config_required=0
# store the value of the QA check, because otherwise we won't catch usages
}
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
- get_version
# although I restructured this code - I really really really dont support it!
ebegin "checking ZLIB_INFLATE"
linux_chkconfig_builtin CONFIG_ZLIB_INFLATE
- eend $?
- [ "$?" != 0 ] && die
+ eend $? || die
ebegin "checking ZLIB_DEFLATE"
linux_chkconfig_builtin CONFIG_ZLIB_DEFLATE
- eend $?
- [ "$?" != 0 ] && die
+ eend $? || die
local LINENO_START
local LINENO_END
# Force a get_version() call when inherited from linux-mod.eclass and then check if the kernel is configured
# to support the options specified in CONFIG_CHECK (if not null)
linux-info_pkg_setup() {
+ use kernel_linux || return
+
linux-info_get_any_version
if kernel_is 2 4; then