forked from hmtheboy154/android_kernel_oneplus_sm7250
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·226 lines (180 loc) · 5.75 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
#! /bin/bash
# Script For Building Android arm64 Kernel
#
# Copyright (c) 2018-2020 Panchajanya1999 <[email protected]>
# Copyright (c) 2019-2020 iamsaalim <[email protected]>
# Copyright (c) 2021 Amol Amrit <[email protected]>
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#Kernel building script
# Function to show an informational message
msg() {
echo -e "\e[1;32m$*\e[0m"
}
err() {
echo -e "\e[1;41m$*\e[0m"
exit 1
}
# Constants
green='\033[01;32m'
red='\033[01;31m'
blink_red='\033[05;31m'
cyan='\033[0;36m'
yellow='\033[0;33m'
blue='\033[0;34m'
default='\033[0m'
##--------------------------------------------------------##
##----------Basic Informations and Variables--------------##
# The defult directory where the kernel should be placed
KERNEL_DIR=$PWD
# Kernel Version
VERSION="alpha"
# The name of the device for which the kernel is built
#MODEL="OnePlus Nord"
# The codename of the device
DEVICE="avicii"
# The defconfig which should be used. Get it from config.gz from
# your device or check source
DEFCONFIG=vendor/lito-perf_defconfig
# Specify compiler.
# 'clang' or 'gcc'
COMPILER=clang
# Clean source prior building. 1 is NO(default) | 0 is YES
INCREMENTAL=0
# Generate a full DEFCONFIG prior building. 1 is YES | 0 is NO(default)
DEF_REG=1
# Build dtbo.img (select this only if your source has support to building dtbo.img)
# 1 is YES | 0 is NO(default)
BUILD_DTBO=0
# Silence the compilation
# 1 is YES(default) | 0 is NO
SILENCE=0
# The name of the Kernel, to name the ZIP
ZIPNAME="Stormbreaker-r3c0nf1gur3d-$VERSION"
# Set Date and Time Zone
DATE=$(TZ=Asia/Ho_Chi_Minh date +"%Y%m%d-%T")
##----------------------------------------------------------------------------------##
##----------Now Its time for other stuffs like cloning, exporting, etc--------------##
clone() {
echo " "
if [ $COMPILER = "clang" ]
then
msg "|| Cloning Proton Clang-13 ||"
git clone --depth=1 https://github.com/kdrag0n/proton-clang.git /src/clang-llvm
# Toolchain Directory defaults to clang-llvm
TC_DIR=/src/clang-llvm
elif [ $COMPILER = "gcc" ]
then
msg "|| Cloning GCC 9.3.0 baremetal ||"
git clone --depth=1 https://github.com/arter97/arm64-gcc.git gcc64
git clone --depth=1 https://github.com/arter97/arm32-gcc.git gcc32
GCC64_DIR=$KERNEL_DIR/gcc64
GCC32_DIR=$KERNEL_DIR/gcc32
fi
msg "|| Cloning libufdt ||"
git clone https://android.googlesource.com/platform/system/libufdt /src/libufdt
}
##----------------------------------------------------------------------------##
##----------Export more variables --------------------------------------------##
exports() {
export KBUILD_BUILD_USER="HMTheBoy154"
export KBUILD_BUILD_HOST="jenkins"
export ARCH=arm64
export SUBARCH=arm64
if [ $COMPILER = "clang" ]
then
KBUILD_COMPILER_STRING=$("$TC_DIR"/bin/clang --version | head -n 1 | perl -pe 's/\(http.*?\)//gs' | sed -e 's/ */ /g' -e 's/[[:space:]]*$//')
PATH=$TC_DIR/bin/:$PATH
elif [ $COMPILER = "gcc" ]
then
KBUILD_COMPILER_STRING=$("$GCC64_DIR"/bin/aarch64-elf-gcc --version | head -n 1)
PATH=$GCC64_DIR/bin/:$GCC32_DIR/bin/:/usr/bin:$PATH
fi
export PATH KBUILD_COMPILER_STRING
PROCS=$(nproc --all)
export PROCS
}
##---------------------------------------------------------##
##--------------------Now Build it-------------------------##
build_kernel() {
if [ $INCREMENTAL = 0 ]
then
msg "|| Cleaning Sources ||"
make clean && make mrproper && rm -rf out && rm -rf AnyKernel3/Image && rm -rf AnyKernel3/*.zip
fi
make O=out $DEFCONFIG
BUILD_START=$(date +"%s")
if [ $COMPILER = "clang" ]
then
MAKE+=(
CROSS_COMPILE=aarch64-linux-gnu- \
CROSS_COMPILE_ARM32=arm-linux-gnueabi- \
CC=clang \
AR=llvm-ar \
OBJDUMP=llvm-objdump \
STRIP=llvm-strip \
DTC_EXT=$KERNEL_DIR/dtc
)
elif [ $COMPILER = "gcc" ]
then
MAKE+=(
CROSS_COMPILE_ARM32=arm-eabi- \
CROSS_COMPILE=aarch64-elf- \
AR=aarch64-elf-ar \
OBJDUMP=aarch64-elf-objdump \
STRIP=aarch64-elf-strip
)
fi
if [ $SILENCE = "1" ]
then
MAKE+=( -s )
fi
msg "|| Started Compilation ||"
make -j"$PROCS" O=out \
NM=llvm-nm \
OBJCOPY=llvm-objcopy \
LD=ld.lld "${MAKE[@]}" 2>&1
if [ -f "$KERNEL_DIR"/out/arch/arm64/boot/Image ]
then
msg "|| Kernel successfully compiled ||"
if [ $BUILD_DTBO = 1 ]
then
msg "|| Building DTBO ||"
python2 "/src/libufdt/utils/src/mkdtboimg.py" \
create "$KERNEL_DIR/out/arch/arm64/boot/dtbo.img" --page_size=4096 "$KERNEL_DIR/out/arch/arm64/boot/dts/vendor/qcom/avicii-overlay-dvt.dtbo"
fi
gen_zip
fi
}
##-----------------------------------------------------------##
##--------------Compile AnyKernel Zip------------------------##
gen_zip() {
msg "|| Zipping into a flashable zip ||"
mv "$KERNEL_DIR"/out/arch/arm64/boot/Image AnyKernel3/Image
cd AnyKernel3 || exit
zip -r9 $ZIPNAME-$DEVICE-$DATE.zip * -x .git README.md
##-----------------Uploading-------------------------------##
msg "|| Uploading ||"
cp *.zip /var/www/html/builds/avicii/Stormbreaker
cd ..
}
clone
exports
build_kernel
# Build complete
BUILD_END=$(date +"%s")
DIFF=$(($BUILD_END - $BUILD_START))
echo -e "$green Build completed in $(($DIFF / 60)) minute(s) and $(($DIFF % 60)) seconds.$default"
##----------------*****-----------------------------##