/[gentoo-x86]/eclass/linux-info.eclass
Gentoo

Contents of /eclass/linux-info.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations) (download)
Wed Dec 1 23:26:43 2004 UTC (10 years ago) by johnm
Branch: MAIN
Changes since 1.5: +15 -7 lines
Added support for KBUILD_OUTPUT and pulling variables from .config/Makefile using make. This is more reliable and evaluates the makefile vars so we dont need any hacking bandaid to do so.

1 # Copyright 1999-2004 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: $
4 #
5 # This eclass provides functions for querying the installed kernel
6 # source version, selected kernel options etc.
7 #
8
9 ECLASS=linux-info
10 INHERITED="$INHERITED $ECLASS"
11
12 # Overwritable environment Var's
13 # ---------------------------------------
14 KERNEL_DIR="${KERNEL_DIR:-/usr/src/linux}"
15
16 # File Functions
17 # ---------------------------------------
18
19 # getfilevar accepts 2 vars as follows:
20 # getfilevar <VARIABLE> <CONFIGFILE>
21
22 getfilevar() {
23 local ERROR workingdir basefname basedname arch
24 ERROR=0
25
26 [ -z "${1}" ] && ERROR=1
27 [ ! -f "${2}" ] && ERROR=1
28
29 if [ "${ERROR}" = 1 ]
30 then
31 ebeep
32 echo -e "\n"
33 eerror "getfilevar requires 2 variables, with the second a valid file."
34 eerror " getfilevar <VARIABLE> <CONFIGFILE>"
35 else
36 workingdir=${PWD}
37 basefname=$(basename ${2})
38 basedname=$(dirname ${2})
39 arch=${ARCH}
40 unset ARCH
41
42 cd ${basedname}
43 echo -e "include ${basefname}\ne:\n\t@echo \$(${1})" | make -f - e
44 cd ${workingdir}
45
46 ARCH=${arch}
47 fi
48 }
49
50 getfilevar_isset() {
51 local RESULT
52 RESULT="$(getfilevar ${1} ${2})"
53 [ "${RESULT}" = "m" -o "${RESULT}" = "y" ] && return 0 || return 1
54 }
55
56 getfilevar_ismodule() {
57 local RESULT
58 RESULT="$(getfilevar ${1} ${2})"
59 [ "${RESULT}" = "m" ] && return 0 || return 1
60 }
61
62 getfilevar_isbuiltin() {
63 local RESULT
64 RESULT="$(getfilevar ${1} ${2})"
65 [ "${RESULT}" = "y" ] && return 0 || return 1
66 }
67
68 # Versioning Functions
69 # ---------------------------------------
70
71 # kernel_is returns true when the version is the same as the passed version
72 #
73 # For Example where KV = 2.6.9
74 # kernel_is 2 4 returns false
75 # kernel_is 2 returns true
76 # kernel_is 2 6 returns true
77 # kernel_is 2 6 8 returns false
78 # kernel_is 2 6 9 returns true
79 #
80 # got the jist yet?
81
82 kernel_is() {
83 # if we haven't determined the version yet, we need too.
84 get_version;
85
86 local RESULT
87 RESULT=1
88
89 if [ -n "${1}" ]
90 then
91 [ "${1}" = "${KV_MAJOR}" ] && RESULT=0
92 fi
93
94 if [ -n "${2}" ]
95 then
96 RESULT=1
97 [ "${2}" = "${KV_MINOR}" ] && RESULT=0
98 fi
99
100 if [ -n "${3}" ]
101 then
102 RESULT=1
103 [ "${3}" = "${KV_PATCH}" ] && RESULT=0
104 fi
105 return ${RESULT}
106 }
107
108 get_version() {
109 local kbuild_output
110
111 # no need to execute this twice assuming KV_FULL is populated.
112 # we can force by unsetting KV_FULL
113 [ -n "${KV_FULL}" ] && return
114
115 # if we dont know KV_FULL, then we need too.
116 # make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR
117 unset KV_DIR
118
119 # KV_DIR will contain the full path to the sources directory we should use
120 einfo "Determining the location of the kernel source code"
121 [ -h "${KERNEL_DIR}" ] && KV_DIR="$(readlink -f ${KERNEL_DIR})"
122 [ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}"
123
124 if [ -z "${KV_DIR}" ]
125 then
126 eerror "Unable to find kernel sources at ${KERNEL_DIR}"
127 die
128 fi
129
130 # OK so now we know our sources directory, but they might be using
131 # KBUILD_OUTPUT, and we need this for .config and localversions-*
132 # so we better find it eh?
133 # do we pass KBUILD_OUTPUT on the CLI?
134 OUTPUT_DIR="${OUTPUT_DIR:-${KBUILD_OUTPUT}}"
135
136 # And if we didn't pass it, we can take a nosey in the Makefile
137 kbuild_output="$(getfilevar KBUILD_OUTPUT ${KV_DIR}/Makefile)"
138 OUTPUT_DIR="${OUTPUT_DIR:-${kbuild_output}}"
139
140 # And contrary to existing functions I feel we shouldn't trust the
141 # directory name to find version information as this seems insane.
142 # so we parse ${KV_DIR}/Makefile
143 KV_MAJOR="$(getfilevar VERSION ${KV_DIR}/Makefile)"
144 KV_MINOR="$(getfilevar PATCHLEVEL ${KV_DIR}/Makefile)"
145 KV_PATCH="$(getfilevar SUBLEVEL ${KV_DIR}/Makefile)"
146 KV_EXTRA="$(getfilevar EXTRAVERSION ${KV_DIR}/Makefile)"
147
148 # and in newer versions we can also pull LOCALVERSION if it is set.
149 # but before we do this, we need to find if we use a different object directory.
150 # This *WILL* break if the user is using localversions, but we assume it was
151 # caught before this if they are.
152 [ "${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}.${KV_EXTRA}" == "$(uname -r)" ] && \
153 OUTPUT_DIR="/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}.${KV_EXTRA}/build"
154
155 [ -h "${OUTPUT_DIR}" ] && KV_OUT_DIR="$(readlink -f ${OUTPUT_DIR})"
156 [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}"
157 if [ -n "${KV_OUT_DIR}" ];
158 then
159 einfo "Found kernel object directory:"
160 einfo " ${KV_OUT_DIR}"
161
162 KV_LOCAL="$(cat ${KV_OUT_DIR}/localversion* 2>/dev/null)"
163 fi
164 # and if we STILL haven't got it, then we better just set it to KV_DIR
165 KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}"
166
167 KV_LOCAL="${KV_LOCAL}$(cat ${KV_DIR}/localversion* 2>/dev/null)"
168 KV_LOCAL="${KV_LOCAL}$(getfilevar CONFIG_LOCALVERSION ${KV_OUT_DIR}/.config | sed 's:"::g')"
169
170 # And we should set KV_FULL to the full expanded version
171 KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}"
172
173 if [ -z "${KV_FULL}" ]
174 then
175 eerror "We are unable to find a usable kernel source tree in ${KV_DIR}"
176 eerror "Please check a kernel source exists in this directory."
177 die
178 else
179 einfo "Found kernel source directory:"
180 einfo " ${KV_DIR}"
181 einfo "with sources for kernel version:"
182 einfo " ${KV_FULL}"
183 fi
184 }
185
186
187
188
189 # ebuild check functions
190 # ---------------------------------------
191
192 check_kernel_built() {
193 # if we haven't determined the version yet, we need too.
194 get_version;
195
196 if [ ! -f "${KV_OUT_DIR}/System.map" ]
197 then
198 eerror "These sources have not yet been compiled."
199 eerror "We cannot build against an uncompiled tree."
200 eerror "To resolve this, please type the following:"
201 eerror
202 eerror "# cd ${KV_DIR}"
203 eerror "# make oldconfig"
204 eerror "# make bzImage modules modules_install"
205 eerror
206 eerror "Then please try merging this module again."
207 die "Kernel sources need compiling first"
208 fi
209 }
210
211 check_modules_supported() {
212 # if we haven't determined the version yet, we need too.
213 get_version;
214
215 getfilevar_isset CONFIG_MODULES ${KV_OUT_DIR}/.config
216 if [ "$?" != 0 ]
217 then
218 eerror "These sources do not support loading external modules."
219 eerror "to be able to use this module please enable \"Loadable modules support\""
220 eerror "in your kernel, recompile and then try merging this module again."
221 die No support for external modules in ${KV_FULL} config
222 fi
223 }
224
225 check_extra_config() {
226 local config negate error
227
228 # if we haven't determined the version yet, we need too.
229 get_version;
230
231 einfo "Checking for suitable kernel configuration options"
232 for config in ${CONFIG_CHECK}
233 do
234 negate="${config:0:1}"
235 if [ "${negate}" == "!" ];
236 then
237 config="${config:1}"
238 if getfilevar_isset ${config} ${KV_OUT_DIR}/.config ;
239 then
240 eerror " ${config}:\tshould not be set in the kernel configuration, but it is."
241 error=1
242 fi
243 else
244 if ! getfilevar_isset ${config} ${KV_OUT_DIR}/.config ;
245 then
246 eerror " ${config}:\tshould be set in the kernel configuration, but isn't"
247 error=1
248 fi
249 fi
250 done
251
252 if [ -n "${error}" ] ;
253 then
254 eerror "Please check to make sure these options are set correctly."
255 eerror "Once you have satisfied these options, please try merging"
256 eerror "this package again."
257 die Incorrect kernel configuration options
258 fi
259 }
260
261 check_zlibinflate() {
262 # if we haven't determined the version yet, we need too.
263 get_version;
264
265 # although I restructured this code - I really really really dont support it!
266
267 # bug #27882 - zlib routines are only linked into the kernel
268 # if something compiled into the kernel calls them
269 #
270 # plus, for the cloop module, it appears that there's no way
271 # to get cloop.o to include a static zlib if CONFIG_MODVERSIONS
272 # is on
273
274 local INFLATE
275 local DEFLATE
276
277 einfo "Determining the usability of ZLIB_INFLATE support in your kernel"
278
279 ebegin "checking ZLIB_INFLATE"
280 getfilevar_isbuiltin CONFIG_ZLIB_INFLATE ${KV_DIR}/.config
281 eend $?
282 [ "$?" != 0 ] && die
283
284 ebegin "checking ZLIB_DEFLATE"
285 getfilevar_isbuiltin CONFIG_ZLIB_DEFLATE ${KV_DIR}/.config
286 eend $?
287 [ "$?" != 0 ] && die
288
289
290 local LINENO_START
291 local LINENO_END
292 local SYMBOLS
293 local x
294
295 LINENO_END="$(grep -n 'CONFIG_ZLIB_INFLATE y' ${KV_DIR}/lib/Config.in | cut -d : -f 1)"
296 LINENO_START="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | grep -n 'if \[' | tail -n 1 | cut -d : -f 1)"
297 (( LINENO_AMOUNT = $LINENO_END - $LINENO_START ))
298 (( LINENO_END = $LINENO_END - 1 ))
299 SYMBOLS="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;')"
300
301 # okay, now we have a list of symbols
302 # we need to check each one in turn, to see whether it is set or not
303 for x in $SYMBOLS ; do
304 if [ "${!x}" = "y" ]; then
305 # we have a winner!
306 einfo "${x} ensures zlib is linked into your kernel - excellent"
307 return 0
308 fi
309 done
310
311 eerror
312 eerror "This kernel module requires ZLIB library support."
313 eerror "You have enabled zlib support in your kernel, but haven't enabled"
314 eerror "enabled any option that will ensure that zlib is linked into your"
315 eerror "kernel."
316 eerror
317 eerror "Please ensure that you enable at least one of these options:"
318 eerror
319
320 for x in $SYMBOLS ; do
321 eerror " * $x"
322 done
323
324 eerror
325 eerror "Please remember to recompile and install your kernel, and reboot"
326 eerror "into your new kernel before attempting to load this kernel module."
327
328 die "Kernel doesn't include zlib support"
329 }

  ViewVC Help
Powered by ViewVC 1.1.20