forked from xiaomi-sm8250-devs/android_kernel_xiaomi_sm8250
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild3.sh
243 lines (207 loc) · 7.86 KB
/
build3.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
#!/usr/bin/env bash
#
# Script For Building Android Kernel
#
##----------------------------------------------------------##
# Specify Kernel Directory
KERNEL_DIR="$(pwd)"
##----------------------------------------------------------##
# Device Name and Model
MODEL=Mi 10T Pro
DEVICE=Apollo
# Kernel Version Code
VERSION=BETA
# Kernel Defconfig
DEFCONFIG=vendor/apollo_defconfig
# Files
IMAGE=$(pwd)/out/arch/arm64/boot/Image
DTBO=$(pwd)/out/arch/arm64/boot/dtbo.img
DTB=$(pwd)/out/arch/arm64/boot/dts/vendor/qcom/kona-v2.1.dtb
# Verbose Build
VERBOSE=0
# Kernel Version
KERVER=$(make kernelversion)
COMMIT_HEAD=$(git log --oneline -1)
# Date and Time
DATE=$(TZ=Asia/Kolkata date +"%Y%m%d-%T")
TANGGAL=$(date +"%F%S")
# Specify Final Zip Name
ZIPNAME=Nexus
FINAL_ZIP=${ZIPNAME}-${VERSION}-${DEVICE}-KERNEL-AOSP-${TANGGAL}.zip
FINAL_ZIP2=${ZIPNAME}-${VERSION}-${DEVICE}-KERNEL-MIUI-${TANGGAL}.zip
##----------------------------------------------------------##
# Specify compiler [ proton, atomx, eva, aosp ]
COMPILER=prelude
##----------------------------------------------------------##
# Clone ToolChain
function cloneTC() {
if [ $COMPILER = "atomx" ];
then
post_msg " Cloning Atom-X Clang ToolChain "
git clone --depth=1 https://gitlab.com/ElectroPerf/atom-x-clang clang
PATH="${KERNEL_DIR}/clang/bin:$PATH"
elif [ $COMPILER = "proton" ];
then
post_msg " Cloning Proton Clang ToolChain "
git clone --depth=1 https://github.com/kdrag0n/proton-clang.git clang
PATH="${KERNEL_DIR}/clang/bin:$PATH"
elif [ $COMPILER = "prelude" ];
then
post_msg " Cloning Prelude Clang ToolChain"
git clone --depth=1 https://gitlab.com/jjpprrrr/prelude-clang.git clang
PATH="${KERNEL_DIR}/clang/bin:$PATH"
elif [ $COMPILER = "eva" ];
then
post_msg " Cloning Eva GCC ToolChain "
git clone --depth=1 https://github.com/mvaisakh/gcc-arm64.git -b gcc-new gcc64
git clone --depth=1 https://github.com/mvaisakh/gcc-arm.git -b gcc-new gcc32
PATH=$KERNEL_DIR/gcc64/bin/:$KERNEL_DIR/gcc32/bin/:/usr/bin:$PATH
elif [ $COMPILER = "aosp" ];
then
post_msg " Cloning Aosp Clang 14.0.1 ToolChain "
mkdir aosp-clang
cd aosp-clang || exit
wget -q https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/refs/heads/master/clang-r450784b.tar.gz
tar -xf clang*
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
PATH="${KERNEL_DIR}/aosp-clang/bin:${KERNEL_DIR}/gcc/bin:${KERNEL_DIR}/gcc32/bin:${PATH}"
fi
# Clone AnyKernel
git clone --depth=1 https://github.com/NotZeetaa/Flashable_Zip_lmi.git -b apollo AnyKernel3
}
##------------------------------------------------------##
# 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}/aosp-clang ];
then
export KBUILD_COMPILER_STRING=$(${KERNEL_DIR}/aosp-clang/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
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=Asia/Kolkata 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}
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}/aosp-clang ];
then
make O=out CC=clang ARCH=arm64 ${DEFCONFIG}
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 "
fi
}
##----------------------------------------------------------------##
function zipping() {
# Copy Files To AnyKernel3 Zip
cp $IMAGE AnyKernel3
cp $DTBO AnyKernel3
cp $DTB AnyKernel3/dtb
rm -rf $IMAGE
rm -rf $DTBO
rm -rf $DTB
# 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>"
rm -rf dtbo.img && rm -rf *.zip
zip -r9 ${FINAL_ZIP2} *
MD5CHECK=$(md5sum "$FINAL_ZIP2" | cut -d' ' -f1)
push "$FINAL_ZIP2" "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
configs
compile
END=$(date +"%s")
DIFF=$(($END - $START))
zipping
##----------------*****-----------------------------##