-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-cross-linux-toolchain.sh
More file actions
executable file
·1556 lines (1352 loc) · 46.2 KB
/
build-cross-linux-toolchain.sh
File metadata and controls
executable file
·1556 lines (1352 loc) · 46.2 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
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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
set -u
set -o errexit
set -o pipefail
PS4='+$(date +%Y-%m-%d:%H:%M:%S) (${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
## Find our executable location
execdir=`dirname $0`
execdir=`cd $execdir; pwd`
default_target=aarch64-none-linux-gnu
all_args="$*"
this_script="build-cross-linux-toolchain.sh"
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if [ ! -f "$script_dir/utilities.sh" ]; then
echo "error:Could not find helper script at $script_dir/utilities.sh"
exit 1
else
source $script_dir/utilities.sh
fi
tmpdir=$(mktemp -d)
trap cleanup 0
if [ "$(uname -s)" == "Darwin" ]; then
set_darwin_envvars
fi
usage ()
{
cat <<EOF
usage: $this_script [OPTION] [STAGE]
Build linux cross toolchains targetting a specified architecture.
Without a stage, $this_script will start with "start" and sequence through each of the build stages. At each stage
progress is recorded. Should execution stop and subsequently be restarted, $this_script will continue from the
recorded progress point. With one or more stage arguments, $this_script will ignore any recorded progress and
proceed directly with the specified stages, in the order specified.
Many of the stages are "chained", once complete they chain into the next stage of the build process. The chained
stages generally have an unchained equivalent, which if specified, will trigger just the execution of that stage.
These unchained stages are convenient for development.
Interesting stages are:
clean:
Wipe the build and head for stage start.
start
The default stage.
check
A pseudo stage that invokes all available check stages.
binutils (the unchained binutils-chained)
Build binutils.
gcc3 (the unchained gcc3-chained)
Build stage 3 gcc.
libc (the unchained libc-chained)
Build glibc.
Options are:
--bugurl=TEXT
Define the --with-bugurl=FOO configuration option text for relevant packages.
--builddir=DIR
Define the build directory to be used. Defaults to the current working
directory.
--[no-]check-gdb
Enable check-gdb as a target for check. Default off. Using this will run
gdb testing by default.
--config-flags-binutils=FLAGS
Specify additional configuration flags for binutils.
--config-flags-gcc=FLAGS
Specify additional configuration flags for gcc.
--config-flags-host-tools=FLAGS
Specify additional configuration flags for host-tools.
--config-flags-libc=options
Pass options to the configuration of libc.
--config-flags-qemu=FLAGS
Specify additional configuration flags for qemu.
--debug
Options for debugging the toolchain. Builds the host components of
the toolchain with extra debugging information. Disabled by default.
--debug-target
Enable debugging options when building target code (e.g. target
libraries such as libgcc and libstdc++). Disabled by default.
--dejagnu-site=Alternative site.exp file to be used.
Specify name of an alternative site.exp to be used along with --dejagnu-src
if on a different path. Else this will look for the named site.exp in
the default location. Default is to use site-exhaustive-fastmodels.exp.
--dejagnu-src=PATH.
Define the PATH to a dejagnu install. Default is to use the relative
path from gnu-devtools-for-arm/dejagnu in the source area.
--enable-gdb
--disable-gdb
Disable building and testing GDB. The default is to build GDB.
--enable-gcc
--disable-gcc
Disable building and testing GCC. Default enabled.
--enable-binutils
--disable-binutils
Disable building and testing Binutils. Default enabled.
--enable-gdb-with-python=PATH
Enable building GDB with Python support. PATH determines configuration
file behavior. 'yes' enables Python support. PATH can be also a path to
special python-config.sh script which helps to determine local Python
environment settings. Default disabled.
--enable-maintainer-mode
--disable-maintainer-mode
Enable or disable maintainer mode, default disable.
--enable-qemu
--disable-qemu
Disable building QEMU. Default enabled.
--morello
Build Morello toolchain.
-h, --help
Print brief usage information and exit.
--host
The host triple to use. Defaults to that of the build machine (i.e.
the machine on which this script is run).
--host-toolchain-path=DIR)
Path to the host toolchain. Default is to use a toolchain
on the standard PATH.
-j N
Use a maximum of N threads of parallel tasks.
-l N
Do not spawn additional threads whilst the system load is N (a
floating-point number) or more
--[no-]package
Enable or disable packaging.
--qemu-test-path=PATH
Define a PATH to be add to environment PATH in order to find
an appropriate pre-built qemu for testing.
--[no-]release
Enable a release build. Default off. Turns down self consistency
checking, turns up optimization and disables debug support.
--resultdir=PATH
PATH to a directory to copy all test results into.
--srcdir=PATH
PATH to a directory containing all the source modules required
for the build. Default <builddir>/src
--tag=FOO
Define the build tag / version identifier to be hardwired into
the built components that support such a concept. Default 'unknown'.
--tardir=PATH
PATH to a directory where the built binary tar balls should be placed.
Default <builddir>
--target=GNU-TRIPLE
The GNU-TRIPLE that the built toolchain should target. Default
$default_target.
--target-board=BOARD
Specify a dejagnu target board. Defaults to site.exp selection.
--timestamp=TIMESTAMP
--with-language=LANGUAGE
Add the specified language to the gcc configure line.
-x
Enable shell debugging of this script.
EOF
}
## The stack of stages is abstracted out to these functions primarily to
## isolate the pain of bash arrays in conjunction with set -u. We want
## set -u behaviour on in order to improve script robustness. However
## bash arrays do not play nicely in this context. Notably taking
## the ${# size of an empty array will throw an exception.
declare -a stages
stages=()
cwd=`pwd`
set_gdb_config()
{
# GDB now requires mpfr [1] and prefix is required when using --with-gmp and --with-mpfr options.
# We still want to keep the previous config flags --with-libgmp-prefix, --with-libgmp-type, --with-libmpfr-type, and --with-libmpfr-prefix
# so that previous versions of GDB can still build.
# [1] See commit 991180627851801f1999d1ebbc0e569a17e47c74 from binutils-gdb--gdb: Use toplevel configure for GMP and MPFR for gdb.
# https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=991180627851801f1999d1ebbc0e569a17e47c74
gdb_config="--enable-64-bit-bfd \
--enable-targets="$enable_binutils_targets" \
--target="$target" \
${bugurl:+--with-bugurl="\"$bugurl\""} \
--enable-initfini-array \
--enable-plugins \
--enable-tui \
--disable-binutils \
--disable-sim \
--disable-as \
--disable-ld \
--disable-doc \
--disable-gdbtk \
--disable-nls \
--disable-werror \
--without-x \
--prefix="${host_prefix}" \
--with-build-sysroot="${build_sysroot}" \
--with-sysroot="${sysroot}" \
${hostmpfr:+--with-libmpfr-prefix=$hostmpfr} \
${hostmpfr:+--with-libmpfr-type=static} \
${hostmpfr:+--with-mpfr=$hostmpfr} \
${hostgmp:+--with-libgmp-prefix=$hostgmp} \
${hostgmp:+--with-libgmp-type=static} \
${hostgmp:+--with-gmp=$hostgmp} \
${extra_config_flags_binutils:-} \
${extra_config_flags_host_tools:-} \
${extra_config_flags_gdb:-}"
}
## The layout version for the binary tar ball we create. This should be stepped
## each time we change the structure of the delivered tar ball.
layout_version="2"
# Reload configuration options
if [ -r build.status ]; then
. build.status
fi
## Enabled by default, but note may be overridden by host or target options
package_flag=0
release_flag=0
gdb_only_flag=0
extra_languages=""
flag_check_gdb=0
flag_debug_options_flag=0
flag_debug_target_flag=0
flag_enable_gdb=1
flag_enable_gcc=1
flag_enable_binutils=1
enable_multiarch=0
flag_enable_qemu=1
flag_enable_mingw=0
flag_morello=0
libname=glibc
# All the check targets supported by this script.
check_targets="check-binutils check-gdb check-ld check-gold check-gas check-gcc check-g++ check-fortran check-target-libatomic check-target-libstdc++-v3 check-target-libgomp check-ffi"
# Parse command-line options
args=$(getopt -ohj:l:x -l bugurl:,builddir:,config-flags-binutils:,config-flags-gcc:,config-flags-host-tools:,config-flags-libc:,config-flags-qemu:,debug,debug-target,dejagnu-site:,dejagnu-src:,enable-gdb,enable-gdb-with-python:,disable-gdb,enable-gcc,disable-gcc,enable-binutils,disable-binutils,enable-maintainer-mode,disable-maintainer-mode,enable-qemu,disable-qemu,enable-multiarch,disable-multiarch,gdb-only,help,host-toolchain-path:,package,no-package,release,no-release,resultdir:,srcdir:,tag:,tardir:,target:,target-board:,timestamp:,with-language:,check-gdb,no-check-gdb,morello,host: -n $(basename "$0") -- "$@")
eval set -- "$args"
while [ $# -gt 0 ]; do
if [ -n "${opt_prev:-}" ]; then
eval "$opt_prev=\$1"
opt_prev=
shift 1
continue
elif [ -n "${opt_append:-}" ]; then
eval "$opt_append=\"\${$opt_append:-} \$1\""
opt_append=
shift 1
continue
fi
case $1 in
--bugurl)
opt_prev=bugurl
;;
--builddir)
opt_prev=builddir
;;
--check-gdb)
flag_check_gdb=1
;;
--no-check-gdb)
flag_check_gdb=0
;;
--config-flags-binutils)
opt_append=extra_config_flags_binutils
;;
--config-flags-gcc)
opt_append=extra_config_flags_gcc
;;
--config-flags-host-tools)
opt_append=extra_config_flags_host_tools
;;
--config-flags-qemu)
opt_append=extra_config_flags_qemu
;;
--debug)
flag_debug_options_flag=1
;;
--debug-target)
flag_debug_target_flag=1
;;
--dejagnu-site)
opt_prev=dejagnu_site
;;
--dejagnu-src)
opt_prev=dejagnu_src
;;
--enable-gdb)
flag_enable_gdb=1
;;
--disable-gdb)
flag_enable_gdb=0
;;
--enable-gcc)
flag_enable_gcc=1
;;
--disable-gcc)
flag_enable_gcc=0
;;
--enable-binutils)
flag_enable_binutils=1
;;
--disable-binutils)
flag_enable_binutils=0
;;
--enable-maintainer-mode)
flag_maintainer_mode=1
;;
--disable-maintainer-mode)
flag_maintainer_mode=0
;;
--morello)
flag_morello=1
;;
--enable-gdb-with-python)
opt_prev=gdb_with_python
;;
--config-flags-libc)
opt_append=extra_config_flags_libc
;;
--disable-multiarch)
enable_multiarch=0
;;
--enable-multiarch)
enable_multiarch=1
;;
--enable-qemu)
flag_enable_qemu=1
;;
--disable-qemu)
flag_enable_qemu=0
;;
-h | --help)
usage
exit 0
;;
--host)
opt_prev=host
;;
--host-toolchain-path)
opt_prev=host_toolchain_path
;;
-j)
opt_prev=flag_parallel
;;
-l)
opt_prev=flag_load
;;
--package)
package_flag=1
;;
--gdb-only)
gdb_only_flag=1
;;
--no-package)
package_flag=0
;;
--release)
package_flag=1
release_flag=1
;;
--no-release)
release_flag=0
;;
--resultdir)
opt_prev=resultdir
;;
--srcdir)
opt_prev=srcdir
;;
--tag)
opt_prev=tag
;;
--tardir)
opt_prev=tardir
;;
--target)
opt_prev=target
;;
--target-board)
opt_prev=target_board
;;
--timestamp)
opt_prev=timestamp
;;
--with-language)
opt_append=extra_languages
;;
-x)
set -x
;;
--)
shift
break 2
;;
esac
shift 1
done
build=`find_build_triple`
if [[ "$build" == *"darwin"* ]]; then
TAR_CMD=gtar
host_is_darwin=1
else
TAR_CMD=tar
host_is_darwin=0
fi
if [ -n "${flag_parallel:-}" ]; then
parallel="-j$flag_parallel"
else
parallel="-j`number_of_cores`"
fi
if [ -n "${flag_load:-}" ]; then
parallel="${parallel:-} -l$flag_load"
fi
# If the host triple hasn't been given on the command-line, default to
# the triple of the machine we're building on.
if [ -z "${host:-}" ]; then
host="$build"
fi
native_build=0
if [ "$build" == "$host" ] && [ "$host" == "$target" ]; then
native_build=1
fi
if [ $# -gt 0 ]; then
stages=("$@")
fi
languages=c,c++
for language in $extra_languages
do
languages="$languages,$language"
done
# Set a default build tag if we didn't get one on the command line.
tag="${tag:-unknown}"
# target
target=${target:-$default_target}
timestamp=${timestamp:-`date +"%Y%m%d-%H%M%S"`}
# builddir: where to build the programs
builddir=${builddir:-$cwd}
# Set a default value for tardir.
tardir="${tardir:-$builddir/bin-tar}"
# Install prefix.
prefix="${prefix:-/}"
host_prefix=
# Install tree staging directory.
installdir="${installdir:-$builddir/install}"
# Install tree staging area for qemu build.
qemu_installdir="${qemu_installdir:-$builddir/install-qemu}"
# Install tree staging area for gdb only.
gdb_only_installdir="${gdb_only_installdir:-$builddir/install-gdb}"
srcdir="${srcdir:-$builddir/src}"
objdir="${objdir:-$builddir/obj}"
resultdir="${resultdir:-$builddir/results}"
build_flags_path="$installdir$prefix/.build_flags"
# Install dir for host tools.
host_tools_install=$builddir/host-tools
build_sysroot=${installdir}/${host_prefix}/${target}/libc
stage_include="$builddir"/stage-include
sysroot=${host_prefix}/${target}/libc
# The machine setup may have set LD_RUN_PATH when installing gcc
# we really do not want this since it will affect both host and cross toolchains
export -n LD_RUN_PATH
case "${extra_config_flags_host_tools:-}" in
*--host=*mingw*)
# MinGW builds are special case and are only used for toolchain official
# releases. We do not redistribute QEMU. Newlib and Newlib-nano are off
# as we build Newlib* libraries (if needed) in separate build passes.
flag_enable_mingw=1
flag_enable_qemu=0
# Explicitly use -static-libstdc++ and -static-libgcc
# Default linking behavior of GDB changed. It was static linking by
# default. Now it has to be explicitly enabled with
# --with-static-standard-libraries flag
extra_config_flags_gdb="${extra_config_flags_gdb:-} --disable-source-highlight --with-static-standard-libraries"
;;
esac
if [ $flag_enable_mingw -eq 0 ]; then
# For MinGW, --host is passed via $extra_config_flags_host_tools.
# FIXME: MinGW builds should really use this new --host option instead.
# Then we can remove this logic.
host_config_flag="--host=$host"
fi
if [ $release_flag -eq 0 ]; then
if [ $flag_debug_options_flag -eq 0 ]; then
cflags="-O1 -g"
else
cflags="-O0 -g3"
fi
flag_check_bootstrap="${flag_check_bootstrap:-yes}"
flag_check_final="${flag_check_final:-yes}"
else
cflags="-O2"
flag_check_bootstrap="${flag_check_bootstrap:-yes}"
flag_check_final="${flag_check_final:-release}"
fi
if [ $flag_debug_target_flag -eq 1 ]; then
cflags_for_target="-O0 -g3"
fi
target_prefix=/usr
target_lib=lib
multilib_purecap=0
case $target in
arm*-*-linux-gnueabi* | arm*-linux-gnueabi*)
extra_config_flags_gcc="${extra_config_flags_gcc:-} --with-arch=armv7-a"
linux_arch=arm
qemu_target=arm-linux-user,armeb-linux-user
enable_binutils_targets="arm-none-eabi,arm-none-linux-gnueabihf,armeb-none-eabi,armeb-none-linux-gnueabihf"
;;
aarch64*-*-linux-gnu* | aarch64*-linux-gnu)
linux_arch=arm64
qemu_target="aarch64-linux-user,aarch64_be-linux-user"
enable_binutils_targets="arm-none-eabi,aarch64_be-none-linux-gnu,aarch64_be-none-elf,aarch64-none-linux-gnu,aarch64-none-linux-gnu_ilp32,aarch64-none-elf"
extra_config_flags_gcc="${extra_config_flags_gcc:-} --enable-fix-cortex-a53-843419"
target_lib=lib64
case $target in *ilp32)
# check configure?
target_lib=libilp32
extra_config_flags_gcc="${extra_config_flags_gcc:-} --disable-libsanitizer"
esac
multilib_purecap=$flag_morello
build_purecap=$flag_morello
case $target in *purecap)
target_lib=lib64c
multilib_purecap=0
build_purecap=1
esac
if [ $build_purecap -eq 1 ]; then
# disable non-purecap-compatible libs
extra_config_flags_gcc="${extra_config_flags_gcc:-} --disable-libsanitizer --disable-libgomp --disable-libitm"
# avoid cheri warnings breaking libc-headers build
extra_config_flags_libc="${extra_config_flags_libc:-} --disable-werror"
# only c,c++ is supported
extra_languages=
fi
;;
*)
printf "error: $target not recognized\n" >&2
exit 1
;;
esac
libc_cv_slibdir=""
libc_cv_rtlddir=""
case $target in
aarch64-*-linux-gnu | aarch64-linux-gnu)
target_tuple=aarch64-linux-gnu
ldsoname="ld-linux-aarch64.so.1"
if [ $multilib_purecap -eq 1 ]; then
purecap_ldsoname="ld-linux-aarch64_purecap.so.1"
purecap_abi="-mabi=purecap -march=morello+c64"
purecap_libname="$libname-purecap"
purecap_target_lib=lib64c
# No multiarch support for now.
purecap_target_libdir="$target_prefix/$purecap_target_lib"
if [ $enable_multiarch -eq 1 ]; then
printf "error: multiarch is not supported with multilib" >&2
exit 1
fi
fi
;;
aarch64*-linux-gnu_purecap)
target_tuple=aarch64-linux-gnu_purecap
ldsoname="ld-linux-aarch64_purecap.so.1"
;;
aarch64*-linux-gnu_ilp32)
target_tuple=aarch64-linux-gnu_ilp32
# This is not necessary but one day we will support multilib
abi="-mabi=ilp32"
ldsoname="ld-linux-aarch64_ilp32.so.1"
;;
aarch64_be-*-linux-gnu | aarch64_be-linux-gnu)
target_tuple=aarch64_be-linux-gnu
ldsoname="ld-linux-aarch64_be.so.1"
if [ $multilib_purecap -eq 1 ]; then
printf "error: $target is not supported with multilib purecap" >&2
exit 1
fi
;;
arm-*-linux-gnueabi | arm-linux-gnueabi)
target_tuple=arm-linux-gnueabi
ldsoname="ld-linux.so.3"
;;
arm-*-linux-gnueabihf | arm-linux-gnueabihf)
target_tuple=arm-linux-gnueabihf
ldsoname="ld-linux-armhf.so.3"
;;
armeb-*-linux-gnueabi | armeb-linux-gnueabi)
target_tuple=arm-linux-gnueabi
ldsoname="ld-linux.so.3"
;;
armeb-*-linux-gnueabihf | armeb-linux-gnueabihf)
target_tuple=arm-linux-gnueabihf
ldsoname="ld-linux-armhf.so.3"
;;
*)
echo "Specify one {arm x86 ppc mips} architecture to build."
exit 1
;;
esac
## Ensure the work directory exists
mkdir -p "$builddir"
cd "$builddir"
for component in gcc linux "$libname" gmp mpfr mpc binutils isl
do
find_component_or_error "$srcdir" $component
done
for component in cloog libffi libiconv newlib qemu
do
find_component "$srcdir" "$component" || true
done
if [ -d "$srcdir/binutils-gdb" ]; then
binutils_src="$srcdir/binutils-gdb"
fi
gdb_src="$binutils_src"
if [ -d "$srcdir/binutils-gdb--gdb" ]; then
gdb_src="$srcdir/binutils-gdb--gdb"
fi
eval libc_src="\${${libname}_src}"
# dejagnu site.exp
dejagnu_site="${dejagnu_site:-site-exhaustive-fastmodels.exp}"
if [ -z "${dejagnu_src:-}" ]; then
# The dejagnu directory should be available in gnu-devtools-for-arm
find_component_or_error "$srcdir/gnu-devtools-for-arm" dejagnu
fi
##Set the DEJAGNU environment variable for check targets
set_env_var DEJAGNU "$dejagnu_src/$dejagnu_site"
check_if_readable $DEJAGNU
std_libc_config_opts="--enable-shared --with-tls --disable-profile --disable-omitfp --disable-bounded --disable-sanity-checks"
if [ $enable_multiarch -eq 1 ]; then
std_libc_config_opts="$std_libc_config_opts --enable-multi-arch --libdir=/lib/$target_tuple"
libc_cv_slibdir="/lib/$target_tuple"
libc_cv_rtlddir="/lib"
fi
AARCH64SYSROOT="$build_sysroot"
export AARCH64SYSROOT
if empty_stages_p; then
if [ -r ,stage ]; then
# Continue from last failing stage
stages=(`cat ,stage`)
else
# Build from the start
stages=(start)
fi
fi
hostgmp="$host_tools_install"
hosticonv="$host_tools_install"
hostmpfr="$host_tools_install"
hostmpc="$host_tools_install"
hostexpat="$host_tools_install"
# We are (currently) tolerant to absence ISL and CLOOG hence we only setup
# the relevant --with- flags if the source is present. These are set here
# rather than in the corresponding build or install stages because it is a
# valid use case to repeatedly restart a build at an arbitrary stage.
if [ -d "$srcdir/isl" ];
then
hostisl="$host_tools_install"
# CLOOG requires ISL hence only enable if ISL is also enabled.
if [ -d "$srcdir/cloog" ];
then
hostcloog="$host_tools_install"
fi
fi
# Ensure binutils components are visible in the PATH
PATH_ORIGINAL="$PATH"
PATH="${installdir}/${host_prefix}/bin:${qemu_installdir}/${host_prefix}/bin:$execdir:$PATH"
if [ -n "${host_toolchain_path:-}" ]; then
PATH="$host_toolchain_path:$PATH"
fi
target_rtlddir="$target_prefix/lib"
if [ "$enable_multiarch" -eq 1 -a -n "${target_tuple:-}" ]; then
target_libdir="$target_prefix/lib/$target_tuple"
else
target_libdir="$target_prefix/$target_lib"
fi
RUNTESTFLAGS="${target_board:+--target_board=$target_board} ${RUNTESTFLAGS:-}"
# 8GB limit on ulimit -v
# Note that 32 bit qemu guest on 64 bit host will request 4GB reserved
# virtual address space.
memlimit=8000000
while true; do
# If jump_stage is set to a stage, it is run instead of popping an item
# from the stage list. This allows running a stage without recording it
# on disk which is necessary if it cannot be restarted on interrupt.
if [ -n "${jump_stage:-}" ]; then
stage="$jump_stage"
jump_stage=
else
if empty_stages_p; then
push_stages stop
fi
# Record the current build stage and shift
echo "${stages[*]}" >,stage
pop_stages
stage="$item"
fi
update_stage "$stage"
case "$stage" in
clean)
rm -rf "$installdir"
rm -rf "$prefix"
rm -rf "$objdir"
rm -rf "$qemu_installdir"
rm -rf "$gdb_only_installdir"
push_stages "start"
;;
start)
mk_bin_dirs $host_prefix $build_sysroot
write_build_status > build.status
push_stages gmp mpfr mpc isl cloog iconv qemu binutils-chain gdb perms
;;
gmp)
gmp_srcdir=$gmp_src
gmp_objdir=$objdir/gmp
gmp_config="--disable-maintainer-mode --disable-shared --prefix=${host_tools_install} ${extra_config_flags_host_tools:-} ${host_config_flag:-}"
do_config_build_install gmp
;;
mpfr)
mpfr_srcdir=$mpfr_src
mpfr_objdir=$objdir/mpfr
mpfr_config="--disable-maintainer-mode --disable-shared --prefix=${host_tools_install} ${hostgmp:+--with-gmp=$hostgmp} ${extra_config_flags_host_tools:-}"
do_config_build_install mpfr
;;
mpc)
mpc_srcdir=$mpc_src
mpc_objdir=$objdir/mpc
mpc_config="--disable-maintainer-mode --disable-shared --prefix=${host_tools_install} ${hostgmp:+--with-gmp=$hostgmp} ${hostmpfr:+--with-mpfr=$hostmpfr} ${extra_config_flags_host_tools:-}"
do_config_build_install mpc
;;
isl)
if [ -n "${hostisl:-}" ]; then
isl_srcdir=$isl_src
isl_objdir=$objdir/isl
isl_config="--disable-maintainer-mode --disable-shared --prefix=${host_tools_install} ${hostgmp:+--with-gmp-prefix=$hostgmp} ${extra_config_flags_host_tools:-}"
do_config_build_install isl
fi
;;
cloog)
if [ -n "${hostcloog:-}" ]; then
cloog_srcdir=$cloog_src
cloog_objdir=$objdir/cloog
cloog_config="--disable-maintainer-mode --disable-shared --prefix=${host_tools_install} ${hostgmp:+--with-gmp-prefix=$hostgmp} ${hostisl:+--with-isl-prefix=$hostisl} ${extra_config_flags_host_tools:-}"
do_config_build_install cloog
fi
;;
qemu)
if [ $flag_enable_qemu -eq 1 -a -n "${qemu_src:-}" ]; then
qemu_parallel=0
qemu_srcdir="$qemu_src"
qemu_objdir="$objdir/qemu"
qemu_config="--target-list=$qemu_target \
--prefix=${qemu_installdir}/${host_prefix} \
--disable-strip \
--disable-werror \
--disable-docs \
--disable-kvm \
--disable-system \
--disable-tools \
${extra_config_flags_qemu:-}"
do_config_build_install qemu
fi
;;
iconv)
if [ $flag_enable_mingw -eq 1 ]; then
iconv_srcdir="$libiconv_src"
iconv_objdir="$objdir/iconv"
iconv_config="--prefix=$hosticonv \
--disable-shared \
${extra_config_flags_host_tools:-}"
do_config_build_install iconv
fi
;;
binutils-chain)
push_stages binutils gcc1-chain
;;
binutils)
binutils_srcdir=$binutils_src
binutils_objdir=$objdir/binutils
extra_config_flags_binutils="${extra_config_flags_binutils:-} --without-debuginfod"
if [ $flag_enable_mingw -eq 1 ]; then
extra_config_flags_binutils="${extra_config_flags_binutils:-} --disable-werror"
fi
if [ ${flag_maintainer_mode:-0} -eq 1 ]; then
extra_config_flags_binutils="${extra_config_flags_binutils:-} --enable-maintainer-mode"
fi
binutils_cflags="$cflags"
binutils_cxxflags="$cflags"
# binutils gold requires C++11. Add -std=gnu++11 as a temporary workaround to build binutils gold if GCC major version is less than 6.
gcc_major_ver=$( gcc -dumpfullversion -dumpversion | awk -F. '{print $1}' )
if [ $gcc_major_ver -lt 6 ]; then
binutils_cxxflags="$binutils_cxxflags -std=gnu++11"
fi
binutils_config="--enable-64-bit-bfd \
--enable-targets=$enable_binutils_targets \
--target=$target \
${bugurl:+--with-bugurl="\"$bugurl\""} \
--enable-gold \
--enable-initfini-array \
--enable-plugins \
--disable-doc \
--disable-gdb \
--disable-gdbtk \
--disable-nls \
--disable-tui \
--disable-werror \
--without-gdb \
--without-python \
--without-x \
--prefix=${host_prefix} \
--with-build-sysroot=${build_sysroot} \
--with-sysroot=${sysroot} \
${extra_config_flags_host_tools:-} \
${extra_config_flags_binutils:-}"
binutils_build_targets="all-binutils all-gas all-gprof all-ld all-gold"
binutils_install_targets="install-binutils install-gas install-ld install-gold install-gprof"
binutils_destdir=${installdir}
do_config_build_install binutils
;;
gdb)
if [ $flag_enable_gdb -eq 1 ]; then
extra_config_flags_gdb="${extra_config_flags_gdb:-} --without-debuginfod"
if [ -d "$srcdir/libexpat" ]; then
# With libexpat component present add libexpat to GDB configuration
extra_config_flags_gdb="${extra_config_flags_gdb:-} --with-expat --with-libexpat-prefix=${host_tools_install} --with-libexpat-type=static"
push_stages libexpat main-gdb gdbserver
else
push_stages main-gdb gdbserver
fi
fi
;;
libexpat)
libexpat_srcdir="$srcdir/libexpat/expat"
libexpat_objdir="$objdir/libexpat"
libexpat_config="--prefix="${host_tools_install}" \
--without-docbook \
--without-xmlwf \
${extra_config_flags_host_tools:-}"
libexpat_build_targets="lib"
libexpat_install_targets="install"
do_config_build_install libexpat
# Upgrade Note: Updating libexpat from version 2.2.5 to 2.7.1.
# Workaround: Delete libexpat.la to prevent incorrect linker flags from being injected
# when building GDB with a static archive of libexpat. This .la file may cause libtool
# or the build system to pull in unnecessary dependencies like -lm and the libm.a static
# archive, which leads to link errors in environments where libm is not available.
# Removing the .la file ensures a cleaner and more predictable link process.
rm -f $hostexpat/lib/libexpat.la
;;
main-gdb)
gdb_srcdir="$gdb_src"
gdb_objdir="$objdir/gdb"
if [ $flag_enable_mingw -eq 1 ]; then
extra_config_flags_gdb="${extra_config_flags_gdb:-} --disable-tui"
fi
saved_path="$PATH"
if [ $native_build -eq 1 ]; then
# If we're doing a native build (e.g. on aarch64 linux), then we want to
# make sure our GDB can do native debugging. For this to work, GDB
# needs to be in a native config (i.e. --host == --build == --target).
#
# Typically we will have a target like aarch64-none-linux-gnu, but
# if we don't set --host or --build, then configure will
# auto-detect --host=aarch64-unknown-linux-gnu, and since --host
# != --target in this case, native debugging will not be enabled.
#
# To fix this, we can force --host = --build = --target =
# aarch64-none-linux-gnu if we know we're doing a native build, but we
# must make sure to sanitize the PATH to avoid GDB picking up the
# newly-built tools and thus linking against the target libc.
#
# Dropping our newly-built tools from the PATH will force GDB to use the
# system tools and link against the system libc, which is what we want
# here.
PATH="$PATH_ORIGINAL"
extra_config_flags_gdb="${extra_config_flags_gdb:-} --host=$host --build=$build"
# We want the final binaries to be named e.g. $tuple-gdb, not just "gdb",