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

Contents of /eclass/linux-mod.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.22 - (hide annotations) (download)
Sun Jan 16 22:54:56 2005 UTC (9 years, 9 months ago) by johnm
Branch: MAIN
Changes since 1.21: +22 -14 lines
few minor fixes. added support for econf if needed

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 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     if [ -x /sbin/modules-update ] ;
112     then
113     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.22 for n in $(find_module_params ${i})
247     do
248     eval ${n/:*}=${n/*:/}
249     done
250     einfo " # echo \"${modulename}\" >> ${file}"
251 johnm 1.20 done
252 johnm 1.22 einfo
253     fi
254 johnm 1.1 }
255    
256 johnm 1.18 find_module_params() {
257     local matched_offset=0 matched_opts=0 test="${@}" temp_var result
258     local i=0 y=0 z=0
259    
260     for((i=0; i<=${#test}; i++))
261     do
262     case ${test:${i}:1} in
263     \() matched_offset[0]=${i};;
264     \:) matched_opts=$((${matched_opts} + 1));
265     matched_offset[${matched_opts}]="${i}";;
266     \)) matched_opts=$((${matched_opts} + 1));
267     matched_offset[${matched_opts}]="${i}";;
268     esac
269     done
270    
271     for((i=0; i<=${matched_opts}; i++))
272     do
273     # i = offset were working on
274     # y = last offset
275     # z = current offset - last offset
276     # temp_var = temporary name
277     case ${i} in
278     0) tempvar=${test:0:${matched_offset[0]}};;
279     *) y=$((${matched_offset[$((${i} - 1))]} + 1))
280     z=$((${matched_offset[${i}]} - ${matched_offset[$((${i} - 1))]}));
281     z=$((${z} - 1))
282     tempvar=${test:${y}:${z}};;
283     esac
284    
285     case ${i} in
286     0) result="${result} modulename:${tempvar}";;
287     1) result="${result} libdir:${tempvar}";;
288     2) result="${result} srcdir:${tempvar}";;
289     3) result="${result} objdir:${tempvar}";;
290     esac
291     done
292    
293     echo ${result}
294     }
295    
296 johnm 1.1 # default ebuild functions
297     # --------------------------------
298    
299     linux-mod_pkg_setup() {
300 johnm 1.6 linux-info_pkg_setup;
301     check_kernel_built;
302 johnm 1.1 check_modules_supported;
303     set_kvobj;
304     }
305    
306     linux-mod_src_compile() {
307 johnm 1.21 local modulename libdir srcdir objdir i n myARCH=${ARCH}
308     unset ARCH
309 johnm 1.16
310     BUILD_TARGETS=${BUILD_TARGETS:-clean module}
311 johnm 1.20
312     for i in ${MODULE_IGNORE}
313     do
314     MODULE_NAMES=${MODULE_NAMES//${i}(*}
315     done
316 johnm 1.1
317 johnm 1.9 for i in ${MODULE_NAMES}
318 johnm 1.1 do
319 johnm 1.18 for n in $(find_module_params ${i})
320     do
321     eval ${n/:*}=${n/*:/}
322     done
323     libdir=${libdir:-misc}
324     srcdir=${srcdir:-${S}}
325     objdir=${objdir:-${srcdir}}
326 johnm 1.10
327 johnm 1.18 if [ ! -f "${srcdir}/.built" ];
328 johnm 1.16 then
329 johnm 1.18 cd ${srcdir}
330 johnm 1.16 einfo "Preparing ${modulename} module"
331 johnm 1.22 if [[ -n ${ECONF_PARAMS} ]]
332     then
333     econf ${ECONF_PARAMS} || \
334     die "Unable to run econf ${ECONF_PARAMS}"
335     fi
336    
337 johnm 1.21 emake ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS} \
338 johnm 1.18 || die "Unable to make \
339     ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}."
340     touch ${srcdir}/.built
341 johnm 1.16 cd ${OLDPWD}
342     fi
343 johnm 1.1 done
344 johnm 1.21
345     ARCH=${myARCH}
346 johnm 1.1 }
347    
348     linux-mod_src_install() {
349 johnm 1.18 local modulename libdir srcdir objdir i n
350 johnm 1.20
351     for i in ${MODULE_IGNORE}
352     do
353     MODULE_NAMES=${MODULE_NAMES//${i}(*}
354     done
355 johnm 1.1
356 johnm 1.9 for i in ${MODULE_NAMES}
357 johnm 1.1 do
358 johnm 1.18 for n in $(find_module_params ${i})
359     do
360     eval ${n/:*}=${n/*:/}
361     done
362     libdir=${libdir:-misc}
363     srcdir=${srcdir:-${S}}
364     objdir=${objdir:-${srcdir}}
365 johnm 1.1
366     einfo "Installing ${modulename} module"
367 johnm 1.18 cd ${objdir}
368    
369     insinto /lib/modules/${KV_FULL}/${libdir}
370 johnm 1.1 doins ${modulename}.${KV_OBJ}
371 johnm 1.16 cd ${OLDPWD}
372 johnm 1.11
373 johnm 1.18 [ -z "${NO_MODULESD}" ] && generate_modulesd ${objdir}/${modulename}
374 johnm 1.1 done
375     }
376    
377     linux-mod_pkg_postinst() {
378     update_depmod;
379 johnm 1.3 update_modules;
380 johnm 1.1 display_postinst;
381     }

  ViewVC Help
Powered by ViewVC 1.1.20