coreos-kernel: use $S for the build directory instead of source

Most operations are manipulating the build directory, making everything
overly verbose by having to reference $KBUILD_OUTPUT constantly. The
only command that actually needs to run from source directory is `make`.
This commit is contained in:
Michael Marineau 2015-08-04 12:43:19 -07:00
parent cccf38e880
commit 720b14f18b

View File

@ -28,8 +28,6 @@ RESTRICT="binchecks strip"
# Use source installed by coreos-sources # Use source installed by coreos-sources
KERNEL_DIR="${SYSROOT}/usr/src/${COREOS_SOURCE_NAME}" KERNEL_DIR="${SYSROOT}/usr/src/${COREOS_SOURCE_NAME}"
S="${KERNEL_DIR}"
KBUILD_OUTPUT="${WORKDIR}/${P}"
# Search for an apropriate defconfig in ${FILESDIR}. The config should reflect # Search for an apropriate defconfig in ${FILESDIR}. The config should reflect
# the kernel version but partial matching is allowed if the config is # the kernel version but partial matching is allowed if the config is
@ -64,8 +62,7 @@ find_defconfig() {
# As if using cpio isn't bad enough already. # As if using cpio isn't bad enough already.
# If lib doesn't exist or isn't a symlink then nothing is returned. # If lib doesn't exist or isn't a symlink then nothing is returned.
get_bootengine_lib() { get_bootengine_lib() {
local cpio_path="${KBUILD_OUTPUT}/bootengine.cpio" cpio -itv --quiet < bootengine.cpio | \
cpio -itv --quiet < "${cpio_path}" | \
awk '$1 ~ /^l/ && $9 == "lib" { print $11 }' awk '$1 ~ /^l/ && $9 == "lib" { print $11 }'
assert assert
} }
@ -76,17 +73,18 @@ get_bootengine_lib() {
# Allows us to stick kernel modules into the initramfs built into the image. # Allows us to stick kernel modules into the initramfs built into the image.
update_bootengine_cpio() { update_bootengine_cpio() {
local extra_root="$1" local extra_root="$1"
local cpio_path="${KBUILD_OUTPUT}/bootengine.cpio" local cpio_args=(
local cpio_args=(--create --append --null --create --append --null
# dracut uses the 'newc' cpio format # dracut uses the 'newc' cpio format
--format=newc --format=newc
# squash file ownership to root for new files. # squash file ownership to root for new files.
--owner=root:root --owner=root:root
# append to our local copy of bootengine
-F "${S}/bootengine.cpio"
) )
echo "Updating bootengine.cpio" echo "Updating bootengine.cpio"
(cd "${extra_root}" && \ (cd "${extra_root}" && find . -print0 | cpio "${cpio_args[@]}") || \
find . -print0 | cpio "${cpio_args[@]}" -F "${cpio_path}") || \
die "cpio update failed!" die "cpio update failed!"
} }
@ -95,52 +93,52 @@ kmake() {
if gcc-specs-pie; then if gcc-specs-pie; then
kernel_cflags="-nopie -fstack-check=no" kernel_cflags="-nopie -fstack-check=no"
fi fi
emake ARCH="${kernel_arch}" CROSS_COMPILE="${CHOST}-" \ emake -C "${KERNEL_DIR}" \
KCFLAGS="${kernel_cflags}" LDFLAGS="" "$@" ARCH="${kernel_arch}" \
CROSS_COMPILE="${CHOST}-" \
KBUILD_OUTPUT="${S}" \
KCFLAGS="${kernel_cflags}" \
LDFLAGS="" \
"$@"
} }
# Discard the module signing key, we use new keys for each build. # Discard the module signing key, we use new keys for each build.
shred_keys() { shred_keys() {
if [[ -e "${KBUILD_OUTPUT}"/signing_key.priv ]]; then if [[ -e signing_key.priv ]]; then
shred -u "${KBUILD_OUTPUT}"/signing_key.* || die shred -u signing_key.* || die
rm -f "${KBUILD_OUTPUT}"/x509.genkey || die rm -f x509.genkey || die
fi fi
} }
coreos-kernel_src_unpack() { coreos-kernel_src_unpack() {
export KBUILD_OUTPUT mkdir "${S}" || die
mkdir "${KBUILD_OUTPUT}" || die
} }
coreos-kernel_src_prepare() { coreos-kernel_src_prepare() {
if [[ -f ".config" || -d "include/config" ]] if [[ -f ".config" || -d "include/config" ]]
then then
die "Source is not clean! Run make mrproper in ${S}" die "Source is not clean! Run make mrproper in ${KERNEL_DIR}"
fi fi
rm -f "${KBUILD_OUTPUT}/.config" || die restore_config .config
restore_config "${KBUILD_OUTPUT}/.config" if [[ ! -f .config ]]; then
if [[ ! -f "${KBUILD_OUTPUT}/.config" ]]; then
local config="$(find_defconfig)" local config="$(find_defconfig)"
elog "Building using default config ${config}" elog "Building using default config ${config}"
cp "${config}" "${KBUILD_OUTPUT}/.config" || die cp "${config}" .config || die
fi fi
# copy the cpio initrd to the output build directory so we can tack it # copy the cpio initrd to the output build directory so we can tack it
# onto the kernel image itself. # onto the kernel image itself.
cp "${ROOT}"/usr/share/bootengine/bootengine.cpio "${KBUILD_OUTPUT}" || die cp "${ROOT}"/usr/share/bootengine/bootengine.cpio bootengine.cpio || die
} }
coreos-kernel_src_configure() { coreos-kernel_src_configure() {
if ! use audit; then if ! use audit; then
sed -i -e '/^CONFIG_CMDLINE=/s/"$/ audit=0"/' \ sed -i -e '/^CONFIG_CMDLINE=/s/"$/ audit=0"/' .config || die
"${KBUILD_OUTPUT}/.config" || die
fi fi
if ! use selinux; then if ! use selinux; then
sed -i -e '/CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE/d' \ sed -i -e '/CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE/d' .config || die
"${KBUILD_OUTPUT}/.config" || die echo CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE=0 >> .config || die
echo CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE=0 >> \
"${KBUILD_OUTPUT}/.config" || die
fi fi
# Use default for any options not explitly set in defconfig # Use default for any options not explitly set in defconfig
@ -199,7 +197,7 @@ coreos-kernel_src_install() {
dosym "../../../../boot/config-${version}" \ dosym "../../../../boot/config-${version}" \
"/usr/lib/modules/${version}/build/.config" "/usr/lib/modules/${version}/build/.config"
save_config "${KBUILD_OUTPUT}/defconfig" save_config defconfig
shred_keys shred_keys
} }
@ -207,7 +205,7 @@ coreos-kernel_src_install() {
# TODO(marineam): remove this function once KBUILD_OUTPUT is removed # TODO(marineam): remove this function once KBUILD_OUTPUT is removed
# from src/scripts/setup_board # from src/scripts/setup_board
coreos-kernel_pkg_postinst() { coreos-kernel_pkg_postinst() {
local KBUILD_OUTPUT="${SYSROOT}/var/cache/portage/${CATEGORY}/${PN}" [[ -n "${KBUILD_OUTPUT}" ]] || return 0
# linux-info always expects to be able to find the current .config # linux-info always expects to be able to find the current .config
# so copy it into the build tree if it isn't already there. # so copy it into the build tree if it isn't already there.
if ! cmp --quiet "${ROOT}/usr/boot/config" "${KBUILD_OUTPUT}/.config"; then if ! cmp --quiet "${ROOT}/usr/boot/config" "${KBUILD_OUTPUT}/.config"; then