-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommon.bashinc
545 lines (470 loc) · 19.5 KB
/
common.bashinc
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
#!/usr/bin/env bash
# Copyright 2024-2025 Nick Brassel (@tzarc)
# SPDX-License-Identifier: GPL-2.0-or-later
set -eEuo pipefail
# macOS SDK Version
export SDK_VERSION=15.0
# macOS Target Version (Monterey)
export MACOSX_DEPLOYMENT_TARGET=12.0
# If necessary, re-exec with a clean environment inside docker
function respawn_docker_if_needed() {
if [[ "$(uname -s)" == "Linux" ]] && [[ -n "${EXECUTE_UNDER_DOCKER:-}" ]]; then
eval "$(parse_args "$@")"
[ -n "${container_image:-}" ] || container_image='ghcr.io/tzarc/qmk_toolchains:builder'
cd "$script_dir"
docker run --rm \
-v "$script_dir:$TC_WORKDIR" \
-w "$TC_WORKDIR" \
-e TC_WORKDIR="$TC_WORKDIR" \
$container_image \
./$(basename $this_script) "$@"
exit $?
fi
}
export PATH="$HOME/.local/crosstool-ng/bin:$PATH"
function havecmd() {
type "${1}" >/dev/null 2>&1 || return 1
}
havecmd gsed && SED=gsed || SED=sed
function cpu_count() {
nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1
}
function verify_crosstool() {
if ! havecmd ct-ng; then
echo "ct-ng not found in PATH. Please install crosstool-ng first." >&2
exit 1
fi
}
function fn_os() {
local os_name=$(echo ${1:-} | tr 'A-Z' 'a-z')
if [[ -z "$os_name" ]]; then
os_name=$(uname -s | tr 'A-Z' 'a-z')
fi
case "$os_name" in
*darwin* | *macos* | *apple*)
echo macos
;;
*windows* | *mingw* | *w64*)
echo windows
;;
*linux*)
echo linux
;;
*none* | *unknown* | *picolibc* | *nano*)
echo baremetal
;;
*)
echo unknown
;;
esac
}
function fn_arch() {
local arch_name=$(echo ${1:-} | tr 'A-Z' 'a-z')
if [[ -z "$arch_name" ]]; then
arch_name=$(uname -m | tr 'A-Z' 'a-z')
fi
case "$arch_name" in
*arm64* | *aarch64*)
echo ARM64
;;
*arm*)
echo ARM
;;
*riscv32*)
echo RV32
;;
*riscv64*)
echo RV64
;;
*avr*)
echo AVR
;;
*x86_64* | *x64*)
echo X64
;;
*)
echo unknown
;;
esac
}
function fn_os_arch() {
echo $(fn_os ${1:-})$(fn_arch ${2:-})
}
function fn_os_arch_fromtriplet() {
local input_var=${1:-}
# AVR is a special snowflake.
if [[ "$input_var" == "avr" ]]; then
fn_os_arch_fromtriplet avr-none-none
return
fi
# Remove the qmk vendor from the bootstrapped compiler
input_var=$(echo $input_var | sed -e 's@qmk-@@g')
local input_arch=$(echo $input_var | cut -d'-' -f1)
local input_os=$(echo $input_var | cut -d'-' -f2)
# Try to skip vendor
if [[ "$input_os" == "unknown" ]] || [[ "$input_os" == "none" ]] || [[ "$input_os" == "pc" ]] || [[ "$input_os" == "rpi3" ]] || [[ "$input_os" == "w64" ]]; then
input_os=$(echo $input_var | cut -d'-' -f3)
fi
# If we're into the ABI stuff, then backtrack
if [[ "$input_os" == "eabi" ]] || [[ "$input_os" == "elf" ]] || [[ "$input_os" == "mingw32" ]]; then
input_os=$(echo $input_var | cut -d'-' -f2)
fi
fn_os_arch $input_os $input_arch
}
function build_one_args() {
cat <<__EOT__
--help -- Shows this help text
--build-target=<target> -- Which ct-ng build target to execute, default is 'build' (optional)
--sample-name=<sample> -- Seeds the crosstool-ng build with the sample configuration (required)
--vendor-name=<vendor> -- Overrides the vendor previously supplied by the sample (optional)
--build-host-compile -- Builds the toolchains targeting an older version of gcc for later version compatibility (optional)
--canadian-host=<host> -- The intended final host machine that the toolchain will be executed (optional)
--no-cross-gdb-python -- Disabled python when building cross-gdb for canadian builds (optional)
--libc=<flavour> -- Overrides the C library to build. Usually 'picolibc', 'newlib', or 'none'. (optional)
--extra-newlib-nano -- Builds newlib-nano in addition to the usual C library (optional)
--extra-picolibc -- Builds picolibc in addition to the usual C library (optional)
--static-toolchain -- Builds the toolchain such that it's statically linked (currently broken, skipped) (optional)
--multilib-list=<value> -- Overrides the list of multilib targets generated. Sets \$CT_CC_GCC_MULTILIB_LIST. (optional)
--tools-prefix=<value> -- Override the build toolchain. For example \`x86_64-unknown-linux-gnu-\`, with the trailing slash. \`gcc\` et.al. will be appended. (optional)
--dir-suffix=<value> -- Appends a suffix to the toolchain output directory. (optional)
--container-image -- Which container image to use.
--no-keep-state -- Don't save the state of the build. (optional)
__EOT__
}
function build_one_help() {
for arg in "$@"; do
case "$arg" in
--help)
echo
echo "$(basename $this_script) $(build_one_args | grep '(required)' | ${SED} -e 's@\s\+--.*@@g') $(build_one_args | sort | grep '(optional)' | ${SED} -e 's@\s\+--.*@@g' -e 's@^@[@' -e 's@$@]@' | tr '\n' ' ')"
echo
build_one_args
exit 0
;;
esac
done
}
function ct_ng_olddefconfig() {
ct-ng olddefconfig 2>&1 |
grep -vE 'CONF.*olddefconfig' |
grep -vE '^#' |
grep -vE 'warning: override:' ||
true
}
function parse_args() {
set -eEuo pipefail
umask 022
while read arg; do
unset $arg
done < <(build_one_args | ${SED} -e 's@\s\+--.*@@g' -e 's@^--@@g' -e 's@-@_@g' -e 's@=.*@@g')
unset arg
local -a positional_args=()
while [[ ! -z "${1:-}" ]]; do
case "$1" in
--*=*)
N=${1%%=*}
N=${N##--}
N=$(echo $N | tr '-' '_')
V=${1##*=}
echo export $N="$V"
;;
--*)
N=${1##--}
N=$(echo $N | tr '-' '_')
echo export $N=true
;;
*)
positional_args+=($1)
;;
esac
shift
unset N
unset V
done
echo "positional_args=("${positional_args[@]}")"
}
function build_one() {
set -eEuo pipefail
umask 022
verify_crosstool
eval "$(parse_args "$@")"
if [[ ! -z "${help:-}" ]]; then
build_one_args
exit 0
fi
[[ -d "$script_dir/tarballs" ]] || mkdir -p $script_dir/tarballs
if [[ ! -z "${canadian_host:-}" ]]; then
name_host=$(fn_os_arch_fromtriplet $canadian_host)
name_target=$(fn_os_arch_fromtriplet $sample_name)
else
name_host=$(fn_os_arch)
name_target=$(fn_os_arch_fromtriplet $sample_name)
fi
target_dir="host_${name_host}-target_${name_target}${dir_suffix:-}"
echo ============
echo ' BUILD TARGET:' $target_dir
echo ' BUILD DIR:' "$script_dir/build/$target_dir"
echo 'TOOLCHAIN DIR:' "$script_dir/toolchains/$target_dir"
echo ============
echo
local build_dir="$script_dir/build/$target_dir"
local toolchain_dir="$script_dir/toolchains/$target_dir"
mkdir -p "$build_dir"
cd "$build_dir"
# Remove any existing configuration
[[ ! -e .config ]] || rm .config
# Load the crosstool-ng sample configuration for the target
ct-ng $sample_name
# Set up the build environment params
echo "CT_EXPERIMENTAL=y" >>.config # required for some features
echo "CT_FORCE_EXTRACT=y" >>.config
# Enable stripping of the toolchain executables
echo "CT_STRIP_HOST_TOOLCHAIN_EXECUTABLES=y" >>.config
echo "CT_STRIP_TARGET_TOOLCHAIN_EXECUTABLES=y" >>.config
# Don't go overboard with the parallel jobs
echo "CT_PARALLEL_JOBS=$(($(cpu_count) + 1))" >>.config
ct_ng_olddefconfig
# Disable the progress bar and other unnecessary features, zstd support was broken last time it was checked
${SED} -i \
-e '/CT_LOG_PROGRESS_BAR/s/y$/n/' \
-e 's/^.*CT_PREFIX_DIR_RO.*$/CT_PREFIX_DIR_RO=n/' \
-e 's/^.*CT_CC_LANG_CXX.*$/CT_CC_LANG_CXX=y/' \
-e 's/^.*CT_CC_GCC_LTO_ZSTD.*$/CT_CC_GCC_LTO_ZSTD=n/' \
-e 's/^.*CT_COMP_LIBS_ZSTD.*$/CT_COMP_LIBS_ZSTD=n/' \
-e 's/^.*CT_ZSTD_NEEDED.*$/CT_ZSTD_NEEDED=n/' \
-e 's/^.*CT_ZSTD.*$/CT_ZSTD=n/' \
-e 's/^.*CT_DEBUG_GDB.*$/CT_DEBUG_GDB=y/' \
-e 's@^.*CT_LOCAL_TARBALLS_DIR.*$@CT_LOCAL_TARBALLS_DIR="'"$script_dir/tarballs"'"@' \
.config
# GDB's TUI causes issues with the build, so disable it.
echo 'CT_GDB_CROSS_EXTRA_CONFIG_ARRAY="--disable-tui"' >>.config # see https://github.com/crosstool-ng/crosstool-ng/issues/321
# Builder older versions of the toolchain when we're building the base cross-compilers
if [[ ! -z "${build_host_compile:-}" ]]; then
# Don't need gdb for the host builds
echo 'CT_DEBUG_GDB=n' >>.config
${SED} -i \
-e 's/^.*CT_GCC_V_.*$/# CT_GCC_V_???? is not set/' \
-e 's/^.*CT_GCC_VERSION.*$/# CT_GCC_VERSION is not set/' \
-e 's/^.*CT_GCC_.*_or_later$/# CT_GCC_????_or_later is not set/' \
-e 's/^.*CT_GCC_REQUIRE_.*_or_later$/# CT_GCC_REQUIRE_????_or_later is not set/' \
-e 's/^.*CT_GCC_.*_or_older.*$/# CT_GCC_V_????_or_older is not set/' \
-e 's/^.*CT_GCC_.*_or_later.*$/# CT_GCC_V_????_or_later is not set/' \
-e 's/^.*CT_GCC_later_than_.*$/# CT_GCC_later_than_???? is not set/' \
-e 's/^.*CT_GCC_older_than_.*$/# CT_GCC_older_than_???? is not set/' \
.config
if [[ ! -z "$(echo $sample_name | grep riscv64-unknown-linux-gnu)" ]]; then
echo "CT_GCC_V_10=y" >>.config
echo "CT_GCC_VERSION=\"10.5.0\"" >>.config
else
echo "CT_GCC_V_8=y" >>.config
echo "CT_GCC_VERSION=\"8.5.0\"" >>.config
fi
ct_ng_olddefconfig
${SED} -i \
-e 's/^.*CT_MINGW_W64_V_.*$/# CT_MINGW_W64_V_???? is not set/' \
-e 's/^.*CT_MINGW_W64_VERSION.*$/# CT_MINGW_W64_VERSION is not set/' \
.config
echo "CT_MINGW_W64_V_V10_0=y" >>.config
echo "CT_MINGW_W64_VERSION=\"v10.0.0\"" >>.config
ct_ng_olddefconfig
fi
ct_ng_olddefconfig
# Apparently an older version of GMP is required due to bootstrapping with older gcc
${SED} -i \
-e 's/^.*CT_GMP_V_6.*$/# CT_GMP_V_6_???? is not set/' \
.config
echo 'CT_GMP_V_6_2=y' >>.config
echo 'CT_GMP_VERSION="6.2.1"' >>.config
ct_ng_olddefconfig
# Swap to an older version of Linux (LTS) and glibc to avoid execution issues with older distros, especially things like older Debian with Raspberry Pi targets.
if [[ ! -z "$(echo $sample_name | grep riscv64-unknown-linux-gnu)" ]]; then
# rv64 needs a slightly newer kernel
${SED} -i \
-e 's/^.*CT_LINUX_V_.*$/# CT_LINUX_V_???? is not set/' \
-e 's/^.*CT_LINUX_VERSION.*$/CT_LINUX_VERSION="5.10"/' \
-e 's/^.*CT_GLIBC_MIN_KERNEL.*$/CT_GLIBC_MIN_KERNEL="5.10"/' \
.config
echo CT_LINUX_V_5_10=y >>.config
echo unset CT_GLIBC_KERNEL_VERSION_NONE >>.config
echo CT_GLIBC_KERNEL_VERSION_AS_HEADERS=y >>.config
echo CT_GLIBC_MIN_KERNEL="\${CT_LINUX_VERSION}" >>.config
else
${SED} -i \
-e 's/^.*CT_LINUX_V_.*$/# CT_LINUX_V_???? is not set/' \
-e 's/^.*CT_LINUX_VERSION.*$/CT_LINUX_VERSION="4.19"/' \
-e 's/^.*CT_GLIBC_MIN_KERNEL.*$/CT_GLIBC_MIN_KERNEL="4.19"/' \
.config
echo CT_LINUX_V_4_19=y >>.config
echo unset CT_GLIBC_KERNEL_VERSION_NONE >>.config
echo CT_GLIBC_KERNEL_VERSION_AS_HEADERS=y >>.config
echo CT_GLIBC_MIN_KERNEL="\${CT_LINUX_VERSION}" >>.config
fi
ct_ng_olddefconfig
# Disable unnecessary languages
echo "CT_CC_LANG_FORTRAN=n" >>.config
echo "# CT_CC_LANG_FORTRAN is not set" >>.config
echo "CT_CC_LANG_JIT=n" >>.config
echo "# CT_CC_LANG_JIT is not set" >>.config
echo "CT_CC_LANG_ADA=n" >>.config
echo "# CT_CC_LANG_ADA is not set" >>.config
echo "CT_CC_LANG_D=n" >>.config
echo "# CT_CC_LANG_D is not set" >>.config
echo "CT_CC_LANG_OBJC=n" >>.config
echo "# CT_CC_LANG_OBJC is not set" >>.config
echo "CT_CC_LANG_OBJCXX=n" >>.config
echo "# CT_CC_LANG_OBJCXX is not set" >>.config
echo "CT_CC_LANG_GOLANG=n" >>.config
echo "# CT_CC_LANG_GOLANG is not set" >>.config
ct_ng_olddefconfig
# Link the toolchain statically if requested
if [[ ! -z "${static_toolchain:-}" ]]; then
# ${SED} -i \
# -e 's/^.*CT_STATIC_TOOLCHAIN.*$/CT_STATIC_TOOLCHAIN=y/' \
# -e 's/^.*CT_WANTS_STATIC_LINK.*$/CT_WANTS_STATIC_LINK=y/' \
# -e 's/^.*CT_WANTS_STATIC_LINK_CXX.*$/CT_WANTS_STATIC_LINK_CXX=y/' \
# .config
ct_ng_olddefconfig
fi
# Configure the required C library
if [[ ! -z "${libc:-}" ]]; then
echo "CT_LIBC_$(echo $libc | tr 'a-z' 'A-Z')=y" >>.config
echo "CT_LIBC=\"$(echo $libc | tr 'A-Z' 'a-z')\"" >>.config
echo 'CT_COMP_LIBS_NEWLIB_NANO=n' >>.config
echo 'CT_COMP_LIBS_PICOLIBC=n' >>.config
ct_ng_olddefconfig
if [[ "${libc}" == "newlib" ]]; then
${SED} -i \
-e 's/^.*CT_LIBC_NEWLIB_DISABLE_SUPPLIED_SYSCALLS.*$/CT_LIBC_NEWLIB_DISABLE_SUPPLIED_SYSCALLS=n/' \
.config
fi
ct_ng_olddefconfig
fi
# Enable newlib-nano if requested
if [[ ! -z "${extra_newlib_nano:-}" ]]; then
echo 'CT_COMP_LIBS_NEWLIB_NANO=y' >>.config
ct_ng_olddefconfig
${SED} -i \
-e 's/^.*CT_LIBC_NEWLIB_EXTRA_SECTIONS.*$/CT_LIBC_NEWLIB_EXTRA_SECTIONS=y/' \
-e 's/^.*CT_LIBC_NEWLIB_NANO_MALLOC.*$/CT_LIBC_NEWLIB_NANO_MALLOC=y/' \
-e 's/^.*CT_COMP_LIBS_NEWLIB_NANO.*$/CT_COMP_LIBS_NEWLIB_NANO=y/' \
-e 's/^.*CT_NEWLIB_NANO_INSTALL_IN_TARGET.*$/CT_NEWLIB_NANO_INSTALL_IN_TARGET=y/' \
-e 's/^.*CT_LIBC_NEWLIB_NANO_EXTRA_SECTIONS.*$/CT_LIBC_NEWLIB_NANO_EXTRA_SECTIONS=y/' \
.config
ct_ng_olddefconfig
fi
# Enable picolibc if requested
if [[ ! -z "${extra_picolibc:-}" ]]; then
echo 'CT_COMP_LIBS_PICOLIBC=y' >>.config
ct_ng_olddefconfig
${SED} -i \
-e 's/^.*CT_PICOLIBC_INSTALL_IN_TARGET.*$/CT_PICOLIBC_INSTALL_IN_TARGET=y/' \
-e 's/^.*CT_LIBC_PICOLIBC_GCC_LIBSTDCXX.*$/CT_LIBC_PICOLIBC_GCC_LIBSTDCXX=y/' \
.config
ct_ng_olddefconfig
fi
# Set the list of multilib targets
if [[ ! -z "${multilib_list:-}" ]]; then
${SED} -i \
-e 's/^.*CT_CC_GCC_MULTILIB_LIST.*$/CT_CC_GCC_MULTILIB_LIST="'$multilib_list'"/' \
.config
ct_ng_olddefconfig
fi
# Override the vendor name string
if [[ ! -z "${vendor_name:-}" ]]; then
${SED} -i \
-e 's/^.*CT_TARGET_VENDOR.*$/CT_TARGET_VENDOR="'$vendor_name'"/' \
.config
ct_ng_olddefconfig
fi
# Disable python for cross-compile GDB if necessary
if [[ ! -z "${no_cross_gdb_python:-}" ]]; then
echo CT_GDB_CROSS_PYTHON=n >>.config
ct_ng_olddefconfig
fi
# Enable canadian builds if requested
if [[ ! -z "${canadian_host:-}" ]]; then
${SED} -i \
-e 's/^.*CT_CROSS.*$/# CT_CROSS is not set/' \
-e 's/^.*CT_CANADIAN.*$/CT_CANADIAN=y/' \
-e 's/^.*CT_TOOLCHAIN_TYPE.*$/CT_TOOLCHAIN_TYPE="canadian"/' \
.config
echo "CT_HOST=\"${canadian_host}\"" >>.config
if [[ ! -z "$(echo ${canadian_host} | grep mingw32)" ]]; then
# Fixup Windows builds:
echo "# CT_LIBC_GLIBC is not set" >>.config
echo CT_BINUTILS_PLUGINS=n >>.config # need to disable these as builds providing LTO fail on Windows because the DLLs export too many symbols (>65536)
fi
ct_ng_olddefconfig
fi
if [[ ! -z "$(echo $sample_name | grep linux)" ]]; then
# Swap to an older version of glibc to avoid issues with older distros, especially things like older Debian with Raspberry Pi targets.
# See the glibc version compat list here: https://abi-laboratory.pro/?view=timeline&l=glibc -- 2.28 seems safe enough?
${SED} -i \
-e 's/^.*CT_GLIBC_V_.*$/# CT_GLIBC_V_???? is not set/' \
.config
if [[ ! -z "$(echo $sample_name | grep riscv64-unknown-linux-gnu)" ]]; then
echo "CT_GLIBC_V_2_36=y" >>.config
echo "CT_GLIBC_OLDEST_ABI=\"2.36\"" >>.config
echo "CT_CC_GCC_EXTRA_CONFIG_ARRAY=\"--with-glibc-version=2.36\"" >>.config
else
echo "CT_GLIBC_V_2_28=y" >>.config
echo "CT_GLIBC_OLDEST_ABI=\"2.28\"" >>.config
echo "CT_CC_GCC_EXTRA_CONFIG_ARRAY=\"--with-glibc-version=2.28\"" >>.config
fi
ct_ng_olddefconfig
fi
# Set the toolchain output directory
${SED} -i \
-e 's@^.*CT_PREFIX_DIR=.*$@CT_PREFIX_DIR="'${toolchain_dir}'"@' \
.config
ct_ng_olddefconfig
# Enable debug options
echo "CT_DEBUG_CT=y" >>.config
ct_ng_olddefconfig
if [[ -z "${no_keep_state:-}" ]]; then
# Save the build steps so that we can save/restore on GHA due to build execution time limits.
echo "CT_DEBUG_CT_SAVE_STEPS=y" >>.config
echo "CT_DEBUG_CT_SAVE_STEPS_GZIP=y" >>.config
fi
# Set the toolchain version string
echo "CT_TOOLCHAIN_PKGVERSION=\"qmk/qmk_toolchains @ $(git describe --always --dirty --exclude '*')\"" >>.config
if [[ -n "${tools_prefix:-}" ]]; then
# Set the tools prefix
echo "CT_BUILD_PREFIX=\"${tools_prefix}\"" >>.config
fi
ct_ng_olddefconfig
# Save a copy of the "cut-down" config for inspection purposes.
ct-ng savedefconfig
echo ================================================================================================
echo == begin defconfig =============================================================================
echo ================================================================================================
cat defconfig
echo ================================================================================================
echo == end defconfig ===============================================================================
echo ================================================================================================
echo
# Add the other compilers to the PATH for use in canadian builds
while read bindir; do
export PATH="$bindir:$PATH"
done < <(find "$script_dir/toolchains/host_$(fn_os_arch)"* -maxdepth 1 -type d -name bin)
unset bindir
# Dump out the resulting path
echo '$PATH:'
echo "$PATH" | tr ':' '\n'
if [[ ${#positional_args[@]} -eq 0 ]]; then
positional_args+=(build)
fi
if [[ ${#positional_args[@]} -eq 1 ]] && [[ "${positional_args[0]}" == "source" ]]; then
ct-ng source || true
else
nice -n 10 ionice -c 3 ct-ng ${positional_args[@]}
if [ -n "${canadian_host:-}" ] && [ -n "$(echo $toolchain_dir | grep macos)" ]; then
# Patch the `@rpath` of the toolchain binaries so that they look in `@executable_path/../lib` for libraries
find "$toolchain_dir/bin" -type f -executable -exec "${canadian_host}-install_name_tool" -add_rpath "@executable_path/../lib" '{}' \;
# Copy across libstdc++ for gdb
cp /gcc/${canadian_host}/lib/libstdc++.6.dylib "$toolchain_dir/lib"
# Codesign macOS executables
find "$toolchain_dir" -type f -executable -print -exec rcodesign sign '{}' \; || true
fi
fi
}