| 1 | # Copyright 1999-2004 Gentoo Foundation |
1 | # Copyright 1999-2004 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.3 2004/11/27 11:26:52 johnm Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.6 2004/12/01 23:26:43 johnm Exp $ |
| 4 | # |
4 | # |
| 5 | # This eclass provides functions for querying the installed kernel |
5 | # This eclass provides functions for querying the installed kernel |
| 6 | # source version, selected kernel options etc. |
6 | # source version, selected kernel options etc. |
| 7 | # |
7 | # |
| 8 | |
8 | |
| … | |
… | |
| 11 | |
11 | |
| 12 | # Overwritable environment Var's |
12 | # Overwritable environment Var's |
| 13 | # --------------------------------------- |
13 | # --------------------------------------- |
| 14 | KERNEL_DIR="${KERNEL_DIR:-/usr/src/linux}" |
14 | KERNEL_DIR="${KERNEL_DIR:-/usr/src/linux}" |
| 15 | |
15 | |
| 16 | |
|
|
| 17 | |
|
|
| 18 | # File Functions |
16 | # File Functions |
| 19 | # --------------------------------------- |
17 | # --------------------------------------- |
| 20 | |
18 | |
| 21 | # getfilevar accepts 2 vars as follows: |
19 | # getfilevar accepts 2 vars as follows: |
| 22 | # getfilevar <VARIABLE> <CONFIGFILE> |
20 | # getfilevar <VARIABLE> <CONFIGFILE> |
| 23 | |
21 | |
| 24 | getfilevar() { |
22 | getfilevar() { |
| 25 | local ERROR |
23 | local ERROR workingdir basefname basedname arch |
| 26 | ERROR=0 |
24 | ERROR=0 |
| 27 | |
25 | |
| 28 | [ -z "${1}" ] && ERROR=1 |
26 | [ -z "${1}" ] && ERROR=1 |
| 29 | [ -z "${2}" ] && ERROR=1 |
|
|
| 30 | [ ! -f "${2}" ] && ERROR=1 |
27 | [ ! -f "${2}" ] && ERROR=1 |
| 31 | |
28 | |
| 32 | if [ "${ERROR}" = 1 ] |
29 | if [ "${ERROR}" = 1 ] |
| 33 | then |
30 | then |
|
|
31 | ebeep |
|
|
32 | echo -e "\n" |
| 34 | eerror "getfilevar requires 2 variables, with the second a valid file." |
33 | eerror "getfilevar requires 2 variables, with the second a valid file." |
| 35 | eerror " getfilevar <VARIABLE> <CONFIGFILE>" |
34 | eerror " getfilevar <VARIABLE> <CONFIGFILE>" |
| 36 | else |
35 | else |
| 37 | grep -e "^$1[= ]" $2 | sed 's: = :=:' | cut -d= -f2- |
36 | workingdir=${PWD} |
|
|
37 | basefname=$(basename ${2}) |
|
|
38 | basedname=$(dirname ${2}) |
|
|
39 | arch=${ARCH} |
|
|
40 | unset ARCH |
|
|
41 | |
|
|
42 | cd ${basedname} |
|
|
43 | echo -e "include ${basefname}\ne:\n\t@echo \$(${1})" | make -f - e |
|
|
44 | cd ${workingdir} |
|
|
45 | |
|
|
46 | ARCH=${arch} |
| 38 | fi |
47 | fi |
| 39 | } |
48 | } |
| 40 | |
49 | |
| 41 | getfilevar_isset() { |
50 | getfilevar_isset() { |
| 42 | local RESULT |
51 | local RESULT |
| … | |
… | |
| 95 | fi |
104 | fi |
| 96 | return ${RESULT} |
105 | return ${RESULT} |
| 97 | } |
106 | } |
| 98 | |
107 | |
| 99 | get_version() { |
108 | get_version() { |
|
|
109 | local kbuild_output |
|
|
110 | |
| 100 | # no need to execute this twice assuming KV_FULL is populated. |
111 | # no need to execute this twice assuming KV_FULL is populated. |
| 101 | # we can force by unsetting KV_FULL |
112 | # we can force by unsetting KV_FULL |
| 102 | if [ -n "${KV_FULL}" ] |
113 | [ -n "${KV_FULL}" ] && return |
| 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 | |
114 | |
| 109 | # if we dont know KV_FULL, then we need too. |
115 | # 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 |
116 | # make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR |
| 111 | unset KV_DIR |
117 | unset KV_DIR |
| 112 | |
118 | |
| … | |
… | |
| 118 | if [ -z "${KV_DIR}" ] |
124 | if [ -z "${KV_DIR}" ] |
| 119 | then |
125 | then |
| 120 | eerror "Unable to find kernel sources at ${KERNEL_DIR}" |
126 | eerror "Unable to find kernel sources at ${KERNEL_DIR}" |
| 121 | die |
127 | die |
| 122 | fi |
128 | fi |
|
|
129 | |
|
|
130 | # OK so now we know our sources directory, but they might be using |
|
|
131 | # KBUILD_OUTPUT, and we need this for .config and localversions-* |
|
|
132 | # so we better find it eh? |
|
|
133 | # do we pass KBUILD_OUTPUT on the CLI? |
|
|
134 | OUTPUT_DIR="${OUTPUT_DIR:-${KBUILD_OUTPUT}}" |
|
|
135 | |
|
|
136 | # And if we didn't pass it, we can take a nosey in the Makefile |
|
|
137 | kbuild_output="$(getfilevar KBUILD_OUTPUT ${KV_DIR}/Makefile)" |
|
|
138 | OUTPUT_DIR="${OUTPUT_DIR:-${kbuild_output}}" |
| 123 | |
139 | |
| 124 | # And contrary to existing functions I feel we shouldn't trust the |
140 | # And contrary to existing functions I feel we shouldn't trust the |
| 125 | # directory name to find version information as this seems insane. |
141 | # directory name to find version information as this seems insane. |
| 126 | # so we parse ${KV_DIR}/Makefile |
142 | # so we parse ${KV_DIR}/Makefile |
| 127 | KV_MAJOR="$(getfilevar VERSION ${KV_DIR}/Makefile)" |
143 | KV_MAJOR="$(getfilevar VERSION ${KV_DIR}/Makefile)" |
| 128 | KV_MINOR="$(getfilevar PATCHLEVEL ${KV_DIR}/Makefile)" |
144 | KV_MINOR="$(getfilevar PATCHLEVEL ${KV_DIR}/Makefile)" |
| 129 | KV_PATCH="$(getfilevar SUBLEVEL ${KV_DIR}/Makefile)" |
145 | KV_PATCH="$(getfilevar SUBLEVEL ${KV_DIR}/Makefile)" |
| 130 | KV_EXTRA="$(getfilevar EXTRAVERSION ${KV_DIR}/Makefile)" |
146 | KV_EXTRA="$(getfilevar EXTRAVERSION ${KV_DIR}/Makefile)" |
|
|
147 | |
| 131 | # and in newer versions we can also pull LOCALVERSION if it is set. |
148 | # and in newer versions we can also pull LOCALVERSION if it is set. |
|
|
149 | # but before we do this, we need to find if we use a different object directory. |
|
|
150 | # This *WILL* break if the user is using localversions, but we assume it was |
|
|
151 | # caught before this if they are. |
|
|
152 | [ "${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}.${KV_EXTRA}" == "$(uname -r)" ] && \ |
|
|
153 | OUTPUT_DIR="/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}.${KV_EXTRA}/build" |
|
|
154 | |
|
|
155 | [ -h "${OUTPUT_DIR}" ] && KV_OUT_DIR="$(readlink -f ${OUTPUT_DIR})" |
|
|
156 | [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}" |
|
|
157 | if [ -n "${KV_OUT_DIR}" ]; |
|
|
158 | then |
|
|
159 | einfo "Found kernel object directory:" |
|
|
160 | einfo " ${KV_OUT_DIR}" |
|
|
161 | |
|
|
162 | KV_LOCAL="$(cat ${KV_OUT_DIR}/localversion* 2>/dev/null)" |
|
|
163 | fi |
|
|
164 | # and if we STILL haven't got it, then we better just set it to KV_DIR |
|
|
165 | KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}" |
|
|
166 | |
|
|
167 | KV_LOCAL="${KV_LOCAL}$(cat ${KV_DIR}/localversion* 2>/dev/null)" |
| 132 | KV_LOCAL="$(cat ${KV_DIR}/localversion* 2>/dev/null)$(getfilevar CONFIG_LOCALVERSION ${KV_DIR}/.config | sed 's:"::g')" |
168 | KV_LOCAL="${KV_LOCAL}$(getfilevar CONFIG_LOCALVERSION ${KV_OUT_DIR}/.config | sed 's:"::g')" |
| 133 | |
169 | |
| 134 | # And we should set KV_FULL to the full expanded version |
170 | # And we should set KV_FULL to the full expanded version |
| 135 | KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}" |
171 | KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}" |
| 136 | |
172 | |
| 137 | if [ -z "${KV_FULL}" ] |
173 | if [ -z "${KV_FULL}" ] |
| … | |
… | |
| 155 | |
191 | |
| 156 | check_kernel_built() { |
192 | check_kernel_built() { |
| 157 | # if we haven't determined the version yet, we need too. |
193 | # if we haven't determined the version yet, we need too. |
| 158 | get_version; |
194 | get_version; |
| 159 | |
195 | |
| 160 | if [ ! -f "${KV_DIR}/System.map" ] |
196 | if [ ! -f "${KV_OUT_DIR}/System.map" ] |
| 161 | then |
197 | then |
| 162 | eerror "These sources have not yet been compiled." |
198 | eerror "These sources have not yet been compiled." |
| 163 | eerror "We cannot build against an uncompiled tree." |
199 | eerror "We cannot build against an uncompiled tree." |
| 164 | eerror "To resolve this, please type the following:" |
200 | eerror "To resolve this, please type the following:" |
| 165 | eerror |
201 | eerror |
| … | |
… | |
| 174 | |
210 | |
| 175 | check_modules_supported() { |
211 | check_modules_supported() { |
| 176 | # if we haven't determined the version yet, we need too. |
212 | # if we haven't determined the version yet, we need too. |
| 177 | get_version; |
213 | get_version; |
| 178 | |
214 | |
| 179 | getfilevar_isset CONFIG_MODULES ${KV_DIR}/.config |
215 | getfilevar_isset CONFIG_MODULES ${KV_OUT_DIR}/.config |
| 180 | if [ "$?" != 0 ] |
216 | if [ "$?" != 0 ] |
| 181 | then |
217 | then |
| 182 | eerror "These sources do not support loading external modules." |
218 | eerror "These sources do not support loading external modules." |
| 183 | eerror "to be able to use this module please enable \"Loadable modules support\"" |
219 | 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." |
220 | eerror "in your kernel, recompile and then try merging this module again." |
| 185 | die No support for external modules in ${KV_FUll} config |
221 | die No support for external modules in ${KV_FULL} config |
| 186 | fi |
222 | fi |
| 187 | } |
223 | } |
| 188 | |
224 | |
| 189 | check_extra_config() { |
225 | check_extra_config() { |
| 190 | local config negate error |
226 | local config negate error |
| … | |
… | |
| 197 | do |
233 | do |
| 198 | negate="${config:0:1}" |
234 | negate="${config:0:1}" |
| 199 | if [ "${negate}" == "!" ]; |
235 | if [ "${negate}" == "!" ]; |
| 200 | then |
236 | then |
| 201 | config="${config:1}" |
237 | config="${config:1}" |
| 202 | if getfilevar_isset ${config} ${KV_DIR}/.config ; |
238 | if getfilevar_isset ${config} ${KV_OUT_DIR}/.config ; |
| 203 | then |
239 | then |
| 204 | eerror " ${config}:\tshould not be set in the kernel configuration, but it is." |
240 | eerror " ${config}:\tshould not be set in the kernel configuration, but it is." |
| 205 | error=1 |
241 | error=1 |
| 206 | fi |
242 | fi |
| 207 | else |
243 | else |
| 208 | if ! getfilevar_isset ${config} ${KV_DIR}/.config ; |
244 | if ! getfilevar_isset ${config} ${KV_OUT_DIR}/.config ; |
| 209 | then |
245 | then |
| 210 | eerror " ${config}:\tshould be set in the kernel configuration, but isn't" |
246 | eerror " ${config}:\tshould be set in the kernel configuration, but isn't" |
| 211 | error=1 |
247 | error=1 |
| 212 | fi |
248 | fi |
| 213 | fi |
249 | fi |
| … | |
… | |
| 258 | |
294 | |
| 259 | LINENO_END="$(grep -n 'CONFIG_ZLIB_INFLATE y' ${KV_DIR}/lib/Config.in | cut -d : -f 1)" |
295 | 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)" |
296 | 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 )) |
297 | (( LINENO_AMOUNT = $LINENO_END - $LINENO_START )) |
| 262 | (( LINENO_END = $LINENO_END - 1 )) |
298 | (( 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;')" |
299 | SYMBOLS="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;')" |
| 264 | |
300 | |
| 265 | # okay, now we have a list of symbols |
301 | # 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 |
302 | # we need to check each one in turn, to see whether it is set or not |
| 267 | for x in $SYMBOLS ; do |
303 | for x in $SYMBOLS ; do |
| 268 | if [ "${!x}" = "y" ]; then |
304 | if [ "${!x}" = "y" ]; then |