/[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.22
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.22 2005/01/16 22:54:56 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 ] ;
65 then 112 then
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 for n in $(find_module_params ${i})
96 modulename="${i/(*/}" 247 do
97 moduledir="${module_temp/:*/}" 248 eval ${n/:*}=${n/*:/}
98 moduledir="${moduledir:-misc}" 249 done
99 sourcedir="${module_temp/*:/}"
100 sourcedir="${sourcedir:-${S}}"
101
102 einfo " # echo \"${modulename}\" >> ${file}" 250 einfo " # echo \"${modulename}\" >> ${file}"
103 done 251 done
104 echo 252 einfo
253 fi
254}
255
256find_module_params() {
257 local matched_offset=0 matched_opts=0 test="${@}" temp_var result
258 local i=0 y=0 z=0
259
260 for((i=0; i<=${#test}; i++))
261 do
262 case ${test:${i}:1} in
263 \() matched_offset[0]=${i};;
264 \:) matched_opts=$((${matched_opts} + 1));
265 matched_offset[${matched_opts}]="${i}";;
266 \)) matched_opts=$((${matched_opts} + 1));
267 matched_offset[${matched_opts}]="${i}";;
268 esac
269 done
270
271 for((i=0; i<=${matched_opts}; i++))
272 do
273 # i = offset were working on
274 # y = last offset
275 # z = current offset - last offset
276 # temp_var = temporary name
277 case ${i} in
278 0) tempvar=${test:0:${matched_offset[0]}};;
279 *) y=$((${matched_offset[$((${i} - 1))]} + 1))
280 z=$((${matched_offset[${i}]} - ${matched_offset[$((${i} - 1))]}));
281 z=$((${z} - 1))
282 tempvar=${test:${y}:${z}};;
283 esac
284
285 case ${i} in
286 0) result="${result} modulename:${tempvar}";;
287 1) result="${result} libdir:${tempvar}";;
288 2) result="${result} srcdir:${tempvar}";;
289 3) result="${result} objdir:${tempvar}";;
290 esac
291 done
292
293 echo ${result}
105} 294}
106 295
107# default ebuild functions 296# default ebuild functions
108# -------------------------------- 297# --------------------------------
109 298
110linux-mod_pkg_setup() { 299linux-mod_pkg_setup() {
111 linux-info_pkg_setup; 300 linux-info_pkg_setup;
112 check_kernel_built; 301 check_kernel_built;
113 check_modules_supported; 302 check_modules_supported;
114 check_extra_config;
115 set_kvobj; 303 set_kvobj;
116} 304}
117 305
118linux-mod_src_compile() { 306linux-mod_src_compile() {
119 local modulename moduledir sourcedir module_temp xarch i 307 local modulename libdir srcdir objdir i n myARCH=${ARCH}
120 xarch="${ARCH}"
121 unset ARCH 308 unset ARCH
309
310 BUILD_TARGETS=${BUILD_TARGETS:-clean module}
311
312 for i in ${MODULE_IGNORE}
313 do
314 MODULE_NAMES=${MODULE_NAMES//${i}(*}
315 done
122 316
123 for i in "${MODULE_NAMES}" 317 for i in ${MODULE_NAMES}
318 do
319 for n in $(find_module_params ${i})
124 do 320 do
125 module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" 321 eval ${n/:*}=${n/*:/}
126 modulename="${i/(*/}" 322 done
127 moduledir="${module_temp/:*/}" 323 libdir=${libdir:-misc}
128 moduledir="${moduledir:-misc}"
129 sourcedir="${module_temp/*:/}"
130 sourcedir="${sourcedir:-${S}}" 324 srcdir=${srcdir:-${S}}
131 325 objdir=${objdir:-${srcdir}}
326
327 if [ ! -f "${srcdir}/.built" ];
328 then
329 cd ${srcdir}
132 einfo "Preparing ${modulename} module" 330 einfo "Preparing ${modulename} module"
133 cd ${sourcedir} 331 if [[ -n ${ECONF_PARAMS} ]]
134 emake ${BUILD_PARAMS} ${BUILD_TARGETS:-clean module} || die Unable to make ${BUILD_PARAMS} ${BUILD_TARGETS:-clean module}. 332 then
333 econf ${ECONF_PARAMS} || \
334 die "Unable to run econf ${ECONF_PARAMS}"
335 fi
336
337 emake ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS} \
338 || die "Unable to make \
339 ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}."
340 touch ${srcdir}/.built
341 cd ${OLDPWD}
342 fi
135 done 343 done
136 ARCH="${xarch}" 344
345 ARCH=${myARCH}
137} 346}
138 347
139linux-mod_src_install() { 348linux-mod_src_install() {
140 local modulename moduledir sourcedir module_temp i 349 local modulename libdir srcdir objdir i n
350
351 for i in ${MODULE_IGNORE}
352 do
353 MODULE_NAMES=${MODULE_NAMES//${i}(*}
354 done
141 355
142 for i in "${MODULE_NAMES}" 356 for i in ${MODULE_NAMES}
357 do
358 for n in $(find_module_params ${i})
143 do 359 do
144 module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" 360 eval ${n/:*}=${n/*:/}
145 modulename="${i/(*/}" 361 done
146 moduledir="${module_temp/:*/}" 362 libdir=${libdir:-misc}
147 moduledir="${moduledir:-misc}"
148 sourcedir="${module_temp/*:/}"
149 sourcedir="${sourcedir:-${S}}" 363 srcdir=${srcdir:-${S}}
364 objdir=${objdir:-${srcdir}}
150 365
151 einfo "Installing ${modulename} module" 366 einfo "Installing ${modulename} module"
152 cd ${sourcedir} 367 cd ${objdir}
368
153 insinto /lib/modules/${KV_FULL}/${moduledir} 369 insinto /lib/modules/${KV_FULL}/${libdir}
154 doins ${modulename}.${KV_OBJ} 370 doins ${modulename}.${KV_OBJ}
371 cd ${OLDPWD}
372
373 [ -z "${NO_MODULESD}" ] && generate_modulesd ${objdir}/${modulename}
155 done 374 done
156} 375}
157 376
158linux-mod_pkg_postinst() { 377linux-mod_pkg_postinst() {
159 update_depmod; 378 update_depmod;

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

  ViewVC Help
Powered by ViewVC 1.1.20