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 |
|
|
sys-apps/sed" |
60 |
|
|
|
61 |
|
|
# eclass utilities |
62 |
|
|
# ---------------------------------- |
63 |
|
|
|
64 |
|
|
use_m() { |
65 |
|
|
# if we haven't determined the version yet, we need too. |
66 |
|
|
get_version; |
67 |
|
|
|
68 |
|
|
# if the kernel version is greater than 2.6.6 then we should use |
69 |
johnm |
1.8 |
# M= instead of SUBDIRS= |
70 |
johnm |
1.1 |
[ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \ |
71 |
|
|
return 0 || return 1 |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
convert_to_m() { |
75 |
|
|
[ ! -f "${1}" ] && die "convert_to_m() requires a filename as an argument" |
76 |
|
|
if use_m |
77 |
|
|
then |
78 |
johnm |
1.8 |
ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIRS=" |
79 |
johnm |
1.1 |
sed -i 's:SUBDIRS=:M=:g' ${1} |
80 |
|
|
eend $? |
81 |
|
|
fi |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
update_depmod() { |
85 |
|
|
# if we haven't determined the version yet, we need too. |
86 |
|
|
get_version; |
87 |
|
|
|
88 |
|
|
ebegin "Updating module dependencies for ${KV_FULL}" |
89 |
johnm |
1.5 |
if [ -r ${KV_OUT_DIR}/System.map ] |
90 |
johnm |
1.1 |
then |
91 |
johnm |
1.5 |
depmod -ae -F ${KV_OUT_DIR}/System.map -b ${ROOT} -r ${KV_FULL} |
92 |
johnm |
1.1 |
else |
93 |
|
|
ewarn |
94 |
johnm |
1.5 |
ewarn "${KV_OUT_DIR}/System.map not found." |
95 |
johnm |
1.1 |
ewarn "You must manually update the kernel module dependencies using depmod." |
96 |
|
|
ewarn |
97 |
|
|
fi |
98 |
|
|
eend $? |
99 |
|
|
} |
100 |
|
|
|
101 |
johnm |
1.3 |
update_modules() { |
102 |
|
|
if [ -x /sbin/modules-update ] ; |
103 |
|
|
then |
104 |
|
|
ebegin "Updating modules.conf" |
105 |
|
|
/sbin/modules-update |
106 |
|
|
eend $? |
107 |
|
|
fi |
108 |
|
|
} |
109 |
|
|
|
110 |
johnm |
1.1 |
set_kvobj() { |
111 |
|
|
if kernel_is 2 6 |
112 |
|
|
then |
113 |
|
|
KV_OBJ="ko" |
114 |
|
|
else |
115 |
|
|
KV_OBJ="o" |
116 |
|
|
fi |
117 |
|
|
einfo "Using KV_OBJ=${KV_OBJ}" |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
display_postinst() { |
121 |
|
|
# if we haven't determined the version yet, we need too. |
122 |
|
|
get_version; |
123 |
|
|
|
124 |
johnm |
1.10 |
local modulename moduledir sourcedir moduletemp file i |
125 |
johnm |
1.1 |
|
126 |
|
|
file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR} |
127 |
|
|
file=${file/\/\///} |
128 |
|
|
|
129 |
|
|
einfo "If you would like to load this module automatically upon boot" |
130 |
|
|
einfo "please type the following as root:" |
131 |
|
|
for i in ${MODULE_NAMES} |
132 |
|
|
do |
133 |
johnm |
1.10 |
moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")" |
134 |
|
|
modulename="${moduletemp/ */}" |
135 |
|
|
moduletemp="${moduletemp/* /}" |
136 |
|
|
# if we specify two args, then we can set moduledir |
137 |
|
|
[ -z "${moduletemp/*:*/}" ] && moduledir="${moduletemp/:*/}" |
138 |
|
|
# if we didnt pass the brackets, then we shouldnt accept anything |
139 |
|
|
[ -n "${moduletemp/${modulename}/}" ] && sourcedir="${moduletemp/*:/}" |
140 |
johnm |
1.1 |
moduledir="${moduledir:-misc}" |
141 |
|
|
sourcedir="${sourcedir:-${S}}" |
142 |
|
|
|
143 |
|
|
einfo " # echo \"${modulename}\" >> ${file}" |
144 |
|
|
done |
145 |
|
|
echo |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
# default ebuild functions |
149 |
|
|
# -------------------------------- |
150 |
|
|
|
151 |
|
|
linux-mod_pkg_setup() { |
152 |
johnm |
1.6 |
linux-info_pkg_setup; |
153 |
|
|
check_kernel_built; |
154 |
johnm |
1.1 |
check_modules_supported; |
155 |
johnm |
1.4 |
check_extra_config; |
156 |
johnm |
1.1 |
set_kvobj; |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
linux-mod_src_compile() { |
160 |
johnm |
1.10 |
local modulename moduledir sourcedir moduletemp xarch i |
161 |
johnm |
1.1 |
xarch="${ARCH}" |
162 |
|
|
unset ARCH |
163 |
|
|
|
164 |
johnm |
1.9 |
for i in ${MODULE_NAMES} |
165 |
johnm |
1.1 |
do |
166 |
johnm |
1.10 |
moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")" |
167 |
|
|
modulename="${moduletemp/ */}" |
168 |
|
|
moduletemp="${moduletemp/* /}" |
169 |
|
|
# if we specify two args, then we can set moduledir |
170 |
|
|
[ -z "${moduletemp/*:*/}" ] && moduledir="${moduletemp/:*/}" |
171 |
|
|
# if we didnt pass the brackets, then we shouldnt accept anything |
172 |
|
|
[ -n "${moduletemp/${modulename}/}" ] && sourcedir="${moduletemp/*:/}" |
173 |
johnm |
1.1 |
moduledir="${moduledir:-misc}" |
174 |
|
|
sourcedir="${sourcedir:-${S}}" |
175 |
johnm |
1.10 |
|
176 |
johnm |
1.1 |
einfo "Preparing ${modulename} module" |
177 |
|
|
cd ${sourcedir} |
178 |
johnm |
1.8 |
emake ${BUILD_PARAMS} ${BUILD_TARGETS:-clean module} || die Unable to make ${BUILD_PARAMS} ${BUILD_TARGETS:-clean module}. |
179 |
johnm |
1.1 |
done |
180 |
|
|
ARCH="${xarch}" |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
linux-mod_src_install() { |
184 |
johnm |
1.10 |
local modulename moduledir sourcedir moduletemp i |
185 |
johnm |
1.1 |
|
186 |
johnm |
1.9 |
for i in ${MODULE_NAMES} |
187 |
johnm |
1.1 |
do |
188 |
johnm |
1.10 |
moduletemp="$(echo ${i} | sed -e "s:\(.*\)(\(.*\)):\1 \2:")" |
189 |
|
|
modulename="${moduletemp/ */}" |
190 |
|
|
moduletemp="${moduletemp/* /}" |
191 |
|
|
# if we specify two args, then we can set moduledir |
192 |
|
|
[ -z "${moduletemp/*:*/}" ] && moduledir="${moduletemp/:*/}" |
193 |
|
|
# if we didnt pass the brackets, then we shouldnt accept anything |
194 |
|
|
[ -n "${moduletemp/${modulename}/}" ] && sourcedir="${moduletemp/*:/}" |
195 |
johnm |
1.1 |
moduledir="${moduledir:-misc}" |
196 |
|
|
sourcedir="${sourcedir:-${S}}" |
197 |
|
|
|
198 |
|
|
einfo "Installing ${modulename} module" |
199 |
|
|
cd ${sourcedir} |
200 |
|
|
insinto /lib/modules/${KV_FULL}/${moduledir} |
201 |
|
|
doins ${modulename}.${KV_OBJ} |
202 |
|
|
done |
203 |
|
|
} |
204 |
|
|
|
205 |
|
|
linux-mod_pkg_postinst() { |
206 |
|
|
update_depmod; |
207 |
johnm |
1.3 |
update_modules; |
208 |
johnm |
1.1 |
display_postinst; |
209 |
|
|
} |