-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·289 lines (253 loc) · 8.97 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
#! /bin/bash
#
# Copyright (C) 2020 StarLight5234
# Copyright (C) 2021 GhostMaster69-dev
# Copyright (C) 2022 rk134
export DEVICE="VINCE"
export CONFIG="vince-perf_defconfig"
export CHANNEL_ID="-1001750098178"
export TELEGRAM_TOKEN=$BOT_API_KEY
export TC_PATH="$HOME/toolchains"
export ZIP_DIR="$(pwd)/Flasher"
export IS_MIUI="no"
export KERNEL_DIR=$(pwd)
export KBUILD_BUILD_USER="rxhul"
export GCC_COMPILE="no"
export AOSPCLANG_COMPILE="yes"
export KBUILD_BUILD_HOST="rk134"
export KBUILD_COMPILER_STRING="AOSP's AOSP CLANG"
export COMPILER="AOSP's AOSP CLANG"
#==============================================================
#===================== Function Definition ====================
#==============================================================
#======================= Telegram Start =======================
#==============================================================
# Upload buildlog to group
tg_erlog()
{
ERLOG=$HOME/build/build${BUILD}.txt
curl -F document=@"$ERLOG" "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendDocument" \
-F chat_id=$CHANNEL_ID \
-F caption="Build ran into errors after $(($DIFF / 60)) minute(s) and $(($DIFF % 60)) seconds, plox check logs"
}
# Upload zip to channel
tg_pushzip()
{
FZIP=$ZIP_DIR/$ZIP
curl -F document=@"$FZIP" "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendDocument" \
-F chat_id=$CHANNEL_ID \
-F caption="Build Finished after $(($DIFF / 60)) minute(s) and $(($DIFF % 60)) seconds"
}
# Upload download link to channel
tg_pushlink()
{
export zip_directory="$(cd $(pwd)/Flasher/ && ls *.zip)"
rclone copy $(pwd)/Flasher/*.zip ccache:vince -P
curl -s https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage -d chat_id=$CHANNEL_ID -d text="Download link https://retarded-sprout.axsp.workers.dev/vince/$zip_directory"
}
# Send Updates
function tg_sendinfo() {
curl -s "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage" \
-d "parse_mode=html" \
-d text="${1}" \
-d chat_id="${CHANNEL_ID}" \
-d "disable_web_page_preview=true"
}
# Send a sticker
function start_sticker() {
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendSticker" \
-d sticker="CAACAgQAAxkBAAEDIYdhctPrAm1Ydl3sFori9vNNnjAoigAC9AkAAl79YVHW7zfYKT9-XyEE" \
-d chat_id=$CHANNEL_ID
}
function error_sticker() {
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendSticker" \
-d sticker="$STICKER" \
-d chat_id=$CHANNEL_ID
}
#==============================================================
#======================= Telegram End =========================
#==============================================================
#========================= Clone TC ===========================
#======================== & AnyKernel =========================
#==============================================================
#function clone_tc() {
#[ -d ${TC_PATH} ] || mkdir ${TC_PATH}
#if [ "$GCC_COMPILE" == "no" ]; then
#git clone --depth=1 https://github.com/kdrag0n/proton-clang.git ${TC_PATH}/clang
#export PATH="${TC_PATH}/clang/bin:$PATH"
#export STRIP="${TC_PATH}/clang/aarch64-linux-gnu/bin/strip"
#export COMPILER="Clang 14.0.0"
#else
#git clone --depth=1 https://github.com/arter97/arm64-gcc ${TC_PATH}/gcc64
#git clone --depth=1 https://github.com/arter97/arm32-gcc ${TC_PATH}/gcc32
#export PATH="${TC_PATH}/gcc64/bin:${TC_PATH}/gcc32/bin:$PATH"
#export STRIP="${TC_PATH}/gcc64/aarch64-elf/bin/strip"
#export COMPILER="Arter97's GCC Compiler"
#fi
#}
#==============================================================
#=========================== Make =============================
#========================== Kernel ============================
#==============================================================
build_kernel() {
DATE=`date`
BUILD_START=$(date +"%s")
make O=out ARCH=arm64 "$CONFIG"
if [ "$AOSPCLANG_COMPILE" == "no" ]; then
make -j$(nproc --all) O=out \
ARCH=arm64 \
CC="ccache clang" \
AR=llvm-ar \
AS=llvm-as \
NM=llvm-nm \
LD=ld.lld \
OBJCOPY=llvm-objcopy \
OBJDUMP=llvm-objdump \
OBJSIZE=llvm-size \
READELF=llvm-readelf \
STRIP=llvm-strip \
HOSTCC=clang \
HOSTCXX=clang++ \
HOSTAR=llvm-ar \
HOSTLD=ld.lld \
HOSTAS=llvm-as \
HOSTNM=llvm-nm \
CROSS_COMPILE=aarch64-linux-gnu- \
CROSS_COMPILE_ARM32=arm-linux-gnueabi- |& tee -a $HOME/build/build${BUILD}.txt
else
cd .. \
export PATH="$(pwd)/tools/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin:$PATH" \
export PATH="$(pwd)/tools/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin:$PATH" \
export PATH="$(pwd)/tools/clang/host/linux-x86/clang-r428724/bin:$PATH" \
export LD_LIBRARY_PATH="$(pwd)/tools/clang/host/linux-x86/clang-r428724/lib64:$LD_LIBRARY_PATH" \
export ARCH=arm64 \
export SUBARCH=ARM64 \
export CLANG_TRIPLE=aarch64-linux-gnu- \
export CROSS_COMPILE=aarch64-linux-android- \
export CROSS_COMPILE_ARM32=arm-linux-androideabi- \
make \
O=out \
clean \
mrproper \
CC="ccache clang" \
AR=llvm-ar \
NM=llvm-nm \
OBJCOPY=llvm-objcopy \
OBJDUMP=llvm-objdump \
READELF=llvm-readelf \
OBJSIZE=llvm-size \
STRIP=llvm-strip \
HOSTCC=clang \
HOSTCXX=clang++ \
vince-perf_defconfig
&&
make \
O=out \
CC="ccache clang" \
AR=llvm-ar \
NM=llvm-nm \
OBJCOPY=llvm-objcopy \
OBJDUMP=llvm-objdump \
READELF=llvm-readelf \
OBJSIZE=llvm-size \
STRIP=llvm-strip \
HOSTCC=clang \
HOSTCXX=clang++ \
-j$(nproc --all) -flto=thin -O3 -march=native -mtune=native -pipe |& tee -a $HOME/build/build${BUILD}.txt
fi
BUILD_END=$(date +"%s")
DIFF=$(($BUILD_END - $BUILD_START))
}
#==============================================================
#==================== Make Flashable Zip ======================
#==============================================================
function make_flashable() {
if [ "$IS_MIUI" == "yes" ]; then
# credit @adekmaulana
for MODULES in $(find "$KERNEL_DIR/out" -name '*.ko'); do
"${STRIP}" --strip-unneeded --strip-debug "${MODULES}"
"$KERNEL_DIR/scripts/sign-file" sha512 \
"$KERNEL_DIR/out/signing_key.priv" \
"$KERNEL_DIR/out/signing_key.x509" \
"${MODULES}"
case ${MODULES} in
*/wlan.ko)
cp "${MODULES}" "${VENDOR_MODULEDIR}/pronto_wlan.ko"
;;
esac
done
echo -e "(i) Done moving wifi modules"
fi
cd $ZIP_DIR
make clean &>/dev/null
cp $KERN_IMG $ZIP_DIR/zImage
if [ "$BRANCH" == "threadripper-lmk" ]; then
make stable &>/dev/null
elif [ "$BRANCH" == "beta" ]; then
make beta &>/dev/null
else
make test &>/dev/null
fi
ZIP=$(echo *.zip)
tg_pushzip
}
#==============================================================
#========================= Build Log ==========================
#==============================================================
# Credits: @madeofgreat
BTXT="$HOME/build/buildno.txt" #BTXT is Build number TeXT
if ! [ -a "$BTXT" ]; then
mkdir $HOME/build
touch $HOME/build/buildno.txt
echo $RANDOM > $BTXT
fi
BUILD=$(cat $BTXT)
BUILD=$(($BUILD + 1))
echo ${BUILD} > $BTXT
#==============================================================
#===================== Random sticker =========================
#==================== for build error =========================
#==============================================================
stick=$(($RANDOM % 5))
if [ "$stick" == "0" ]; then
STICKER="CAACAgIAAxkBAAEDIWhhcssHSMR1HTAHtKOby21tVafvWgAC_gADVp29CtoEYTAu-df_IQQ"
elif [ "$stick" == "1" ];then
STICKER="CAACAgIAAxkBAAEDIXlhcsvK31evc58huNXRZnSWf62R2AAC_w4AAhSUAAFL2_NFL9rIYIAhBA"
elif [ "$stick" == "2" ];then
STICKER="CAACAgUAAxkBAAEDIXthcsvYV4zwNP0ousx1ULwkKGRdygACIAADYOojP1RURqxGbEhrIQQ"
elif [ "$stick" == "3" ];then
STICKER="CAACAgUAAxkBAAEDIX1hcsvr8e6DUr1J4KmHCtI98gx1xwACNgADP9jqMxV1oXRlrlnXIQQ"
elif [ "$stick" == "4" ];then
STICKER="CAACAgEAAxkBAAEDIYFhcswQNqw8ZPubg7zGQkNhaYGTBAACKwIAAvx0QESn-U6NZyYYfSEE"
fi
#==============================================================
#===================== End of function ========================
#======================= definition ===========================
#==============================================================
#clone_tc
COMMIT=$(git log --pretty=format:'"%h : %s"' -1)
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
KERNEL_DIR=$(pwd)
KERN_IMG=$KERNEL_DIR/out/arch/arm64/boot/Image.gz-dtb
CONFIG_PATH=$KERNEL_DIR/arch/arm64/configs/$CONFIG
VENDOR_MODULEDIR="$ZIP_DIR/modules/vendor/lib/modules"
export KERN_VER=$(echo "$(make kernelversion)")
# Cleaning source
make mrproper && rm -rf out
start_sticker
tg_sendinfo "$(echo -e "======= <b>$DEVICE</b> =======\n
Build-Host :- <b>$KBUILD_BUILD_HOST</b>
Build-User :- <b>$KBUILD_BUILD_USER</b>\n
Version :- <u><b>$KERN_VER</b></u>
Compiler :- <i>$COMPILER</i>\n
on Branch :- <b>$BRANCH</b>
Commit :- <b>$COMMIT</b>\n")"
build_kernel
# Check if kernel img is there or not and make flashable accordingly
if ! [ -a "$KERN_IMG" ]; then
tg_erlog && error_sticker
exit 1
else
make_flashable
tg_pushlink
fi