| 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.15 2005/01/06 13:58:15 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 | # NO_MODULESD <string> Set this to something to prevent |
|
|
28 | # modulesd file generation |
|
|
29 | |
|
|
30 | |
|
|
31 | # MODULE_NAMES - Detailed Overview |
|
|
32 | # |
|
|
33 | # The structure of each MODULE_NAMES entry is as follows: |
|
|
34 | # modulename(libmodulesdir:modulesourcedir) |
|
|
35 | # for example: |
|
|
36 | # MODULE_NAMES="module_pci(pci:${S}/pci) module_usb(usb:${S}/usb)" |
|
|
37 | # |
|
|
38 | # what this would do is |
|
|
39 | # cd ${S}/pci |
|
|
40 | # make ${BUILD_PARAMS} ${BUILD_TARGETS} |
|
|
41 | # insinto /lib/modules/${KV_FULL}/pci |
|
|
42 | # doins module_pci.${KV_OBJ} |
|
|
43 | # |
|
|
44 | # cd ${S}/usb |
|
|
45 | # make ${BUILD_PARAMS} ${BUILD_TARGETS} |
|
|
46 | # insinto /lib/modules/${KV_FULL}/usb |
|
|
47 | # doins module_usb.${KV_OBJ} |
|
|
48 | # |
|
|
49 | # if the modulessourcedir isnt specified, it assumes ${S} |
|
|
50 | # if the libmodulesdir isnt specified, it assumes misc. |
|
|
51 | # if no seperator is defined ":" then it assumes the argument is modulesourcedir |
| 7 | |
52 | |
| 8 | inherit linux-info |
53 | inherit linux-info |
| 9 | ECLASS=linux-mod |
54 | ECLASS=linux-mod |
| 10 | INHERITED="$INHERITED $ECLASS" |
55 | INHERITED="$INHERITED $ECLASS" |
| 11 | EXPORT_FUNCTIONS pkg_setup pkg_postinst src_compile |
56 | EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst src_compile |
| 12 | |
57 | |
| 13 | DESCRIPTION="Based on the $ECLASS eclass" |
58 | DESCRIPTION="Based on the $ECLASS eclass" |
| 14 | SLOT=0 |
59 | SLOT=0 |
| 15 | DEPEND="virtual/linux-sources |
60 | DEPEND="virtual/linux-sources |
| 16 | sys-apps/sed" |
61 | sys-apps/sed |
| 17 | |
62 | 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 | |
63 | |
| 23 | # eclass utilities |
64 | # eclass utilities |
| 24 | # ---------------------------------- |
65 | # ---------------------------------- |
| 25 | |
66 | |
| 26 | use_m() { |
67 | use_m() { |
| … | |
… | |
| 77 | KV_OBJ="o" |
118 | KV_OBJ="o" |
| 78 | fi |
119 | fi |
| 79 | einfo "Using KV_OBJ=${KV_OBJ}" |
120 | einfo "Using KV_OBJ=${KV_OBJ}" |
| 80 | } |
121 | } |
| 81 | |
122 | |
|
|
123 | generate_modulesd() { |
|
|
124 | # This function will generate the neccessary modules.d file from the |
|
|
125 | # information contained in the modules exported parms |
|
|
126 | |
|
|
127 | local selectedmodule selectedmodule_full selectedmodulevars parameter modinfop arg xifs temp |
|
|
128 | local module_docs module_opts module_aliases module_config |
|
|
129 | |
|
|
130 | for arg in ${@} |
|
|
131 | do |
|
|
132 | selectedmodule_full="${arg}" |
|
|
133 | # strip the directory |
|
|
134 | selectedmodule="${selectedmodule_full/*\//}" |
|
|
135 | # convert the modulename to uppercase |
|
|
136 | selectedmodule="$(echo ${selectedmodule} | tr '[:lower:]' '[:upper:]')" |
|
|
137 | |
|
|
138 | module_docs="MODULESD_${selectedmodule}_DOCS" |
|
|
139 | module_aliases="$(eval echo \$\{#MODULESD_${selectedmodule}_ALIASES[*]\})" |
|
|
140 | [ ${module_aliases} == 0 ] && unset module_aliases |
|
|
141 | module_docs="${!module_docs}" |
|
|
142 | modinfop="$(modinfo -p ${selectedmodule_full}.${KV_OBJ})" |
|
|
143 | |
|
|
144 | # By now we know if there is anything we can use to generate a file with |
|
|
145 | # so unset empty vars and bail out if we find nothing. |
|
|
146 | for parameter in ${!module_*} |
|
|
147 | do |
|
|
148 | [ -z "${!parameter}" ] && unset ${parameter} |
|
|
149 | done |
|
|
150 | [ -z "${!module_*}" -a -z "${modinfop}" ] && return |
|
|
151 | |
|
|
152 | #so now we can set the configfilevar |
|
|
153 | module_config="${T}/modulesd-${selectedmodule}" |
|
|
154 | |
|
|
155 | # and being working on things. |
|
|
156 | ebegin "Preparing file for modules.d" |
|
|
157 | echo "# modules.d config file for ${selectedmodule}" >> ${module_config} |
|
|
158 | echo "# this file was automatically generated from linux-mod.eclass" >> ${module_config} |
|
|
159 | for temp in ${module_docs} |
|
|
160 | do |
|
|
161 | echo "# Please read ${temp/*\//} for more info" >> ${module_config} |
|
|
162 | done |
|
|
163 | |
|
|
164 | if [ ${module_aliases} > 0 ]; |
|
|
165 | then |
|
|
166 | echo >> ${module_config} |
|
|
167 | echo "# Internal Aliases - Do not edit" >> ${module_config} |
|
|
168 | echo "# ------------------------------" >> ${module_config} |
|
|
169 | |
|
|
170 | (( module_aliases-- )) |
|
|
171 | for temp in $(seq 0 ${module_aliases}) |
|
|
172 | do |
|
|
173 | echo "alias $(eval echo \$\{MODULESD_${selectedmodule}_ALIASES[$temp]\})" >> ${module_config} |
|
|
174 | done |
|
|
175 | fi |
|
|
176 | |
|
|
177 | # and then stating any module parameters defined from the module |
|
|
178 | if [ -n "${modinfop}" ]; |
|
|
179 | then |
|
|
180 | echo >> ${module_config} |
|
|
181 | echo "# Configurable module parameters" >> ${module_config} |
|
|
182 | echo "# ------------------------------" >> ${module_config} |
|
|
183 | |
|
|
184 | xifs="${IFS}" |
|
|
185 | IFS="$(echo -en "\n\b")" |
|
|
186 | for parameter in ${modinfop} |
|
|
187 | do |
|
|
188 | temp="$(echo ${parameter#*:} | grep -e " [0-9][ =]" | sed "s:.*\([01][= ]\).*:\1:")" |
|
|
189 | if [ -n "${temp}" ]; |
|
|
190 | then |
|
|
191 | module_opts="${module_opts} ${parameter%%:*}:${temp}" |
|
|
192 | fi |
|
|
193 | echo -e "# ${parameter%%:*}:\t${parameter#*:}" >> ${module_config} |
|
|
194 | done |
|
|
195 | IFS="${xifs}" |
|
|
196 | fi |
|
|
197 | |
|
|
198 | # and any examples we can gather from them |
|
|
199 | if [ -n "${module_opts}" ]; |
|
|
200 | then |
|
|
201 | echo >> ${module_config} |
|
|
202 | echo "# For Example..." >> ${module_config} |
|
|
203 | echo "# ------------------------------" >> ${module_config} |
|
|
204 | for parameter in ${module_opts} |
|
|
205 | do |
|
|
206 | echo "# options ${selectedmodule_full/*\//} ${parameter//:*}=${parameter//*:}" >> ${module_config} |
|
|
207 | done |
|
|
208 | fi |
|
|
209 | |
|
|
210 | # then we install it |
|
|
211 | insinto /etc/modules.d |
|
|
212 | newins ${module_config} ${selectedmodule_full/*\//} |
|
|
213 | |
|
|
214 | # and install any documentation we might have. |
|
|
215 | [ -n "${module_docs}" ] && dodoc ${module_docs} |
|
|
216 | done |
|
|
217 | eend 0 |
|
|
218 | } |
|
|
219 | |
| 82 | display_postinst() { |
220 | display_postinst() { |
| 83 | # if we haven't determined the version yet, we need too. |
221 | # if we haven't determined the version yet, we need too. |
| 84 | get_version; |
222 | get_version; |
| 85 | |
223 | |
| 86 | local modulename moduledir sourcedir module_temp file i |
224 | local modulename moduledir sourcedir moduletemp file i |
| 87 | |
225 | |
| 88 | file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR} |
226 | file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR} |
| 89 | file=${file/\/\///} |
227 | file=${file/\/\///} |
| 90 | |
228 | |
| 91 | einfo "If you would like to load this module automatically upon boot" |
229 | einfo "If you would like to load this module automatically upon boot" |
| 92 | einfo "please type the following as root:" |
230 | einfo "please type the following as root:" |
| 93 | for i in ${MODULE_NAMES} |
231 | for i in ${MODULE_NAMES} |
| 94 | do |
232 | do |
| 95 | module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" |
233 | moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")" |
| 96 | modulename="${i/(*/}" |
|
|
| 97 | moduledir="${module_temp/:*/}" |
234 | modulename="${moduletemp/ */}" |
|
|
235 | moduletemp="${moduletemp/* /}" |
|
|
236 | # if we specify two args, then we can set moduledir |
|
|
237 | [ -z "${moduletemp/*:*/}" ] && moduledir="${moduletemp/:*/}" |
|
|
238 | # if we didnt pass the brackets, then we shouldnt accept anything |
|
|
239 | [ -n "${moduletemp/${modulename}/}" ] && sourcedir="${moduletemp/*:/}" |
| 98 | moduledir="${moduledir:-misc}" |
240 | moduledir="${moduledir:-misc}" |
| 99 | sourcedir="${module_temp/*:/}" |
|
|
| 100 | sourcedir="${sourcedir:-${S}}" |
241 | sourcedir="${sourcedir:-${S}}" |
| 101 | |
242 | |
| 102 | einfo " # echo \"${modulename}\" >> ${file}" |
243 | einfo " # echo \"${modulename}\" >> ${file}" |
| 103 | done |
244 | done |
| 104 | echo |
245 | echo |
| … | |
… | |
| 109 | |
250 | |
| 110 | linux-mod_pkg_setup() { |
251 | linux-mod_pkg_setup() { |
| 111 | linux-info_pkg_setup; |
252 | linux-info_pkg_setup; |
| 112 | check_kernel_built; |
253 | check_kernel_built; |
| 113 | check_modules_supported; |
254 | check_modules_supported; |
| 114 | check_extra_config; |
|
|
| 115 | set_kvobj; |
255 | set_kvobj; |
| 116 | } |
256 | } |
| 117 | |
257 | |
| 118 | linux-mod_src_compile() { |
258 | linux-mod_src_compile() { |
| 119 | local modulename moduledir sourcedir module_temp xarch i |
259 | local modulename moduledir sourcedir moduletemp xarch i |
| 120 | xarch="${ARCH}" |
260 | xarch="${ARCH}" |
| 121 | unset ARCH |
261 | unset ARCH |
| 122 | |
262 | |
| 123 | for i in "${MODULE_NAMES}" |
263 | for i in ${MODULE_NAMES} |
| 124 | do |
264 | do |
| 125 | module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" |
265 | moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")" |
| 126 | modulename="${i/(*/}" |
|
|
| 127 | moduledir="${module_temp/:*/}" |
266 | modulename="${moduletemp/ */}" |
|
|
267 | moduletemp="${moduletemp/* /}" |
|
|
268 | # if we specify two args, then we can set moduledir |
|
|
269 | [ -z "${moduletemp/*:*/}" ] && moduledir="${moduletemp/:*/}" |
|
|
270 | # if we didnt pass the brackets, then we shouldnt accept anything |
|
|
271 | [ -n "${moduletemp/${modulename}/}" ] && sourcedir="${moduletemp/*:/}" |
| 128 | moduledir="${moduledir:-misc}" |
272 | moduledir="${moduledir:-misc}" |
| 129 | sourcedir="${module_temp/*:/}" |
|
|
| 130 | sourcedir="${sourcedir:-${S}}" |
273 | sourcedir="${sourcedir:-${S}}" |
| 131 | |
274 | |
| 132 | einfo "Preparing ${modulename} module" |
275 | einfo "Preparing ${modulename} module" |
| 133 | cd ${sourcedir} |
276 | cd ${sourcedir} |
| 134 | emake ${BUILD_PARAMS} ${BUILD_TARGETS:-clean module} || die Unable to make ${BUILD_PARAMS} ${BUILD_TARGETS:-clean module}. |
277 | emake ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS:-clean module} || \ |
|
|
278 | die Unable to make ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS:-clean module}. |
| 135 | done |
279 | done |
| 136 | ARCH="${xarch}" |
280 | ARCH="${xarch}" |
| 137 | } |
281 | } |
| 138 | |
282 | |
| 139 | linux-mod_src_install() { |
283 | linux-mod_src_install() { |
| 140 | local modulename moduledir sourcedir module_temp i |
284 | local modulename moduledir sourcedir moduletemp i |
| 141 | |
285 | |
| 142 | for i in "${MODULE_NAMES}" |
286 | for i in ${MODULE_NAMES} |
| 143 | do |
287 | do |
| 144 | module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" |
288 | moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")" |
| 145 | modulename="${i/(*/}" |
|
|
| 146 | moduledir="${module_temp/:*/}" |
289 | modulename="${moduletemp/ */}" |
|
|
290 | moduletemp="${moduletemp/* /}" |
|
|
291 | # if we specify two args, then we can set moduledir |
|
|
292 | [ -z "${moduletemp/*:*/}" ] && moduledir="${moduletemp/:*/}" |
|
|
293 | # if we didnt pass the brackets, then we shouldnt accept anything |
|
|
294 | [ -n "${moduletemp/${modulename}/}" ] && sourcedir="${moduletemp/*:/}" |
| 147 | moduledir="${moduledir:-misc}" |
295 | moduledir="${moduledir:-misc}" |
| 148 | sourcedir="${module_temp/*:/}" |
|
|
| 149 | sourcedir="${sourcedir:-${S}}" |
296 | sourcedir="${sourcedir:-${S}}" |
| 150 | |
297 | |
| 151 | einfo "Installing ${modulename} module" |
298 | einfo "Installing ${modulename} module" |
| 152 | cd ${sourcedir} |
299 | cd ${sourcedir} |
| 153 | insinto /lib/modules/${KV_FULL}/${moduledir} |
300 | insinto /lib/modules/${KV_FULL}/${moduledir} |
| 154 | doins ${modulename}.${KV_OBJ} |
301 | doins ${modulename}.${KV_OBJ} |
|
|
302 | |
|
|
303 | [ -z "${NO_MODULESD}" ] && generate_modulesd ${sourcedir}/${modulename} |
| 155 | done |
304 | done |
| 156 | } |
305 | } |
| 157 | |
306 | |
| 158 | linux-mod_pkg_postinst() { |
307 | linux-mod_pkg_postinst() { |
| 159 | update_depmod; |
308 | update_depmod; |