/[gentoo-x86]/eclass/kmod.eclass
Gentoo

Contents of /eclass/kmod.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (show annotations) (download)
Mon Nov 30 04:19:36 2009 UTC (4 years, 9 months ago) by abcd
Branch: MAIN
CVS Tags: HEAD
Changes since 1.19: +1 -1 lines
FILE REMOVED
Remove eclasses that have been marked as deprecated for >=2 years; schedule other deprecated eclasses for removal

1 # Copyright 1999-2004 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/kmod.eclass,v 1.19 2006/02/28 03:05:59 vapier Exp $
4
5 # !!!!!!!!!!
6 #
7 # BEWARE: DO NOT USE. THIS ECLASS IS DEPRECATED AND BROKEN. DO NOT USE.
8 # Use linux-mod.eclass and/or linux-info.eclass instead. --brix
9 #
10 # !!!!!!!!!!
11
12 # This eclass provides help for compiling external kernel modules from
13 # source.
14 #
15 # BEWARE: This eclass is superceding the old kmod.eclass. It does *not*
16 # implement the same functionality as the old kmod.eclass!
17
18 # DOCUMENTATION: Most documentation for this can be found at:
19 # http://www.gentoo.org/doc/en/2.6-koutput.xml
20 #
21 # More documentation comments will follow in the header of this soon!
22
23 # Variables you can use to change behavior
24 #
25 # KMOD_SOURCES - space seperated list of source to unpack in
26 # src_unpack() if you don't want ${A} unpacked.
27 #
28 # KMOD_KOUTPUT_PATCH - Patch to apply in src_unpack() if a seperate output
29 # directory is detected.
30 #
31
32 inherit eutils
33
34 S=${WORKDIR}/${P}
35 DESCRIPTION="Based on the $ECLASS eclass"
36
37 SRC_URI="${SRC_URI:-unknown - please fix me!!}"
38 KERNEL_DIR="${KERNEL_DIR:-${ROOT}/usr/src/linux}"
39
40 EXPORT_FUNCTIONS src_unpack src_compile pkg_postinst
41
42 kmod_get_make_var ()
43 {
44 grep "^${1}" ${2} | head -n 1 | grep -v ":=" | cut -d = -f 2- \
45 | awk '{ print $1 }'
46 }
47
48 # getconfigvar() - Prints the value of a certain config varaible from the
49 # current kernel's config file. Will return "n" for an unset
50 # option
51
52 kmod_get_config_var()
53 {
54 local configopt="CONFIG_${1}"
55 local configresult
56
57 if [ -z ${KV_OUTPUT} ]; then
58 get_kernel_info
59 fi
60
61 configresult="`grep ^$configopt ${KV_OUTPUT}/.config | cut -d= -f 2-`"
62 if [ -z "${configresult}" ]; then
63 echo "n"
64 else
65 echo ${configresult} | awk '{ print $1 }'
66 fi
67 }
68
69 # get_kernel_info is used to get our build environment. It initializes several
70 # variables that can be used in ebuilds
71 #
72 # KV_MAJOR, KV_MINOR, KV_PATCH - the kernel major, minor, and pathlevel #'s
73 # KV_TYPE - the type, as found from EXTRAVERSION.
74 #
75 # KV_VERSION_FULL - full string for the kernel version
76 #
77 # KV_OUTPUT - the output direcotry if used with a 2.6 kernel
78 #
79 # KV_OBJ - extension for kernel objects, "o" for 2.4 kernels and "ko" for 2.6
80 #
81 get_kernel_info()
82 {
83 # yes, this is horrible, but it is effective
84 #
85 # KV_DIR contains the real directory name of the directory containing
86 # the Linux kernel that we are going to compile against
87
88 if [ -h ${KERNEL_DIR} ] ; then
89 einfo "`echo ${KERNEL_DIR} | tr -s /` is a symbolic link"
90 einfo "Determining the real directory of the Linux kernel source code"
91 KV_DIR="`readlink ${KERNEL_DIR}`"
92 elif [ -d ${KERNEL_DIR} ] ; then
93 einfo "`echo ${KERNEL_DIR} | tr -s /` is a real directory"
94 KV_DIR="`ls -d ${KERNEL_DIR}`"
95 # KV_DIR="`ls -ld --full-time ${KERNEL_DIR} | awk '{ print $9 }'`"
96 else
97 eerror "Directory '${KERNEL_DIR}' cannot be found"
98 die
99 fi
100 KV_DIR="`basename ${KV_DIR}`"
101
102 # now, we need to break that down into versions
103
104 KV_DIR_VERSION_FULL="`echo $KV_DIR | cut -f 2- -d -`"
105
106 KV_DIR_MAJOR="`echo ${KV_DIR_VERSION_FULL} | cut -f 1 -d .`"
107 KV_DIR_MINOR="`echo ${KV_DIR_VERSION_FULL} | cut -f 2 -d .`"
108 KV_DIR_PATCH="`echo ${KV_DIR_VERSION_FULL} | cut -f 3 -d . | cut -f 1 -d -`"
109 KV_DIR_TYPE="`echo ${KV_DIR_VERSION_FULL} | cut -f 2- -d -`"
110
111 # sanity check - do the settings in the kernel's makefile match
112 # the directory that the kernel src is stored in?
113
114 KV_MK_FILE="${KERNEL_DIR}/Makefile"
115 KV_MK_MAJOR="`kmod_get_make_var VERSION ${KV_MK_FILE}`"
116 KV_MK_MINOR="`kmod_get_make_var PATCHLEVEL ${KV_MK_FILE}`"
117 KV_MK_PATCH="`kmod_get_make_var SUBLEVEL ${KV_MK_FILE}`"
118 KV_MK_TYPE="`kmod_get_make_var EXTRAVERSION ${KV_MK_FILE}`"
119
120 KV_MK_VERSION_FULL="${KV_MK_MAJOR}.${KV_MK_MINOR}.${KV_MK_PATCH}${KV_MK_TYPE}"
121
122 KV_MK_OUTPUT="`kmod_get_make_var KBUILD_OUTPUT ${KV_MK_FILE}`"
123
124 # May need to deal with a dynamically set KBUILD_OUTPUT variable
125 if [ "${KV_MK_OUTPUT/VERSION/}" != "${KV_MK_OUTPUT}" ]; then
126 KV_MK_OUTPUT="${KV_MK_OUTPUT/\$(VERSION)/${KV_MK_MAJOR}}"
127 KV_MK_OUTPUT="${KV_MK_OUTPUT/\$(PATCHLEVEL)/${KV_MK_MINOR}}"
128 KV_MK_OUTPUT="${KV_MK_OUTPUT/\$(SUBLEVEL)/${KV_MK_PATCH}}"
129 KV_MK_OUTPUT="${KV_MK_OUTPUT/\$(EXTRAVERSION)/${KV_MK_TYPE}}"
130 fi
131
132 if [ "$KV_MK_VERSION_FULL" != "${KV_DIR_VERSION_FULL}" ]; then
133 ewarn
134 ewarn "The kernel Makefile says that this is a ${KV_MK_VERSION_FULL} kernel"
135 ewarn "but the source is in a directory for a ${KV_DIR_VERSION_FULL} kernel."
136 ewarn
137 ewarn "This goes against the recommended Gentoo naming convention."
138 ewarn "Please rename your source directory to 'linux-${KV_MK_VERSION_FULL}'"
139 ewarn
140 fi
141
142 # these variables can be used by ebuilds to determine whether they
143 # will work with the targetted kernel or not
144 #
145 # do not rely on any of the variables above being available
146
147 KV_VERSION_FULL="${KV_MK_VERSION_FULL}"
148 KV_MAJOR="${KV_MK_MAJOR}"
149 KV_MINOR="${KV_MK_MINOR}"
150 KV_PATCH="${KV_MK_PATCH}"
151 KV_TYPE="${KV_MK_TYPE}"
152
153 # if we found an output location, use that. otherwise use KERNEL_DIR.
154 if [ ! -z "${KV_MK_OUTPUT}" ]
155 then
156 KV_OUTPUT="${ROOT}/${KV_MK_OUTPUT}"
157 else
158 KV_OUTPUT="${KERNEL_DIR}"
159 fi
160
161 # KV_OBJ can be used when manually installing kernel modules
162 if [ "${KV_MINOR}" -gt "4" ]
163 then
164 KV_OBJ="ko"
165 else
166 KV_OBJ="o"
167 fi
168
169 einfo "Building for Linux ${KV_VERSION_FULL} found in `echo ${KERNEL_DIR} | tr -s /`"
170
171 if is_kernel 2 5 || is_kernel 2 6
172 then
173 einfo "which outputs to `echo ${KV_OUTPUT} | tr -s /`"
174
175 # Warn them if they aren't using a different output directory
176 if [ "${KV_OUTPUT}" = "${ROOT}/usr/src/linux" ]; then
177 ewarn "By not using the kernel's ability to output to an alternative"
178 ewarn "directory, some external module builds may fail."
179 ewarn "See <insert link to user doc here>"
180 fi
181 fi
182 }
183
184 # kmod_make_linux_writeable() is used to allow portage to write to
185 # /usr/src/linux. This is a BIG no-no, but the "easiest" way for
186 # 2.6 module compilation. Since it's so horrible, we force users to accept
187 # doing it via a variable controlled by /etc/env.d/20kernel and kernel-config
188
189 kmod_make_linux_writable()
190 {
191 # LINUX_PORTAGE_WRITABLE is set in /etc/env.d/20kernel to "yes"
192 # if someone really wants to do that
193 [ -x ${ROOT}/usr/bin/config-kernel ] && LINUX_PORTAGE_WRITABLE="$(${ROOT}/usr/bin/config-kernel --is-writable)"
194
195 if [ "${LINUX_PORTAGE_WRITABLE}" != "yes" ]
196 then
197 if [ "${FEATURES/sandbox/}" != "${FEATURES}" ]
198 then
199 eerror "Due to the 2.6 kernel build system, external module compilation"
200 eerror "with a normal setup requires write access to ${KERNEL_DIR}"
201 eerror "There are several ways to fix/prevent this."
202 eerror "Users can willingly let portage make this writable by doing"
203 eerror "# config-kernel --allow-writable yes"
204 eerror "However, this is considered a security risk!"
205 eerror ""
206 eerror "The prefered method is to enable Gentoo's new 'koutput' method"
207 eerror "for kernel modules. See the doc"
208 eerror "http://www.gentoo.org/doc/en/2.6-koutput-user.xml"
209 eerror "To enable this, you'll need to run"
210 eerror "# config-kernel --output-dir /var/tmp/kernel-output"
211 eerror "and then install a new kernel"
212 die "Incompatible kernel setup"
213 else
214 ewarn "Detected sandbox disabled for kernel module ebuild"
215 fi
216 fi
217
218 eerror "Making ${ROOT}/usr/src/linux-${KV} writable by portage!!!"
219 addwrite ${ROOT}/usr/src/linux-${KV}
220 }
221
222
223 # kmod_do_buildpatches performs the needed koutput patches as needed
224 kmod_do_buildpatches()
225 {
226 if [ -z ${KV_OUTPUT} ]; then
227 get_kernel_info
228 fi
229
230 cd ${S}
231 if is_koutput && [ -n "${KMOD_KOUTPUT_PATCH}" ]; then
232 EPATCH_SINGLE_MESSAGE="Patching to enable koutput compatibility" \
233 epatch ${KMOD_KOUTPUT_PATCH}
234 fi
235 }
236
237 kmod_src_unpack () {
238 check_KV
239 kmod_universal_unpack
240 }
241
242 kmod_universal_unpack()
243 {
244 get_kernel_info
245
246 # KMOD_SOURCES is used if you don't want to unpack just ${A}
247 # It can be set to "none" if you need to unpack things by hand
248 # (like the nvidia-kernel ebuild). If set to "none", you'll have
249 # to do any patching by hand as ${S} won't be around yet!
250 # You can just call kmod_do_buildpatches after unpacking ${S}
251 # if need be.
252 if [ -z "${KMOD_SOURCES}" ]
253 then
254 unpack ${A}
255 elif [ "${KMOD_SOURCES}" != "none" ]
256 then
257 unpack ${KMOD_SOURCES}
258 fi
259
260 if is_kernel 2 5 || is_kernel 2 6
261 then
262 # If we have sources we've unpacked, patch as needed
263 if [ "${KMOD_SOURCES}" != "none" ]; then
264 kmod_do_buildpatches
265 fi
266 fi
267 }
268
269 kmod_src_compile () {
270 if is_kernel 2 5 || is_kernel 2 6
271 then
272 # If we're on 2.5/2.6 and not koutputing, we need to make
273 # /usr/src/linux writable to succeed
274 if ! is_koutput
275 then
276 kmod_make_linux_writable
277 fi
278
279 unset ARCH
280 fi
281 emake KERNEL_DIR=${KERNEL_DIR} || die
282 }
283
284 kmod_pkg_postinst() {
285 einfo "Checking kernel module dependancies"
286 test -r "${ROOT}/${KV_OUTPUT}/System.map" && \
287 depmod -ae -F "${ROOT}/${KV_OUTPUT}/System.map" -b "${ROOT}" -r ${KV}
288 }
289
290 # is_kernel() takes two arguments. They should be the major and minor number
291 # of the kernel you'd like to check for. e.g.
292 #
293 # if is_kernel 2 6; then foo; fi
294 #
295 is_kernel() {
296 if [ -z "${KV_MAJOR}" ]
297 then
298 get_kernel_info
299 fi
300
301 if [ "${KV_MAJOR}" -eq "${1}" -a "${KV_MINOR}" -eq "${2}" ]
302 then
303 return 0
304 else
305 return 1
306 fi
307 }
308
309 # is_koutput() should be used to determing if we are using the koutput
310 # method of compilation for 2.6 kernels
311
312 is_koutput() {
313 if [ -z ${KV_OUTPUT} ]
314 then
315 get_kernel_info
316 fi
317
318 if [ "${KV_OUTPUT}" != "${ROOT}/usr/src/linux" ]; then
319 return 0
320 else
321 return 1
322 fi
323 }

  ViewVC Help
Powered by ViewVC 1.1.20