/[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.40 Revision 1.55
1# Copyright 1999-2006 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.40 2006/02/16 21:46:50 exg Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.55 2008/03/21 11:11:27 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:
67case ${ARCH} in 67case ${ARCH} in
68 ppc) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";; 68 ppc) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";;
69 ppc64) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";; 69 ppc64) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";;
70esac 70esac
71 71
72# These are legacy wrappers for toolchain-funcs. 72# @FUNCTION: set_arch_to_kernel
73# I dont like them here, but oh well. 73# @DESCRIPTION:
74# Set the env ARCH to match what the kernel expects.
74set_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.
75set_arch_to_portage() { export ARCH="$(tc-arch)"; } 79set_arch_to_portage() { export ARCH=$(tc-arch); }
76 80
77# qeinfo "Message" 81# qeinfo "Message"
78# ------------------- 82# -------------------
79# qeinfo is a quiet einfo call when EBUILD_PHASE 83# qeinfo is a quiet einfo call when EBUILD_PHASE
80# should not have visible output. 84# should not have visible output.
117 basefname="$(basename ${2})" 121 basefname="$(basename ${2})"
118 basedname="$(dirname ${2})" 122 basedname="$(dirname ${2})"
119 unset ARCH 123 unset ARCH
120 124
121 cd "${basedname}" 125 cd "${basedname}"
122 echo -e "include ${basefname}\ne:\n\t@echo \$(${1})" | \ 126 echo -e "e:\\n\\t@echo \$(${1})\\ninclude ${basefname}" | \
123 make ${BUILD_FIXES} -s -f - e 2>/dev/null 127 make M="${S}" ${BUILD_FIXES} -s -f - 2>/dev/null
124 cd "${workingdir}" 128 cd "${workingdir}"
125 129
126 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}"
127 fi 146 fi
128} 147}
129 148
130linux_chkconfig_present() { 149linux_chkconfig_present() {
131local RESULT 150local RESULT
151 require_configured_kernel
132 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)" 152 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)"
133 [ "${RESULT}" = "m" -o "${RESULT}" = "y" ] && return 0 || return 1 153 [ "${RESULT}" = "m" -o "${RESULT}" = "y" ] && return 0 || return 1
134} 154}
135 155
136linux_chkconfig_module() { 156linux_chkconfig_module() {
137local RESULT 157local RESULT
158 require_configured_kernel
138 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)" 159 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)"
139 [ "${RESULT}" = "m" ] && return 0 || return 1 160 [ "${RESULT}" = "m" ] && return 0 || return 1
140} 161}
141 162
142linux_chkconfig_builtin() { 163linux_chkconfig_builtin() {
143local RESULT 164local RESULT
165 require_configured_kernel
144 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)" 166 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)"
145 [ "${RESULT}" = "y" ] && return 0 || return 1 167 [ "${RESULT}" = "y" ] && return 0 || return 1
146} 168}
147 169
148linux_chkconfig_string() { 170linux_chkconfig_string() {
171 require_configured_kernel
149 getfilevar "CONFIG_${1}" "${KV_OUT_DIR}/.config" 172 getfilevar "CONFIG_${1}" "${KV_OUT_DIR}/.config"
150} 173}
151 174
152# Versioning Functions 175# Versioning Functions
153# --------------------------------------- 176# ---------------------------------------
162# kernel_is 2 6 9 returns true 185# kernel_is 2 6 9 returns true
163# 186#
164# got the jist yet? 187# got the jist yet?
165 188
166kernel_is() { 189kernel_is() {
167 # if we haven't determined the version yet, we need too. 190 # if we haven't determined the version yet, we need to.
168 get_version; 191 get_version
169 local operator test value x=0 y=0 z=0 192 local operator test value x=0 y=0 z=0
170 193
171 case ${1} in 194 case ${1} in
172 lt) operator="-lt"; shift;; 195 lt) operator="-lt"; shift;;
173 gt) operator="-gt"; shift;; 196 gt) operator="-gt"; shift;;
278 301
279 # 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.
280 # 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.
281 # 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
282 # caught before this if they are. 305 # caught before this if they are.
283 [ "${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}.${KV_EXTRA}" == "$(uname -r)" ] && \ 306 [ "${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}" == "$(uname -r)" ] && \
284 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}"
285 308
286 [ -h "${OUTPUT_DIR}" ] && KV_OUT_DIR="$(readlink -f ${OUTPUT_DIR})" 309 [ -h "${OUTPUT_DIR}" ] && KV_OUT_DIR="$(readlink -f ${OUTPUT_DIR})"
287 [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}" 310 [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}"
288 if [ -n "${KV_OUT_DIR}" ]; 311 if [ -n "${KV_OUT_DIR}" ];
289 then 312 then
290 qeinfo "Found kernel object directory:" 313 qeinfo "Found kernel object directory:"
291 qeinfo " ${KV_OUT_DIR}" 314 qeinfo " ${KV_OUT_DIR}"
292 315
293 KV_LOCAL="$(get_localversion ${KV_OUT_DIR})" 316 KV_LOCAL="$(get_localversion ${KV_OUT_DIR})"
294 fi 317 fi
295 # 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
296 KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}" 319 KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}"
297 320
298 KV_LOCAL="${KV_LOCAL}$(get_localversion ${KV_DIR})" 321 KV_LOCAL="${KV_LOCAL}$(get_localversion ${KV_DIR})"
322 if linux_config_exists; then
299 KV_LOCAL="${KV_LOCAL}$(linux_chkconfig_string LOCALVERSION)" 323 KV_LOCAL="${KV_LOCAL}$(linux_chkconfig_string LOCALVERSION)"
300 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
301 331
302 # And we should set KV_FULL to the full expanded version 332 # And we should set KV_FULL to the full expanded version
303 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}"
304 334
305 qeinfo "Found sources for kernel version:" 335 qeinfo "Found sources for kernel version:"
306 qeinfo " ${KV_FULL}" 336 qeinfo " ${KV_FULL}"
307
308 if [ ! -s "${KV_OUT_DIR}/.config" ]
309 then
310 qeerror "Could not find a usable .config in the kernel source directory."
311 qeerror "Please ensure that ${KERNEL_DIR} points to a configured set of Linux sources."
312 qeerror "If you are using KBUILD_OUTPUT, please set the environment var so that"
313 qeerror "it points to the necessary object directory so that it might find .config."
314 return 1
315 fi
316 337
317 return 0 338 return 0
318} 339}
319 340
320get_running_version() { 341get_running_version() {
344 365
345# ebuild check functions 366# ebuild check functions
346# --------------------------------------- 367# ---------------------------------------
347 368
348check_kernel_built() { 369check_kernel_built() {
349 # 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
350 get_version; 372 get_version
351 373
352 if [ ! -f "${KV_OUT_DIR}/include/linux/version.h" ] 374 if [ ! -f "${KV_OUT_DIR}/include/linux/version.h" ]
353 then 375 then
354 eerror "These sources have not yet been prepared." 376 eerror "These sources have not yet been prepared."
355 eerror "We cannot build against an unprepared tree." 377 eerror "We cannot build against an unprepared tree."
364 fi 386 fi
365} 387}
366 388
367check_modules_supported() { 389check_modules_supported() {
368 # 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
369 get_version; 392 get_version
370 393
371 if ! linux_chkconfig_builtin "MODULES" 394 if ! linux_chkconfig_builtin "MODULES"
372 then 395 then
373 eerror "These sources do not support loading external modules." 396 eerror "These sources do not support loading external modules."
374 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\""
376 die "No support for external modules in ${KV_FULL} config" 399 die "No support for external modules in ${KV_FULL} config"
377 fi 400 fi
378} 401}
379 402
380check_extra_config() { 403check_extra_config() {
381 local config negate error local_error i n
382 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
383 406
384 # if we haven't determined the version yet, we need too. 407 # if we haven't determined the version yet, we need to
385 get_version; 408 get_version
386 409
410 # Determine if we really need a .config. The only time when we don't need
411 # one is when all of the CONFIG_CHECK options are prefixed with "~".
412 for config in ${CONFIG_CHECK}
413 do
414 if [[ "${config:0:1}" != "~" ]]; then
415 config_required=1
416 break
417 fi
418 done
419
420 if [[ ${config_required} == 0 ]]; then
421 # In the case where we don't require a .config, we can now bail out
422 # if the user has no .config as there is nothing to do. Otherwise
423 # code later will cause a failure due to missing .config.
424 if ! linux_config_exists; then
425 return 0
426 fi
427 else
428 require_configured_kernel
429 fi
430
387 einfo "Checking for suitable kernel configuration options:" 431 einfo "Checking for suitable kernel configuration options..."
432
388 for config in ${CONFIG_CHECK} 433 for config in ${CONFIG_CHECK}
389 do 434 do
390 # if we specify any fatal, ensure we honor them 435 # if we specify any fatal, ensure we honor them
391 die=1 436 die=1
392 error=0 437 error=0
393 negate=0 438 negate=0
394 reworkmodulenames=0 439 reworkmodulenames=0
395 440
396 if [[ -z ${config//\!*} ]]; then 441 if [[ ${config:0:1} == "~" ]]; then
397 negate=1 442 die=0
398 config=${config:1} 443 config=${config:1}
399 fi 444 elif [[ ${config:0:1} == "@" ]]; then
400 if [[ -z ${config/\@*} ]]; then
401 die=2 445 die=0
402 reworkmodulenames=1 446 reworkmodulenames=1
403 config=${config:1} 447 config=${config:1}
404 fi 448 fi
405 if [[ -z ${config/\~*} ]]; then 449 if [[ ${config:0:1} == "!" ]]; then
406 die=0 450 negate=1
407 config=${config:1} 451 config=${config:1}
408 fi 452 fi
409 453
410 if [[ ${negate} == 1 ]]; then 454 if [[ ${negate} == 1 ]]; then
411 linux_chkconfig_present ${config} && error=2 455 linux_chkconfig_present ${config} && error=2
412 elif [[ ${reworkmodulenames} == 1 ]]; then 456 elif [[ ${reworkmodulenames} == 1 ]]; then
413 temp_config="${config//*:}" 457 local temp_config="${config//*:}" i n
414 config="${config//:*}" 458 config="${config//:*}"
415 if linux_chkconfig_present ${config}; then 459 if linux_chkconfig_present ${config}; then
416 for i in ${MODULE_NAMES}; do 460 for i in ${MODULE_NAMES}; do
417 n="${i//${temp_config}}" 461 n="${i//${temp_config}}"
418 [[ -z ${n//\(*} ]] && \ 462 [[ -z ${n//\(*} ]] && \
422 fi 466 fi
423 else 467 else
424 linux_chkconfig_present ${config} || error=1 468 linux_chkconfig_present ${config} || error=1
425 fi 469 fi
426 470
427 if [[ ${die} == 0 ]]; then
428 ebegin "CONFIG_${config}"
429 eend ${error}
430 else
431 if [[ ${error} > 0 ]]; then 471 if [[ ${error} > 0 ]]; then
472 local report_func="eerror" local_error
432 local_error="ERROR_${config}" 473 local_error="ERROR_${config}"
474 local_error="${!local_error}"
475
476 if [[ -z "${local_error}" ]]; then
477 # using old, deprecated format.
478 local_error="${config}_ERROR"
433 local_error="${!local_error}" 479 local_error="${!local_error}"
434 480 fi
435 if [[ -z "${local_error}" ]]; then 481 if [[ ${die} == 0 && -z "${local_error}" ]]; then
436 # using old, deprecated format. 482 #soft errors can be warnings
437 local_error="${config}_ERROR" 483 local_error="WARNING_${config}"
438 local_error="${!local_error}" 484 local_error="${!local_error}"
485 if [[ -n "${local_error}" ]] ; then
486 report_func="ewarn"
439 fi 487 fi
440
441 if [[ -z "${local_error}" ]]; then
442 [[ ${error} == 1 ]] \
443 && local_error="is not set when it should be." \
444 || local_error="should not be set. But it is."
445 local_error="CONFIG_${config}:\t ${local_error}"
446 fi
447 eerror " ${local_error}"
448 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
449 fi 503 fi
450 done 504 done
451 505
452 if [[ ${error} > 0 ]]; then 506 if [[ ${hard_errors_count} > 0 ]]; then
453 eerror "Please check to make sure these options are set correctly." 507 eerror "Please check to make sure these options are set correctly."
454 eerror "Failure to do so may cause unexpected problems." 508 eerror "Failure to do so may cause unexpected problems."
455 if [[ ${die} == 1 ]]; then
456 eerror "Once you have satisfied these options, please try merging" 509 eerror "Once you have satisfied these options, please try merging"
457 eerror "this package again." 510 eerror "this package again."
458 die "Incorrect kernel configuration options" 511 die "Incorrect kernel configuration options"
459 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
460 fi 517 fi
461} 518}
462 519
463check_zlibinflate() { 520check_zlibinflate() {
464 # 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
465 get_version; 523 get_version
466 524
467 # 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!
468 526
469 # bug #27882 - zlib routines are only linked into the kernel 527 # bug #27882 - zlib routines are only linked into the kernel
470 # if something compiled into the kernel calls them 528 # if something compiled into the kernel calls them
533# Default pkg_setup 591# Default pkg_setup
534# 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
535 593
536linux-info_pkg_setup() { 594linux-info_pkg_setup() {
537 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
538 [ -n "${CONFIG_CHECK}" ] && check_extra_config; 613 [ -n "${CONFIG_CHECK}" ] && check_extra_config;
539} 614}

Legend:
Removed from v.1.40  
changed lines
  Added in v.1.55

  ViewVC Help
Powered by ViewVC 1.1.20