From 9d198f1ea4658f0a4d970e2f12564a8efb5a1a04 Mon Sep 17 00:00:00 2001 From: Robert Yang Date: Sat, 29 Sep 2018 20:37:22 -0400 Subject: [PATCH] Clean kernel source directory before setting up make alias When kbuild is using a separate directory for output files then it will check if the kernel source directory is clean. The build will throw an error when the source directory is not clean: .. is not clean, please run 'make mrproper' Once envkernel.sh has aliased the make command then make mrproper will be run in the context of .output directory. If the source directory is not clean then user may be wondering why make mrproper doesn't clean it. This change will ensure that the source directory is clean when envkernel is setup. --- helpers/envkernel.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/helpers/envkernel.sh b/helpers/envkernel.sh index 595e328b..a74952df 100644 --- a/helpers/envkernel.sh +++ b/helpers/envkernel.sh @@ -13,6 +13,30 @@ check_kernel_folder() { } +clean_kernel_src_dir() { + + if [ -f ".config" ] || [ -d "include/config" ]; then + echo "Source directory is not clean, running 'make mrproper'." + + tmp_dir="" + if [ -d ".output" ]; then + echo " * Preserving existing build output." + tmp_dir=$(mktemp -d) + sudo mv ".output" "$tmp_dir" + fi; + + # backslash is prefixed to disable the alias + # shellcheck disable=SC1001 + \make mrproper + + if [ ! -z "$tmp_dir" ]; then + sudo mv "$tmp_dir/.output" ".output" + sudo rmdir "$tmp_dir" + fi; + fi; +} + + export_pmbootstrap_dir() { # Get pmbootstrap dir based on this script's location # See also: @@ -144,6 +168,7 @@ main() { # Stop executing once a function fails # shellcheck disable=SC1090 if check_kernel_folder \ + && clean_kernel_src_dir \ && export_pmbootstrap_dir "$1" \ && set_alias_pmbootstrap \ && export_chroot_device_deviceinfo \