2023-11-12 02:26:45 -03:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2023-11-12 02:03:52 -03:00
|
|
|
# Compile script for FSociety kernel
|
2023-11-12 02:26:45 -03:00
|
|
|
# Copyright (C) 2020-2021 Adithya R.
|
|
|
|
|
|
|
|
SECONDS=0 # builtin bash timer
|
2023-11-12 02:03:52 -03:00
|
|
|
ZIPNAME="FSociety-surya-$(date '+%Y%m%d-%H%M').zip"
|
2025-02-04 23:41:09 -03:00
|
|
|
TC_DIR="$(pwd)/tc/clang-20"
|
2023-01-08 20:05:49 -03:00
|
|
|
AK3_DIR="$(pwd)/android/AnyKernel3"
|
2023-11-12 02:03:52 -03:00
|
|
|
DEFCONFIG="surya_defconfig"
|
2023-11-12 02:26:45 -03:00
|
|
|
|
|
|
|
if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
|
|
|
|
head=$(git rev-parse --verify HEAD 2>/dev/null); then
|
|
|
|
ZIPNAME="${ZIPNAME::-4}-$(echo $head | cut -c1-8).zip"
|
|
|
|
fi
|
|
|
|
|
|
|
|
export PATH="$TC_DIR/bin:$PATH"
|
|
|
|
|
2024-12-19 00:32:13 -03:00
|
|
|
sync_repo() {
|
|
|
|
local dir=$1
|
|
|
|
local repo_url=$2
|
|
|
|
local branch=$3
|
|
|
|
local update=$4
|
|
|
|
|
|
|
|
if [ -d "$dir" ]; then
|
|
|
|
if $update; then
|
|
|
|
# Fetch the latest changes
|
|
|
|
git -C "$dir" fetch origin --quiet
|
|
|
|
|
|
|
|
# Compare local and remote commits
|
|
|
|
LOCAL_COMMIT=$(git -C "$dir" rev-parse HEAD)
|
|
|
|
REMOTE_COMMIT=$(git -C "$dir" rev-parse "origin/$branch")
|
|
|
|
|
|
|
|
# If there are changes, reset and log the update
|
|
|
|
if [ "$LOCAL_COMMIT" != "$REMOTE_COMMIT" ]; then
|
|
|
|
git -C "$dir" reset --quiet --hard "origin/$branch"
|
|
|
|
LATEST_COMMIT=$(git -C "$dir" log -1 --oneline)
|
|
|
|
echo -e "Updated $repo_url to: $LATEST_COMMIT\n" | tee -a "$dir/updates.txt"
|
|
|
|
else
|
|
|
|
echo "No changes found for $repo_url. Skipping update."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# Clone the repository if it doesn't exist
|
|
|
|
echo "Cloning $repo_url to $dir..."
|
|
|
|
if ! git clone --quiet --depth=1 -b "$branch" "$repo_url" "$dir"; then
|
|
|
|
echo "Cloning failed! Aborting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ $1 = "-u" || $1 = "--update" ]]; then
|
|
|
|
sync_repo $AK3_DIR "https://github.com/rd-stuffs/AnyKernel3.git" "FSociety" true
|
2025-02-04 23:41:09 -03:00
|
|
|
sync_repo $TC_DIR "https://bitbucket.org/rdxzv/clang-standalone.git" "20" true
|
2024-12-19 00:32:13 -03:00
|
|
|
exit
|
|
|
|
else
|
|
|
|
sync_repo $AK3_DIR "https://github.com/rd-stuffs/AnyKernel3.git" "FSociety" false
|
2025-02-04 23:41:09 -03:00
|
|
|
sync_repo $TC_DIR "https://bitbucket.org/rdxzv/clang-standalone.git" "20" false
|
2024-12-19 00:32:13 -03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "$AK3_DIR" ] || [ ! -d "$TC_DIR" ]; then
|
|
|
|
echo "Error: Required directories are missing. Aborting the build process."
|
|
|
|
exit 1
|
2024-06-26 13:59:16 +02:00
|
|
|
fi
|
2024-04-18 20:09:47 -03:00
|
|
|
|
2023-11-12 02:26:45 -03:00
|
|
|
if [[ $1 = "-r" || $1 = "--regen" ]]; then
|
2020-12-24 16:29:31 -08:00
|
|
|
make $DEFCONFIG savedefconfig
|
2023-11-12 02:26:45 -03:00
|
|
|
cp out/defconfig arch/arm64/configs/$DEFCONFIG
|
|
|
|
echo -e "\nSuccessfully regenerated defconfig at $DEFCONFIG"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2023-01-11 15:45:43 -03:00
|
|
|
if [[ $1 = "-rf" || $1 = "--regen-full" ]]; then
|
2020-12-24 16:29:31 -08:00
|
|
|
make $DEFCONFIG
|
2023-01-11 15:45:43 -03:00
|
|
|
cp out/.config arch/arm64/configs/$DEFCONFIG
|
|
|
|
echo -e "\nSuccessfully regenerated full defconfig at $DEFCONFIG"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2024-12-04 01:48:51 -03:00
|
|
|
CLEAN_BUILD=false
|
|
|
|
ENABLE_KSU=false
|
|
|
|
|
|
|
|
for arg in "$@"; do
|
|
|
|
case $arg in
|
|
|
|
-c|--clean)
|
|
|
|
CLEAN_BUILD=true
|
|
|
|
;;
|
|
|
|
-s|--su)
|
|
|
|
ENABLE_KSU=true
|
|
|
|
ZIPNAME="${ZIPNAME/FSociety-surya/FSociety-KSU}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown argument: $arg"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if $CLEAN_BUILD; then
|
|
|
|
echo "Cleaning output directory..."
|
2023-11-12 02:26:45 -03:00
|
|
|
rm -rf out
|
|
|
|
fi
|
|
|
|
|
2024-12-04 01:48:51 -03:00
|
|
|
if $ENABLE_KSU; then
|
|
|
|
echo "Building with KSU support..."
|
|
|
|
KSU_DEFCONFIG="ksu_${DEFCONFIG}"
|
|
|
|
KSU_DEFCONFIG_PATH="arch/arm64/configs/${KSU_DEFCONFIG}"
|
|
|
|
cp arch/arm64/configs/$DEFCONFIG $KSU_DEFCONFIG_PATH
|
|
|
|
sed -i 's/# CONFIG_KSU is not set/CONFIG_KSU=y/g' $KSU_DEFCONFIG_PATH
|
2024-12-13 03:37:45 -03:00
|
|
|
trap '[[ -f $KSU_DEFCONFIG_PATH ]] && rm -f $KSU_DEFCONFIG_PATH' EXIT
|
2024-12-04 01:48:51 -03:00
|
|
|
fi
|
|
|
|
|
2023-11-12 02:26:45 -03:00
|
|
|
echo -e "\nStarting compilation...\n"
|
2024-12-04 01:48:51 -03:00
|
|
|
if $ENABLE_KSU; then
|
|
|
|
make $KSU_DEFCONFIG
|
|
|
|
else
|
|
|
|
make $DEFCONFIG
|
|
|
|
fi
|
2024-07-03 01:33:43 -03:00
|
|
|
make -j$(nproc --all) LLVM=1 Image.gz dtb.img dtbo.img 2> >(tee log.txt >&2) || exit $?
|
2023-11-12 02:26:45 -03:00
|
|
|
|
|
|
|
kernel="out/arch/arm64/boot/Image.gz"
|
2023-11-12 02:43:08 -03:00
|
|
|
dtb="out/arch/arm64/boot/dtb.img"
|
2023-11-12 02:26:45 -03:00
|
|
|
dtbo="out/arch/arm64/boot/dtbo.img"
|
|
|
|
|
|
|
|
if [ -f "$kernel" ] && [ -f "$dtb" ] && [ -f "$dtbo" ]; then
|
2024-12-04 01:48:51 -03:00
|
|
|
echo -e "\nKernel compiled successfully! Zipping up...\n"
|
2024-12-19 00:32:13 -03:00
|
|
|
cp -r $AK3_DIR AnyKernel3
|
2023-11-12 02:43:08 -03:00
|
|
|
cp $kernel $dtb $dtbo AnyKernel3
|
2023-11-12 02:26:45 -03:00
|
|
|
cd AnyKernel3
|
2023-11-12 02:03:52 -03:00
|
|
|
git checkout FSociety &> /dev/null
|
2024-07-04 12:45:34 -03:00
|
|
|
zip -r9 "../$ZIPNAME" * -x .git modules\* patch\* ramdisk\* README.md *placeholder
|
2023-11-12 02:26:45 -03:00
|
|
|
cd ..
|
|
|
|
rm -rf AnyKernel3
|
|
|
|
echo -e "\nCompleted in $((SECONDS / 60)) minute(s) and $((SECONDS % 60)) second(s) !"
|
|
|
|
echo "Zip: $ZIPNAME"
|
|
|
|
else
|
|
|
|
echo -e "\nCompilation failed!"
|
|
|
|
exit 1
|
|
|
|
fi
|