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

Contents of /eclass/linux-info.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Wed Dec 1 18:08:57 2004 UTC (9 years, 8 months ago) by johnm
Branch: MAIN
Changes since 1.4: +6 -3 lines
Updating PV to PVR

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

  ViewVC Help
Powered by ViewVC 1.1.20