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

Contents of /eclass/linux-info.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Fri Dec 10 22:43:03 2004 UTC (9 years, 7 months ago) by johnm
Branch: MAIN
Changes since 1.8: +8 -8 lines
Moving .config check, so this is purely a sanity test now. If we use LOCALVERSION in the .config, we will laready have failed the test but the sanity check will cause it to bail. Fixes bug: #73726

1 johnm 1.1 # Copyright 1999-2004 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 johnm 1.9 # $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.8 2004/12/06 18:33:10 johnm Exp $
4 johnm 1.1 #
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 johnm 1.8 EXPORT_FUNCTIONS pkg_setup
12 johnm 1.1
13     # Overwritable environment Var's
14     # ---------------------------------------
15     KERNEL_DIR="${KERNEL_DIR:-/usr/src/linux}"
16    
17 johnm 1.7
18     # Pulled from eutils as it might be more useful only being here since
19     # very few ebuilds which dont use this eclass will ever ever use these functions
20     set_arch_to_kernel() {
21     export PORTAGE_ARCH="${ARCH}"
22     case ${ARCH} in
23     x86) export ARCH="i386";;
24     amd64) export ARCH="x86_64";;
25     hppa) export ARCH="parisc";;
26     mips) export ARCH="mips";;
27     *) export ARCH="${ARCH}";;
28     esac
29     }
30    
31     # set's ARCH back to what portage expects
32     set_arch_to_portage() {
33     export ARCH="${PORTAGE_ARCH}"
34     }
35    
36 johnm 1.1 # File Functions
37     # ---------------------------------------
38    
39     # getfilevar accepts 2 vars as follows:
40     # getfilevar <VARIABLE> <CONFIGFILE>
41    
42     getfilevar() {
43 johnm 1.7 local ERROR workingdir basefname basedname xarch
44 johnm 1.1 ERROR=0
45    
46     [ -z "${1}" ] && ERROR=1
47     [ ! -f "${2}" ] && ERROR=1
48    
49     if [ "${ERROR}" = 1 ]
50     then
51 johnm 1.6 ebeep
52     echo -e "\n"
53 johnm 1.1 eerror "getfilevar requires 2 variables, with the second a valid file."
54     eerror " getfilevar <VARIABLE> <CONFIGFILE>"
55     else
56 johnm 1.6 workingdir=${PWD}
57     basefname=$(basename ${2})
58     basedname=$(dirname ${2})
59 johnm 1.7 xarch=${ARCH}
60 johnm 1.6 unset ARCH
61    
62     cd ${basedname}
63 johnm 1.7 echo -e "include ${basefname}\ne:\n\t@echo \$(${1})" | \
64     make -f - e 2>/dev/null
65 johnm 1.6 cd ${workingdir}
66    
67 johnm 1.7 ARCH=${xarch}
68 johnm 1.1 fi
69     }
70    
71 johnm 1.7 linux_chkconfig_present() {
72 johnm 1.1 local RESULT
73 johnm 1.7 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)"
74 johnm 1.1 [ "${RESULT}" = "m" -o "${RESULT}" = "y" ] && return 0 || return 1
75     }
76    
77 johnm 1.7 linux_chkconfig_module() {
78 johnm 1.1 local RESULT
79 johnm 1.7 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)"
80 johnm 1.1 [ "${RESULT}" = "m" ] && return 0 || return 1
81     }
82    
83 johnm 1.7 linux_chkconfig_builtin() {
84 johnm 1.1 local RESULT
85 johnm 1.7 RESULT="$(getfilevar CONFIG_${1} ${KV_OUT_DIR}/.config)"
86 johnm 1.1 [ "${RESULT}" = "y" ] && return 0 || return 1
87     }
88    
89 johnm 1.7 linux_chkconfig_string() {
90     getfilevar "CONFIG_${1}" "${KV_OUT_DIR}/.config"
91     }
92    
93 johnm 1.1 # Versioning Functions
94     # ---------------------------------------
95    
96     # kernel_is returns true when the version is the same as the passed version
97     #
98     # For Example where KV = 2.6.9
99     # kernel_is 2 4 returns false
100     # kernel_is 2 returns true
101     # kernel_is 2 6 returns true
102     # kernel_is 2 6 8 returns false
103     # kernel_is 2 6 9 returns true
104 johnm 1.3 #
105 johnm 1.1 # got the jist yet?
106    
107     kernel_is() {
108     # if we haven't determined the version yet, we need too.
109     get_version;
110    
111     local RESULT
112     RESULT=1
113    
114     if [ -n "${1}" ]
115     then
116     [ "${1}" = "${KV_MAJOR}" ] && RESULT=0
117     fi
118    
119     if [ -n "${2}" ]
120     then
121     RESULT=1
122     [ "${2}" = "${KV_MINOR}" ] && RESULT=0
123     fi
124    
125     if [ -n "${3}" ]
126     then
127     RESULT=1
128     [ "${3}" = "${KV_PATCH}" ] && RESULT=0
129     fi
130     return ${RESULT}
131     }
132    
133     get_version() {
134 johnm 1.4 local kbuild_output
135    
136 johnm 1.1 # no need to execute this twice assuming KV_FULL is populated.
137     # we can force by unsetting KV_FULL
138 johnm 1.4 [ -n "${KV_FULL}" ] && return
139 johnm 1.1
140     # if we dont know KV_FULL, then we need too.
141     # make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR
142     unset KV_DIR
143    
144     # KV_DIR will contain the full path to the sources directory we should use
145     einfo "Determining the location of the kernel source code"
146     [ -h "${KERNEL_DIR}" ] && KV_DIR="$(readlink -f ${KERNEL_DIR})"
147     [ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}"
148    
149     if [ -z "${KV_DIR}" ]
150     then
151     eerror "Unable to find kernel sources at ${KERNEL_DIR}"
152 johnm 1.7 einfo "This package requires Linux sources."
153     if [ "${KERNEL_DIR}" == "/usr/src/linux" ] ; then
154     einfo "Please make sure that ${KERNEL_DIR} points at your running kernel, "
155     einfo "(or the kernel you wish to build against)."
156     einfo "Alternatively, set the KERNEL_DIR environment variable to the kernel sources location"
157     else
158     einfo "Please ensure that the KERNEL_DIR environment variable points at full Linux sources of the kernel you wish to compile against."
159     fi
160     die "Cannot locate Linux sources at ${KERNEL_DIR}"
161     fi
162    
163     einfo "Found kernel source directory:"
164     einfo " ${KV_DIR}"
165    
166     if [ ! -s "${KV_DIR}/Makefile" ]
167     then
168     eerror "Could not find a Makefile in the kernel source directory."
169     eerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources"
170     die "Makefile not found in ${KV_DIR}"
171     fi
172 johnm 1.1
173 johnm 1.4 # OK so now we know our sources directory, but they might be using
174     # KBUILD_OUTPUT, and we need this for .config and localversions-*
175     # so we better find it eh?
176     # do we pass KBUILD_OUTPUT on the CLI?
177     OUTPUT_DIR="${OUTPUT_DIR:-${KBUILD_OUTPUT}}"
178    
179 johnm 1.6 # And if we didn't pass it, we can take a nosey in the Makefile
180 johnm 1.4 kbuild_output="$(getfilevar KBUILD_OUTPUT ${KV_DIR}/Makefile)"
181     OUTPUT_DIR="${OUTPUT_DIR:-${kbuild_output}}"
182    
183 johnm 1.1 # And contrary to existing functions I feel we shouldn't trust the
184     # directory name to find version information as this seems insane.
185     # so we parse ${KV_DIR}/Makefile
186     KV_MAJOR="$(getfilevar VERSION ${KV_DIR}/Makefile)"
187     KV_MINOR="$(getfilevar PATCHLEVEL ${KV_DIR}/Makefile)"
188     KV_PATCH="$(getfilevar SUBLEVEL ${KV_DIR}/Makefile)"
189     KV_EXTRA="$(getfilevar EXTRAVERSION ${KV_DIR}/Makefile)"
190 johnm 1.4
191 johnm 1.7 if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ]
192     then
193     eerror "Could not detect kernel version."
194     eerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources"
195     die "Could not parse version info from ${KV_DIR}/Makefile"
196     fi
197    
198 johnm 1.1 # and in newer versions we can also pull LOCALVERSION if it is set.
199 johnm 1.4 # but before we do this, we need to find if we use a different object directory.
200     # This *WILL* break if the user is using localversions, but we assume it was
201     # caught before this if they are.
202     [ "${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}.${KV_EXTRA}" == "$(uname -r)" ] && \
203 johnm 1.7 OUTPUT_DIR="${OUTPUT_DIR:-/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}.${KV_EXTRA}/build}"
204 johnm 1.4
205     [ -h "${OUTPUT_DIR}" ] && KV_OUT_DIR="$(readlink -f ${OUTPUT_DIR})"
206     [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}"
207     if [ -n "${KV_OUT_DIR}" ];
208     then
209     einfo "Found kernel object directory:"
210     einfo " ${KV_OUT_DIR}"
211    
212     KV_LOCAL="$(cat ${KV_OUT_DIR}/localversion* 2>/dev/null)"
213     fi
214     # and if we STILL haven't got it, then we better just set it to KV_DIR
215     KV_OUT_DIR="${KV_OUT_DIR:-${KV_DIR}}"
216    
217     KV_LOCAL="${KV_LOCAL}$(cat ${KV_DIR}/localversion* 2>/dev/null)"
218 johnm 1.7 KV_LOCAL="${KV_LOCAL}$(linux_chkconfig_string LOCALVERSION)"
219     KV_LOCAL="${KV_LOCAL//\"/}"
220 johnm 1.1
221     # And we should set KV_FULL to the full expanded version
222     KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}"
223    
224 johnm 1.7 einfo "Found sources for kernel version:"
225     einfo " ${KV_FULL}"
226 johnm 1.9
227     if [ ! -s "${KV_OUT_DIR}/.config" ]
228     then
229     eerror "Could not find a usable .config in the kernel source directory."
230     eerror "Please ensure that ${KERNEL_DIR} points to a configured set of Linux sources"
231     die ".config not found in ${KV_OUT_DIR}"
232     fi
233 johnm 1.1 }
234    
235    
236    
237    
238     # ebuild check functions
239     # ---------------------------------------
240    
241     check_kernel_built() {
242     # if we haven't determined the version yet, we need too.
243     get_version;
244    
245 johnm 1.4 if [ ! -f "${KV_OUT_DIR}/System.map" ]
246 johnm 1.1 then
247     eerror "These sources have not yet been compiled."
248     eerror "We cannot build against an uncompiled tree."
249     eerror "To resolve this, please type the following:"
250     eerror
251     eerror "# cd ${KV_DIR}"
252     eerror "# make oldconfig"
253     eerror "# make bzImage modules modules_install"
254     eerror
255     eerror "Then please try merging this module again."
256     die "Kernel sources need compiling first"
257     fi
258     }
259    
260     check_modules_supported() {
261     # if we haven't determined the version yet, we need too.
262     get_version;
263    
264 johnm 1.7 if ! linux_chkconfig_builtin "MODULES"
265 johnm 1.1 then
266     eerror "These sources do not support loading external modules."
267     eerror "to be able to use this module please enable \"Loadable modules support\""
268     eerror "in your kernel, recompile and then try merging this module again."
269 johnm 1.7 die "No support for external modules in ${KV_FULL} config"
270 johnm 1.3 fi
271     }
272    
273     check_extra_config() {
274 johnm 1.7 local config negate error local_error
275 johnm 1.3
276     # if we haven't determined the version yet, we need too.
277     get_version;
278    
279     einfo "Checking for suitable kernel configuration options"
280     for config in ${CONFIG_CHECK}
281     do
282     negate="${config:0:1}"
283     if [ "${negate}" == "!" ];
284     then
285     config="${config:1}"
286 johnm 1.7 if linux_chkconfig_present ${config}
287 johnm 1.3 then
288 johnm 1.7 local_error="${config}_ERROR"
289     local_error="${!local_error}"
290     [ -n "${local_error}" ] && eerror " ${local_error}" || \
291     eerror " CONFIG_${config}:\tshould not be set in the kernel configuration, but it is."
292 johnm 1.3 error=1
293     fi
294     else
295 johnm 1.7 if ! linux_chkconfig_present ${config}
296 johnm 1.3 then
297 johnm 1.7 local_error="${config}_ERROR"
298     local_error="${!local_error}"
299     [ -n "${local_error}" ] && eerror " ${local_error}" || \
300     eerror " CONFIG_${config}:\tshould be set in the kernel configuration, but isn't"
301 johnm 1.3 error=1
302     fi
303     fi
304     done
305    
306     if [ -n "${error}" ] ;
307     then
308     eerror "Please check to make sure these options are set correctly."
309     eerror "Once you have satisfied these options, please try merging"
310     eerror "this package again."
311 johnm 1.7 die "Incorrect kernel configuration options"
312 johnm 1.1 fi
313     }
314    
315     check_zlibinflate() {
316     # if we haven't determined the version yet, we need too.
317     get_version;
318    
319     # although I restructured this code - I really really really dont support it!
320    
321     # bug #27882 - zlib routines are only linked into the kernel
322     # if something compiled into the kernel calls them
323     #
324     # plus, for the cloop module, it appears that there's no way
325     # to get cloop.o to include a static zlib if CONFIG_MODVERSIONS
326     # is on
327    
328     local INFLATE
329     local DEFLATE
330    
331     einfo "Determining the usability of ZLIB_INFLATE support in your kernel"
332    
333     ebegin "checking ZLIB_INFLATE"
334     getfilevar_isbuiltin CONFIG_ZLIB_INFLATE ${KV_DIR}/.config
335     eend $?
336     [ "$?" != 0 ] && die
337    
338     ebegin "checking ZLIB_DEFLATE"
339     getfilevar_isbuiltin CONFIG_ZLIB_DEFLATE ${KV_DIR}/.config
340     eend $?
341     [ "$?" != 0 ] && die
342    
343    
344     local LINENO_START
345     local LINENO_END
346     local SYMBOLS
347     local x
348    
349     LINENO_END="$(grep -n 'CONFIG_ZLIB_INFLATE y' ${KV_DIR}/lib/Config.in | cut -d : -f 1)"
350     LINENO_START="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | grep -n 'if \[' | tail -n 1 | cut -d : -f 1)"
351     (( LINENO_AMOUNT = $LINENO_END - $LINENO_START ))
352     (( LINENO_END = $LINENO_END - 1 ))
353 johnm 1.4 SYMBOLS="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;')"
354 johnm 1.1
355     # okay, now we have a list of symbols
356     # we need to check each one in turn, to see whether it is set or not
357     for x in $SYMBOLS ; do
358     if [ "${!x}" = "y" ]; then
359     # we have a winner!
360     einfo "${x} ensures zlib is linked into your kernel - excellent"
361     return 0
362     fi
363     done
364    
365     eerror
366     eerror "This kernel module requires ZLIB library support."
367     eerror "You have enabled zlib support in your kernel, but haven't enabled"
368     eerror "enabled any option that will ensure that zlib is linked into your"
369     eerror "kernel."
370     eerror
371     eerror "Please ensure that you enable at least one of these options:"
372     eerror
373    
374     for x in $SYMBOLS ; do
375     eerror " * $x"
376     done
377    
378     eerror
379     eerror "Please remember to recompile and install your kernel, and reboot"
380     eerror "into your new kernel before attempting to load this kernel module."
381    
382     die "Kernel doesn't include zlib support"
383     }
384 johnm 1.8
385     ################################
386     # Default pkg_setup
387     # Also used when inheriting linux-mod to force a get_version call
388    
389     linux-info_pkg_setup() {
390     get_version;
391     }

  ViewVC Help
Powered by ViewVC 1.1.20