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

Contents of /eclass/linux-info.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Sat Nov 27 11:26:52 2004 UTC (9 years, 7 months ago) by johnm
Branch: MAIN
Changes since 1.2: +41 -2 lines
add support for CHECK_CONFIG=

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

  ViewVC Help
Powered by ViewVC 1.1.20