forked from vantoman/kernel_xiaomi_sm6150
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmk.sh
188 lines (172 loc) · 4.98 KB
/
mk.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
#!/bin/bash
#
# Compile script for FuAnDo Raphael kernel
# Copyright (C) 2020-2021 Adithya R.
# Copyright (C) 2021-2022 @LeCmnGend.
#
# Download needed files
KERNEL_DIR=`pwd`
CLANG="neutron"
TC_BRANCH="18"
TC_DIR="$HOME/courbet/clang-$CLANG"
AK3_URL="https://github.com/meloalfa159/AnyKernel3.git"
AK3_BRANCH="master"
AK3_DIR="$HOME/courbet/anykernel"
# Check if AK3 exist
if ! [ -d "$AK3_DIR" ]; then
echo "$AK3_DIR not found! Cloning to $AK3_DIR..."
if ! git clone -q --single-branch --depth 1 -b $AK3_BRANCH $AK3_URL $AK3_DIR; then
echo "Cloning failed! Aborting..."
exit 1
fi
else
echo "$AK3_DIR found! Update $AK3_DIR"
cd $AK3_DIR
git pull
cd $KERNEL_DIR
fi
# Setup environment
DEFCONFIG="courbet_defconfig"
SECONDS=0 # builtin bash timer
ZIPNAME="AlfaKernel-melo159-$(git describe --abbrev=0 --tags)-$(date '+%Y%m%d-%H%M').zip"
export PROC="-j8"
# Setup ccache environment
export USE_CCACHE=1
export CCACHE_EXEC=/usr/local/bin/ccache
CROSS_COMPILE+="ccache clang"
# Toolchain environtment
export PATH="$TC_DIR/bin:$PATH"
export THINLTO_CACHE_DIR="/mnt/d/.ccache/ltocache/"
export KBUILD_COMPILER_STRING="$($TC_DIR/bin/clang --version | head -n 1 | perl -pe 's/\((?:http|git).*?\)//gs' | sed -e 's/ */ /g' -e 's/[[:space:]]*$//' -e 's/^.*clang/clang/')"
export STRIP="$TC_DIR/bin/$(echo "$(find "$TC_DIR/bin" -type f -name "aarch64-*-gcc")" | awk -F '/' '{print $NF}' | sed -e 's/gcc/strip/')"
# Kernel Details
KERNEL_VER="$(date '+%Y%m%d-%H%M')"
OUT="$HOME/courbet/kernel-out"
function clean_all {
cd $KERNEL_DIR
echo
rm -rf prebuilt
rm -rf out && rm -rf $OUT
}
if [ -d "$OUT" ]; then
while read -p "Do you want to clean stuffs (y/n)? " cchoice
do
case "$cchoice" in
y|Y )
clean_all
echo
echo "All Cleaned now."
break
;;
n|N )
echo
break
;;
* )
echo
echo "Invalid try again!"
echo
;;
esac
done
fi
# Delete old file before build
if [[ $1 = "-c" || $1 = "--clean" ]]; then
rm -rf $OUT
fi
# Make out folder
mkdir -p $HOME/courbet/kernel-out
make $PROC O=$OUT ARCH=arm64 $DEFCONFIG \
CLANG_PATH=$TC_DIR/bin \
CC="ccache clang" \
CXX="ccache clang++" \
HOSTCC="ccache clang" \
HOSTCXX="ccache clang++" \
LD=ld.lld \
AR=llvm-ar \
AS=llvm-as \
NM=llvm-nm \
OBJCOPY=llvm-objcopy \
OBJDUMP=llvm-objdump \
STRIP=llvm-strip \
CROSS_COMPILE="aarch64-linux-gnu-" \
CROSS_COMPILE_COMPAT=arm-linux-gnueabi- \
CROSS_COMPILE_ARM32=arm-linux-gnueabi-
# Regened defconfig
# Test use ccache. -j$(nproc --all)
if [[ $1 == "-r" || $1 == "--regen" ]]; then
cp $OUT/.config arch/arm64/configs/$DEFCONFIG
echo -e "\nRegened defconfig succesfully!"
exit 0
else
echo -e "\nStarting compilation...\n"
make $PROC O=$OUT ARCH=arm64 \
CLANG_PATH=$TC_DIR/bin \
CC="ccache clang" \
CXX="ccache clang++" \
HOSTCC="ccache clang" \
HOSTCXX="ccache clang++" \
LD=ld.lld \
AR=llvm-ar \
AS=llvm-as \
NM=llvm-nm \
OBJCOPY=llvm-objcopy \
OBJDUMP=llvm-objdump \
STRIP=llvm-strip \
CROSS_COMPILE="aarch64-linux-gnu-" \
CROSS_COMPILE_COMPAT=arm-linux-gnueabi- \
CROSS_COMPILE_ARM32=arm-linux-gnueabi-
fi
# Creating zip flashable file
function create_zip {
#Copy AK3 to out/Anykernel3
cp -r $AK3_DIR AnyKernel3
cp $OUT/arch/arm64/boot/Image.gz AnyKernel3
cp $OUT/arch/arm64/boot/dtbo.img AnyKernel3
cp $OUT/arch/arm64/boot/dtb.img AnyKernel3
# Change dir to AK3 to make zip kernel
cd AnyKernel3
zip -r9 "../$ZIPNAME" * -x '*.git*' README.md *placeholder
#Back to out folder and clean
cd ..
rm -rf AnyKernel3
rm -rf $OUT/arch/arm64/boot ##keep boot to compile rom
echo -e "\nCompleted in $((SECONDS / 60)) minute(s) and $((SECONDS % 60)) second(s) !"
echo "Zip: $ZIPNAME"
}
function create_prebuilt {
#Copy Image.gz and dtbo.img to prebuilt folder
mkdir -p prebuilt
cp $OUT/arch/arm64/boot/Image.gz prebuilt
cp $OUT/arch/arm64/boot/dtbo.img prebuilt
cp $OUT/arch/arm64/boot/dtb.img prebuilt
}
if [ -f "$OUT/arch/arm64/boot/Image.gz" ] && [ -f "$OUT/arch/arm64/boot/dtbo.img" ]; then
echo -e "\nKernel compiled succesfully!\n"
while read -p "Do you want to create Zip file (y) or prebuilt (p)? (y/n/p) " cchoice
do
case "$cchoice" in
y|Y )
create_zip
echo -e "\nDone !"
break
;;
n|N )
echo -e "\nCompleted in $((SECONDS / 60)) minute(s) and $((SECONDS % 60)) second(s) !"
break
;;
p|P )
create_prebuilt
echo -e "\nCompleted in $((SECONDS / 60)) minute(s) and $((SECONDS % 60)) second(s) !"
break
;;
* )
echo
echo "Invalid try again!"
echo
;;
esac
done
else
echo -e "\nFailed!"
fi