--- eclass/linux-info.eclass 2005/07/11 15:08:06 1.29 +++ eclass/linux-info.eclass 2009/09/06 22:54:58 1.62 @@ -1,58 +1,118 @@ -# Copyright 1999-2004 Gentoo Foundation +# 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.29 2005/07/11 15:08:06 swegener Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.62 2009/09/06 22:54:58 robbat2 Exp $ # -# Description: This eclass is used as a central eclass for accessing kernel -# related information for sources already installed. -# It is vital for linux-mod to function correctly, and is split -# out so that any ebuild behaviour "templates" are abstracted out -# using additional eclasses. -# -# Maintainer: John Mylchreest -# Copyright 2004 Gentoo Linux +# 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 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. + # 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" # -# Env Var Option Description -# KERNEL_DIR The directory containing kernel the target kernel -# sources. -# CONFIG_CHECK a list of .config options to check for before -# proceeding with the install. ie: CONFIG_CHECK="MTRR" -# You can also check that an option doesn't exist by -# prepending it with an exclamation mark (!). -# ie: CONFIG_CHECK="!MTRR" -# ERROR_CFG The error message to display when the above check -# fails. should reference the appropriate option -# as above. ie: ERROR_MTRR="MTRR exists in the .config -# but shouldn't!!" -# KBUILD_OUTPUT This is passed on commandline, or can be set from -# the kernel makefile. This contains the directory -# which is to be used as the kernel object directory. +# 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: -# -# Env Var Option Description -# KV_FULL The full kernel version. ie: 2.6.9-gentoo-johnm-r1 -# KV_MAJOR The kernel major version. ie: 2 -# KV_MINOR The kernel minor version. ie: 6 -# KV_PATCH The kernel patch version. ie: 9 -# KV_EXTRA The kernel EXTRAVERSION. ie: -gentoo -# KV_LOCAL The kernel LOCALVERSION concatenation. ie: -johnm -# KV_DIR The kernel source directory, will be null if -# KERNEL_DIR is invalid. -# KV_OUT_DIR The kernel object directory. will be KV_DIR unless -# koutput is used. This should be used for referencing -# .config. + +# @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. + +# @ECLASS-VARIABLE: I_KNOW_WHAT_I_AM_DOING +# @DESCRIPTION: +# Temporary variable for the migration to making linux-info non-fatal. # 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}" @@ -65,10 +125,14 @@ ppc64) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";; esac -# These are legacy wrappers for toolchain-funcs. -# I dont like them here, but oh well. -set_arch_to_kernel() { export ARCH="$(tc-arch-kernel)"; } -set_arch_to_portage() { export ARCH="$(tc-arch)"; } +# @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" # ------------------- @@ -93,11 +157,15 @@ # File Functions # --------------------------------------- -# getfilevar accepts 2 vars as follows: -# getfilevar - +# @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 workingdir basefname basedname myARCH="${ARCH}" +local ERROR basefname basedname myARCH="${ARCH}" ERROR=0 [ -z "${1}" ] && ERROR=1 @@ -109,59 +177,181 @@ eerror "getfilevar requires 2 variables, with the second a valid file." eerror " getfilevar " else - workingdir=${PWD} - basefname=$(basename ${2}) - basedname=$(dirname ${2}) + basefname="$(basename ${2})" + basedname="$(dirname ${2})" unset ARCH - cd ${basedname} - echo -e "include ${basefname}\ne:\n\t@echo \$(${1})" | \ - make ${BUILD_FIXES} -s -f - e 2>/dev/null - cd ${workingdir} + 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 +} + + +# @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() { + [ -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() { + [ -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_