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