/[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.4
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.4 2004/11/28 09:47:31 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>
32 if [ "${ERROR}" = 1 ] 30 if [ "${ERROR}" = 1 ]
33 then 31 then
34 eerror "getfilevar requires 2 variables, with the second a valid file." 32 eerror "getfilevar requires 2 variables, with the second a valid file."
35 eerror " getfilevar <VARIABLE> <CONFIGFILE>" 33 eerror " getfilevar <VARIABLE> <CONFIGFILE>"
36 else 34 else
37 grep -e "^$1" $2 | sed 's: = :=:' | cut -d= -f2- 35 grep -e "^$1[= ]" $2 | sed 's: = :=:' | cut -d= -f2-
38 fi 36 fi
39} 37}
40 38
41getfilevar_isset() { 39getfilevar_isset() {
42local RESULT 40local RESULT
95 fi 93 fi
96 return ${RESULT} 94 return ${RESULT}
97} 95}
98 96
99get_version() { 97get_version() {
98 local kbuild_output
99
100 # no need to execute this twice assuming KV_FULL is populated. 100 # no need to execute this twice assuming KV_FULL is populated.
101 # we can force by unsetting KV_FULL 101 # we can force by unsetting KV_FULL
102 if [ -n "${KV_FULL}" ] 102 [ -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 103
109 # if we dont know KV_FULL, then we need too. 104 # 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 105 # make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR
111 unset KV_DIR 106 unset KV_DIR
112 107
118 if [ -z "${KV_DIR}" ] 113 if [ -z "${KV_DIR}" ]
119 then 114 then
120 eerror "Unable to find kernel sources at ${KERNEL_DIR}" 115 eerror "Unable to find kernel sources at ${KERNEL_DIR}"
121 die 116 die
122 fi 117 fi
118
119 # OK so now we know our sources directory, but they might be using
120 # KBUILD_OUTPUT, and we need this for .config and localversions-*
121 # so we better find it eh?
122 # do we pass KBUILD_OUTPUT on the CLI?
123 OUTPUT_DIR="${OUTPUT_DIR:-${KBUILD_OUTPUT}}"
124
125 # Or maybe KBUILD_OUTPUT is set in Makefile?
126 kbuild_output="$(getfilevar KBUILD_OUTPUT ${KV_DIR}/Makefile)"
127 OUTPUT_DIR="${OUTPUT_DIR:-${kbuild_output}}"
123 128
124 # And contrary to existing functions I feel we shouldn't trust the 129 # And contrary to existing functions I feel we shouldn't trust the
125 # directory name to find version information as this seems insane. 130 # directory name to find version information as this seems insane.
126 # so we parse ${KV_DIR}/Makefile 131 # so we parse ${KV_DIR}/Makefile
127 KV_MAJOR="$(getfilevar VERSION ${KV_DIR}/Makefile)" 132 KV_MAJOR="$(getfilevar VERSION ${KV_DIR}/Makefile)"
128 KV_MINOR="$(getfilevar PATCHLEVEL ${KV_DIR}/Makefile)" 133 KV_MINOR="$(getfilevar PATCHLEVEL ${KV_DIR}/Makefile)"
129 KV_PATCH="$(getfilevar SUBLEVEL ${KV_DIR}/Makefile)" 134 KV_PATCH="$(getfilevar SUBLEVEL ${KV_DIR}/Makefile)"
130 KV_EXTRA="$(getfilevar EXTRAVERSION ${KV_DIR}/Makefile)" 135 KV_EXTRA="$(getfilevar EXTRAVERSION ${KV_DIR}/Makefile)"
136
131 # and in newer versions we can also pull LOCALVERSION if it is set. 137 # and in newer versions we can also pull LOCALVERSION if it is set.
138 # but before we do this, we need to find if we use a different object directory.
139 # This *WILL* break if the user is using localversions, but we assume it was
140 # caught before this if they are.
141 [ "${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}.${KV_EXTRA}" == "$(uname -r)" ] && \
142 OUTPUT_DIR="/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}.${KV_EXTRA}/build"
143
144 [ -h "${OUTPUT_DIR}" ] && KV_OUT_DIR="$(readlink -f ${OUTPUT_DIR})"
145 [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}"
146 if [ -n "${KV_OUT_DIR}" ];
147 then
148 einfo "Found kernel object directory:"
149 einfo " ${KV_OUT_DIR}"
150
151 KV_LOCAL="$(cat ${KV_OUT_DIR}/localversion* 2>/dev/null)"
152 fi
153 # and if we STILL haven't got it, then we better just set it to KV_DIR
154 KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}"
155
156 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')" 157 KV_LOCAL="${KV_LOCAL}$(getfilevar CONFIG_LOCALVERSION ${KV_OUT_DIR}/.config | sed 's:"::g')"
133 158
134 # And we should set KV_FULL to the full expanded version 159 # And we should set KV_FULL to the full expanded version
135 KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}" 160 KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}"
136 161
137 if [ -z "${KV_FULL}" ] 162 if [ -z "${KV_FULL}" ]
155 180
156check_kernel_built() { 181check_kernel_built() {
157 # if we haven't determined the version yet, we need too. 182 # if we haven't determined the version yet, we need too.
158 get_version; 183 get_version;
159 184
160 if [ ! -f "${KV_DIR}/System.map" ] 185 if [ ! -f "${KV_OUT_DIR}/System.map" ]
161 then 186 then
162 eerror "These sources have not yet been compiled." 187 eerror "These sources have not yet been compiled."
163 eerror "We cannot build against an uncompiled tree." 188 eerror "We cannot build against an uncompiled tree."
164 eerror "To resolve this, please type the following:" 189 eerror "To resolve this, please type the following:"
165 eerror 190 eerror
174 199
175check_modules_supported() { 200check_modules_supported() {
176 # if we haven't determined the version yet, we need too. 201 # if we haven't determined the version yet, we need too.
177 get_version; 202 get_version;
178 203
179 getfilevar_isset CONFIG_MODULES ${KV_DIR}/.config 204 getfilevar_isset CONFIG_MODULES ${KV_OUT_DIR}/.config
180 if [ "$?" != 0 ] 205 if [ "$?" != 0 ]
181 then 206 then
182 eerror "These sources do not support loading external modules." 207 eerror "These sources do not support loading external modules."
183 eerror "to be able to use this module please enable \"Loadable modules support\"" 208 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." 209 eerror "in your kernel, recompile and then try merging this module again."
210 die No support for external modules in ${KV_FULL} config
211 fi
212}
213
214check_extra_config() {
215local config negate error
216
217 # if we haven't determined the version yet, we need too.
218 get_version;
219
220 einfo "Checking for suitable kernel configuration options"
221 for config in ${CONFIG_CHECK}
222 do
223 negate="${config:0:1}"
224 if [ "${negate}" == "!" ];
225 then
226 config="${config:1}"
227 if getfilevar_isset ${config} ${KV_OUT_DIR}/.config ;
228 then
229 eerror " ${config}:\tshould not be set in the kernel configuration, but it is."
230 error=1
231 fi
232 else
233 if ! getfilevar_isset ${config} ${KV_OUT_DIR}/.config ;
234 then
235 eerror " ${config}:\tshould be set in the kernel configuration, but isn't"
236 error=1
237 fi
238 fi
239 done
240
241 if [ -n "${error}" ] ;
242 then
243 eerror "Please check to make sure these options are set correctly."
244 eerror "Once you have satisfied these options, please try merging"
245 eerror "this package again."
246 die Incorrect kernel configuration options
185 fi 247 fi
186} 248}
187 249
188check_zlibinflate() { 250check_zlibinflate() {
189 # if we haven't determined the version yet, we need too. 251 # if we haven't determined the version yet, we need too.
221 283
222 LINENO_END="$(grep -n 'CONFIG_ZLIB_INFLATE y' ${KV_DIR}/lib/Config.in | cut -d : -f 1)" 284 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)" 285 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 )) 286 (( LINENO_AMOUNT = $LINENO_END - $LINENO_START ))
225 (( LINENO_END = $LINENO_END - 1 )) 287 (( 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;')" 288 SYMBOLS="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;')"
227 289
228 # okay, now we have a list of symbols 290 # 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 291 # we need to check each one in turn, to see whether it is set or not
230 for x in $SYMBOLS ; do 292 for x in $SYMBOLS ; do
231 if [ "${!x}" = "y" ]; then 293 if [ "${!x}" = "y" ]; then

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

  ViewVC Help
Powered by ViewVC 1.1.20