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

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

  ViewVC Help
Powered by ViewVC 1.1.20