| 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.19 2005/01/15 21:19:02 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() { |
| … | |
… | |
| 49 | |
92 | |
| 50 | ebegin "Updating module dependencies for ${KV_FULL}" |
93 | ebegin "Updating module dependencies for ${KV_FULL}" |
| 51 | if [ -r ${KV_OUT_DIR}/System.map ] |
94 | if [ -r ${KV_OUT_DIR}/System.map ] |
| 52 | then |
95 | then |
| 53 | depmod -ae -F ${KV_OUT_DIR}/System.map -b ${ROOT} -r ${KV_FULL} |
96 | depmod -ae -F ${KV_OUT_DIR}/System.map -b ${ROOT} -r ${KV_FULL} |
|
|
97 | eend $? |
| 54 | else |
98 | else |
| 55 | ewarn |
99 | ewarn |
| 56 | ewarn "${KV_OUT_DIR}/System.map not found." |
100 | ewarn "${KV_OUT_DIR}/System.map not found." |
| 57 | ewarn "You must manually update the kernel module dependencies using depmod." |
101 | ewarn "You must manually update the kernel module dependencies using depmod." |
|
|
102 | eend 1 |
| 58 | ewarn |
103 | ewarn |
| 59 | fi |
104 | fi |
| 60 | eend $? |
|
|
| 61 | } |
105 | } |
| 62 | |
106 | |
| 63 | update_modules() { |
107 | update_modules() { |
| 64 | if [ -x /sbin/modules-update ] ; |
108 | if [ -x /sbin/modules-update ] ; |
| 65 | then |
109 | then |
| … | |
… | |
| 77 | KV_OBJ="o" |
121 | KV_OBJ="o" |
| 78 | fi |
122 | fi |
| 79 | einfo "Using KV_OBJ=${KV_OBJ}" |
123 | einfo "Using KV_OBJ=${KV_OBJ}" |
| 80 | } |
124 | } |
| 81 | |
125 | |
|
|
126 | generate_modulesd() { |
|
|
127 | # This function will generate the neccessary modules.d file from the |
|
|
128 | # information contained in the modules exported parms |
|
|
129 | |
|
|
130 | local selectedmodule selectedmodule_full selectedmodulevars parameter modinfop arg xifs temp |
|
|
131 | local module_docs module_opts module_aliases module_config |
|
|
132 | |
|
|
133 | for arg in ${@} |
|
|
134 | do |
|
|
135 | selectedmodule_full="${arg}" |
|
|
136 | # strip the directory |
|
|
137 | selectedmodule="${selectedmodule_full/*\//}" |
|
|
138 | # convert the modulename to uppercase |
|
|
139 | selectedmodule="$(echo ${selectedmodule} | tr '[:lower:]' '[:upper:]')" |
|
|
140 | |
|
|
141 | module_docs="MODULESD_${selectedmodule}_DOCS" |
|
|
142 | module_aliases="$(eval echo \$\{#MODULESD_${selectedmodule}_ALIASES[*]\})" |
|
|
143 | [ ${module_aliases} == 0 ] && unset module_aliases |
|
|
144 | module_docs="${!module_docs}" |
|
|
145 | modinfop="$(modinfo -p ${selectedmodule_full}.${KV_OBJ})" |
|
|
146 | |
|
|
147 | # By now we know if there is anything we can use to generate a file with |
|
|
148 | # so unset empty vars and bail out if we find nothing. |
|
|
149 | for parameter in ${!module_*} |
|
|
150 | do |
|
|
151 | [ -z "${!parameter}" ] && unset ${parameter} |
|
|
152 | done |
|
|
153 | [ -z "${!module_*}" -a -z "${modinfop}" ] && return |
|
|
154 | |
|
|
155 | #so now we can set the configfilevar |
|
|
156 | module_config="${T}/modulesd-${selectedmodule}" |
|
|
157 | |
|
|
158 | # and being working on things. |
|
|
159 | ebegin "Preparing file for modules.d" |
|
|
160 | echo "# modules.d config file for ${selectedmodule}" >> ${module_config} |
|
|
161 | echo "# this file was automatically generated from linux-mod.eclass" >> ${module_config} |
|
|
162 | for temp in ${module_docs} |
|
|
163 | do |
|
|
164 | echo "# Please read ${temp/*\//} for more info" >> ${module_config} |
|
|
165 | done |
|
|
166 | |
|
|
167 | if [ ${module_aliases} > 0 ]; |
|
|
168 | then |
|
|
169 | echo >> ${module_config} |
|
|
170 | echo "# Internal Aliases - Do not edit" >> ${module_config} |
|
|
171 | echo "# ------------------------------" >> ${module_config} |
|
|
172 | |
|
|
173 | (( module_aliases-- )) |
|
|
174 | for temp in $(seq 0 ${module_aliases}) |
|
|
175 | do |
|
|
176 | echo "alias $(eval echo \$\{MODULESD_${selectedmodule}_ALIASES[$temp]\})" >> ${module_config} |
|
|
177 | done |
|
|
178 | fi |
|
|
179 | |
|
|
180 | # and then stating any module parameters defined from the module |
|
|
181 | if [ -n "${modinfop}" ]; |
|
|
182 | then |
|
|
183 | echo >> ${module_config} |
|
|
184 | echo "# Configurable module parameters" >> ${module_config} |
|
|
185 | echo "# ------------------------------" >> ${module_config} |
|
|
186 | |
|
|
187 | xifs="${IFS}" |
|
|
188 | IFS="$(echo -en "\n\b")" |
|
|
189 | for parameter in ${modinfop} |
|
|
190 | do |
|
|
191 | temp="$(echo ${parameter#*:} | grep -e " [0-9][ =]" | sed "s:.*\([01][= ]\).*:\1:")" |
|
|
192 | if [ -n "${temp}" ]; |
|
|
193 | then |
|
|
194 | module_opts="${module_opts} ${parameter%%:*}:${temp}" |
|
|
195 | fi |
|
|
196 | echo -e "# ${parameter%%:*}:\t${parameter#*:}" >> ${module_config} |
|
|
197 | done |
|
|
198 | IFS="${xifs}" |
|
|
199 | fi |
|
|
200 | |
|
|
201 | # and any examples we can gather from them |
|
|
202 | if [ -n "${module_opts}" ]; |
|
|
203 | then |
|
|
204 | echo >> ${module_config} |
|
|
205 | echo "# For Example..." >> ${module_config} |
|
|
206 | echo "# ------------------------------" >> ${module_config} |
|
|
207 | for parameter in ${module_opts} |
|
|
208 | do |
|
|
209 | echo "# options ${selectedmodule_full/*\//} ${parameter//:*}=${parameter//*:}" >> ${module_config} |
|
|
210 | done |
|
|
211 | fi |
|
|
212 | |
|
|
213 | # then we install it |
|
|
214 | insinto /etc/modules.d |
|
|
215 | newins ${module_config} ${selectedmodule_full/*\//} |
|
|
216 | |
|
|
217 | # and install any documentation we might have. |
|
|
218 | [ -n "${module_docs}" ] && dodoc ${module_docs} |
|
|
219 | done |
|
|
220 | eend 0 |
|
|
221 | } |
|
|
222 | |
| 82 | display_postinst() { |
223 | display_postinst() { |
| 83 | # if we haven't determined the version yet, we need too. |
224 | # if we haven't determined the version yet, we need too. |
| 84 | get_version; |
225 | get_version; |
| 85 | |
226 | |
| 86 | local modulename moduledir sourcedir module_temp file i |
227 | local modulename moduledir sourcedir moduletemp file i |
| 87 | |
228 | |
| 88 | file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR} |
229 | file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR} |
| 89 | file=${file/\/\///} |
230 | file=${file/\/\///} |
| 90 | |
231 | |
| 91 | einfo "If you would like to load this module automatically upon boot" |
232 | einfo "If you would like to load this module automatically upon boot" |
| 92 | einfo "please type the following as root:" |
233 | einfo "please type the following as root:" |
| 93 | for i in ${MODULE_NAMES} |
234 | for i in ${MODULE_NAMES} |
| 94 | do |
235 | do |
| 95 | module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" |
236 | moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")" |
| 96 | modulename="${i/(*/}" |
|
|
| 97 | moduledir="${module_temp/:*/}" |
237 | modulename="${moduletemp/ */}" |
|
|
238 | moduletemp="${moduletemp/* /}" |
|
|
239 | # if we specify two args, then we can set moduledir |
|
|
240 | [ -z "${moduletemp/*:*/}" ] && moduledir="${moduletemp/:*/}" |
|
|
241 | # if we didnt pass the brackets, then we shouldnt accept anything |
|
|
242 | [ -n "${moduletemp/${modulename}/}" ] && sourcedir="${moduletemp/*:/}" |
| 98 | moduledir="${moduledir:-misc}" |
243 | moduledir="${moduledir:-misc}" |
| 99 | sourcedir="${module_temp/*:/}" |
|
|
| 100 | sourcedir="${sourcedir:-${S}}" |
244 | sourcedir="${sourcedir:-${S}}" |
| 101 | |
245 | |
| 102 | einfo " # echo \"${modulename}\" >> ${file}" |
246 | einfo " # echo \"${modulename}\" >> ${file}" |
| 103 | done |
247 | done |
| 104 | echo |
248 | echo |
|
|
249 | } |
|
|
250 | |
|
|
251 | find_module_params() { |
|
|
252 | local matched_offset=0 matched_opts=0 test="${@}" temp_var result |
|
|
253 | local i=0 y=0 z=0 |
|
|
254 | |
|
|
255 | for((i=0; i<=${#test}; i++)) |
|
|
256 | do |
|
|
257 | case ${test:${i}:1} in |
|
|
258 | \() matched_offset[0]=${i};; |
|
|
259 | \:) matched_opts=$((${matched_opts} + 1)); |
|
|
260 | matched_offset[${matched_opts}]="${i}";; |
|
|
261 | \)) matched_opts=$((${matched_opts} + 1)); |
|
|
262 | matched_offset[${matched_opts}]="${i}";; |
|
|
263 | esac |
|
|
264 | done |
|
|
265 | |
|
|
266 | for((i=0; i<=${matched_opts}; i++)) |
|
|
267 | do |
|
|
268 | # i = offset were working on |
|
|
269 | # y = last offset |
|
|
270 | # z = current offset - last offset |
|
|
271 | # temp_var = temporary name |
|
|
272 | case ${i} in |
|
|
273 | 0) tempvar=${test:0:${matched_offset[0]}};; |
|
|
274 | *) y=$((${matched_offset[$((${i} - 1))]} + 1)) |
|
|
275 | z=$((${matched_offset[${i}]} - ${matched_offset[$((${i} - 1))]})); |
|
|
276 | z=$((${z} - 1)) |
|
|
277 | tempvar=${test:${y}:${z}};; |
|
|
278 | esac |
|
|
279 | |
|
|
280 | case ${i} in |
|
|
281 | 0) result="${result} modulename:${tempvar}";; |
|
|
282 | 1) result="${result} libdir:${tempvar}";; |
|
|
283 | 2) result="${result} srcdir:${tempvar}";; |
|
|
284 | 3) result="${result} objdir:${tempvar}";; |
|
|
285 | esac |
|
|
286 | done |
|
|
287 | |
|
|
288 | echo ${result} |
| 105 | } |
289 | } |
| 106 | |
290 | |
| 107 | # default ebuild functions |
291 | # default ebuild functions |
| 108 | # -------------------------------- |
292 | # -------------------------------- |
| 109 | |
293 | |
| 110 | linux-mod_pkg_setup() { |
294 | linux-mod_pkg_setup() { |
| 111 | linux-info_pkg_setup; |
295 | linux-info_pkg_setup; |
| 112 | check_kernel_built; |
296 | check_kernel_built; |
| 113 | check_modules_supported; |
297 | check_modules_supported; |
| 114 | check_extra_config; |
|
|
| 115 | set_kvobj; |
298 | set_kvobj; |
| 116 | } |
299 | } |
| 117 | |
300 | |
| 118 | linux-mod_src_compile() { |
301 | linux-mod_src_compile() { |
| 119 | local modulename moduledir sourcedir module_temp xarch i |
302 | local modulename libdir srcdir objdir i n |
| 120 | xarch="${ARCH}" |
303 | |
| 121 | unset ARCH |
304 | BUILD_TARGETS=${BUILD_TARGETS:-clean module} |
|
|
305 | MODULE_NAMES=${MODULE_NAMES//${MODULE_IGNORE}} |
| 122 | |
306 | |
| 123 | for i in "${MODULE_NAMES}" |
307 | for i in ${MODULE_NAMES} |
|
|
308 | do |
|
|
309 | for n in $(find_module_params ${i}) |
| 124 | do |
310 | do |
| 125 | module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" |
311 | eval ${n/:*}=${n/*:/} |
| 126 | modulename="${i/(*/}" |
312 | done |
| 127 | moduledir="${module_temp/:*/}" |
313 | libdir=${libdir:-misc} |
| 128 | moduledir="${moduledir:-misc}" |
|
|
| 129 | sourcedir="${module_temp/*:/}" |
|
|
| 130 | sourcedir="${sourcedir:-${S}}" |
314 | srcdir=${srcdir:-${S}} |
| 131 | |
315 | objdir=${objdir:-${srcdir}} |
|
|
316 | |
|
|
317 | if [ ! -f "${srcdir}/.built" ]; |
|
|
318 | then |
|
|
319 | cd ${srcdir} |
| 132 | einfo "Preparing ${modulename} module" |
320 | einfo "Preparing ${modulename} module" |
| 133 | cd ${sourcedir} |
321 | env -u ARCH 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}. |
322 | || die "Unable to make \ |
|
|
323 | ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}." |
|
|
324 | touch ${srcdir}/.built |
|
|
325 | cd ${OLDPWD} |
|
|
326 | fi |
| 135 | done |
327 | done |
| 136 | ARCH="${xarch}" |
|
|
| 137 | } |
328 | } |
| 138 | |
329 | |
| 139 | linux-mod_src_install() { |
330 | linux-mod_src_install() { |
| 140 | local modulename moduledir sourcedir module_temp i |
331 | local modulename libdir srcdir objdir i n |
| 141 | |
332 | |
| 142 | for i in "${MODULE_NAMES}" |
333 | for i in ${MODULE_NAMES} |
|
|
334 | do |
|
|
335 | for n in $(find_module_params ${i}) |
| 143 | do |
336 | do |
| 144 | module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")" |
337 | eval ${n/:*}=${n/*:/} |
| 145 | modulename="${i/(*/}" |
338 | done |
| 146 | moduledir="${module_temp/:*/}" |
339 | libdir=${libdir:-misc} |
| 147 | moduledir="${moduledir:-misc}" |
|
|
| 148 | sourcedir="${module_temp/*:/}" |
|
|
| 149 | sourcedir="${sourcedir:-${S}}" |
340 | srcdir=${srcdir:-${S}} |
|
|
341 | objdir=${objdir:-${srcdir}} |
| 150 | |
342 | |
| 151 | einfo "Installing ${modulename} module" |
343 | einfo "Installing ${modulename} module" |
| 152 | cd ${sourcedir} |
344 | cd ${objdir} |
|
|
345 | |
| 153 | insinto /lib/modules/${KV_FULL}/${moduledir} |
346 | insinto /lib/modules/${KV_FULL}/${libdir} |
| 154 | doins ${modulename}.${KV_OBJ} |
347 | doins ${modulename}.${KV_OBJ} |
|
|
348 | cd ${OLDPWD} |
|
|
349 | |
|
|
350 | [ -z "${NO_MODULESD}" ] && generate_modulesd ${objdir}/${modulename} |
| 155 | done |
351 | done |
| 156 | } |
352 | } |
| 157 | |
353 | |
| 158 | linux-mod_pkg_postinst() { |
354 | linux-mod_pkg_postinst() { |
| 159 | update_depmod; |
355 | update_depmod; |