/[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.99
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.99 2013/02/10 06:20:10 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
100 108
101# And to ensure all the weirdness with crosscompile 109# And to ensure all the weirdness with crosscompile
102inherit toolchain-funcs versionator 110inherit toolchain-funcs versionator
103 111
104EXPORT_FUNCTIONS pkg_setup 112EXPORT_FUNCTIONS pkg_setup
105
106DEPEND=""
107RDEPEND=""
108 113
109# Overwritable environment Var's 114# Overwritable environment Var's
110# --------------------------------------- 115# ---------------------------------------
111KERNEL_DIR="${KERNEL_DIR:-${ROOT}usr/src/linux}" 116KERNEL_DIR="${KERNEL_DIR:-${ROOT}usr/src/linux}"
112 117
157# @DESCRIPTION: 162# @DESCRIPTION:
158# It detects the value of the variable defined in the file configfile. This is 163# 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. 164# done by including the configfile, and printing the variable with Make.
160# It WILL break if your makefile has missing dependencies! 165# It WILL break if your makefile has missing dependencies!
161getfilevar() { 166getfilevar() {
162local ERROR basefname basedname myARCH="${ARCH}" 167 local ERROR basefname basedname myARCH="${ARCH}"
163 ERROR=0 168 ERROR=0
164 169
165 [ -z "${1}" ] && ERROR=1 170 [ -z "${1}" ] && ERROR=1
166 [ ! -f "${2}" ] && ERROR=1 171 [ ! -f "${2}" ] && ERROR=1
167 172
173 else 178 else
174 basefname="$(basename ${2})" 179 basefname="$(basename ${2})"
175 basedname="$(dirname ${2})" 180 basedname="$(dirname ${2})"
176 unset ARCH 181 unset ARCH
177 182
183 # We use nonfatal because we want the caller to take care of things #373151
184 [[ ${EAPI:-0} == [0123] ]] && nonfatal() { "$@"; }
178 echo -e "e:\\n\\t@echo \$(${1})\\ninclude ${basefname}" | \ 185 echo -e "e:\\n\\t@echo \$(${1})\\ninclude ${basefname}" | \
179 make -C "${basedname}" M="${S}" ${BUILD_FIXES} -s -f - 2>/dev/null 186 nonfatal emake -C "${basedname}" M="${S}" ${BUILD_FIXES} -s -f - 2>/dev/null
180 187
181 ARCH=${myARCH} 188 ARCH=${myARCH}
182 fi 189 fi
183} 190}
184 191
188# @DESCRIPTION: 195# @DESCRIPTION:
189# It detects the value of the variable defined in the file configfile. 196# 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, 197# 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. 198# you will run into problems. See getfilevar for those cases.
192getfilevar_noexec() { 199getfilevar_noexec() {
193 local ERROR basefname basedname mycat myARCH="${ARCH}" 200 local ERROR basefname basedname mycat myARCH="${ARCH}"
194 ERROR=0 201 ERROR=0
195 mycat='cat' 202 mycat='cat'
196 203
197 [ -z "${1}" ] && ERROR=1 204 [ -z "${1}" ] && ERROR=1
198 [ ! -f "${2}" ] && ERROR=1 205 [ ! -f "${2}" ] && ERROR=1
235# @RETURN: true or false 242# @RETURN: true or false
236# @DESCRIPTION: 243# @DESCRIPTION:
237# It returns true if .config exists in a build directory otherwise false 244# It returns true if .config exists in a build directory otherwise false
238linux_config_src_exists() { 245linux_config_src_exists() {
239 export _LINUX_CONFIG_EXISTS_DONE=1 246 export _LINUX_CONFIG_EXISTS_DONE=1
240 [ -s "${KV_OUT_DIR}/.config" ] 247 [[ -n ${KV_OUT_DIR} && -s ${KV_OUT_DIR}/.config ]]
241} 248}
242 249
243# @FUNCTION: linux_config_bin_exists 250# @FUNCTION: linux_config_bin_exists
244# @RETURN: true or false 251# @RETURN: true or false
245# @DESCRIPTION: 252# @DESCRIPTION:
246# It returns true if .config exists in /proc, otherwise false 253# It returns true if .config exists in /proc, otherwise false
247linux_config_bin_exists() { 254linux_config_bin_exists() {
248 export _LINUX_CONFIG_EXISTS_DONE=1 255 export _LINUX_CONFIG_EXISTS_DONE=1
249 [ -s "/proc/config.gz" ] 256 [[ -s /proc/config.gz ]]
250} 257}
251 258
252# @FUNCTION: linux_config_exists 259# @FUNCTION: linux_config_exists
253# @RETURN: true or false 260# @RETURN: true or false
254# @DESCRIPTION: 261# @DESCRIPTION:
256# 263#
257# This function MUST be checked before using any of the linux_chkconfig_* 264# This function MUST be checked before using any of the linux_chkconfig_*
258# functions. 265# functions.
259linux_config_exists() { 266linux_config_exists() {
260 linux_config_src_exists || linux_config_bin_exists 267 linux_config_src_exists || linux_config_bin_exists
268}
269
270# @FUNCTION: linux_config_path
271# @DESCRIPTION:
272# Echo the name of the config file to use. If none are found,
273# then return false.
274linux_config_path() {
275 if linux_config_src_exists; then
276 echo "${KV_OUT_DIR}/.config"
277 elif linux_config_bin_exists; then
278 echo "/proc/config.gz"
279 else
280 return 1
281 fi
261} 282}
262 283
263# @FUNCTION: require_configured_kernel 284# @FUNCTION: require_configured_kernel
264# @DESCRIPTION: 285# @DESCRIPTION:
265# This function verifies that the current kernel is configured (it checks against the existence of .config) 286# 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 302# 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 303# If linux_config_exists returns false, the results of this are UNDEFINED. You
283# MUST call linux_config_exists first. 304# MUST call linux_config_exists first.
284linux_chkconfig_present() { 305linux_chkconfig_present() {
285 linux_config_qa_check linux_chkconfig_present 306 linux_config_qa_check linux_chkconfig_present
286 local RESULT 307 [[ $(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} 308}
293 309
294# @FUNCTION: linux_chkconfig_module 310# @FUNCTION: linux_chkconfig_module
295# @USAGE: option 311# @USAGE: option
296# @RETURN: true or false 312# @RETURN: true or false
298# It checks that CONFIG_<option>=m is present in the current kernel .config 314# 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 315# If linux_config_exists returns false, the results of this are UNDEFINED. You
300# MUST call linux_config_exists first. 316# MUST call linux_config_exists first.
301linux_chkconfig_module() { 317linux_chkconfig_module() {
302 linux_config_qa_check linux_chkconfig_module 318 linux_config_qa_check linux_chkconfig_module
303 local RESULT 319 [[ $(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} 320}
310 321
311# @FUNCTION: linux_chkconfig_builtin 322# @FUNCTION: linux_chkconfig_builtin
312# @USAGE: option 323# @USAGE: option
313# @RETURN: true or false 324# @RETURN: true or false
315# It checks that CONFIG_<option>=y is present in the current kernel .config 326# 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 327# If linux_config_exists returns false, the results of this are UNDEFINED. You
317# MUST call linux_config_exists first. 328# MUST call linux_config_exists first.
318linux_chkconfig_builtin() { 329linux_chkconfig_builtin() {
319 linux_config_qa_check linux_chkconfig_builtin 330 linux_config_qa_check linux_chkconfig_builtin
320 local RESULT 331 [[ $(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} 332}
327 333
328# @FUNCTION: linux_chkconfig_string 334# @FUNCTION: linux_chkconfig_string
329# @USAGE: option 335# @USAGE: option
330# @RETURN: CONFIG_<option> 336# @RETURN: CONFIG_<option>
332# It prints the CONFIG_<option> value of the current kernel .config (it requires a configured kernel). 338# 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 339# If linux_config_exists returns false, the results of this are UNDEFINED. You
334# MUST call linux_config_exists first. 340# MUST call linux_config_exists first.
335linux_chkconfig_string() { 341linux_chkconfig_string() {
336 linux_config_qa_check linux_chkconfig_string 342 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}" 343 getfilevar_noexec "CONFIG_$1" "$(linux_config_path)"
341} 344}
342 345
343# Versioning Functions 346# Versioning Functions
344# --------------------------------------- 347# ---------------------------------------
345 348
579 KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build) 582 KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
580 unset KV_FULL 583 unset KV_FULL
581 get_version 584 get_version
582 return $? 585 return $?
583 else 586 else
587 # This handles a variety of weird kernel versions. Make sure to update
588 # tests/linux-info:get_running_version.sh if you want to change this.
589 local kv_full=${KV_FULL//[-+_]*}
584 KV_MAJOR=$(get_version_component_range 1 ${KV_FULL}) 590 KV_MAJOR=$(get_version_component_range 1 ${kv_full})
585 KV_MINOR=$(get_version_component_range 2 ${KV_FULL}) 591 KV_MINOR=$(get_version_component_range 2 ${kv_full})
586 KV_PATCH=$(get_version_component_range 3 ${KV_FULL}) 592 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}}" 593 KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}${KV_PATCH:+.${KV_PATCH}}}"
594 : ${KV_PATCH:=0}
589 fi 595 fi
590 return 0 596 return 0
591} 597}
592 598
593# This next function is named with the eclass prefix to avoid conflicts with 599# This next function is named with the eclass prefix to avoid conflicts with
615check_kernel_built() { 621check_kernel_built() {
616 # if we haven't determined the version yet, we need to 622 # if we haven't determined the version yet, we need to
617 require_configured_kernel 623 require_configured_kernel
618 get_version 624 get_version
619 625
626 local versionh_path
627 if kernel_is -ge 3 7; then
628 versionh_path="include/generated/uapi/linux/version.h"
629 else
630 versionh_path="include/linux/version.h"
631 fi
632
620 if [ ! -f "${KV_OUT_DIR}/include/linux/version.h" ] 633 if [ ! -f "${KV_OUT_DIR}/${versionh_path}" ]
621 then 634 then
622 eerror "These sources have not yet been prepared." 635 eerror "These sources have not yet been prepared."
623 eerror "We cannot build against an unprepared tree." 636 eerror "We cannot build against an unprepared tree."
624 eerror "To resolve this, please type the following:" 637 eerror "To resolve this, please type the following:"
625 eerror 638 eerror
638check_modules_supported() { 651check_modules_supported() {
639 # if we haven't determined the version yet, we need too. 652 # if we haven't determined the version yet, we need too.
640 require_configured_kernel 653 require_configured_kernel
641 get_version 654 get_version
642 655
643 if ! linux_chkconfig_builtin "MODULES" 656 if ! linux_chkconfig_builtin "MODULES"; then
644 then
645 eerror "These sources do not support loading external modules." 657 eerror "These sources do not support loading external modules."
646 eerror "to be able to use this module please enable \"Loadable modules support\"" 658 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." 659 eerror "in your kernel, recompile and then try merging this module again."
648 die "No support for external modules in ${KV_FULL} config" 660 die "No support for external modules in ${KV_FULL} config"
649 fi 661 fi
652# @FUNCTION: check_extra_config 664# @FUNCTION: check_extra_config
653# @DESCRIPTION: 665# @DESCRIPTION:
654# It checks the kernel config options specified by CONFIG_CHECK. It dies only when a required config option (i.e. 666# 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. 667# the prefix ~ is not used) doesn't satisfy the directive.
656check_extra_config() { 668check_extra_config() {
657 local config negate die error reworkmodulenames 669 local config negate die error reworkmodulenames
658 local soft_errors_count=0 hard_errors_count=0 config_required=0 670 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 671 # 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 672 # after if check_extra_config is called AND other direct calls are done
661 # later. 673 # later.
662 local old_LINUX_CONFIG_EXISTS_DONE="${_LINUX_CONFIG_EXISTS_DONE}" 674 local old_LINUX_CONFIG_EXISTS_DONE="${_LINUX_CONFIG_EXISTS_DONE}"
663 675
664 # if we haven't determined the version yet, we need to 676 # if we haven't determined the version yet, we need to
665 linux-info_get_any_version 677 linux-info_get_any_version
666 678
667 # Determine if we really need a .config. The only time when we don't need 679 # 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 "~". 680 # one is when all of the CONFIG_CHECK options are prefixed with "~".
669 for config in ${CONFIG_CHECK} 681 for config in ${CONFIG_CHECK}; do
670 do
671 if [[ "${config:0:1}" != "~" ]]; then 682 if [[ "${config:0:1}" != "~" ]]; then
672 config_required=1 683 config_required=1
673 break 684 break
674 fi 685 fi
675 done 686 done

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

  ViewVC Help
Powered by ViewVC 1.1.20