/[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.34 Revision 1.54
1# Copyright 1999-2004 Gentoo Foundation 1# Copyright 1999-2006 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.34 2005/12/30 18:36:39 johnm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.54 2008/01/23 20:58:08 dsd Exp $
4# 4#
5# Description: This eclass is used as a central eclass for accessing kernel 5# Description: This eclass is used as a central eclass for accessing kernel
6# related information for sources already installed. 6# related information for sources already installed.
7# It is vital for linux-mod to function correctly, and is split 7# It is vital for linux-mod to function correctly, and is split
8# out so that any ebuild behaviour "templates" are abstracted out 8# out so that any ebuild behaviour "templates" are abstracted out
9# using additional eclasses. 9# using additional eclasses.
10# 10#
11# Maintainer: John Mylchreest <johnm@gentoo.org> 11# Original author: John Mylchreest <johnm@gentoo.org>
12# Copyright 2004 Gentoo Linux 12# Maintainer: kernel-misc@gentoo.org
13# 13#
14# Please direct your bugs to the current eclass maintainer :) 14# Please direct your bugs to the current eclass maintainer :)
15 15
16# A Couple of env vars are available to effect usage of this eclass 16# A Couple of env vars are available to effect usage of this eclass
17# These are as follows: 17# These are as follows:
22# CONFIG_CHECK <string> a list of .config options to check for before 22# CONFIG_CHECK <string> a list of .config options to check for before
23# proceeding with the install. ie: CONFIG_CHECK="MTRR" 23# proceeding with the install. ie: CONFIG_CHECK="MTRR"
24# You can also check that an option doesn't exist by 24# You can also check that an option doesn't exist by
25# prepending it with an exclamation mark (!). 25# prepending it with an exclamation mark (!).
26# ie: CONFIG_CHECK="!MTRR" 26# ie: CONFIG_CHECK="!MTRR"
27# To simply warn about a missing option, prepend a '~'.
27# ERROR_CFG <string> The error message to display when the above check 28# ERROR_CFG <string> The error message to display when the above check
28# fails. <CFG> should reference the appropriate option 29# fails. <CFG> should reference the appropriate option
29# as above. ie: ERROR_MTRR="MTRR exists in the .config 30# as above. ie: ERROR_MTRR="MTRR exists in the .config
30# but shouldn't!!" 31# but shouldn't!!"
31# KBUILD_OUTPUT <string> This is passed on commandline, or can be set from 32# KBUILD_OUTPUT <string> This is passed on commandline, or can be set from
51# And to ensure all the weirdness with crosscompile 52# And to ensure all the weirdness with crosscompile
52inherit toolchain-funcs versionator 53inherit toolchain-funcs versionator
53 54
54EXPORT_FUNCTIONS pkg_setup 55EXPORT_FUNCTIONS pkg_setup
55 56
57DEPEND="kernel_linux? ( virtual/linux-sources )"
58RDEPEND=""
59
56# Overwritable environment Var's 60# Overwritable environment Var's
57# --------------------------------------- 61# ---------------------------------------
58KERNEL_DIR="${KERNEL_DIR:-${ROOT}usr/src/linux}" 62KERNEL_DIR="${KERNEL_DIR:-${ROOT}usr/src/linux}"
59 63
60 64
63case ${ARCH} in 67case ${ARCH} in
64 ppc) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";; 68 ppc) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";;
65 ppc64) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";; 69 ppc64) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";;
66esac 70esac
67 71
68# These are legacy wrappers for toolchain-funcs. 72# @FUNCTION: set_arch_to_kernel
69# I dont like them here, but oh well. 73# @DESCRIPTION:
74# Set the env ARCH to match what the kernel expects.
70set_arch_to_kernel() { export ARCH="$(tc-arch-kernel)"; } 75set_arch_to_kernel() { export ARCH=$(tc-arch-kernel); }
76# @FUNCTION: set_arch_to_portage
77# @DESCRIPTION:
78# Set the env ARCH to match what portage expects.
71set_arch_to_portage() { export ARCH="$(tc-arch)"; } 79set_arch_to_portage() { export ARCH=$(tc-arch); }
72 80
73# qeinfo "Message" 81# qeinfo "Message"
74# ------------------- 82# -------------------
75# qeinfo is a quiet einfo call when EBUILD_PHASE 83# qeinfo is a quiet einfo call when EBUILD_PHASE
76# should not have visible output. 84# should not have visible output.
113 basefname="$(basename ${2})" 121 basefname="$(basename ${2})"
114 basedname="$(dirname ${2})" 122 basedname="$(dirname ${2})"
115 unset ARCH 123 unset ARCH
116 124
117 cd "${basedname}" 125 cd "${basedname}"
118 echo -e "include ${basefname}\ne:\n\t@echo \$(${1})" | \ 126 echo -e "e:\\n\\t@echo \$(${1})\\ninclude ${basefname}" | \
119 make ${BUILD_FIXES} -s -f - e 2>/dev/null 127 make M="${S}" ${BUILD_FIXES} -s -f - 2>/dev/null
120 cd "${workingdir}" 128 cd "${workingdir}"
121 129
122 ARCH=${myARCH} 130 ARCH=${myARCH}
131 fi
132}
133
134
135linux_config_exists() {
136 [ -s "${KV_OUT_DIR}/.config" ]
137}
138
139require_configured_kernel() {
140 if ! linux_config_exists; then
141 qeerror "Could not find a usable .config in the kernel source directory."
142 qeerror "Please ensure that ${KERNEL_DIR} points to a configured set of Linux sources."
143 qeerror "If you are using KBUILD_OUTPUT, please set the environment var so that"
144 qeerror "it points to the necessary object directory so that it might find .config."
145 die "Kernel not configured; no .config found in ${KV_OUT_DIR}"
123 fi 146 fi
124} 147}
125 148
126linux_chkconfig_present() { 149linux_chkconfig_present() {
127local RESULT 150local RESULT
151 require_configured_kernel
128 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)" 152 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)"
129 [ "${RESULT}" = "m" -o "${RESULT}" = "y" ] && return 0 || return 1 153 [ "${RESULT}" = "m" -o "${RESULT}" = "y" ] && return 0 || return 1
130} 154}
131 155
132linux_chkconfig_module() { 156linux_chkconfig_module() {
133local RESULT 157local RESULT
158 require_configured_kernel
134 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)" 159 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)"
135 [ "${RESULT}" = "m" ] && return 0 || return 1 160 [ "${RESULT}" = "m" ] && return 0 || return 1
136} 161}
137 162
138linux_chkconfig_builtin() { 163linux_chkconfig_builtin() {
139local RESULT 164local RESULT
165 require_configured_kernel
140 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)" 166 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)"
141 [ "${RESULT}" = "y" ] && return 0 || return 1 167 [ "${RESULT}" = "y" ] && return 0 || return 1
142} 168}
143 169
144linux_chkconfig_string() { 170linux_chkconfig_string() {
171 require_configured_kernel
145 getfilevar "CONFIG_${1}" "${KV_OUT_DIR}/.config" 172 getfilevar "CONFIG_${1}" "${KV_OUT_DIR}/.config"
146} 173}
147 174
148# Versioning Functions 175# Versioning Functions
149# --------------------------------------- 176# ---------------------------------------
158# kernel_is 2 6 9 returns true 185# kernel_is 2 6 9 returns true
159# 186#
160# got the jist yet? 187# got the jist yet?
161 188
162kernel_is() { 189kernel_is() {
163 # if we haven't determined the version yet, we need too. 190 # if we haven't determined the version yet, we need to.
164 get_version; 191 get_version
165 local operator test value x=0 y=0 z=0 192 local operator test value x=0 y=0 z=0
166 193
167 case ${1} in 194 case ${1} in
168 lt) operator="-lt"; shift;; 195 lt) operator="-lt"; shift;;
169 gt) operator="-gt"; shift;; 196 gt) operator="-gt"; shift;;
274 301
275 # and in newer versions we can also pull LOCALVERSION if it is set. 302 # and in newer versions we can also pull LOCALVERSION if it is set.
276 # but before we do this, we need to find if we use a different object directory. 303 # but before we do this, we need to find if we use a different object directory.
277 # This *WILL* break if the user is using localversions, but we assume it was 304 # This *WILL* break if the user is using localversions, but we assume it was
278 # caught before this if they are. 305 # caught before this if they are.
279 [ "${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}.${KV_EXTRA}" == "$(uname -r)" ] && \ 306 [ "${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}" == "$(uname -r)" ] && \
280 OUTPUT_DIR="${OUTPUT_DIR:-/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}.${KV_EXTRA}/build}" 307 OUTPUT_DIR="${OUTPUT_DIR:-/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build}"
281 308
282 [ -h "${OUTPUT_DIR}" ] && KV_OUT_DIR="$(readlink -f ${OUTPUT_DIR})" 309 [ -h "${OUTPUT_DIR}" ] && KV_OUT_DIR="$(readlink -f ${OUTPUT_DIR})"
283 [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}" 310 [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}"
284 if [ -n "${KV_OUT_DIR}" ]; 311 if [ -n "${KV_OUT_DIR}" ];
285 then 312 then
286 qeinfo "Found kernel object directory:" 313 qeinfo "Found kernel object directory:"
287 qeinfo " ${KV_OUT_DIR}" 314 qeinfo " ${KV_OUT_DIR}"
288 315
289 KV_LOCAL="$(get_localversion ${KV_OUT_DIR})" 316 KV_LOCAL="$(get_localversion ${KV_OUT_DIR})"
290 fi 317 fi
291 # and if we STILL haven't got it, then we better just set it to KV_DIR 318 # and if we STILL have not got it, then we better just set it to KV_DIR
292 KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}" 319 KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}"
293 320
294 KV_LOCAL="${KV_LOCAL}$(get_localversion ${KV_DIR})" 321 KV_LOCAL="${KV_LOCAL}$(get_localversion ${KV_DIR})"
322 if linux_config_exists; then
295 KV_LOCAL="${KV_LOCAL}$(linux_chkconfig_string LOCALVERSION)" 323 KV_LOCAL="${KV_LOCAL}$(linux_chkconfig_string LOCALVERSION)"
296 KV_LOCAL="${KV_LOCAL//\"/}" 324 KV_LOCAL="${KV_LOCAL//\"/}"
325
326 # For things like git that can append extra stuff:
327 [ -e ${KV_DIR}/scripts/setlocalversion ] &&
328 linux_chkconfig_builtin LOCALVERSION_AUTO &&
329 KV_LOCAL="${KV_LOCAL}$(sh ${KV_DIR}/scripts/setlocalversion ${KV_DIR})"
330 fi
297 331
298 # And we should set KV_FULL to the full expanded version 332 # And we should set KV_FULL to the full expanded version
299 KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}" 333 KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}"
300 334
301 qeinfo "Found sources for kernel version:" 335 qeinfo "Found sources for kernel version:"
302 qeinfo " ${KV_FULL}" 336 qeinfo " ${KV_FULL}"
303
304 if [ ! -s "${KV_OUT_DIR}/.config" ]
305 then
306 qeerror "Could not find a usable .config in the kernel source directory."
307 qeerror "Please ensure that ${KERNEL_DIR} points to a configured set of Linux sources."
308 qeerror "If you are using KBUILD_OUTPUT, please set the environment var so that"
309 qeerror "it points to the necessary object directory so that it might find .config."
310 return 1
311 fi
312 337
313 return 0 338 return 0
314} 339}
315 340
316get_running_version() { 341get_running_version() {
340 365
341# ebuild check functions 366# ebuild check functions
342# --------------------------------------- 367# ---------------------------------------
343 368
344check_kernel_built() { 369check_kernel_built() {
345 # if we haven't determined the version yet, we need too. 370 # if we haven't determined the version yet, we need to
371 require_configured_kernel
346 get_version; 372 get_version
347 373
348 if [ ! -f "${KV_OUT_DIR}/include/linux/version.h" ] 374 if [ ! -f "${KV_OUT_DIR}/include/linux/version.h" ]
349 then 375 then
350 eerror "These sources have not yet been prepared." 376 eerror "These sources have not yet been prepared."
351 eerror "We cannot build against an unprepared tree." 377 eerror "We cannot build against an unprepared tree."
360 fi 386 fi
361} 387}
362 388
363check_modules_supported() { 389check_modules_supported() {
364 # if we haven't determined the version yet, we need too. 390 # if we haven't determined the version yet, we need too.
391 require_configured_kernel
365 get_version; 392 get_version
366 393
367 if ! linux_chkconfig_builtin "MODULES" 394 if ! linux_chkconfig_builtin "MODULES"
368 then 395 then
369 eerror "These sources do not support loading external modules." 396 eerror "These sources do not support loading external modules."
370 eerror "to be able to use this module please enable \"Loadable modules support\"" 397 eerror "to be able to use this module please enable \"Loadable modules support\""
372 die "No support for external modules in ${KV_FULL} config" 399 die "No support for external modules in ${KV_FULL} config"
373 fi 400 fi
374} 401}
375 402
376check_extra_config() { 403check_extra_config() {
377 local config negate error local_error i n
378 local temp_config die reworkmodulenames 404 local config negate die error reworkmodulenames
405 local soft_errors_count=0 hard_errors_count=0 config_required=0
406
407 # Determine if we really need a .config. The only time when we don't need
408 # one is when all of the CONFIG_CHECK options are prefixed with "~".
409 for config in ${CONFIG_CHECK}
410 do
411 if [[ "${config:0:1}" != "~" ]]; then
412 config_required=1
413 break
414 fi
415 done
416
417 if [[ ${config_required} == 0 ]]; then
418 # In the case where we don't require a .config, we can now bail out
419 # if the user has no .config as there is nothing to do. Otherwise
420 # code later will cause a failure due to missing .config.
421 if ! linux_config_exists; then
422 return 0
423 fi
424 else
425 require_configured_kernel
426 fi
379 427
380 # if we haven't determined the version yet, we need too. 428 # if we haven't determined the version yet, we need too.
381 get_version; 429 get_version
382 430
383 einfo "Checking for suitable kernel configuration options:" 431 einfo "Checking for suitable kernel configuration options..."
432
384 for config in ${CONFIG_CHECK} 433 for config in ${CONFIG_CHECK}
385 do 434 do
386 # if we specify any fatal, ensure we honor them 435 # if we specify any fatal, ensure we honor them
387 die=1 436 die=1
388 error=0 437 error=0
389 negate=0 438 negate=0
390 reworkmodulenames=0 439 reworkmodulenames=0
391 440
392 if [[ -z ${config//\!*} ]]; then 441 if [[ ${config:0:1} == "~" ]]; then
393 negate=1 442 die=0
394 config=${config:1} 443 config=${config:1}
395 fi 444 elif [[ ${config:0:1} == "@" ]]; then
396 if [[ -z ${config/\@*} ]]; then
397 die=2 445 die=0
398 reworkmodulenames=1 446 reworkmodulenames=1
399 config=${config:1} 447 config=${config:1}
400 fi 448 fi
401 if [[ -z ${config/\~*} ]]; then 449 if [[ ${config:0:1} == "!" ]]; then
402 die=0 450 negate=1
403 config=${config:1} 451 config=${config:1}
404 fi 452 fi
405 453
406 if [[ ${negate} == 1 ]]; then 454 if [[ ${negate} == 1 ]]; then
407 linux_chkconfig_present ${config} && error=2 455 linux_chkconfig_present ${config} && error=2
408 elif [[ ${reworkmodulenames} == 1 ]]; then 456 elif [[ ${reworkmodulenames} == 1 ]]; then
409 temp_config="${config//*:}" 457 local temp_config="${config//*:}" i n
410 config="${config//:*}" 458 config="${config//:*}"
411 if linux_chkconfig_present ${config}; then 459 if linux_chkconfig_present ${config}; then
412 for i in ${MODULE_NAMES}; do 460 for i in ${MODULE_NAMES}; do
413 n="${i//${temp_config}}" 461 n="${i//${temp_config}}"
414 [[ -z ${n//(*} ]] && \ 462 [[ -z ${n//\(*} ]] && \
415 MODULE_IGNORE="${MODULE_IGNORE} ${temp_config}" 463 MODULE_IGNORE="${MODULE_IGNORE} ${temp_config}"
416 done 464 done
417 error=2 465 error=2
418 fi 466 fi
419 else 467 else
420 linux_chkconfig_present ${config} || error=1 468 linux_chkconfig_present ${config} || error=1
421 fi 469 fi
422 470
423 if [[ ${die} == 0 ]]; then
424 ebegin "CONFIG_${config}"
425 eend ${error}
426 else
427 if [[ ${error} > 0 ]]; then 471 if [[ ${error} > 0 ]]; then
472 local report_func="eerror" local_error
473 local_error="ERROR_${config}"
474 local_error="${!local_error}"
475
476 if [[ -z "${local_error}" ]]; then
477 # using old, deprecated format.
428 local_error="${config}_ERROR" 478 local_error="${config}_ERROR"
429 local_error="${!local_error}" 479 local_error="${!local_error}"
480 fi
481 if [[ ${die} == 0 && -z "${local_error}" ]]; then
482 #soft errors can be warnings
483 local_error="WARNING_${config}"
484 local_error="${!local_error}"
430 if [[ -z "${local_error}" ]]; then 485 if [[ -n "${local_error}" ]] ; then
431 [[ ${error} == 1 ]] \ 486 report_func="ewarn"
432 && local_error="is not set when it should be." \
433 || local_error="should not be set. But it is."
434 local_error="CONFIG_${config}:\t ${local_error}"
435 fi 487 fi
436 eerror " ${local_error}"
437 fi 488 fi
489
490 if [[ -z "${local_error}" ]]; then
491 [[ ${error} == 1 ]] \
492 && local_error="is not set when it should be." \
493 || local_error="should not be set. But it is."
494 local_error="CONFIG_${config}:\t ${local_error}"
495 fi
496 if [[ ${die} == 0 ]]; then
497 ${report_func} " ${local_error}"
498 soft_errors_count=$[soft_errors_count + 1]
499 else
500 ${report_func} " ${local_error}"
501 hard_errors_count=$[hard_errors_count + 1]
502 fi
438 fi 503 fi
439 done 504 done
440 505
441 if [[ ${error} > 0 ]]; then 506 if [[ ${hard_errors_count} > 0 ]]; then
442 eerror "Please check to make sure these options are set correctly." 507 eerror "Please check to make sure these options are set correctly."
443 eerror "Failure to do so may cause unexpected problems." 508 eerror "Failure to do so may cause unexpected problems."
444 if [[ ${die} == 1 ]]; then
445 eerror "Once you have satisfied these options, please try merging" 509 eerror "Once you have satisfied these options, please try merging"
446 eerror "this package again." 510 eerror "this package again."
447 die "Incorrect kernel configuration options" 511 die "Incorrect kernel configuration options"
448 fi 512 elif [[ ${soft_errors_count} > 0 ]]; then
513 ewarn "Please check to make sure these options are set correctly."
514 ewarn "Failure to do so may cause unexpected problems."
515 else
516 eend 0
449 fi 517 fi
450} 518}
451 519
452check_zlibinflate() { 520check_zlibinflate() {
453 # if we haven't determined the version yet, we need too. 521 # if we haven't determined the version yet, we need to
522 require_configured_kernel
454 get_version; 523 get_version
455 524
456 # although I restructured this code - I really really really dont support it! 525 # although I restructured this code - I really really really dont support it!
457 526
458 # bug #27882 - zlib routines are only linked into the kernel 527 # bug #27882 - zlib routines are only linked into the kernel
459 # if something compiled into the kernel calls them 528 # if something compiled into the kernel calls them
522# Default pkg_setup 591# Default pkg_setup
523# Also used when inheriting linux-mod to force a get_version call 592# Also used when inheriting linux-mod to force a get_version call
524 593
525linux-info_pkg_setup() { 594linux-info_pkg_setup() {
526 get_version || die "Unable to calculate Linux Kernel version" 595 get_version || die "Unable to calculate Linux Kernel version"
596
597 if kernel_is 2 4; then
598 if [ "$( gcc-major-version )" -eq "4" ] ; then
599 echo
600 ewarn "Be warned !! >=sys-devel/gcc-4.0.0 isn't supported with"
601 ewarn "linux-2.4 (or modules building against a linux-2.4 kernel)!"
602 echo
603 ewarn "Either switch to another gcc-version (via gcc-config) or use a"
604 ewarn "newer kernel that supports gcc-4."
605 echo
606 ewarn "Also be aware that bugreports about gcc-4 not working"
607 ewarn "with linux-2.4 based ebuilds will be closed as INVALID!"
608 echo
609 epause 10
610 fi
611 fi
612
527 [ -n "${CONFIG_CHECK}" ] && check_extra_config; 613 [ -n "${CONFIG_CHECK}" ] && check_extra_config;
528} 614}

Legend:
Removed from v.1.34  
changed lines
  Added in v.1.54

  ViewVC Help
Powered by ViewVC 1.1.20