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

Contents of /eclass/linux-mod.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (show annotations) (download)
Thu Jan 6 17:58:59 2005 UTC (9 years, 6 months ago) by johnm
Branch: MAIN
Changes since 1.15: +15 -5 lines
Changing build logic. now we dont build BUILD_TARGETS more than once, in the same directory. will still support MODULENAME_TARGETS when this logic is available

1 # Copyright 1999-2004 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: $
4
5 # 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 # 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
54
55 inherit linux-info
56 ECLASS=linux-mod
57 INHERITED="$INHERITED $ECLASS"
58 EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst src_compile
59
60 DESCRIPTION="Based on the $ECLASS eclass"
61 SLOT=0
62 DEPEND="virtual/linux-sources
63 sys-apps/sed
64 sys-apps/module-init-tools"
65
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 # M= instead of SUBDIRS=
75 [ ${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 ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIRS="
84 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 if [ -r ${KV_OUT_DIR}/System.map ]
95 then
96 depmod -ae -F ${KV_OUT_DIR}/System.map -b ${ROOT} -r ${KV_FULL}
97 else
98 ewarn
99 ewarn "${KV_OUT_DIR}/System.map not found."
100 ewarn "You must manually update the kernel module dependencies using depmod."
101 ewarn
102 fi
103 eend $?
104 }
105
106 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 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 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
222 display_postinst() {
223 # if we haven't determined the version yet, we need too.
224 get_version;
225
226 local modulename moduledir sourcedir moduletemp file i
227
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 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 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 linux-info_pkg_setup;
255 check_kernel_built;
256 check_modules_supported;
257 set_kvobj;
258 }
259
260 linux-mod_src_compile() {
261 local modulename moduledir sourcedir moduletemp xarch i
262 xarch="${ARCH}"
263 unset ARCH
264
265 BUILD_TARGETS=${BUILD_TARGETS:-clean module}
266
267 for i in ${MODULE_NAMES}
268 do
269 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 moduledir="${moduledir:-misc}"
277 sourcedir="${sourcedir:-${S}}"
278
279 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 done
289 ARCH="${xarch}"
290 }
291
292 linux-mod_src_install() {
293 local modulename moduledir sourcedir moduletemp i
294
295 for i in ${MODULE_NAMES}
296 do
297 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 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 cd ${OLDPWD}
312
313 [ -z "${NO_MODULESD}" ] && generate_modulesd ${sourcedir}/${modulename}
314 done
315 }
316
317 linux-mod_pkg_postinst() {
318 update_depmod;
319 update_modules;
320 display_postinst;
321 }

  ViewVC Help
Powered by ViewVC 1.1.20