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

Diff of /eclass/linux-info.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 Revision 1.5
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.1 2004/11/24 16:36:38 johnm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.5 2004/12/01 18:08:57 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# ---------------------------------------
14KERNEL_DIR="${KERNEL_DIR:-/usr/src/linux}" 14KERNEL_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
24getfilevar() { 22getfilevar() {
25local ERROR 23local ERROR curpwd
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
34 eerror "getfilevar requires 2 variables, with the second a valid file." 31 eerror "getfilevar requires 2 variables, with the second a valid file."
35 eerror " getfilevar <VARIABLE> <CONFIGFILE>" 32 eerror " getfilevar <VARIABLE> <CONFIGFILE>"
36 else 33 else
34 curpwd="${PWD}"
35 cd $(dirname ${2})
36 echo $(echo -e "include $(basename ${2})\ne:\n\t@echo \$(${1})" | make -f - e)
37 cd ${curpwd}
37 grep -e "^$1" $2 | sed 's: = :=:' | cut -d= -f2- 38 # grep -e "^$1[= ]" $2 | sed 's: = :=:' | cut -d= -f2-
38 fi 39 fi
39} 40}
40 41
41getfilevar_isset() { 42getfilevar_isset() {
42local RESULT 43local RESULT
95 fi 96 fi
96 return ${RESULT} 97 return ${RESULT}
97} 98}
98 99
99get_version() { 100get_version() {
101 local kbuild_output
102
100 # no need to execute this twice assuming KV_FULL is populated. 103 # no need to execute this twice assuming KV_FULL is populated.
101 # we can force by unsetting KV_FULL 104 # we can force by unsetting KV_FULL
102 if [ -n "${KV_FULL}" ] 105 [ -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 106
109 # if we dont know KV_FULL, then we need too. 107 # 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 108 # make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR
111 unset KV_DIR 109 unset KV_DIR
112 110
118 if [ -z "${KV_DIR}" ] 116 if [ -z "${KV_DIR}" ]
119 then 117 then
120 eerror "Unable to find kernel sources at ${KERNEL_DIR}" 118 eerror "Unable to find kernel sources at ${KERNEL_DIR}"
121 die 119 die
122 fi 120 fi
121
122 # 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}}"
123 131
124 # And contrary to existing functions I feel we shouldn't trust the 132 # And contrary to existing functions I feel we shouldn't trust the
125 # directory name to find version information as this seems insane. 133 # directory name to find version information as this seems insane.
126 # so we parse ${KV_DIR}/Makefile 134 # so we parse ${KV_DIR}/Makefile
127 KV_MAJOR="$(getfilevar VERSION ${KV_DIR}/Makefile)" 135 KV_MAJOR="$(getfilevar VERSION ${KV_DIR}/Makefile)"
128 KV_MINOR="$(getfilevar PATCHLEVEL ${KV_DIR}/Makefile)" 136 KV_MINOR="$(getfilevar PATCHLEVEL ${KV_DIR}/Makefile)"
129 KV_PATCH="$(getfilevar SUBLEVEL ${KV_DIR}/Makefile)" 137 KV_PATCH="$(getfilevar SUBLEVEL ${KV_DIR}/Makefile)"
130 KV_EXTRA="$(getfilevar EXTRAVERSION ${KV_DIR}/Makefile)" 138 KV_EXTRA="$(getfilevar EXTRAVERSION ${KV_DIR}/Makefile)"
139
131 # and in newer versions we can also pull LOCALVERSION if it is set. 140 # and in newer versions we can also pull LOCALVERSION if it is set.
141 # 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)"
132 KV_LOCAL="$(cat ${KV_DIR}/localversion* 2>/dev/null)$(getfilevar CONFIG_LOCALVERSION ${KV_DIR}/.config | sed 's:"::g')" 160 KV_LOCAL="${KV_LOCAL}$(getfilevar CONFIG_LOCALVERSION ${KV_OUT_DIR}/.config | sed 's:"::g')"
133 161
134 # And we should set KV_FULL to the full expanded version 162 # And we should set KV_FULL to the full expanded version
135 KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}" 163 KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}"
136 164
137 if [ -z "${KV_FULL}" ] 165 if [ -z "${KV_FULL}" ]
155 183
156check_kernel_built() { 184check_kernel_built() {
157 # if we haven't determined the version yet, we need too. 185 # if we haven't determined the version yet, we need too.
158 get_version; 186 get_version;
159 187
160 if [ ! -f "${KV_DIR}/System.map" ] 188 if [ ! -f "${KV_OUT_DIR}/System.map" ]
161 then 189 then
162 eerror "These sources have not yet been compiled." 190 eerror "These sources have not yet been compiled."
163 eerror "We cannot build against an uncompiled tree." 191 eerror "We cannot build against an uncompiled tree."
164 eerror "To resolve this, please type the following:" 192 eerror "To resolve this, please type the following:"
165 eerror 193 eerror
174 202
175check_modules_supported() { 203check_modules_supported() {
176 # if we haven't determined the version yet, we need too. 204 # if we haven't determined the version yet, we need too.
177 get_version; 205 get_version;
178 206
179 getfilevar_isset CONFIG_MODULES ${KV_DIR}/.config 207 getfilevar_isset CONFIG_MODULES ${KV_OUT_DIR}/.config
180 if [ "$?" != 0 ] 208 if [ "$?" != 0 ]
181 then 209 then
182 eerror "These sources do not support loading external modules." 210 eerror "These sources do not support loading external modules."
183 eerror "to be able to use this module please enable \"Loadable modules support\"" 211 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." 212 eerror "in your kernel, recompile and then try merging this module again."
213 die No support for external modules in ${KV_FULL} config
214 fi
215}
216
217check_extra_config() {
218local 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 if getfilevar_isset ${config} ${KV_OUT_DIR}/.config ;
231 then
232 eerror " ${config}:\tshould not be set in the kernel configuration, but it is."
233 error=1
234 fi
235 else
236 if ! getfilevar_isset ${config} ${KV_OUT_DIR}/.config ;
237 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
185 fi 250 fi
186} 251}
187 252
188check_zlibinflate() { 253check_zlibinflate() {
189 # if we haven't determined the version yet, we need too. 254 # if we haven't determined the version yet, we need too.
221 286
222 LINENO_END="$(grep -n 'CONFIG_ZLIB_INFLATE y' ${KV_DIR}/lib/Config.in | cut -d : -f 1)" 287 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)" 288 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 )) 289 (( LINENO_AMOUNT = $LINENO_END - $LINENO_START ))
225 (( LINENO_END = $LINENO_END - 1 )) 290 (( 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;')" 291 SYMBOLS="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;')"
227 292
228 # okay, now we have a list of symbols 293 # 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 294 # we need to check each one in turn, to see whether it is set or not
230 for x in $SYMBOLS ; do 295 for x in $SYMBOLS ; do
231 if [ "${!x}" = "y" ]; then 296 if [ "${!x}" = "y" ]; then

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.20