-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_kernel
More file actions
executable file
·417 lines (343 loc) · 8.23 KB
/
Copy pathbuild_kernel
File metadata and controls
executable file
·417 lines (343 loc) · 8.23 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
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
#!/bin/bash
# SPDX-FileCopyrightText: 2024 Edrick Sinsuan
# SPDX-License-Identifier: Apache-2.0
script_dir=$(dirname $0)
if ! check_file "$script_dir/setup_env"; then
decho "setup_env must be present in $script_dir!"
exit_timestamp 1
fi
source $script_dir/setup_env
# Kernel directories
readonly KERNEL_PARENT_DIR=$HOME/kernel
readonly SRC_DIR=$KERNEL_PARENT_DIR
readonly OUT_DIR=$KERNEL_PARENT_DIR/output
readonly TARGET_DIR=$KERNEL_PARENT_DIR/test
readonly SRT_DIR=$KERNEL_PARENT_DIR/scripts
readonly ZIP_DIR=$KERNEL_PARENT_DIR/zip
readonly LOG_DIR=$KERNEL_PARENT_DIR/buildlog
readonly CLANG_DIR=$KERNEL_PARENT_DIR/toolchain/clang
readonly GCC_DIR=$KERNEL_PARENT_DIR/toolchain/gcc
# Default properties
test_build=n
debug=n
log=/dev/null
brnch_ver=$curr_date
ver=1
jn=$(nproc)
# Build x-ft by default
srcn="x-ft"
#
# Defined srcn properties
#
define_x-ft() {
if [[ $debug == "y" ]]; then
dc="msm8998_oneplus_debug_android_defconfig"
else
dc="msm8998_oneplus_android_defconfig"
fi
af="arch/arm64/configs"
arch="arm64"
subarch=$arch
lwimg="Image.gz-dtb"
clang_path="$CLANG_DIR/clang-r530567/bin"
gcc_path="${GCC_DIR}64/bin:${GCC_DIR}32/bin"
cc_path="$clang_path:$cc_path"
c64="aarch64-linux-gnu-"
c32="arm-linux-gnueabi-"
cc="${c64}gcc"
use_clang=y
export PATH="/usr/local/bin:$cc_path:$PATH"
}
define_wsl2() {
dcf="config-wsl-x86"
af="arch/x86/configs"
dc="KCONFIG_CONFIG=$af/$dcf"
arch="x86"
lwimg="bzImage"
# WSL directory (windows and linux) for wsl2-kernel
readonly WSLKDIRW='C:\\Users\\evcsi\\WSL\\'
readonly WSLKDIRL=$C_USER_DIR/WSL
use_clang=y
export PATH="/usr/lib/ccache:$PATH"
}
define_srcn() {
if [[ $srcn == "x-ft" ]]; then
define_x-ft
return 0
fi
if [[ $srcn == "wsl2-kernel" ]]; then
define_wsl2
return 0
fi
return 1
}
#
# Build functions
#
define_log() {
create_dir "$LOG_DIR"
if ! check_file "$log"; then
touch "$LOG_DIR/$kname.log"
else
echo "" > $log
fi
decho "Build start: $date_full" >> $log
log="$LOG_DIR/$kname.log"
{
border
echo "Last Commit:"
echo $(git -C $srcn_dir log -1 --pretty=%B)
border
} >> $log
}
define_kname() {
khash=$(git rev-parse --short HEAD)
kname="$userhost-$srcn-$src_brnch-$brnch_ver-$ver"
kname_s="$srcn-$brnch_ver-$ver"
if [[ $debug == "y" ]]; then
kname="d-$kname"
kname_s="d-$kname_s"
fi
if [[ $ksu_build == "y" ]]; then
kname="k-$kname"
kname_s="k-$kname_s"
fi
}
define_clang() {
cc="clang"
clangmkp=" \
LLVM=1 \
LLVM_IAS=1 \
"
}
define_debug() {
debugmkp=" \
CONFIG_DEBUG_SECTION_MISMATCH=y \
"
}
define_ksu() {
ksumkp=" \
KSU_DEFINED=1 \
"
}
define_env() {
border
if [[ $src_brnch != "" ]]; then
echo "Checking out to branch:"
git checkout $src_brnch
else
echo "Using current branch:"
src_brnch="$(git rev-parse --abbrev-ref HEAD)"
fi
echo $src_brnch
border
out=$OUT_DIR/$srcn/$src_brnch
bti=$out/arch/$arch/boot
define_kname
if [[ $force_ver != "y" ]]; then
while [[ -f $LOG_DIR/$kname.log ]]
do
ver="$(($ver + 1))"
define_kname
done
fi
if [[ $configure == "y" ]]; then
echo "Configure only, no builds will be made..."
else
log=$LOG_DIR/$kname.log
define_log
fi
if [[ $use_clang == "y" ]]; then
define_clang
fi
if [[ $debug == "y" ]]; then
define_debug
fi
if [[ $ksu_build == "y" ]]; then
define_ksu
fi
local compiler="$($cc --version | head -1)"
decho_log "Compiler being used: $compiler"
build_str="$srcn release: $src_brnch-$brnch_ver-$ver built using $compiler | \
Date: $date_full | Hash: $khash"
mkp=" \
$clangmkp \
$debugmkp \
$ksumkp \
CC_WRAPPER=ccache \
ARCH=$arch \
SUBARCH=$subarch \
CROSS_COMPILE=$c64 \
CROSS_COMPILE_ARM32=$c32 \
LOCALVERSION=-$kname_s \
O=$out \
-j$jn \
"
if [[ $srcn == "wsl2-kernel" ]]; then
mkp=" \
$clangmkp \
$debugmkp \
LOCALVERSION=-$kname_s \
O=$out \
-j$jn \
"
fi
decho "Make variables: $mkp" >> $log
}
build_func() {
cd $srcn_dir
define_env
if create_dir "$out"; then
time make_cmd clean
time make_cmd mrproper
fi
if [[ $configure == "y" ]]; then
time make_cmd $dc menuconfig
if [[ $srcn == "wsl2-kernel" ]]; then
dc=$dcf
fi
time make_cmd $dc savedefconfig
cp -v $out/defconfig $srcn_dir/$af/$dc
decho "Copied defconfig to $dc"
exit_timestamp 0
fi
time make_cmd $dc
if [[ $srcn == "wsl2-kernel" ]]; then
return
fi
if [[ $make_only == "y" ]]; then
decho_log "Done generating .config at $out"
code $out/.config
exit_timestamp 0
fi
time make_cmd
}
export_img_wsl2() {
decho "Copying $bti/$lwimg to $C_USER_DIR/WSL"
cp $bti/$lwimg $WSLKDIRL/$kname_s
decho "Updating kernel in .wslconfig"
sed -i '/kernel=/d' $C_USER_DIR/.wslconfig
echo "kernel=$WSLKDIRW$kname_s" >> $C_USER_DIR/.wslconfig
cat $C_USER_DIR/.wslconfig
}
export_img_zip() {
if ! check_dir "$ZIP_DIR" || ! cd "$ZIP_DIR"; then
decho_log "There's no zip directory, abort!"
exit_timestamp 1
fi
create_dir $TARGET_DIR
mv -f $bti/$lwimg $ZIP_DIR
touch version
{
echo "Kernel: $srcn by $userhost"
echo "Build code: $src_brnch-$brnch_ver-$ver"
echo "Date: $date_full"
echo "Hash: $khash"
} >> version
zip_image $TARGET_DIR/$kname
create_dir $SHARED_ROOT_DIR/builds
cp $TARGET_DIR/$kname.zip $SHARED_ROOT_DIR/builds/
rm -f $lwimg
rm -f version
}
export_img() {
if [[ $srcn == "wsl2-kernel" ]]; then
export_img_wsl2
return 0
fi
# Set kernel zipping as default
export_img_zip
return 0
}
main_func() {
if ! check_dir $srcn_dir; then
decho_log "Abort, source directory must exist."
exit_timestamp 1
fi
build_func
if check_file "$bti/$lwimg"; then
export_img
decho "Log file: $log"
elif [[ $log != "/dev/null" ]]; then
decho "$log"
cat $log
fi
decho "$build_str"
create_dir $SHARED_ROOT_DIR/logs
cp $log $SHARED_ROOT_DIR/logs/
}
param_func() {
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-s|--source)
if check_valid "$2"; then
srcn="$2"
shift
fi
;;
-b|--branch)
if check_valid "$2"; then
src_brnch="$2"
shift
fi
;;
-v|--version)
if check_valid "$2"; then
force_ver=y
ver="$2"
shift
fi
;;
-cl|--clang)
use_clang=y
;;
-a|--all)
build_all=y
;;
-c|--configure)
configure=y
;;
-t|--test)
test_build=y
;;
-d|--debug)
debug=y
;;
-mo|--make-only)
make_only=y
;;
-k|--ksu)
ksu_build=y
;;
esac
shift
done
}
param_main_func() {
param_func "$@"
main_func
}
#
# Build start
#
decho "Executing build script..."
param_func "$@"
if ! define_srcn; then
decho "srcn=$srcn is unknown, please define in $0!"
exit_timestamp 1
fi
srcn_dir=$SRC_DIR/$srcn
if [[ $srcn == "x-ft" ]] && [[ $build_all == "y" ]]; then
if [[ $test_build == "y" ]]; then
param_main_func -b testing
param_main_func -b testing -k
else
param_main_func -b stable
param_main_func -b stable -k
fi
exit_timestamp 0
fi
main_func
exit_timestamp 0