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

Contents of /eclass/linux-mod.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.17 - (hide annotations) (download)
Sun Jan 9 19:10:55 2005 UTC (9 years, 9 months ago) by johnm
Branch: MAIN
Changes since 1.16: +2 -2 lines
changing back to virtual. if this causes problems, then please look at changing the default virtual for that profile to module-init-tools

1 johnm 1.1 # Copyright 1999-2004 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 johnm 1.17 # $Header: /var/cvsroot/gentoo-x86/eclass/linux-mod.eclass,v 1.16 2005/01/06 17:58:59 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     # 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 johnm 1.16 # It will only make BUILD_TARGETS once
28     # in any directory.
29 johnm 1.12 # NO_MODULESD <string> Set this to something to prevent
30     # modulesd file generation
31 johnm 1.10
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
54 johnm 1.1
55     inherit linux-info
56     ECLASS=linux-mod
57     INHERITED="$INHERITED $ECLASS"
58 johnm 1.14 EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst src_compile
59 johnm 1.1
60     DESCRIPTION="Based on the $ECLASS eclass"
61     SLOT=0
62     DEPEND="virtual/linux-sources
63 johnm 1.11 sys-apps/sed
64 johnm 1.17 virtual/modutils"
65 johnm 1.1
66     # eclass utilities
67     # ----------------------------------
68    
69     use_m() {
70     # if we haven't determined the version yet, we need too.
71     get_version;
72    
73     # if the kernel version is greater than 2.6.6 then we should use
74 johnm 1.8 # M= instead of SUBDIRS=
75 johnm 1.1 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \
76     return 0 || return 1
77     }
78    
79     convert_to_m() {
80     [ ! -f "${1}" ] && die "convert_to_m() requires a filename as an argument"
81     if use_m
82     then
83 johnm 1.8 ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIRS="
84 johnm 1.1 sed -i 's:SUBDIRS=:M=:g' ${1}
85     eend $?
86     fi
87     }
88    
89     update_depmod() {
90     # if we haven't determined the version yet, we need too.
91     get_version;
92    
93     ebegin "Updating module dependencies for ${KV_FULL}"
94 johnm 1.5 if [ -r ${KV_OUT_DIR}/System.map ]
95 johnm 1.1 then
96 johnm 1.5 depmod -ae -F ${KV_OUT_DIR}/System.map -b ${ROOT} -r ${KV_FULL}
97 johnm 1.1 else
98     ewarn
99 johnm 1.5 ewarn "${KV_OUT_DIR}/System.map not found."
100 johnm 1.1 ewarn "You must manually update the kernel module dependencies using depmod."
101     ewarn
102     fi
103     eend $?
104     }
105    
106 johnm 1.3 update_modules() {
107     if [ -x /sbin/modules-update ] ;
108     then
109     ebegin "Updating modules.conf"
110     /sbin/modules-update
111     eend $?
112     fi
113     }
114    
115 johnm 1.1 set_kvobj() {
116     if kernel_is 2 6
117     then
118     KV_OBJ="ko"
119     else
120     KV_OBJ="o"
121     fi
122     einfo "Using KV_OBJ=${KV_OBJ}"
123     }
124    
125 johnm 1.11 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 johnm 1.12 # strip the directory
136 johnm 1.11 selectedmodule="${selectedmodule_full/*\//}"
137 johnm 1.12 # convert the modulename to uppercase
138 johnm 1.11 selectedmodule="$(echo ${selectedmodule} | tr '[:lower:]' '[:upper:]')"
139    
140     module_docs="MODULESD_${selectedmodule}_DOCS"
141     module_aliases="$(eval echo \$\{#MODULESD_${selectedmodule}_ALIASES[*]\})"
142 johnm 1.12 [ ${module_aliases} == 0 ] && unset module_aliases
143 johnm 1.11 module_docs="${!module_docs}"
144 johnm 1.12 modinfop="$(modinfo -p ${selectedmodule_full}.${KV_OBJ})"
145 johnm 1.11
146 johnm 1.12 # 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 johnm 1.11 for parameter in ${!module_*}
149     do
150     [ -z "${!parameter}" ] && unset ${parameter}
151     done
152 johnm 1.12 [ -z "${!module_*}" -a -z "${modinfop}" ] && return
153 johnm 1.11
154 johnm 1.12 #so now we can set the configfilevar
155 johnm 1.11 module_config="${T}/modulesd-${selectedmodule}"
156 johnm 1.12
157     # and being working on things.
158 johnm 1.11 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 johnm 1.12 if [ ${module_aliases} > 0 ];
167 johnm 1.11 then
168 johnm 1.13 echo >> ${module_config}
169 johnm 1.11 echo "# Internal Aliases - Do not edit" >> ${module_config}
170     echo "# ------------------------------" >> ${module_config}
171 johnm 1.12
172 johnm 1.11 (( module_aliases-- ))
173     for temp in $(seq 0 ${module_aliases})
174     do
175     echo "alias $(eval echo \$\{MODULESD_${selectedmodule}_ALIASES[$temp]\})" >> ${module_config}
176 johnm 1.12 done
177 johnm 1.11 fi
178    
179 johnm 1.12 # and then stating any module parameters defined from the module
180 johnm 1.11 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 johnm 1.12 # and any examples we can gather from them
201 johnm 1.11 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 johnm 1.12 # then we install it
213 johnm 1.11 insinto /etc/modules.d
214     newins ${module_config} ${selectedmodule_full/*\//}
215    
216 johnm 1.12 # and install any documentation we might have.
217 johnm 1.11 [ -n "${module_docs}" ] && dodoc ${module_docs}
218     done
219     eend 0
220     }
221    
222 johnm 1.1 display_postinst() {
223     # if we haven't determined the version yet, we need too.
224     get_version;
225    
226 johnm 1.10 local modulename moduledir sourcedir moduletemp file i
227 johnm 1.1
228     file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}
229     file=${file/\/\///}
230    
231     einfo "If you would like to load this module automatically upon boot"
232     einfo "please type the following as root:"
233     for i in ${MODULE_NAMES}
234     do
235 johnm 1.10 moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")"
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/*:/}"
242 johnm 1.1 moduledir="${moduledir:-misc}"
243     sourcedir="${sourcedir:-${S}}"
244    
245     einfo " # echo \"${modulename}\" >> ${file}"
246     done
247     echo
248     }
249    
250     # default ebuild functions
251     # --------------------------------
252    
253     linux-mod_pkg_setup() {
254 johnm 1.6 linux-info_pkg_setup;
255     check_kernel_built;
256 johnm 1.1 check_modules_supported;
257     set_kvobj;
258     }
259    
260     linux-mod_src_compile() {
261 johnm 1.10 local modulename moduledir sourcedir moduletemp xarch i
262 johnm 1.1 xarch="${ARCH}"
263 johnm 1.16 unset ARCH
264    
265     BUILD_TARGETS=${BUILD_TARGETS:-clean module}
266 johnm 1.1
267 johnm 1.9 for i in ${MODULE_NAMES}
268 johnm 1.1 do
269 johnm 1.10 moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")"
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/*:/}"
276 johnm 1.1 moduledir="${moduledir:-misc}"
277     sourcedir="${sourcedir:-${S}}"
278 johnm 1.10
279 johnm 1.16 if [ ! -f "${sourcedir}/.built" ];
280     then
281     cd ${sourcedir}
282     einfo "Preparing ${modulename} module"
283     emake ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS} || \
284     die Unable to make ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}.
285     touch ${sourcedir}/.built
286     cd ${OLDPWD}
287     fi
288 johnm 1.1 done
289     ARCH="${xarch}"
290     }
291    
292     linux-mod_src_install() {
293 johnm 1.10 local modulename moduledir sourcedir moduletemp i
294 johnm 1.1
295 johnm 1.9 for i in ${MODULE_NAMES}
296 johnm 1.1 do
297 johnm 1.10 moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")"
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/*:/}"
304 johnm 1.1 moduledir="${moduledir:-misc}"
305     sourcedir="${sourcedir:-${S}}"
306    
307     einfo "Installing ${modulename} module"
308     cd ${sourcedir}
309     insinto /lib/modules/${KV_FULL}/${moduledir}
310     doins ${modulename}.${KV_OBJ}
311 johnm 1.16 cd ${OLDPWD}
312 johnm 1.11
313 johnm 1.12 [ -z "${NO_MODULESD}" ] && generate_modulesd ${sourcedir}/${modulename}
314 johnm 1.1 done
315     }
316    
317     linux-mod_pkg_postinst() {
318     update_depmod;
319 johnm 1.3 update_modules;
320 johnm 1.1 display_postinst;
321     }

  ViewVC Help
Powered by ViewVC 1.1.20