forked from Jebaitedneko/android_kernel_xiaomi_vayu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·133 lines (121 loc) · 3.78 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
#!/bin/bash
# Initialize variables
GRN='\033[01;32m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
RED='\033[01;31m'
RST='\033[0m'
ORIGIN_DIR=$(pwd)
TOOLCHAIN=$ORIGIN_DIR/build-shit
IMAGE=$ORIGIN_DIR/out/arch/arm64/boot/Image
DEVICE=nabu
CONFIG="${DEVICE}_defconfig"
MAKE+=(
-j$(($(nproc)+1)) \
O=out \
CROSS_COMPILE=aarch64-elf- \
CROSS_COMPILE_ARM32=arm-eabi- \
HOSTCC=gcc \
HOSTCXX=aarch64-elf-g++ \
CC=aarch64-elf-gcc \
LD=ld.lld
)
# export environment variables
export_env_vars() {
export KBUILD_BUILD_USER=Const
export KBUILD_BUILD_HOST=Coccinelle
export ARCH=arm64
# CCACHE
export USE_CCACHE=1
export CCACHE_SLOPPINESS="file_macro,locale,time_macros"
export CCACHE_NOHASHDIR="true"
}
script_echo() {
echo " $1"
}
exit_script() {
kill -INT $$
}
add_deps() {
echo -e "${CYAN}"
if [ ! -d "$TOOLCHAIN" ]
then
script_echo "Create build-shit folder"
mkdir "$TOOLCHAIN"
fi
if [ ! -d "$TOOLCHAIN/gcc-arm64" ]
then
script_echo "Downloading toolchain...."
cd "$TOOLCHAIN" || exit
git clone https://github.com/KenHV/gcc-arm64.git --single-branch -b master --depth=1 2>&1 | sed 's/^/ /'
git clone https://github.com/KenHV/gcc-arm.git --single-branch -b master --depth=1 2>&1 | sed 's/^/ /'
cd ../
fi
verify_toolchain_install
}
verify_toolchain_install() {
script_echo " "
if [[ -d "${TOOLCHAIN}" ]]; then
script_echo "I: Toolchain found at default location"
export PATH="${TOOLCHAIN}/gcc-arm64/bin:${PATH}:${TOOLCHAIN}/gcc-arm/bin:${PATH}"
else
script_echo "I: Toolchain not found"
script_echo " Downloading recommended toolchain at ${TOOLCHAIN}..."
add_deps
fi
}
build_kernel_image() {
cleanup
script_echo " "
echo -e "${GRN}"
read -p "Write the Kernel version: " KV
echo -e "${YELLOW}"
script_echo "Building CosmicFresh Kernel For $DEVICE"
make "${MAKE[@]}" LOCALVERSION="—CosmicFresh-R$KV" $CONFIG 2>&1 | sed 's/^/ /'
echo -e "${YELLOW}"
make "${MAKE[@]}" LOCALVERSION="—CosmicFresh-R$KV" 2>&1 | sed 's/^/ /'
SUCCESS=$?
echo -e "${RST}"
if [ $SUCCESS -eq 0 ] && [ -f "$IMAGE" ]
then
echo -e "${GRN}"
script_echo "------------------------------------------------------------"
script_echo "Compilation successful..."
script_echo "Image can be found at out/arch/arm64/boot/Image"
script_echo "------------------------------------------------------------"
build_flashable_zip
elif [ $SUCCESS -eq 130 ]
then
echo -e "${RED}"
script_echo "------------------------------------------------------------"
script_echo "Build force stopped by the user."
script_echo "------------------------------------------------------------"
echo -e "${RST}"
elif [ $SUCCESS -eq 1 ]
then
echo -e "${RED}"
script_echo "------------------------------------------------------------"
script_echo "Compilation failed.."
script_echo "------------------------------------------------------------"
echo -e "${RST}"
cleanup
fi
}
build_flashable_zip() {
script_echo " "
script_echo "I: Building kernel image..."
echo -e "${GRN}"
cp "$ORIGIN_DIR"/out/arch/arm64/boot/{Image,dtbo.img} CosmicFresh/
cp "$ORIGIN_DIR"/out/arch/arm64/boot/dtb.img CosmicFresh/dtb
cd "$ORIGIN_DIR"/CosmicFresh/ || exit
zip -r9 "CosmicFresh-R$KV-$DEVICE.zip" META-INF version anykernel.sh tools Image dtb dtbo.img
rm -rf {Image,dtb,dtbo.img}
cd ../
}
cleanup() {
rm -rf "$ORIGIN_DIR"/out/arch/arm64/boot/{Image,dt*}
rm -rf "$ORIGIN_DIR"/CosmicFresh/{Image,*.zip,dt*}
}
add_deps
export_env_vars
build_kernel_image