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

Contents of /eclass/linux-info.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Wed Nov 24 16:36:38 2004 UTC (9 years, 7 months ago) by johnm
Branch: MAIN
Updating kernel-2 to properly honour strict patch levels with *.diff , adding linux-* in preparation for the 'Big Module Move of 2004'

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
17
18 # 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 grep -e "^$1" $2 | sed 's: = :=:' | cut -d= -f2-
38 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 #
71 # 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 fi
186 }
187
188 check_zlibinflate() {
189 # if we haven't determined the version yet, we need too.
190 get_version;
191
192 # although I restructured this code - I really really really dont support it!
193
194 # bug #27882 - zlib routines are only linked into the kernel
195 # if something compiled into the kernel calls them
196 #
197 # plus, for the cloop module, it appears that there's no way
198 # to get cloop.o to include a static zlib if CONFIG_MODVERSIONS
199 # is on
200
201 local INFLATE
202 local DEFLATE
203
204 einfo "Determining the usability of ZLIB_INFLATE support in your kernel"
205
206 ebegin "checking ZLIB_INFLATE"
207 getfilevar_isbuiltin CONFIG_ZLIB_INFLATE ${KV_DIR}/.config
208 eend $?
209 [ "$?" != 0 ] && die
210
211 ebegin "checking ZLIB_DEFLATE"
212 getfilevar_isbuiltin CONFIG_ZLIB_DEFLATE ${KV_DIR}/.config
213 eend $?
214 [ "$?" != 0 ] && die
215
216
217 local LINENO_START
218 local LINENO_END
219 local SYMBOLS
220 local x
221
222 LINENO_END="$(grep -n 'CONFIG_ZLIB_INFLATE y' ${KV_DIR}/lib/Config.in | cut -d : -f 1)"
223 LINENO_START="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | grep -n 'if \[' | tail -n 1 | cut -d : -f 1)"
224 (( LINENO_AMOUNT = $LINENO_END - $LINENO_START ))
225 (( LINENO_END = $LINENO_END - 1 ))
226 SYMBOLS="$(head -n $LINENO_END ${KERNEL_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;')"
227
228 # okay, now we have a list of symbols
229 # we need to check each one in turn, to see whether it is set or not
230 for x in $SYMBOLS ; do
231 if [ "${!x}" = "y" ]; then
232 # we have a winner!
233 einfo "${x} ensures zlib is linked into your kernel - excellent"
234 return 0
235 fi
236 done
237
238 eerror
239 eerror "This kernel module requires ZLIB library support."
240 eerror "You have enabled zlib support in your kernel, but haven't enabled"
241 eerror "enabled any option that will ensure that zlib is linked into your"
242 eerror "kernel."
243 eerror
244 eerror "Please ensure that you enable at least one of these options:"
245 eerror
246
247 for x in $SYMBOLS ; do
248 eerror " * $x"
249 done
250
251 eerror
252 eerror "Please remember to recompile and install your kernel, and reboot"
253 eerror "into your new kernel before attempting to load this kernel module."
254
255 die "Kernel doesn't include zlib support"
256 }

  ViewVC Help
Powered by ViewVC 1.1.20