View | Details | Raw Unified
Collapse All | Expand All

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