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

Collapse All | Expand All

(-)kernel-mod.eclass (-39 / +278 lines)
Lines 8-24 Link Here
8
# This eclass differs from kmod.eclass because it doesn't require modules
8
# This eclass differs from kmod.eclass because it doesn't require modules
9
# to be added to the kernel source tree first.
9
# to be added to the kernel source tree first.
10
10
11
# Variables you can use to change behavior
12
#
13
# KERNEL_MOD_SOURCES - space seperated list of source to unpack in 
14
#					   kernel-mod_src_unpack() if you don't want ${A} unpacked.
15
#
16
# KERNEL_MOD_KOUTPUT_PATCH - Patch to apply in src_unpack() if a seperate output
17
#							directory is detected.
18
#
19
20
inherit eutils
21
11
ECLASS=kernel-mod
22
ECLASS=kernel-mod
12
INHERITED="$INHERITED $ECLASS"
23
INHERITED="$INHERITED $ECLASS"
13
S=${WORKDIR}/${P}
24
S=${WORKDIR}/${P}
14
DESCRIPTION="Based on the $ECLASS eclass"
25
DESCRIPTION="Based on the $ECLASS eclass"
15
26
16
SRC_URI="${SRC_URI:-unknown - please fix me!!}"
27
SRC_URI="${SRC_URI:-unknown - please fix me!!}"
17
KERNEL_DIR="${KERNEL_DIR:-/usr/src/linux}"
28
KERNEL_DIR="${KERNEL_DIR:-${ROOT}/usr/src/linux}"
18
29
19
kernel-mod_getmakefilevar ()
30
kernel-mod_getmakefilevar ()
20
{
31
{
21
	grep $1 $2 | head -n 1 | cut -d = -f 2- | awk '{ print $1 }'
32
	grep $1 $2 | head -n 1 | grep -v ":=" | cut -d = -f 2- | awk '{ print $1 }'
33
}
34
35
kernel-mod_getconfigvar()
36
{
37
	local configopt="CONFIG_${1}"
38
	local configresult
39
40
	if [ -z ${KV_OUTPUT} ]; then
41
		kernel-mod_getversion
42
	fi
43
44
	configresult="`grep ^$configopt ${KV_OUTPUT}/.config | cut -d= -f 2-`"
45
	if [ -z "${configresult}" ]; then
46
		echo "n"
47
	else
48
		echo ${configresult} | awk '{ print $1 }'
49
	fi
22
}
50
}
23
51
24
kernel-mod_getversion ()
52
kernel-mod_getversion ()
Lines 29-70 Link Here
29
	# the Linux kernel that we are going to compile against
57
	# the Linux kernel that we are going to compile against
30
58
31
	if [ -h ${KERNEL_DIR} ] ; then
59
	if [ -h ${KERNEL_DIR} ] ; then
32
		einfo "${KERNEL_DIR} is a symbolic link"
60
		einfo "`echo ${KERNEL_DIR} | tr -s /` is a symbolic link"
33
		einfo "Determining the real directory of the Linux kernel source code"
61
		einfo "Determining the real directory of the Linux kernel source code"
34
		KV_DIR="`ls -ld --full-time ${KERNEL_DIR} | awk '{ print $11 }'`"
62
		KV_DIR="`readlink ${KERNEL_DIR}`"
35
	elif [ -d ${KERNEL_DIR} ] ; then
63
	elif [ -d ${KERNEL_DIR} ] ; then
36
		einfo "${KERNEL_DIR} is a real directory"
64
		einfo "`echo ${KERNEL_DIR} | tr -s /` is a real directory"
37
		KV_DIR="`ls -ld --full-time ${KERNEL_DIR} | awk '{ print $9 }'`"
65
		KV_DIR="`ls -d ${KERNEL_DIR}`"
66
		# KV_DIR="`ls -ld --full-time ${KERNEL_DIR} | awk '{ print $9 }'`"
38
	else
67
	else
39
		eerror "Directory '${KERNEL_DIR}' cannot be found"
68
		eerror "Directory '${KERNEL_DIR}' cannot be found"
40
		die
69
		die
41
	fi
70
	fi
42
	KV_DIR="`basename $KV_DIR`"
71
	KV_DIR="`basename ${KV_DIR}`"
43
72
44
	# now, we need to break that down into versions
73
	# now, we need to break that down into versions
45
74
46
	KV_DIR_VERSION_FULL="`echo $KV_DIR | cut -f 2- -d -`"
75
	KV_DIR_VERSION_FULL="`echo $KV_DIR | cut -f 2- -d -`"
47
76
48
	KV_DIR_MAJOR="`echo $KV_DIR_VERSION_FULL | cut -f 1 -d .`"
77
	KV_DIR_MAJOR="`echo ${KV_DIR_VERSION_FULL} | cut -f 1 -d .`"
49
	KV_DIR_MINOR="`echo $KV_DIR_VERSION_FULL | cut -f 2 -d .`"
78
	KV_DIR_MINOR="`echo ${KV_DIR_VERSION_FULL} | cut -f 2 -d .`"
50
	KV_DIR_PATCH="`echo $KV_DIR_VERSION_FULL | cut -f 3 -d . | cut -f 3 -d -`"
79
	KV_DIR_PATCH="`echo ${KV_DIR_VERSION_FULL} | cut -f 3 -d . | cut -f 3 -d -`"
51
	KV_DIR_TYPE="`echo $KV_DIR_VERSION_FULL | cut -f 2- -d -`"
80
	KV_DIR_TYPE="`echo ${KV_DIR_VERSION_FULL} | cut -f 2- -d -`"
52
81
53
	# sanity check - do the settings in the kernel's makefile match
82
	# sanity check - do the settings in the kernel's makefile match
54
	# the directory that the kernel src is stored in?
83
	# the directory that the kernel src is stored in?
55
84
56
	KV_MK_FILE="${KERNEL_DIR}/Makefile"
85
	KV_MK_FILE="${KERNEL_DIR}/Makefile"
57
	KV_MK_MAJOR="`kernel-mod_getmakefilevar VERSION $KV_MK_FILE`"
86
	KV_MK_MAJOR="`kernel-mod_getmakefilevar VERSION ${KV_MK_FILE}`"
58
	KV_MK_MINOR="`kernel-mod_getmakefilevar PATCHLEVEL $KV_MK_FILE`"
87
	KV_MK_MINOR="`kernel-mod_getmakefilevar PATCHLEVEL ${KV_MK_FILE}`"
59
	KV_MK_PATCH="`kernel-mod_getmakefilevar SUBLEVEL $KV_MK_FILE`"
88
	KV_MK_PATCH="`kernel-mod_getmakefilevar SUBLEVEL ${KV_MK_FILE}`"
60
	KV_MK_TYPE="`kernel-mod_getmakefilevar EXTRAVERSION $KV_MK_FILE`"
89
	KV_MK_TYPE="`kernel-mod_getmakefilevar EXTRAVERSION ${KV_MK_FILE}`"
61
90
62
	KV_MK_VERSION_FULL="$KV_MK_MAJOR.$KV_MK_MINOR.$KV_MK_PATCH$KV_MK_TYPE"
91
	KV_MK_VERSION_FULL="${KV_MK_MAJOR}.${KV_MK_MINOR}.${KV_MK_PATCH}${KV_MK_TYPE}"
63
92
64
	if [ "$KV_MK_VERSION_FULL" != "$KV_DIR_VERSION_FULL" ]; then
93
	KV_MK_OUTPUT="`kernel-mod_getmakefilevar ^KBUILD_OUTPUT ${KV_MK_FILE}`"
94
	
95
	if [ "$KV_MK_VERSION_FULL" != "${KV_DIR_VERSION_FULL}" ]; then
65
		ewarn
96
		ewarn
66
		ewarn "The kernel Makefile says that this is a $KV_MK_VERSION_FULL kernel"
97
		ewarn "The kernel Makefile says that this is a ${KV_MK_VERSION_FULL} kernel"
67
		ewarn "but the source is in a directory for a $KV_DIR_VERSION_FULL kernel."
98
		ewarn "but the source is in a directory for a ${KV_DIR_VERSION_FULL} kernel."
68
		ewarn
99
		ewarn
69
		ewarn "This goes against the recommended Gentoo naming convention."
100
		ewarn "This goes against the recommended Gentoo naming convention."
70
		ewarn "Please rename your source directory to 'linux-${KV_MK_VERSION_FULL}'"
101
		ewarn "Please rename your source directory to 'linux-${KV_MK_VERSION_FULL}'"
Lines 76-97 Link Here
76
	#
107
	#
77
	# do not rely on any of the variables above being available
108
	# do not rely on any of the variables above being available
78
109
79
	KV_VERSION_FULL="$KV_MK_VERSION_FULL"
110
	KV_VERSION_FULL="${KV_MK_VERSION_FULL}"
80
	KV_MAJOR="$KV_MK_MAJOR"
111
	KV_MAJOR="${KV_MK_MAJOR}"
81
	KV_MINOR="$KV_MK_MINOR"
112
	KV_MINOR="${KV_MK_MINOR}"
82
	KV_PATCH="$KV_MK_PATCH"
113
	KV_PATCH="${KV_MK_PATCH}"
83
	KV_TYPE="$KV_MK_TYPE"
114
	KV_TYPE="${KV_MK_TYPE}"
115
116
	# if we found an output location, use that. otherwise use KERNEL_DIR.
117
	if [ ! -z "${KV_MK_OUTPUT}" ]
118
	then
119
		KV_OUTPUT="${ROOT}/${KV_MK_OUTPUT}"
120
	else
121
		KV_OUTPUT="${KERNEL_DIR}"
122
	fi
123
124
	# KV_OBJ can be used when manually installing kernel modules
125
	if [ "${KV_MINOR}" -gt "4" ]
126
	then
127
		KV_OBJ="ko"
128
	else
129
		KV_OBJ="o"
130
	fi
131
132
	einfo "Building for Linux ${KV_VERSION_FULL} found in `echo ${KERNEL_DIR} | tr -s /`"
84
133
85
	einfo "Building for Linux ${KV_VERSION_FULL} found in ${KERNEL_DIR}"
134
	if kernel-mod_is_kernel 2 5 || kernel-mod_is_kernel 2 6
135
	then
136
		einfo "which outputs to `echo ${KV_OUTPUT} | tr -s /`"
137
138
		# Warn them if they aren't using a different output directory
139
		if [ "${KV_OUTPUT}" = "${ROOT}/usr/src/linux" ]; then
140
			ewarn "By not using the kernel's ability to output to an alternative"
141
			ewarn "directory, some external module builds may fail."
142
			ewarn "See <insert link to user doc here>"
143
		fi
144
	fi
86
}
145
}
87
146
88
kernel-mod_checkzlibinflate_configured ()
147
kernel-mod_checkzlibinflate_configured ()
89
{
148
{
90
	einfo "Checking for status of CONFIG_ZLIB_INFLATE support in your kernel"
149
	einfo "Checking for status of CONFIG_ZLIB_INFLATE support in your kernel"
91
150
92
	. ${KERNEL_DIR}/.config || die "kernel has not been configured yet"
151
	if [ -z ${KV_OUTPUT} ]; then
93
	[ "$CONFIG_ZLIB_INFLATE" != "y" ] && kernel-mod_badconfig_zlib
152
		kernel-mod_getversion
94
	[ "$CONFIG_ZLIB_DEFLATE" != "y" ] && kernel-mod_badconfig_zlib
153
	fi
154
155
	! -f ${KV_OUTPUT}/.config || die "kernel has not been configured yet"
156
	[ "`kernel-mod_getconfigvar ZLIB_INFLATE`" != "y" ] && \
157
		kernel-mod_badconfig_zlib
158
	[ "`kernel-mod_getconfigvar ZLIB_DEFLATE`" != "y" ] && \
159
		kernel-mod_badconfig_zlib
95
160
96
	# bug #27882 - zlib routines are only linked into the kernel
161
	# bug #27882 - zlib routines are only linked into the kernel
97
	# if something compiled into the kernel calls them
162
	# if something compiled into the kernel calls them
Lines 109-124 Link Here
109
	local x
174
	local x
110
175
111
	LINENO_END="`grep -n 'CONFIG_ZLIB_INFLATE y' ${KERNEL_DIR}/lib/Config.in | cut -d : -f 1`"
176
	LINENO_END="`grep -n 'CONFIG_ZLIB_INFLATE y' ${KERNEL_DIR}/lib/Config.in | cut -d : -f 1`"
112
	LINENO_START="`head -n $LINENO_END ${KERNEL_DIR}/lib/Config.in | grep -n 'if \[' | tail -n 1 | cut -d : -f 1`"
177
	LINENO_START="`head -n ${LINENO_END} ${KERNEL_DIR}/lib/Config.in | grep -n 'if \[' | tail -n 1 | cut -d : -f 1`"
113
	(( LINENO_AMOUNT = $LINENO_END - $LINENO_START ))
178
	(( LINENO_AMOUNT = ${LINENO_END} - ${LINENO_START} ))
114
	(( LINENO_END = $LINENO_END - 1 ))
179
	(( LINENO_END = ${LINENO_END} - 1 ))
115
	
180
	
116
	SYMBOLS="`head -n $LINENO_END ${KERNEL_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;'`"
181
	SYMBOLS="`head -n ${LINENO_END} ${KERNEL_DIR}/lib/Config.in | tail -n ${LINENO_AMOUNT} | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;'`"
117
182
118
	# okay, now we have a list of symbols
183
	# okay, now we have a list of symbols
119
	# we need to check each one in turn, to see whether it is set or not
184
	# we need to check each one in turn, to see whether it is set or not
120
185
121
	for x in $SYMBOLS ; do
186
	for x in ${SYMBOLS} ; do
122
		if [ "${!x}" = "y" ]; then
187
		if [ "${!x}" = "y" ]; then
123
			# we have a winner!
188
			# we have a winner!
124
			einfo "${x} ensures zlib is linked into your kernel - excellent"
189
			einfo "${x} ensures zlib is linked into your kernel - excellent"
Lines 140-147 Link Here
140
	eerror "Please ensure that you enable at least one of these options:"
205
	eerror "Please ensure that you enable at least one of these options:"
141
	eerror
206
	eerror
142
207
143
	for x in $SYMBOLS ; do
208
	for x in ${SYMBOLS} ; do
144
		eerror "  * $x"
209
		eerror "  * ${x}"
145
	done
210
	done
146
211
147
	eerror
212
	eerror
Lines 151-163 Link Here
151
	die "Kernel doesn't include zlib support"
216
	die "Kernel doesn't include zlib support"
152
}
217
}
153
218
219
# make_linux_writeable() is used to allow portage to write to
220
# /usr/src/linux. This is a BIG no-no, but the "easiest" way for
221
# 2.6 module compilation. Since it's so horrible, we force users to accept
222
# doing it via a variable controlled by /etc/env.d/20kernel and kernel-config
223
224
kernel-mod_make_linux_writable()
225
{
226
	# LINUX_PORTAGE_WRITABLE is set in /etc/env.d/20kernel to "yes"
227
	# if someone really wants to do that
228
	if [ "${LINUX_PORTAGE_WRITABLE}" != "yes" ]
229
	then
230
		if [ "${FEATURES/sandbox/}" != "${FEATURES}" ]
231
		then
232
			eerror "Due to the 2.6 kernel build system, external module compilation"
233
			eerror "with a normal setup requires write access to ${KERNEL_DIR}"
234
			eerror "There are several ways to fix/prevent this."
235
			eerror "Users can willingly let portage make this writable by doing"
236
			eerror "# kernel-config permit-writable on"
237
			eerror "and then running 'env-update && source /etc/profile'"
238
			eerror "However, this is considered a security risk!"
239
			eerror ""
240
			eerror "The prefered method is to enable Gentoo's new 'koutput' method"
241
			eerror "for kernel modules. See the doc FIXME"
242
			eerror "To enable this, you'll need to run"
243
			eerror "# kernel-config kernel-output /var/tmp/kernel-output"
244
			eerror "and then install a new kernel"
245
			die "Incompatible kernel setup"
246
		else
247
			ewarn "Detected sandbox disabled for kernel module ebuild"
248
		fi
249
	fi
250
251
	ewarn "Making ${ROOT}/usr/src/linux-${KV} writable by portage!!!"
252
	addwrite ${ROOT}/usr/src/linux-${KV}
253
}
254
255
256
# do_buildpatches performs the needed koutput patches as needed
257
kernel-mod_do_buildpatches()
258
{
259
	if [ -z ${KV_OUTPUT} ]; then
260
		kernel-mod_getversion
261
	fi
262
263
	cd ${S}
264
	if kernel-mod_is_koutput && [ -n "${KERNEL_MOD_KOUTPUT_PATCH}" ]; then
265
		EPATCH_SINGLE_MESSAGE="Patching to enable koutput compatibility" \
266
			epatch ${KERNEL_MOD_KOUTPUT_PATCH}
267
	fi
268
}
269
	
270
kernel-mod_src_unpack ()
271
{
272
	check_KV
273
	kernel-mod_getversion
274
275
	# KERNEL_MOD_SOURCES is used if you don't want to unpack just ${A}
276
	# It can be set to "none" if you need to unpack things by hand
277
	# (like the nvidia-kernel ebuild). If set to "none", you'll have
278
	# to do any patching by hand as ${S} won't be around yet!
279
	# You can just call kernel-mod_do_buildpatches after unpacking ${S}
280
	# if need be.
281
	if [ -z "${KERNEL_MOD_SOURCES}" ]
282
	then
283
		unpack ${A}
284
	elif [ "${KERNEL_MOD_SOURCES}" != "none" ]
285
	then
286
		unpack ${KERNEL_MOD_SOURCES}
287
	fi
288
289
	if is_kernel 2 5 || is_kernel 2 6
290
	then
291
		# If we have sources we've unpacked, patch as needed
292
		if [ "${KERNEL_MOD_SOURCES}" != "none" ]; then
293
			kernel-mod_do_buildpatches
294
		fi
295
	fi
296
}
297
154
kernel-mod_src_compile ()
298
kernel-mod_src_compile ()
155
{
299
{
300
	if is_kernel 2 5 || is_kernel 2 6
301
	then
302
		# If we're on 2.5/2.6 and not koutputing, we need to make
303
		# /usr/src/linux writable to succeed
304
		if ! is_koutput
305
		then
306
			kernel-mod_make_linux_writable
307
		fi
308
309
		unset ARCH
310
	fi
156
	emake KERNEL_DIR=${KERNEL_DIR} || die
311
	emake KERNEL_DIR=${KERNEL_DIR} || die
157
}
312
}
158
313
314
kernel-mod_pkg_postinst()
315
{
316
	einfo "Checking kernel module dependancies"
317
	test -r "${ROOT}/${KV_OUTPUT}/System.map" && \
318
		depmod -ae -F "${ROOT}/${KV_OUTPUT}/System.map" -b "${ROOT}" -r ${KV}
319
}
320
321
# is_kernel() takes two arguments. They should be the major and minor number
322
# of the kernel you'd like to check for. e.g.
323
#
324
# if is_kernel 2 6; then foo; fi
325
#
326
kernel-mod_is_kernel() {
327
	if [ -z "${KV_MAJOR}" ]
328
	then
329
		kernel-mod_getversion
330
	fi
331
332
	if [ "${KV_MAJOR}" -eq "${1}" -a "${KV_MINOR}" -eq "${2}" ]
333
	then    
334
		return 0
335
	else    
336
		return 1
337
	fi
338
}
339
340
# is_koutput() should be used to determing if we are using the koutput
341
# method of compilation for 2.6 kernels
342
343
kernel-mod_is_koutput() {
344
	if [ -z ${KV_OUTPUT} ]
345
	then
346
		kernel-mod_getversion
347
	fi
348
349
	if [ "${KV_OUTPUT}" != "${ROOT}/usr/src/linux" ]; then
350
		return 0
351
	else
352
		return 1
353
	fi
354
}
355
356
357
# warn_deprecated() is here to give a consistent warning message
358
# about the deprecation of certain functions
359
360
warn_deprecated() {
361
	if [ -z ${1} ]
362
	then
363
		eerror "warn_deprecated called from invalid context."
364
		eerror "Please pass the function name as an argument."
365
		die "warn_deprecated called without an argument"
366
	fi
367
368
	ewarn ""
369
	ewarn "The function ${1} is deprecated. Please remove the use"
370
	ewarn "of this function from your ebuilds."
371
372
	if [ -n ${2} ]
373
	then
374
		ewarn ""
375
		ewarn "Use of this function has been replaced by ${2}"
376
		ewarn "See kernel-mod.eclass for more information"
377
	fi
378
}
379
380
# The is_X_X_kernel() functions are now deprecated. Please convert
381
# existing and new ebuilds to using the is_kernel() function.
382
159
kernel-mod_is_2_4_kernel() {
383
kernel-mod_is_2_4_kernel() {
160
	kernel-mod_getversion
384
	if [ -z ${KV_MINOR} ]
385
	then
386
		kernel-mod_getversion
387
	fi
388
389
	warn_deprecated kernel-mod_is_2_4_kernel is_kernel
161
390
162
    if [ "${KV_MAJOR}" -eq 2 -a "${KV_MINOR}" -eq 4 ]
391
    if [ "${KV_MAJOR}" -eq 2 -a "${KV_MINOR}" -eq 4 ]
163
    then
392
    then
Lines 168-174 Link Here
168
}
397
}
169
398
170
kernel-mod_is_2_5_kernel() {
399
kernel-mod_is_2_5_kernel() {
171
	kernel-mod_getversion
400
	if [ -z ${KV_MINOR} ]
401
	then
402
		kernel-mod_getversion
403
	fi
404
405
	warn_deprecated kernel-mod_is_2_5_kernel is_kernel
172
406
173
    if [ "${KV_MAJOR}" -eq 2 -a "${KV_MINOR}" -eq 5 ]
407
    if [ "${KV_MAJOR}" -eq 2 -a "${KV_MINOR}" -eq 5 ]
174
    then
408
    then
Lines 179-185 Link Here
179
}
413
}
180
414
181
kernel-mod_is_2_6_kernel() {
415
kernel-mod_is_2_6_kernel() {
182
	kernel-mod_getversion
416
	if [ -z ${KV_MINOR} ]
417
	then
418
		kernel-mod_getversion
419
	fi
420
421
	warn_deprecated kernel-mod_is_2_6_kernel is_kernel
183
422
184
    if [ "${KV_MAJOR}" -eq 2 -a "${KV_MINOR}" -eq 6 ]
423
    if [ "${KV_MAJOR}" -eq 2 -a "${KV_MINOR}" -eq 6 ]
185
    then
424
    then
Lines 189-192 Link Here
189
    fi
428
    fi
190
}
429
}
191
430
192
EXPORT_FUNCTIONS src_compile
431
EXPORT_FUNCTIONS src_unpack src_compile pkg_postinst is_kernel is_koutput

Return to bug 32737