Last active
September 29, 2020 16:53
-
-
Save gyakovlev/bbcedebb0cb4931a926be92970a45d7f to your computer and use it in GitHub Desktop.
/etc/portage/env/sys-kernel/gentoo-kernel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# place this file to /etc/portage/env/sys-kernel/gentoo-kernel | |
# please, pre-fetch zfs tarball, like 'emerge zfs-kmod --fetchonly' | |
# also make sure that $PORTAGE_TMPDIR/portage/sys-fs/zfs-kmod* is not present | |
# simply set to false if not needed | |
: "${__EZFS_KERNEL_BUILTIN:=true}" | |
__ORIG_DISTDIR="${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}" | |
post_src_unpack() { | |
[[ ${__EZFS_KERNEL_BUILTIN} == true ]] || return | |
ebegin "zfs-builtin: hooked by ${BASH_SOURCE[0]} in ${FUNCNAME[0]}" | |
# this will obey keywords/masks, so make sure you have | |
# it in sync with sys-fs/zfs | |
# eg sys-fs/zfs-kmod-0.8.4-r1 | |
best_zfs_kmod="$(portageq best_visible ${EROOT%/}/ zfs-kmod 2>/dev/null)" | |
einfo "zfs-builtin: will embed ${best_zfs_kmod} into linux source" | |
local orig_distdir zsrc_uri zdistfile | |
orig_distdir="${__ORIG_DISTDIR}" | |
zsrc_uri="$(portageq metadata ${EROOT%/}/ ebuild ${best_zfs_kmod} SRC_URI 2>/dev/null)" | |
zdistfile="${zsrc_uri##*/}" # eg zfs-0.8.4.tar.gz | |
# we need to copy it to tmpdir for further use below | |
einfo "zfs-builtin: getting ${zdistfile}" | |
cp -v "${orig_distdir}/${zdistfile}" "${T}" || die | |
eend ${?} | |
} | |
post_src_configure() { | |
[[ ${__EZFS_KERNEL_BUILTIN} == true ]] || return | |
ebegin "zfs-builtin: hooked by ${BASH_SOURCE[0]} in ${FUNCNAME[0]}" | |
local repo zpvr zpv zp | |
repo="$(portageq get_repo_path ${EROOT%/}/ gentoo 2>/dev/null)" # eg /var/db/repos/gentoo | |
zpvr="${best_zfs_kmod#*/}" # eg zfs-kmod-0.8.4-r1 | |
zp="${zpvr%-r*}" # eg zfs-kmod-0.8.4 | |
zpv="${zp#zfs-kmod-}" # eg 0.8.4 | |
zpv="${zpv%_rc*}" # unpacked directories never contain rcX suffix | |
# we want to run this in a subshell to prevent env pollution | |
# it still receives current env and subshell die works in EAPI=7 | |
( | |
pushd "${repo}" > /dev/null || die | |
# turn off some features, since we already sandboxed. | |
# we have to pass DISTDIR here so it can find zfs tarball. | |
FEATURES="-cgroup -ipc-sandbox -mount-sandbox -pid-sandbox" \ | |
KERNEL_DIR="${WORKDIR}/${MY_P}" KBUILD_OUTPUT="${WORKDIR}/modprep" \ | |
DISTDIR="${T}" EXTRA_ECONF="--enable-linux-builtin\ | |
--with-linux="${WORKDIR}/${MY_P}"\ | |
--with-linux-obj="${WORKDIR}"/modprep"\ | |
ebuild sys-fs/zfs-kmod/"${zpvr}".ebuild clean configure || die | |
popd > /dev/null || die | |
pushd "${PORTAGE_TMPDIR}/portage/${best_zfs_kmod}/work/zfs-${zpv}" > /dev/null || die | |
./copy-builtin "${WORKDIR}/${MY_P}" || die | |
popd > /dev/null || die | |
) | |
# end subshell | |
einfo "zfs-builtin: ${zpvr} embedded into ${WORKDIR}/${MY_P}" | |
# we now have to re-run configure phase with zfs enabled, so start clean | |
# this is not really required, but better be safe | |
rm -rf "${WORKDIR}"/build || die | |
emake O="${WORKDIR}"/modprep "${MAKEARGS[@]}" clean | |
emake O="${WORKDIR}"/modprep "${MAKEARGS[@]}" olddefconfig | |
# it may be disabled if not restored from savedconfig | |
einfo "zfs-builtin: enabling CONFIG_ZFS=y in case it's disabled" | |
sed -i 's/# CONFIG_ZFS is not set/CONFIG_ZFS=y/' "${WORKDIR}"/modprep/.config || die | |
emake O="${WORKDIR}"/modprep "${MAKEARGS[@]}" olddefconfig | |
emake O="${WORKDIR}"/modprep "${MAKEARGS[@]}" modules_prepare | |
cp -pR "${WORKDIR}"/modprep "${WORKDIR}"/build || die | |
einfo "zfs-builtin: ZFSification done" | |
eend ${?} | |
} | |
post_src_install() { | |
[[ ${__EZFS_KERNEL_BUILTIN} == true ]] || return | |
ebegin "zfs-builtin: hooked by ${BASH_SOURCE[0]} in ${FUNCNAME[0]}" | |
# now it's safe to delete source | |
# not needed to keep tree with zfs-2*, but does not hurt ether | |
# https://github.com/openzfs/zfs/commit/71504277ae5537007a99864e53a3b5ceb211a660 | |
[[ -d "${PORTAGE_TMPDIR}/portage/${best_zfs_kmod}" ]] &&\ | |
{ rm -rf "${PORTAGE_TMPDIR}/portage/${best_zfs_kmod}" || die ; } | |
einfo "zfs-builtin: ZFS src cleanup done" | |
eend ${?} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment