/[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.6 Revision 1.11
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.6 2004/12/06 18:33:11 johnm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/linux-mod.eclass,v 1.11 2004/12/18 16:00:10 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# BUILD_PARAMS <string> The parameters to pass to make.
22# BUILD_TARGETS <string> clean modules The build targets to pass to make.
23# MODULE_NAMES <string> This is the modules which are
24# to be built automatically using the
25# default pkg_compile/install. They
26# are explained properly below.
27
28
29# MODULE_NAMES - Detailed Overview
30#
31# The structure of each MODULE_NAMES entry is as follows:
32# modulename(libmodulesdir:modulesourcedir)
33# for example:
34# MODULE_NAMES="module_pci(pci:${S}/pci) module_usb(usb:${S}/usb)"
35#
36# what this would do is
37# cd ${S}/pci
38# make ${BUILD_PARAMS} ${BUILD_TARGETS}
39# insinto /lib/modules/${KV_FULL}/pci
40# doins module_pci.${KV_OBJ}
41#
42# cd ${S}/usb
43# make ${BUILD_PARAMS} ${BUILD_TARGETS}
44# insinto /lib/modules/${KV_FULL}/usb
45# doins module_usb.${KV_OBJ}
46#
47# if the modulessourcedir isnt specified, it assumes ${S}
48# if the libmodulesdir isnt specified, it assumes misc.
49# if no seperator is defined ":" then it assumes the argument is modulesourcedir
7 50
8inherit linux-info 51inherit linux-info
9ECLASS=linux-mod 52ECLASS=linux-mod
10INHERITED="$INHERITED $ECLASS" 53INHERITED="$INHERITED $ECLASS"
11EXPORT_FUNCTIONS pkg_setup pkg_postinst src_compile 54EXPORT_FUNCTIONS pkg_setup pkg_postinst src_compile
12 55
13DESCRIPTION="Based on the $ECLASS eclass" 56DESCRIPTION="Based on the $ECLASS eclass"
14SLOT=0 57SLOT=0
15DEPEND="virtual/linux-sources 58DEPEND="virtual/linux-sources
16 sys-apps/sed" 59 sys-apps/sed
17 60 sys-apps/module-init-tools"
18
19# This eclass is designed to help ease the installation of external kernel
20# modules into the kernel tree.
21
22 61
23# eclass utilities 62# eclass utilities
24# ---------------------------------- 63# ----------------------------------
25 64
26use_m() { 65use_m() {
27 # if we haven't determined the version yet, we need too. 66 # if we haven't determined the version yet, we need too.
28 get_version; 67 get_version;
29 68
30 # if the kernel version is greater than 2.6.6 then we should use 69 # if the kernel version is greater than 2.6.6 then we should use
31 # M= instead of SUBDIR= 70 # M= instead of SUBDIRS=
32 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \ 71 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \
33 return 0 || return 1 72 return 0 || return 1
34} 73}
35 74
36convert_to_m() { 75convert_to_m() {
37 [ ! -f "${1}" ] && die "convert_to_m() requires a filename as an argument" 76 [ ! -f "${1}" ] && die "convert_to_m() requires a filename as an argument"
38 if use_m 77 if use_m
39 then 78 then
40 ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIR=" 79 ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIRS="
41 sed -i 's:SUBDIRS=:M=:g' ${1} 80 sed -i 's:SUBDIRS=:M=:g' ${1}
42 eend $? 81 eend $?
43 fi 82 fi
44} 83}
45 84
77 KV_OBJ="o" 116 KV_OBJ="o"
78 fi 117 fi
79 einfo "Using KV_OBJ=${KV_OBJ}" 118 einfo "Using KV_OBJ=${KV_OBJ}"
80} 119}
81 120
121generate_modulesd() {
122 # This function will generate the neccessary modules.d file from the
123 # information contained in the modules exported parms
124
125 local selectedmodule selectedmodule_full selectedmodulevars parameter modinfop arg xifs temp
126 local module_docs module_opts module_aliases module_config
127
128 for arg in ${@}
129 do
130 # convert the modulename to uppercase
131 selectedmodule_full="${arg}"
132 selectedmodule="${selectedmodule_full/*\//}"
133 selectedmodule="$(echo ${selectedmodule} | tr '[:lower:]' '[:upper:]')"
134
135 module_docs="MODULESD_${selectedmodule}_DOCS"
136 module_aliases="$(eval echo \$\{#MODULESD_${selectedmodule}_ALIASES[*]\})"
137 module_docs="${!module_docs}"
138
139 for parameter in ${!module_*}
140 do
141 [ -z "${!parameter}" ] && unset ${parameter}
142 done
143
144 # OK, so now ${!module_*} only contains stuff from the ebuild.
145 # now we can do some proper work!
146 [ -z "${!module_*}" ] && return
147
148 module_config="${T}/modulesd-${selectedmodule}"
149
150 ebegin "Preparing file for modules.d"
151 echo "# modules.d config file for ${selectedmodule}" >> ${module_config}
152 echo "# this file was automatically generated from linux-mod.eclass" >> ${module_config}
153 echo "# on behalf of ${EBUILD/*\//}" >> ${module_config}
154 for temp in ${module_docs}
155 do
156 echo "# Please read ${temp/*\//} for more info" >> ${module_config}
157 done
158
159 if [ ${module_aliases} -gt 0 ];
160 then
161 echo "# Internal Aliases - Do not edit" >> ${module_config}
162 echo "# ------------------------------" >> ${module_config}
163
164 (( module_aliases-- ))
165 for temp in $(seq 0 ${module_aliases})
166 do
167 echo "alias $(eval echo \$\{MODULESD_${selectedmodule}_ALIASES[$temp]\})" >> ${module_config}
168
169 done
170 fi
171
172 modinfop="$(modinfo -p ${selectedmodule_full}.${KV_OBJ})"
173 if [ -n "${modinfop}" ];
174 then
175 echo >> ${module_config}
176 echo "# Configurable module parameters" >> ${module_config}
177 echo "# ------------------------------" >> ${module_config}
178
179 xifs="${IFS}"
180 IFS="$(echo -en "\n\b")"
181 for parameter in ${modinfop}
182 do
183 temp="$(echo ${parameter#*:} | grep -e " [0-9][ =]" | sed "s:.*\([01][= ]\).*:\1:")"
184 if [ -n "${temp}" ];
185 then
186 module_opts="${module_opts} ${parameter%%:*}:${temp}"
187 fi
188 echo -e "# ${parameter%%:*}:\t${parameter#*:}" >> ${module_config}
189 done
190 IFS="${xifs}"
191 fi
192
193 if [ -n "${module_opts}" ];
194 then
195 echo >> ${module_config}
196 echo "# For Example..." >> ${module_config}
197 echo "# ------------------------------" >> ${module_config}
198 for parameter in ${module_opts}
199 do
200 echo "# options ${selectedmodule_full/*\//} ${parameter//:*}=${parameter//*:}" >> ${module_config}
201 done
202 fi
203
204 insinto /etc/modules.d
205 newins ${module_config} ${selectedmodule_full/*\//}
206
207 [ -n "${module_docs}" ] && dodoc ${module_docs}
208 done
209 eend 0
210}
211
82display_postinst() { 212display_postinst() {
83 # if we haven't determined the version yet, we need too. 213 # if we haven't determined the version yet, we need too.
84 get_version; 214 get_version;
85 215
86 local modulename moduledir sourcedir module_temp file i 216 local modulename moduledir sourcedir moduletemp file i
87 217
88 file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR} 218 file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}
89 file=${file/\/\///} 219 file=${file/\/\///}
90 220
91 einfo "If you would like to load this module automatically upon boot" 221 einfo "If you would like to load this module automatically upon boot"
92 einfo "please type the following as root:" 222 einfo "please type the following as root:"
93 for i in ${MODULE_NAMES} 223 for i in ${MODULE_NAMES}
94 do 224 do
95 module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" 225 moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")"
96 modulename="${i/(*/}"
97 moduledir="${module_temp/:*/}" 226 modulename="${moduletemp/ */}"
227 moduletemp="${moduletemp/* /}"
228 # if we specify two args, then we can set moduledir
229 [ -z "${moduletemp/*:*/}" ] && moduledir="${moduletemp/:*/}"
230 # if we didnt pass the brackets, then we shouldnt accept anything
231 [ -n "${moduletemp/${modulename}/}" ] && sourcedir="${moduletemp/*:/}"
98 moduledir="${moduledir:-misc}" 232 moduledir="${moduledir:-misc}"
99 sourcedir="${module_temp/*:/}"
100 sourcedir="${sourcedir:-${S}}" 233 sourcedir="${sourcedir:-${S}}"
101 234
102 einfo " # echo \"${modulename}\" >> ${file}" 235 einfo " # echo \"${modulename}\" >> ${file}"
103 done 236 done
104 echo 237 echo
114 check_extra_config; 247 check_extra_config;
115 set_kvobj; 248 set_kvobj;
116} 249}
117 250
118linux-mod_src_compile() { 251linux-mod_src_compile() {
119 local modulename moduledir sourcedir module_temp xarch i 252 local modulename moduledir sourcedir moduletemp xarch i
120 xarch="${ARCH}" 253 xarch="${ARCH}"
121 unset ARCH 254 unset ARCH
122 255
123 for i in "${MODULE_NAMES}" 256 for i in ${MODULE_NAMES}
124 do 257 do
125 module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" 258 moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")"
126 modulename="${i/(*/}"
127 moduledir="${module_temp/:*/}" 259 modulename="${moduletemp/ */}"
260 moduletemp="${moduletemp/* /}"
261 # if we specify two args, then we can set moduledir
262 [ -z "${moduletemp/*:*/}" ] && moduledir="${moduletemp/:*/}"
263 # if we didnt pass the brackets, then we shouldnt accept anything
264 [ -n "${moduletemp/${modulename}/}" ] && sourcedir="${moduletemp/*:/}"
128 moduledir="${moduledir:-misc}" 265 moduledir="${moduledir:-misc}"
129 sourcedir="${module_temp/*:/}"
130 sourcedir="${sourcedir:-${S}}" 266 sourcedir="${sourcedir:-${S}}"
131 267
132 einfo "Preparing ${modulename} module" 268 einfo "Preparing ${modulename} module"
133 cd ${sourcedir} 269 cd ${sourcedir}
134 emake clean || die Unable to make clean.
135 emake ${BUILD_PARAMS} module || die Unable to make ${BUILD_PARAMS} module. 270 emake ${BUILD_PARAMS} ${BUILD_TARGETS:-clean module} || die Unable to make ${BUILD_PARAMS} ${BUILD_TARGETS:-clean module}.
136 done 271 done
137 ARCH="${xarch}" 272 ARCH="${xarch}"
138} 273}
139 274
140linux-mod_src_install() { 275linux-mod_src_install() {
141 local modulename moduledir sourcedir module_temp i 276 local modulename moduledir sourcedir moduletemp i
142 277
143 for i in "${MODULE_NAMES}" 278 for i in ${MODULE_NAMES}
144 do 279 do
145 module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" 280 moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")"
146 modulename="${i/(*/}"
147 moduledir="${module_temp/:*/}" 281 modulename="${moduletemp/ */}"
282 moduletemp="${moduletemp/* /}"
283 # if we specify two args, then we can set moduledir
284 [ -z "${moduletemp/*:*/}" ] && moduledir="${moduletemp/:*/}"
285 # if we didnt pass the brackets, then we shouldnt accept anything
286 [ -n "${moduletemp/${modulename}/}" ] && sourcedir="${moduletemp/*:/}"
148 moduledir="${moduledir:-misc}" 287 moduledir="${moduledir:-misc}"
149 sourcedir="${module_temp/*:/}"
150 sourcedir="${sourcedir:-${S}}" 288 sourcedir="${sourcedir:-${S}}"
151 289
152 einfo "Installing ${modulename} module" 290 einfo "Installing ${modulename} module"
153 cd ${sourcedir} 291 cd ${sourcedir}
154 insinto /lib/modules/${KV_FULL}/${moduledir} 292 insinto /lib/modules/${KV_FULL}/${moduledir}
155 doins ${modulename}.${KV_OBJ} 293 doins ${modulename}.${KV_OBJ}
294
295 generate_modulesd ${sourcedir}/${modulename}
156 done 296 done
157} 297}
158 298
159linux-mod_pkg_postinst() { 299linux-mod_pkg_postinst() {
160 update_depmod; 300 update_depmod;

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.11

  ViewVC Help
Powered by ViewVC 1.1.20