/[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.91 Revision 1.97
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2013 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.91 2011/12/12 22:01:37 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.97 2013/02/10 02:21:55 vapier Exp $
4 4
5# @ECLASS: linux-info.eclass 5# @ECLASS: linux-info.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# kernel-misc@gentoo.org 7# kernel-misc@gentoo.org
8# @AUTHOR: 8# @AUTHOR:
16# using additional eclasses. 16# using additional eclasses.
17# 17#
18# "kernel config" in this file means: 18# "kernel config" in this file means:
19# The .config of the currently installed sources is used as the first 19# The .config of the currently installed sources is used as the first
20# preference, with a fall-back to bundled config (/proc/config.gz) if available. 20# preference, with a fall-back to bundled config (/proc/config.gz) if available.
21#
22# Before using any of the config-handling functions in this eclass, you must
23# ensure that one of the following functions has been called (in order of
24# preference), otherwise you will get bugs like #364041):
25# linux-info_pkg_setup
26# linux-info_get_any_version
27# get_version
28# get_running_version
21 29
22# A Couple of env vars are available to effect usage of this eclass 30# A Couple of env vars are available to effect usage of this eclass
23# These are as follows: 31# These are as follows:
24 32
25# @ECLASS-VARIABLE: KERNEL_DIR 33# @ECLASS-VARIABLE: KERNEL_DIR
157# @DESCRIPTION: 165# @DESCRIPTION:
158# It detects the value of the variable defined in the file configfile. This is 166# It detects the value of the variable defined in the file configfile. This is
159# done by including the configfile, and printing the variable with Make. 167# done by including the configfile, and printing the variable with Make.
160# It WILL break if your makefile has missing dependencies! 168# It WILL break if your makefile has missing dependencies!
161getfilevar() { 169getfilevar() {
162local ERROR basefname basedname myARCH="${ARCH}" 170 local ERROR basefname basedname myARCH="${ARCH}"
163 ERROR=0 171 ERROR=0
164 172
165 [ -z "${1}" ] && ERROR=1 173 [ -z "${1}" ] && ERROR=1
166 [ ! -f "${2}" ] && ERROR=1 174 [ ! -f "${2}" ] && ERROR=1
167 175
188# @DESCRIPTION: 196# @DESCRIPTION:
189# It detects the value of the variable defined in the file configfile. 197# It detects the value of the variable defined in the file configfile.
190# This is done with sed matching an expression only. If the variable is defined, 198# This is done with sed matching an expression only. If the variable is defined,
191# you will run into problems. See getfilevar for those cases. 199# you will run into problems. See getfilevar for those cases.
192getfilevar_noexec() { 200getfilevar_noexec() {
193 local ERROR basefname basedname mycat myARCH="${ARCH}" 201 local ERROR basefname basedname mycat myARCH="${ARCH}"
194 ERROR=0 202 ERROR=0
195 mycat='cat' 203 mycat='cat'
196 204
197 [ -z "${1}" ] && ERROR=1 205 [ -z "${1}" ] && ERROR=1
198 [ ! -f "${2}" ] && ERROR=1 206 [ ! -f "${2}" ] && ERROR=1
235# @RETURN: true or false 243# @RETURN: true or false
236# @DESCRIPTION: 244# @DESCRIPTION:
237# It returns true if .config exists in a build directory otherwise false 245# It returns true if .config exists in a build directory otherwise false
238linux_config_src_exists() { 246linux_config_src_exists() {
239 export _LINUX_CONFIG_EXISTS_DONE=1 247 export _LINUX_CONFIG_EXISTS_DONE=1
240 [ -s "${KV_OUT_DIR}/.config" ] 248 [[ -n ${KV_OUT_DIR} && -s ${KV_OUT_DIR}/.config ]]
241} 249}
242 250
243# @FUNCTION: linux_config_bin_exists 251# @FUNCTION: linux_config_bin_exists
244# @RETURN: true or false 252# @RETURN: true or false
245# @DESCRIPTION: 253# @DESCRIPTION:
246# It returns true if .config exists in /proc, otherwise false 254# It returns true if .config exists in /proc, otherwise false
247linux_config_bin_exists() { 255linux_config_bin_exists() {
248 export _LINUX_CONFIG_EXISTS_DONE=1 256 export _LINUX_CONFIG_EXISTS_DONE=1
249 [ -s "/proc/config.gz" ] 257 [[ -s /proc/config.gz ]]
250} 258}
251 259
252# @FUNCTION: linux_config_exists 260# @FUNCTION: linux_config_exists
253# @RETURN: true or false 261# @RETURN: true or false
254# @DESCRIPTION: 262# @DESCRIPTION:
256# 264#
257# This function MUST be checked before using any of the linux_chkconfig_* 265# This function MUST be checked before using any of the linux_chkconfig_*
258# functions. 266# functions.
259linux_config_exists() { 267linux_config_exists() {
260 linux_config_src_exists || linux_config_bin_exists 268 linux_config_src_exists || linux_config_bin_exists
269}
270
271# @FUNCTION: linux_config_path
272# @DESCRIPTION:
273# Echo the name of the config file to use. If none are found,
274# then return false.
275linux_config_path() {
276 if linux_config_src_exists; then
277 echo "${KV_OUT_DIR}/.config"
278 elif linux_config_bin_exists; then
279 echo "/proc/config.gz"
280 else
281 return 1
282 fi
261} 283}
262 284
263# @FUNCTION: require_configured_kernel 285# @FUNCTION: require_configured_kernel
264# @DESCRIPTION: 286# @DESCRIPTION:
265# This function verifies that the current kernel is configured (it checks against the existence of .config) 287# This function verifies that the current kernel is configured (it checks against the existence of .config)
281# It checks that CONFIG_<option>=y or CONFIG_<option>=m is present in the current kernel .config 303# It checks that CONFIG_<option>=y or CONFIG_<option>=m is present in the current kernel .config
282# If linux_config_exists returns false, the results of this are UNDEFINED. You 304# If linux_config_exists returns false, the results of this are UNDEFINED. You
283# MUST call linux_config_exists first. 305# MUST call linux_config_exists first.
284linux_chkconfig_present() { 306linux_chkconfig_present() {
285 linux_config_qa_check linux_chkconfig_present 307 linux_config_qa_check linux_chkconfig_present
286 local RESULT 308 [[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == [my] ]]
287 local config
288 config="${KV_OUT_DIR}/.config"
289 [ ! -f "${config}" ] && config="/proc/config.gz"
290 RESULT="$(getfilevar_noexec CONFIG_${1} "${config}")"
291 [ "${RESULT}" = "m" -o "${RESULT}" = "y" ] && return 0 || return 1
292} 309}
293 310
294# @FUNCTION: linux_chkconfig_module 311# @FUNCTION: linux_chkconfig_module
295# @USAGE: option 312# @USAGE: option
296# @RETURN: true or false 313# @RETURN: true or false
298# It checks that CONFIG_<option>=m is present in the current kernel .config 315# It checks that CONFIG_<option>=m is present in the current kernel .config
299# If linux_config_exists returns false, the results of this are UNDEFINED. You 316# If linux_config_exists returns false, the results of this are UNDEFINED. You
300# MUST call linux_config_exists first. 317# MUST call linux_config_exists first.
301linux_chkconfig_module() { 318linux_chkconfig_module() {
302 linux_config_qa_check linux_chkconfig_module 319 linux_config_qa_check linux_chkconfig_module
303 local RESULT 320 [[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == m ]]
304 local config
305 config="${KV_OUT_DIR}/.config"
306 [ ! -f "${config}" ] && config="/proc/config.gz"
307 RESULT="$(getfilevar_noexec CONFIG_${1} "${config}")"
308 [ "${RESULT}" = "m" ] && return 0 || return 1
309} 321}
310 322
311# @FUNCTION: linux_chkconfig_builtin 323# @FUNCTION: linux_chkconfig_builtin
312# @USAGE: option 324# @USAGE: option
313# @RETURN: true or false 325# @RETURN: true or false
315# It checks that CONFIG_<option>=y is present in the current kernel .config 327# It checks that CONFIG_<option>=y is present in the current kernel .config
316# If linux_config_exists returns false, the results of this are UNDEFINED. You 328# If linux_config_exists returns false, the results of this are UNDEFINED. You
317# MUST call linux_config_exists first. 329# MUST call linux_config_exists first.
318linux_chkconfig_builtin() { 330linux_chkconfig_builtin() {
319 linux_config_qa_check linux_chkconfig_builtin 331 linux_config_qa_check linux_chkconfig_builtin
320 local RESULT 332 [[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == y ]]
321 local config
322 config="${KV_OUT_DIR}/.config"
323 [ ! -f "${config}" ] && config="/proc/config.gz"
324 RESULT="$(getfilevar_noexec CONFIG_${1} "${config}")"
325 [ "${RESULT}" = "y" ] && return 0 || return 1
326} 333}
327 334
328# @FUNCTION: linux_chkconfig_string 335# @FUNCTION: linux_chkconfig_string
329# @USAGE: option 336# @USAGE: option
330# @RETURN: CONFIG_<option> 337# @RETURN: CONFIG_<option>
332# It prints the CONFIG_<option> value of the current kernel .config (it requires a configured kernel). 339# It prints the CONFIG_<option> value of the current kernel .config (it requires a configured kernel).
333# If linux_config_exists returns false, the results of this are UNDEFINED. You 340# If linux_config_exists returns false, the results of this are UNDEFINED. You
334# MUST call linux_config_exists first. 341# MUST call linux_config_exists first.
335linux_chkconfig_string() { 342linux_chkconfig_string() {
336 linux_config_qa_check linux_chkconfig_string 343 linux_config_qa_check linux_chkconfig_string
337 local config
338 config="${KV_OUT_DIR}/.config"
339 [ ! -f "${config}" ] && config="/proc/config.gz"
340 getfilevar_noexec "CONFIG_${1}" "${config}" 344 getfilevar_noexec "CONFIG_$1" "$(linux_config_path)"
341} 345}
342 346
343# Versioning Functions 347# Versioning Functions
344# --------------------------------------- 348# ---------------------------------------
345 349
579 KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build) 583 KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
580 unset KV_FULL 584 unset KV_FULL
581 get_version 585 get_version
582 return $? 586 return $?
583 else 587 else
588 # This handles a variety of weird kernel versions. Make sure to update
589 # tests/linux-info:get_running_version.sh if you want to change this.
590 local kv_full=${KV_FULL//[-+_]*}
584 KV_MAJOR=$(get_version_component_range 1 ${KV_FULL}) 591 KV_MAJOR=$(get_version_component_range 1 ${kv_full})
585 KV_MINOR=$(get_version_component_range 2 ${KV_FULL}) 592 KV_MINOR=$(get_version_component_range 2 ${kv_full})
586 KV_PATCH=$(get_version_component_range 3 ${KV_FULL}) 593 KV_PATCH=$(get_version_component_range 3 ${kv_full})
587 KV_PATCH=${KV_PATCH//-*}
588 KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}}" 594 KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}${KV_PATCH:+.${KV_PATCH}}}"
595 : ${KV_PATCH:=0}
589 fi 596 fi
590 return 0 597 return 0
591} 598}
592 599
593# This next function is named with the eclass prefix to avoid conflicts with 600# This next function is named with the eclass prefix to avoid conflicts with
615check_kernel_built() { 622check_kernel_built() {
616 # if we haven't determined the version yet, we need to 623 # if we haven't determined the version yet, we need to
617 require_configured_kernel 624 require_configured_kernel
618 get_version 625 get_version
619 626
627 local versionh_path
628 if kernel_is -ge 3 7; then
629 versionh_path="include/generated/uapi/linux/version.h"
630 else
631 versionh_path="include/linux/version.h"
632 fi
633
620 if [ ! -f "${KV_OUT_DIR}/include/linux/version.h" ] 634 if [ ! -f "${KV_OUT_DIR}/${versionh_path}" ]
621 then 635 then
622 eerror "These sources have not yet been prepared." 636 eerror "These sources have not yet been prepared."
623 eerror "We cannot build against an unprepared tree." 637 eerror "We cannot build against an unprepared tree."
624 eerror "To resolve this, please type the following:" 638 eerror "To resolve this, please type the following:"
625 eerror 639 eerror
638check_modules_supported() { 652check_modules_supported() {
639 # if we haven't determined the version yet, we need too. 653 # if we haven't determined the version yet, we need too.
640 require_configured_kernel 654 require_configured_kernel
641 get_version 655 get_version
642 656
643 if ! linux_chkconfig_builtin "MODULES" 657 if ! linux_chkconfig_builtin "MODULES"; then
644 then
645 eerror "These sources do not support loading external modules." 658 eerror "These sources do not support loading external modules."
646 eerror "to be able to use this module please enable \"Loadable modules support\"" 659 eerror "to be able to use this module please enable \"Loadable modules support\""
647 eerror "in your kernel, recompile and then try merging this module again." 660 eerror "in your kernel, recompile and then try merging this module again."
648 die "No support for external modules in ${KV_FULL} config" 661 die "No support for external modules in ${KV_FULL} config"
649 fi 662 fi
652# @FUNCTION: check_extra_config 665# @FUNCTION: check_extra_config
653# @DESCRIPTION: 666# @DESCRIPTION:
654# It checks the kernel config options specified by CONFIG_CHECK. It dies only when a required config option (i.e. 667# It checks the kernel config options specified by CONFIG_CHECK. It dies only when a required config option (i.e.
655# the prefix ~ is not used) doesn't satisfy the directive. 668# the prefix ~ is not used) doesn't satisfy the directive.
656check_extra_config() { 669check_extra_config() {
657 local config negate die error reworkmodulenames 670 local config negate die error reworkmodulenames
658 local soft_errors_count=0 hard_errors_count=0 config_required=0 671 local soft_errors_count=0 hard_errors_count=0 config_required=0
659 # store the value of the QA check, because otherwise we won't catch usages 672 # store the value of the QA check, because otherwise we won't catch usages
660 # after if check_extra_config is called AND other direct calls are done 673 # after if check_extra_config is called AND other direct calls are done
661 # later. 674 # later.
662 local old_LINUX_CONFIG_EXISTS_DONE="${_LINUX_CONFIG_EXISTS_DONE}" 675 local old_LINUX_CONFIG_EXISTS_DONE="${_LINUX_CONFIG_EXISTS_DONE}"
663 676
664 # if we haven't determined the version yet, we need to 677 # if we haven't determined the version yet, we need to
665 linux-info_get_any_version 678 linux-info_get_any_version
666 679
667 # Determine if we really need a .config. The only time when we don't need 680 # Determine if we really need a .config. The only time when we don't need
668 # one is when all of the CONFIG_CHECK options are prefixed with "~". 681 # one is when all of the CONFIG_CHECK options are prefixed with "~".
669 for config in ${CONFIG_CHECK} 682 for config in ${CONFIG_CHECK}; do
670 do
671 if [[ "${config:0:1}" != "~" ]]; then 683 if [[ "${config:0:1}" != "~" ]]; then
672 config_required=1 684 config_required=1
673 break 685 break
674 fi 686 fi
675 done 687 done

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

  ViewVC Help
Powered by ViewVC 1.1.20