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.81.eclass (-34 / +77 lines)
Lines 148-153 qout() { Link Here
148
}
148
}
149
149
150
qeinfo() { qout einfo "${@}" ; }
150
qeinfo() { qout einfo "${@}" ; }
151
qewarn() { qout ewarn "$@" ; }
151
qeerror() { qout eerror "${@}" ; }
152
qeerror() { qout eerror "${@}" ; }
152
153
153
# File Functions
154
# File Functions
Lines 208-214 getfilevar_noexec() { Link Here
208
	else
209
	else
209
		${mycat} "${2}" | \
210
		${mycat} "${2}" | \
210
		sed -n \
211
		sed -n \
211
		-e "/^[[:space:]]*${1}[[:space:]]*=[[:space:]]*\(.*\)\$/{ 
212
		-e "/^[[:space:]]*${1}[[:space:]]*:\\?=[[:space:]]*\(.*\)\$/{ 
212
			s,^[^=]*[[:space:]]*=[[:space:]]*,,g ;
213
			s,^[^=]*[[:space:]]*=[[:space:]]*,,g ;
213
			s,[[:space:]]*\$,,g ;
214
			s,[[:space:]]*\$,,g ;
214
			p
215
			p
Lines 414-419 get_localversion() { Link Here
414
# internal variable, so we know to only print the warning once
415
# internal variable, so we know to only print the warning once
415
get_version_warning_done=
416
get_version_warning_done=
416
417
418
check_kbuild_output() {
419
	if [ ! -s "${KBUILD_OUTPUT}/Makefile" ]; then
420
		if [ -z "${get_version_warning_done}" ]; then
421
			get_version_warning_done=1
422
			qeerror "Could not find a Makefile in the kernel build directory."
423
			qeerror "Please ensure that ${KBUILD_OUTPUT} points to an initialized"
424
			qeerror "kernel output directory."
425
		fi
426
		return 1
427
	else
428
		local make_args="$(getfilevar MAKEARGS ${KBUILD_OUTPUT}/Makefile)"
429
		if [ -n "${make_args}" ]; then
430
			# 2.6.25 or more recent Makefile of KBUILD_OUTPUT
431
			[ -z "${get_version_warning_done}" ] && \
432
				qeinfo "This KBUILD_OUTPUT makefile looks like 2.6.25 or more recent format"
433
			OUTPUT_DIR=$(echo ${make_args} | sed -r -e 's:^(.* )?O=([^ ]*)/\.( .*)?$:\2:')
434
			KV_DIR=$(echo ${make_args} | sed -r -e 's:^(.* )?-C ([^ ]*)/? .*$:\2:')
435
		else
436
			# Attempt vars as in KBUILD_OUTPUT Makefile of older kernels
437
			OUTPUT_DIR="$(getfilevar_noexec KERNELOUTPUT ${KBUILD_OUTPUT}/Makefile)"
438
			KV_DIR="$(getfilevar_noexec KERNELSRC ${KBUILD_OUTPUT}/Makefile)"
439
		fi
440
		if [ -z "${KV_DIR}" ] && [ -n "$(getfilevar_noexec SUBLEVEL ${KBUILD_OUTPUT}/Makefile)" ]; then
441
			# KBUILD_OUTPUT is the same as KERNEL_DIR
442
			OUTPUT_DIR="${KBUILD_OUTPUT}"
443
			KV_DIR="${KBUILD_OUTPUT}"
444
		elif [ -z "${KV_DIR}" ]; then
445
			if [ -z "${get_version_warning_done}" ]; then
446
				get_version_warning_done=1
447
				qeerror "Can't figure out anything out of ${KBUILD_OUTPUT},"
448
				qeerror "make sure it points to a valid kernel object tree or"
449
				qeerror "kernel source tree if you build in tree."
450
			fi
451
			return 1
452
		fi
453
	fi
454
	return 0
455
}
456
417
# @FUNCTION: get_version
457
# @FUNCTION: get_version
418
# @DESCRIPTION:
458
# @DESCRIPTION:
419
# It gets the version of the kernel inside KERNEL_DIR and populates the KV_FULL variable
459
# It gets the version of the kernel inside KERNEL_DIR and populates the KV_FULL variable
Lines 434-446 get_version() { Link Here
434
	# if we dont know KV_FULL, then we need too.
474
	# if we dont know KV_FULL, then we need too.
435
	# make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR
475
	# make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR
436
	unset KV_DIR
476
	unset KV_DIR
477
	unset OUTPUT_DIR
437
478
438
	# KV_DIR will contain the full path to the sources directory we should use
439
	[ -z "${get_version_warning_done}" ] && \
479
	[ -z "${get_version_warning_done}" ] && \
440
	qeinfo "Determining the location of the kernel source code"
480
	qeinfo "Determining the location of the kernel source code"
441
	[ -h "${KERNEL_DIR}" ] && KV_DIR="$(readlink -f ${KERNEL_DIR})"
442
	[ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}"
443
481
482
	if [ -n "${KBUILD_OUTPUT}" ]; then
483
		check_kbuild_output || return 1
484
	fi
485
486
	if [ -z "${KV_DIR}" ]; then
487
		# KV_DIR will contain the full path to the sources directory we should use
488
		[ -h "${KERNEL_DIR}" ] && KV_DIR="$(readlink -f ${KERNEL_DIR})"
489
		[ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}"
490
	fi
444
	if [ -z "${KV_DIR}" ]
491
	if [ -z "${KV_DIR}" ]
445
	then
492
	then
446
		if [ -z "${get_version_warning_done}" ]; then
493
		if [ -z "${get_version_warning_done}" ]; then
Lines 466-471 get_version() { Link Here
466
	if [ ! -s "${KV_DIR}/Makefile" ]
513
	if [ ! -s "${KV_DIR}/Makefile" ]
467
	then
514
	then
468
		if [ -z "${get_version_warning_done}" ]; then
515
		if [ -z "${get_version_warning_done}" ]; then
516
			qewarn "${KV_DIR}/Makefile does not exist/is empty"
469
			get_version_warning_done=1
517
			get_version_warning_done=1
470
			qeerror "Could not find a Makefile in the kernel source directory."
518
			qeerror "Could not find a Makefile in the kernel source directory."
471
			qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources"
519
			qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources"
Lines 473-511 get_version() { Link Here
473
		return 1
521
		return 1
474
	fi
522
	fi
475
523
476
	# OK so now we know our sources directory, but they might be using
477
	# KBUILD_OUTPUT, and we need this for .config and localversions-*
478
	# so we better find it eh?
479
	# do we pass KBUILD_OUTPUT on the CLI?
480
	OUTPUT_DIR="${OUTPUT_DIR:-${KBUILD_OUTPUT}}"
481
482
	# keep track of it
483
	KERNEL_MAKEFILE="${KV_DIR}/Makefile"
484
485
	# Check if the Makefile is valid for direct parsing.
486
	# Check status results:
487
	# - PASS, use 'getfilevar' to extract values
488
	# - FAIL, use 'getfilevar_noexec' to extract values
489
	# The check may fail if:
490
	# - make is not present
491
	# - corruption exists in the kernel makefile
492
	local a='' b='' mkfunc='getfilevar'
493
	a="$(getfilevar VERSION ${KERNEL_MAKEFILE})"
494
	b="$(getfilevar_noexec VERSION ${KERNEL_MAKEFILE})"
495
	[[ "${a}" != "${b}" ]] && mkfunc='getfilevar_noexec'
496
497
	# And if we didn't pass it, we can take a nosey in the Makefile
498
	kbuild_output="$(${mkfunc} KBUILD_OUTPUT ${KERNEL_MAKEFILE})"
499
	OUTPUT_DIR="${OUTPUT_DIR:-${kbuild_output}}"
500
501
	# And contrary to existing functions I feel we shouldn't trust the
524
	# And contrary to existing functions I feel we shouldn't trust the
502
	# directory name to find version information as this seems insane.
525
	# directory name to find version information as this seems insane.
503
	# so we parse ${KERNEL_MAKEFILE}
526
	# so we parse ${KV_DIR}/Makefile
504
	KV_MAJOR="$(${mkfunc} VERSION ${KERNEL_MAKEFILE})"
527
	KV_MAJOR="$(getfilevar_noexec VERSION ${KV_DIR}/Makefile)"
505
	KV_MINOR="$(${mkfunc} PATCHLEVEL ${KERNEL_MAKEFILE})"
528
	KV_MINOR="$(getfilevar_noexec PATCHLEVEL ${KV_DIR}/Makefile)"
506
	KV_PATCH="$(${mkfunc} SUBLEVEL ${KERNEL_MAKEFILE})"
529
	KV_PATCH="$(getfilevar_noexec SUBLEVEL ${KV_DIR}/Makefile)"
507
	KV_EXTRA="$(${mkfunc} EXTRAVERSION ${KERNEL_MAKEFILE})"
530
	KV_EXTRA="$(getfilevar_noexec EXTRAVERSION ${KV_DIR}/Makefile)"
531
532
	if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ]; then
533
		qewarn "It was not a kernel source directory, checking as kernel object directory"
534
		KBUILD_OUTPUT=${KV_DIR}
535
		if check_kbuild_output; then
536
			if [ -z "${get_version_warning_done}" ]; then
537
				qeinfo "Found kernel source directory:"
538
				qeinfo "    ${KV_DIR}"
539
			fi
508
540
541
			KV_MAJOR="$(getfilevar_noexec VERSION ${KV_DIR}/Makefile)"
542
			KV_MINOR="$(getfilevar_noexec PATCHLEVEL ${KV_DIR}/Makefile)"
543
			KV_PATCH="$(getfilevar_noexec SUBLEVEL ${KV_DIR}/Makefile)"
544
			KV_EXTRA="$(getfilevar_noexec EXTRAVERSION ${KV_DIR}/Makefile)"
545
		fi
546
	fi
509
	if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ]
547
	if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ]
510
	then
548
	then
511
		if [ -z "${get_version_warning_done}" ]; then
549
		if [ -z "${get_version_warning_done}" ]; then
Lines 514-519 get_version() { Link Here
514
			qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources."
552
			qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources."
515
		fi
553
		fi
516
		return 1
554
		return 1
555
	elif [ -z "${OUTPUT_DIR}" -a -s "${KV_DIR}/.config" ]; then
556
		OUTPUT_DIR="${KV_DIR}"
517
	fi
557
	fi
518
558
519
	# and in newer versions we can also pull LOCALVERSION if it is set.
559
	# and in newer versions we can also pull LOCALVERSION if it is set.
Lines 563-568 get_running_version() { Link Here
563
603
564
	if [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile ]]; then
604
	if [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile ]]; then
565
		KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
605
		KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
606
		if [[ -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
607
			KBUILD_OUTPUT=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
608
		fi
566
		unset KV_FULL
609
		unset KV_FULL
567
		get_version
610
		get_version
568
		return $?
611
		return $?

Return to bug 87242