# Copyright 1999-2006 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.58 2009/01/12 23:04:54 maekke Exp $ # # Original author: John Mylchreest # Maintainer: kernel-misc@gentoo.org # # Please direct your bugs to the current eclass maintainer :) # @ECLASS: linux-info.eclass # @MAINTAINER: # kernel-misc@gentoo.org # @BLURB: eclass used for accessing kernel related information # @DESCRIPTION: # This eclass is used as a central eclass for accessing kernel # related information for sources 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. # 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 '~'. # @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="kernel_linux? ( virtual/linux-sources )" 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 "${@}" ; } 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 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: linux_config_exists # @RETURN: true or false # @DESCRIPTION: # It returns true if .config exists otherwise false linux_config_exists() { [ -s "${KV_OUT_DIR}/.config" ] } # @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_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_