| 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.62 2009/09/06 22:54:58 robbat2 Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.74 2009/12/11 20:42:51 robbat2 Exp $ |
| 4 | # |
4 | # |
| 5 | # Original author: John Mylchreest <johnm@gentoo.org> |
5 | # Original author: John Mylchreest <johnm@gentoo.org> |
| 6 | # Maintainer: kernel-misc@gentoo.org |
6 | # Maintainer: kernel-misc@gentoo.org |
| 7 | # |
7 | # |
| 8 | # Please direct your bugs to the current eclass maintainer :) |
8 | # Please direct your bugs to the current eclass maintainer :) |
| … | |
… | |
| 108 | # And to ensure all the weirdness with crosscompile |
108 | # And to ensure all the weirdness with crosscompile |
| 109 | inherit toolchain-funcs versionator |
109 | inherit toolchain-funcs versionator |
| 110 | |
110 | |
| 111 | EXPORT_FUNCTIONS pkg_setup |
111 | EXPORT_FUNCTIONS pkg_setup |
| 112 | |
112 | |
|
|
113 | DEPEND="" |
|
|
114 | RDEPEND="" |
|
|
115 | |
|
|
116 | [ -z "${I_KNOW_WHAT_I_AM_DOING}" ] && \ |
| 113 | DEPEND="kernel_linux? ( virtual/linux-sources )" |
117 | DEPEND="kernel_linux? ( virtual/linux-sources )" |
| 114 | RDEPEND="" |
|
|
| 115 | |
118 | |
| 116 | # Overwritable environment Var's |
119 | # Overwritable environment Var's |
| 117 | # --------------------------------------- |
120 | # --------------------------------------- |
| 118 | KERNEL_DIR="${KERNEL_DIR:-${ROOT}usr/src/linux}" |
121 | KERNEL_DIR="${KERNEL_DIR:-${ROOT}usr/src/linux}" |
| 119 | |
122 | |
| … | |
… | |
| 200 | ERROR=0 |
203 | ERROR=0 |
| 201 | mycat='cat' |
204 | mycat='cat' |
| 202 | |
205 | |
| 203 | [ -z "${1}" ] && ERROR=1 |
206 | [ -z "${1}" ] && ERROR=1 |
| 204 | [ ! -f "${2}" ] && ERROR=1 |
207 | [ ! -f "${2}" ] && ERROR=1 |
| 205 | [ "${2#.gz}" != "${2}" ] && mycat='zcat' |
208 | [ "${2%.gz}" != "${2}" ] && mycat='zcat' |
| 206 | |
209 | |
| 207 | if [ "${ERROR}" = 1 ] |
210 | if [ "${ERROR}" = 1 ] |
| 208 | then |
211 | then |
| 209 | echo -e "\n" |
212 | echo -e "\n" |
| 210 | eerror "getfilevar_noexec requires 2 variables, with the second a valid file." |
213 | eerror "getfilevar_noexec requires 2 variables, with the second a valid file." |
| … | |
… | |
| 232 | # @FUNCTION: linux_config_bin_exists |
235 | # @FUNCTION: linux_config_bin_exists |
| 233 | # @RETURN: true or false |
236 | # @RETURN: true or false |
| 234 | # @DESCRIPTION: |
237 | # @DESCRIPTION: |
| 235 | # It returns true if .config exists in /proc, otherwise false |
238 | # It returns true if .config exists in /proc, otherwise false |
| 236 | linux_config_bin_exists() { |
239 | linux_config_bin_exists() { |
| 237 | [ -s "/proc/config.gz" ] |
240 | [ -n "${I_KNOW_WHAT_I_AM_DOING}" -a -s "/proc/config.gz" ] |
| 238 | } |
241 | } |
| 239 | |
242 | |
| 240 | # @FUNCTION: linux_config_exists |
243 | # @FUNCTION: linux_config_exists |
| 241 | # @RETURN: true or false |
244 | # @RETURN: true or false |
| 242 | # @DESCRIPTION: |
245 | # @DESCRIPTION: |
| … | |
… | |
| 349 | |
352 | |
| 350 | # got the jist yet? |
353 | # got the jist yet? |
| 351 | |
354 | |
| 352 | kernel_is() { |
355 | kernel_is() { |
| 353 | # if we haven't determined the version yet, we need to. |
356 | # if we haven't determined the version yet, we need to. |
| 354 | get_version |
357 | linux-info_get_any_version |
|
|
358 | |
| 355 | local operator test value x=0 y=0 z=0 |
359 | local operator test value x=0 y=0 z=0 |
| 356 | |
360 | |
| 357 | case ${1} in |
361 | case ${1} in |
| 358 | lt) operator="-lt"; shift;; |
362 | -lt|lt) operator="-lt"; shift;; |
| 359 | gt) operator="-gt"; shift;; |
363 | -gt|gt) operator="-gt"; shift;; |
| 360 | le) operator="-le"; shift;; |
364 | -le|le) operator="-le"; shift;; |
| 361 | ge) operator="-ge"; shift;; |
365 | -ge|ge) operator="-ge"; shift;; |
| 362 | eq) operator="-eq"; shift;; |
366 | -eq|eq) operator="-eq"; shift;; |
| 363 | *) operator="-eq";; |
367 | *) operator="-eq";; |
| 364 | esac |
368 | esac |
| 365 | |
369 | |
| 366 | for x in ${@}; do |
370 | for x in ${@}; do |
| 367 | for((y=0; y<$((3 - ${#x})); y++)); do value="${value}0"; done |
371 | for((y=0; y<$((3 - ${#x})); y++)); do value="${value}0"; done |
| 368 | value="${value}${x}" |
372 | value="${value}${x}" |
| … | |
… | |
| 376 | 3) for((y=0; y<$((3 - ${#KV_PATCH})); y++)); do test="${test}0"; done; |
380 | 3) for((y=0; y<$((3 - ${#KV_PATCH})); y++)); do test="${test}0"; done; |
| 377 | test="${test}${KV_PATCH}";; |
381 | test="${test}${KV_PATCH}";; |
| 378 | *) die "Error in kernel-2_kernel_is(): Too many parameters.";; |
382 | *) die "Error in kernel-2_kernel_is(): Too many parameters.";; |
| 379 | esac |
383 | esac |
| 380 | done |
384 | done |
| 381 | |
385 | |
| 382 | [ ${test} ${operator} ${value} ] && return 0 || return 1 |
386 | [ ${test} ${operator} ${value} ] && return 0 || return 1 |
| 383 | } |
387 | } |
| 384 | |
388 | |
| 385 | get_localversion() { |
389 | get_localversion() { |
| 386 | local lv_list i x |
390 | local lv_list i x |
| … | |
… | |
| 395 | done |
399 | done |
| 396 | x=${x/ /} |
400 | x=${x/ /} |
| 397 | echo ${x} |
401 | echo ${x} |
| 398 | } |
402 | } |
| 399 | |
403 | |
|
|
404 | # internal variable, so we know to only print the warning once |
|
|
405 | get_version_warning_done= |
|
|
406 | |
| 400 | # @FUNCTION: get_version |
407 | # @FUNCTION: get_version |
| 401 | # @DESCRIPTION: |
408 | # @DESCRIPTION: |
| 402 | # It gets the version of the kernel inside KERNEL_DIR and populates the KV_FULL variable |
409 | # It gets the version of the kernel inside KERNEL_DIR and populates the KV_FULL variable |
| 403 | # (if KV_FULL is already set it does nothing). |
410 | # (if KV_FULL is already set it does nothing). |
| 404 | # |
411 | # |
| … | |
… | |
| 417 | # if we dont know KV_FULL, then we need too. |
424 | # if we dont know KV_FULL, then we need too. |
| 418 | # make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR |
425 | # make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR |
| 419 | unset KV_DIR |
426 | unset KV_DIR |
| 420 | |
427 | |
| 421 | # KV_DIR will contain the full path to the sources directory we should use |
428 | # KV_DIR will contain the full path to the sources directory we should use |
|
|
429 | [ -z "${get_version_warning_done}" ] && \ |
| 422 | qeinfo "Determining the location of the kernel source code" |
430 | qeinfo "Determining the location of the kernel source code" |
| 423 | [ -h "${KERNEL_DIR}" ] && KV_DIR="$(readlink -f ${KERNEL_DIR})" |
431 | [ -h "${KERNEL_DIR}" ] && KV_DIR="$(readlink -f ${KERNEL_DIR})" |
| 424 | [ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}" |
432 | [ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}" |
| 425 | |
433 | |
| 426 | if [ -z "${KV_DIR}" ] |
434 | if [ -z "${KV_DIR}" ] |
| 427 | then |
435 | then |
|
|
436 | if [ -z "${get_version_warning_done}" ]; then |
|
|
437 | get_version_warning_done=1 |
| 428 | qeerror "Unable to find kernel sources at ${KERNEL_DIR}" |
438 | qeerror "Unable to find kernel sources at ${KERNEL_DIR}" |
| 429 | qeinfo "This package requires Linux sources." |
439 | #qeinfo "This package requires Linux sources." |
| 430 | if [ "${KERNEL_DIR}" == "/usr/src/linux" ] ; then |
440 | if [ "${KERNEL_DIR}" == "/usr/src/linux" ] ; then |
| 431 | qeinfo "Please make sure that ${KERNEL_DIR} points at your running kernel, " |
441 | qeinfo "Please make sure that ${KERNEL_DIR} points at your running kernel, " |
| 432 | qeinfo "(or the kernel you wish to build against)." |
442 | qeinfo "(or the kernel you wish to build against)." |
| 433 | qeinfo "Alternatively, set the KERNEL_DIR environment variable to the kernel sources location" |
443 | qeinfo "Alternatively, set the KERNEL_DIR environment variable to the kernel sources location" |
| 434 | else |
444 | else |
| 435 | qeinfo "Please ensure that the KERNEL_DIR environment variable points at full Linux sources of the kernel you wish to compile against." |
445 | qeinfo "Please ensure that the KERNEL_DIR environment variable points at full Linux sources of the kernel you wish to compile against." |
|
|
446 | fi |
| 436 | fi |
447 | fi |
| 437 | return 1 |
448 | return 1 |
| 438 | fi |
449 | fi |
| 439 | |
450 | |
|
|
451 | if [ -z "${get_version_warning_done}" ]; then |
| 440 | qeinfo "Found kernel source directory:" |
452 | qeinfo "Found kernel source directory:" |
| 441 | qeinfo " ${KV_DIR}" |
453 | qeinfo " ${KV_DIR}" |
|
|
454 | fi |
| 442 | |
455 | |
| 443 | if [ ! -s "${KV_DIR}/Makefile" ] |
456 | if [ ! -s "${KV_DIR}/Makefile" ] |
| 444 | then |
457 | then |
|
|
458 | if [ -z "${get_version_warning_done}" ]; then |
|
|
459 | get_version_warning_done=1 |
| 445 | qeerror "Could not find a Makefile in the kernel source directory." |
460 | qeerror "Could not find a Makefile in the kernel source directory." |
| 446 | qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources" |
461 | qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources" |
|
|
462 | fi |
| 447 | return 1 |
463 | return 1 |
| 448 | fi |
464 | fi |
| 449 | |
465 | |
| 450 | # OK so now we know our sources directory, but they might be using |
466 | # OK so now we know our sources directory, but they might be using |
| 451 | # KBUILD_OUTPUT, and we need this for .config and localversions-* |
467 | # KBUILD_OUTPUT, and we need this for .config and localversions-* |
| … | |
… | |
| 465 | KV_PATCH="$(getfilevar_noexec SUBLEVEL ${KV_DIR}/Makefile)" |
481 | KV_PATCH="$(getfilevar_noexec SUBLEVEL ${KV_DIR}/Makefile)" |
| 466 | KV_EXTRA="$(getfilevar_noexec EXTRAVERSION ${KV_DIR}/Makefile)" |
482 | KV_EXTRA="$(getfilevar_noexec EXTRAVERSION ${KV_DIR}/Makefile)" |
| 467 | |
483 | |
| 468 | if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ] |
484 | if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ] |
| 469 | then |
485 | then |
|
|
486 | if [ -z "${get_version_warning_done}" ]; then |
|
|
487 | get_version_warning_done=1 |
| 470 | qeerror "Could not detect kernel version." |
488 | qeerror "Could not detect kernel version." |
| 471 | qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources." |
489 | qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources." |
|
|
490 | fi |
| 472 | return 1 |
491 | return 1 |
| 473 | fi |
492 | fi |
| 474 | |
493 | |
| 475 | # and in newer versions we can also pull LOCALVERSION if it is set. |
494 | # and in newer versions we can also pull LOCALVERSION if it is set. |
| 476 | # but before we do this, we need to find if we use a different object directory. |
495 | # but before we do this, we need to find if we use a different object directory. |
| … | |
… | |
| 490 | fi |
509 | fi |
| 491 | # and if we STILL have not got it, then we better just set it to KV_DIR |
510 | # and if we STILL have not got it, then we better just set it to KV_DIR |
| 492 | KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}" |
511 | KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}" |
| 493 | |
512 | |
| 494 | KV_LOCAL="${KV_LOCAL}$(get_localversion ${KV_DIR})" |
513 | KV_LOCAL="${KV_LOCAL}$(get_localversion ${KV_DIR})" |
| 495 | if linux_config_exists; then |
514 | if linux_config_src_exists; then |
| 496 | KV_LOCAL="${KV_LOCAL}$(linux_chkconfig_string LOCALVERSION)" |
515 | KV_LOCAL="${KV_LOCAL}$(linux_chkconfig_string LOCALVERSION)" |
| 497 | KV_LOCAL="${KV_LOCAL//\"/}" |
516 | KV_LOCAL="${KV_LOCAL//\"/}" |
| 498 | |
517 | |
| 499 | # For things like git that can append extra stuff: |
518 | # For things like git that can append extra stuff: |
| 500 | [ -e ${KV_DIR}/scripts/setlocalversion ] && |
519 | [ -e ${KV_DIR}/scripts/setlocalversion ] && |
| … | |
… | |
| 537 | && KV_EXTRA="-${KV_FULL#*-}" |
556 | && KV_EXTRA="-${KV_FULL#*-}" |
| 538 | fi |
557 | fi |
| 539 | return 0 |
558 | return 0 |
| 540 | } |
559 | } |
| 541 | |
560 | |
|
|
561 | # This next function is named with the eclass prefix to avoid conflicts with |
|
|
562 | # some old versionator-like eclass functions. |
|
|
563 | |
|
|
564 | # @FUNCTION: linux-info_get_any_version |
|
|
565 | # @DESCRIPTION: |
|
|
566 | # This attempts to find the version of the sources, and otherwise falls back to |
|
|
567 | # the version of the running kernel. |
|
|
568 | linux-info_get_any_version() { |
|
|
569 | get_version |
|
|
570 | if [[ $? -ne 0 ]]; then |
|
|
571 | ewarn "Unable to calculate Linux Kernel version for build, attempting to use running version" |
|
|
572 | get_running_version |
|
|
573 | fi |
|
|
574 | } |
|
|
575 | |
| 542 | |
576 | |
| 543 | # ebuild check functions |
577 | # ebuild check functions |
| 544 | # --------------------------------------- |
578 | # --------------------------------------- |
| 545 | |
579 | |
| 546 | # @FUNCTION: check_kernel_built |
580 | # @FUNCTION: check_kernel_built |
| … | |
… | |
| 590 | check_extra_config() { |
624 | check_extra_config() { |
| 591 | local config negate die error reworkmodulenames |
625 | local config negate die error reworkmodulenames |
| 592 | local soft_errors_count=0 hard_errors_count=0 config_required=0 |
626 | local soft_errors_count=0 hard_errors_count=0 config_required=0 |
| 593 | |
627 | |
| 594 | # if we haven't determined the version yet, we need to |
628 | # if we haven't determined the version yet, we need to |
| 595 | get_version |
629 | linux-info_get_any_version |
| 596 | |
630 | |
| 597 | # Determine if we really need a .config. The only time when we don't need |
631 | # Determine if we really need a .config. The only time when we don't need |
| 598 | # one is when all of the CONFIG_CHECK options are prefixed with "~". |
632 | # one is when all of the CONFIG_CHECK options are prefixed with "~". |
| 599 | for config in ${CONFIG_CHECK} |
633 | for config in ${CONFIG_CHECK} |
| 600 | do |
634 | do |
| … | |
… | |
| 602 | config_required=1 |
636 | config_required=1 |
| 603 | break |
637 | break |
| 604 | fi |
638 | fi |
| 605 | done |
639 | done |
| 606 | |
640 | |
|
|
641 | # TODO: After we enable the new code for /proc/config.gz, we need to |
|
|
642 | # change this back to linux_config_exists. |
| 607 | if [[ ${config_required} == 0 ]]; then |
643 | if [[ ${config_required} == 0 ]]; then |
| 608 | # In the case where we don't require a .config, we can now bail out |
644 | # In the case where we don't require a .config, we can now bail out |
| 609 | # if the user has no .config as there is nothing to do. Otherwise |
645 | # if the user has no .config as there is nothing to do. Otherwise |
| 610 | # code later will cause a failure due to missing .config. |
646 | # code later will cause a failure due to missing .config. |
| 611 | if ! linux_config_exists; then |
647 | if ! linux_config_src_exists; then |
| 612 | ewarn "Unable to check for the following kernel config options due" |
648 | ewarn "Unable to check for the following kernel config options due" |
| 613 | ewarn "to absence of any configured kernel sources:" |
649 | ewarn "to absence of any configured kernel sources or compiled" |
|
|
650 | ewarn "config:" |
| 614 | for config in ${CONFIG_CHECK}; do |
651 | for config in ${CONFIG_CHECK}; do |
| 615 | ewarn " - ${config#\~}" |
652 | ewarn " - ${config#\~}" |
| 616 | done |
653 | done |
| 617 | ewarn "You're on your own to make sure they are set if needed." |
654 | ewarn "You're on your own to make sure they are set if needed." |
| 618 | return 0 |
655 | return 0 |
| 619 | fi |
656 | fi |
| 620 | else |
657 | else |
| 621 | require_configured_kernel |
658 | [ -n "${I_KNOW_WHAT_I_AM_DOING}" ] && require_configured_kernel |
| 622 | fi |
659 | fi |
| 623 | |
660 | |
| 624 | einfo "Checking for suitable kernel configuration options..." |
661 | einfo "Checking for suitable kernel configuration options..." |
| 625 | |
662 | |
| 626 | for config in ${CONFIG_CHECK} |
663 | for config in ${CONFIG_CHECK} |
| … | |
… | |
| 786 | # @FUNCTION: linux-info_pkg_setup |
823 | # @FUNCTION: linux-info_pkg_setup |
| 787 | # @DESCRIPTION: |
824 | # @DESCRIPTION: |
| 788 | # Force a get_version() call when inherited from linux-mod.eclass and then check if the kernel is configured |
825 | # Force a get_version() call when inherited from linux-mod.eclass and then check if the kernel is configured |
| 789 | # to support the options specified in CONFIG_CHECK (if not null) |
826 | # to support the options specified in CONFIG_CHECK (if not null) |
| 790 | linux-info_pkg_setup() { |
827 | linux-info_pkg_setup() { |
| 791 | get_version |
828 | linux-info_get_any_version |
| 792 | if [[ $rc -ne 0 ]]; then |
|
|
| 793 | ewarn "Unable to calculate Linux Kernel version for build, attempting to use running version" |
|
|
| 794 | get_running_version |
|
|
| 795 | fi |
|
|
| 796 | |
829 | |
| 797 | if kernel_is 2 4; then |
830 | if kernel_is 2 4; then |
| 798 | if [ "$( gcc-major-version )" -eq "4" ] ; then |
831 | if [ "$( gcc-major-version )" -eq "4" ] ; then |
| 799 | echo |
832 | echo |
| 800 | ewarn "Be warned !! >=sys-devel/gcc-4.0.0 isn't supported with" |
833 | ewarn "Be warned !! >=sys-devel/gcc-4.0.0 isn't supported with" |