forked from ProjectElixir-Devices/kernel_xiaomi_sm6250
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
284 lines (242 loc) · 9.07 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
#!/usr/bin/env bash
#
# Script For Building Android Kernel
#
##----------------------------------------------------------##
# Specify Kernel Directory
KERNEL_DIR="$(pwd)"
##----------------------------------------------------------##
# Device Name and Model
MODEL=Xiaomi
DEVICE=Miatoll
# Kernel Version Code
VERSION=
# Kernel Defconfig
DEFCONFIG=cust_defconfig
# Select LTO variant ( Full LTO by default )
DISABLE_LTO=0
THIN_LTO=0
# Files
IMAGE=$(pwd)/out/arch/arm64/boot/Image.gz
DTBO=$(pwd)/out/arch/arm64/boot/dtbo.img
DTB=$(pwd)/out/arch/arm64/boot/dts/qcom/cust-atoll-ab.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=Forza
FINAL_ZIP=${ZIPNAME}-kernel-${DEVICE}-${TANGGAL}.zip
##----------------------------------------------------------##
# Specify compiler.
COMPILER=azure
##----------------------------------------------------------##
# Specify Linker
LINKER=ld.lld
##----------------------------------------------------------##
##----------------------------------------------------------##
# Clone ToolChain
function cloneTC() {
if [ $COMPILER = "atomx" ];
then
git clone --depth=1 https://gitlab.com/ElectroPerf/atom-x-clang.git clang
PATH="${KERNEL_DIR}/clang/bin:$PATH"
elif [ $COMPILER = "neutron" ];
then
git clone --depth=1 https://gitlab.com/dakkshesh07/neutron-clang.git clang
PATH="${KERNEL_DIR}/clang/bin:$PATH"
elif [ $COMPILER = "azure" ];
then
git clone --depth=1 https://gitlab.com/Panchajanya1999/azure-clang.git clang
PATH="${KERNEL_DIR}/clang/bin:$PATH"
elif [ $COMPILER = "proton" ];
then
git clone --depth=1 https://github.com/kdrag0n/proton-clang.git clang
PATH="${KERNEL_DIR}/clang/bin:$PATH"
elif [ $COMPILER = "eva" ];
then
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
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/Abhishek001konni/AnyKernel3.git
}
##------------------------------------------------------##
# 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
# Export Local Version
export LOCALVERSION="-${VERSION}"
# KBUILD HOST and USER
export KBUILD_BUILD_HOST=Linux
export KBUILD_BUILD_USER="Lopster"
# 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"
}
##----------------------------------------------------------------##
# Export Configs
function configs() {
if [ -d ${KERNEL_DIR}/clang ] || [ -d ${KERNEL_DIR}/aosp-clang ]; then
if [ $DISABLE_LTO = "1" ]; then
sed -i 's/CONFIG_LTO_CLANG=y/# CONFIG_LTO_CLANG is not set/' arch/arm64/configs/cust_defconfig
sed -i 's/CONFIG_LTO=y/# CONFIG_LTO is not set/' arch/arm64/configs/cust_defconfig
sed -i 's/# CONFIG_LTO_NONE is not set/CONFIG_LTO_NONE=y/' arch/arm64/configs/cust_defconfig
elif [ $THIN_LTO = "1" ]; then
sed -i 's/# CONFIG_THINLTO is not set/CONFIG_THINLTO=y/' arch/arm64/configs/cust_defconfig
fi
elif [ -d ${KERNEL_DIR}/gcc64 ]; then
sed -i 's/CONFIG_LLVM_POLLY=y/# CONFIG_LLVM_POLLY is not set/' arch/arm64/configs/cust_defconfig
sed -i 's/# CONFIG_GCC_GRAPHITE is not set/CONFIG_GCC_GRAPHITE=y/' arch/arm64/configs/cust_defconfig
if ! [ $DISABLE_LTO = "1" ]; then
sed -i 's/# CONFIG_LTO_GCC is not set/CONFIG_LTO_GCC=y/' arch/arm64/configs/cust_defconfig
fi
fi
}
##----------------------------------------------------------##
# 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>Linker : </b><code>$LINKER</code>%0a<b>Branch : </b><code>$CI_BRANCH</code>%0A<b>Top Commit : </b><a href='$DRONE_COMMIT_LINK'>$COMMIT_HEAD</a>"
# Compile
make O=out ${DEFCONFIG}
if [ -d ${KERNEL_DIR}/clang ];
then
make -kj$(nproc --all) O=out \
ARCH=arm64 \
CC=clang \
HOSTCC=clang \
HOSTCXX=clang++ \
CROSS_COMPILE=aarch64-linux-gnu- \
CROSS_COMPILE_ARM32=arm-linux-gnueabi- \
LD=${LINKER} \
AR=llvm-ar \
NM=llvm-nm \
OBJCOPY=llvm-objcopy \
OBJDUMP=llvm-objdump \
STRIP=llvm-strip \
READELF=llvm-readelf \
OBJSIZE=llvm-size \
V=$VERBOSE 2>&1 | tee error.log
elif [ -d ${KERNEL_DIR}/gcc64 ];
then
make -kj$(nproc --all) O=out \
ARCH=arm64 \
CROSS_COMPILE_ARM32=arm-eabi- \
CROSS_COMPILE=aarch64-elf- \
LD=aarch64-elf-${LINKER} \
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 -kj$(nproc --all) O=out \
ARCH=arm64 \
CC=clang \
HOSTCC=clang \
HOSTCXX=clang++ \
CLANG_TRIPLE=aarch64-linux-gnu- \
CROSS_COMPILE=aarch64-linux-android- \
CROSS_COMPILE_ARM32=arm-linux-androideabi- \
LD=${LINKER} \
AR=llvm-ar \
NM=llvm-nm \
OBJCOPY=llvm-objcopy \
OBJDUMP=llvm-objdump \
STRIP=llvm-strip \
READELF=llvm-readelf \
OBJSIZE=llvm-size \
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
# 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 ..
}
##----------------------------------------------------------##
cloneTC
exports
configs
compile
END=$(date +"%s")
DIFF=$(($END - $START))
zipping
##----------------*****-----------------------------##