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