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

Contents of /eclass/linux-info.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Sun Nov 28 09:47:31 2004 UTC (9 years, 9 months ago) by johnm
Branch: MAIN
Changes since 1.3: +40 -15 lines
Fixing up support for KBUILD_OUTPUT.

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

  ViewVC Help
Powered by ViewVC 1.1.20