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

Contents of /eclass/linux-mod.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (hide annotations) (download)
Sun Jan 16 12:24:23 2005 UTC (9 years, 6 months ago) by johnm
Branch: MAIN
Changes since 1.20: +5 -2 lines
Changing ARCH unset in src-compile

1 johnm 1.1 # Copyright 1999-2004 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 johnm 1.18 # $Header: /var/cvsroot/gentoo-x86/eclass/linux-mod.eclass,v 1.17 2005/01/09 19:10:55 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.18 eend $?
98 johnm 1.1 else
99     ewarn
100 johnm 1.5 ewarn "${KV_OUT_DIR}/System.map not found."
101 johnm 1.1 ewarn "You must manually update the kernel module dependencies using depmod."
102 johnm 1.18 eend 1
103 johnm 1.1 ewarn
104     fi
105     }
106    
107 johnm 1.3 update_modules() {
108     if [ -x /sbin/modules-update ] ;
109     then
110     ebegin "Updating modules.conf"
111     /sbin/modules-update
112     eend $?
113     fi
114     }
115    
116 johnm 1.1 set_kvobj() {
117     if kernel_is 2 6
118     then
119     KV_OBJ="ko"
120     else
121     KV_OBJ="o"
122     fi
123     einfo "Using KV_OBJ=${KV_OBJ}"
124     }
125    
126 johnm 1.11 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 johnm 1.12 # strip the directory
137 johnm 1.11 selectedmodule="${selectedmodule_full/*\//}"
138 johnm 1.12 # convert the modulename to uppercase
139 johnm 1.11 selectedmodule="$(echo ${selectedmodule} | tr '[:lower:]' '[:upper:]')"
140    
141     module_docs="MODULESD_${selectedmodule}_DOCS"
142     module_aliases="$(eval echo \$\{#MODULESD_${selectedmodule}_ALIASES[*]\})"
143 johnm 1.12 [ ${module_aliases} == 0 ] && unset module_aliases
144 johnm 1.11 module_docs="${!module_docs}"
145 johnm 1.12 modinfop="$(modinfo -p ${selectedmodule_full}.${KV_OBJ})"
146 johnm 1.11
147 johnm 1.12 # 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 johnm 1.11 for parameter in ${!module_*}
150     do
151     [ -z "${!parameter}" ] && unset ${parameter}
152     done
153 johnm 1.12 [ -z "${!module_*}" -a -z "${modinfop}" ] && return
154 johnm 1.11
155 johnm 1.12 #so now we can set the configfilevar
156 johnm 1.11 module_config="${T}/modulesd-${selectedmodule}"
157 johnm 1.12
158     # and being working on things.
159 johnm 1.11 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 johnm 1.12 if [ ${module_aliases} > 0 ];
168 johnm 1.11 then
169 johnm 1.13 echo >> ${module_config}
170 johnm 1.11 echo "# Internal Aliases - Do not edit" >> ${module_config}
171     echo "# ------------------------------" >> ${module_config}
172 johnm 1.12
173 johnm 1.11 (( module_aliases-- ))
174     for temp in $(seq 0 ${module_aliases})
175     do
176     echo "alias $(eval echo \$\{MODULESD_${selectedmodule}_ALIASES[$temp]\})" >> ${module_config}
177 johnm 1.12 done
178 johnm 1.11 fi
179    
180 johnm 1.12 # and then stating any module parameters defined from the module
181 johnm 1.11 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 johnm 1.12 # and any examples we can gather from them
202 johnm 1.11 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 johnm 1.12 # then we install it
214 johnm 1.11 insinto /etc/modules.d
215     newins ${module_config} ${selectedmodule_full/*\//}
216    
217 johnm 1.12 # and install any documentation we might have.
218 johnm 1.11 [ -n "${module_docs}" ] && dodoc ${module_docs}
219     done
220     eend 0
221     }
222    
223 johnm 1.1 display_postinst() {
224     # if we haven't determined the version yet, we need too.
225     get_version;
226    
227 johnm 1.10 local modulename moduledir sourcedir moduletemp file i
228 johnm 1.1
229     file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}
230     file=${file/\/\///}
231    
232 johnm 1.20 for i in ${MODULE_IGNORE}
233     do
234     MODULE_NAMES=${MODULE_NAMES//${i}(*}
235     done
236    
237 johnm 1.1 einfo "If you would like to load this module automatically upon boot"
238     einfo "please type the following as root:"
239     for i in ${MODULE_NAMES}
240     do
241 johnm 1.20 for n in $(find_module_params ${i})
242     do
243     eval ${n/:*}=${n/*:/}
244     done
245     libdir=${libdir:-misc}
246     srcdir=${srcdir:-${S}}
247     objdir=${objdir:-${srcdir}}
248 johnm 1.1
249     einfo " # echo \"${modulename}\" >> ${file}"
250     done
251     echo
252     }
253    
254 johnm 1.18 find_module_params() {
255     local matched_offset=0 matched_opts=0 test="${@}" temp_var result
256     local i=0 y=0 z=0
257    
258     for((i=0; i<=${#test}; i++))
259     do
260     case ${test:${i}:1} in
261     \() matched_offset[0]=${i};;
262     \:) matched_opts=$((${matched_opts} + 1));
263     matched_offset[${matched_opts}]="${i}";;
264     \)) matched_opts=$((${matched_opts} + 1));
265     matched_offset[${matched_opts}]="${i}";;
266     esac
267     done
268    
269     for((i=0; i<=${matched_opts}; i++))
270     do
271     # i = offset were working on
272     # y = last offset
273     # z = current offset - last offset
274     # temp_var = temporary name
275     case ${i} in
276     0) tempvar=${test:0:${matched_offset[0]}};;
277     *) y=$((${matched_offset[$((${i} - 1))]} + 1))
278     z=$((${matched_offset[${i}]} - ${matched_offset[$((${i} - 1))]}));
279     z=$((${z} - 1))
280     tempvar=${test:${y}:${z}};;
281     esac
282    
283     case ${i} in
284     0) result="${result} modulename:${tempvar}";;
285     1) result="${result} libdir:${tempvar}";;
286     2) result="${result} srcdir:${tempvar}";;
287     3) result="${result} objdir:${tempvar}";;
288     esac
289     done
290    
291     echo ${result}
292     }
293    
294 johnm 1.1 # default ebuild functions
295     # --------------------------------
296    
297     linux-mod_pkg_setup() {
298 johnm 1.6 linux-info_pkg_setup;
299     check_kernel_built;
300 johnm 1.1 check_modules_supported;
301     set_kvobj;
302     }
303    
304     linux-mod_src_compile() {
305 johnm 1.21 local modulename libdir srcdir objdir i n myARCH=${ARCH}
306     unset ARCH
307 johnm 1.16
308     BUILD_TARGETS=${BUILD_TARGETS:-clean module}
309 johnm 1.20
310     for i in ${MODULE_IGNORE}
311     do
312     MODULE_NAMES=${MODULE_NAMES//${i}(*}
313     done
314 johnm 1.1
315 johnm 1.9 for i in ${MODULE_NAMES}
316 johnm 1.1 do
317 johnm 1.18 for n in $(find_module_params ${i})
318     do
319     eval ${n/:*}=${n/*:/}
320     done
321     libdir=${libdir:-misc}
322     srcdir=${srcdir:-${S}}
323     objdir=${objdir:-${srcdir}}
324 johnm 1.10
325 johnm 1.18 if [ ! -f "${srcdir}/.built" ];
326 johnm 1.16 then
327 johnm 1.18 cd ${srcdir}
328 johnm 1.16 einfo "Preparing ${modulename} module"
329 johnm 1.21 emake ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS} \
330 johnm 1.18 || die "Unable to make \
331     ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}."
332     touch ${srcdir}/.built
333 johnm 1.16 cd ${OLDPWD}
334     fi
335 johnm 1.1 done
336 johnm 1.21
337     ARCH=${myARCH}
338 johnm 1.1 }
339    
340     linux-mod_src_install() {
341 johnm 1.18 local modulename libdir srcdir objdir i n
342 johnm 1.20
343     for i in ${MODULE_IGNORE}
344     do
345     MODULE_NAMES=${MODULE_NAMES//${i}(*}
346     done
347 johnm 1.1
348 johnm 1.9 for i in ${MODULE_NAMES}
349 johnm 1.1 do
350 johnm 1.18 for n in $(find_module_params ${i})
351     do
352     eval ${n/:*}=${n/*:/}
353     done
354     libdir=${libdir:-misc}
355     srcdir=${srcdir:-${S}}
356     objdir=${objdir:-${srcdir}}
357 johnm 1.1
358     einfo "Installing ${modulename} module"
359 johnm 1.18 cd ${objdir}
360    
361     insinto /lib/modules/${KV_FULL}/${libdir}
362 johnm 1.1 doins ${modulename}.${KV_OBJ}
363 johnm 1.16 cd ${OLDPWD}
364 johnm 1.11
365 johnm 1.18 [ -z "${NO_MODULESD}" ] && generate_modulesd ${objdir}/${modulename}
366 johnm 1.1 done
367     }
368    
369     linux-mod_pkg_postinst() {
370     update_depmod;
371 johnm 1.3 update_modules;
372 johnm 1.1 display_postinst;
373     }

  ViewVC Help
Powered by ViewVC 1.1.20