# Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.93 2012/10/22 19:00:52 mpagano Exp $ # @ECLASS: linux-info.eclass # @MAINTAINER: # kernel-misc@gentoo.org # @AUTHOR: # Original author: John Mylchreest # @BLURB: eclass used for accessing kernel related information # @DESCRIPTION: # This eclass is used as a central eclass for accessing kernel # related information for source or binary already installed. # It is vital for linux-mod.eclass to function correctly, and is split # out so that any ebuild behaviour "templates" are abstracted out # using additional eclasses. # # "kernel config" in this file means: # The .config of the currently installed sources is used as the first # preference, with a fall-back to bundled config (/proc/config.gz) if available. # # Before using any of the config-handling functions in this eclass, you must # ensure that one of the following functions has been called (in order of # preference), otherwise you will get bugs like #364041): # linux-info_pkg_setup # linux-info_get_any_version # get_version # get_running_version # A Couple of env vars are available to effect usage of this eclass # These are as follows: # @ECLASS-VARIABLE: KERNEL_DIR # @DESCRIPTION: # A string containing the directory of the target kernel sources. The default value is # "/usr/src/linux" # @ECLASS-VARIABLE: CONFIG_CHECK # @DESCRIPTION: # A string containing a list of .config options to check for before # proceeding with the install. # # e.g.: CONFIG_CHECK="MTRR" # # You can also check that an option doesn't exist by # prepending it with an exclamation mark (!). # # e.g.: CONFIG_CHECK="!MTRR" # # To simply warn about a missing option, prepend a '~'. # It may be combined with '!'. # # In general, most checks should be non-fatal. The only time fatal checks should # be used is for building kernel modules or cases that a compile will fail # without the option. # # This is to allow usage of binary kernels, and minimal systems without kernel # sources. # @ECLASS-VARIABLE: ERROR_ # @DESCRIPTION: # A string containing the error message to display when the check against CONFIG_CHECK # fails. should reference the appropriate option used in CONFIG_CHECK. # # e.g.: ERROR_MTRR="MTRR exists in the .config but shouldn't!!" # @ECLASS-VARIABLE: KBUILD_OUTPUT # @DESCRIPTION: # A string passed on commandline, or set from the kernel makefile. It contains the directory # which is to be used as the kernel object directory. # There are also a couple of variables which are set by this, and shouldn't be # set by hand. These are as follows: # @ECLASS-VARIABLE: KV_FULL # @DESCRIPTION: # A read-only variable. It's a string containing the full kernel version. ie: 2.6.9-gentoo-johnm-r1 # @ECLASS-VARIABLE: KV_MAJOR # @DESCRIPTION: # A read-only variable. It's an integer containing the kernel major version. ie: 2 # @ECLASS-VARIABLE: KV_MINOR # @DESCRIPTION: # A read-only variable. It's an integer containing the kernel minor version. ie: 6 # @ECLASS-VARIABLE: KV_PATCH # @DESCRIPTION: # A read-only variable. It's an integer containing the kernel patch version. ie: 9 # @ECLASS-VARIABLE: KV_EXTRA # @DESCRIPTION: # A read-only variable. It's a string containing the kernel EXTRAVERSION. ie: -gentoo # @ECLASS-VARIABLE: KV_LOCAL # @DESCRIPTION: # A read-only variable. It's a string containing the kernel LOCALVERSION concatenation. ie: -johnm # @ECLASS-VARIABLE: KV_DIR # @DESCRIPTION: # A read-only variable. It's a string containing the kernel source directory, will be null if # KERNEL_DIR is invalid. # @ECLASS-VARIABLE: KV_OUT_DIR # @DESCRIPTION: # A read-only variable. It's a string containing the kernel object directory, will be KV_DIR unless # KBUILD_OUTPUT is used. This should be used for referencing .config. # And to ensure all the weirdness with crosscompile inherit toolchain-funcs versionator EXPORT_FUNCTIONS pkg_setup DEPEND="" RDEPEND="" # Overwritable environment Var's # --------------------------------------- KERNEL_DIR="${KERNEL_DIR:-${ROOT}usr/src/linux}" # Bug fixes # fix to bug #75034 case ${ARCH} in ppc) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";; ppc64) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";; esac # @FUNCTION: set_arch_to_kernel # @DESCRIPTION: # Set the env ARCH to match what the kernel expects. set_arch_to_kernel() { export ARCH=$(tc-arch-kernel); } # @FUNCTION: set_arch_to_portage # @DESCRIPTION: # Set the env ARCH to match what portage expects. set_arch_to_portage() { export ARCH=$(tc-arch); } # qeinfo "Message" # ------------------- # qeinfo is a quiet einfo call when EBUILD_PHASE # should not have visible output. qout() { local outputmsg type type=${1} shift outputmsg="${@}" case "${EBUILD_PHASE}" in depend) unset outputmsg;; clean) unset outputmsg;; preinst) unset outputmsg;; esac [ -n "${outputmsg}" ] && ${type} "${outputmsg}" } qeinfo() { qout einfo "${@}" ; } qewarn() { qout ewarn "${@}" ; } qeerror() { qout eerror "${@}" ; } # File Functions # --------------------------------------- # @FUNCTION: getfilevar # @USAGE: variable configfile # @RETURN: the value of the variable # @DESCRIPTION: # It detects the value of the variable defined in the file configfile. This is # done by including the configfile, and printing the variable with Make. # It WILL break if your makefile has missing dependencies! getfilevar() { local ERROR basefname basedname myARCH="${ARCH}" ERROR=0 [ -z "${1}" ] && ERROR=1 [ ! -f "${2}" ] && ERROR=1 if [ "${ERROR}" = 1 ] then echo -e "\n" eerror "getfilevar requires 2 variables, with the second a valid file." eerror " getfilevar " else basefname="$(basename ${2})" basedname="$(dirname ${2})" unset ARCH echo -e "e:\\n\\t@echo \$(${1})\\ninclude ${basefname}" | \ make -C "${basedname}" M="${S}" ${BUILD_FIXES} -s -f - 2>/dev/null ARCH=${myARCH} fi } # @FUNCTION: getfilevar_noexec # @USAGE: variable configfile # @RETURN: the value of the variable # @DESCRIPTION: # It detects the value of the variable defined in the file configfile. # This is done with sed matching an expression only. If the variable is defined, # you will run into problems. See getfilevar for those cases. getfilevar_noexec() { local ERROR basefname basedname mycat myARCH="${ARCH}" ERROR=0 mycat='cat' [ -z "${1}" ] && ERROR=1 [ ! -f "${2}" ] && ERROR=1 [ "${2%.gz}" != "${2}" ] && mycat='zcat' if [ "${ERROR}" = 1 ] then echo -e "\n" eerror "getfilevar_noexec requires 2 variables, with the second a valid file." eerror " getfilevar_noexec " else ${mycat} "${2}" | \ sed -n \ -e "/^[[:space:]]*${1}[[:space:]]*:\\?=[[:space:]]*\(.*\)\$/{ s,^[^=]*[[:space:]]*=[[:space:]]*,,g ; s,[[:space:]]*\$,,g ; p }" fi } # @ECLASS-VARIABLE: _LINUX_CONFIG_EXISTS_DONE # @INTERNAL # @DESCRIPTION: # This is only set if one of the linux_config_*exists functions has been called. # We use it for a QA warning that the check for a config has not been performed, # as linux_chkconfig* in non-legacy mode WILL return an undefined value if no # config is available at all. _LINUX_CONFIG_EXISTS_DONE= linux_config_qa_check() { local f="$1" if [ -z "${_LINUX_CONFIG_EXISTS_DONE}" ]; then ewarn "QA: You called $f before any linux_config_exists!" ewarn "QA: The return value of $f will NOT guaranteed later!" fi } # @FUNCTION: linux_config_src_exists # @RETURN: true or false # @DESCRIPTION: # It returns true if .config exists in a build directory otherwise false linux_config_src_exists() { export _LINUX_CONFIG_EXISTS_DONE=1 [ -s "${KV_OUT_DIR}/.config" ] } # @FUNCTION: linux_config_bin_exists # @RETURN: true or false # @DESCRIPTION: # It returns true if .config exists in /proc, otherwise false linux_config_bin_exists() { export _LINUX_CONFIG_EXISTS_DONE=1 [ -s "/proc/config.gz" ] } # @FUNCTION: linux_config_exists # @RETURN: true or false # @DESCRIPTION: # It returns true if .config exists otherwise false # # This function MUST be checked before using any of the linux_chkconfig_* # functions. linux_config_exists() { linux_config_src_exists || linux_config_bin_exists } # @FUNCTION: require_configured_kernel # @DESCRIPTION: # This function verifies that the current kernel is configured (it checks against the existence of .config) # otherwise it dies. require_configured_kernel() { 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 "If you are using KBUILD_OUTPUT, please set the environment var so that" 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 } # @FUNCTION: linux_chkconfig_present # @USAGE: option # @RETURN: true or false # @DESCRIPTION: # It checks that CONFIG_