This repository has been archived by the owner on Apr 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sh
executable file
·130 lines (119 loc) · 4.55 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#! /bin/bash
# Setup environment
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
blue='\033[0;34m'
clear='\033[0m'
KERNEL_PATH=$PWD
ARCH=arm64
DEFCONFIG=vendor/lahaina-qgki_defconfig
CLANG_PATH=$KERNEL_PATH/out/clang/clang-r510928
export PATH=$CLANG_PATH/bin:$PATH
KernelSU=false # Enable if you want KernelSU
BUILD_CC="LLVM=1 LLVM_IAS=1 CC=clang LD=ld.lld AR=llvm-ar AS=llvm-as NM=llvm-nm OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump READELF=llvm-readelf OBJSIZE=llvm-objsize STRIP=llvm-strip"
clone_tools() {
cd $KERNEL_PATH
git clone https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86 --depth=1 $KERNEL_PATH/out/clang
git clone https://gitlab.com/inferno0230/AnyKernel3 --depth=1 $KERNEL_PATH/AnyKernel3
}
setup_ksu() {
cd $KERNEL_PATH
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -
grep -q "CONFIG_MODULES=y" "arch/arm64/configs/$DEFCONFIG" || echo "CONFIG_MODULES=y" >> "arch/arm64/configs/$DEFCONFIG"
grep -q "CONFIG_KPROBES=y" "arch/arm64/configs/$DEFCONFIG" || echo "CONFIG_KPROBES=y" >> "arch/arm64/configs/$DEFCONFIG"
grep -q "CONFIG_HAVE_KPROBES=y" "arch/arm64/configs/$DEFCONFIG" || echo "CONFIG_HAVE_KPROBES=y" >> "arch/arm64/configs/$DEFCONFIG"
grep -q "CONFIG_KPROBE_EVENTS=y" "arch/arm64/configs/$DEFCONFIG" || echo "CONFIG_KPROBE_EVENTS=y" >> "arch/arm64/configs/$DEFCONFIG"
}
ArchLinux() {
# Check if yay is installed
if ! command -v yay &> /dev/null
then
echo -e "${red}yay is not installed, please install it first!${clear}"
exit
else
yay -S lineageos-devel aosp-devel zstd tar wget curl base-devel lib32-ncurses lib32-zlib lib32-readline --noconfirm
fi
}
Fedora() {
curl -LSs "https://raw.githubusercontent.com/akhilnarang/scripts/master/setup/fedora.sh" | bash -
}
Ubuntu() {
curl -LSs "https://raw.githubusercontent.com/akhilnarang/scripts/master/setup/android_build_env.sh" | bash -
}
build_kernel() {
cd $KERNEL_PATH
make O=out ARCH=arm64 $BUILD_CC $DEFCONFIG savedefconfig
if [[ $(echo "$(awk '/MemTotal/ {print $2}' /proc/meminfo) > 16000000" | bc -l) -eq 1 ]]; then
echo -e "${green}Total RAM is greater than 16GB${clear}"
echo -e "${green}Continuing with FULL_LTO Build${clear}"
else
echo -e "${yellow}Total RAM is less than 16GB${clear}"
echo "${yellow}Disabling LTO${clear}"
sed -i 's/CONFIG_LTO=y/CONFIG_LTO=n/' out/.config
sed -i 's/CONFIG_LTO_CLANG=y/CONFIG_LTO_CLANG=n/' out/.config
sed -i 's/CONFIG_THINLTO=y/CONFIG_THINLTO=n/' out/.config
echo "CONFIG_LTO_NONE=y" >> out/.config
fi
# Begin compilation
start=$(date +%s)
make O=out CC=clang CXX=clang++ ARCH=arm64 -j`nproc` ${BUILD_CC} 2>&1 | tee error.log
if [ -f $KERNEL_PATH/out/arch/arm64/boot/Image ]; then
echo -e "${green}Kernel Compilation successful!, Zipping...${clear}"
make_anykernel3_zip
else
echo -e "${red}Compilation failed!${clear}"
echo -e "${red}Check error.log for more info!${clear}"
exit
fi
}
make_anykernel3_zip() {
cd $KERNEL_PATH
# Extract the kernel version from the Makefile
zip_name="OP9RT-v5.4.$(grep "^SUBLEVEL =" Makefile | awk '{print $3}')-$(date +"%Y%m%d").zip"
cd $KERNEL_PATH/AnyKernel3
cp $KERNEL_PATH/out/arch/arm64/boot/Image $KERNEL_PATH/AnyKernel3
zip -r kernel.zip *
mv kernel.zip $KERNEL_PATH/out
ln -sf $KERNEL_PATH/out/kernel.zip $KERNEL_PATH/out/${zip_name}
echo -e "${green}out: ${KERNEL_PATH}/out/${zip_name}${clear}"
echo -e "${clear}"
echo -e "${green}Completed in $(($(date +%s) - start)) seconds.${clear}"
cd $KERNEL_PATH
exit
}
distro_check(){
if [ -f /etc/arch-release ]; then
echo -e "${green}Arch Linux detected!${clear}"
ArchLinux
elif [ -f /etc/fedora-release ]; then
echo -e "${green}Fedora detected!${clear}"
Fedora
elif [ -f /etc/lsb-release ]; then
echo -e "${green}Debian based distro detected!${clear}"
Ubuntu
else
echo -e "${red}Unsupported OS or ARCH!${clear}"
exit
fi
}
start=$(date +%s)
if [ -d $CLANG_PATH ]; then
echo -e "${blue}Clang exists, Skipping !${clear}"
else
echo -e "${red}Clang is missing, Cloning...${clear}"
echo -e "${yellow}This will take a while...${clear}"
clone_tools
distro_check
fi
# Check if KernelSU is enabled
if [ "$KernelSU" = true ]; then
echo -e "${red}KernelSU compilation is Enabled!${clear}"
setup_ksu
build_kernel
make_anykernel3_zip
else
echo -e "${green}KernelSU compilation is disabled!${clear}"
build_kernel
make_anykernel3_zip
fi