Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 87242 | Differences between
and this patch

Collapse All | Expand All

(-)linux-info-1.83.eclass (-26 / +100 lines)
Lines 430-435 get_makefile_extract_function() { Link Here
430
# internal variable, so we know to only print the warning once
430
# internal variable, so we know to only print the warning once
431
get_version_warning_done=
431
get_version_warning_done=
432
432
433
check_kbuild_output() {
434
	if [ ! -s "${KBUILD_OUTPUT}/Makefile" ]; then
435
		if [ -z "${get_version_warning_done}" ]; then
436
			get_version_warning_done=1
437
			qeerror "Could not find a Makefile in the kernel build directory."
438
			qeerror "Please ensure that ${KBUILD_OUTPUT} points to an initialized"
439
			qeerror "kernel output directory."
440
		fi
441
		return 1
442
	else
443
		local make_args="$(getfilevar MAKEARGS ${KBUILD_OUTPUT}/Makefile)"
444
		if [ -n "${make_args}" ]; then
445
			# 2.6.25 or more recent Makefile of KBUILD_OUTPUT
446
			[ -z "${get_version_warning_done}" ] && \
447
				qeinfo "This KBUILD_OUTPUT makefile looks like 2.6.25 or more recent format"
448
			OUTPUT_DIR=$(echo ${make_args} | sed -r -e 's:^(.* )?O=([^ ]*)/\.( .*)?$:\2:')
449
			KV_DIR=$(echo ${make_args} | sed -r -e 's:^(.* )?-C ([^ ]*)/? .*$:\2:')
450
		else
451
			# Attempt vars as in KBUILD_OUTPUT Makefile of older kernels
452
			OUTPUT_DIR="$(getfilevar_noexec KERNELOUTPUT ${KBUILD_OUTPUT}/Makefile)"
453
			KV_DIR="$(getfilevar_noexec KERNELSRC ${KBUILD_OUTPUT}/Makefile)"
454
		fi
455
		if [ -z "${KV_DIR}" ] && [ -n "$(getfilevar_noexec SUBLEVEL ${KBUILD_OUTPUT}/Makefile)" ]; then
456
			# KBUILD_OUTPUT is the same as KERNEL_DIR
457
			OUTPUT_DIR="${KBUILD_OUTPUT}"
458
			KV_DIR="${KBUILD_OUTPUT}"
459
		elif [ -z "${KV_DIR}" ]; then
460
			if [ -z "${get_version_warning_done}" ]; then
461
				get_version_warning_done=1
462
				qeerror "Can't figure out anything out of ${KBUILD_OUTPUT},"
463
				qeerror "make sure it points to a valid kernel object tree or"
464
				qeerror "kernel source tree if you build in tree."
465
			fi
466
			return 1
467
		fi
468
	fi
469
	return 0
470
}
471
433
# @FUNCTION: get_version
472
# @FUNCTION: get_version
434
# @DESCRIPTION:
473
# @DESCRIPTION:
435
# It gets the version of the kernel inside KERNEL_DIR and populates the KV_FULL variable
474
# It gets the version of the kernel inside KERNEL_DIR and populates the KV_FULL variable
Lines 450-462 get_version() { Link Here
450
	# if we dont know KV_FULL, then we need too.
489
	# if we dont know KV_FULL, then we need too.
451
	# make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR
490
	# make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR
452
	unset KV_DIR
491
	unset KV_DIR
492
	unset OUTPUT_DIR
453
493
454
	# KV_DIR will contain the full path to the sources directory we should use
455
	[ -z "${get_version_warning_done}" ] && \
494
	[ -z "${get_version_warning_done}" ] && \
456
	qeinfo "Determining the location of the kernel source code"
495
	qeinfo "Determining the location of the kernel source code"
457
	[ -h "${KERNEL_DIR}" ] && KV_DIR="$(readlink -f ${KERNEL_DIR})"
458
	[ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}"
459
496
497
	if [ -n "${KBUILD_OUTPUT}" ]; then
498
		check_kbuild_output || return 1
499
	fi
500
501
	if [ -z "${KV_DIR}" ]; then
502
		# KV_DIR will contain the full path to the sources directory we should use
503
		[ -h "${KERNEL_DIR}" ] && KV_DIR="$(readlink -f ${KERNEL_DIR})"
504
		[ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}"
505
	fi
460
	if [ -z "${KV_DIR}" ]
506
	if [ -z "${KV_DIR}" ]
461
	then
507
	then
462
		if [ -z "${get_version_warning_done}" ]; then
508
		if [ -z "${get_version_warning_done}" ]; then
Lines 484-510 get_version() { Link Here
484
		if [ -z "${get_version_warning_done}" ]; then
530
		if [ -z "${get_version_warning_done}" ]; then
485
			get_version_warning_done=1
531
			get_version_warning_done=1
486
			qeerror "Could not find a Makefile in the kernel source directory."
532
			qeerror "Could not find a Makefile in the kernel source directory."
487
			qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources"
533
			qeerror "Please ensure that ${KV_DIR} points to a complete set of Linux sources"
488
		fi
534
		fi
489
		return 1
535
		return 1
490
	fi
536
	fi
491
537
492
	# OK so now we know our sources directory, but they might be using
493
	# KBUILD_OUTPUT, and we need this for .config and localversions-*
494
	# so we better find it eh?
495
	# do we pass KBUILD_OUTPUT on the CLI?
496
	OUTPUT_DIR="${OUTPUT_DIR:-${KBUILD_OUTPUT}}"
497
498
	# keep track of it
538
	# keep track of it
499
	KERNEL_MAKEFILE="${KV_DIR}/Makefile"
539
	KERNEL_MAKEFILE="${KV_DIR}/Makefile"
500
	
540
501
	# Decide the function used to extract makefile variables.
541
	# Decide the function used to extract makefile variables.
502
	mkfunc="$(get_makefile_extract_function "${KERNEL_MAKEFILE}")"
542
	mkfunc="$(get_makefile_extract_function "${KERNEL_MAKEFILE}")"
503
543
504
	# And if we didn't pass it, we can take a nosey in the Makefile
505
	kbuild_output="$(${mkfunc} KBUILD_OUTPUT ${KERNEL_MAKEFILE})"
506
	OUTPUT_DIR="${OUTPUT_DIR:-${kbuild_output}}"
507
508
	# And contrary to existing functions I feel we shouldn't trust the
544
	# And contrary to existing functions I feel we shouldn't trust the
509
	# directory name to find version information as this seems insane.
545
	# directory name to find version information as this seems insane.
510
	# so we parse ${KERNEL_MAKEFILE}
546
	# so we parse ${KERNEL_MAKEFILE}
Lines 513-534 get_version() { Link Here
513
	KV_PATCH="$(${mkfunc} SUBLEVEL ${KERNEL_MAKEFILE})"
549
	KV_PATCH="$(${mkfunc} SUBLEVEL ${KERNEL_MAKEFILE})"
514
	KV_EXTRA="$(${mkfunc} EXTRAVERSION ${KERNEL_MAKEFILE})"
550
	KV_EXTRA="$(${mkfunc} EXTRAVERSION ${KERNEL_MAKEFILE})"
515
551
552
	if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ]; then
553
		qewarn "It was not a kernel source directory, checking as kernel object directory"
554
		KBUILD_OUTPUT=${KV_DIR}
555
		if check_kbuild_output; then
556
			if [ -z "${get_version_warning_done}" ]; then
557
				qeinfo "Found kernel source directory:"
558
				qeinfo "    ${KV_DIR}"
559
			fi
560
561
			# KV_DIR has changed so update both
562
			KERNEL_MAKEFILE="${KV_DIR}/Makefile"
563
			mkfunc="$(get_makefile_extract_function "${KERNEL_MAKEFILE}")"
564
565
			KV_MAJOR="$(${mkfunc} VERSION ${KV_DIR}/Makefile)"
566
			KV_MINOR="$(${mkfunc} PATCHLEVEL ${KV_DIR}/Makefile)"
567
			KV_PATCH="$(${mkfunc} SUBLEVEL ${KV_DIR}/Makefile)"
568
			KV_EXTRA="$(${mkfunc} EXTRAVERSION ${KV_DIR}/Makefile)"
569
		fi
570
	fi
516
	if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ]
571
	if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ]
517
	then
572
	then
518
		if [ -z "${get_version_warning_done}" ]; then
573
		if [ -z "${get_version_warning_done}" ]; then
519
			get_version_warning_done=1
574
			get_version_warning_done=1
520
			qeerror "Could not detect kernel version."
575
			qeerror "Could not detect kernel version."
521
			qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources."
576
			qeerror "Please ensure that ${KV_DIR} points to a complete set of Linux sources."
522
		fi
577
		fi
523
		return 1
578
		return 1
579
	elif [ -z "${OUTPUT_DIR}" -a -s "${KV_DIR}/.config" ]; then
580
		# Default to in-tree build if nothing was indicated
581
		OUTPUT_DIR="${KV_DIR}"
524
	fi
582
	fi
525
583
526
	# and in newer versions we can also pull LOCALVERSION if it is set.
527
	# but before we do this, we need to find if we use a different object directory.
528
	# This *WILL* break if the user is using localversions, but we assume it was
529
	# caught before this if they are.
530
	OUTPUT_DIR="${OUTPUT_DIR:-/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build}"
531
532
	[ -h "${OUTPUT_DIR}" ] && KV_OUT_DIR="$(readlink -f ${OUTPUT_DIR})"
584
	[ -h "${OUTPUT_DIR}" ] && KV_OUT_DIR="$(readlink -f ${OUTPUT_DIR})"
533
	[ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}"
585
	[ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}"
534
	if [ -n "${KV_OUT_DIR}" ];
586
	if [ -n "${KV_OUT_DIR}" ];
Lines 568-583 get_version() { Link Here
568
get_running_version() {
620
get_running_version() {
569
	KV_FULL=$(uname -r)
621
	KV_FULL=$(uname -r)
570
622
623
	get_version_warning_done=
571
	if [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile ]]; then
624
	if [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile ]]; then
572
		KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
625
		KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
626
		if [[ -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
627
			KBUILD_OUTPUT=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
628
		fi
573
		unset KV_FULL
629
		unset KV_FULL
574
		get_version
630
		if get_version; then
575
		return $?
631
			if [[ "$(uname -r)" = "${KV_FULL}" ]]; then
632
				return 0
633
			else
634
				qewarn "Kernel sources have changed since kernel was built"
635
				qewarn "git tree updated or patch applied?"
636
				return 0
637
			fi
638
		else
639
			return $?
640
		fi
576
	elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
641
	elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
577
		KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
642
		KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
578
		unset KV_FULL
643
		unset KV_FULL
579
		get_version
644
		if get_version; then
580
		return $?
645
			if [[ "$(uname -r)" = "${KV_FULL}" ]]; then
646
				return 0
647
			else
648
				qewarn "Kernel sources have changed since kernel was built"
649
				qewarn "git tree updated or patch applied?"
650
				return 0
651
			fi
652
		else
653
			return $?
654
		fi
581
	else
655
	else
582
		KV_MAJOR=$(get_version_component_range 1 ${KV_FULL})
656
		KV_MAJOR=$(get_version_component_range 1 ${KV_FULL})
583
		KV_MINOR=$(get_version_component_range 2 ${KV_FULL})
657
		KV_MINOR=$(get_version_component_range 2 ${KV_FULL})

Return to bug 87242