dotfiles/.local/bin/build-anykernel.sh

205 lines
4.1 KiB
Bash
Raw Normal View History

#!/bin/bash
#
# Build Script for RenderZenith!
# Based off AK's build script - Thanks!
#
# Bash Color
rm .version
green='\033[01;32m'
red='\033[01;31m'
blink_red='\033[05;31m'
restore='\033[0m'
clear
# Resources
THREAD="-j$(grep -c ^processor /proc/cpuinfo)"
KERNEL="Image.gz"
export DEFCONFIG="oneplus6_defconfig"
# Kernel Details
VER=RenderZenith
DEVICE=OP6
VARIANT="OP6-Q-UNIFIED"
# Kernel zip name
HASH=`git rev-parse --short=8 HEAD`
KERNEL_ZIP="RZ-$VARIANT-$(date +%y%m%d)-$HASH"
# Enable ccache per device
CCACHE=ccache
export CCACHE_DIR="$HOME/.ccache/kernel/$DEVICE"
# Vars
export LOCALVERSION=~`echo $VER`
export ARCH=arm64
export SUBARCH=arm64
export KBUILD_BUILD_USER=xstefen
export KBUILD_BUILD_HOST=leviathan
export LOCALVERSION=~`echo $KERNEL_ZIP`
# Extra make arguments
EXTRA_CONFIGS="CONFIG_DEBUG_SECTION_MISMATCH=y"
# Paths
KERNEL_DIR=`pwd`
KBUILD_OUTPUT="${KERNEL_DIR}/out"
REPACK_DIR="${HOME}/android/AnyKernel3"
PATCH_DIR="${HOME}/android/AnyKernel3/patch"
MODULES_DIR="${HOME}/android/AnyKernel3/modules"
ZIP_MOVE="${HOME}/android/zips"
ZIMAGE_DIR="$KBUILD_OUTPUT/arch/arm64/boot"
# Create output directory
mkdir -p $KBUILD_OUTPUT
# Functions
#function checkout_ak3_branches {
# cd $REPACK_DIR
# git checkout rz-op6-oos-q
# cd $KERNEL_DIR
#}
function clean_all {
rm -rf $REPACK_DIR/$MODULES_DIR/*
rm -f $REPACK_DIR/$KERNEL
rm -f $REPACK_DIR/zImage
rm -f $REPACK_DIR/dtb
echo
make O=$KBUILD_OUTPUT clean && make O=$KBUILD_OUTPUT mrproper
}
function make_clang_kernel {
export CROSS_COMPILE="${HOME}/android/toolchains/proton-clang/bin/aarch64-linux-gnu-"
REAL_CC="${HOME}/android/toolchains/proton-clang/bin/clang"
echo
make $DEFCONFIG O=$KBUILD_OUTPUT $EXTRA_CONFIGS
echo
echo "Building with Clang..."
echo
PATH="${HOME}/android/toolchains/proton-clang/bin:${PATH}" \
make $THREAD \
ARCH=$ARCH \
CC="$CCACHE $REAL_CC" \
CROSS_COMPILE="$CROSS_COMPILE" \
O=$KBUILD_OUTPUT \
$EXTRA_CONFIGS
}
function make_gcc_kernel {
export CROSS_COMPILE="${CCACHE} ${HOME}/android/toolchains/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-"
echo
echo "Building with GCC..."
echo
make O=${KBUILD_OUTPUT} $DEFCONFIG
make -s O=${KBUILD_OUTPUT} $THREAD $EXTRA_CONFIGS
}
function make_modules {
# Remove and re-create modules directory
rm -rf $MODULES_DIR
mkdir -p $MODULES_DIR
# Copy modules over
echo
find $KBUILD_OUTPUT -name '*.ko' -exec cp -v {} $MODULES_DIR \;
# Strip modules
${CROSS_COMPILE}strip --strip-unneeded $MODULES_DIR/*.ko
# Sign modules
if grep -Fxq "CONFIG_MODULE_SIG=y" $KBUILD_OUTPUT/.config
then
find $MODULES_DIR -name '*.ko' -exec $KBUILD_OUTPUT/scripts/sign-file sha512 $KBUILD_OUTPUT/certs/signing_key.pem $KBUILD_OUTPUT/certs/signing_key.x509 {} \;
fi
}
function make_zip {
cp -vr $ZIMAGE_DIR/$KERNEL $REPACK_DIR/$KERNEL
find $KBUILD_OUTPUT/arch/arm64/boot/dts -name '*.dtb' -exec cat {} + > $REPACK_DIR/dtb
cd $REPACK_DIR
zip -r9 $KERNEL_ZIP.zip *
mv $KERNEL_ZIP.zip $ZIP_MOVE
cd $KERNEL_DIR
}
DATE_START=$(date +"%s")
echo -e "${green}"
echo "RenderZenith creation script:"
echo -e "${restore}"
while read -p "Do you want to clean stuffs (y/n)? " cchoice
do
case "$cchoice" in
y|Y )
#checkout_ak3_branches
clean_all
echo
echo "All Cleaned now."
break
;;
n|N )
#checkout_ak3_branches
break
;;
* )
echo
echo "Invalid try again!"
echo
;;
esac
done
echo
echo "Pick which toolchain to build with:"
select choice in Clang GCC
do
case "$choice" in
"Clang")
make_clang_kernel
break;;
"GCC")
make_gcc_kernel
break;;
esac
done
while read -p "Do you want to ZIP kernel (y/n)? " dchoice
do
case "$dchoice" in
y|Y)
make_modules
make_zip
break
;;
n|N )
break
;;
* )
echo
echo "Invalid try again!"
echo
;;
esac
done
echo -e "${green}"
echo "-------------------"
echo "Build Completed in:"
echo "-------------------"
echo -e "${restore}"
DATE_END=$(date +"%s")
DIFF=$(($DATE_END - $DATE_START))
echo "Time: $(($DIFF / 60)) minute(s) and $(($DIFF % 60)) seconds."
echo