-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathbuild.sh
378 lines (334 loc) · 10.7 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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#!/usr/bin/env bash
#
# Script For Building Android Kernel
#
# Specify Kernel Directory
KERNEL_DIR="$(pwd)"
BUILD=$1
if [ "$BUILD" = "local" ]; then
if [ -e ids.txt ]; then
chat_id=$(awk "NR==1{print;exit}" ids.txt)
token=$(awk "NR==2{print;exit}" ids.txt)
else
echo "Type ur chat id:"
read chat
echo "$chat" > ids.txt
chat_id=$chat
echo "Type ur bot token:"
read token
echo "$token" >> ids.txt
token=$token
fi
fi
DEVICE=$2
VERSION=BETA
if [ "${DEVICE}" = "alioth" ]; then
DEFCONFIG=alioth_defconfig
MODEL="Poco F3"
elif [ "${DEVICE}" = "lmi" ]; then
DEFCONFIG=lmi_defconfig
MODEL="Poco F2 Pro"
elif [ "${DEVICE}" = "apollo" ]; then
DEFCONFIG=apollo_defconfig
MODEL="Mi 10T Pro"
elif [ "${DEVICE}" = "munch" ]; then
DEFCONFIG=munch_defconfig
MODEL="Poco F4"
fi
# Files
IMAGE=$(pwd)/out/arch/arm64/boot/Image
DTBO=$(pwd)/out/arch/arm64/boot/dtbo.img
OUT_DIR=out/
dts_source=arch/arm64/boot/dts/vendor/qcom
# Verbose Build
VERBOSE=0
# Kernel Version
KERVER=$(make kernelversion)
COMMIT_HEAD=$(git log --oneline -1)
# Date and Time
DATE=$(TZ=Europe/Lisbon date +"%Y%m%d-%T")
TM=$(date +"%F%S")
# Specify Final Zip Name
ZIPNAME=Nexus
FINAL_ZIP=${ZIPNAME}-${VERSION}-${DEVICE}-RC3.0-KERNEL-AOSP-${TM}.zip
# Specify compiler [ proton, nexus, aosp ]
COMPILER=neutron
# Clone ToolChain
function cloneTC() {
case $COMPILER in
proton)
git clone --depth=1 https://github.com/kdrag0n/proton-clang.git clang
PATH="${KERNEL_DIR}/clang/bin:$PATH"
;;
nexus)
git clone --depth=1 https://gitlab.com/Project-Nexus/nexus-clang.git clang
PATH="${KERNEL_DIR}/clang/bin:$PATH"
;;
neutron)
if [ ! -d clang ]; then
mkdir clang && cd clang
bash <(curl -s https://raw.githubusercontent.com/Neutron-Toolchains/antman/main/antman) -S
cd ..
else
echo "Neutron alreay cloned"
fi
PATH="${KERNEL_DIR}/clang/bin:$PATH"
;;
nex14)
git clone --depth=1 https://gitlab.com/Project-Nexus/nexus-clang.git -b nexus-14 clang
PATH="${KERNEL_DIR}/clang/bin:$PATH"
;;
aosp)
echo "* Checking if Aosp Clang is already cloned..."
if [ -d clangB ]; then
echo "××××××××××××××××××××××××××××"
echo " Already Cloned Aosp Clang"
echo "××××××××××××××××××××××××××××"
else
export CLANG_VERSION="clang-r498229"
echo "* It's not cloned, cloning it..."
mkdir clangB
cd clangB || exit
wget -q https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/refs/heads/master/${CLANG_VERSION}.tgz
tar -xf ${CLANG_VERSION}.tgz
cd .. || exit
git clone https://github.com/LineageOS/android_prebuilts_gcc_linux-x86_aarch64_aarch64-linux-android-4.9.git --depth=1 gcc
git clone https://github.com/LineageOS/android_prebuilts_gcc_linux-x86_arm_arm-linux-androideabi-4.9.git --depth=1 gcc32
fi
PATH="${KERNEL_DIR}/clangB/bin:${KERNEL_DIR}/gcc/bin:${KERNEL_DIR}/gcc32/bin:${PATH}"
;;
zyc)
if [ ! -d clang ]; then
mkdir clang
cd clang
wget https://raw.githubusercontent.com/ZyCromerZ/Clang/main/Clang-16-lastbuild.txt
V="$(cat Clang-16-lastbuild.txt)"
wget -q https://github.com/ZyCromerZ/Clang/releases/download/16.0.4-$V-release/Clang-16.0.4-$V.tar.gz
tar -xf Clang-16.0.4-$V.tar.gz
cd ..
fi
PATH="${KERNEL_DIR}/clang/bin:$PATH"
;;
*)
echo "Compiler not defined"
;;
esac
# Clone AnyKernel
rm -rf AnyKernel3
if [ "${DEVICE}" = "alioth" ]; then
git clone --depth=1 https://github.com/NotZeetaa/AnyKernel3 -b alioth AnyKernel3
elif [ "${DEVICE}" = "apollo" ]; then
git clone --depth=1 https://github.com/NotZeetaa/AnyKernel3 -b apollo AnyKernel3
elif [ "${DEVICE}" = "munch" ]; then
git clone --depth=1 https://github.com/NotZeetaa/AnyKernel3 -b munch AnyKernel3
else
git clone --depth=1 https://github.com/NotZeetaa/AnyKernel3 -b lmi AnyKernel3
fi
}
# Export Variables
function exports() {
# Export KBUILD_COMPILER_STRING
if [ -d ${KERNEL_DIR}/clang ];
then
export KBUILD_COMPILER_STRING=$(${KERNEL_DIR}/clang/bin/clang --version | head -n 1 | perl -pe 's/\(http.*?\)//gs' | sed -e 's/ */ /g' -e 's/[[:space:]]*$//')
elif [ -d ${KERNEL_DIR}/gcc64 ];
then
export KBUILD_COMPILER_STRING=$("$KERNEL_DIR/gcc64"/bin/aarch64-elf-gcc --version | head -n 1)
elif [ -d ${KERNEL_DIR}/clangB ];
then
export KBUILD_COMPILER_STRING=$(${KERNEL_DIR}/clangB/bin/clang --version | head -n 1 | perl -pe 's/\(http.*?\)//gs' | sed -e 's/ */ /g' -e 's/[[:space:]]*$//')
fi
# Export ARCH and SUBARCH
export ARCH=arm64
export SUBARCH=arm64
# KBUILD HOST and USER
export KBUILD_BUILD_HOST=ArchLinux
export KBUILD_BUILD_USER="NotZeeta"
# CI
if [ "$CI" ]
then
if [ "$CIRCLECI" ]
then
export KBUILD_BUILD_VERSION=${CIRCLE_BUILD_NUM}
export CI_BRANCH=${CIRCLE_BRANCH}
elif [ "$DRONE" ]
then
export KBUILD_BUILD_VERSION=${DRONE_BUILD_NUMBER}
export CI_BRANCH=${DRONE_BRANCH}
fi
fi
export PROCS=$(nproc --all)
export DISTRO=$(source /etc/os-release && echo "${NAME}")
}
# Telegram Bot Integration
function post_msg() {
curl -s -X POST "https://api.telegram.org/bot$token/sendMessage" \
-d chat_id="$chat_id" \
-d "disable_web_page_preview=true" \
-d "parse_mode=html" \
-d text="$1"
}
function push() {
curl -F document=@$1 "https://api.telegram.org/bot$token/sendDocument" \
-F chat_id="$chat_id" \
-F "disable_web_page_preview=true" \
-F "parse_mode=html" \
-F caption="$2"
}
# Compilation
METHOD=$3
function compile() {
START=$(date +"%s")
# Push Notification
post_msg "<b>$KBUILD_BUILD_VERSION CI Build Triggered</b>%0A<b>Docker OS: </b><code>$DISTRO</code>%0A<b>Kernel Version : </b><code>$KERVER</code>%0A<b>Date : </b><code>$(TZ=Europe/Lisbon date)</code>%0A<b>Device : </b><code>$MODEL [$DEVICE]</code>%0A<b>Pipeline Host : </b><code>$KBUILD_BUILD_HOST</code>%0A<b>Host Core Count : </b><code>$PROCS</code>%0A<b>Compiler Used : </b><code>$KBUILD_COMPILER_STRING</code>%0A<b>Branch : </b><code>$CI_BRANCH</code>%0A<b>Top Commit : </b><a href='$DRONE_COMMIT_LINK'>$COMMIT_HEAD</a>"
# Compile
if [ -d ${KERNEL_DIR}/clang ];
then
make O=out CC=clang ARCH=arm64 ${DEFCONFIG}
if [ "$METHOD" = "lto" ]; then
scripts/config --file ${OUT_DIR}/.config \
-e LTO_CLANG \
-d THINLTO
fi
make -kj$(nproc --all) O=out \
ARCH=arm64 \
LLVM=1 \
LLVM_IAS=1 \
CROSS_COMPILE=aarch64-linux-gnu- \
CROSS_COMPILE_COMPAT=arm-linux-gnueabi- \
V=$VERBOSE 2>&1 | tee error.log
elif [ -d ${KERNEL_DIR}/gcc64 ];
then
make O=out ARCH=arm64 ${DEFCONFIG}
make -kj$(nproc --all) O=out \
ARCH=arm64 \
CROSS_COMPILE_COMPAT=arm-eabi- \
CROSS_COMPILE=aarch64-elf- \
AR=llvm-ar \
NM=llvm-nm \
OBJCOPY=llvm-objcopy \
OBJDUMP=llvm-objdump \
STRIP=llvm-strip \
OBJSIZE=llvm-size \
V=$VERBOSE 2>&1 | tee error.log
elif [ -d ${KERNEL_DIR}/clangB ];
then
make O=out CC=clang ARCH=arm64 ${DEFCONFIG}
if [ "$METHOD" = "lto" ]; then
scripts/config --file ${OUT_DIR}/.config \
-e LTO_CLANG \
-d THINLTO
fi
make -kj$(nproc --all) O=out \
ARCH=arm64 \
LLVM=1 \
LLVM_IAS=1 \
CLANG_TRIPLE=aarch64-linux-gnu- \
CROSS_COMPILE=aarch64-linux-android- \
CROSS_COMPILE_COMPAT=arm-linux-androideabi- \
V=$VERBOSE 2>&1 | tee error.log
fi
# Verify Files
if ! [ -a "$IMAGE" ];
then
push "error.log" "Build Throws Errors"
exit 1
else
find ${OUT_DIR}/$dts_source -name '*.dtb' -exec cat {} + >${OUT_DIR}/arch/arm64/boot/dtb
DTB=$(pwd)/out/arch/arm64/boot/dtb
fi
}
function compile_ksu() {
START=$(date +"%s")
# Compile
if [ -d ${KERNEL_DIR}/clang ];
then
make O=out CC=clang ARCH=arm64 ${DEFCONFIG}
if [ "$METHOD" = "lto" ]; then
scripts/config --file ${OUT_DIR}/.config \
-e LTO_CLANG \
-d THINLTO
fi
make -kj$(nproc --all) O=out \
ARCH=arm64 \
LLVM=1 \
LLVM_IAS=1 \
CROSS_COMPILE=aarch64-linux-gnu- \
CROSS_COMPILE_COMPAT=arm-linux-gnueabi- \
V=$VERBOSE 2>&1 | tee error.log
elif [ -d ${KERNEL_DIR}/gcc64 ];
then
make O=out ARCH=arm64 ${DEFCONFIG}
make -kj$(nproc --all) O=out \
ARCH=arm64 \
CROSS_COMPILE_COMPAT=arm-eabi- \
CROSS_COMPILE=aarch64-elf- \
AR=llvm-ar \
NM=llvm-nm \
OBJCOPY=llvm-objcopy \
OBJDUMP=llvm-objdump \
STRIP=llvm-strip \
OBJSIZE=llvm-size \
V=$VERBOSE 2>&1 | tee error.log
elif [ -d ${KERNEL_DIR}/clangB ];
then
make O=out CC=clang ARCH=arm64 ${DEFCONFIG}
if [ "$METHOD" = "lto" ]; then
scripts/config --file ${OUT_DIR}/.config \
-e LTO_CLANG \
-d THINLTO
fi
make -kj$(nproc --all) O=out \
ARCH=arm64 \
LLVM=1 \
LLVM_IAS=1 \
CLANG_TRIPLE=aarch64-linux-gnu- \
CROSS_COMPILE=aarch64-linux-android- \
CROSS_COMPILE_COMPAT=arm-linux-androideabi- \
V=$VERBOSE 2>&1 | tee error.log
fi
# Verify Files
if ! [ -a "$IMAGE" ];
then
push "error.log" "Build Throws Errors"
exit 1
else
post_msg " Kernel Compilation Finished. Started Zipping "
find ${OUT_DIR}/$dts_source -name '*.dtb' -exec cat {} + >${OUT_DIR}/arch/arm64/boot/dtb
DTB=$(pwd)/out/arch/arm64/boot/dtb
fi
}
# Zipping
function move() {
# Copy Files To AnyKernel3 Zip
mv $IMAGE AnyKernel3
mv $DTBO AnyKernel3
mv $DTB AnyKernel3
}
function move_ksu() {
mv $IMAGE AnyKernel3/ksu/
}
function zipping() {
# Zipping and Push Kernel
cd AnyKernel3 || exit 1
zip -r9 ${FINAL_ZIP} *
MD5CHECK=$(md5sum "$FINAL_ZIP" | cut -d' ' -f1)
push "$FINAL_ZIP" "Build took : $(($DIFF / 60)) minute(s) and $(($DIFF % 60)) second(s) | For <b>$MODEL ($DEVICE)</b> | <b>${KBUILD_COMPILER_STRING}</b> | <b>MD5 Checksum : </b><code>$MD5CHECK</code>"
cd ..
rm -rf AnyKernel3
}
cloneTC
exports
compile
END=$(date +"%s")
DIFF=$(($END - $START))
move
# KernelSU
echo "CONFIG_KSU=y" >> $(pwd)/arch/arm64/configs/$DEFCONFIG
compile_ksu
move_ksu
zipping
if [ "$BUILD" = "local" ]; then
# Discard KSU changes in defconfig
git restore arch/arm64/configs/$DEFCONFIGf
fi