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

Diff of /eclass/linux-mod.eclass

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

Revision 1.8 Revision 1.25
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-mod.eclass,v 1.8 2004/12/06 22:05:08 johnm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/linux-mod.eclass,v 1.25 2005/01/28 17:33:17 johnm Exp $
4 4
5# This eclass provides functions for compiling external kernel modules 5# Description: This eclass is used to interface with linux-info in such a way
6# from source. 6# to provide the functionality required and initial functions
7# required to install external modules against a kernel source
8# tree.
9#
10# Maintainer: John Mylchreest <johnm@gentoo.org>
11# Copyright 2004 Gentoo Linux
12#
13# Please direct your bugs to the current eclass maintainer :)
14
15# A Couple of env vars are available to effect usage of this eclass
16# These are as follows:
17#
18# Env Var Option Default Description
19# KERNEL_DIR <string> /usr/src/linux The directory containing kernel
20# the target kernel sources.
21# ECONF_PARAMS <string> The parameters to pass to econf.
22# If this is not set, then econf isn't
23# run.
24# BUILD_PARAMS <string> The parameters to pass to emake.
25# BUILD_TARGETS <string> clean modules The build targets to pass to make.
26# MODULE_NAMES <string> This is the modules which are
27# to be built automatically using the
28# default pkg_compile/install. They
29# are explained properly below.
30# It will only make BUILD_TARGETS once
31# in any directory.
32# NO_MODULESD <string> Set this to something to prevent
33# modulesd file generation
34
35
36# MODULE_NAMES - Detailed Overview
37#
38# The structure of each MODULE_NAMES entry is as follows:
39# modulename(libmodulesdir:modulesourcedir)
40# for example:
41# MODULE_NAMES="module_pci(pci:${S}/pci) module_usb(usb:${S}/usb)"
42#
43# what this would do is
44# cd ${S}/pci
45# make ${BUILD_PARAMS} ${BUILD_TARGETS}
46# insinto /lib/modules/${KV_FULL}/pci
47# doins module_pci.${KV_OBJ}
48#
49# cd ${S}/usb
50# make ${BUILD_PARAMS} ${BUILD_TARGETS}
51# insinto /lib/modules/${KV_FULL}/usb
52# doins module_usb.${KV_OBJ}
53#
54# if the modulessourcedir isnt specified, it assumes ${S}
55# if the libmodulesdir isnt specified, it assumes misc.
56# if no seperator is defined ":" then it assumes the argument is modulesourcedir
7 57
8inherit linux-info 58inherit linux-info
9ECLASS=linux-mod 59ECLASS=linux-mod
10INHERITED="$INHERITED $ECLASS" 60INHERITED="$INHERITED $ECLASS"
11EXPORT_FUNCTIONS pkg_setup pkg_postinst src_compile 61EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst src_compile
12 62
13DESCRIPTION="Based on the $ECLASS eclass" 63DESCRIPTION="Based on the $ECLASS eclass"
14SLOT=0 64SLOT=0
15DEPEND="virtual/linux-sources 65DEPEND="virtual/linux-sources
16 sys-apps/sed" 66 sys-apps/sed
17 67 virtual/modutils"
18
19# This eclass is designed to help ease the installation of external kernel
20# modules into the kernel tree.
21
22 68
23# eclass utilities 69# eclass utilities
24# ---------------------------------- 70# ----------------------------------
25 71
26use_m() { 72use_m() {
49 95
50 ebegin "Updating module dependencies for ${KV_FULL}" 96 ebegin "Updating module dependencies for ${KV_FULL}"
51 if [ -r ${KV_OUT_DIR}/System.map ] 97 if [ -r ${KV_OUT_DIR}/System.map ]
52 then 98 then
53 depmod -ae -F ${KV_OUT_DIR}/System.map -b ${ROOT} -r ${KV_FULL} 99 depmod -ae -F ${KV_OUT_DIR}/System.map -b ${ROOT} -r ${KV_FULL}
100 eend $?
54 else 101 else
55 ewarn 102 ewarn
56 ewarn "${KV_OUT_DIR}/System.map not found." 103 ewarn "${KV_OUT_DIR}/System.map not found."
57 ewarn "You must manually update the kernel module dependencies using depmod." 104 ewarn "You must manually update the kernel module dependencies using depmod."
105 eend 1
58 ewarn 106 ewarn
59 fi 107 fi
60 eend $?
61} 108}
62 109
63update_modules() { 110update_modules() {
64 if [ -x /sbin/modules-update ] ; 111 if [ -x /sbin/modules-update -a \
65 then 112 -n "$(grep -v -e "^#" -e "^$" ${D}/etc/modules.d/*)" ] ; then
66 ebegin "Updating modules.conf" 113 ebegin "Updating modules.conf"
67 /sbin/modules-update 114 /sbin/modules-update
68 eend $? 115 eend $?
69 fi 116 fi
70} 117}
77 KV_OBJ="o" 124 KV_OBJ="o"
78 fi 125 fi
79 einfo "Using KV_OBJ=${KV_OBJ}" 126 einfo "Using KV_OBJ=${KV_OBJ}"
80} 127}
81 128
129generate_modulesd() {
130 # This function will generate the neccessary modules.d file from the
131 # information contained in the modules exported parms
132
133 local selectedmodule selectedmodule_full selectedmodulevars parameter modinfop arg xifs temp
134 local module_docs module_opts module_aliases module_config
135
136 for arg in ${@}
137 do
138 selectedmodule_full="${arg}"
139 # strip the directory
140 selectedmodule="${selectedmodule_full/*\//}"
141 # convert the modulename to uppercase
142 selectedmodule="$(echo ${selectedmodule} | tr '[:lower:]' '[:upper:]')"
143
144 module_docs="MODULESD_${selectedmodule}_DOCS"
145 module_aliases="$(eval echo \$\{#MODULESD_${selectedmodule}_ALIASES[*]\})"
146 [ ${module_aliases} == 0 ] && unset module_aliases
147 module_docs="${!module_docs}"
148 modinfop="$(modinfo -p ${selectedmodule_full}.${KV_OBJ})"
149
150 # By now we know if there is anything we can use to generate a file with
151 # so unset empty vars and bail out if we find nothing.
152 for parameter in ${!module_*}
153 do
154 [ -z "${!parameter}" ] && unset ${parameter}
155 done
156 [ -z "${!module_*}" -a -z "${modinfop}" ] && return
157
158 #so now we can set the configfilevar
159 module_config="${T}/modulesd-${selectedmodule}"
160
161 # and being working on things.
162 ebegin "Preparing file for modules.d"
163 echo "# modules.d config file for ${selectedmodule}" >> ${module_config}
164 echo "# this file was automatically generated from linux-mod.eclass" >> ${module_config}
165 for temp in ${module_docs}
166 do
167 echo "# Please read ${temp/*\//} for more info" >> ${module_config}
168 done
169
170 if [ ${module_aliases} > 0 ];
171 then
172 echo >> ${module_config}
173 echo "# Internal Aliases - Do not edit" >> ${module_config}
174 echo "# ------------------------------" >> ${module_config}
175
176 (( module_aliases-- ))
177 for temp in $(seq 0 ${module_aliases})
178 do
179 echo "alias $(eval echo \$\{MODULESD_${selectedmodule}_ALIASES[$temp]\})" >> ${module_config}
180 done
181 fi
182
183 # and then stating any module parameters defined from the module
184 if [ -n "${modinfop}" ];
185 then
186 echo >> ${module_config}
187 echo "# Configurable module parameters" >> ${module_config}
188 echo "# ------------------------------" >> ${module_config}
189
190 xifs="${IFS}"
191 IFS="$(echo -en "\n\b")"
192 for parameter in ${modinfop}
193 do
194 temp="$(echo ${parameter#*:} | grep -e " [0-9][ =]" | sed "s:.*\([01][= ]\).*:\1:")"
195 if [ -n "${temp}" ];
196 then
197 module_opts="${module_opts} ${parameter%%:*}:${temp}"
198 fi
199 echo -e "# ${parameter%%:*}:\t${parameter#*:}" >> ${module_config}
200 done
201 IFS="${xifs}"
202 fi
203
204 # and any examples we can gather from them
205 if [ -n "${module_opts}" ];
206 then
207 echo >> ${module_config}
208 echo "# For Example..." >> ${module_config}
209 echo "# ------------------------------" >> ${module_config}
210 for parameter in ${module_opts}
211 do
212 echo "# options ${selectedmodule_full/*\//} ${parameter//:*}=${parameter//*:}" >> ${module_config}
213 done
214 fi
215
216 # then we install it
217 insinto /etc/modules.d
218 newins ${module_config} ${selectedmodule_full/*\//}
219
220 # and install any documentation we might have.
221 [ -n "${module_docs}" ] && dodoc ${module_docs}
222 done
223 eend 0
224}
225
82display_postinst() { 226display_postinst() {
83 # if we haven't determined the version yet, we need too. 227 # if we haven't determined the version yet, we need too.
84 get_version; 228 get_version;
85 229
86 local modulename moduledir sourcedir module_temp file i 230 local modulename moduledir sourcedir moduletemp file i
87 231
88 file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR} 232 file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}
89 file=${file/\/\///} 233 file=${file/\/\///}
90 234
235 for i in ${MODULE_IGNORE}
236 do
237 MODULE_NAMES=${MODULE_NAMES//${i}(*}
238 done
239
240 if [[ -n ${MODULE_NAMES} ]]
241 then
91 einfo "If you would like to load this module automatically upon boot" 242 einfo "If you would like to load this module automatically upon boot"
92 einfo "please type the following as root:" 243 einfo "please type the following as root:"
93 for i in ${MODULE_NAMES} 244 for i in ${MODULE_NAMES}
94 do 245 do
95 module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" 246 unset libdir srcdir objdir
96 modulename="${i/(*/}" 247 for n in $(find_module_params ${i})
97 moduledir="${module_temp/:*/}" 248 do
98 moduledir="${moduledir:-misc}" 249 eval ${n/:*}=${n/*:/}
99 sourcedir="${module_temp/*:/}" 250 done
100 sourcedir="${sourcedir:-${S}}"
101
102 einfo " # echo \"${modulename}\" >> ${file}" 251 einfo " # echo \"${modulename}\" >> ${file}"
103 done 252 done
104 echo 253 einfo
254 fi
255}
256
257find_module_params() {
258 local matched_offset=0 matched_opts=0 test="${@}" temp_var result
259 local i=0 y=0 z=0
260
261 for((i=0; i<=${#test}; i++))
262 do
263 case ${test:${i}:1} in
264 \() matched_offset[0]=${i};;
265 \:) matched_opts=$((${matched_opts} + 1));
266 matched_offset[${matched_opts}]="${i}";;
267 \)) matched_opts=$((${matched_opts} + 1));
268 matched_offset[${matched_opts}]="${i}";;
269 esac
270 done
271
272 for((i=0; i<=${matched_opts}; i++))
273 do
274 # i = offset were working on
275 # y = last offset
276 # z = current offset - last offset
277 # temp_var = temporary name
278 case ${i} in
279 0) tempvar=${test:0:${matched_offset[0]}};;
280 *) y=$((${matched_offset[$((${i} - 1))]} + 1))
281 z=$((${matched_offset[${i}]} - ${matched_offset[$((${i} - 1))]}));
282 z=$((${z} - 1))
283 tempvar=${test:${y}:${z}};;
284 esac
285
286 case ${i} in
287 0) result="${result} modulename:${tempvar}";;
288 1) result="${result} libdir:${tempvar}";;
289 2) result="${result} srcdir:${tempvar}";;
290 3) result="${result} objdir:${tempvar}";;
291 esac
292 done
293
294 echo ${result}
105} 295}
106 296
107# default ebuild functions 297# default ebuild functions
108# -------------------------------- 298# --------------------------------
109 299
110linux-mod_pkg_setup() { 300linux-mod_pkg_setup() {
111 linux-info_pkg_setup; 301 linux-info_pkg_setup;
112 check_kernel_built; 302 check_kernel_built;
113 check_modules_supported; 303 check_modules_supported;
114 check_extra_config;
115 set_kvobj; 304 set_kvobj;
116} 305}
117 306
118linux-mod_src_compile() { 307linux-mod_src_compile() {
119 local modulename moduledir sourcedir module_temp xarch i 308 local modulename libdir srcdir objdir i n myARCH=${ARCH}
120 xarch="${ARCH}"
121 unset ARCH 309 unset ARCH
310
311 BUILD_TARGETS=${BUILD_TARGETS:-clean module}
312
313 for i in ${MODULE_IGNORE}
314 do
315 MODULE_NAMES=${MODULE_NAMES//${i}(*}
316 done
122 317
123 for i in "${MODULE_NAMES}" 318 for i in ${MODULE_NAMES}
319 do
320 unset libdir srcdir objdir
321 for n in $(find_module_params ${i})
124 do 322 do
125 module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" 323 eval ${n/:*}=${n/*:/}
126 modulename="${i/(*/}" 324 done
127 moduledir="${module_temp/:*/}" 325 libdir=${libdir:-misc}
128 moduledir="${moduledir:-misc}"
129 sourcedir="${module_temp/*:/}"
130 sourcedir="${sourcedir:-${S}}" 326 srcdir=${srcdir:-${S}}
131 327 objdir=${objdir:-${srcdir}}
328
329 if [ ! -f "${srcdir}/.built" ];
330 then
331 cd ${srcdir}
132 einfo "Preparing ${modulename} module" 332 einfo "Preparing ${modulename} module"
133 cd ${sourcedir} 333 if [[ -n ${ECONF_PARAMS} ]]
134 emake ${BUILD_PARAMS} ${BUILD_TARGETS:-clean module} || die Unable to make ${BUILD_PARAMS} ${BUILD_TARGETS:-clean module}. 334 then
335 econf ${ECONF_PARAMS} || \
336 die "Unable to run econf ${ECONF_PARAMS}"
337 fi
338
339 emake ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS} \
340 || die "Unable to make \
341 ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}."
342 touch ${srcdir}/.built
343 cd ${OLDPWD}
344 fi
135 done 345 done
136 ARCH="${xarch}" 346
347 ARCH=${myARCH}
137} 348}
138 349
139linux-mod_src_install() { 350linux-mod_src_install() {
140 local modulename moduledir sourcedir module_temp i 351 local modulename libdir srcdir objdir i n
352
353 for i in ${MODULE_IGNORE}
354 do
355 MODULE_NAMES=${MODULE_NAMES//${i}(*}
356 done
141 357
142 for i in "${MODULE_NAMES}" 358 for i in ${MODULE_NAMES}
359 do
360 unset libdir srcdir objdir
361 for n in $(find_module_params ${i})
143 do 362 do
144 module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" 363 eval ${n/:*}=${n/*:/}
145 modulename="${i/(*/}" 364 done
146 moduledir="${module_temp/:*/}" 365 libdir=${libdir:-misc}
147 moduledir="${moduledir:-misc}"
148 sourcedir="${module_temp/*:/}"
149 sourcedir="${sourcedir:-${S}}" 366 srcdir=${srcdir:-${S}}
367 objdir=${objdir:-${srcdir}}
150 368
151 einfo "Installing ${modulename} module" 369 einfo "Installing ${modulename} module"
152 cd ${sourcedir} 370 cd ${objdir}
371
153 insinto /lib/modules/${KV_FULL}/${moduledir} 372 insinto /lib/modules/${KV_FULL}/${libdir}
154 doins ${modulename}.${KV_OBJ} 373 doins ${modulename}.${KV_OBJ}
374 cd ${OLDPWD}
375
376 [ -z "${NO_MODULESD}" ] && generate_modulesd ${objdir}/${modulename}
155 done 377 done
156} 378}
157 379
158linux-mod_pkg_postinst() { 380linux-mod_pkg_postinst() {
159 update_depmod; 381 update_depmod;

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.25

  ViewVC Help
Powered by ViewVC 1.1.20