summaryrefslogtreecommitdiff
blob: 539026f9896499fa8ebe1dcad4ea6113b17e72a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.56 2008/10/31 22:01:32 dsd Exp $
#
# Original author: John Mylchreest <johnm@gentoo.org>
# Maintainer: kernel-misc@gentoo.org
#
# Please direct your bugs to the current eclass maintainer :)

# @ECLASS: linux-info.eclass
# @MAINTAINER:
# kernel-misc@gentoo.org
# @BLURB: eclass used for accessing kernel related information
# @DESCRIPTION:
# This eclass is used as a central eclass for accessing kernel
# related information for sources already installed.
# It is vital for linux-mod.eclass to function correctly, and is split
# out so that any ebuild behaviour "templates" are abstracted out
# using additional eclasses.

# A Couple of env vars are available to effect usage of this eclass
# These are as follows:

# @ECLASS-VARIABLE: KERNEL_DIR
# @DESCRIPTION:
# A string containing the directory of the target kernel sources. The default value is
# "/usr/src/linux"

# @ECLASS-VARIABLE: CONFIG_CHECK
# @DESCRIPTION:
# A string containing a list of .config options to check for before
# proceeding with the install.
#
#   e.g.: CONFIG_CHECK="MTRR"
#
# You can also check that an option doesn't exist by
# prepending it with an exclamation mark (!).
#
#   e.g.: CONFIG_CHECK="!MTRR"
#
# To simply warn about a missing option, prepend a '~'.

# @ECLASS-VARIABLE: ERROR_<CFG>
# @DESCRIPTION:
# A string containing the error message to display when the check against CONFIG_CHECK
# fails. <CFG> should reference the appropriate option used in CONFIG_CHECK.
#
#   e.g.: ERROR_MTRR="MTRR exists in the .config but shouldn't!!"

# @ECLASS-VARIABLE: KBUILD_OUTPUT
# @DESCRIPTION:
# A string passed on commandline, or set from the kernel makefile. It contains the directory
# which is to be used as the kernel object directory.

# There are also a couple of variables which are set by this, and shouldn't be
# set by hand. These are as follows:

# @ECLASS-VARIABLE: KV_FULL
# @DESCRIPTION:
# A read-only variable. It's a string containing the full kernel version. ie: 2.6.9-gentoo-johnm-r1

# @ECLASS-VARIABLE: KV_MAJOR
# @DESCRIPTION:
# A read-only variable. It's an integer containing the kernel major version. ie: 2

# @ECLASS-VARIABLE: KV_MINOR
# @DESCRIPTION:
# A read-only variable. It's an integer containing the kernel minor version. ie: 6

# @ECLASS-VARIABLE: KV_PATCH
# @DESCRIPTION:
# A read-only variable. It's an integer containing the kernel patch version. ie: 9

# @ECLASS-VARIABLE: KV_EXTRA
# @DESCRIPTION:
# A read-only variable. It's a string containing the kernel EXTRAVERSION. ie: -gentoo

# @ECLASS-VARIABLE: KV_LOCAL
# @DESCRIPTION:
# A read-only variable. It's a string containing the kernel LOCALVERSION concatenation. ie: -johnm

# @ECLASS-VARIABLE: KV_DIR
# @DESCRIPTION:
# A read-only variable. It's a string containing the kernel source directory, will be null if
# KERNEL_DIR is invalid.

# @ECLASS-VARIABLE: KV_OUT_DIR
# @DESCRIPTION:
# A read-only variable. It's a string containing the kernel object directory, will be KV_DIR unless
# KBUILD_OUTPUT is used. This should be used for referencing .config.

# And to ensure all the weirdness with crosscompile
inherit toolchain-funcs versionator

EXPORT_FUNCTIONS pkg_setup

DEPEND="kernel_linux? ( virtual/linux-sources )"
RDEPEND=""

# Overwritable environment Var's
# ---------------------------------------
KERNEL_DIR="${KERNEL_DIR:-${ROOT}usr/src/linux}"


# Bug fixes
# fix to bug #75034
case ${ARCH} in
	ppc)	BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";;
	ppc64)	BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";;
esac

# @FUNCTION: set_arch_to_kernel
# @DESCRIPTION:
# Set the env ARCH to match what the kernel expects.
set_arch_to_kernel() { export ARCH=$(tc-arch-kernel); }
# @FUNCTION: set_arch_to_portage
# @DESCRIPTION:
# Set the env ARCH to match what portage expects.
set_arch_to_portage() { export ARCH=$(tc-arch); }

# qeinfo "Message"
# -------------------
# qeinfo is a quiet einfo call when EBUILD_PHASE
# should not have visible output.
qout() {
	local outputmsg type
	type=${1}
	shift
	outputmsg="${@}"
	case "${EBUILD_PHASE}" in
		depend)  unset outputmsg;;
		clean)   unset outputmsg;;
		preinst) unset outputmsg;;
	esac
	[ -n "${outputmsg}" ] && ${type} "${outputmsg}"
}

qeinfo() { qout einfo "${@}" ; }
qeerror() { qout eerror "${@}" ; }

# File Functions
# ---------------------------------------

# @FUNCTION: getfilevar
# @USAGE: variable configfile
# @RETURN: the value of the variable
# @DESCRIPTION:
# It detects the value of the variable defined in the file configfile
getfilevar() {
local	ERROR workingdir basefname basedname myARCH="${ARCH}"
	ERROR=0

	[ -z "${1}" ] && ERROR=1
	[ ! -f "${2}" ] && ERROR=1

	if [ "${ERROR}" = 1 ]
	then
		echo -e "\n"
		eerror "getfilevar requires 2 variables, with the second a valid file."
		eerror "   getfilevar <VARIABLE> <CONFIGFILE>"
	else
		workingdir="${PWD}"
		basefname="$(basename ${2})"
		basedname="$(dirname ${2})"
		unset ARCH

		cd "${basedname}"
		echo -e "e:\\n\\t@echo \$(${1})\\ninclude ${basefname}" | \
			make M="${S}" ${BUILD_FIXES} -s -f - 2>/dev/null
		cd "${workingdir}"

		ARCH=${myARCH}
	fi
}


# @FUNCTION: linux_config_exists
# @RETURN: true or false
# @DESCRIPTION:
# It returns true if .config exists otherwise false
linux_config_exists() {
	[ -s "${KV_OUT_DIR}/.config" ]
}

# @FUNCTION: require_configured_kernel
# @DESCRIPTION:
# This function verifies that the current kernel is configured (it checks against the existence of .config)
# otherwise it dies.
require_configured_kernel() {
	if ! linux_config_exists; 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."
		qeerror "If you are using KBUILD_OUTPUT, please set the environment var so that"
		qeerror "it points to the necessary object directory so that it might find .config."
		die "Kernel not configured; no .config found in ${KV_OUT_DIR}"
	fi
}

# @FUNCTION: linux_chkconfig_present
# @USAGE: option
# @RETURN: true or false
# @DESCRIPTION:
# It checks that CONFIG_<option>=y or CONFIG_<option>=n is present in the current kernel .config
linux_chkconfig_present() {
local	RESULT
	require_configured_kernel
	RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)"
	[ "${RESULT}" = "m" -o "${RESULT}" = "y" ] && return 0 || return 1
}

# @FUNCTION: linux_chkconfig_module
# @USAGE: option
# @RETURN: true or false
# @DESCRIPTION:
# It checks that CONFIG_<option>=m is present in the current kernel .config
linux_chkconfig_module() {
local	RESULT
	require_configured_kernel
	RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)"
	[ "${RESULT}" = "m" ] && return 0 || return 1
}

# @FUNCTION: linux_chkconfig_builtin
# @USAGE: option
# @RETURN: true or false
# @DESCRIPTION:
# It checks that CONFIG_<option>=y is present in the current kernel .config
linux_chkconfig_builtin() {
local	RESULT
	require_configured_kernel
	RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)"
	[ "${RESULT}" = "y" ] && return 0 || return 1
}

# @FUNCTION: linux_chkconfig_string
# @USAGE: option
# @RETURN: CONFIG_<option>
# @DESCRIPTION:
# It prints the CONFIG_<option> value of the current kernel .config (it requires a configured kernel).
linux_chkconfig_string() {
	require_configured_kernel
	getfilevar "CONFIG_${1}" "${KV_OUT_DIR}/.config"
}

# Versioning Functions
# ---------------------------------------

# @FUNCTION: kernel_is
# @USAGE: [-lt -gt -le -ge -eq] major_number [minor_number patch_number]
# @RETURN: true or false
# @DESCRIPTION:
# It returns true when the current kernel version satisfies the comparison against the passed version.
# -eq is the default comparison.
#
# @CODE
# For Example where KV = 2.6.9
# kernel_is 2 4   returns false
# kernel_is 2     returns true
# kernel_is 2 6   returns true
# kernel_is 2 6 8 returns false
# kernel_is 2 6 9 returns true
# @CODE

# got the jist yet?

kernel_is() {
	# 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
	  lt) operator="-lt"; shift;;
	  gt) operator="-gt"; shift;;
	  le) operator="-le"; shift;;
	  ge) operator="-ge"; shift;;
	  eq) operator="-eq"; shift;;
	   *) operator="-eq";;
	esac

	for x in ${@}; do
		for((y=0; y<$((3 - ${#x})); y++)); do value="${value}0"; done
		value="${value}${x}"
		z=$((${z} + 1))

		case ${z} in
		  1) for((y=0; y<$((3 - ${#KV_MAJOR})); y++)); do test="${test}0"; done;
		     test="${test}${KV_MAJOR}";;
		  2) for((y=0; y<$((3 - ${#KV_MINOR})); y++)); do test="${test}0"; done;
		     test="${test}${KV_MINOR}";;
		  3) for((y=0; y<$((3 - ${#KV_PATCH})); y++)); do test="${test}0"; done;
		     test="${test}${KV_PATCH}";;
		  *) die "Error in kernel-2_kernel_is(): Too many parameters.";;
		esac
	done

	[ ${test} ${operator} ${value} ] && return 0 || return 1
}

get_localversion() {
	local lv_list i x

	# ignore files with ~ in it.
	for i in $(ls ${1}/localversion* 2>/dev/null); do
		[[ -n ${i//*~*} ]] && lv_list="${lv_list} ${i}"
	done

	for i in ${lv_list}; do
		x="${x}$(<${i})"
	done
	x=${x/ /}
	echo ${x}
}

# @FUNCTION: get_version
# @DESCRIPTION:
# It gets the version of the kernel inside KERNEL_DIR and populates the KV_FULL variable
# (if KV_FULL is already set it does nothing).
#
# The kernel version variables (KV_MAJOR, KV_MINOR, KV_PATCH, KV_EXTRA and KV_LOCAL) are also set.
#
# The KV_DIR is set using the KERNEL_DIR env var, the KV_DIR_OUT is set using a valid
# KBUILD_OUTPUT (in a decreasing priority list, we look for the env var, makefile var or the
# symlink /lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build).
get_version() {
	local kbuild_output

	# 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."
		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}}"

	KV_LOCAL="${KV_LOCAL}$(get_localversion ${KV_DIR})"
	if linux_config_exists; then
		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 ] &&
			linux_chkconfig_builtin LOCALVERSION_AUTO &&
			KV_LOCAL="${KV_LOCAL}$(sh ${KV_DIR}/scripts/setlocalversion ${KV_DIR})"
	fi

	# 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}"

	return 0
}

# @FUNCTION: get_running_version
# @DESCRIPTION:
# It gets the version of the current running kernel and the result is the same as get_version() if the
# function can find the sources.
get_running_version() {
	KV_FULL=$(uname -r)

	if [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile ]]; then
		KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
		unset KV_FULL
		get_version
		return $?
	elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
		KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
		unset KV_FULL
		get_version
		return $?
	else
		KV_MAJOR=$(get_version_component_range 1 ${KV_FULL})
		KV_MINOR=$(get_version_component_range 2 ${KV_FULL})
		KV_PATCH=$(get_version_component_range 3- ${KV_FULL})
		KV_PATCH=${KV_PATCH//-*}
		[[ -n ${KV_FULL#*-} ]] && [[ -n ${KV_FULL//${KV_FULL#*-}} ]] \
			&& KV_EXTRA="-${KV_FULL#*-}"
	fi
	return 0
}


# ebuild check functions
# ---------------------------------------

# @FUNCTION: check_kernel_built
# @DESCRIPTION:
# This function verifies that the current kernel sources have been already prepared otherwise it dies.
check_kernel_built() {
	# if we haven't determined the version yet, we need to
	require_configured_kernel
	get_version

	if [ ! -f "${KV_OUT_DIR}/include/linux/version.h" ]
	then
		eerror "These sources have not yet been prepared."
		eerror "We cannot build against an unprepared tree."
		eerror "To resolve this, please type the following:"
		eerror
		eerror "# cd ${KV_DIR}"
		eerror "# make oldconfig"
		eerror "# make modules_prepare"
		eerror
		eerror "Then please try merging this module again."
		die "Kernel sources need compiling first"
	fi
}

# @FUNCTION: check_modules_supported
# @DESCRIPTION:
# This function verifies that the current kernel support modules (it checks CONFIG_MODULES=y) otherwise it dies.
check_modules_supported() {
	# if we haven't determined the version yet, we need too.
	require_configured_kernel
	get_version

	if ! linux_chkconfig_builtin "MODULES"
	then
		eerror "These sources do not support loading external modules."
		eerror "to be able to use this module please enable \"Loadable modules support\""
		eerror "in your kernel, recompile and then try merging this module again."
		die "No support for external modules in ${KV_FULL} config"
	fi
}

# @FUNCTION: check_extra_config
# @DESCRIPTION:
# It checks the kernel config options specified by CONFIG_CHECK. It dies only when a required config option (i.e.
# the prefix ~ is not used) doesn't satisfy the directive.
check_extra_config() {
	local	config negate die error reworkmodulenames
	local	soft_errors_count=0 hard_errors_count=0 config_required=0

	# if we haven't determined the version yet, we need to
	get_version

	# Determine if we really need a .config. The only time when we don't need
	# one is when all of the CONFIG_CHECK options are prefixed with "~".
	for config in ${CONFIG_CHECK}
	do
		if [[ "${config:0:1}" != "~" ]]; then
			config_required=1
			break
		fi
	done

	if [[ ${config_required} == 0 ]]; then
		# In the case where we don't require a .config, we can now bail out
		# if the user has no .config as there is nothing to do. Otherwise
		# code later will cause a failure due to missing .config.
		if ! linux_config_exists; then
			return 0
		fi
	else
		require_configured_kernel
	fi

	einfo "Checking for suitable kernel configuration options..."
	
	for config in ${CONFIG_CHECK}
	do
		# if we specify any fatal, ensure we honor them
		die=1
		error=0
		negate=0
		reworkmodulenames=0

		if [[ ${config:0:1} == "~" ]]; then
			die=0
			config=${config:1}
		elif [[ ${config:0:1} == "@" ]]; then
			die=0
			reworkmodulenames=1
			config=${config:1}
		fi
		if [[ ${config:0:1} == "!" ]]; then
			negate=1
			config=${config:1}
		fi

		if [[ ${negate} == 1 ]]; then
			linux_chkconfig_present ${config} && error=2
		elif [[ ${reworkmodulenames} == 1 ]]; then
			local temp_config="${config//*:}" i n
			config="${config//:*}"
			if linux_chkconfig_present ${config}; then
				for i in ${MODULE_NAMES}; do
					n="${i//${temp_config}}"
					[[ -z ${n//\(*} ]] && \
						MODULE_IGNORE="${MODULE_IGNORE} ${temp_config}"
				done
				error=2
			fi
		else
			linux_chkconfig_present ${config} || error=1
		fi

		if [[ ${error} > 0 ]]; then
			local report_func="eerror" local_error
			local_error="ERROR_${config}"
			local_error="${!local_error}"

			if [[ -z "${local_error}" ]]; then
				# using old, deprecated format.
				local_error="${config}_ERROR"
				local_error="${!local_error}"
			fi
			if [[ ${die} == 0 && -z "${local_error}" ]]; then
				#soft errors can be warnings
				local_error="WARNING_${config}"
				local_error="${!local_error}"
				if [[ -n "${local_error}" ]] ; then
					report_func="ewarn"
				fi
			fi

			if [[ -z "${local_error}" ]]; then
				[[ ${error} == 1 ]] \
					&& local_error="is not set when it should be." \
					|| local_error="should not be set. But it is."
				local_error="CONFIG_${config}:\t ${local_error}"
			fi
			if [[ ${die} == 0 ]]; then
				${report_func} "  ${local_error}"
				soft_errors_count=$[soft_errors_count + 1]
			else
				${report_func} "  ${local_error}"
				hard_errors_count=$[hard_errors_count + 1]
			fi
		fi
	done

	if [[ ${hard_errors_count} > 0 ]]; then
		eerror "Please check to make sure these options are set correctly."
		eerror "Failure to do so may cause unexpected problems."
		eerror "Once you have satisfied these options, please try merging"
		eerror "this package again."
		die "Incorrect kernel configuration options"
	elif [[ ${soft_errors_count} > 0 ]]; then
		ewarn "Please check to make sure these options are set correctly."
		ewarn "Failure to do so may cause unexpected problems."
	else
		eend 0
	fi
}

check_zlibinflate() {
	# if we haven't determined the version yet, we need to
	require_configured_kernel
	get_version

	# although I restructured this code - I really really really dont support it!

	# bug #27882 - zlib routines are only linked into the kernel
	# if something compiled into the kernel calls them
	#
	# plus, for the cloop module, it appears that there's no way
	# to get cloop.o to include a static zlib if CONFIG_MODVERSIONS
	# is on

	local INFLATE
	local DEFLATE

	einfo "Determining the usability of ZLIB_INFLATE support in your kernel"

	ebegin "checking ZLIB_INFLATE"
	getfilevar_isbuiltin CONFIG_ZLIB_INFLATE ${KV_DIR}/.config
	eend $?
	[ "$?" != 0 ] && die

	ebegin "checking ZLIB_DEFLATE"
	getfilevar_isbuiltin CONFIG_ZLIB_DEFLATE ${KV_DIR}/.config
	eend $?
	[ "$?" != 0 ] && die

	local LINENO_START
	local LINENO_END
	local SYMBOLS
	local x

	LINENO_END="$(grep -n 'CONFIG_ZLIB_INFLATE y' ${KV_DIR}/lib/Config.in | cut -d : -f 1)"
	LINENO_START="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | grep -n 'if \[' | tail -n 1 | cut -d : -f 1)"
	(( LINENO_AMOUNT = $LINENO_END - $LINENO_START ))
	(( LINENO_END = $LINENO_END - 1 ))
	SYMBOLS="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;')"

	# okay, now we have a list of symbols
	# we need to check each one in turn, to see whether it is set or not
	for x in $SYMBOLS ; do
		if [ "${!x}" = "y" ]; then
			# we have a winner!
			einfo "${x} ensures zlib is linked into your kernel - excellent"
			return 0
		fi
	done

	eerror
	eerror "This kernel module requires ZLIB library support."
	eerror "You have enabled zlib support in your kernel, but haven't enabled"
	eerror "enabled any option that will ensure that zlib is linked into your"
	eerror "kernel."
	eerror
	eerror "Please ensure that you enable at least one of these options:"
	eerror

	for x in $SYMBOLS ; do
		eerror "  * $x"
	done

	eerror
	eerror "Please remember to recompile and install your kernel, and reboot"
	eerror "into your new kernel before attempting to load this kernel module."

	die "Kernel doesn't include zlib support"
}

################################
# Default pkg_setup
# Also used when inheriting linux-mod to force a get_version call
# @FUNCTION: linux-info_pkg_setup
# @DESCRIPTION:
# Force a get_version() call when inherited from linux-mod.eclass and then check if the kernel is configured
# to support the options specified in CONFIG_CHECK (if not null)
linux-info_pkg_setup() {
	get_version || die "Unable to calculate Linux Kernel version"

	if kernel_is 2 4; then
		if [ "$( gcc-major-version )" -eq "4" ] ; then
			echo
			ewarn "Be warned !! >=sys-devel/gcc-4.0.0 isn't supported with"
			ewarn "linux-2.4 (or modules building against a linux-2.4 kernel)!"
			echo
			ewarn "Either switch to another gcc-version (via gcc-config) or use a"
			ewarn "newer kernel that supports gcc-4."
			echo
			ewarn "Also be aware that bugreports about gcc-4 not working"
			ewarn "with linux-2.4 based ebuilds will be closed as INVALID!"
			echo
			epause 10
		fi
	fi

	[ -n "${CONFIG_CHECK}" ] && check_extra_config;
}