summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
Diffstat (limited to 'eclass')
-rw-r--r--eclass/kernel-2.eclass199
-rw-r--r--eclass/linux-info.eclass256
-rw-r--r--eclass/linux-mod.eclass154
3 files changed, 522 insertions, 87 deletions
diff --git a/eclass/kernel-2.eclass b/eclass/kernel-2.eclass
index 3751d2bbec15..35c6ac365e11 100644
--- a/eclass/kernel-2.eclass
+++ b/eclass/kernel-2.eclass
@@ -1,34 +1,49 @@
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/kernel-2.eclass,v 1.46 2004/10/19 19:51:12 vapier Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/kernel-2.eclass,v 1.47 2004/11/24 16:36:38 johnm Exp $
-# Description: kernel.eclass rewrite for a clean base regarding the 2.6
-# series of kernel with back-compatibility for 2.4
+# kernel.eclass rewrite for a clean base regarding the 2.6 series of kernel
+# with back-compatibility for 2.4
#
-# Maintainer: John Mylchreest <johnm@gentoo.org>
+# Author: John Mylchreest <johnm@gentoo.org>
+# Copyright 2004 Gentoo Linux
#
# Please direct your bugs to the current eclass maintainer :)
+# thatll be: johnm
# added functionality:
# unipatch - a flexible, singular method to extract, add and remove patches.
-# A Couple of env vars are available to effect usage of this eclass
+# A Couple of env vars are available to effect behaviour of this eclass
# These are as follows:
#
-# K_NOSETEXTRAVERSION - if this is set then EXTRAVERSION will not be automatically set within the kernel Makefile
-# K_NOUSENAME - if this is set then EXTRAVERSION will not include the first part of ${PN} in EXTRAVERSION
-# K_PREPATCHED - if the patchset is prepatched (ie: mm-sources, ck-sources, ac-sources) it will use PR (ie: -r5) as the patchset version for
-# - and not use it as a true package revision
-# K_EXTRAEINFO - this is a new-line seperated list of einfo displays in postinst and can be used to carry additional postinst messages
-# K_EXTRAEWARN - same as K_EXTRAEINFO except ewarn's instead of einfo's
-
-# H_SUPPORTEDARCH - this should be a space separated list of ARCH's which can be supported by the headers ebuild
-
-# UNIPATCH_LIST - space delimetered list of patches to be applied to the kernel
-# UNIPATCH_EXCLUDE - an addition var to support exlusion based completely on "<passedstring>*" and not "<passedno#>_*"
-# - this should _NOT_ be used from the ebuild as this is reserved for end users passing excludes from the cli
-# UNIPATCH_DOCS - space delimemeted list of docs to be installed to the doc dir
-# UNIPATCH_STRICTORDER - if this is set places patches into directories of order, so they are applied in the order passed
+# K_NOFIXINSTALL_PATH - some patches (wolk for example) dont like INSTALL_PATH
+# being fixed prior to patching. therefore having this
+# option set disables the command to change this.
+# K_NOSETEXTRAVERSION - if this is set then EXTRAVERSION will not be
+# automatically set within the kernel Makefile
+# K_NOUSENAME - if this is set then EXTRAVERSION will not include the
+# first part of ${PN} in EXTRAVERSION
+# K_PREPATCHED - if the patchset is prepatched (ie: mm-sources,
+# ck-sources, ac-sources) it will use PR (ie: -r5)
+# as the patchset version and not use it as a true
+# package revision
+# K_EXTRAEINFO - this is a new-line seperated list of einfo displays in
+# postinst and can be used to carry additional postinst
+# messages
+# K_EXTRAEWARN - same as K_EXTRAEINFO except ewarn's instead of einfo's
+# H_SUPPORTEDARCH - this should be a space separated list of ARCH's which
+# can be supported by the headers ebuild
+# UNIPATCH_LIST - space delimetered list of patches to be applied to the
+# kernel
+# UNIPATCH_EXCLUDE - an additional var to support exlusion based completely
+# on "<passedstring>*" and not "<passedno#>_*"
+# - this should _NOT_ be used from the ebuild as this is
+# reserved for end users passing excludes from the cli
+# UNIPATCH_DOCS - space delimemeted list of docs to be installed to the
+# doc dir
+# UNIPATCH_STRICTORDER - if this is set places patches into directories of
+# order, so they are applied in the order passed
ECLASS="kernel-2"
INHERITED="$INHERITED $ECLASS"
@@ -46,13 +61,13 @@ SLOT="${KV}"
# Grab kernel version from KV
KV_MAJOR=$(echo ${KV} | cut -d. -f1)
KV_MINOR=$(echo ${KV} | cut -d. -f2)
-KV_PATCH=$(echo ${KV} | cut -d. -f3)
+KV_PATCH=$(echo ${KV} | cut -d. -f3-)
KV_PATCH=${KV_PATCH/[-_]*/}
# set LINUX_HOSTCFLAGS if not already set
[ -z "$LINUX_HOSTCFLAGS" ] && LINUX_HOSTCFLAGS="-Wall -Wstrict-prototypes -Os -fomit-frame-pointer -I${S}/include"
-#Eclass functions only from here onwards ...
+#Eclass functions only from here onwards...
#==============================================================
kernel_is() {
local RESULT
@@ -82,13 +97,14 @@ kernel_is_2_4() {
}
kernel_is_2_6() {
- [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -eq 5 -o ${KV_MINOR} -eq 6 ] && return 0 || return 1
+ [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -eq 5 -o ${KV_MINOR} -eq 6 ] && \
+ return 0 || return 1
}
# Capture the sources type and set DEPENDs
if [ "${ETYPE}" == "sources" ]
then
- #console-tools is needed to solve the loadkeys fiasco; binutils version needed to avoid Athlon/PIII/SSE assembler bugs.
+ # binutils version needed to avoid Athlon/PIII/SSE assembler bugs.
DEPEND="!build? ( sys-apps/sed
>=sys-devel/binutils-2.11.90.0.31 )
doc? ( !arm? ( !s390? ( app-text/docbook-sgml-utils ) ) )"
@@ -99,7 +115,9 @@ then
sys-apps/module-init-tools
sys-devel/make )"
- [ $(kernel_is_2_4) $? == 0 ] && PROVIDE="virtual/linux-sources" || PROVIDE="virtual/linux-sources virtual/alsa"
+ [ $(kernel_is_2_4) $? == 0 ] && \
+ PROVIDE="virtual/linux-sources" || \
+ PROVIDE="virtual/linux-sources virtual/alsa"
elif [ "${ETYPE}" == "headers" ]
then
@@ -127,15 +145,14 @@ universal_unpack() {
unpack linux-${OKV}.tar.bz2
if [ "${OKV}" != "${KV}" ]
then
- mv linux-${OKV} linux-${KV} || die "Unable to move source tree to ${KV}."
+ mv linux-${OKV} linux-${KV} || \
+ die "Unable to move source tree to ${KV}."
fi
cd ${S}
# change incorrect install path
- mv Makefile Makefile.orig
- sed -e 's:#export\tINSTALL_PATH:export\tINSTALL_PATH:' \
- Makefile.orig > Makefile
- rm Makefile.orig
+ [ -z "${K_NOFIXINSTALL_PATH}" ] && \
+ sed -i -e 's:#export\tINSTALL_PATH:export\tINSTALL_PATH:' Makefile
# remove all backup files
find . -iname "*~" -exec rm {} \; 2> /dev/null
@@ -143,19 +160,14 @@ universal_unpack() {
if [ -d "${S}/Documentation/DocBook" ]
then
cd ${S}/Documentation/DocBook
- sed -e "s:db2:docbook2:g" Makefile > Makefile.new \
- && mv Makefile.new Makefile
+ sed -i -e "s:db2:docbook2:g" Makefile
cd ${S}
fi
}
unpack_set_extraversion() {
- # Gentoo Linux uses /boot, so fix 'make install' to work properly and fix EXTRAVERSION
cd ${S}
- mv Makefile Makefile.orig
- sed -e "s:^\(EXTRAVERSION =\).*:\1 ${EXTRAVERSION}:" \
- Makefile.orig > Makefile
- rm Makefile.orig
+ sed -i -e "s:^\(EXTRAVERSION =\).*:\1 ${EXTRAVERSION}:" Makefile
}
# Compile Functions
@@ -173,7 +185,7 @@ compile_headers() {
compile_manpages() {
local MY_ARCH
- einfo "Making manpages ..."
+ einfo "Making manpages..."
MY_ARCH=${ARCH}
unset ARCH
make mandocs
@@ -215,16 +227,16 @@ install_sources() {
cd ${S}
dodir /usr/src
- echo ">>> Copying sources ..."
+ echo ">>> Copying sources..."
file="$(find ${WORKDIR} -iname "docs" -type d)"
if [ -n "${file}" ]
then
for file in $(find ${file} -type f)
do
echo "${file/*docs\//}" >> ${S}/patches.txt
- echo "===================================================" >> ${S}/patches.txt
+ echo "=========================================" >> ${S}/patches.txt
cat ${file} >> ${S}/patches.txt
- echo "===================================================" >> ${S}/patches.txt
+ echo "=========================================" >> ${S}/patches.txt
echo "" >> ${S}/patches.txt
done
fi
@@ -232,7 +244,9 @@ install_sources() {
if [ ! -f ${S}/patches.txt ]
then
# patches.txt is empty so lets use our ChangeLog
- [ -f ${FILESDIR}/../ChangeLog ] && echo "Please check the ebuild ChangeLog for more details." > ${S}/patches.txt
+ [ -f ${FILESDIR}/../ChangeLog ] && \
+ echo "Please check the ebuild ChangeLog for more details." \
+ > ${S}/patches.txt
fi
for doc in ${UNIPATCH_DOCS}
@@ -304,8 +318,8 @@ postinst_sources() {
echo
fi
- # Show policy version, if this kernel has SELinux ...
- local secfile="${ROOT}usr/src/linux-${KV}/security/selinux/include/security.h"
+ # Show policy version, if this kernel has SELinux...
+ local secfile="${ROOT}usr/src/linux-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}/security/selinux/include/security.h"
if use selinux && [ -f "$secfile" ]
then
local polver=$(awk '/POLICYDB_VERSION /{print $3}' $secfile)
@@ -340,7 +354,9 @@ postinst_headers() {
# pkg_setup functions
#==============================================================
setup_headers() {
- ARCH=$(uname -m | sed -e s/[i].86/i386/ -e s/x86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/amd64/x86_64/)
+ ARCH=$(uname -m | sed -e s/[i].86/i386/ -e s/x86/i386/ \
+ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ \
+ -e s/amd64/x86_64/)
[ "$ARCH" == "sparc" -a "$PROFILE_ARCH" == "sparc64" ] && ARCH="sparc64"
[ -z "${H_SUPPORTEDARCH}" ] && H_SUPPORTEDARCH="${PN/-*/}"
@@ -379,12 +395,10 @@ unipatch() {
# We're gonna need it when doing patches with a predefined patchlevel
shopt -s extglob
- # This function will unpack all passed tarballs, add any passed patches, and remove any passed patchnumbers
+ # This function will unpack all passed tarballs, add any passed patches,
+ # and remove any passed patchnumbers
# usage can be either via an env var or by params
- # although due to the nature we pass this within this eclass
- # it shall be by param only.
- # -z "${UNIPATCH_LIST}" ] && UNIPATCH_LIST="${@}"
- UNIPATCH_LIST="${@}"
+ [ -n "${@}" ] && UNIPATCH_LIST="${@} ${UNIPATCH_LIST}"
#unpack any passed tarballs
for i in ${UNIPATCH_LIST}
@@ -406,7 +420,8 @@ unipatch() {
then
STRICT_COUNT=$((${STRICT_COUNT} + 1))
mkdir -p ${KPATCH_DIR}/${STRICT_COUNT}/
- ${PIPE_CMD} ${i/:*/} -C ${KPATCH_DIR}/${STRICT_COUNT}/ 1>/dev/null
+ ${PIPE_CMD} ${i/:*/} -C ${KPATCH_DIR}/${STRICT_COUNT}/ \
+ 1>/dev/null
else
${PIPE_CMD} ${i/:*/} -C ${KPATCH_DIR} 1>/dev/null
fi
@@ -414,7 +429,8 @@ unipatch() {
if [ $? == 0 ]
then
einfo "${i/*\//} unpacked"
- [ -n "$(echo ${i} | grep ':')" ] && echo ">>> Strict patch levels not currently supported for tarballed patchsets"
+ [ -n "$(echo ${i} | grep ':')" ] && \
+ echo ">>> Strict patch levels not currently supported for tarballed patchsets"
else
eerror "Failed to unpack ${i/:*/}"
die "unable to unpack patch tarball"
@@ -444,8 +460,8 @@ unipatch() {
echo
eerror "FATAL: unable to locate:"
eerror "${i}"
- eerror "for read-only. The file either has incorrect permissions"
- eerror "or does not exist."
+ eerror "for read-only. The file either has incorrect"
+ eerror "permissions or does not exist."
die Unable to locate ${i}
fi
@@ -453,7 +469,8 @@ unipatch() {
then
STRICT_COUNT=$((${STRICT_COUNT} + 1))
mkdir -p ${KPATCH_DIR}/${STRICT_COUNT}/
- $(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${STRICT_COUNT}/${x}.patch${PATCH_LEVEL})
+ $(${PIPE_CMD} ${i} > \
+ ${KPATCH_DIR}/${STRICT_COUNT}/${x}.patch${PATCH_LEVEL})
else
$(${PIPE_CMD} ${i} > ${KPATCH_DIR}/${x}.patch${PATCH_LEVEL})
fi
@@ -474,26 +491,26 @@ unipatch() {
UNIPATCH_DROP="${UNIPATCH_EXCLUDE} ${UNIPATCH_DROP}"
for i in ${UNIPATCH_DROP}
do
+ einfo "Excluding Patch #${i}"
for x in ${KPATCH_DIR}
do
rm -f ${x}/${i}* 2>/dev/null
- if [ $? == 0 ]
- then
- einfo "Excluding Patch #${i}"
- einfo "From: ${x/${WORKDIR}/}"
- fi
done
done
# and now, finally, we patch it :)
for x in ${KPATCH_DIR}
do
- for i in $(find ${x} -maxdepth 1 -iname "*.patch*" -or -iname "*.diff" | sort -n)
+ for i in $(find ${x} -maxdepth 1 -iname "*.patch*" -or -iname "*.diff*" | sort -n)
do
+ unset PATCH_DEPTH
+
STDERR_T="${T}/${i/*\//}"
STDERR_T="${STDERR_T/.patch*/.err}"
+ STDERR_T="${STDERR_T/.diff*/.err}"
- PATCH_DEPTH=${i/*.patch/}
+ [ -z ${i/*.patch*/} ] && PATCH_DEPTH=${i/*.patch/}
+ [ -z ${i/*.diff*/} ] && PATCH_DEPTH=${i/*.diff/}
if [ -z "${PATCH_DEPTH}" ]; then
PATCH_DEPTH=0
@@ -504,12 +521,12 @@ unipatch() {
do
echo "Attempting Dry-run:" >> ${STDERR_T}
echo "cmd: patch -p${PATCH_DEPTH} --dry-run -f < ${i}" >> ${STDERR_T}
- echo "=======================================================" >> ${STDERR_T}
+ echo "==========================================" >> ${STDERR_T}
if [ $(patch -p${PATCH_DEPTH} --dry-run -f < ${i} >> ${STDERR_T}) $? -eq 0 ]
then
echo "Attempting patch:" > ${STDERR_T}
echo "cmd: patch -p${PATCH_DEPTH} -f < ${i}" >> ${STDERR_T}
- echo "=======================================================" >> ${STDERR_T}
+ echo "======================================" >> ${STDERR_T}
if [ $(patch -p${PATCH_DEPTH} -f < ${i} >> ${STDERR_T}) "$?" -eq 0 ]
then
eend 0
@@ -518,7 +535,7 @@ unipatch() {
else
eend 1
eerror "Failed to apply patch ${i/*\//}"
- eerror "Please attach ${STDERR_T} to any bug you may post."
+ eerror "Please attach ${STDERR_T} to any bug you post."
die "Failed to apply ${i/*\//}"
fi
else
@@ -528,7 +545,7 @@ unipatch() {
if [ ${PATCH_DEPTH} -eq 5 ]
then
eend 1
- eerror "Please attach ${STDERR_T} to any bug you may post."
+ eerror "Please attach ${STDERR_T} to any bug you post."
die "Unable to dry-run patch."
fi
done
@@ -546,19 +563,22 @@ unipatch() {
#==============================================================
detect_version() {
# this function will detect and set
- # - OKV: Original Kernel Version (2.6.0/2.6.0-test11)
- # - KV: Kernel Version (2.6.0-gentoo/2.6.0-test11-gentoo-r1)
- # - EXTRAVERSION: The additional version appended to OKV (-gentoo/-gentoo-r1)
+ # OKV: Original Kernel Version (2.6.0/2.6.0-test11)
+ # KV: Kernel Version (2.6.0-gentoo/2.6.0-test11-gentoo-r1)
+ # EXTRAVERSION: The additional version appended to OKV (-gentoo/-gentoo-r1)
- OKV=${PV/_beta/-test}
- OKV=${OKV/_rc/-rc}
- OKV=${OKV/_pre*/}
- OKV=${OKV/-r*/}
+ if [ -z "${OKV}" ]
+ then
+ OKV=${PV/_beta/-test}
+ OKV=${OKV/_rc/-rc}
+ OKV=${OKV/_pre*/}
+ OKV=${OKV/-r*/}
+ fi
KV_MAJOR=$(echo ${OKV} | cut -d. -f1)
KV_MINOR=$(echo ${OKV} | cut -d. -f2)
KV_PATCH=$(echo ${OKV} | cut -d. -f3)
- KV_PATCH=${KV_PATCH/[-_]*/}
+ KV_PATCH=${KV_PATCH/[-_]*/}
KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
@@ -569,29 +589,31 @@ detect_version() {
then
RELEASE=${RELEASE/_pre/-pre}
else
- RELEASE=${RELEASE/_pre/-bk}
+ RELEASE=${RELEASE/_pre/-bk}
fi
RELEASETYPE=${RELEASE//[0-9]/}
EXTRAVERSION="${RELEASE}"
-
+
if [ -n "${K_PREPATCHED}" ]
then
EXTRAVERSION="${EXTRAVERSION}-${PN/-*/}${PR/r/}"
else
[ -z "${K_NOUSENAME}" ] && EXTRAVERSION="${EXTRAVERSION}-${PN/-*/}"
+ [ "${PN/-*/}" == "wolk" ] && EXTRAVERSION="-${PN/-*/}-${PV}"
[ "${PR}" != "r0" ] && EXTRAVERSION="${EXTRAVERSION}-${PR}"
fi
-
+
KV=${OKV}${EXTRAVERSION}
-
- # -rcXX-bkXX pulls are *IMPOSSIBLE* to support within the portage naming convention
- # these cannot be supported, but the code here can handle it up until this point
- # and theoretically thereafter.
+
+ # -rcXX-bkXX pulls are *IMPOSSIBLE* to support within the
+ # portage naming convention these cannot be supported, but the code here can
+ # handle it up until this point and theoretically thereafter.
if [ "${RELEASETYPE}" == "-rc" -o "${RELEASETYPE}" == "-pre" ]
then
- OKV="${KV_MAJOR}.${KV_MINOR}.$([ $((${KV_PATCH} - 1)) -lt 0 ] && echo ${KV_PATCH} || echo $((${KV_PATCH} - 1)))"
+ OKV="${KV_MAJOR}.${KV_MINOR}.$([ $((${KV_PATCH} - 1)) -lt 0 ] && \
+ echo ${KV_PATCH} || echo $((${KV_PATCH} - 1)))"
KERNEL_URI="mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/testing/patch-${PV//_/-}.bz2
mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/linux-${OKV}.tar.bz2"
UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${PV//_/-}.bz2"
@@ -617,7 +639,7 @@ detect_version() {
UNIPATCH_LIST_DEFAULT="${DISTDIR}/patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${RELEASE}.bz2"
KV=${PV/[-_]*/}${EXTRAVERSION}
fi
-
+
S=${WORKDIR}/linux-${KV}
}
@@ -644,9 +666,10 @@ detect_arch() {
COMPAT_URI="${LOOP_ARCH}_URI"
COMPAT_URI="${!COMPAT_URI}"
- [ -n "${COMPAT_URI}" ] && ARCH_URI="${ARCH_URI} $(echo ${LOOP_ARCH} | tr '[:upper:]' '[:lower:]')? ( ${COMPAT_URI} )"
+ [ -n "${COMPAT_URI}" ] && \
+ ARCH_URI="${ARCH_URI} $(echo ${LOOP_ARCH} | tr [A-Z] [a-z])? ( ${COMPAT_URI} )"
- if [ "${LOOP_ARCH}" == "$(echo ${ARCH} | tr '[:lower:]' '[:upper:]')" ]
+ if [ "${LOOP_ARCH}" == "$(echo ${ARCH} | tr [a-z] [A-Z])" ]
then
for i in ${COMPAT_URI}
do
@@ -661,14 +684,16 @@ detect_arch() {
#==============================================================
kernel-2_src_unpack() {
universal_unpack
- [ -n "${UNIPATCH_LIST}" -o -n "${UNIPATCH_LIST_DEFAULT}" ] && unipatch "${UNIPATCH_LIST_DEFAULT} ${UNIPATCH_LIST}"
+ [ -n "${UNIPATCH_LIST}" -o -n "${UNIPATCH_LIST_DEFAULT}" ] && \
+ unipatch "${UNIPATCH_LIST_DEFAULT}"
[ -z "${K_NOSETEXTRAVERSION}" ] && unpack_set_extraversion
[ $(kernel_is_2_4) $? == 0 ] && unpack_2_4
}
kernel-2_src_compile() {
[ "${ETYPE}" == "headers" ] && compile_headers
- [ "${ETYPE}" == "sources" ] && use doc && ! use arm && ! use s390 && compile_manpages
+ [ "${ETYPE}" == "sources" ] && \
+ use doc && ! use arm && ! use s390 && compile_manpages
}
kernel-2_pkg_preinst() {
@@ -690,5 +715,5 @@ kernel-2_pkg_setup() {
[ "${ETYPE}" == "headers" ] && setup_headers
# This is to fix some weird portage bug? in stable versions of portage.
- [ "${ETYPE}" == "sources" ] && echo ">>> Preparing to unpack ..."
+ [ "${ETYPE}" == "sources" ] && echo ">>> Preparing to unpack..."
}
diff --git a/eclass/linux-info.eclass b/eclass/linux-info.eclass
new file mode 100644
index 000000000000..5d2beacaf5c1
--- /dev/null
+++ b/eclass/linux-info.eclass
@@ -0,0 +1,256 @@
+# Copyright 1999-2004 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/eclass/linux-info.eclass,v 1.1 2004/11/24 16:36:38 johnm Exp $
+#
+# This eclass provides functions for querying the installed kernel
+# source version, selected kernel options etc.
+#
+
+ECLASS=linux-info
+INHERITED="$INHERITED $ECLASS"
+
+# Overwritable environment Var's
+# ---------------------------------------
+KERNEL_DIR="${KERNEL_DIR:-/usr/src/linux}"
+
+
+
+# File Functions
+# ---------------------------------------
+
+# getfilevar accepts 2 vars as follows:
+# getfilevar <VARIABLE> <CONFIGFILE>
+
+getfilevar() {
+local ERROR
+ ERROR=0
+
+ [ -z "${1}" ] && ERROR=1
+ [ -z "${2}" ] && ERROR=1
+ [ ! -f "${2}" ] && ERROR=1
+
+ if [ "${ERROR}" = 1 ]
+ then
+ eerror "getfilevar requires 2 variables, with the second a valid file."
+ eerror " getfilevar <VARIABLE> <CONFIGFILE>"
+ else
+ grep -e "^$1" $2 | sed 's: = :=:' | cut -d= -f2-
+ fi
+}
+
+getfilevar_isset() {
+local RESULT
+ RESULT="$(getfilevar ${1} ${2})"
+ [ "${RESULT}" = "m" -o "${RESULT}" = "y" ] && return 0 || return 1
+}
+
+getfilevar_ismodule() {
+local RESULT
+ RESULT="$(getfilevar ${1} ${2})"
+ [ "${RESULT}" = "m" ] && return 0 || return 1
+}
+
+getfilevar_isbuiltin() {
+local RESULT
+ RESULT="$(getfilevar ${1} ${2})"
+ [ "${RESULT}" = "y" ] && return 0 || return 1
+}
+
+# Versioning Functions
+# ---------------------------------------
+
+# kernel_is returns true when the version is the same as the passed version
+#
+# For Example where KV = 2.6.9
+# kernel_is 2 4 returns false
+# kernel_is 2 returns true
+# kernel_is 2 6 returns true
+# kernel_is 2 6 8 returns false
+# kernel_is 2 6 9 returns true
+#
+# got the jist yet?
+
+kernel_is() {
+ # if we haven't determined the version yet, we need too.
+ get_version;
+
+ local RESULT
+ RESULT=1
+
+ if [ -n "${1}" ]
+ then
+ [ "${1}" = "${KV_MAJOR}" ] && RESULT=0
+ fi
+
+ if [ -n "${2}" ]
+ then
+ RESULT=1
+ [ "${2}" = "${KV_MINOR}" ] && RESULT=0
+ fi
+
+ if [ -n "${3}" ]
+ then
+ RESULT=1
+ [ "${3}" = "${KV_PATCH}" ] && RESULT=0
+ fi
+ return ${RESULT}
+}
+
+get_version() {
+ # no need to execute this twice assuming KV_FULL is populated.
+ # we can force by unsetting KV_FULL
+ if [ -n "${KV_FULL}" ]
+ then
+ # Lets keep this quiet eh?
+ # einfo "\${KV_FULL} is already set. Not running get_version again"
+ return
+ fi
+
+ # if we dont know KV_FULL, then we need too.
+ # make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR
+ unset KV_DIR
+
+ # KV_DIR will contain the full path to the sources directory we should use
+ einfo "Determining the location of the kernel source code"
+ [ -h "${KERNEL_DIR}" ] && KV_DIR="$(readlink -f ${KERNEL_DIR})"
+ [ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}"
+
+ if [ -z "${KV_DIR}" ]
+ then
+ eerror "Unable to find kernel sources at ${KERNEL_DIR}"
+ die
+ fi
+
+ # And contrary to existing functions I feel we shouldn't trust the
+ # directory name to find version information as this seems insane.
+ # so we parse ${KV_DIR}/Makefile
+ KV_MAJOR="$(getfilevar VERSION ${KV_DIR}/Makefile)"
+ KV_MINOR="$(getfilevar PATCHLEVEL ${KV_DIR}/Makefile)"
+ KV_PATCH="$(getfilevar SUBLEVEL ${KV_DIR}/Makefile)"
+ KV_EXTRA="$(getfilevar EXTRAVERSION ${KV_DIR}/Makefile)"
+ # and in newer versions we can also pull LOCALVERSION if it is set.
+ KV_LOCAL="$(cat ${KV_DIR}/localversion* 2>/dev/null)$(getfilevar CONFIG_LOCALVERSION ${KV_DIR}/.config | sed 's:"::g')"
+
+ # And we should set KV_FULL to the full expanded version
+ KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}"
+
+ if [ -z "${KV_FULL}" ]
+ then
+ eerror "We are unable to find a usable kernel source tree in ${KV_DIR}"
+ eerror "Please check a kernel source exists in this directory."
+ die
+ else
+ einfo "Found kernel source directory:"
+ einfo " ${KV_DIR}"
+ einfo "with sources for kernel version:"
+ einfo " ${KV_FULL}"
+ fi
+}
+
+
+
+
+# ebuild check functions
+# ---------------------------------------
+
+check_kernel_built() {
+ # if we haven't determined the version yet, we need too.
+ get_version;
+
+ if [ ! -f "${KV_DIR}/System.map" ]
+ then
+ eerror "These sources have not yet been compiled."
+ eerror "We cannot build against an uncompiled tree."
+ eerror "To resolve this, please type the following:"
+ eerror
+ eerror "# cd ${KV_DIR}"
+ eerror "# make oldconfig"
+ eerror "# make bzImage modules modules_install"
+ eerror
+ eerror "Then please try merging this module again."
+ die "Kernel sources need compiling first"
+ fi
+}
+
+check_modules_supported() {
+ # if we haven't determined the version yet, we need too.
+ get_version;
+
+ getfilevar_isset CONFIG_MODULES ${KV_DIR}/.config
+ if [ "$?" != 0 ]
+ then
+ eerror "These sources do not support loading external modules."
+ eerror "to be able to use this module please enable \"Loadable modules support\""
+ eerror "in your kernel, recompile and then try merging this module again."
+ fi
+}
+
+check_zlibinflate() {
+ # if we haven't determined the version yet, we need too.
+ get_version;
+
+ # although I restructured this code - I really really really dont support it!
+
+ # bug #27882 - zlib routines are only linked into the kernel
+ # if something compiled into the kernel calls them
+ #
+ # plus, for the cloop module, it appears that there's no way
+ # to get cloop.o to include a static zlib if CONFIG_MODVERSIONS
+ # is on
+
+local INFLATE
+local DEFLATE
+
+ einfo "Determining the usability of ZLIB_INFLATE support in your kernel"
+
+ ebegin "checking ZLIB_INFLATE"
+ getfilevar_isbuiltin CONFIG_ZLIB_INFLATE ${KV_DIR}/.config
+ eend $?
+ [ "$?" != 0 ] && die
+
+ ebegin "checking ZLIB_DEFLATE"
+ getfilevar_isbuiltin CONFIG_ZLIB_DEFLATE ${KV_DIR}/.config
+ eend $?
+ [ "$?" != 0 ] && die
+
+
+ local LINENO_START
+ local LINENO_END
+ local SYMBOLS
+ local x
+
+ LINENO_END="$(grep -n 'CONFIG_ZLIB_INFLATE y' ${KV_DIR}/lib/Config.in | cut -d : -f 1)"
+ LINENO_START="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | grep -n 'if \[' | tail -n 1 | cut -d : -f 1)"
+ (( LINENO_AMOUNT = $LINENO_END - $LINENO_START ))
+ (( LINENO_END = $LINENO_END - 1 ))
+ SYMBOLS="$(head -n $LINENO_END ${KERNEL_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;')"
+
+ # okay, now we have a list of symbols
+ # we need to check each one in turn, to see whether it is set or not
+ for x in $SYMBOLS ; do
+ if [ "${!x}" = "y" ]; then
+ # we have a winner!
+ einfo "${x} ensures zlib is linked into your kernel - excellent"
+ return 0
+ fi
+ done
+
+ eerror
+ eerror "This kernel module requires ZLIB library support."
+ eerror "You have enabled zlib support in your kernel, but haven't enabled"
+ eerror "enabled any option that will ensure that zlib is linked into your"
+ eerror "kernel."
+ eerror
+ eerror "Please ensure that you enable at least one of these options:"
+ eerror
+
+ for x in $SYMBOLS ; do
+ eerror " * $x"
+ done
+
+ eerror
+ eerror "Please remember to recompile and install your kernel, and reboot"
+ eerror "into your new kernel before attempting to load this kernel module."
+
+ die "Kernel doesn't include zlib support"
+}
diff --git a/eclass/linux-mod.eclass b/eclass/linux-mod.eclass
new file mode 100644
index 000000000000..86219a36d9c8
--- /dev/null
+++ b/eclass/linux-mod.eclass
@@ -0,0 +1,154 @@
+# Copyright 1999-2004 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/eclass/linux-mod.eclass,v 1.1 2004/11/24 16:36:38 johnm Exp $
+
+# This eclass provides functions for compiling external kernel modules
+# from source.
+
+inherit linux-info
+ECLASS=linux-mod
+INHERITED="$INHERITED $ECLASS"
+EXPORT_FUNCTIONS pkg_setup pkg_postinst src_compile
+
+DESCRIPTION="Based on the $ECLASS eclass"
+SLOT=0
+DEPEND="virtual/linux-sources
+ sys-apps/sed"
+
+
+
+
+# This eclass is designed to help ease the installation of external kernel
+# modules into the kernel tree.
+
+
+# eclass utilities
+# ----------------------------------
+
+use_m() {
+ # if we haven't determined the version yet, we need too.
+ get_version;
+
+ # if the kernel version is greater than 2.6.6 then we should use
+ # M= instead of SUBDIR=
+ [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \
+ return 0 || return 1
+}
+
+convert_to_m() {
+ [ ! -f "${1}" ] && die "convert_to_m() requires a filename as an argument"
+ if use_m
+ then
+ ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIR="
+ sed -i 's:SUBDIRS=:M=:g' ${1}
+ eend $?
+ fi
+}
+
+update_depmod() {
+ # if we haven't determined the version yet, we need too.
+ get_version;
+
+ ebegin "Updating module dependencies for ${KV_FULL}"
+ if [ -r ${KV_DIR}/System.map ]
+ then
+ depmod -ae -F ${KV_DIR}/System.map -b ${ROOT} -r ${KV_FULL}
+ else
+ ewarn
+ ewarn "${KV_DIR}/System.map not found."
+ ewarn "You must manually update the kernel module dependencies using depmod."
+ ewarn
+ fi
+ eend $?
+}
+
+set_kvobj() {
+ if kernel_is 2 6
+ then
+ KV_OBJ="ko"
+ else
+ KV_OBJ="o"
+ fi
+ einfo "Using KV_OBJ=${KV_OBJ}"
+}
+
+display_postinst() {
+ # if we haven't determined the version yet, we need too.
+ get_version;
+
+ local modulename moduledir sourcedir module_temp file i
+
+ file=${ROOT}/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}
+ file=${file/\/\///}
+
+ einfo "If you would like to load this module automatically upon boot"
+ einfo "please type the following as root:"
+ for i in ${MODULE_NAMES}
+ do
+ module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")"
+ modulename="${i/(*/}"
+ moduledir="${module_temp/:*/}"
+ moduledir="${moduledir:-misc}"
+ sourcedir="${module_temp/*:/}"
+ sourcedir="${sourcedir:-${S}}"
+
+ einfo " # echo \"${modulename}\" >> ${file}"
+ done
+ echo
+}
+
+# default ebuild functions
+# --------------------------------
+
+linux-mod_pkg_setup() {
+ get_version;
+ check_kernel_built
+ check_modules_supported;
+ set_kvobj;
+}
+
+linux-mod_src_compile() {
+ local modulename moduledir sourcedir module_temp xarch i
+ xarch="${ARCH}"
+ unset ARCH
+
+ for i in ${MODULE_NAMES}
+ do
+ module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")"
+ modulename="${i/(*/}"
+ moduledir="${module_temp/:*/}"
+ moduledir="${moduledir:-misc}"
+ sourcedir="${module_temp/*:/}"
+ sourcedir="${sourcedir:-${S}}"
+
+ einfo "Preparing ${modulename} module"
+ cd ${sourcedir}
+ make clean
+ make ${BUILD_PARAMS} module
+ done
+ ARCH="${xarch}"
+}
+
+linux-mod_src_install() {
+ local modulename moduledir sourcedir module_temp i
+
+ for i in "${MODULE_NAMES}"
+ do
+ module_temp="$(echo ${i} | sed -e "s:.*(\(.*\)):\1:")"
+ modulename="${i/(*/}"
+ moduledir="${module_temp/:*/}"
+ moduledir="${moduledir:-misc}"
+ sourcedir="${module_temp/*:/}"
+ sourcedir="${sourcedir:-${S}}"
+
+ einfo "Installing ${modulename} module"
+ cd ${sourcedir}
+ insinto /lib/modules/${KV_FULL}/${moduledir}
+ doins ${modulename}.${KV_OBJ}
+ done
+}
+
+linux-mod_pkg_postinst() {
+ update_depmod;
+ display_postinst;
+}