-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.sh
executable file
·436 lines (367 loc) · 9.89 KB
/
1.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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
#!/bin/bash
pwd=$PWD
DATE=$(date +'%d-%m-%Y')
BUILD_START=$(date +"%s")
blue='\033[0;34m'
cyan='\033[0;36m'
yellow='\033[0;33m'
red='\033[0;31m'
nocol='\033[0m'
echo -e "$red\n ##----------------------------------------------------------------------------##$nocol\n"
echo -e "$blue\n #### ## ## ## ## ####### ######## ######## ### ## "
echo -e " ## ### ### ### ### ## ## ## ## ## ## ## ## "
echo -e " ## #### #### #### #### ## ## ## ## ## ## ## ## "
echo -e " ## ## ### ## ## ### ## ## ## ######## ## ## ## ## "
echo -e " ## ## ## ## ## ## ## ## ## ## ######### ## "
echo -e " ## ## ## ## ## ## ## ## ## ## ## ## ## "
echo -e " #### ## ## ## ## ####### ## ## ## ## ## ########$nocol"
echo -e "$red\n ##----------------------------------------------------------------------------##$nocol\n"
#################
#==[ Export ]===#
#################
#===[ Most Editable ]===#
DEFCONFIG=akame_defconfig
NKD=AkameKernel-begonia
CODENAME=begonia
GCC_or_CLANG=1
BUILD_KH=2
ONLY_BUILD_KH=1
ONLY_BUILD_AN=1
IMAGE=Image.gz-dtb
VER="-11"
ANDROID=Q
COMPILE="$IMAGE modules_install dtb dtbo.img"
#===[ Editable ]===#
#export USE_CCACHE=1
#export CCACHE_DIR=~/.ccache
JOBS="-j14"
#===[ Standart ]===#
export HOST_ARCH=$(arch)
ANYKERNEL_DIR=AnyKernel3
OUT_DIR=out
ARCH=arm64
SUBARCH=$ARCH
UN=$HOME/kernels
CONFIG=".config"
LOG="2>&1 | tee log.txt"
KBUILD_BUILD_USER=Anonym3310
KBUILD_KVER="-AkameKernel"
KBUILD_BUILD_HOST=anonym3310
KERNEL_MAKE_ENV="DTC_EXT=/usr/bin/dtc CONFIG_BUILD_ARM64_DT_OVERLAY=y"
CLANG_VAL="OBJCOPY=llvm-objcopy${VER} \
OBJDUMP=llvm-objdump${VER} \
STRIP=llvm-strip${VER} \
NM=llvm-nm${VER} \
AR=llvm-ar${VER} \
AS=llvm-as${VER}"
LD=ld.lld${VER}
VALUES="${LD} #$KERNEL_MAKE_ENV #$CLANG_VAL"
#########################
#===[ Smart Exports ]===#
#########################
if [ "$GCC_or_CLANG" -eq "1" ]
####-------####
#===[ GCC ]===#
####-------####
then
#===[ Most Editable ]===#
CC=aarch64-zyc-linux-gnu-gcc
GCC_PATH64=/root/kernels/aarch64-zyc-linux-gnu
GCC_PATH32=/root/kernels/arm-zyc-linux-gnueabi
GCC_BIN64=$GCC_PATH64/bin
GCC_BIN32=$GCC_PATH32/bin
#===[ Editable ]===#
GCC_PREF64=aarch64-zyc-linux-gnu
GCC_PREF32=arm-zyc-linux-gnueabi
GCC_PREFIX64=$GCC_PREF64-
GCC_PREFIX32=$GCC_PREF32-
GCC_LIB32=$GCC_PATH32/lib/$GCC_PREF32
GCC_LIB64=$GCC_PATH64/lib/$GCC_PREF64
#===[ Standart ]===#
GCC_LIBS=$GCC_LIB64:$GCC_LIB32
GCC_BINS=$GCC_BIN64:$GCC_BIN32
LD_LIBRARY_PATH=$GCC_LIBS:$LD_LIBRARY_PATH
PATH=$GCC_BINS:$PATH
CROSS_COMPILE=$GCC_PREFIX64
CROSS_COMPILE_ARM32=$GCC_PREFIX32
####---------####
#===[ Clang ]===#
####---------####
else
#===[ Most Editable ]===#
CC=clang${VER}
LLVM=llvm${VER}
CLANG_PATH1=/usr
CLANG_BIN=$CLANG_PATH1/lib/${LLVM}/bin
GCC_PATH64=/usr
GCC_PATH32=/usr
GCC_BIN64=$GCC_PATH64/bin
GCC_BIN32=$GCC_PATH32/bin
#===[ Editable ]===#
GCC_PREF64=aarch64-linux-gnu
GCC_PREF32=arm-linux-gnueabi
GCC_PREFIX64=aarch64-linux-gnu-
GCC_PREFIX32=arm-linux-gnueabi-
CLANG_LIB32=$CLANG_PATH1/lib/${LLVM}/lib
CLANG_LIB64=$CLANG_PATH1/lib/${LLVM}/lib64
GCC_LIB64=$GCC_PATH64/lib/$GCC_PREF64
GCC_LIB32=$GCC_PATH32/lib/$GCC_PREF32
#===[ Standart ]===#
GCC_BINS=$GCC_BIN64:$GCC_BIN32
GCC_LIBS=$GCC_LIB64:$GCC_LIB32
CLANG_LIBS=$CLANG_LIB64:$CLANG_LIB32
LD_LIBRARY_PATH=$CLANG_LIBS:$GCC_LIBS:$LD_LIBRARY_PATH
CLANG_PATH=${CLANG_BIN}
PATH=${CLANG_PATH}:${PATH}
CROSS_COMPILE=$GCC_PREFIX64
CLANG_TRIPLE=$GCC_PREFIX64
CROSS_COMPILE_ARM32=$GCC_PREFIX32
KBUILD_COMPILER_STRING="$(${CLANG_PATH}/clang --version | head -n 1 | perl -pe 's/\(http.*?\)//gs' | sed -e 's/ */ /g')"
fi
#======[ FUNCTIONS ]======#
buildtime()
{
BUILD_END=$(date +"%s")
DIFF=$(($BUILD_END - $BUILD_START))
echo -e "$blue Kernel compiled on $(($DIFF / 60)) minute(s) \
and $(($DIFF % 60)) seconds$nocol"
}
buildkernel()
{
echo -e "$yellow\n ##============================================================================##"
echo -e " ##========================= Build Kernel From Source =========================##"
echo -e " ##============================================================================##$nocol\n"
if [ "$GCC_or_CLANG" -eq "1" ]
####-------####
#===[ GCC ]===#
####-------####
then
make $DEFCONFIG $COMPILE \
CC=${CC} \
PATH=${PATH} \
CROSS_COMPILE=${CROSS_COMPILE} \
CROSS_COMPILE_ARM32=${CROSS_COMPILE_ARM32} \
ARCH=${ARCH} \
O=${OUT_DIR} \
INSTALL_MOD_PATH=. \
INSTALL_MOD_DIR=. \
${JOBS} \
${VALUES} \
${LOG}
####---------####
#===[ Clang ]===#
####---------####
else
make all modules $DEFCONFIG $COMPILE \
CC=${CC} \
CLANG_PATH=${CLANG_PATH} \
PATH=${PATH} \
CLANG_TRIPLE=${CLANG_TRIPLE} \
CROSS_COMPILE=${CROSS_COMPILE} \
CROSS_COMPILE_ARM32=${CROSS_COMPILE_ARM32} \
ARCH=${ARCH} \
O=${OUT_DIR} \
${JOBS} \
INSTALL_MOD_PATH=. \
INSTALL_MOD_DIR=. \
$VALUES \
${LOG}
fi
}
buildkh()
{
echo -e "$yellow\n ##============================================================================##"
echo -e " ##=========================== Build Kernel Headers ===========================##"
echo -e " ##============================================================================##$nocol\n"
if [ -f ${UN}/kernel-headers ]
then
rm -rf ${UN}/kernel-headers/kernel-headers/*
rm -rf ${UN}/kernel-headers-${CODENAME}.tar.xz
cp -r * ${UN}/kernel-headers/kernel-headers/
cd ${UN}/kernel-headers/kernel-headers/
else
git clone https://github.com/Anonym3310/kernel-headers --depth 1
rm ${UN}/kernel-headers/kernel-headers/*
cp -r * ${UN}/kernel-headers/kernel-headers/
cd ${UN}/kernel-headers/kernel-headers/
fi
if [ "$GCC_or_CLANG" -eq "1" ]
####-------####
#===[ GCC ]===#
####-------####
then
make $DEFCONFIG prepare modules_prepare vdso_prepare \
CC=${CC} \
PATH=${PATH} \
CROSS_COMPILE=${CROSS_COMPILE} \
CROSS_COMPILE_ARM32=${CROSS_COMPILE_ARM32} \
ARCH=${ARCH} \
${VALUES} \
${JOBS}
####---------####
#===[ Clang ]===#
####---------####
else
make $DEFCONFIG prepare modules_prepare vdso_prepare \
CC=${CC} \
CLANG_PATH=${CLANG_PATH} \
PATH=${PATH} \
CLANG_TRIPLE=${CLANG_TRIPLE} \
CROSS_COMPILE=${CROSS_COMPILE} \
CROSS_COMPILE_ARM32=${CROSS_COMPILE_ARM32} \
ARCH=${ARCH} \
${JOBS} \
$VALUES
fi
exit
mkdir ${UN}/tmp
KN=$(find ${OUT_DIR}/lib/modules/ -name modules.*)
cp -r arch/arm* Makefile ${OUT_DIR}/Module.symvers \
${KN} ${OUT_DIR}/scripts/mod/modpost ${OUT_DIR}/scripts/genksyms/genksyms \
include scripts drivers/misc /${UN}/tmp
rm -rf *
cp -r ${UN}/tmp/* $PWD
mv modpost scripts/mod/
mv genksyms scripts/genksyms/
rm -rf ${UN}/tmp
mkdir arch
cp -r arm* arch
rm -rf arm*
mkdir drivers
cp -r misc drivers
rm -rf misc
cd $UN/
sudo dpkg-deb --build kernel-headers kernel-headers-${CODENAME}.deb
ls -l kernel-headers-${CODENAME}.deb
buildtime
}
zipak3()
{
echo -e "$yellow\n ##============================================================================##"
echo -e " ##===================== Creating A Flashable *.zip Archive ===================##"
echo -e " ##============================================================================##$nocol\n"
cd ${UN}/${NKD}
rm -rf ${ANYKERNEL_DIR}
cp ${UN}/${ANYKERNEL_DIR} ${UN}/${NKD} -r
if [ "$GCC_or_CLANG" -eq "1" ]
####-------####
#===[ GCC ]===#
####-------####
then
make modules_install \
CC=${CC} \
PATH=${PATH} \
CROSS_COMPILE=${CROSS_COMPILE} \
CROSS_COMPILE_ARM32=${CROSS_COMPILE_ARM32} \
ARCH=${ARCH} \
O=${OUT_DIR} \
INSTALL_MOD_DIR=. \
${JOBS}
KERNEL_NAME=$(make kernelrelease \
CC=${CC} \
PATH=${PATH} \
CROSS_COMPILE=${CROSS_COMPILE} \
CROSS_COMPILE_ARM32=${CROSS_COMPILE_ARM32} \
ARCH=${ARCH} \
O=${OUT_DIR} \
INSTALL_MOD_PATH=. \
${VALUES} \
${JOBS})
####---------####
#===[ Clang ]===#
####---------####
else
make modules_install \
CC=${CC} \
CLANG_PATH=${CLANG_PATH} \
PATH=${PATH} \
CLANG_TRIPLE=${CLANG_TRIPLE} \
CROSS_COMPILE=${CROSS_COMPILE} \
CROSS_COMPILE_ARM32=${CROSS_COMPILE_ARM32} \
ARCH=${ARCH} \
O=${OUT_DIR} \
INSTALL_MOD_DIR=. \
${JOBS} \
$VALUES
KERNEL_NAME=$(make kernelrelease \
CC=${CC} \
CLANG_PATH=${CLANG_PATH} \
PATH=${PATH} \
CLANG_TRIPLE=${CLANG_TRIPLE} \
CROSS_COMPILE=${CROSS_COMPILE} \
CROSS_COMPILE_ARM32=${CROSS_COMPILE_ARM32} \
ARCH=${ARCH} \
O=${OUT_DIR} \
${JOBS} \
$VALUES)
fi
#===[ COPYNG ]===#
cd ${UN}/${NKD}/${OUT_DIR}
rm $(find lib/modules/ -name build)
rm $(find lib/modules/ -name source)
cp lib/modules/ -r ${UN}/${NKD}/${ANYKERNEL_DIR}/modules/system/lib/
cd firmware
#cp $(find -name *.bin) -r --parents ${UN}/${NKD}/${ANYKERNEL_DIR}/modules/system/etc/firmware
#cp $(find -name *.fw) -r --parents ${UN}/${NKD}/${ANYKERNEL_DIR}/modules/system/etc/firmware
cd ../../
#===( EDITABLE )===#
cp $(find -name ${IMAGE}) ${ANYKERNEL_DIR}/
cp $(find -name dtb) ${ANYKERNEL_DIR}/
cp $(find -name dtbo.img) ${ANYKERNEL_DIR}/
#===[ ZIPPING ]===#
cd ${UN}/${NKD}
if [ -f AK3 ]
then
cp -r AK3/* ${ANYKERNEL_DIR}
fi
cd ${ANYKERNEL_DIR}
zip -r -9 AkameKernel-${CODENAME}-${ANDROID}-$(date +%d-%m-%y).zip * \
-x .git README.md *placeholder
#===[ TIME BUILD ]===#
buildtime
}
ziptest()
{
if [ -f ${UN}/${NKD}/${OUT_DIR}/arch/arm64/boot/${IMAGE} ]
then
zipak3
else
echo ""
echo $red"Compilation failed"
echo $red"$IMAGE not builded"
echo ""
exit
fi
}
######################
#=[ START OF BUILD ]=#
######################
if [ "$ONLY_BUILD_AN" -eq "1" ]
then
if [ "$ONLY_BUILD_KH" -eq "1" ]
then
buildkernel
if [ "$BUILD_KH" -eq "1" ]
#####################
#===[ Biuild KH ]===#
#####################
then
buildkh
ziptest
#################
#===[Skip KH]===#
#################
else
ziptest
fi
#===[ END BUILD ]===#
#===[ ONLY BUILD KERNEL HEADERS ]===#
else
buildkh
fi
################################
#===[ ONLY_BUILD_ANYKERNEL ]===#
################################
else
ziptest
fi