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

Contents of /eclass/linux-mod.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (hide annotations) (download)
Sat Dec 18 16:00:10 2004 UTC (10 years ago) by johnm
Branch: MAIN
Changes since 1.10: +95 -1 lines
adding support for automated modules.d file generation

1 johnm 1.1 # Copyright 1999-2004 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 johnm 1.3 # $Header: $
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    
28    
29     # MODULE_NAMES - Detailed Overview
30     #
31     # The structure of each MODULE_NAMES entry is as follows:
32     # modulename(libmodulesdir:modulesourcedir)
33     # for example:
34     # MODULE_NAMES="module_pci(pci:${S}/pci) module_usb(usb:${S}/usb)"
35     #
36     # what this would do is
37     # cd ${S}/pci
38     # make ${BUILD_PARAMS} ${BUILD_TARGETS}
39     # insinto /lib/modules/${KV_FULL}/pci
40     # doins module_pci.${KV_OBJ}
41     #
42     # cd ${S}/usb
43     # make ${BUILD_PARAMS} ${BUILD_TARGETS}
44     # insinto /lib/modules/${KV_FULL}/usb
45     # doins module_usb.${KV_OBJ}
46     #
47     # if the modulessourcedir isnt specified, it assumes ${S}
48     # if the libmodulesdir isnt specified, it assumes misc.
49     # if no seperator is defined ":" then it assumes the argument is modulesourcedir
50 johnm 1.1
51     inherit linux-info
52     ECLASS=linux-mod
53     INHERITED="$INHERITED $ECLASS"
54     EXPORT_FUNCTIONS pkg_setup pkg_postinst src_compile
55    
56     DESCRIPTION="Based on the $ECLASS eclass"
57     SLOT=0
58     DEPEND="virtual/linux-sources
59 johnm 1.11 sys-apps/sed
60     sys-apps/module-init-tools"
61 johnm 1.1
62     # eclass utilities
63     # ----------------------------------
64    
65     use_m() {
66     # if we haven't determined the version yet, we need too.
67     get_version;
68    
69     # if the kernel version is greater than 2.6.6 then we should use
70 johnm 1.8 # M= instead of SUBDIRS=
71 johnm 1.1 [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \
72     return 0 || return 1
73     }
74    
75     convert_to_m() {
76     [ ! -f "${1}" ] && die "convert_to_m() requires a filename as an argument"
77     if use_m
78     then
79 johnm 1.8 ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIRS="
80 johnm 1.1 sed -i 's:SUBDIRS=:M=:g' ${1}
81     eend $?
82     fi
83     }
84    
85     update_depmod() {
86     # if we haven't determined the version yet, we need too.
87     get_version;
88    
89     ebegin "Updating module dependencies for ${KV_FULL}"
90 johnm 1.5 if [ -r ${KV_OUT_DIR}/System.map ]
91 johnm 1.1 then
92 johnm 1.5 depmod -ae -F ${KV_OUT_DIR}/System.map -b ${ROOT} -r ${KV_FULL}
93 johnm 1.1 else
94     ewarn
95 johnm 1.5 ewarn "${KV_OUT_DIR}/System.map not found."
96 johnm 1.1 ewarn "You must manually update the kernel module dependencies using depmod."
97     ewarn
98     fi
99     eend $?
100     }
101    
102 johnm 1.3 update_modules() {
103     if [ -x /sbin/modules-update ] ;
104     then
105     ebegin "Updating modules.conf"
106     /sbin/modules-update
107     eend $?
108     fi
109     }
110    
111 johnm 1.1 set_kvobj() {
112     if kernel_is 2 6
113     then
114     KV_OBJ="ko"
115     else
116     KV_OBJ="o"
117     fi
118     einfo "Using KV_OBJ=${KV_OBJ}"
119     }
120    
121 johnm 1.11 generate_modulesd() {
122     # This function will generate the neccessary modules.d file from the
123     # information contained in the modules exported parms
124    
125     local selectedmodule selectedmodule_full selectedmodulevars parameter modinfop arg xifs temp
126     local module_docs module_opts module_aliases module_config
127    
128     for arg in ${@}
129     do
130     # convert the modulename to uppercase
131     selectedmodule_full="${arg}"
132     selectedmodule="${selectedmodule_full/*\//}"
133     selectedmodule="$(echo ${selectedmodule} | tr '[:lower:]' '[:upper:]')"
134    
135     module_docs="MODULESD_${selectedmodule}_DOCS"
136     module_aliases="$(eval echo \$\{#MODULESD_${selectedmodule}_ALIASES[*]\})"
137     module_docs="${!module_docs}"
138    
139     for parameter in ${!module_*}
140     do
141     [ -z "${!parameter}" ] && unset ${parameter}
142     done
143    
144     # OK, so now ${!module_*} only contains stuff from the ebuild.
145     # now we can do some proper work!
146     [ -z "${!module_*}" ] && return
147    
148     module_config="${T}/modulesd-${selectedmodule}"
149    
150     ebegin "Preparing file for modules.d"
151     echo "# modules.d config file for ${selectedmodule}" >> ${module_config}
152     echo "# this file was automatically generated from linux-mod.eclass" >> ${module_config}
153     echo "# on behalf of ${EBUILD/*\//}" >> ${module_config}
154     for temp in ${module_docs}
155     do
156     echo "# Please read ${temp/*\//} for more info" >> ${module_config}
157     done
158    
159     if [ ${module_aliases} -gt 0 ];
160     then
161     echo "# Internal Aliases - Do not edit" >> ${module_config}
162     echo "# ------------------------------" >> ${module_config}
163    
164     (( module_aliases-- ))
165     for temp in $(seq 0 ${module_aliases})
166     do
167     echo "alias $(eval echo \$\{MODULESD_${selectedmodule}_ALIASES[$temp]\})" >> ${module_config}
168    
169     done
170     fi
171    
172     modinfop="$(modinfo -p ${selectedmodule_full}.${KV_OBJ})"
173     if [ -n "${modinfop}" ];
174     then
175     echo >> ${module_config}
176     echo "# Configurable module parameters" >> ${module_config}
177     echo "# ------------------------------" >> ${module_config}
178    
179     xifs="${IFS}"
180     IFS="$(echo -en "\n\b")"
181     for parameter in ${modinfop}
182     do
183     temp="$(echo ${parameter#*:} | grep -e " [0-9][ =]" | sed "s:.*\([01][= ]\).*:\1:")"
184     if [ -n "${temp}" ];
185     then
186     module_opts="${module_opts} ${parameter%%:*}:${temp}"
187     fi
188     echo -e "# ${parameter%%:*}:\t${parameter#*:}" >> ${module_config}
189     done
190     IFS="${xifs}"
191     fi
192    
193     if [ -n "${module_opts}" ];
194     then
195     echo >> ${module_config}
196     echo "# For Example..." >> ${module_config}
197     echo "# ------------------------------" >> ${module_config}
198     for parameter in ${module_opts}
199     do
200     echo "# options ${selectedmodule_full/*\//} ${parameter//:*}=${parameter//*:}" >> ${module_config}
201     done
202     fi
203    
204     insinto /etc/modules.d
205     newins ${module_config} ${selectedmodule_full/*\//}
206    
207     [ -n "${module_docs}" ] && dodoc ${module_docs}
208     done
209     eend 0
210     }
211    
212 johnm 1.1 display_postinst() {
213     # if we haven't determined the version yet, we need too.
214     get_version;
215    
216 johnm 1.10 local modulename moduledir sourcedir moduletemp file i
217 johnm 1.1
218     file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}
219     file=${file/\/\///}
220    
221     einfo "If you would like to load this module automatically upon boot"
222     einfo "please type the following as root:"
223     for i in ${MODULE_NAMES}
224     do
225 johnm 1.10 moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")"
226     modulename="${moduletemp/ */}"
227     moduletemp="${moduletemp/* /}"
228     # if we specify two args, then we can set moduledir
229     [ -z "${moduletemp/*:*/}" ] && moduledir="${moduletemp/:*/}"
230     # if we didnt pass the brackets, then we shouldnt accept anything
231     [ -n "${moduletemp/${modulename}/}" ] && sourcedir="${moduletemp/*:/}"
232 johnm 1.1 moduledir="${moduledir:-misc}"
233     sourcedir="${sourcedir:-${S}}"
234    
235     einfo " # echo \"${modulename}\" >> ${file}"
236     done
237     echo
238     }
239    
240     # default ebuild functions
241     # --------------------------------
242    
243     linux-mod_pkg_setup() {
244 johnm 1.6 linux-info_pkg_setup;
245     check_kernel_built;
246 johnm 1.1 check_modules_supported;
247 johnm 1.4 check_extra_config;
248 johnm 1.1 set_kvobj;
249     }
250    
251     linux-mod_src_compile() {
252 johnm 1.10 local modulename moduledir sourcedir moduletemp xarch i
253 johnm 1.1 xarch="${ARCH}"
254     unset ARCH
255    
256 johnm 1.9 for i in ${MODULE_NAMES}
257 johnm 1.1 do
258 johnm 1.10 moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")"
259     modulename="${moduletemp/ */}"
260     moduletemp="${moduletemp/* /}"
261     # if we specify two args, then we can set moduledir
262     [ -z "${moduletemp/*:*/}" ] && moduledir="${moduletemp/:*/}"
263     # if we didnt pass the brackets, then we shouldnt accept anything
264     [ -n "${moduletemp/${modulename}/}" ] && sourcedir="${moduletemp/*:/}"
265 johnm 1.1 moduledir="${moduledir:-misc}"
266     sourcedir="${sourcedir:-${S}}"
267 johnm 1.10
268 johnm 1.1 einfo "Preparing ${modulename} module"
269     cd ${sourcedir}
270 johnm 1.8 emake ${BUILD_PARAMS} ${BUILD_TARGETS:-clean module} || die Unable to make ${BUILD_PARAMS} ${BUILD_TARGETS:-clean module}.
271 johnm 1.1 done
272     ARCH="${xarch}"
273     }
274    
275     linux-mod_src_install() {
276 johnm 1.10 local modulename moduledir sourcedir moduletemp i
277 johnm 1.1
278 johnm 1.9 for i in ${MODULE_NAMES}
279 johnm 1.1 do
280 johnm 1.10 moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")"
281     modulename="${moduletemp/ */}"
282     moduletemp="${moduletemp/* /}"
283     # if we specify two args, then we can set moduledir
284     [ -z "${moduletemp/*:*/}" ] && moduledir="${moduletemp/:*/}"
285     # if we didnt pass the brackets, then we shouldnt accept anything
286     [ -n "${moduletemp/${modulename}/}" ] && sourcedir="${moduletemp/*:/}"
287 johnm 1.1 moduledir="${moduledir:-misc}"
288     sourcedir="${sourcedir:-${S}}"
289    
290     einfo "Installing ${modulename} module"
291     cd ${sourcedir}
292     insinto /lib/modules/${KV_FULL}/${moduledir}
293     doins ${modulename}.${KV_OBJ}
294 johnm 1.11
295     generate_modulesd ${sourcedir}/${modulename}
296 johnm 1.1 done
297     }
298    
299     linux-mod_pkg_postinst() {
300     update_depmod;
301 johnm 1.3 update_modules;
302 johnm 1.1 display_postinst;
303     }

  ViewVC Help
Powered by ViewVC 1.1.20