-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocalkernel.sh
265 lines (252 loc) · 8.77 KB
/
localkernel.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/env bash
# Ubuntu 18.04 LTS - Simple local kernel build script
# Copyright (C) 2019, 2020, Raphielscape LLC (@raphielscape)
# Copyright (C) 2019, 2020, Dicky Herlambang (@Nicklas373)
# Copyright (C) 2019, 2020, Dhimas Bagus Prayoga (@kry9ton)
# Copyright (C) 2020, Muhammad Fadlyas (@fadlyas07)
# Copyright (c) 2020, Mr.Miss (@KeselekPermen69)
clear
echo -e ""
echo -e "Let's setup your build enviroment"
echo -e ""
echo -e "[1] setup android build enviroment + docker"
echo -e "[2] skip"
echo -e "[3] cancel"
echo -ne "\nEnter a choice[1-3]: "
read setup
if [ $setup = "1" ]; then
echo -e "pulling docker"
docker pull mrmiss/doker:latest
sleep 3
clear
echo -e "setting up android build env"
git clone https://github.com/akhilnarang/scripts buildenv
cd buildenv
bash setup/android_build_env.sh
cd ..
rm -rf buildenv
fi
if [ $setup = "2" ]; then
echo -e "Skipping build setup"
fi
if [ $choice = "3" ]; then
exit 1
fi
clear
# Clone AnyKernel If not exist
if ! [[ -e $(pwd)/anykernel-3 ]]; then
echo -e ""
echo -e "Determine your AnyKernel now"
echo -e ""
echo -e "\n[1] KeselekPermen69 - anykernel3"
echo -e "[2] Custom anykernel"
echo -e "[3] cancel"
echo -ne "\nEnter a choice[1-3]: "
read choice
if [ $choice = "1" ]; then
echo -e "cloning anykernel-3..."
anykernel_link=https://github.com/keselekpermen69/AnyKernel3
git clone --depth=1 "$anykernel_link" anykernel-3
fi
if [ $choice = "2" ]; then
echo -e "cloning anykernel-3..."
echo -e "Enter the Link of your custom anykernel here"
read -p "AnyAkernel URL's: " anykernel_link
git clone --depth=1 "$anykernel_link" anykernel-3
fi
if [ $choice = "3" ]; then
exit 1
fi
fi
# Clone Compiler If not exist
if ! [[ -e $(pwd)/tc-clang ]]; then
echo -e ""
echo "Ok now determine clang will you use"
echo -e ""
echo -e "Why clang? clang is Future plox :v"
echo -e ""
echo -e "\n[1] Proton Clang 11.0.0"
echo -e "[2] Custom clang"
echo -e "[3] Exit"
echo -ne "\nEnter a choice[1-3]: "
read choice
if [ $choice = "1" ]; then
echo -e "Cloning Proton clang 11.0.0..."
git clone --depth=1 https://github.com/kdrag0n/proton-clang tc-clang
fi
if [ $choice = "2" ]; then
echo -e ""
echo -e "⚠️ Make sure Clang is based on LLVM and built with binutils in it, or compilation will fail."
echo -e ""
echo -e "Place the clang link here"
read -p "Enter Clang URL's: " URL
echo -e ""
echo -e "Cloning $URL"
git clone --depth=1 "$URL" tc-clang
fi
if [ $choice = "3" ]; then
exit 1
fi
fi
# Main Environment
export ARCH=arm64
export SUBARCH=arm64
export pack=$(pwd)/anykernel-3
export github_name=$(git config user.name)
export github_email=$(git config user.email)
export parse_branch=$(git rev-parse --abbrev-ref HEAD)
export kernel_img=$(pwd)/out/arch/arm64/boot/Image.gz-dtb
# GitHub Config
if [ -z $github_name ] && [ -z $github_email ]; then
echo -e "Username & empty email, please enter it below here!"
read -p "Enter username: " USER
read -p "Enter email: " EMAIL
git config --global user.name "$USER"
git config --global user.email "$EMAIL"
fi
clear
while true; do
echo -e ""
echo -e "⚠️ READ THIS BEFORE USING THIS SCRIPT"
echo -e ""
echo -e "This is a script to build an Android kernel (ARM64) on Linux (especially Ubuntu & Debian)."
echo -e "This script was built and tested on Linux 18.04 LTS and everything went well. I made this script"
echo -e "for personal purposes, and it is not recommended for everyone to use, But it's free to use."
echo -e "I made this script inspired by @Krypton A.K.A Dimas Bagus Prayoga to simplify the kernel making"
echo -e "process. (Original Script -> https://github.com/Kry9toN/Scripts)"
echo -e ""
echo -e "OK! let's start to building android kernel now!"
echo -e ""
echo -e "\n[1] Build an android Kernel"
echo -e "[2] Cleanup source"
echo -e "[3] Create flashable zip"
echo -e "[4] Changing compiler"
echo -e "[5] Exit"
echo -ne "\n(i) Please enter a choice[1-5]: "
read choice
# Choice 1
if [ $choice = "1" ]; then
echo -e ""
echo -e "Enter the name of your defconfig"
read -p "Enter defconfig: " DEFCONFIG
# if user does not set defconfig
if [[ -z $DEFCONFIG ]]; then
echo -e " Please!! enter your defconfig name first!"
exit 1
fi
echo -e "##-------------------------------##-------------------------------##"
echo -e ""
echo -ne " BUILD STARTED! "
echo -e ""
echo -e "##-------------------------------##-------------------------------##"
START_TIME=$(date +"%s")
export LD_LIBRARY_PATH=$(pwd)/tc-clang/bin/../lib:$PATH
make ARCH=arm64 O=out "$DEFCONFIG" && \
PATH=$(pwd)/tc-clang/bin:$PATH \
make -j$(nproc) O=out \
ARCH=arm64 \
AR=llvm-ar \
CC=clang \
CROSS_COMPILE=aarch64-linux-gnu- \
CROSS_COMPILE_ARM32=arm-linux-gnueabi- \
NM=llvm-nm \
OBJCOPY=llvm-objcopy \
OBJDUMP=llvm-objdump \
STRIP=llvm-strip 2>&1| tee Log-$(TZ=Asia/Jakarta date +'%d%m%y').log
if ! [[ -f "$kernel_img" ]]; then
grep -iE 'not|empty|in file|waiting|crash|error|fail|fatal' "$(echo *.log)" &> "trimmed_log.txt"
rm -rf Log*.log
echo -e "##-------------------------------##-------------------------------##"
echo -e ""
echo -ne " BUILD FAILED! "
echo -e ""
echo -e "##-------------------------------##-------------------------------##"
echo -e "Open trimmed_log.txt to see that error"
exit 1
fi
FINISH_TIME=$(date +"%s")
DIFF=$(($FINISH_TIME - $START_TIME))
echo -e "##-------------------------------##-------------------------------##"
echo -e ""
echo -ne " BUILD SUCCESS! "
echo -e ""
echo -e "##-------------------------------##-------------------------------##"
echo -e "removing build log"
rm -rf Log*.log
echo -e "done"
echo -e "Build took $(($DIFF / 60)) minute(s) and $(($DIFF % 60)) second(s)."
fi
# Choice 2
if [ $choice = "2" ]; then
echo -e "##-------------------------------##-------------------------------##"
echo -e ""
echo -ne " CLEAN-UP KERNEL DIRECTORY "
echo -e ""
echo -e "##-------------------------------##-------------------------------##"
make O=out clean &>/dev/null
make mrproper &>/dev/null
rm -rf out/* trimm*.txt
echo -e "##-------------------------------##-------------------------------##"
echo -e ""
echo -ne " SUCCESS! "
echo -e ""
echo -e "##-------------------------------##-------------------------------##"
fi
# Choice 3
if [ $choice = "3" ]; then
echo -e ""
echo -e "##-------------------------------##-------------------------------##"
echo -e ""
echo -ne " CREATING FLASHABLE ZIP "
echo -e ""
echo -e "##-------------------------------##-------------------------------##"
cd "$pack"
make clean &>/dev/null
echo -e "Checking your image.gz-dtb..."
sleep 2
if ! [[ -f "$kernel_img" ]]; then
echo -e "Image.gz-dtb Not Found!"
sleep 1
echo -e "Aborting process..."
else
mv "$kernel_img" $pack/zImage
zip -r9 kernel.zip * &>/dev/null
echo -e "##-------------------------------##-------------------------------##"
echo -e ""
echo -ne " SUCCESS!! "
echo -e ""
echo -e "##-------------------------------##-------------------------------##"
fi
echo "successful creating zip, look at the zip at anykernel-3/kernel.zip"
sleep 5
cd ~/
fi
# Choice 4
if [ $choice = "4" ]; then
clear
unset URL
echo -e ""
echo -e "⚠️ Make sure Clang is based on LLVM and built with binutils in it, or compilation will fail"
echo -e ""
echo -e "Place the compiler link here"
read -p "Enter Clang URL's: " URL
if [ -z $URL ]; then
echo -e "Changing Compiler failed!"
echo -e "Please enter the link correctly"
else
echo -e "Cleaning old compiler...."
rm -rf tc-clang
sleep 2
echo -e "Cloning new compiler..."
git clone --quiet --depth=1 "$URL" tc-clang
toolchain_ver=$($(pwd)/tc-clang/bin/clang --version | head -n 1)
echo "Track compiler to -> $toolchain_ver"
sleep 5
fi
fi
# Choice 5
if [ $choice = "5" ]; then
clear
exit
fi
done