-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·114 lines (97 loc) · 3.02 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
#!/bin/bash
[ ! -e "KernelSU/kernel/setup.sh" ] && git submodule init && git submodule update
[ ! -d "toolchain" ] && echo "installing toolchain..." && bash init_clang.sh
export KBUILD_BUILD_USER=ghazzor
PATH=$PWD/toolchain/bin:$PATH
export LLVM_DIR=$PWD/toolchain/bin
export LLVM=1
export AnyKernel3=AnyKernel3
export TIME="$(date "+%Y%m%d")"
export modpath=${AnyKernel3}/modules/vendor/lib/modules
export ARCH=arm64
if [ -z "$DEVICE" ]; then
export DEVICE=g84
fi
if [[ -z "$KSU" || "$KSU" = "0" ]]; then
KSU=0
export KSUSTAT=
elif [ "$KSU" = "1" ]; then
CONFIG_KSU=ksu.config
export KSUSTAT=_KSU
else
echo "Error: Set KSU to 0 or 1 to build"
exit 1
fi
export KSU
if [[ -z "$T" || "$T" = "0" ]]; then
T=0
export testbld=
elif [ "$T" = "1" ]; then
CONFIG_TEST=test.config
export testbld=-test
else
echo "Error: Set KSU to 0 or 1 to build"
exit 1
fi
export T
if [[ -z "$1" || "$1" = "-c" ]]; then
echo "Clean Build"
rm -rf out
elif [ "$1" = "-d" ]; then
echo "Dirty Build"
else
echo "Error: Set $1 to -c or -d"
exit 1
fi
ARGS='
CC=clang
LD='${LLVM_DIR}/ld.lld'
ARCH=arm64
AR='${LLVM_DIR}/llvm-ar'
NM='${LLVM_DIR}/llvm-nm'
AS='${LLVM_DIR}/llvm-as'
OBJCOPY='${LLVM_DIR}/llvm-objcopy'
OBJDUMP='${LLVM_DIR}/llvm-objdump'
READELF='${LLVM_DIR}/llvm-readelf'
OBJSIZE='${LLVM_DIR}/llvm-size'
STRIP='${LLVM_DIR}/llvm-strip'
LLVM_AR='${LLVM_DIR}/llvm-ar'
LLVM_DIS='${LLVM_DIR}/llvm-dis'
LLVM_NM='${LLVM_DIR}/llvm-nm'
LLVM=1
'
make ${ARGS} O=out ${DEVICE}_defconfig moto.config $CONFIG_KSU $CONFIG_TEST
make ${ARGS} O=out -j$(nproc)
[ ! -e "out/arch/arm64/boot/Image" ] && \
echo " ERROR : image binary not found in any of the specified locations , fix compile!" && \
exit 1
make O=out ${ARGS} -j$(nproc) INSTALL_MOD_PATH=modules INSTALL_MOD_STRIP=1 modules_install
#Clean Up
rm -rf ${modpath}/*
rm -rf ${AnyKernel3}/{Image, dtb, dtbo.img}
rm -rf ${AnyKernel3}/*.zip
#Setup
mkdir -p ${modpath}
kver=$(make kernelversion)
kmod=$(echo ${kver} | awk -F'.' '{print $3}')
#Copy stuff
cp out/.config ${AnyKernel3}/config
cp out/arch/arm64/boot/Image ${AnyKernel3}/Image
cp out/arch/arm64/boot/dtb.img ${AnyKernel3}/dtb
cp out/arch/arm64/boot/dtbo.img ${AnyKernel3}/dtbo.img
#cp build.sta/${DEVICE}_modules.blocklist ${modpath}/modules.blocklist
cp $(find out/modules/lib/modules/5.4* -name '*.ko') ${modpath}/
cp out/modules/lib/modules/5.4*/modules.{alias,dep,softdep} ${modpath}/
cp out/modules/lib/modules/5.4*/modules.order ${modpath}/modules.load
#Edit
sed -i 's/\(kernel\/[^: ]*\/\)\([^: ]*\.ko\)/\/vendor\/lib\/modules\/\2/g' ${modpath}/modules.dep
#sed -i 's/.*\//.ko/g' ${AnyKernel3}/modules/vendor/lib/modules/modules.load
#sed -i 's#.*/##; s/\.ko$//' ${AnyKernel3}/modules/vendor/lib/modules/modules.load
sed -i 's/.*\///; s/\.ko$//' ${modpath}/modules.load
source build.sta/${DEVICE}_mdconf
for useles_modules in "${modules_to_nuke[@]}"; do
grep -vE "$useles_modules" ${modpath}/modules.load > /tmp/templd && mv /tmp/templd ${modpath}/modules.load
done
#Zip
cd ${AnyKernel3}
zip -r9 O_KERNEL.${kmod}_${DEVICE}${KSUSTAT}${testbld}-${TIME}.zip * -x .git README.md *placeholder