/[gentoo-x86]/eclass/linux-mod.eclass
Gentoo

Contents of /eclass/linux-mod.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.25 - (hide annotations) (download)
Fri Jan 28 17:33:17 2005 UTC (9 years, 7 months ago) by johnm
Branch: MAIN
Changes since 1.24: +3 -3 lines
Changing detection of module.d/* file to see if the file is actually setting anything. if it isnt, dont bother running modules-update

1 johnm 1.1 # Copyright 1999-2004 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 johnm 1.25 # $Header: /var/cvsroot/gentoo-x86/eclass/linux-mod.eclass,v 1.24 2005/01/28 15:15:01 johnm Exp $
4 johnm 1.1
5 johnm 1.10 # Description: This eclass is used to interface with linux-info in such a way
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 johnm 1.22 # 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 johnm 1.10 # 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 johnm 1.16 # It will only make BUILD_TARGETS once
31     # in any directory.
32 johnm 1.12 # NO_MODULESD <string> Set this to something to prevent
33     # modulesd file generation
34 johnm 1.10
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
57 johnm 1.1
58     inherit linux-info
59     ECLASS=linux-mod
60     INHERITED="$INHERITED $ECLASS"
61 johnm 1.14 EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst src_compile
62 johnm 1.1
63     DESCRIPTION="Based on the $ECLASS eclass"
64     SLOT=0
65     DEPEND="virtual/linux-sources
66 johnm 1.11 sys-apps/sed
67 johnm 1.17 virtual/modutils"
68 johnm 1.1
69     # eclass utilities
70     # ----------------------------------
71    
72     use_m() {
73     # if we haven't determined the version yet, we need too.
74     get_version;
75    
76     # if the kernel version is greater than 2.6.6 then we should use
77 johnm 1.8 # M= instead of SUBDIRS=
78 johnm 1.1 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \
79     return 0 || return 1
80     }
81    
82     convert_to_m() {
83     [ ! -f "${1}" ] && die "convert_to_m() requires a filename as an argument"
84     if use_m
85     then
86 johnm 1.8 ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIRS="
87 johnm 1.1 sed -i 's:SUBDIRS=:M=:g' ${1}
88     eend $?
89     fi
90     }
91    
92     update_depmod() {
93     # if we haven't determined the version yet, we need too.
94     get_version;
95    
96     ebegin "Updating module dependencies for ${KV_FULL}"
97 johnm 1.5 if [ -r ${KV_OUT_DIR}/System.map ]
98 johnm 1.1 then
99 johnm 1.5 depmod -ae -F ${KV_OUT_DIR}/System.map -b ${ROOT} -r ${KV_FULL}
100 johnm 1.18 eend $?
101 johnm 1.1 else
102     ewarn
103 johnm 1.5 ewarn "${KV_OUT_DIR}/System.map not found."
104 johnm 1.1 ewarn "You must manually update the kernel module dependencies using depmod."
105 johnm 1.18 eend 1
106 johnm 1.1 ewarn
107     fi
108     }
109    
110 johnm 1.3 update_modules() {
111 johnm 1.25 if [ -x /sbin/modules-update -a \
112     -n "$(grep -v -e "^#" -e "^$" ${D}/etc/modules.d/*)" ] ; then
113 johnm 1.3 ebegin "Updating modules.conf"
114     /sbin/modules-update
115     eend $?
116     fi
117     }
118    
119 johnm 1.1 set_kvobj() {
120     if kernel_is 2 6
121     then
122     KV_OBJ="ko"
123     else
124     KV_OBJ="o"
125     fi
126     einfo "Using KV_OBJ=${KV_OBJ}"
127     }
128    
129 johnm 1.11 generate_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 johnm 1.12 # strip the directory
140 johnm 1.11 selectedmodule="${selectedmodule_full/*\//}"
141 johnm 1.12 # convert the modulename to uppercase
142 johnm 1.11 selectedmodule="$(echo ${selectedmodule} | tr '[:lower:]' '[:upper:]')"
143    
144     module_docs="MODULESD_${selectedmodule}_DOCS"
145     module_aliases="$(eval echo \$\{#MODULESD_${selectedmodule}_ALIASES[*]\})"
146 johnm 1.12 [ ${module_aliases} == 0 ] && unset module_aliases
147 johnm 1.11 module_docs="${!module_docs}"
148 johnm 1.12 modinfop="$(modinfo -p ${selectedmodule_full}.${KV_OBJ})"
149 johnm 1.11
150 johnm 1.12 # 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 johnm 1.11 for parameter in ${!module_*}
153     do
154     [ -z "${!parameter}" ] && unset ${parameter}
155     done
156 johnm 1.12 [ -z "${!module_*}" -a -z "${modinfop}" ] && return
157 johnm 1.11
158 johnm 1.12 #so now we can set the configfilevar
159 johnm 1.11 module_config="${T}/modulesd-${selectedmodule}"
160 johnm 1.12
161     # and being working on things.
162 johnm 1.11 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 johnm 1.12 if [ ${module_aliases} > 0 ];
171 johnm 1.11 then
172 johnm 1.13 echo >> ${module_config}
173 johnm 1.11 echo "# Internal Aliases - Do not edit" >> ${module_config}
174     echo "# ------------------------------" >> ${module_config}
175 johnm 1.12
176 johnm 1.11 (( module_aliases-- ))
177     for temp in $(seq 0 ${module_aliases})
178     do
179     echo "alias $(eval echo \$\{MODULESD_${selectedmodule}_ALIASES[$temp]\})" >> ${module_config}
180 johnm 1.12 done
181 johnm 1.11 fi
182    
183 johnm 1.12 # and then stating any module parameters defined from the module
184 johnm 1.11 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 johnm 1.12 # and any examples we can gather from them
205 johnm 1.11 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 johnm 1.12 # then we install it
217 johnm 1.11 insinto /etc/modules.d
218     newins ${module_config} ${selectedmodule_full/*\//}
219    
220 johnm 1.12 # and install any documentation we might have.
221 johnm 1.11 [ -n "${module_docs}" ] && dodoc ${module_docs}
222     done
223     eend 0
224     }
225    
226 johnm 1.1 display_postinst() {
227     # if we haven't determined the version yet, we need too.
228     get_version;
229    
230 johnm 1.10 local modulename moduledir sourcedir moduletemp file i
231 johnm 1.1
232     file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}
233     file=${file/\/\///}
234    
235 johnm 1.20 for i in ${MODULE_IGNORE}
236     do
237     MODULE_NAMES=${MODULE_NAMES//${i}(*}
238     done
239    
240 johnm 1.22 if [[ -n ${MODULE_NAMES} ]]
241     then
242     einfo "If you would like to load this module automatically upon boot"
243     einfo "please type the following as root:"
244     for i in ${MODULE_NAMES}
245 johnm 1.20 do
246 johnm 1.23 unset libdir srcdir objdir
247 johnm 1.22 for n in $(find_module_params ${i})
248     do
249     eval ${n/:*}=${n/*:/}
250     done
251     einfo " # echo \"${modulename}\" >> ${file}"
252 johnm 1.20 done
253 johnm 1.22 einfo
254     fi
255 johnm 1.1 }
256    
257 johnm 1.18 find_module_params() {
258     local matched_offset=0 matched_opts=0 test="${@}" temp_var result
259     local i=0 y=0 z=0
260    
261     for((i=0; i<=${#test}; i++))
262     do
263     case ${test:${i}:1} in
264     \() matched_offset[0]=${i};;
265     \:) matched_opts=$((${matched_opts} + 1));
266     matched_offset[${matched_opts}]="${i}";;
267     \)) matched_opts=$((${matched_opts} + 1));
268     matched_offset[${matched_opts}]="${i}";;
269     esac
270     done
271    
272     for((i=0; i<=${matched_opts}; i++))
273     do
274     # i = offset were working on
275     # y = last offset
276     # z = current offset - last offset
277     # temp_var = temporary name
278     case ${i} in
279     0) tempvar=${test:0:${matched_offset[0]}};;
280     *) y=$((${matched_offset[$((${i} - 1))]} + 1))
281     z=$((${matched_offset[${i}]} - ${matched_offset[$((${i} - 1))]}));
282     z=$((${z} - 1))
283     tempvar=${test:${y}:${z}};;
284     esac
285    
286     case ${i} in
287     0) result="${result} modulename:${tempvar}";;
288     1) result="${result} libdir:${tempvar}";;
289     2) result="${result} srcdir:${tempvar}";;
290     3) result="${result} objdir:${tempvar}";;
291     esac
292     done
293    
294     echo ${result}
295     }
296    
297 johnm 1.1 # default ebuild functions
298     # --------------------------------
299    
300     linux-mod_pkg_setup() {
301 johnm 1.6 linux-info_pkg_setup;
302     check_kernel_built;
303 johnm 1.1 check_modules_supported;
304     set_kvobj;
305     }
306    
307     linux-mod_src_compile() {
308 johnm 1.21 local modulename libdir srcdir objdir i n myARCH=${ARCH}
309     unset ARCH
310 johnm 1.16
311     BUILD_TARGETS=${BUILD_TARGETS:-clean module}
312 johnm 1.20
313     for i in ${MODULE_IGNORE}
314     do
315     MODULE_NAMES=${MODULE_NAMES//${i}(*}
316     done
317 johnm 1.1
318 johnm 1.9 for i in ${MODULE_NAMES}
319 johnm 1.1 do
320 johnm 1.23 unset libdir srcdir objdir
321 johnm 1.18 for n in $(find_module_params ${i})
322     do
323     eval ${n/:*}=${n/*:/}
324     done
325     libdir=${libdir:-misc}
326     srcdir=${srcdir:-${S}}
327     objdir=${objdir:-${srcdir}}
328 johnm 1.10
329 johnm 1.18 if [ ! -f "${srcdir}/.built" ];
330 johnm 1.16 then
331 johnm 1.18 cd ${srcdir}
332 johnm 1.16 einfo "Preparing ${modulename} module"
333 johnm 1.22 if [[ -n ${ECONF_PARAMS} ]]
334     then
335     econf ${ECONF_PARAMS} || \
336     die "Unable to run econf ${ECONF_PARAMS}"
337     fi
338    
339 johnm 1.21 emake ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS} \
340 johnm 1.18 || die "Unable to make \
341     ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}."
342     touch ${srcdir}/.built
343 johnm 1.16 cd ${OLDPWD}
344     fi
345 johnm 1.1 done
346 johnm 1.21
347     ARCH=${myARCH}
348 johnm 1.1 }
349    
350     linux-mod_src_install() {
351 johnm 1.18 local modulename libdir srcdir objdir i n
352 johnm 1.20
353     for i in ${MODULE_IGNORE}
354     do
355     MODULE_NAMES=${MODULE_NAMES//${i}(*}
356     done
357 johnm 1.1
358 johnm 1.9 for i in ${MODULE_NAMES}
359 johnm 1.1 do
360 johnm 1.23 unset libdir srcdir objdir
361 johnm 1.18 for n in $(find_module_params ${i})
362     do
363     eval ${n/:*}=${n/*:/}
364     done
365     libdir=${libdir:-misc}
366     srcdir=${srcdir:-${S}}
367     objdir=${objdir:-${srcdir}}
368 johnm 1.1
369     einfo "Installing ${modulename} module"
370 johnm 1.18 cd ${objdir}
371    
372     insinto /lib/modules/${KV_FULL}/${libdir}
373 johnm 1.1 doins ${modulename}.${KV_OBJ}
374 johnm 1.16 cd ${OLDPWD}
375 johnm 1.11
376 johnm 1.18 [ -z "${NO_MODULESD}" ] && generate_modulesd ${objdir}/${modulename}
377 johnm 1.1 done
378     }
379    
380     linux-mod_pkg_postinst() {
381     update_depmod;
382 johnm 1.3 update_modules;
383 johnm 1.1 display_postinst;
384     }

  ViewVC Help
Powered by ViewVC 1.1.20