--- /usr/portage/eclass/linux-info.eclass 2007-10-03 14:05:52.000000000 +0100 +++ /usr/local/portage/eclass/linux-info.eclass 2008-01-15 07:53:59.000000000 +0000 @@ -168,8 +168,8 @@ # got the jist yet? kernel_is() { - # if we haven't determined the version yet, we need too. - get_version; + # if we haven't determined the version yet, we need to. + get_version local operator test value x=0 y=0 z=0 case ${1} in @@ -215,91 +215,96 @@ echo ${x} } +declare -i linuxInfoGotCfg + +# Added -c option to check config as well (Bug 192556) +# This means it won't check for a config file without -c get_version() { - local kbuild_output + local kbuild_output getCfg=0 + [[ $1 = -c ]] && getCfg=1 # no need to execute this twice assuming KV_FULL is populated. - # we can force by unsetting KV_FULL - [ -n "${KV_FULL}" ] && return 0 - - # if we dont know KV_FULL, then we need too. - # make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR - unset KV_DIR - - # KV_DIR will contain the full path to the sources directory we should use - qeinfo "Determining the location of the kernel source code" - [ -h "${KERNEL_DIR}" ] && KV_DIR="$(readlink -f ${KERNEL_DIR})" - [ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}" - - if [ -z "${KV_DIR}" ] - then - qeerror "Unable to find kernel sources at ${KERNEL_DIR}" - qeinfo "This package requires Linux sources." - if [ "${KERNEL_DIR}" == "/usr/src/linux" ] ; then - qeinfo "Please make sure that ${KERNEL_DIR} points at your running kernel, " - qeinfo "(or the kernel you wish to build against)." - qeinfo "Alternatively, set the KERNEL_DIR environment variable to the kernel sources location" - else - qeinfo "Please ensure that the KERNEL_DIR environment variable points at full Linux sources of the kernel you wish to compile against." + # we can force by unsetting KV_FULL, or setting it empty + [[ $KV_FULL ]] && ((!getCfg||linuxInfoGotCfg)) && return 0 + [[ $KV_FULL ]] || { + # if we dont know KV_FULL, then we need too. + # make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR + unset KV_DIR + + # KV_DIR will contain the full path to the sources directory we should use + qeinfo "Determining the location of the kernel source code" + [ -h "${KERNEL_DIR}" ] && KV_DIR="$(readlink -f ${KERNEL_DIR})" + [ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}" + + if [ -z "${KV_DIR}" ] + then + qeerror "Unable to find kernel sources at ${KERNEL_DIR}" + qeinfo "This package requires Linux sources." + if [ "${KERNEL_DIR}" == "/usr/src/linux" ] ; then + qeinfo "Please make sure that ${KERNEL_DIR} points at your running kernel, " + qeinfo "(or the kernel you wish to build against)." + qeinfo "Alternatively, set the KERNEL_DIR environment variable to the kernel sources location" + else + qeinfo "Please ensure that the KERNEL_DIR environment variable points at full Linux sources of the kernel you wish to compile against." + fi + return 1 fi - return 1 - fi - - qeinfo "Found kernel source directory:" - qeinfo " ${KV_DIR}" - - if [ ! -s "${KV_DIR}/Makefile" ] - then - qeerror "Could not find a Makefile in the kernel source directory." - qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources" - return 1 - fi - - # OK so now we know our sources directory, but they might be using - # KBUILD_OUTPUT, and we need this for .config and localversions-* - # so we better find it eh? - # do we pass KBUILD_OUTPUT on the CLI? - OUTPUT_DIR="${OUTPUT_DIR:-${KBUILD_OUTPUT}}" - - # And if we didn't pass it, we can take a nosey in the Makefile - kbuild_output="$(getfilevar KBUILD_OUTPUT ${KV_DIR}/Makefile)" - OUTPUT_DIR="${OUTPUT_DIR:-${kbuild_output}}" - - # And contrary to existing functions I feel we shouldn't trust the - # directory name to find version information as this seems insane. - # so we parse ${KV_DIR}/Makefile - KV_MAJOR="$(getfilevar VERSION ${KV_DIR}/Makefile)" - KV_MINOR="$(getfilevar PATCHLEVEL ${KV_DIR}/Makefile)" - KV_PATCH="$(getfilevar SUBLEVEL ${KV_DIR}/Makefile)" - KV_EXTRA="$(getfilevar EXTRAVERSION ${KV_DIR}/Makefile)" - - if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ] - then - qeerror "Could not detect kernel version." - qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources." - return 1 - fi - - # and in newer versions we can also pull LOCALVERSION if it is set. - # but before we do this, we need to find if we use a different object directory. - # This *WILL* break if the user is using localversions, but we assume it was - # caught before this if they are. - [ "${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}" == "$(uname -r)" ] && \ - OUTPUT_DIR="${OUTPUT_DIR:-/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build}" - - [ -h "${OUTPUT_DIR}" ] && KV_OUT_DIR="$(readlink -f ${OUTPUT_DIR})" - [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}" - if [ -n "${KV_OUT_DIR}" ]; - then - qeinfo "Found kernel object directory:" - qeinfo " ${KV_OUT_DIR}" - - KV_LOCAL="$(get_localversion ${KV_OUT_DIR})" - fi - # and if we STILL have not got it, then we better just set it to KV_DIR - KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}" - - if [ ! -s "${KV_OUT_DIR}/.config" ] + + qeinfo "Found kernel source directory:" + qeinfo " ${KV_DIR}" + + if [ ! -s "${KV_DIR}/Makefile" ] + then + qeerror "Could not find a Makefile in the kernel source directory." + qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources" + return 1 + fi + + # OK so now we know our sources directory, but they might be using + # KBUILD_OUTPUT, and we need this for .config and localversions-* + # so we better find it eh? + # do we pass KBUILD_OUTPUT on the CLI? + OUTPUT_DIR="${OUTPUT_DIR:-${KBUILD_OUTPUT}}" + + # And if we didn't pass it, we can take a nosey in the Makefile + kbuild_output="$(getfilevar KBUILD_OUTPUT ${KV_DIR}/Makefile)" + OUTPUT_DIR="${OUTPUT_DIR:-${kbuild_output}}" + + # And contrary to existing functions I feel we shouldn't trust the + # directory name to find version information as this seems insane. + # so we parse ${KV_DIR}/Makefile + KV_MAJOR="$(getfilevar VERSION ${KV_DIR}/Makefile)" + KV_MINOR="$(getfilevar PATCHLEVEL ${KV_DIR}/Makefile)" + KV_PATCH="$(getfilevar SUBLEVEL ${KV_DIR}/Makefile)" + KV_EXTRA="$(getfilevar EXTRAVERSION ${KV_DIR}/Makefile)" + + if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ] + then + qeerror "Could not detect kernel version." + qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources." + return 1 + fi + + # and in newer versions we can also pull LOCALVERSION if it is set. + # but before we do this, we need to find if we use a different object directory. + # This *WILL* break if the user is using localversions, but we assume it was + # caught before this if they are. + [ "${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}" == "$(uname -r)" ] && \ + OUTPUT_DIR="${OUTPUT_DIR:-/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build}" + + [ -h "${OUTPUT_DIR}" ] && KV_OUT_DIR="$(readlink -f ${OUTPUT_DIR})" + [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}" + if [ -n "${KV_OUT_DIR}" ]; + then + qeinfo "Found kernel object directory:" + qeinfo " ${KV_OUT_DIR}" + + KV_LOCAL="$(get_localversion ${KV_OUT_DIR})" + fi + # and if we STILL have not got it, then we better just set it to KV_DIR + KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}" + } + if ((getCfg)) && [ ! -s "${KV_OUT_DIR}/.config" ] then qeerror "Could not find a usable .config in the kernel source directory." qeerror "Please ensure that ${KERNEL_DIR} points to a configured set of Linux sources." @@ -309,20 +314,20 @@ fi KV_LOCAL="${KV_LOCAL}$(get_localversion ${KV_DIR})" - KV_LOCAL="${KV_LOCAL}$(linux_chkconfig_string LOCALVERSION)" + ((getCfg)) && KV_LOCAL="${KV_LOCAL}$(linux_chkconfig_string LOCALVERSION)" KV_LOCAL="${KV_LOCAL//\"/}" # For things like git that can append extra stuff: - [ -e ${KV_DIR}/scripts/setlocalversion ] && + ((getCfg)) && [[ -e ${KV_DIR}/scripts/setlocalversion ]] && linux_chkconfig_builtin LOCALVERSION_AUTO && - KV_LOCAL="${KV_LOCAL}$(sh ${KV_DIR}/scripts/setlocalversion ${KV_DIR})" + KV_LOCAL="${KV_LOCAL}$(sh ${KV_DIR}/scripts/setlocalversion ${KV_DIR})" # And we should set KV_FULL to the full expanded version KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}" qeinfo "Found sources for kernel version:" qeinfo " ${KV_FULL}" - + ((getCfg)) && linuxInfoGotCfg=1 return 0 } @@ -356,7 +361,7 @@ check_kernel_built() { # if we haven't determined the version yet, we need too. - get_version; + get_version if [ ! -f "${KV_OUT_DIR}/include/linux/version.h" ] then @@ -374,8 +379,7 @@ } check_modules_supported() { - # if we haven't determined the version yet, we need too. - get_version; + get_version -c || die 'No kernel config' if ! linux_chkconfig_builtin "MODULES" then @@ -390,8 +394,7 @@ local config negate die error reworkmodulenames local soft_errors_count=0 hard_errors_count=0 - # if we haven't determined the version yet, we need too. - get_version; + get_version -c || die 'No kernel config' einfo "Checking for suitable kernel configuration options..." for config in ${CONFIG_CHECK} @@ -482,8 +485,7 @@ } check_zlibinflate() { - # if we haven't determined the version yet, we need too. - get_version; + get_version -c || die 'No kernel config' # although I restructured this code - I really really really dont support it! @@ -555,7 +557,10 @@ # Also used when inheriting linux-mod to force a get_version call linux-info_pkg_setup() { - get_version || die "Unable to calculate Linux Kernel version" + if [[ $CONFIG_CHECK ]]; then + get_version -c || die 'No kernel config' + else get_version + fi if kernel_is 2 4; then if [ "$( gcc-major-version )" -eq "4" ] ; then @@ -573,5 +578,5 @@ fi fi - [ -n "${CONFIG_CHECK}" ] && check_extra_config; + [[ $CONFIG_CHECK ]] && check_extra_config }