-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathbuild-toolchain.sh
executable file
·1260 lines (1042 loc) · 38.8 KB
/
build-toolchain.sh
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
#!/bin/sh
# Copyright (C) 2009 - 2014 Embecosm Limited
# Contributor Joern Rennecke <joern.rennecke@embecosm.com>
# Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
# Contributor Simon Cook <simon.cook@embecosm.com>
# This file is a script to build the Epiphany tool chain
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
# This is a convenience wrapper for the GNU toolchain build files.
# There are two possible ways of using this script
# 1. The compiler is intended to run on the same machine on which it is built
# (typically an Intel based PC or the ARM based Parallella board). The
# compiler will generate code for the Epiphany processor. Since the code
# is to run on a different machine to the platform on which the compiler
# is run, this is known as a *cross compiler*.
# 2. The compiler is intended to run on a *different* machine (known as the
# host) to that on which it is built. For Parallella this is invariably
# done on an Intel based PC to create a compiler which will run on the ARM
# based Parallella board where it will generate code for the Epiphany
# processor. The compiler is built on one machine to be hosted on a
# second machine to generate code for a third machine. This is known as a
# *Canadian cross compiler".
# In this script method 2 is trigged by setting the --host parameter to
# something other than the build architecture.
# When reading the comments in this script it is useful to be clear about
# three terms:
# build machine
# The platform on which this script is being run to build the compiler.
# host machine
# The platform on which the generated compiler will be run (invariably the
# Parallella ARM platform).
# target machine
# The platform for which the compiler will generate code. In this case for
# the Epiphany processor.
# On this notation, method 1 of using this script has build and host machines
# identical.
# Invocation:
# ./build-toolchain.sh [--build-dir <dir>]
# [--build-dir-build <dir>]
# [--build-dir-host <dir>]
# [--host <host-triplet>]
# [--install-dir <dir>]
# [--install-dir-build <dir>]
# [--install-dir-host <dir>]
# [--symlink-dir <dir>]
# [--destdir <dir>]
# [--datestamp-install]
# [--datestamp-install-build]
# [--datestamp-install-host]
# [--clean | --no-clean]
# [--clean-build | --no-clean-build]
# [--clean-host | --no-clean-host]
# [--preserve-unisrc | --rebuild-unisrc]
# [--unified-dir <dir>]
# [--auto-pull | --no-auto-pull]
# [--auto-checkout | --no-auto-checkout]
# [--jobs <count>] [--load <load>] [--single-thread]
# [--gmp | --no-gmp]
# [--mpfr | --no-mpfr]
# [--mpc | --no-mpc]
# [--isl | --no-isl]
# [--cloog | --no-cloog]
# [--target-cflags <flags>]
# [--config-extra <flags>]
# [--disable-werror | --enable-werror]
# [--enable-cgen-maint]
# [--help | -h]
# A number of arguments specify directories relative to the base directory.
# This is the parent directory of the directory containing this script. Other
# arguments use the release name, which is set up in the environment variable
# RELEASE. The meanings of the various options and their defaults are as
# follows.
# --build-dir-build <dir>
# The directory in which the tool chain to run on the *build* machine will
# be built. The default is builds/bd-epiphany-$RELEASE in the base
# directory.
# --build-dir <dir>
# --build-dir-host <dir>
# The directory in which the tool chain to run on the *host* machine will
# be built if needed. The default is builds/bd-epiphany-host-$RELEASE in
# the base directory. This argument is only relevant if --host is set to
# a triplet whose architecture differs from the build machine.
# --host <host-triplet>
# If specified, the tool chain will be built to run on the designated
# host. This is of most value to users wishing to build the toolchain on
# a PC, but to run on the Parallella board. Useful values are
# "arm-linux-gnu" on Fedora/Red Hat systems "arm-linux-gnueabihf" or
# "arm-linux-gnueabihf" on Ubuntu (the hf at the end signifying hardware
# floating point support, which Parallella has, and will yield a faster
# compiler).
# An Epiphany cross-compiler for the build machine is still needed (to
# build libraries). This will trigger building of GCC and binutils for the
# host unless those tools have been previously built, or are found in the
# existing search path.
# --install-dir-build <install_dir>
# The directory in which the tool chain to run on the *build* machine
# should be installed. If not specified, it will be installed in the
# /opt/adapteva/edsk.$RELEASE/tools/e-gnu.<build-arch> directory, where
# <build-arch> is the architecture name of the *build* machine (so should
# be one of x86, x86_64 or armv7l).
# --install-dir <install_dir>
# --install-dir-host <install_dir>
# The directory in which the tool chain to run on the *host* machine
# should be installed if needed. If not specified, it will be installed in
# the /opt/adapteva/edsk.$RELEASE/tools/e-gnu.<host-arch> directory, where
# <host-arch> is the architecture name of the *host* machine (so should
# usually be armv7l). This argument is only relevant if --host is set to
# a triplet whose architecture differs from the build machine.
# --destdir <destdir>
# If specified, all files will be installed to <destdir> staging
# directory.
# --symlink-dir <symlink_dir>
# If specified, the install directory will be symbolically linked to this
# directory. It must be a plain relative directory name (no
# hierarchy). It defaults to e-gnu. If a hierarchy is given, only the
# basename will be used.
# --datestamp-install-build
# If specified, this will insert a date and timestamp in the install
# directory name for the *build* architecture. If the install directory
# has the default name, the datestamp will be inserted after the $RELEASE,
# otherwise it will be appended to the name.
# --datestamp-install
# --datestamp-install-host
# If specified, this will insert a date and timestamp in the install
# directory name for the *host* architecture. If the install directory
# has the default name, the datestamp will be inserted after the $RELEASE,
# otherwise it will be appended to the name.
# --clean-build | --no-clean-build
# If --clean-build is specified, delete any previous build directory for
# the *build* machine. Default --no-clean-build.
# --clean | --no-clean
# --clean-host | --no-clean-host
# If --clean or --clean-host is specified, delete any previous host
# directory for the *host* machine. Default --no-clean-host. This
# argument is only relevant if --host is set to a triplet whose
# architecture differs from the build machine.
# --auto-pull | --no-auto-pull
# If specified, a "git pull" will be attempted in each component
# repository after checkout to ensure the latest code is in use. Default
# is --auto-pull. Note that pulling will only be attempted in components
# which are git repositories, so this may safely be used, even if some
# component trees are not git repositories.
# --auto-checkout | --no-auto-checkout
# If specified, a "git checkout" will be attempted in each component
# repository to ensure the correct branch is checked out. Default is
# --auto-checkout. Note that checkout will only be attempted in
# components which are git repositories, so this may safely be used, even
# if some component trees are not git repositories.
# --preserve-unisrc | --rebuild-unisrc
# If --preserve-unisrc is specified, use an existing unified source tree
# if it exists. If --rebuild-unisrc is specified blow away any existing
# source tree and rebuild it. Default --preserve-unisrc.
# --unified-dir <dir>
# Specify the name of the unified directory. The default is
# unisrc-<release>, where release is the name of the release being built
# (defined by the branch of this repository) in the base directory.
# --jobs <count>
# Specify that parallel make should run at most <count> jobs. The default
# is one more than the number of processor cores shown by /proc/cpuinfo.
# --load <load>
# Specify that parallel make should not start a new job if the load
# average exceed <load>. The default is one more than the number of
# processor cores shown by /proc/cpuinfo.
# --single-thread
# Equivalent to --jobs 1 --load 1000. Only run one job at a time, but run
# whatever the load average.
# --gmp | --no-gmp
# --mpfr | --no-mpfr
# --mpc | --no-mpc
# --isl | --no-isl
# --cloog | --no-cloog
# --ncurses | --no-ncurses
# Indicate that the corresponding GCC infrastructure component exists as a
# source directory within the base directory and should be linked into the
# unified source directory. With the "--no-" versions, indicate the
# component is not available as a source directory, and that the compiler
# should rely on the installed developer package for the relevant headers
# and libraries.
# Note that in this case it is the *developer* version of the package that
# must be installed. Specifiying --no-gmp, --no-mpfr or --no-mpc if the
# corresponding developer package is not available will cause tool chain
# building to fail. Specifying --no-isl or --no-cloog when the developer
# package is not available will cause some GCC optimizatiosn to be
# omitted. Specifying --no-ncurses when the developer cross-compiled
# package is not available will cause a Canadian Cross build (i.e. with
# different build and host architectures) to fail.
# Defaults --gmp --mpfr --mpc --isl --cloog --ncurses.
# --expat | --no-expat
# Indicate that the corresponding GDB infrastructure component exists as a
# source directory within the base directory and should be linked into the
# unified source directory. With the "--no-" versions, indicate the
# component is not available as a source directory, and that the compiler
# should rely on the installed developer package for the relevant headers
# and libraries.
# Defaults --expat
# --target-cflags <flags>
# Specify C flags to be used when building target libraries (libgcc.a,
# libc.a and libm.a). For example specifying -Os -g would cause libraries
# to be built optimized for small size and suitable for debugging.
# The default "-O2 -g" is because constant merging in the assembler/linker
# does not work.
# --config-extra <flags>
# This is an option for developers, allowing additional flags to be
# specified when configuring the tool chain.
# --disable-werror | --enable-werror
# This is an option for developers, allowing them to compile the tool
# chain with the -Werror option. This is generally good practice for such
# users, to ensures any new code is as robust as possible. However it is
# not recommended for general use, since the wide variety and age of
# compilers used mean that errors will be triggered, just due to historic
# incompatibilities, but which have no impact on the quality of the
# compiler.
# --enable-cgen-maint
# This is an option for developers allowing the CGEN tables to be
# rebuilt. This is required after a change to the CGEN description, so
# the new specifications are included in the assembler/disassembler and
# simulator.
# --help | -h
# Print out a short message about usage.
# The script returns 0 if the tool chain was successfully built, and 1
# otherwise. Note that some errors do not prevent a tool chain being built,
# so will generate warning messages in the log, but the script will still
# return 0.
# Define the basedir
d=`dirname "$0"`
basedir=`(cd "$d/.." && pwd)`
# Common functions
. ${basedir}/sdk/common-functions
# Set the release parameters
. ${basedir}/sdk/define-release.sh
# Set up a clean log
logfile=${LOGDIR}/build-$(date -u +%F-%H%M).log
rm -f "${logfile}"
echo "Logging to ${logfile}"
################################################################################
# #
# Parse arguments #
# #
################################################################################
# Defaults
bd_build=
bd_host=
host=
id_build=
id_host=
staging_host=
destdir=
symlink_dir=e-gnu
ds_build=
ds_host=
do_clean_build="--no-clean-build"
do_clean_host="--no-clean-host"
auto_pull="--auto-pull"
auto_checkout="--auto-checkout"
rebuild_unisrc="--preserve-unisrc"
unisrc_dir=${basedir}/unisrc-${RELEASE}
jobs=
load=
# TODO: Get rid of all these flags. If you don't want something comment out the
# line in the components file.
do_gmp="--gmp"
do_mpfr="--mpfr"
do_mpc="--mpc"
do_isl="--isl"
do_cloog="--no-cloog"
do_ncurses="--ncurses"
do_expat="--expat"
# The assembler and/or linker are broken so that constant merging doesn't
# work.
CFLAGS_FOR_TARGET=${CFLAGS_FOR_TARGET:-"-O2 -g"}
CXXFLAGS_FOR_TARGET=${CXXFLAGS_FOR_TARGET:-"-O2 -g"}
CFLAGS=${CFLAGS:-"-O2 -g"}
CXXFLAGS=${CXXFLAGS:-"-O2 -g"}
config_extra=""
disable_werror="--disable-werror"
until
opt=$1
case ${opt} in
--build-dir-build)
shift
bd_build=`absdir "$1"`
;;
--build-dir | --build-dir-host)
shift
bd_host=`absdir "$1"`
;;
--host)
shift
host="$1"
;;
--install-dir-build)
shift
id_build=`absdir "$1"`
;;
--install-dir | --install-dir-host)
shift
id_host=`absdir "$1"`
;;
--destdir)
shift
destdir="$(absdir $1 | sed s,[/]*$,,g)/"
;;
--symlink-dir)
shift
# Force it to be simple name
symlink_dir="`basename $1`"
;;
--datestamp-install-build)
ds_build=-`date -u +%F-%H%M`
;;
--datestamp-install | --datestamp-install-host)
ds_host=-`date -u +%F-%H%M`
;;
--clean-build | --no-clean-build)
do_clean_build="$1"
;;
--clean)
do_clean_host="--clean-host"
;;
--no-clean)
do_clean_host="--no-clean-host"
;;
--clean-host | --no-clean-host)
do_clean_host="$1"
;;
--preserve-unisrc | --rebuild-unisrc)
rebuild_unisrc="$1"
;;
--unified-dir)
shift
unisrc_dir="$1"
;;
--auto-pull | --no-auto-pull)
auto_pull="$1"
;;
--auto-checkout | --no-auto-checkout)
auto_checkout="$1"
;;
--jobs)
shift
jobs=$1
;;
--load)
shift
load=$1
;;
--single-thread)
jobs=1
load=1000
;;
--gmp | --no-gmp)
do_gmp="$1"
;;
--mpfr | --no-mpfr)
do_mpfr="$1"
;;
--mpc | --no-mpc)
do_mpc="$1"
;;
--isl | --no-isl)
do_isl="$1"
;;
--cloog | --no-cloog)
do_cloog="$1"
;;
--ncurses | --no-ncurses)
do_ncurses="$1"
;;
--expat | --no-expat)
do_expat="$1"
;;
--target-cflags)
shift
CFLAGS_FOR_TARGET="$1"
;;
--config-extra)
shift
config_extra="${config_extra} $1"
;;
--disable-werror | --enable-werror)
disable_werror="$1"
;;
--enable-cgen-maint)
config_extra="${config_extra} --enable-cgen-maint"
;;
?*)
echo "Usage: ./build-toolchain.sh [--build-dir <dir>]"
echo " [--build-dir-build <dir>]"
echo " [--build-dir-host <dir>]"
echo " [--host <host-triplet>]"
echo " [--install-dir <dir> ]"
echo " [--install-dir-build <dir> ]"
echo " [--install-dir-host <dir> ]"
echo " [--symlink-dir <dir>]"
echo " [--datestamp-install]"
echo " [--datestamp-install-build]"
echo " [--datestamp-install-host]"
echo " [--clean | --no-clean]"
echo " [--clean-build | --no-clean-build]"
echo " [--clean-host | --no-clean-host]"
echo " |--preserve-unisrc | --rebuild-unisrc]"
echo " [--unified-dir <dir>]"
echo " [--auto-pull | --no-auto-pull]"
echo " [--auto-checkout | --no-auto-checkout]"
echo " [--jobs <count>] [--load <load>] [--single-thread]"
echo " [--gmp | --no-gmp]"
echo " [--mpfr | --no-mpfr]"
echo " [--mpc | --no-mpc]"
echo " [--isl | --no-isl]"
echo " [--cloog | --no-cloog]"
echo " [--ncurses | --no-ncurses]"
echo " [--expat | --no-expat]"
echo " [--target-cflags <flags>]"
echo " [--config-extra <flags>]"
echo " [--disable-werror | --enable-werror]"
echo " [--enable-cgen-maint]"
echo " [--help | -h]"
exit 0
;;
*)
;;
esac
[ "x${opt}" = "x" ]
do
shift
done
# Sort out Canadian cross stuff. First is it really a canadian cross
build_arch=`uname -m`
if [ "x" != "x${host}" ]
then
host_arch=`getarch ${host}`
if [ "x${host_arch}" = "x${build_arch}" ]
then
# Not really a Canadian Cross
host=
fi
else
host_arch=${build_arch}
fi
# Create build directory names if needed.
if [ "x${bd_build}" = "x" ]
then
bd_build=${basedir}/builds/bd-${build_arch}-${RELEASE}
fi
if [ "x${bd_host}" = "x" ]
then
bd_host=${basedir}/builds/bd-${host_arch}-${RELEASE}
fi
# Set up staging directory. This is where we install static libraries, include
# files etc. that is needed for building, but we don't want in the SDK.
staging_host=${bd_host}/staging
# Set up install dirs. Four cases each time according to whether and install
# dir and a datestamp have been set.
if [ "x${id_build}" = "x" ]
then
if [ "x${ds_build}" = "x" ]
then
# Default install directory without datestamp
id_build="/opt/adapteva/esdk.${RELEASE}/tools/e-gnu.${build_arch}"
else
# Default install directory with datestamp
id_build="/opt/adapteva/esdk.${RELEASE}-${ds_build}/tools/e-gnu.${build_arch}"
fi
else
if [ "x${ds_build}" = "x" ]
then
# Custom install directory without datestamp
# No nothing
true
else
# Custom install directory with datestamp
id_build="${id_build}-${ds_build}"
fi
fi
if [ "x${id_host}" = "x" ]
then
if [ "x${ds_host}" = "x" ]
then
# Default install directory without datestamp
id_host="/opt/adapteva/esdk.${RELEASE}/tools/e-gnu.${host_arch}"
else
# Default install directory with datestamp
id_host="/opt/adapteva/esdk.${RELEASE}-${ds_host}/tools/e-gnu.${host_arch}"
fi
else
if [ "x${ds_host}" = "x" ]
then
# Custom install directory without datestamp
# No nothing
true
else
# Custom install directory with datestamp
id_host="${id_host}-${ds_host}"
fi
fi
if [ "x${destdir}" = "x" ]
then
destdir_str=""
else
destdir_str="DESTDIR=\"${destdir}\""
fi
# Add ${disable_werror} to ${config_extra}. Note that this argument takes
# precedence, so don't try setting disable-werror in config_extra.
config_extra="${config_extra} ${disable_werror}"
# Default parallellism if none set.
mem=`sed < /proc/meminfo -n -e 's/MemTotal:[ \n\t] *\([0-9]*\).*$/\1/p'`
if [ "0${mem}" -le 2097152 ]
then
# No parallelism if memory is small.
make_load=1
else
make_load="`(echo processor; cat /proc/cpuinfo 2>/dev/null || echo processor) \
| grep -c processor`"
fi
if [ "x${jobs}" = "x" ]
then
jobs=${make_load}
fi
if [ "x${load}" = "x" ]
then
load=${make_load}
fi
parallel="-j ${jobs} -l ${load}"
logterm "START BUILD: $(date)"
logonly "Build directory (build arch): ${bd_build}"
logonly "Build directory (host arch): ${bd_host}"
logonly "Build architecture: ${build_arch}"
logonly "Host: ${host}"
logonly "Host architecture: ${host_arch}"
logonly "Install directory (build arch): ${id_build}"
logonly "Install directory (host arch): ${id_host}"
logonly "Staging directory (destdir): ${destdir}"
logonly "Symlink directory: ${symlink_dir}"
logonly "Datestamp (build arch): ${ds_build}"
logonly "Datestamp (host arch): ${ds_host}"
logonly "Clean (build arch): ${do_clean_build}"
logonly "Clean (host arch): ${do_clean_host}"
logonly "Automatic pull: ${auto_pull}"
logonly "Automatic checkout: ${auto_checkout}"
logonly "Rebuild unified source: ${rebuild_unisrc}"
logonly "Unified source directory: ${unisrc_dir}"
logonly "Maximum jobs: ${jobs}"
logonly "Maximum load: ${load}"
logonly "Use GMP source: ${do_gmp}"
logonly "Use MPFR source: ${do_mpfr}"
logonly "Use MPC source: ${do_mpc}"
logonly "Use ISL source: ${do_isl}"
logonly "Use Cloog source: ${do_cloog}"
logonly "Use ncurses source: ${do_ncurses}"
logonly "Use expat source: ${do_expat}"
logonly "Target CFLAGS: ${CFLAGS_FOR_TARGET}"
logonly "Target CXXFLAGS: ${CXXFLAGS_FOR_TARGET}"
logonly "CFLAGS: ${CFLAGS}"
logonly "CXXFLAGS: ${CXXFLAGS}"
logonly "Extra config flags: ${config_extra}"
################################################################################
# #
# Validate source and build unified source directory. #
# #
################################################################################
# Work from the base directory.
if ! cd ${basedir}
then
logterm "ERROR: Unable to change to base directory ${basedir}."
failedbuild
fi
# Sanity check if we are trying to build a Canadian cross
if [ "x" != "x${host}" ]
then
if ! which ${host}-gcc >> ${logfile} 2>&1
then
logterm "ERROR: No cross-compiler for ${host} found"
failedbuild
fi
host_str="--host=${host}"
else
host_str=""
fi
# Sanity check that we have everything we need. Take the opportunity to set up
# the component lists at the same time. Note that later items in the list
# override earlier items.
res="success"
# First the main components, which we *must* have.
check_dir_exists "gcc" || res="failure"
check_dir_exists "binutils" || res="failure"
check_dir_exists "gdb" || res="failure"
check_dir_exists "newlib" || res="failure"
check_dir_exists "cgen" || res="failure"
check_dir_exists "sdk" || res="failure"
component_dirs="newlib gdb binutils cgen gcc"
# Optional GCC infrastructure components
infra_dir=""
infra_exclude=""
if [ "${do_gmp}" = "--gmp" ]
then
check_dir_exists "gcc-infrastructure/gmp" || res="failure"
infra_dir="gcc-infrastructure"
else
infra_exclude="gmp ${infra_exclude}"
fi
if [ "${do_mpfr}" = "--mpfr" ]
then
check_dir_exists "gcc-infrastructure/mpfr" || res="failure"
infra_dir="gcc-infrastructure"
else
infra_exclude="mpfr ${infra_exclude}"
fi
if [ "${do_mpc}" = "--mpc" ]
then
check_dir_exists "gcc-infrastructure/mpc" || res="failure"
infra_dir="gcc-infrastructure"
else
infra_exclude="mpc ${infra_exclude}"
fi
if [ "${do_isl}" = "--isl" ]
then
check_dir_exists "gcc-infrastructure/isl" || res="failure"
infra_dir="gcc-infrastructure"
else
infra_exclude="isl ${infra_exclude}"
fi
if [ "${do_cloog}" = "--cloog" ]
then
check_dir_exists "gcc-infrastructure/cloog" || res="failure"
infra_dir="gcc-infrastructure"
else
infra_exclude="cloog ${infra_exclude}"
fi
if [ "${do_ncurses}" = "--ncurses" ]
then
check_dir_exists "gcc-infrastructure/ncurses" || res="failure"
infra_dir="gcc-infrastructure"
else
infra_exclude="ncurses ${infra_exclude}"
fi
if [ "${do_expat}" = "--expat" ]
then
check_dir_exists "gcc-infrastructure/expat" || res="failure"
infra_dir="gcc-infrastructure"
else
infra_exclude="expat ${infra_exclude}"
fi
if [ "${res}" != "success" ]
then
failedbuild
fi
component_dirs="${infra_dir} ${component_dirs}"
regex="toolchain"
# Checkout and pull repos if necessary
if ! ${basedir}/sdk/get-versions.sh ${basedir} sdk/components.conf \
${logfile} ${auto_pull} \
${auto_checkout} \
--regex ${regex}
then
logterm "ERROR: Could not get correct versions of tools"
failedbuild
fi
# We need to force a clean build if there was not a previous successful
# configure.
if [ "${do_clean_host}" = "--no-clean-host" ]
then
if [ -d ${bd_host} -a -e ${bd_host}/config.log ] \
&& grep "configure: exit 0" ${bd_host}/config.log > /dev/null 2>&1
then
# We did have a previous successful config we can reuse. This then
# overrides any specified install directory.
id_host=`sed -n -e 's/^.*\-\-prefix=\([^ \t\n]*\).*$/\1/p' \
< ${bd_host}/config.log | head -1`
logterm "Reusing previous build and installing at ${id_host}."
else
logterm "Forcing clean build"
do_clean_host="--clean-host"
fi
fi
# Clean up old build directories if specified.
if [ "${do_clean_build}" = "--clean-build" ]
then
rm -rf "${bd_build}"
fi
# Clean up old build directories if specified.
if [ "${do_clean_host}" = "--clean-host" ]
then
rm -rf "${bd_host}"
rm -rf "${staging_host}"
fi
# Blow away the unified source directory if requested
if [ "${rebuild_unisrc}" = "--rebuild-unisrc" ]
then
rm -rf "${unisrc_dir}" >> ${logfile} 2>&1
fi
# Create unified source directory if it doesn't exist
if ! [ -d "${unisrc_dir}" ]
then
# Create a unified source directory
if ! mkdir "${unisrc_dir}" >> ${logfile} 2>&1
then
logterm "ERROR: Could not create unified source dir ${unisrc_dir}."
failedbuild
fi
logterm "Creating unified source tree..."
if ! ${basedir}/sdk/symlink-all.sh "${basedir}" "${logfile}" \
"${infra_exclude}" "${unisrc_dir}" "${component_dirs}"
then
logterm "ERROR: Failed to build unified source tree in ${unisrc_dir}."
failedbuild
fi
# Apply patches. Symlink will be overwritten, not the underlying file.
for p in ${basedir}/sdk/patches/*; do
logterm "Applying patch: $p"
if ! patch -d ${unisrc_dir} --follow-symlinks -Np1 < $p
then
logterm "ERROR: Failed to apply patch \"${p}\"."
failedbuild
fi
done
fi
# Ensure the staging directory exists.
if ! mkdir -p "$staging_host"
then
logterm "ERROR: Failed to create staging directory ${staging_host}."
failedbuild
fi
################################################################################
# #
# Make sure we have an epiphany tool chain on the build machine if needed #
# #
################################################################################
# Put the build directory toolchain on our PATH. Then we will find it
# if we have already built it.
PATH=${id_build}/bin:$PATH
export PATH
if [ "x${host}" != "x" ]
then
if which epiphany-elf-gcc && which epiphany-elf-as \
&& which epiphany-elf-ld && which epiphany-elf-ar
then
logterm "Epiphany tools found on build machine"
else
# A cross compiler also needs a compiler on the build machine to build
# libraries.
# Ensure the build directory exists. We don't do fancy stuff about
# trying to preserve previous builds. If we get here, by definition
# they were no good.
rm -rf "${bd_build}"
if ! mkdir -p "${bd_build}"
then
logterm "ERROR: Failed to create build directory ${bd_build}."
failedbuild
fi
# Change to the build directory
if ! cd ${bd_build}
then
logterm "ERROR: Could not change to build directory ${bd_build}."
failedbuild
fi
# Force guile 1.8 in build if available.
guile18=`which guile1.8 2>/dev/null`
[ "x$guile18" = x ] && guile18=`which guile-1.8 2>/dev/null`
if ! [ "x${guile18}" = "x" ]
then
mkdir -p guile/libguile
ln -sf ${guile18} guile/libguile/guile
fi
unset guile18
# Configure the required components of the tool chain. We only need
# binutils, as, ld and gcc. We need to temporarily move
# CFLAGS_FOR_TARGET out of the way.
# Append -fPIC to CFLAGS. Needed for building simulator shared library.
logterm "Configuring build machine tool chain..."
OLD_CFLAGS_FOR_TARGET=${CFLAGS_FOR_TARGET}
CFLAGS_FOR_TARGET=
OLD_CXXFLAGS_FOR_TARGET=${CXXFLAGS_FOR_TARGET}
CXXFLAGS_FOR_TARGET=
if ! "${unisrc_dir}/configure" \
CFLAGS="${CFLAGS} -fPIC" \
CXXFLAGS="${CXXFLAGS} -fPIC" \
--target=epiphany-elf \
--with-pkgversion="Epiphany toolchain ${RELEASE}" \
--with-bugurl=support-sdk@adapteva.com \
--enable-fast-install=N/A \
--enable-languages=c,c++ --prefix="${id_build}" \
--with-newlib --disable-gdbtk ${config_extra} >> "${logfile}" 2>&1
then
logterm "ERROR: Tool chain configuration for build machine failed."
failedbuild
fi
# Build the parts of the tool chain we need: binutils and GCC
logterm "Building build machine tool chain..."
if ! make ${parallel} all-build all-binutils all-gas all-ld all-gcc \
all-target-libgcc all-target-libgloss all-target-newlib \
all-target-libstdc++-v3 >> "${logfile}" 2>&1
then
logterm "ERROR: Tool chain build for build machine failed."
failedbuild
fi
# Install binutils, GCC, newlib and GDB
logterm "Installing build machine tool chain..."
if ! make install-binutils install-gas install-ld install-gcc \
install-target-libgcc install-target-libgloss install-target-newlib \
install-target-libstdc++-v3 >> "${logfile}" 2>&1
then
logterm "Error: Tool chain installation for build machine failed."
failedbuild
fi
# Sanity check that we now do really have the tools we need.
if ! ( which epiphany-elf-gcc && which epiphany-elf-as \
&& which epiphany-elf-ld && which epiphany-elf-ar )
then
logterm "Error: Failed to created tools for build machine."
failedbuild
fi
CFLAGS_FOR_TARGET=${OLD_CFLAGS_FOR_TARGET}