-
Notifications
You must be signed in to change notification settings - Fork 5
/
clang.sh
executable file
·178 lines (138 loc) · 4.82 KB
/
clang.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
#!/usr/bin/env bash
# Copyright (C) 2018 Abubakar Yagob (blacksuan19)
# Copyright (C) 2018 Rama Bondan Prakoso (rama982)
# SPDX-License-Identifier: GPL-3.0-or-later
# Color
green='\033[0;32m'
echo -e "$green"
BUILD_START=$(date +"%s")
# Main Environment
KERNEL_DIR=$PWD
DATE=$(date +"%d-%m-%Y-%I-%M")
CORES=$(grep -c ^processor /proc/cpuinfo)
THREAD="-j$CORES"
KERN_IMG=$KERNEL_DIR/out/arch/arm64/boot/Image.gz-dtb
ZIP_DIR=$KERNEL_DIR/AnyKernel3
CROSS_COMPILE+="ccache clang"
CCACHE=true
# Modules environtment
OUTDIR="$PWD/out/"
SRCDIR="$PWD/"
MODULEDIR="$PWD/AnyKernel3/modules/system/lib/modules/"
PRIMA="$PWD/AnyKernel3/modules/vendor/lib/modules/wlan.ko"
PRONTO="$PWD/AnyKernel3/modules/vendor/lib/modules/pronto/pronto_wlan.ko"
STRIP="$PWD/vortex-clang/bin/$(echo "$(find "$PWD/vortex-clang/bin" -type f -name "aarch64-*-gcc")" | awk -F '/' '{print $NF}' |\
sed -e 's/gcc/strip/')"
# Main script
while true; do
echo -e "\n[1] Build Kernel"
echo -e "[2] Regenerate defconfig"
echo -e "[3] Source cleanup"
echo -e "[4] Create flashable zip"
echo -e "[5] Quit"
echo -ne "\n(i) Please enter a choice[1-5]: "
read choice
if [ "$choice" == "1" ]; then
echo -e "\n(i) Cloning toolcahins if folder not exist..."
git clone https://github.com/vijaymalav564/vortex-clang --depth=1
echo
echo "Issue Kernel Build Commands"
echo
mkdir -p out
export ARCH=arm64
export SUBARCH=arm64
export CLANG_PATH=$PWD/vortex-clang/bin
export PATH=${CLANG_PATH}:${PATH}
export CROSS_COMPILE=aarch64-linux-gnu-
export CROSS_COMPILE_ARM32=arm-linux-gnueabi-
export KBUILD_BUILD_USER=ꪜⅈ𝕛ꪖꪗꪑꪖꪶꪖꪜ
export KBUILD_BUILD_HOST=ᧁᥴꪶꪮꪊᦔ
echo
echo "Set DEFCONFIG"
echo
make CC='ccache clang -Qunused-arguments -fcolor-diagnostics' LD=ld.lld AR=llvm-ar NM=llvm-nm OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump STRIP=llvm-strip O=out RMX1801_defconfig
echo
echo "Starting Building Kernel"
echo
echo -e ""
make CC='ccache clang -Qunused-arguments -fcolor-diagnostics' LD=ld.lld AR=llvm-ar NM=llvm-nm OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump STRIP=llvm-strip O=out $THREAD
echo -e ""
DATE=`date`
echo -e "\n#######################################################################"
echo -e "(i) Build started at $DATE using $CORES thread"
spin[0]="-"
spin[1]="\\"
spin[2]="|"
spin[3]="/"
echo -ne "\n[Please wait...] ${spin[0]}"
while kill -0 $pid &>/dev/null
do
for i in "${spin[@]}"
do
echo -ne "\b$i"
sleep 0.1
done
done
if ! [ -a $KERN_IMG ]; then
echo -e "\n(!) Kernel compilation failed, See buildlog to fix errors"
echo -e "#######################################################################"
exit 1
fi
BUILD_END=$(date +"%s")
DIFF=$(($BUILD_END - $BUILD_START))
echo -e "\nImage-dtb compiled successfully."
echo -e "#######################################################################"
echo -e "Build completed in $(($DIFF / 60)) minute(s) and $(($DIFF % 60)) seconds."
echo -e "#######################################################################"
fi
if [ "$choice" == "2" ]; then
echo -e "\n#######################################################################"
make O=out $CONFIG savedefconfig &>/dev/null
cp out/defconfig arch/arm64/configs/$CONFIG &>/dev/null
echo -e "(i) Defconfig generated."
echo -e "#######################################################################"
fi
if [ "$choice" == "3" ]; then
echo -e "\n#######################################################################"
make O=out clean &>/dev/null
make mrproper &>/dev/null
rm -rf out/*
echo -e "(i) Kernel source cleaned up."
echo -e "#######################################################################"
fi
if [ "$choice" == "4" ]; then
echo -e "\n#######################################################################"
echo -e "\n(i) Cloning AnyKernel3 if folder not exist..."
git clone -b rmx1801 https://github.com/vijaymalav564/AnyKernel3.git
echo -e "\n(i) Strip and move modules to AnyKernel3..."
# thanks to @adekmaulana
cd $ZIP_DIR
make clean &>/dev/null
cd ..
for MOD in $(find "${OUTDIR}" -name '*.ko') ; do
"${STRIP}" --strip-unneeded --strip-debug "${MOD}" &> /dev/null
"${SRCDIR}"/scripts/sign-file sha512 \
"${OUTDIR}/signing_key.priv" \
"${OUTDIR}/signing_key.x509" \
"${MOD}"
find "${OUTDIR}" -name '*.ko' -exec cp {} "${MODULEDIR}" \;
case ${MOD} in
*/wlan.ko)
cp -ar "${MOD}" "${PRIMA}"
cp -ar "${MOD}" "${PRONTO}"
esac
done
echo -e "\n(i) Done moving modules"
rm $PWD/AnyKernel3/modules/system/lib/modules/wlan.ko
cd $ZIP_DIR
cp $KERN_IMG $ZIP_DIR/zImage
make normal &>/dev/null
cd ..
echo -e "Flashable zip generated under $ZIP_DIR."
echo -e "#######################################################################"
fi
if [ "$choice" == "5" ]; then
exit
fi
done
echo -e "$nc"