You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-overlay/eclass/calculate-kernel-6.eclass

167 lines
5.1 KiB

# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
#
# Original Author: © 2007-2009 Mir Calculate, Ltd.
# Purpose: Installing linux-desktop, linux-server.
# Build the kernel from source.
inherit calculate eutils kernel-2
EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_postinst
IUSE="vmlinuz minimal"
REQUIRED_USE="minimal? ( vmlinuz )"
RDEPEND="vmlinuz? ( sys-kernel/dracut )"
detect_version
detect_arch
if [[ ${KV_MAJOR} -lt 3 ]]
then
die "Eclass is used only for kernel-3"
fi
SLOT=${PV}
EXTRAVERSION="-${KERNELNAME:calculate}"
KV_FULL="${PV}${EXTRAVERSION}"
S="${WORKDIR}/linux-${KV_FULL}"
calculate-kernel-6_pkg_setup() {
kernel-2_pkg_setup
eqawarn "!!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!"
eqawarn "After the kernel assemble perform command to update modules:"
eqawarn " emerge @modules-rebuild"
}
calculate-kernel-6_src_unpack() {
kernel-2_src_unpack
}
vmlinuz_src_compile() {
# disable sandbox
local GENTOOARCH="${ARCH}"
unset ARCH
cd ${S}
emake olddefconfig || die "kernel configure failed"
emake && emake modules || die "kernel build failed"
[ -f .config ] && cp .config .config.save
ARCH="${GENTOOARCH}"
}
calculate-kernel-6_src_compile() {
use vmlinuz && vmlinuz_src_compile
}
vmlinuz_src_install() {
# dracut change this files in chroot of ramdisk
SANDBOX_WRITE="${SANDBOX_WRITE}:/etc/ld.so.cache~:/etc/ld.so.cache:/etc/mtab"
cd ${S}
dodir /usr/share/${PN}/${PV}/boot
INSTALL_PATH=${D}/usr/share/${PN}/${PV}/boot emake install
INSTALL_MOD_PATH=${D} emake modules_install
/sbin/depmod -b ${D} ${KV_FULL}
/usr/bin/dracut -a calculate -a plymouth -a video -k ${D}/lib/modules/${KV_FULL} \
--kver ${KV_FULL} \
${D}/usr/share/${PN}/${PV}/boot/initramfs-${KV_FULL}
# move firmware to share, because /lib/firmware installation does collisions
mv ${D}/lib/firmware ${D}/usr/share/${PN}/${PV}
insinto /usr/share/${PN}/${PV}/boot/
newins .config config-${KV_FULL}
# recreate symlink in /lib/modules because symlink point to tmp/portage after make install
rm ${D}/lib/modules/${KV_FULL}/build
rm ${D}/lib/modules/${KV_FULL}/source
dosym /usr/src/linux-${KV_FULL} \
"/lib/modules/${KV_FULL}/source" ||
die "cannot install source symlink"
dosym /usr/src/linux-${KV_FULL} \
"/lib/modules/${KV_FULL}/build" ||
die "cannot install build symlink"
}
# FUNCTION: clean_for_minimal
# DESCRIPTION:
# Clear kernel sources, keeping only need for custom modules compilation
clean_for_minimal() {
local GENTOOARCH="${ARCH}"
unset ARCH
ARCH="${GENTOOARCH}"
emake distclean &>/dev/null || die "cannot perform distclean"
mv .config.save .config
ebegin "kernel: >> Running modules_prepare..."
emake modules_prepare &>/dev/null
eend $? "Failed modules prepare"
einfo "Cleaning sources"
for rmpath in $(ls arch | grep -v x86)
do
rm -r arch/$rmpath
done
KEEPLIST="scripts/Makefile.lib scripts/module-common.lds \
scripts/gcc-version.sh scripts/Makefile.help \
scripts/Makefile.modinst scripts/Makefile.asm-generic \
scripts/Makefile.modbuiltin scripts/Makefile.fwinst \
scripts/depmod.sh scripts/Makefile.host \
scripts/Kbuild.include scripts/Makefile.modpost \
scripts/gcc-goto.sh scripts/Makefile.headersinst \
scripts/Makefile.build scripts/basic/fixdep \
scripts/Makefile.clean scripts/mod/modpost \
include/config/kernel.release include/config/auto.conf \
arch/x86/Makefile_32.cpu arch/x86/Makefile \
System.map Makefile Kbuild"
find . -type f -a \! -wholename ./.config \
$(echo $KEEPLIST | sed -r 's/(\S+)(\s|$)/-a \! -wholename .\/\1 /g') \
-a \! -name "*.h" -delete
find . -type l -delete
rm -r drivers
rm -r Documentation
}
calculate-kernel-6_src_install() {
use vmlinuz && vmlinuz_src_install
use minimal && clean_for_minimal
kernel-2_src_install
if ! use vmlinuz
then
cp .config ${D}/usr/share/${PN}/${PV}/boot/config-${KV_FULL}
fi
use vmlinuz && touch ${D}/usr/src/linux-${KV_FULL}/.calculate
}
vmlinuz_pkg_postinst() {
# install kernel into /boot
calculate_update_ver /boot vmlinuz ${KV_FULL} /usr/share/${PN}/${PV}/boot/vmlinuz-${KV_FULL}
calculate_update_ver /boot config ${KV_FULL} /usr/share/${PN}/${PV}/boot/config-${KV_FULL}
calculate_update_ver /boot initramfs ${KV_FULL} /usr/share/${PN}/${PV}/boot/initramfs-${KV_FULL} .img
calculate_update_ver /boot System.map ${KV_FULL} /usr/share/${PN}/${PV}/boot/System.map-${KV_FULL}
# install firmware into /
mkdir -p ${ROOT}/lib/firmware
cp -a ${ROOT}/usr/share/${PN}/${PV}/firmware/* ${ROOT}/lib/firmware/
calculate_update_depmod
calculate_update_modules
}
calculate-kernel-6_pkg_postinst() {
kernel-2_pkg_postinst
KV_OUT_DIR=${ROOT}/usr/src/linux-${KV_FULL}
use vmlinuz && cp -p /usr/share/${PN}/${PV}/boot/System.map* ${KV_OUT_DIR}/System.map
if ! use minimal
then
cd ${KV_OUT_DIR}
local GENTOOARCH="${ARCH}"
unset ARCH
ebegin "kernel: >> Running modules_prepare..."
(emake oldconfig && emake modules_prepare) &>/dev/null
eend $? "Failed modules prepare"
ARCH="${GENTOOARCH}"
fi
use vmlinuz && vmlinuz_pkg_postinst
use vmlinuz && calculate_fix_lib_modules_contents
}