-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·298 lines (259 loc) · 9.84 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
#!/usr/bin/env bash
#
# Script For Building Android Kernel
#
##----------------------------------------------------------##
# Specify Kernel Directory
KERNEL_DIR=$(pwd)
# Kernel defconfig
DEFCONFIG=vendor/meteoric_defconfig
# AnyKernel3 directory
ANYKERNEL3_DIR=$KERNEL_DIR/anykernel
# Compiler cleanup
COMPILER_CLEANUP=true
# Cleanup
CLEANUP=true
# Release Repo
RELEASE_REMOTE=$(git remote)
RELEASE_REPO=$(git ls-remote --get-url $RELEASE_REMOTE)
# Files
IMAGE=$KERNEL_DIR/out/arch/arm64/boot/Image
DTBO=$KERNEL_DIR/out/arch/arm64/boot/dtbo.img
DTB=$KERNEL_DIR/out/arch/arm64/boot/dtb
# Verbose Build
VERBOSE=0
# Kernel Version
KERVER=$(make kernelversion)
# Specify Final Zip Name
ZIPNAME=Meteoric
# Zip version
VERSION=$(cat $KERNEL_DIR/Version)
# Specify compiler
COMPILER=neutron
# Sigint detection
SIGINT_DETECT=0
# Start build
BUILD_START=$(date +"%s")
nocol='\033[0m'
red='\033[0;31m'
green='\033[0;32m'
orange='\033[0;33m'
blue='\033[0;34m'
magenta='\033[0;35m'
cyan='\033[0;36m'
# Startup
echo -e "$cyan***********************************************"
echo " STARTING THE ENGINE "
echo -e "***********************************************$nocol"
##----------------------------------------------------------##
# Clone ToolChain
function cloneTC() {
case $COMPILER in
proton)
if [ $COMPILER_CLEANUP = true ]; then
rm -rf ~/meteoric/neutron-clang
fi
if [ $(ls $HOME/meteoric/proton-clang 2>/dev/null | wc -l) -ne 0 ]; then
PATH="$HOME/meteoric/proton-clang/bin:$PATH"
else
git clone --depth=1 https://github.com/kdrag0n/proton-clang.git ~/meteoric/proton-clang
PATH="$HOME/meteoric/proton-clang/bin:$PATH"
fi
;;
neutron)
if [ $COMPILER_CLEANUP = true ]; then
rm -rf ~/meteoric/proton-clang
fi
if [ $(ls $HOME/meteoric/neutron-clang/bin 2>/dev/null | wc -l ) -ne 0 ] &&
[ $(find $HOME/meteoric/neutron-clang -name *.tar.zst | wc -l) -eq 0 ]; then
PATH="$HOME/meteoric/neutron-clang/bin:$PATH"
else
rm -rf ~/meteoric/neutron-clang
mkdir -p ~/meteoric/neutron-clang
cd ~/meteoric/neutron-clang || exit
curl -LO "https://raw.githubusercontent.com/Neutron-Toolchains/antman/main/antman"
chmod a+x antman
./antman -S
cd - || exit
PATH="$HOME/meteoric/neutron-clang/bin:$PATH"
fi
;;
esac
}
##------------------------------------------------------##
# Export Variables
function exports() {
# Export KBUILD_COMPILER_STRING
export KBUILD_COMPILER_STRING=$($HOME/meteoric/$COMPILER-clang/bin/clang --version | head -n 1 | perl -pe 's/\(http.*?\)//gs' | sed -e 's/ */ /g' -e 's/[[:space:]]*$//')
# Export ARCH and SUBARCH
export ARCH=arm64
export SUBARCH=arm64
# Export KBUILD HOST and USER
export KBUILD_BUILD_HOST=Neoteric
export KBUILD_BUILD_USER=HELLBOY017
# Export PROCS and DISTRO
export PROCS=$(nproc --all)
export DISTRO=$(source /etc/os-release && echo "$NAME")
}
##----------------------------------------------------------##
# Sigint handler
function sigint() {
SIGINT_DETECT=1
}
##----------------------------------------------------------##
# Compilation choices
function choices() {
echo -e "$green***********************************************"
echo " BUILDING KERNEL "
echo -e "***********************************************$nocol"
# KernelSU
read -p "Include KernelSU? If unsure, say N. (Y/N) " KSU_RESP
case $KSU_RESP in
[yY] )
if [ $(ls $KERNEL_DIR/KernelSU 2>/dev/null | wc -l) -eq 0 ]; then
rm -rf $KERNEL_DIR/KernelSU
git submodule update --init --recursive KernelSU
else
ZIPNAME=Meteoric-KernelSU
KSU_CONFIG=ksu.config
if [ $(grep -c "KSU" arch/arm64/configs/$DEFCONFIG) -eq 0 ]; then
sed -i "s/-Meteoric/-Meteoric-$VERSION-KSU/" arch/arm64/configs/$DEFCONFIG
fi
fi
;;
*)
if [ $(grep -c $VERSION arch/arm64/configs/$DEFCONFIG) -eq 0 ]; then
sed -i "s/-Meteoric/-Meteoric-$VERSION/" arch/arm64/configs/$DEFCONFIG
fi
;;
esac
# Clean build
read -p "Do you want to do a clean build? If unsure, say N. (Y/N) " CLEAN_RESP
case $CLEAN_RESP in
[yY] )
make O=out clean && make O=out mrproper
;;
esac
# Interrupt detected
if [ $SIGINT_DETECT -eq 1 ]; then
if [ $(grep -c "KSU" arch/arm64/configs/$DEFCONFIG) -ne 0 ]; then
sed -i "s/-Meteoric-$VERSION-KSU/-Meteoric/" arch/arm64/configs/$DEFCONFIG
elif [ $(grep -c $VERSION arch/arm64/configs/$DEFCONFIG) -ne 0 ]; then
sed -i "s/-Meteoric-$VERSION/-Meteoric/" arch/arm64/configs/$DEFCONFIG
fi
exit
fi
}
##----------------------------------------------------------##
# Compilation process
function compile() {
# Make kernel
make O=out CC=clang ARCH=arm64 $DEFCONFIG $KSU_CONFIG savedefconfig
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- \
AR=llvm-ar \
NM=llvm-nm \
OBJCOPY=llvm-objcopy \
OBJDUMP=llvm-objdump \
STRIP=llvm-strip \
V=$VERBOSE 2>&1 | tee out/error.log
# KernelSU
if [ $ZIPNAME = Meteoric-KernelSU ]; then
sed -i 's/CONFIG_KSU=y/# CONFIG_KSU is not set/g' out/.config
sed -i '/CONFIG_KSU=y/d' out/defconfig
sed -i "s/-Meteoric-$VERSION-KSU/-Meteoric/" out/defconfig out/.config arch/arm64/configs/$DEFCONFIG
if [ $(grep -c "# KernelSU" arch/arm64/configs/$DEFCONFIG) -eq 1 ]; then
sed -i 's/CONFIG_KSU=y/# CONFIG_KSU is not set/g' arch/arm64/configs/$DEFCONFIG
else
sed -i '/CONFIG_KSU=y/d' arch/arm64/configs/$DEFCONFIG
fi
else
sed -i "s/-Meteoric-$VERSION/-Meteoric/" out/defconfig out/.config arch/arm64/configs/$DEFCONFIG
fi
# Verify build
if [ $(grep -c "Error 2" out/error.log) -ne 0 ] || [ $SIGINT_DETECT -eq 1 ]; then
echo ""
echo -e "$red***********************************************"
echo " KERNEL COMPILATION FAILED "
echo -e "***********************************************$nocol"
exit 1
else
echo -e "$green***********************************************"
echo " KERNEL COMPILATION FINISHED "
echo -e "***********************************************$nocol"
fi
}
##----------------------------------------------------------##
function zipping() {
# Copying kernel essentials
cp $IMAGE $DTBO $DTB $ANYKERNEL3_DIR
echo -e "$magenta***********************************************"
echo " Time to zip up! "
echo -e "***********************************************$nocol"
# Cleanup
if [ $CLEANUP = true ]; then
rm -rf out/*.zip
fi
# Make zip and transfer it to out directory
cd $ANYKERNEL3_DIR/
FINAL_ZIP=$ZIPNAME-$VERSION-$(date +%y%m%d-%H%M).zip
zip -r9 "../out/$FINAL_ZIP" * -x README $FINAL_ZIP
# Clean AnyKernel3 directory
cd ..
rm -rf $ANYKERNEL3_DIR/Image $ANYKERNEL3_DIR/Image.* $ANYKERNEL3_DIR/dtbo.img $ANYKERNEL3_DIR/dtb
if [ $(find out/ -name $FINAL_ZIP | wc -l) -ne 0 ]; then
echo -e "$orange***********************************************"
echo " Done, here is your sha1 "
echo -e "***********************************************$nocol"
sha1sum out/$FINAL_ZIP
# Github release
read -p "Do you want to do a github release? If unsure, say N. (Y/N) " GIT_RESP
case $GIT_RESP in
[yY] )
gh release create $VERSION out/$FINAL_ZIP --repo $RELEASE_REPO --title Meteoric-$VERSION
;;
*)
read -p "Do you want to upload files to the current github release? If unsure, say N. (Y/N) " UPLOAD_RESP
case $UPLOAD_RESP in
[yY] )
gh release upload $VERSION out/$FINAL_ZIP --repo $RELEASE_REPO
;;
esac
;;
esac
echo -e "$cyan***********************************************"
echo " All done !! "
echo -e "***********************************************$nocol"
else
echo ""
echo -e "$red***********************************************"
echo " ZIPPING FAILED! "
echo -e "***********************************************$nocol"
exit 1
fi
}
##----------------------------------------------------------##
cloneTC
exports
trap sigint SIGINT
choices
compile
trap - SIGINT
BUILD_END=$(date +"%s")
DIFF=$(($BUILD_END - $BUILD_START))
echo -e "$blue Build completed in $(($DIFF / 60)) minute(s) and $(($DIFF % 60)) seconds.$nocol"
if [ $(ls $ANYKERNEL3_DIR 2>/dev/null | wc -l) -ne 0 ]; then
zipping
else
echo -e "$red#############################################################################################"
echo "# IN ORDER TO MAKE A KERNEL ZIP MAKE SURE THAT ANYKERNEL3 IS ADDED IN THE CORRECT DIRECTORY #"
echo "# REFER TO THE ANYKERNEL3_DIR VARIABLE FOR THE CORRECT DIRECTORY #"
echo -e "#############################################################################################$nocol"
exit 1
fi
##----------------------------------------------------------##