/[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.80 Revision 1.91
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.80 2010/01/10 09:25:12 robbat2 Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.91 2011/12/12 22:01:37 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.
146 esac 143 esac
147 [ -n "${outputmsg}" ] && ${type} "${outputmsg}" 144 [ -n "${outputmsg}" ] && ${type} "${outputmsg}"
148} 145}
149 146
150qeinfo() { qout einfo "${@}" ; } 147qeinfo() { qout einfo "${@}" ; }
148qewarn() { qout ewarn "${@}" ; }
151qeerror() { qout eerror "${@}" ; } 149qeerror() { qout eerror "${@}" ; }
152 150
153# File Functions 151# File Functions
154# --------------------------------------- 152# ---------------------------------------
155 153
206 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."
207 eerror " getfilevar_noexec <VARIABLE> <CONFIGFILE>" 205 eerror " getfilevar_noexec <VARIABLE> <CONFIGFILE>"
208 else 206 else
209 ${mycat} "${2}" | \ 207 ${mycat} "${2}" | \
210 sed -n \ 208 sed -n \
211 -e "/^[[:space:]]*${1}[[:space:]]*=[[:space:]]*\(.*\)\$/{ 209 -e "/^[[:space:]]*${1}[[:space:]]*:\\?=[[:space:]]*\(.*\)\$/{
212 s,^[^=]*[[:space:]]*=[[:space:]]*,,g ; 210 s,^[^=]*[[:space:]]*=[[:space:]]*,,g ;
213 s,[[:space:]]*\$,,g ; 211 s,[[:space:]]*\$,,g ;
214 p 212 p
215 }" 213 }"
216 fi 214 fi
217} 215}
218 216
219# @PRIVATE-VARIABLE: _LINUX_CONFIG_EXISTS_DONE 217# @ECLASS-VARIABLE: _LINUX_CONFIG_EXISTS_DONE
218# @INTERNAL
220# @DESCRIPTION: 219# @DESCRIPTION:
221# 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.
222# 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,
223# 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
224# config is available at all. 223# config is available at all.
226 225
227linux_config_qa_check() { 226linux_config_qa_check() {
228 local f="$1" 227 local f="$1"
229 if [ -z "${_LINUX_CONFIG_EXISTS_DONE}" ]; then 228 if [ -z "${_LINUX_CONFIG_EXISTS_DONE}" ]; then
230 ewarn "QA: You called $f before any linux_config_exists!" 229 ewarn "QA: You called $f before any linux_config_exists!"
231 ewarn "QA: The return value of $f will NOT gaurenteed later!" 230 ewarn "QA: The return value of $f will NOT guaranteed later!"
232 fi 231 fi
233} 232}
234 233
235# @FUNCTION: linux_config_src_exists 234# @FUNCTION: linux_config_src_exists
236# @RETURN: true or false 235# @RETURN: true or false
358# kernel_is 2 6 returns true 357# kernel_is 2 6 returns true
359# kernel_is 2 6 8 returns false 358# kernel_is 2 6 8 returns false
360# kernel_is 2 6 9 returns true 359# kernel_is 2 6 9 returns true
361# @CODE 360# @CODE
362 361
363# got the jist yet? 362# Note: duplicated in kernel-2.eclass
364
365kernel_is() { 363kernel_is() {
366 # if we haven't determined the version yet, we need to. 364 # if we haven't determined the version yet, we need to.
367 linux-info_get_any_version 365 linux-info_get_any_version
368 366
369 local operator testagainst value x=0 y=0 z=0 367 # Now we can continue
368 local operator test value
370 369
371 case ${1} in 370 case ${1#-} in
372 -lt|lt) operator="-lt"; shift;; 371 lt) operator="-lt"; shift;;
373 -gt|gt) operator="-gt"; shift;; 372 gt) operator="-gt"; shift;;
374 -le|le) operator="-le"; shift;; 373 le) operator="-le"; shift;;
375 -ge|ge) operator="-ge"; shift;; 374 ge) operator="-ge"; shift;;
376 -eq|eq) operator="-eq"; shift;; 375 eq) operator="-eq"; shift;;
377 *) operator="-eq";; 376 *) operator="-eq";;
378 esac 377 esac
379
380 for x in ${@}; do
381 for((y=0; y<$((3 - ${#x})); y++)); do value="${value}0"; done
382 value="${value}${x}"
383 z=$((${z} + 1))
384
385 case ${z} in
386 1) for((y=0; y<$((3 - ${#KV_MAJOR})); y++)); do testagainst="${testagainst}0"; done;
387 testagainst="${testagainst}${KV_MAJOR}";;
388 2) for((y=0; y<$((3 - ${#KV_MINOR})); y++)); do testagainst="${testagainst}0"; done;
389 testagainst="${testagainst}${KV_MINOR}";;
390 3) for((y=0; y<$((3 - ${#KV_PATCH})); y++)); do testagainst="${testagainst}0"; done;
391 testagainst="${testagainst}${KV_PATCH}";;
392 *) die "Error in kernel-2_kernel_is(): Too many parameters.";; 378 [[ $# -gt 3 ]] && die "Error in kernel-2_kernel_is(): too many parameters"
393 esac
394 done
395 379
396 [ "${testagainst}" ${operator} "${value}" ] && return 0 || return 1 380 : $(( test = (KV_MAJOR << 16) + (KV_MINOR << 8) + KV_PATCH ))
381 : $(( value = (${1:-${KV_MAJOR}} << 16) + (${2:-${KV_MINOR}} << 8) + ${3:-${KV_PATCH}} ))
382 [ ${test} ${operator} ${value} ]
397} 383}
398 384
399get_localversion() { 385get_localversion() {
400 local lv_list i x 386 local lv_list i x
401 387
409 done 395 done
410 x=${x/ /} 396 x=${x/ /}
411 echo ${x} 397 echo ${x}
412} 398}
413 399
400# Check if the Makefile is valid for direct parsing.
401# Check status results:
402# - PASS, use 'getfilevar' to extract values
403# - FAIL, use 'getfilevar_noexec' to extract values
404# The check may fail if:
405# - make is not present
406# - corruption exists in the kernel makefile
407get_makefile_extract_function() {
408 local a='' b='' mkfunc='getfilevar'
409 a="$(getfilevar VERSION ${KERNEL_MAKEFILE})"
410 b="$(getfilevar_noexec VERSION ${KERNEL_MAKEFILE})"
411 [[ "${a}" != "${b}" ]] && mkfunc='getfilevar_noexec'
412 echo "${mkfunc}"
413}
414
414# internal variable, so we know to only print the warning once 415# internal variable, so we know to only print the warning once
415get_version_warning_done= 416get_version_warning_done=
416 417
417# @FUNCTION: get_version 418# @FUNCTION: get_version
418# @DESCRIPTION: 419# @DESCRIPTION:
423# 424#
424# The KV_DIR is set using the KERNEL_DIR env var, the KV_DIR_OUT is set using a valid 425# The KV_DIR is set using the KERNEL_DIR env var, the KV_DIR_OUT is set using a valid
425# KBUILD_OUTPUT (in a decreasing priority list, we look for the env var, makefile var or the 426# KBUILD_OUTPUT (in a decreasing priority list, we look for the env var, makefile var or the
426# symlink /lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build). 427# symlink /lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build).
427get_version() { 428get_version() {
428 local kbuild_output 429 local kbuild_output mkfunc tmplocal
429 430
430 # no need to execute this twice assuming KV_FULL is populated. 431 # no need to execute this twice assuming KV_FULL is populated.
431 # we can force by unsetting KV_FULL 432 # we can force by unsetting KV_FULL
432 [ -n "${KV_FULL}" ] && return 0 433 [ -n "${KV_FULL}" ] && return 0
433 434
480 OUTPUT_DIR="${OUTPUT_DIR:-${KBUILD_OUTPUT}}" 481 OUTPUT_DIR="${OUTPUT_DIR:-${KBUILD_OUTPUT}}"
481 482
482 # keep track of it 483 # keep track of it
483 KERNEL_MAKEFILE="${KV_DIR}/Makefile" 484 KERNEL_MAKEFILE="${KV_DIR}/Makefile"
484 485
485 # Check if the Makefile is valid for direct parsing. 486 # Decide the function used to extract makefile variables.
486 # Check status results: 487 mkfunc="$(get_makefile_extract_function "${KERNEL_MAKEFILE}")"
487 # - PASS, use 'getfilevar' to extract values
488 # - FAIL, use 'getfilevar_noexec' to extract values
489 # The check may fail if:
490 # - make is not present
491 # - corruption exists in the kernel makefile
492 local a='' b='' mkfunc='getfilevar'
493 a="$(getfilevar VERSION ${KERNEL_MAKEFILE})"
494 b="$(getfilevar_noexec VERSION ${KERNEL_MAKEFILE})"
495 [[ "${a}" != "${b}" ]] && mkfunc='getfilevar_noexec'
496 488
497 # And if we didn't pass it, we can take a nosey in the Makefile 489 # And if we didn't pass it, we can take a nosey in the Makefile
498 kbuild_output="$(${mkfunc} KBUILD_OUTPUT ${KERNEL_MAKEFILE})" 490 kbuild_output="$(${mkfunc} KBUILD_OUTPUT ${KERNEL_MAKEFILE})"
499 OUTPUT_DIR="${OUTPUT_DIR:-${kbuild_output}}" 491 OUTPUT_DIR="${OUTPUT_DIR:-${kbuild_output}}"
500 492
518 510
519 # and in newer versions we can also pull LOCALVERSION if it is set. 511 # and in newer versions we can also pull LOCALVERSION if it is set.
520 # but before we do this, we need to find if we use a different object directory. 512 # but before we do this, we need to find if we use a different object directory.
521 # This *WILL* break if the user is using localversions, but we assume it was 513 # This *WILL* break if the user is using localversions, but we assume it was
522 # caught before this if they are. 514 # caught before this if they are.
523 [ "${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}" == "$(uname -r)" ] && \
524 OUTPUT_DIR="${OUTPUT_DIR:-/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build}" 515 OUTPUT_DIR="${OUTPUT_DIR:-/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build}"
525 516
526 [ -h "${OUTPUT_DIR}" ] && KV_OUT_DIR="$(readlink -f ${OUTPUT_DIR})" 517 [ -h "${OUTPUT_DIR}" ] && KV_OUT_DIR="$(readlink -f ${OUTPUT_DIR})"
527 [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}" 518 [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}"
528 if [ -n "${KV_OUT_DIR}" ]; 519 if [ -n "${KV_OUT_DIR}" ];
529 then 520 then
530 qeinfo "Found kernel object directory:" 521 qeinfo "Found kernel object directory:"
531 qeinfo " ${KV_OUT_DIR}" 522 qeinfo " ${KV_OUT_DIR}"
532
533 KV_LOCAL="$(get_localversion ${KV_OUT_DIR})"
534 fi 523 fi
535 # and if we STILL have not got it, then we better just set it to KV_DIR 524 # and if we STILL have not got it, then we better just set it to KV_DIR
536 KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}" 525 KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}"
537 526
538 KV_LOCAL="${KV_LOCAL}$(get_localversion ${KV_DIR})" 527 # Grab the kernel release from the output directory.
539 if linux_config_src_exists; then 528 # TODO: we MUST detect kernel.release being out of date, and 'return 1' from
540 KV_LOCAL="${KV_LOCAL}$(linux_chkconfig_string LOCALVERSION)" 529 # this function.
541 KV_LOCAL="${KV_LOCAL//\"/}" 530 if [ -s "${KV_OUT_DIR}"/include/config/kernel.release ]; then
531 KV_LOCAL=$(<"${KV_OUT_DIR}"/include/config/kernel.release)
532 elif [ -s "${KV_OUT_DIR}"/.kernelrelease ]; then
533 KV_LOCAL=$(<"${KV_OUT_DIR}"/.kernelrelease)
534 else
535 KV_LOCAL=
536 fi
542 537
543 # For things like git that can append extra stuff: 538 # KV_LOCAL currently contains the full release; discard the first bits.
544 [ -e ${KV_DIR}/scripts/setlocalversion ] && 539 tmplocal=${KV_LOCAL#${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}}
545 linux_chkconfig_builtin LOCALVERSION_AUTO && 540
546 KV_LOCAL="${KV_LOCAL}$(sh ${KV_DIR}/scripts/setlocalversion ${KV_DIR})" 541 # If the updated local version was not changed, the tree is not prepared.
542 # Clear out KV_LOCAL in that case.
543 # TODO: this does not detect a change in the localversion part between
544 # kernel.release and the value that would be generated.
545 if [ "$KV_LOCAL" = "$tmplocal" ]; then
546 KV_LOCAL=
547 else
548 KV_LOCAL=$tmplocal
547 fi 549 fi
548 550
549 # And we should set KV_FULL to the full expanded version 551 # And we should set KV_FULL to the full expanded version
550 KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}" 552 KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}"
551 553
560# It gets the version of the current running kernel and the result is the same as get_version() if the 562# It gets the version of the current running kernel and the result is the same as get_version() if the
561# function can find the sources. 563# function can find the sources.
562get_running_version() { 564get_running_version() {
563 KV_FULL=$(uname -r) 565 KV_FULL=$(uname -r)
564 566
567 if [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile && -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
568 KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
569 KBUILD_OUTPUT=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
570 unset KV_FULL
571 get_version
572 return $?
565 if [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile ]]; then 573 elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile ]]; then
566 KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source) 574 KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
567 unset KV_FULL 575 unset KV_FULL
568 get_version 576 get_version
569 return $? 577 return $?
570 elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then 578 elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
573 get_version 581 get_version
574 return $? 582 return $?
575 else 583 else
576 KV_MAJOR=$(get_version_component_range 1 ${KV_FULL}) 584 KV_MAJOR=$(get_version_component_range 1 ${KV_FULL})
577 KV_MINOR=$(get_version_component_range 2 ${KV_FULL}) 585 KV_MINOR=$(get_version_component_range 2 ${KV_FULL})
578 KV_PATCH=$(get_version_component_range 3- ${KV_FULL}) 586 KV_PATCH=$(get_version_component_range 3 ${KV_FULL})
579 KV_PATCH=${KV_PATCH//-*} 587 KV_PATCH=${KV_PATCH//-*}
580 [[ -n ${KV_FULL#*-} ]] && [[ -n ${KV_FULL//${KV_FULL#*-}} ]] \ 588 KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}}"
581 && KV_EXTRA="-${KV_FULL#*-}"
582 fi 589 fi
583 return 0 590 return 0
584} 591}
585 592
586# This next function is named with the eclass prefix to avoid conflicts with 593# This next function is named with the eclass prefix to avoid conflicts with

Legend:
Removed from v.1.80  
changed lines
  Added in v.1.91

  ViewVC Help
Powered by ViewVC 1.1.20