/[gentoo-x86]/eclass/linux-info.eclass
Gentoo

Diff of /eclass/linux-info.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.83 Revision 1.90
1# Copyright 1999-2006 Gentoo Foundation 1# Copyright 1999-2011 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.83 2010/01/17 21:46:55 robbat2 Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.90 2011/08/22 04:46:32 vapier Exp $
4#
5# Original author: John Mylchreest <johnm@gentoo.org>
6# Maintainer: kernel-misc@gentoo.org
7#
8# Please direct your bugs to the current eclass maintainer :)
9 4
10# @ECLASS: linux-info.eclass 5# @ECLASS: linux-info.eclass
11# @MAINTAINER: 6# @MAINTAINER:
12# kernel-misc@gentoo.org 7# kernel-misc@gentoo.org
8# @AUTHOR:
9# Original author: John Mylchreest <johnm@gentoo.org>
13# @BLURB: eclass used for accessing kernel related information 10# @BLURB: eclass used for accessing kernel related information
14# @DESCRIPTION: 11# @DESCRIPTION:
15# This eclass is used as a central eclass for accessing kernel 12# This eclass is used as a central eclass for accessing kernel
16# related information for source or binary already installed. 13# related information for source or binary already installed.
17# It is vital for linux-mod.eclass to function correctly, and is split 14# It is vital for linux-mod.eclass to function correctly, and is split
40# You can also check that an option doesn't exist by 37# You can also check that an option doesn't exist by
41# prepending it with an exclamation mark (!). 38# prepending it with an exclamation mark (!).
42# 39#
43# e.g.: CONFIG_CHECK="!MTRR" 40# e.g.: CONFIG_CHECK="!MTRR"
44# 41#
45# To simply warn about a missing option, prepend a '~'. 42# To simply warn about a missing option, prepend a '~'.
46# It may be combined with '!'. 43# It may be combined with '!'.
47# 44#
48# In general, most checks should be non-fatal. The only time fatal checks should 45# In general, most checks should be non-fatal. The only time fatal checks should
49# be used is for building kernel modules or cases that a compile will fail 46# be used is for building kernel modules or cases that a compile will fail
50# without the option. 47# without the option.
207 eerror "getfilevar_noexec requires 2 variables, with the second a valid file." 204 eerror "getfilevar_noexec requires 2 variables, with the second a valid file."
208 eerror " getfilevar_noexec <VARIABLE> <CONFIGFILE>" 205 eerror " getfilevar_noexec <VARIABLE> <CONFIGFILE>"
209 else 206 else
210 ${mycat} "${2}" | \ 207 ${mycat} "${2}" | \
211 sed -n \ 208 sed -n \
212 -e "/^[[:space:]]*${1}[[:space:]]*:\\?=[[:space:]]*\(.*\)\$/{ 209 -e "/^[[:space:]]*${1}[[:space:]]*:\\?=[[:space:]]*\(.*\)\$/{
213 s,^[^=]*[[:space:]]*=[[:space:]]*,,g ; 210 s,^[^=]*[[:space:]]*=[[:space:]]*,,g ;
214 s,[[:space:]]*\$,,g ; 211 s,[[:space:]]*\$,,g ;
215 p 212 p
216 }" 213 }"
217 fi 214 fi
218} 215}
219 216
220# @PRIVATE-VARIABLE: _LINUX_CONFIG_EXISTS_DONE 217# @ECLASS-VARIABLE: _LINUX_CONFIG_EXISTS_DONE
218# @INTERNAL
221# @DESCRIPTION: 219# @DESCRIPTION:
222# This is only set if one of the linux_config_*exists functions has been called. 220# This is only set if one of the linux_config_*exists functions has been called.
223# We use it for a QA warning that the check for a config has not been performed, 221# We use it for a QA warning that the check for a config has not been performed,
224# as linux_chkconfig* in non-legacy mode WILL return an undefined value if no 222# as linux_chkconfig* in non-legacy mode WILL return an undefined value if no
225# config is available at all. 223# config is available at all.
227 225
228linux_config_qa_check() { 226linux_config_qa_check() {
229 local f="$1" 227 local f="$1"
230 if [ -z "${_LINUX_CONFIG_EXISTS_DONE}" ]; then 228 if [ -z "${_LINUX_CONFIG_EXISTS_DONE}" ]; then
231 ewarn "QA: You called $f before any linux_config_exists!" 229 ewarn "QA: You called $f before any linux_config_exists!"
232 ewarn "QA: The return value of $f will NOT gaurenteed later!" 230 ewarn "QA: The return value of $f will NOT guaranteed later!"
233 fi 231 fi
234} 232}
235 233
236# @FUNCTION: linux_config_src_exists 234# @FUNCTION: linux_config_src_exists
237# @RETURN: true or false 235# @RETURN: true or false
439# 437#
440# The KV_DIR is set using the KERNEL_DIR env var, the KV_DIR_OUT is set using a valid 438# The KV_DIR is set using the KERNEL_DIR env var, the KV_DIR_OUT is set using a valid
441# KBUILD_OUTPUT (in a decreasing priority list, we look for the env var, makefile var or the 439# KBUILD_OUTPUT (in a decreasing priority list, we look for the env var, makefile var or the
442# symlink /lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build). 440# symlink /lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build).
443get_version() { 441get_version() {
444 local kbuild_output mkfunc 442 local kbuild_output mkfunc tmplocal
445 443
446 # no need to execute this twice assuming KV_FULL is populated. 444 # no need to execute this twice assuming KV_FULL is populated.
447 # we can force by unsetting KV_FULL 445 # we can force by unsetting KV_FULL
448 [ -n "${KV_FULL}" ] && return 0 446 [ -n "${KV_FULL}" ] && return 0
449 447
495 # do we pass KBUILD_OUTPUT on the CLI? 493 # do we pass KBUILD_OUTPUT on the CLI?
496 OUTPUT_DIR="${OUTPUT_DIR:-${KBUILD_OUTPUT}}" 494 OUTPUT_DIR="${OUTPUT_DIR:-${KBUILD_OUTPUT}}"
497 495
498 # keep track of it 496 # keep track of it
499 KERNEL_MAKEFILE="${KV_DIR}/Makefile" 497 KERNEL_MAKEFILE="${KV_DIR}/Makefile"
500 498
501 # Decide the function used to extract makefile variables. 499 # Decide the function used to extract makefile variables.
502 mkfunc="$(get_makefile_extract_function "${KERNEL_MAKEFILE}")" 500 mkfunc="$(get_makefile_extract_function "${KERNEL_MAKEFILE}")"
503 501
504 # And if we didn't pass it, we can take a nosey in the Makefile 502 # And if we didn't pass it, we can take a nosey in the Makefile
505 kbuild_output="$(${mkfunc} KBUILD_OUTPUT ${KERNEL_MAKEFILE})" 503 kbuild_output="$(${mkfunc} KBUILD_OUTPUT ${KERNEL_MAKEFILE})"
533 [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}" 531 [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}"
534 if [ -n "${KV_OUT_DIR}" ]; 532 if [ -n "${KV_OUT_DIR}" ];
535 then 533 then
536 qeinfo "Found kernel object directory:" 534 qeinfo "Found kernel object directory:"
537 qeinfo " ${KV_OUT_DIR}" 535 qeinfo " ${KV_OUT_DIR}"
538
539 KV_LOCAL="$(get_localversion ${KV_OUT_DIR})"
540 fi 536 fi
541 # and if we STILL have not got it, then we better just set it to KV_DIR 537 # and if we STILL have not got it, then we better just set it to KV_DIR
542 KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}" 538 KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}"
543 539
544 KV_LOCAL="${KV_LOCAL}$(get_localversion ${KV_DIR})" 540 # Grab the kernel release from the output directory.
545 if linux_config_src_exists; then 541 # TODO: we MUST detect kernel.release being out of date, and 'return 1' from
546 KV_LOCAL="${KV_LOCAL}$(linux_chkconfig_string LOCALVERSION)" 542 # this function.
547 KV_LOCAL="${KV_LOCAL//\"/}" 543 if [ -s "${KV_OUT_DIR}"/include/config/kernel.release ]; then
544 KV_LOCAL=$(<"${KV_OUT_DIR}"/include/config/kernel.release)
545 elif [ -s "${KV_OUT_DIR}"/.kernelrelease ]; then
546 KV_LOCAL=$(<"${KV_OUT_DIR}"/.kernelrelease)
547 else
548 KV_LOCAL=
549 fi
548 550
549 # For things like git that can append extra stuff: 551 # KV_LOCAL currently contains the full release; discard the first bits.
550 [ -e ${KV_DIR}/scripts/setlocalversion ] && 552 tmplocal=${KV_LOCAL#${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}}
551 linux_chkconfig_builtin LOCALVERSION_AUTO && 553
552 KV_LOCAL="${KV_LOCAL}$(sh ${KV_DIR}/scripts/setlocalversion ${KV_DIR})" 554 # If the updated local version was not changed, the tree is not prepared.
555 # Clear out KV_LOCAL in that case.
556 # TODO: this does not detect a change in the localversion part between
557 # kernel.release and the value that would be generated.
558 if [ "$KV_LOCAL" = "$tmplocal" ]; then
559 KV_LOCAL=
560 else
561 KV_LOCAL=$tmplocal
553 fi 562 fi
554 563
555 # And we should set KV_FULL to the full expanded version 564 # And we should set KV_FULL to the full expanded version
556 KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}" 565 KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}"
557 566
566# It gets the version of the current running kernel and the result is the same as get_version() if the 575# It gets the version of the current running kernel and the result is the same as get_version() if the
567# function can find the sources. 576# function can find the sources.
568get_running_version() { 577get_running_version() {
569 KV_FULL=$(uname -r) 578 KV_FULL=$(uname -r)
570 579
580 if [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile && -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
581 KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
582 KBUILD_OUTPUT=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
583 unset KV_FULL
584 get_version
585 return $?
571 if [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile ]]; then 586 elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile ]]; then
572 KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source) 587 KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
573 unset KV_FULL 588 unset KV_FULL
574 get_version 589 get_version
575 return $? 590 return $?
576 elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then 591 elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
579 get_version 594 get_version
580 return $? 595 return $?
581 else 596 else
582 KV_MAJOR=$(get_version_component_range 1 ${KV_FULL}) 597 KV_MAJOR=$(get_version_component_range 1 ${KV_FULL})
583 KV_MINOR=$(get_version_component_range 2 ${KV_FULL}) 598 KV_MINOR=$(get_version_component_range 2 ${KV_FULL})
584 KV_PATCH=$(get_version_component_range 3- ${KV_FULL}) 599 KV_PATCH=$(get_version_component_range 3 ${KV_FULL})
585 KV_PATCH=${KV_PATCH//-*} 600 KV_PATCH=${KV_PATCH//-*}
586 [[ -n ${KV_FULL#*-} ]] && [[ -n ${KV_FULL//${KV_FULL#*-}} ]] \ 601 KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}}"
587 && KV_EXTRA="-${KV_FULL#*-}"
588 fi 602 fi
589 return 0 603 return 0
590} 604}
591 605
592# This next function is named with the eclass prefix to avoid conflicts with 606# This next function is named with the eclass prefix to avoid conflicts with

Legend:
Removed from v.1.83  
changed lines
  Added in v.1.90

  ViewVC Help
Powered by ViewVC 1.1.20