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

Contents of /eclass/linux-info.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Thu Nov 25 19:47:18 2004 UTC (9 years, 8 months ago) by johnm
Branch: MAIN
Changes since 1.1: +1 -3 lines
Fixing permissions

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

  ViewVC Help
Powered by ViewVC 1.1.20