-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathakb
executable file
·452 lines (410 loc) · 14.5 KB
/
akb
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
#!/usr/bin/env bash
if [ -f /.dockerenv ]; then
echo "Welcome to AKB!"
else
echo "Please run inside a ubuntu bionic docker container!";
exit
fi
##############################################
### SET UP DEPENDENCIES
##############################################
function check_install() {
INSTALL_LIST=""
for A in $@
do
if [ $(dpkg-query -W -f='${Status}' $A 2>/dev/null | grep -c "ok installed") == 1 ]; then
echo "$A INSTALLED"
else
echo "$A NOT INSTALLED"
INSTALL_LIST="$INSTALL_LIST $A"
fi
done
if [ "$INSTALL_LIST" == "" ]; then
echo "NOTHING TO INSTALL"
else
echo "Install:$INSTALL_LIST"
apt update
apt install -y$INSTALL_LIST
fi
}
function check_repo() {
if [ ! -f "/usr/bin/repo" ]; then
check_install "curl"
curl https://storage.googleapis.com/git-repo-downloads/repo > /usr/bin/repo
chmod a+x /usr/bin/repo
fi
}
check_install "git ccache make gcc zip bc python"
# Avoid git nosense
git config --global user.name "example"
git config --global user.email [email protected]
##############################################
### RETRIEVE WORKDIR
##############################################
WORKDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "WORKDIR: $WORKDIR"
cd $WORKDIR
##############################################
### VARIABLES
##############################################
KERNEL_REPO=""
KERNEL_BRANCHES="master"
KERNEL_CONF=""
KERNEL_NAME=""
KERNEL_ARCH="arm64"
ZIP_SCRIPT="dummy"
# Toolchain config
GCC_PROVIDER="GOOGLE" # LOS GOOGLE
CLANG_PROVIDER="GOOGLE" # BENZO-BUILD PROTON-BUILD PROTON-PREBUILT LOLZ GOOGLE
GCC_ARM32_DIR="$WORKDIR/tools/gcc/arm32/bin"
GCC_ARM64_DIR="$WORKDIR/tools/gcc/arm64/bin"
CLANG_DIR="$WORKDIR/tools/clang/bin"
REPO_GCC_ARM64=""
REPO_GCC_ARM32=""
MAKE_ADDITIONAL=""
NEEDS_PACKAGES=""
CONF_CLANG_TRIPLE="aarch64-linux-gnu-"
CONF_CROSS_COMPILE="aarch64-linux-android-"
CONF_CROSS_COMPILE_ARM32="arm-linux-androideabi-"
# Load from file
if [ -f "kernel_templates/$1.config" ]; then
echo "Loading env: $1"
CONFIG_FILE=$1
. kernel_templates/$1.config
else
echo "$1 not found in kernel_templates"
exit
fi
if [ -f "_env" ]; then
echo "Loading _env"
. _env
fi
if [ "$NEEDS_PACKAGES" != "" ]; then
check_install "$NEEDS_PACKAGES"
fi
# Do not touch this variables if not needed
KERNEL_DIR="$WORKDIR/_kernel_$CONFIG_FILE"
CCACHE_DIR="$WORKDIR/_ccache"
BASE_OUT_DIR="$WORKDIR/_out_$CONFIG_FILE"
DIST_DIR="$WORKDIR/dist"
## Variables end
for VAR in KERNEL_REPO KERNEL_BRANCHES KERNEL_CONF KERNEL_NAME KERNEL_ARCH GCC_PROVIDER CLANG_PROVIDER KERNEL_DIR BASE_OUT_DIR DIST_DIR
do
echo "$VAR > ""${!VAR}"
TST="${!VAR}"
if [ "$TST" == "" ]; then
echo "Required variable $VAR is not set, aborting"
exit
fi
done
# Create dist dir
mkdir -p $DIST_DIR
##############################################
### ENV-TOOLS CONFIGURATION
##############################################
# Kernel
if [ ! -d "$KERNEL_DIR" ]; then
echo "Kernel not found cloning it..."
BCOUNT="$(echo $KERNEL_BRANCHES | wc -w)"
EX=""
if [ "$BCOUNT" == "1" ]; then
EX="--depth 1 -b $KERNEL_BRANCHES"
echo "Detected only one branch, let's shallow clone!"
fi
echo
git clone $EX $KERNEL_REPO $KERNEL_DIR
if [ -f "$KERNEL_DIR/.gitmodules" ]; then
echo "Git submodules detected, cloning..."
cd $KERNEL_DIR && git submodule update --init --recursive
fi
fi
# GCC
case $GCC_PROVIDER in
GOOGLE)
REPO_GCC_ARM32="https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9"
REPO_GCC_ARM64="https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9"
GCC_ARM32_DIR="$WORKDIR/tools/gcc/google-arm32/bin"
CLONE_GCC_ARM32_DIR="$WORKDIR/tools/gcc/google-arm32"
GCC_ARM64_DIR="$WORKDIR/tools/gcc/google-arm64/bin"
CLONE_GCC_ARM64_DIR="$WORKDIR/tools/gcc/google-arm64"
;;
LOS)
REPO_GCC_ARM32="https://github.com/LineageOS/android_prebuilts_gcc_linux-x86_arm_arm-linux-androideabi-4.9.git"
REPO_GCC_ARM64="https://github.com/LineageOS/android_prebuilts_gcc_linux-x86_aarch64_aarch64-linux-android-4.9.git"
GCC_ARM32_DIR="$WORKDIR/tools/gcc/los-arm32/bin"
CLONE_GCC_ARM32_DIR="$WORKDIR/tools/gcc/los-arm32"
GCC_ARM64_DIR="$WORKDIR/tools/gcc/los-arm64/bin"
CLONE_GCC_ARM64_DIR="$WORKDIR/tools/gcc/los-arm64"
;;
LINARO)
URL_ARM32="https://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/arm-linux-gnueabi/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabi.tar.xz"
URL_ARM64="https://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/aarch64-linux-gnu/gcc-linaro-4.9-2016.02-x86_64_aarch64-linux-gnu.tar.xz"
GCC_ARM32_DIR="$WORKDIR/tools/gcc/linaro-arm32/bin"
GCC_ARM64_DIR="$WORKDIR/tools/gcc/linaro-arm64/bin"
if [ ! -d "$GCC_ARM32_DIR" ]; then
check_install "wget xz-utils"
wget $URL_ARM32 -O "$WORKDIR/tools/gcc/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabi.tar.xz"
tar -C "$WORKDIR/tools/gcc" -vxf "$WORKDIR/tools/gcc/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabi.tar.xz"
rm "$WORKDIR/tools/gcc/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabi.tar.xz"
mv "$WORKDIR/tools/gcc/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabi" "$WORKDIR/tools/gcc/linaro-arm32"
fi
if [ ! -d "$GCC_ARM64_DIR" ]; then
check_install "wget xz-utils"
wget $URL_ARM64 -O "$WORKDIR/tools/gcc/gcc-linaro-4.9-2016.02-x86_64_aarch64-linux-gnu.tar.xz"
tar -C "$WORKDIR/tools/gcc" -vxf "$WORKDIR/tools/gcc/gcc-linaro-4.9-2016.02-x86_64_aarch64-linux-gnu.tar.xz"
rm "$WORKDIR/tools/gcc/gcc-linaro-4.9-2016.02-x86_64_aarch64-linux-gnu.tar.xz"
mv "$WORKDIR/tools/gcc/gcc-linaro-4.9-2016.02-x86_64_aarch64-linux-gnu" "$WORKDIR/tools/gcc/linaro-arm64"
fi
CONF_CROSS_COMPILE="aarch64-linux-gnu-"
CONF_CROSS_COMPILE_ARM32="arm-linux-gnueabi-"
;;
esac
if [ ! -d "${CLONE_GCC_ARM32_DIR:-$GCC_ARM32_DIR}" ]; then
if [ -z "$REPO_GCC_ARM32" ];
then
echo "GCC32 not found in $GCC_ARM32_DIR and no REPO_GCC_ARM32 defined, aborting!"
exit
else
echo "GCC32 not found cloning it..."
git clone --depth 1 $REPO_GCC_ARM32 ${CLONE_GCC_ARM32_DIR:-$GCC_ARM32_DIR}
fi
fi
if [ ! -d "${CLONE_GCC_ARM64_DIR:-$GCC_ARM64_DIR}" ]; then
if [ -z "$REPO_GCC_ARM64" ];
then
echo "GCC64 not found in $GCC_ARM64_DIR and no REPO_GCC_ARM64 defined, aborting!"
exit
else
echo "GCC64 not found cloning it..."
git clone --depth 1 $REPO_GCC_ARM64 ${CLONE_GCC_ARM64_DIR:-$GCC_ARM64_DIR}
fi
fi
# CLANG
case $CLANG_PROVIDER in
CLANG-BUILT-LINUX)
CLANG_DIR="$WORKDIR/tools/clang/clang-built-linux/install/bin"
if [ ! -d "$WORKDIR/tools/clang/clang-built-linux" ]; then
git clone --depth 1 https://github.com/ClangBuiltLinux/tc-build.git "$WORKDIR/tools/clang/clang-built-linux"
fi
if [ ! -d "$CLANG_DIR" ]; then
echo "Installing deps to build clang-built-linux..."
check_install "bc bison ca-certificates ccache clang cmake curl file flex gcc g++ git libelf-dev libssl-dev make ninja-build python3 texinfo u-boot-tools zlib1g-dev lld"
$WORKDIR/tools/clang/clang-built-linux/build-llvm.py
fi
;;
PROTON-BUILD)
CLANG_DIR="$WORKDIR/tools/clang/proton-build/install/bin"
if [ ! -d "$WORKDIR/tools/clang/proton-build" ]; then
git clone --depth 1 https://github.com/kdrag0n/proton-clang-build.git "$WORKDIR/tools/clang/proton-build"
fi
if [ ! -d "$CLANG_DIR" ]; then
echo "Installing deps to build proton..."
check_install "bc bison ca-certificates ccache clang cmake curl file flex gcc g++ git libelf-dev libssl-dev make ninja-build python3 texinfo u-boot-tools zlib1g-dev lld"
$WORKDIR/tools/clang/proton-build/build-llvm.py
fi
;;
BENZO-BUILD)
CLANG_DIR="$WORKDIR/tools/clang/benzo-build/out/install/linux-x86/clang-benzo/bin"
if [ ! -d "$WORKDIR/tools/clang/benzo-build" ]; then
check_repo
check_install "bc bison ca-certificates ccache clang cmake curl file flex gcc g++ git libelf-dev libssl-dev make ninja-build python3 texinfo u-boot-tools zlib1g-dev lld"
mkdir -p "$WORKDIR/tools/clang/benzo-build"
cd "$WORKDIR/tools/clang/benzo-build"
repo init -u https://github.com/benzoClang/manifest -b master
repo sync -j$(nproc --all) -f
fi
if [ ! -d "$CLANG_DIR" ]; then
cd "$WORKDIR/tools/clang/benzo-build"
toolchain/llvm_benzo/build.py --no-lto
fi
;;
BENZO-BUILD-LTO)
CLANG_DIR="$WORKDIR/tools/clang/benzo-build-lto/out/install/linux-x86/clang-benzo/bin"
if [ ! -d "$WORKDIR/tools/clang/benzo-build-lto" ]; then
check_repo
check_install "bc bison ca-certificates ccache clang cmake curl file flex gcc g++ git libelf-dev libssl-dev make ninja-build python3 texinfo u-boot-tools zlib1g-dev lld"
mkdir -p "$WORKDIR/tools/clang/benzo-build-lto"
cd "$WORKDIR/tools/clang/benzo-build-lto"
repo init -u https://github.com/benzoClang/manifest -b master
repo sync -j$(nproc --all) -f
fi
if [ ! -d "$CLANG_DIR" ]; then
cd "$WORKDIR/tools/clang/benzo-build-lto"
# (ThinLTO builds take a lot longer)
toolchain/llvm_benzo/build.py
fi
;;
PROTON-PREBUILT-TAR)
CLANG_DIR="$WORKDIR/tools/clang/proton-prebuilt-tar/bin"
if [ ! -d "$CLANG_DIR" ]; then
echo "Proton prebuilt needs configuration"
check_install "wget tar zstd"
CLANG_ARCHIVE="$WORKDIR/tools/clang/proton-prebuilt-tar/proton_clang-latest.tar.zst"
if [ ! -f "$CLANG_ARCHIVE" ]; then
mkdir -p "$WORKDIR/tools/clang/proton-prebuilt-tar"
wget https://kdrag0n.dev/files/redirector/proton_clang-latest.tar.zst -O "$CLANG_ARCHIVE"
fi
if [ ! -d "$CLANG_DIR" ]; then
FIRST_DIR=$(ls -d $WORKDIR/tools/clang/proton-prebuilt-tar/*/ 2>/dev/null)
if [ -z "$FIRST_DIR" ]; then
echo "NO FIRST DIR, EXTRACT!"
tar -C "$WORKDIR/tools/clang/proton-prebuilt-tar" -I zstd -xvf $CLANG_ARCHIVE
CLANG_DIR=$(ls -d $WORKDIR/tools/clang/proton-prebuilt-tar/*/ 2>/dev/null)
CLANG_DIR="$CLANG_DIR""bin"
else
CLANG_DIR="$FIRST_DIR""bin"
fi
fi
fi
;;
PROTON-PREBUILT)
REPO_CLANG="https://github.com/kdrag0n/proton-clang.git"
CLONE_CLANG_DIR="$WORKDIR/tools/clang/proton-prebuilt"
CLANG_DIR="$WORKDIR/tools/clang/proton-prebuilt/bin"
;;
LOLZ)
REPO_CLANG="https://github.com/Jprimero15/lolz_clang.git"
CLONE_CLANG_DIR="$WORKDIR/tools/clang/lolz"
CLANG_DIR="$WORKDIR/tools/clang/lolz/bin"
;;
AVALON)
REPO_CLANG="https://github.com/Haseo97/Avalon-Clang-11.0.1.git"
CLONE_CLANG_DIR="$WORKDIR/tools/clang/avalon"
CLANG_DIR="$WORKDIR/tools/clang/avalon/bin"
;;
GOOGLE)
REPO_CLANG="https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86"
CLONE_CLANG_DIR="$WORKDIR/tools/clang/google"
GOOGLE_CLANG_VERSION=""
if [ -z "$GOOGLE_CLANG_VERSION" ]; then
echo "GOOGLE GLAN VERSION NOT SET, DEFAULTING r377782d"
GOOGLE_CLANG_VERSION="r377782d"
fi
CLANG_DIR="$WORKDIR/tools/clang/google/clang-$GOOGLE_CLANG_VERSION/bin"
;;
esac
if [ ! -d "${CLONE_CLANG_DIR:-$CLANG_DIR}" ]; then
if [ -z "$REPO_CLANG" ];
then
echo "CLANG not found in $CLANG_DIR and no REPO_CLANG defined, aborting!"
exit
else
echo "CLANG not found cloning it..."
git clone --depth 1 $REPO_CLANG ${CLONE_CLANG_DIR:-$CLANG_DIR}
fi
fi
echo "GCC_ARM32_DIR: $GCC_ARM32_DIR"
echo "GCC_ARM64_DIR: $GCC_ARM64_DIR"
echo "CLANG_DIR: $CLANG_DIR"
# CCACHE
echo "SETTING CCACHE"
ccache -M 10G
ccache --set-config=cache_dir=$CCACHE_DIR
# PATH
PATH_GCC=$GCC_ARM32_DIR:$GCC_ARM64_DIR
PATH_CLANG=$CLANG_DIR
PATH="$WORKDIR/tools/bin:$PATH_GCC:$PATH_CLANG:${PATH}"
echo "SETTING PATH: $PATH"
DATE=""
function update_date(){
DATE=$(date +'%Y-%m-%d_%H-%M-%S')
echo "Date is now: $DATE"
}
function switch_branch(){
cd $KERNEL_DIR
#git checkout .
#if [ $? -ne 0 ]; then
# echo "<<<< FAILED CHECKOUT ."
# exit
# fi
# git fetch origin "$1"
# if [ $? -ne 0 ]; then
# echo "<<<< FAILED FETCH"
# exit
#fi
# git reset --hard "origin/$1"
# if [ $? -ne 0 ]; then
# echo "<<<< FAILED RESET"
# exit
# fi
# git fetch --unshallow
#if [ $? -ne 0 ]; then
# echo "<<<< FAILED FETCH"
# exit
#fi
git fetch --all
git checkout "$1"
if [ $? -ne 0 ]; then
echo "<<<< FAILED CHECKOUT $1"
exit
fi
git pull
if [ $? -ne 0 ]; then
echo "<<<< FAILED PULL"
exit
fi
if [ "$PAUSE_AFTER_PULL" != "" ]; then
read -n1 -r -p "Pull complete, press space to continue..." key
if [ "$key" = '' ]; then
# Space pressed, do something
echo "ok!"
else
echo "exiting..."
exit
fi
fi
GIT_HASH=$(git rev-parse --short HEAD)
cd ..
update_date
}
function build_kernel(){
if [ "$OVERWRITE_CONFIG_LOCALVERSION" != "" ]; then
echo ">>>> OVERWRITE_CONFIG_LOCALVERSION: $OVERWRITE_CONFIG_LOCALVERSION"
sed -i 's/^CONFIG_LOCALVERSION=.*$/CONFIG_LOCALVERSION="-$OVERWRITE_CONFIG_LOCALVERSION"/' "$KERNEL_DIR/arch/$KERNEL_ARCH/configs/$KERNEL_CONF"
fi
# scripts/mkcompile_h
if [ "$BUILD_USER" != "" ]; then
echo ">>>> BUILD_USER: $BUILD_USER"
export KBUILD_BUILD_USER="$BUILD_USER"
fi
if [ "$BUILD_HOST" != "" ]; then
echo ">>>> BUILD_HOST: $BUILD_HOST"
export KBUILD_BUILD_HOST="$BUILD_HOST"
fi
cd $KERNEL_DIR
echo ">>>>>> CONFIGURING"
make O=$OUT_DIR ARCH=$KERNEL_ARCH $KERNEL_CONF -j$(nproc --all)
if [ $? -ne 0 ]; then
echo "<<<< FAILED CONFIGURING"
exit
fi
# CC=clang
echo ">>>>>> MAKING"
make -j$(nproc --all) O=$OUT_DIR \
$MAKE_ADDITIONAL \
ARCH=$KERNEL_ARCH \
CC="ccache clang" \
CLANG_TRIPLE=$CONF_CLANG_TRIPLE \
CROSS_COMPILE=$CONF_CROSS_COMPILE \
CROSS_COMPILE_ARM32=$CONF_CROSS_COMPILE_ARM32
if [ $? -ne 0 ]; then
echo "<<<< FAILED MAKING"
exit
fi
cd ..
}
function build_zip(){
if [ -f "$WORKDIR/zip_templates/$ZIP_SCRIPT.sh" ]; then
echo "Launching $ZIP_SCRIPT zip script..."
chmod +x "$WORKDIR/zip_templates/$ZIP_SCRIPT.sh"
$WORKDIR/zip_templates/$ZIP_SCRIPT.sh $KERNEL_NAME $OUT_DIR $DIST_DIR $BRANCH $DATE $GCC_PROVIDER $CLANG_PROVIDER $CONFIG_FILE $GIT_HASH
fi
}
for BRANCH in $KERNEL_BRANCHES
do
OUT_DIR=$BASE_OUT_DIR"_"$BRANCH
echo "Building $BRANCH in $OUT_DIR"
switch_branch $BRANCH
build_kernel
build_zip
done