forked from Panchajanya1999/myscripts
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathgcc.sh
More file actions
165 lines (126 loc) · 4.76 KB
/
gcc.sh
File metadata and controls
165 lines (126 loc) · 4.76 KB
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
#! /bin/bash
# Script For Building Android arm64 Kernel
#
# Copyright (c) 2018-2020 Panchajanya1999 <rsk52959@gmail.com>
#
# 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
}
##------------------------------------------------------##
##----------Basic Informations, COMPULSORY--------------##
# The defult directory where the kernel should be placed
KERNEL_DIR=$PWD
# The name of the Kernel, to name the ZIP
ZIPNAME="SiLonT-TEST"
# The codename of the device
DEVICE="whyred"
# The defconfig which should be used. Get it from config.gz from
# your device or check source
DEFCONFIG=whyred_defconfig
##------------------------------------------------------##
##---------Do Not Touch Anything Beyond This------------##
## Set defaults first
CI_BRANCH=$(git rev-parse --abbrev-ref HEAD)
token=$TELEGRAM_TOKEN
export KBUILD_BUILD_HOST CI_BRANCH
## Export CI Env
export KBUILD_BUILD_VERSION=$DRONE_BUILD_NUMBER
export CI_BRANCH=$DRONE_BRANCH
export CHATID="-1001403511595"
#Check Kernel Version
KERVER=$(make kernelversion)
# Set a commit head
COMMIT_HEAD=$(git log --oneline -1)
#Now Its time for other stuffs like cloning, exporting, etc
clone() {
echo " "
msg "|| Cloning GCC ||"
git clone --depth=1 https://github.com/silont-project/aarch64-elf-gcc -b arm64/11 gcc64
git clone --depth=1 https://github.com/silont-project/arm-eabi-gcc -b arm/11 gcc32
GCC64_DIR=$KERNEL_DIR/gcc64
GCC32_DIR=$KERNEL_DIR/gcc32
msg "|| Cloning Anykernel ||"
git clone --depth 1 --no-single-branch https://github.com/Reinazhard/AnyKernel3.git -b master
}
##------------------------------------------------------##
exports() {
export KBUILD_BUILD_USER="reina"
export KBUILD_BUILD_HOST="Laptop-Sangar"
export ARCH=arm64
export SUBARCH=arm64
KBUILD_COMPILER_STRING=$("$GCC64_DIR"/bin/aarch64-elf-gcc --version | head -n 1)
PATH=$GCC64_DIR/bin/:$GCC32_DIR/bin/:/usr/bin:$PATH
export CROSS_COMPILE_ARM32=$GCC32_DIR/bin/arm-eabi-
export CROSS_COMPILE=$GCC64_DIR/bin/aarch64-elf-
export PATH KBUILD_COMPILER_STRING
export BOT_MSG_URL="https://api.telegram.org/bot$token/sendMessage"
export BOT_BUILD_URL="https://api.telegram.org/bot$token/sendDocument"
PROCS=$(nproc --all)
export PROCS
}
##---------------------------------------------------------##
tg_post_msg() {
curl -s -X POST "$BOT_MSG_URL" -d chat_id="$CHATID" \
-d "disable_web_page_preview=true" \
-d "parse_mode=html" \
-d text="$1"
}
##----------------------------------------------------------------##
tg_post_build() {
#Show the Checksum alongwith caption
curl --progress-bar -F document=@"$1" "$BOT_BUILD_URL" \
-F chat_id="$2" \
-F "disable_web_page_preview=true" \
-F "parse_mode=html" \
-F caption="$3 | <code>Build Number : </code><b>$DRONE_BUILD_NUMBER</b>"
}
##----------------------------------------------------------##
build_kernel() {
tg_post_msg "<b>🔨 $KBUILD_BUILD_VERSION CI Build Triggered</b>%0A<b>Kernel Version : </b><code>$KERVER</code>%0A<b>Date : </b><code>$(TZ=Asia/Jakarta date)</code>%0A<b>Compiler Used : </b><code>$KBUILD_COMPILER_STRING</code>%0a<b>Branch : </b><code>$CI_BRANCH</code>%0A<b>Top Commit : </b><a href='$DRONE_COMMIT_LINK'>$COMMIT_HEAD</a>" "$CHATID"
msg "|| Started Compilation ||"
BUILD_START=$(date +"%s")
make O=out $DEFCONFIG
make -j"$PROCS" O=out
BUILD_END=$(date +"%s")
DIFF=$((BUILD_END - BUILD_START))
if [ -f "$KERNEL_DIR"/out/arch/arm64/boot/Image.gz-dtb ]
then
msg "|| Kernel successfully compiled ||"
gen_zip
else
tg_post_msg "<b>❌ Build failed to compile after $((DIFF / 60)) minute(s) and $((DIFF % 60)) seconds</b>" "$CHATID"
fi
}
##--------------------------------------------------------------##
gen_zip() {
msg "|| Zipping into a flashable zip ||"
mv "$KERNEL_DIR"/out/arch/arm64/boot/Image.gz-dtb AnyKernel3/Image.gz-dtb
cd AnyKernel3 || exit
zip -r9 $ZIPNAME-$DEVICE-"$DRONE_BUILD_NUMBER" ./* -x .git README.md
## Prepare a final zip variable
ZIP_FINAL="$ZIPNAME-$DEVICE-$DRONE_BUILD_NUMBER.zip"
tg_post_build "$ZIP_FINAL" "$CHATID" "✅ Build took : $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)"
cd ..
}
clone
exports
build_kernel
##----------------*****-----------------------------##