-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfigure
executable file
·498 lines (415 loc) · 12.9 KB
/
configure
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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
#!/bin/bash
# This script is used to install the necessary packages for the project
# Paths
CFGDIR="$(pwd)/build/setup"
PKGDIR="$(pwd)/build/packages"
# URLs
URL_KCONFIGLIB="https://github.com/kwrx/aplus-kconfiglib"
URL_TOOLCHAIN="https://github.com/kwrx/aplus-toolchain"
# Config
HOST_PYTHON=""
PREBUILT_TOOLCHAIN_AVAILABLE=1
PREBUILT_TOOLCHAIN_NEEDS_REBUILD=1
#
# Functions
#
optional() {
echo -n "Checking for $1..."
if ! command -v "$1"; then
tput setaf 3
echo "not found, $2"
tput sgr0
fi
}
required() {
echo -n "Checking for $1..."
if ! command -v "$1"; then
tput setaf 1
echo "not found, dependency not satisfied, please install $1 and try again."
tput sgr0
exit 1
fi
}
required_python_3() {
echo -n "Checking for python..."
if command -v python; then
HOST_PYTHON=$(command -v python)
else
echo "not found"
echo -n "Checking for python3..."
if command -v python3; then
HOST_PYTHON=$(command -v python3)
else
tput setaf 1
echo "not found, dependency not satisfied, please install python3 and try again."
tput sgr0
exit 1
fi
fi
}
die() {
tput setaf 8
echo "> $@"
tput sgr0
$@ || exit 1
}
stage_1() {
tput setaf 6
echo "## Stage 1: Collecting dependencies"
tput sgr0
if [ ! -d "$PKGDIR/kconfiglib" ]; then
echo "+ kconfiglib: GET $URL_KCONFIGLIB"
die git clone -q --depth=1 https://github.com/kwrx/aplus-kconfiglib $PKGDIR/kconfiglib
else
if [ -n "$(git -C $PKGDIR/kconfiglib fetch)" ]; then
echo "+ kconfiglib: PULL $URL_KCONFIGLIB"
die git -C $PKGDIR/kconfiglib pull 1>/dev/null
else
echo "+ kconfiglib: CACHED"
fi
fi
if [ $PREBUILT_TOOLCHAIN_AVAILABLE -eq 0 ]; then
if [ ! -d "$PKGDIR/aplus-toolchain" ]; then
echo "+ toolchain: GET $URL_TOOLCHAIN"
die git clone -q --depth=1 $URL_TOOLCHAIN $PKGDIR/aplus-toolchain
else
if [ -n "$(git -C $PKGDIR/aplus-toolchain fetch)" ]; then
echo "+ toolchain: PULL $URL_TOOLCHAIN"
die git -C $PKGDIR/aplus-toolchain -q pull
else
PREBUILT_TOOLCHAIN_NEEDS_REBUILD=0
echo "+ toolchain: CACHED"
fi
fi
else
echo "+ toolchain: PREBUILT"
fi
echo "+ requirements.txt"
die pip install -q -r $(pwd)/requirements.txt
}
stage_2() {
tput setaf 6
echo "## Stage 2: Generating configuration"
tput sgr0
if [ -f $TMPLDIR/$ARG_KCONFIG.config ]; then
KCONFIG_CONFIG=config.mk die python $PKGDIR/kconfiglib/defconfig.py --kconfig $(pwd)/.config $TMPLDIR/$ARG_KCONFIG.config
else
KCONFIG_CONFIG=config.mk die python $PKGDIR/kconfiglib/menuconfig.py $(pwd)/.config
fi
KCONFIG_CONFIG=config.mk die python $PKGDIR/kconfiglib/genconfig.py $(pwd)/.config
if [ ! -f $(pwd)/config.mk ]; then
tput setaf 1
echo "config.mk: not found, configuration failed."
tput sgr0
exit 1
fi
if [ ! -f $(pwd)/config.h ]; then
tput setaf 1
echo "config.h: not found, configuration failed."
tput sgr0
exit 1
fi
. $(pwd)/config.mk
export PATH="$PATH:$CONFIG_SYSTEM_PATH_TOOLCHAIN/bin"
}
stage_3() {
tput setaf 6
echo "## Stage 3: Getting Packages"
tput sgr0
packages="system-base system-cursors system-fonts system-images system-keymaps"
if [ "$CONFIG_HAVE_BUSYBOX" == "y" ]; then
packages="$packages busybox"
fi
if [ "$CONFIG_HAVE_DASH" == "y" ]; then
packages="$packages dash"
fi
if [ "$CONFIG_HAVE_BASH" == "y" ]; then
packages="$packages bash"
fi
if [ "$CONFIG_HAVE_ATERM" == "y" ]; then
packages="$packages libtsm"
fi
if [ "$CONFIG_HAVE_ZLIB" == "y" ]; then
packages="$packages zlib"
fi
if [ "$CONFIG_HAVE_LIBPNG" == "y" ]; then
packages="$packages libpng"
fi
if [ "$CONFIG_HAVE_LIBWEBP" == "y" ]; then
packages="$packages libwebp"
fi
if [ "$CONFIG_HAVE_FREETYPE" == "y" ]; then
packages="$packages freetype"
fi
if [ "$CONFIG_HAVE_PIXMAN" == "y" ]; then
packages="$packages pixman"
fi
if [ "$CONFIG_HAVE_CAIRO" == "y" ]; then
packages="$packages cairo"
fi
if [ "$CONFIG_HAVE_BINUTILS" == "y" ]; then
packages="$packages binutils"
fi
if [ "$CONFIG_HAVE_GCC" == "y" ]; then
packages="$packages gcc"
fi
if [ "$CONFIG_HAVE_MPC" == "y" ]; then
packages="$packages mpc"
fi
if [ "$CONFIG_HAVE_MPFR" == "y" ]; then
packages="$packages mpfr"
fi
if [ "$CONFIG_HAVE_GMP" == "y" ]; then
packages="$packages gmp"
fi
if [ "$CONFIG_HAVE_ISL" == "y" ]; then
packages="$packages isl"
fi
if [ "$CONFIG_HAVE_MESA" == "y" ]; then
packages="$packages mesa"
fi
# Get packages
die python ./scripts/get-pkg.py --repo kwrx/aplus-packages --prefix $CONFIG_SYSTEM_PATH_SYSROOT -i $packages
# Get additional packages
if [ "$CONFIG_HAVE_GAMES_DOOM" == "y" ]; then
die python ./scripts/get-pkg.py --repo kwrx/aplus-doom --prefix $CONFIG_SYSTEM_PATH_SYSROOT -i doom
fi
if [ "$CONFIG_HAVE_GAMES_NESEMU" == "y" ]; then
die python ./scripts/get-pkg.py --repo kwrx/aplus-nesemu --prefix $CONFIG_SYSTEM_PATH_SYSROOT -i nesemu
fi
}
stage_4() {
tput setaf 6
echo "## Stage 4: Getting Toolchain"
tput sgr0
if [ $PREBUILT_TOOLCHAIN_AVAILABLE -eq 1 ]; then
if [ ! -d "$CONFIG_SYSTEM_PATH_TOOLCHAIN" ]; then
die python ./scripts/get-pkg.py --repo kwrx/aplus-toolchain --prefix $CONFIG_SYSTEM_PATH_TOOLCHAIN -i $CONFIG_COMPILER_HOST-aplus-toolchain
fi
else
if [ ! -d "$CONFIG_SYSTEM_PATH_TOOLCHAIN" ]; then
PREBUILT_TOOLCHAIN_NEEDS_REBUILD=1
fi
if [ $PREBUILT_TOOLCHAIN_NEEDS_REBUILD -eq 1 ]; then
pushd $PKGDIR/aplus-toolchain &>/dev/null
echo "Cleaning toolchain..."
die rm -rf toolchain
die rm -rf tmp
echo "Building toolchain..."
if [ $ARG_VERBOSE -eq 1 ]; then
die ./ci/build.sh $CONFIG_COMPILER_HOST-aplus $(gcc -dumpmachine)
else
die ./ci/build.sh $CONFIG_COMPILER_HOST-aplus $(gcc -dumpmachine) &>build.log
fi
popd
fi
die mkdir -p $(dirname $CONFIG_SYSTEM_PATH_TOOLCHAIN)
die ln -sf $PKGDIR/aplus-toolchain/toolchain $(dirname $CONFIG_SYSTEM_PATH_TOOLCHAIN)
fi
}
stage_5() {
tput setaf 6
echo "## Stage 5: Setting up Rust"
tput sgr0
# Nightly
die rustup default nightly
# Target
die rustup target add $CONFIG_COMPILER_TARGET
}
stage_6() {
tput setaf 6
echo "## Stage 6: Generating Wrapper"
tput sgr0
echo '#!/bin/sh' >makew
echo 'export PATH="$PATH:$(pwd)/'$CONFIG_SYSTEM_PATH_TOOLCHAIN'/bin"' >>makew
echo 'make --no-print-directory -s MAKE_WRAPPER=y REMOTE="$ARG_REMOTE" -j$(nproc) $@' >>makew
chmod +x makew
}
#
# Main
#
# Arguments
ARG_KCONFIG=""
ARG_SKIP_PACKAGES=0
ARG_SKIP_TOOLCHAIN=0
ARG_VERBOSE=0
ARG_STAGE=0
# Parse arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--kconfig)
ARG_KCONFIG="$2"
shift
shift
;;
--skip-packages)
ARG_SKIP_PACKAGES=1
shift
;;
--skip-toolchain)
ARG_SKIP_TOOLCHAIN=1
shift
;;
--remote)
ARG_REMOTE="$2"
shift
shift
;;
--stage)
ARG_STAGE="$2"
shift
shift
;;
-v | --verbose)
ARG_VERBOSE=1
shift
;;
-h | --help)
echo "Usage: configure [OPTIONS]"
echo ""
echo "Options:"
echo " --kconfig FILE: use a specific Kconfig file"
echo " --skip-packages: skip packages"
echo " --skip-toolchain: skip toolchain"
echo " --remote URI: use a remote toolchain"
echo " -v, --verbose: enable verbose mode"
echo " -h, --help: show this help message and exit"
exit 0
;;
*)
echo "Unknown argument: $1"
exit 1
;;
esac
done
# Check if the script is run on a Linux machine
if [ "$(uname)" != "Linux" ]; then
echo "This script is intended to run on a Linux machine."
exit 1
fi
# Check if the script is run as root
if [ "$(id -u)" -eq 0 ]; then
echo "This script should not be run as root."
exit 1
fi
# Check for required tools
optional clang-format "formatting will not be available"
optional doxygen "documentation will not be available"
optional qemu-img "disk images conversion will not be available"
optional mkisofs "Live images creation will not be available"
required git
required make
required automake
required autoconf
required gcc
required ld
required gdisk
required mkfs.vfat
required mkfs.ext2
required dd
required sync
required sudo
required find
required awk
required grub-install
required fc-scan
required gzip
required zip
required rustc
required rustup
required cargo
required od
required_python_3
# Check for host architecture
HOST=$(gcc -dumpmachine)
# Check if a prebuilt toolchain is available
case $HOST in
x86_64-*) ;;
*)
PREBUILT_TOOLCHAIN_AVAILABLE=0
tput setaf 3
echo "WARN! Prebuilt toolchain is not available for $HOST, a custom toolchain will be built from source."
tput sgr0
;;
esac
# Prepare .venv
die $HOST_PYTHON -m venv .venv
die source .venv/bin/activate
# Execute stages
if [ $ARG_STAGE -eq 1 ]; then
stage_1
elif [ $ARG_STAGE -eq 2 ]; then
stage_2
elif [ $ARG_STAGE -eq 3 ]; then
stage_2
stage_3
elif [ $ARG_STAGE -eq 4 ]; then
stage_2
stage_4
elif [ $ARG_STAGE -eq 5 ]; then
stage_2
stage_5
elif [ $ARG_STAGE -eq 6 ]; then
stage_2
stage_6
else
stage_1
stage_2
if [ $ARG_SKIP_PACKAGES -eq 0 ]; then
stage_3
fi
if [ $ARG_SKIP_TOOLCHAIN -eq 0 ]; then
stage_4
fi
# stage_5
stage_6
fi
# Cleanup
die deactivate
# Output configuration
if [ "$CONFIG_HAVE_DEBUG" == "y" ]; then
buildtype="Debug"
else
buildtype="Release"
fi
if [ "$CONFIG_HAVE_GUI" == "y" ]; then
gui="True"
else
gui="False"
fi
if [ "$CONFIG_HAVE_NETWORK" == "y" ]; then
networking="True"
else
networking="False"
fi
if [ "$CONFIG_HAVE_SMP" == "y" ]; then
smp="True"
else
smp="False"
fi
echo -e "\
\n\
Setup completed! \n\
\n\
Your configuration is: \n\
\n\
Project: $CONFIG_SYSTEM_NAME-$CONFIG_SYSTEM_CODENAME v$CONFIG_SYSTEM_VERSION \n\
BuildType: $buildtype \n\
\n\
Host: $CONFIG_COMPILER_HOST \n\
Sysroot: $CONFIG_SYSTEM_PATH_SYSROOT \n\
Toolchain: $CONFIG_SYSTEM_PATH_TOOLCHAIN \n\
Locale: $CONFIG_SYSTEM_LOCALE \n\
Timezone: $CONFIG_SYSTEM_TIMEZONE \n\
\n\
GUI: $gui \n\
SMP: $smp \n\
Networking: $networking \n\
\n\
Run: \n\
$ ./makew [MAKEARGS] \n\
\n\
See config.h to more detals. \n\
\n"
exit 0