-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
executable file
·1457 lines (1251 loc) · 45 KB
/
build.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/bash -e
###############################################################################
#
# Development installation script for Patmos compiler+tools
#
# The builds performed by this script are out-of-source builds.
#
# Benedikt Huber <benedikt@vmars.tuwien.ac.at>
# Daniel Prokesch <daniel@vmars.tuwien.ac.at>
# Stefan Hepp <hepp@complang.tuwien.ac.at>
#
# Usage of paths and functions in this script:
#
# - build_* functions are top-level build scripts. Must handle cleaning,
# configuring, building, installing and testing.
#
# - make_* functions are used by the generic build_cmake or build_autoconf
# build functions to make, install and run tests. Make functions are executed
# in the build directory.
#
# Paths generated by get_repo_dir, get_build_dir, and paths passed to build_*
# functions are always relative to ROOT_DIR. ROOT_DIR itself may be relative
# to some dir (i.e., this directory), use $(abspath ) to make it absolute.
#
#
# TODO find out whether all variables are quoted where necessary
# NB: CMake does not want it's program path quoted.
#
###############################################################################
#
# Note: This function is only safe to use when the path exists.
# When using for build paths, make sure it has been created first.
#
function abspath() {
local path=$1
local pwd_restore="$(pwd)"
# readlink -f does not work on OSX, so we do this manually
local dir=$(dirname "$path")
if [ -d "$dir" ]; then
cd "$dir" > /dev/null
path=$(basename "$path")
# follow chain of symlinks
while [ -L "$path" ]; do
path=$(readlink "$path")
cd $(dirname "$path") > /dev/null
path=$(basename "$path")
done
echo "$(pwd -P)/$path"
cd "$pwd_restore" > /dev/null
elif [[ "$BUILDDIR_SUFFIX" =~ ^/ ]]; then
echo $path
else
echo "Trying to resolve non-existent relative path $path, don't want to use PWD."
exit 1
fi
}
OS_NAME=$(uname -s)
ARCH_NAME=$(uname -m)
# avoid changing into CDPATH directories
unset CDPATH
# Prevent custom GREP options from breaking the build
unset GREP_OPTIONS
# physical location of this script, and the config
self=$(abspath $0)
CFGFILE=$(dirname $self)/build.cfg
# location of the patmos-chrpath script
CHRPATH=$(dirname $self)/patmos-chrpath
# location of the custom install script
INSTALL_SH=$(dirname $self)/scripts/install.sh
# List of available targets
ALLTARGETS="simulator gold llvm1 newlib compiler-rt argo soc-comm poseidon patmos bench otawa"
########### Start of user configs, overwrite in build.cfg ##############
# List of targets to build by default when running toolchain1 (using the new version of the compiler 'llvm2'),
# developers may set this to $ALLTARGETS or a subset of interesting tools
TOOLCHAIN1_TARGETS="simulator gold llvm1 platin newlib compiler-rt argo soc-comm poseidon patmos"
# List of targets to build for toolchain2 (using the new version of the compiler 'llvm2')
# Should be kept up to date with 'TOOLCHAIN1_TARGETS'
TOOLCHAIN2_TARGETS="simulator llvm2 platin argo soc-comm poseidon patmos"
# Root directory for all repositories
ROOT_DIR=$(pwd)
# Set to 'short' for llvm/clang/... directory names, 'long' for
# patmos-llvm/patmos-clang/.. or 'prefix' to use $(REPO_PREFIX)llvm/..
REPO_NAMES=short
REPO_PREFIX=
# Installation directory prefix
INSTALL_DIR="$ROOT_DIR/local"
# Directory suffix for directory containing generated files
BUILDDIR_SUFFIX="/build"
# Whether to download pre-built binaries where available.
PREFER_DOWNLAOD=false
# RTEMS subdirectory prefix. Set to empty to checkout without subdirectories.
RTEMS_SUBDIR_PREFIX="rtems-4.10.2"
# Targets to support with patmos-clang
#LLVM_TARGETS=all
#LLVM_TARGETS="ARM;Mips;Patmos;X86"
LLVM_TARGETS=Patmos
ECLIPSE_LLVM_TARGETS=Patmos
# build LLVM using configure instead of cmake
LLVM_USE_CONFIGURE=false
# Set the build type for LLVM (currently only for cmake builds)
LLVM_BUILD_TYPE=Release
# build LLVM using shared libraries instead of static libs
LLVM_BUILD_SHARED=true
# skip checking out clang
LLVM_OMIT_CLANG=false
# Set to the name of the clang binary to use for compiling LLVM itself.
# Leave empty to use cmake defaults, set to "clang" to use clang
CLANG_COMPILER=
# Build gold binutils and LLVM LTO plugin
BUILD_LTO=true
# Build newlib, compiler-rt and benchmarks with softfloats
BUILD_SOFTFLOAT=true
# Build the Patmos Chisel emulator
BUILD_EMULATOR=true
# Create symlinks instead of copying files where applicable
# (llvm, clang, gold)
INSTALL_SYMLINKS=false
# Update rpath of binaries during installation:
# - 'remove' Remove rpath
# - 'build' Set install rpath at build time
# - 'true' Update rpath to the install dir on installation
# - 'false' Do not change rpath on installation
INSTALL_RPATH=true
# Base URL for checking out new repositories. 'auto' tries to use
# the same base-url as the patmos-misc repository. Defaults to
# 'https://github.com/t-crest'
GITHUB_BASEURL="auto"
# URL for the repository containing the benchmarks
BENCH_REPO_URL="https://github.com/t-crest/patmos-benchmarks.git"
# URL for repository containing additional non-free benchmarks
BENCH_NONFREE_REPO_URL=
# Optional path to use for the gcc.c_torture/execute checkout.
# Set this to somewhere outside the build directory to avoid checking the
# sources out on clean benchmark builds.
#BENCH_GCC_C_TORTURE_PATH=
# Set the target architecture for gold
# auto use HOST on Linux, 'patmos-unknown-unknown-elf' otherwise
# none do not set --target
# <target> use <target> as target architecture
GOLD_TARGET_ARCH=auto
# Target triple for Patmos libraries and benchmarks:
# patmos-unknown-unknown-elf Default
# patmos-unknown-rtems Used with RTEMS
TARGET="patmos-unknown-unknown-elf"
# Additional arguments for cmake / configure
LLVM_CMAKE_ARGS=
# e.g., use ninja for building instead of make
#LLVM_CMAKE_ARGS="-G Ninja"
LLVM_CONFIGURE_ARGS=
GOLD_ARGS=
NEWLIB_ARGS=
# Additional RTEMS configure options
RTEMS_ARGS=
# Select BSP for RTEMS build
RTEMS_BSP=pasim
# Whether to use simulator (pasim) of FPGA (patex) for RTEMS tests
RTEMS_SIM=pasim
# Build simulator in Debug mode (default: RelWithDebInfo)
#PASIM_ARGS="-DCMAKE_BUILD_TYPE=Debug"
# Use a custom installation of Boost libraries
#PASIM_ARGS="-DBOOST_ROOT=$HOME/local/ -DBoost_NO_BOOST_CMAKE=TRUE"
# Patmos C-tools cmake options
CTOOLS_ARGS=
## Options for the patmos-bench test environment
# PML architecture files configure clang/llvm, pasim, and platin:
# PML_CONFIG and PML_CONFIG_LARGERAM (for benchmarks requiring >2Mb RAM)
#BENCH_ARGS="-DCONFIG_PML=scripts/patmos-config.pml"
# Add extra options for pasim when executing tests
#BENCH_ARGS="${BENCH_ARGS} -DPASIM_EXTRA_OPTIONS='--maxc 1000'"
# Disable gcc torture tests
#BENCH_ARGS="${BENCH_ARGS} -DENABLE_CTORTURE=false"
# Set path to a3, or set to empty string to disable a3
#BENCH_ARGS="${BENCH_ARGS} -DA3_EXECUTABLE="
# Additional CFLAGS, LDFLAGS
GOLD_CFLAGS=
# Use this flag if gcc throws errors about narrowing conversions
#GOLD_CXXFLAGS="-Wno-narrowing"
GOLD_CXXFLAGS=
# Disable inline-assembly implementations in compiler-rt
COMPILER_RT_CFLAGS="-DCRT_NO_INLINE_ASM"
BENCH_LDFLAGS=
# CFLAGS for host compiler
NEWLIB_CFLAGS=
# CFLAGS for target compiler (patmos-clang)
NEWLIB_TARGET_CFLAGS=
# Use the following FLAGS to link runtime libraries as binaries
#NEWLIB_TARGET_CFLAGS="-fpatmos-emit-obj"
#COMPILER_RT_CFLAGS="-fpatmos-emit-obj"
#BENCH_LDFLAGS="-fpatmos-lto-defaultlibs"
# If 'y' the 'patmos' target will automatically switch to the llvm1 branch as part of the build
AUTO_PATMOS_LLVM1=n
# Commandline option to pass to make/ctest for parallel builds
MAKEJ=-j2
# Arguments to pass to ctest
# Use "-jN" to enable parallel benchmark testing
if [ "$OS_NAME" == "Darwin" ]; then
CORE_COUNT=$(sysctl -n hw.ncpu)
else
CORE_COUNT=$(grep -c ^processor /proc/cpuinfo)
fi
CTEST_ARGS=-j$CORE_COUNT
# Set nice level for the whole build.sh run. No renice happens if undefined.
#NICENESS=10
#################### End of user configs #####################
# Internal options, set by command line
MAKE_VERBOSE=
DO_CLEAN=false
DO_RECONFIGURE=false
DO_UPDATE=false
DO_SHOW_CONFIGURE=false
DO_RUN_TESTS=false
DRYRUN=false
VERBOSE=false
DO_RUN_ALL=false
# user config
if [ -f $CFGFILE ]; then
source $CFGFILE
fi
# renice if niceness has been set
if [ -n "$NICENESS" ]; then
renice -n $NICENESS $$
fi
##################### Helper Functions ######################
function info() {
echo -e "\033[32m ===== $1 ===== \033[0m" >&2
}
run() {
if [ "$VERBOSE" == "true" ]; then
echo "$@"
fi
if [ "$DRYRUN" != "true" ]; then
eval $@
ret=$?
if [ $ret != 0 ]; then
echo "$@ failed ($ret)!"
return $ret
fi
fi
}
function install() {
# if $src is a directory, $dst must be the target directory, not the parent directory!
local src=$1
local dst=$2
if [ -f $src -a -d $dst ]; then
dst=$dst/$(basename $src)
fi
run mkdir -p $(dirname $dst)
if [ "$INSTALL_SYMLINKS" == "true" ]; then
echo "Symlinking $src -> $dst"
if [ -d $src ]; then
run rm -rf $dst
fi
run ln -sf $src $dst
else
echo "Installing $src -> $dst"
if [ -L $dst ]; then
rm -f $dst
fi
# TODO option to use hardlinking instead
# Maybe, if $src is a directory, make sure we remove any trash in $dst (use rsync??) .. should be optional, off by default!
if [ "$OS_NAME" == "Linux" ]; then
run cp -fauT $src $dst
else
if [ -e $dst ]; then
run rm -rf $dst
fi
run cp -fR $src $dst
fi
fi
}
function update_rpath() {
local repo=$1
if [ "$INSTALL_RPATH" == "true" ]; then
if [ -x $CHRPATH ]; then
echo "Setting rpath of binaries to install dir .. "
run $CHRPATH -w -p $repo -i $INSTALL_DIR
else
echo "** Warning: patmos-chrpath script not found, skipping setting rpath."
fi
fi
if [ "$INSTALL_RPATH" == "remove" ]; then
if [ -x $CHRPATH ]; then
echo "Removing rpath from installed binaries .. "
run $CHRPATH -w -d -p $repo -i $INSTALL_DIR
else
echo "** Warning: patmos-chrpath script not found, skipping removing rpath."
fi
fi
}
#
# Get the source directory name for a repository, relative to the rootdir.
#
# This function expects the same arguments as get_build_dir, just that subdirectories
# are separeted by '/' instead of being passed as separate directory.
#
function get_repo_dir() {
# name of the repository (not a directory name)
local repo=$1
# TODO if subdir is set to empty, we could instead make a flat hierarchy,
# i.e., check out patmos-rtems, patmos-rtems-examples, patmos-rtems-compiler-rt, ..
# Needs to be consistent with get_build_dir.
if [ ! -z "$RTEMS_SUBDIR_PREFIX" ]; then
case $repo in
rtems/rtems)
repo=rtems/${RTEMS_SUBDIR_PREFIX}
;;
rtems/examples)
repo=rtems/${RTEMS_SUBDIR_PREFIX}-examples
;;
*) ;;
esac
fi
case $REPO_NAMES in
short)
echo $repo
;;
long)
case $repo in
patmos) echo "patmos" ;;
patmos/*) echo $repo ;;
bench) echo "patmos-benchmarks" ;;
*) echo "patmos-"$repo ;;
esac
;;
prefix)
echo $REPO_PREFIX$repo
;;
*)
# TODO uhm.. make sure that this never happens by checking earlier
echo $repo
;;
esac
}
#
# Get the build directory name for a repository or a subdirectory of a repository.
#
# The build directory is relative to the root directory.
#
function get_build_dir() {
# name of the repository (not a path), excluding subdirs
local repo=$1
# subdirectory inside the repository, can be omitted
local subdir=$2
local repodir=$(get_repo_dir $1)
if [ "$repo" == "patmos" ]; then
if [[ "$BUILDDIR_SUFFIX" =~ ^/ ]]; then
builddir=$repodir/$subdir$BUILDDIR_SUFFIX
else
builddir=$repodir$BUILDDIR_SUFFIX/$subdir
fi
elif [ "$repo" == "rtems" ]; then
# For RTEMS, we always subdir the build directory, not the other way round
builddir=$repodir$BUILDDIR_SUFFIX/$subdir
else
builddir=$repodir$BUILDDIR_SUFFIX
fi
echo $builddir
}
function clone_update() {
local srcurl=$1
local target=$ROOT_DIR/$2
local branch=$3
if [ "$branch" == "" ]; then
branch="master"
fi
if [ "$DO_SHOW_CONFIGURE" == "true" ]; then
return
fi
if [ ! -d "$target" ] ; then
info "Cloning from $srcurl"
run git clone "$srcurl" "$target" --branch "$branch"
elif [ ${DO_UPDATE} != false ] ; then
#TODO find a better way (e.g. stash away only on demand)
info "Updating $1"
run pushd "$target" ">/dev/null"
if [ "$DRYRUN" == "true" ]; then
echo git stash
else
ret=$(git stash)
# TODO is there a better way of doing this?
local skip_stash=false
if [ "$ret" == "No local changes to save" ]; then
skip_stash=true
fi
fi
run git pull --rebase
if [ "$DRYRUN" == "true" ]; then
echo git stash pop
else
if [ "$skip_stash" != "true" ]; then
git stash pop
fi
fi
run popd ">/dev/null"
fi
}
#
# Get all build flags for a given repository from the configuration.
#
function get_build_flags() {
# name of the repository, may include subdirs (subdirs will be added to the config-variable name).
local repo=$1
local cflagsname=$(echo "${repo}_CFLAGS" | tr '[a-z-/]' '[A-Z__]')
local cppflagsname=$(echo "${repo}_CPPFLAGS" | tr '[a-z-/]' '[A-Z__]')
local cxxflagsname=$(echo "${repo}_CXXFLAGS" | tr '[a-z-/]' '[A-Z__]')
local ldflagsname=$(echo "${repo}_LDFLAGS" | tr '[a-z-/]' '[A-Z__]')
local envvarsname=$(echo "${repo}_ENVVARS" | tr '[a-z-/]' '[A-Z__]')
if [ ! -z "${!cflagsname}$CFLAGS" ]; then
echo -n "CFLAGS='${!cflagsname} $CFLAGS'"
fi
if [ ! -z "${!cppflagsname}$CPPFLAGS" ]; then
echo -n " CPPFLAGS='${!cppflagsname} $CPPFLAGS'"
fi
if [ ! -z "${!cxxflagsname}$CXXFLAGS" ]; then
echo -n " CXXFLAGS='${!cxxflagsname} $CXXFLAGS'"
fi
if [ ! -z "${!ldflagsname}$LDFLAGS" ]; then
echo -n " LDFLAGS='${!ldflagsname} $LDFLAGS'"
fi
if [ ! -z "${!envvarsname}" ]; then
echo -n " ${!envvarsname}"
fi
}
function build_cmake() {
# name of the repository
local repo=$1
# path of the repository (might be relative)
local root=$ROOT_DIR/$(get_repo_dir $repo)
# function to use for building
local make_function=$2
# path to the build directory (might be relative)
local builddir=$ROOT_DIR/$3
# absolute path to sources
local rootdir=$(abspath $root)
shift 3
# TODO pass get_build_flags result to cmake
local flags=$(get_build_flags $repo)
if [ "$DO_SHOW_CONFIGURE" == "true" ]; then
echo cd $builddir
echo "$flags" cmake $@ -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} $rootdir
return
fi
if [ -e $builddir -a ! -e $builddir/Makefile -a ! -e $builddir/build.ninja ]; then
echo "Recreating builddir after unfinished configure"
run rm -rf $builddir
fi
if [ $DO_CLEAN == true -o ! -e "$builddir" ] ; then
run rm -rf $builddir
run mkdir -p $builddir
run pushd $builddir ">/dev/null"
run "$flags" cmake $@ -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} $rootdir
elif [ $DO_RECONFIGURE == true ] ; then
run pushd $builddir ">/dev/null"
run rm -f CMakeCache.txt
run "$flags" cmake --no-warn-unused-cli $@ -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} $rootdir
else
run pushd $builddir ">/dev/null"
fi
$make_function $rootdir $(abspath $builddir)
run popd ">/dev/null"
}
function build_autoconf() {
# name of the repository
local repo=$1
# path of the repository (might be relative)
local root=$ROOT_DIR/$(get_repo_dir $repo)
# function to use for building
local make_function=$2
# path to the build directory (might be relative)
local builddir=$ROOT_DIR/$3
# absolute path to sources
local rootdir=$(abspath $root)
# configure script to use (absolute path)
local configscript=$rootdir/configure
shift 3
# Read out GOLD_CPPFLAGS, NEWLIB_CPPFLAGS, ..
local flags=$(get_build_flags $repo)
if [ "$DO_SHOW_CONFIGURE" == "true" ]; then
echo cd $builddir
echo "$flags" $configscript "$@" --prefix=${INSTALL_DIR}
return
fi
if [ -e $builddir -a ! -e $builddir/Makefile ]; then
echo "Recreating builddir after unfinished configure"
run rm -rf $builddir
fi
if [ $DO_CLEAN == true -o ! -e "$builddir" ] ; then
run rm -rf $builddir
run mkdir -p $builddir
run pushd $builddir ">/dev/null"
run "$flags" $configscript "$@" --prefix=${INSTALL_DIR}
elif [ $DO_RECONFIGURE == true ] ; then
run pushd $builddir ">/dev/null"
run "$flags" $configscript "$@" --prefix=${INSTALL_DIR}
else
run pushd $builddir ">/dev/null"
fi
$make_function $rootdir $(abspath $builddir)
run popd ">/dev/null"
}
function usage() {
cat <<EOT
Usage: $0 [-c] [-j<n>] [-p] [-i <install_dir>] [-h] [-a|-o|<targets>]
-a Build all targets
-c Cleanup builds and rerun configure
-r Rerun configure (resetting CMake cache where applicable)
-j <n> Pass -j<n> to make
-i <dir> Set the install dir
-h Show this help
-p Create builddirs outside the source dirs
-u Update repositories
-d Dryrun, just show what would be executed
-s Show configure commands for all given targets
-v Show command that are executed
-V Make make verbosive
-t Run tests
-o Build toolchain (simulator, gold, llvm, patmos, newlib, compiler-rt) and do clean build of bench with tests.
-q Download and install from pre-built binaries where available, instead of building from source. Disables testing of downloaded targets (with -t)
Available targets:
simulator gold llvm newlib compiler-rt patmos otawa bench rtems rtems-test rtems-examples eclipse poseidon soc-comm
The command-line options override the user-config read from '$CFGFILE'.
EOT
}
function make_simulator() {
# absolute source dir
local rootdir=$1
# absolute build dir
local builddir=$2
# Build binaries
make $MAKEJ $MAKE_VERBOSE
# Package binaries
make Package
if $DO_RUN_TESTS; then
make test
fi
# Install
echo "Installing files ..."
mkdir -p $INSTALL_DIR
cp $builddir/patmos-simulator*.tar.gz $INSTALL_DIR/
tar -xvf $INSTALL_DIR/patmos-simulator*.tar.gz --directory=$INSTALL_DIR
rm -rf $INSTALL_DIR/patmos-simulator*.tar.gz
}
function make_llvm-project() {
# First, Ensure that GNU tar is installed as 'tar'
# This is usually not the case on MacOS (usually uses bsdtar)
TAR_VERSION=$(tar --version)
if [[ $TAR_VERSION != "tar (GNU tar)"* ]]; then
echo "Error: Must have GNU Tar installed as 'tar'."
echo "Error: Your installed 'tar':"
echo "Error: $TAR_VERSION"
echo "Error: Hint: if you are using macos, bsdtar is the default 'tar' installed. You can use brew to get GNU tar instead"
exit 1
fi
mkdir -p $1
cd $1
# Build binaries
cmake ../llvm \
-DCMAKE_CXX_STANDARD=14 \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_TARGETS_TO_BUILD="Patmos" \
-DLLVM_DEFAULT_TARGET_TRIPLE=patmos-unknown-unknown-elf \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DCLANG_ENABLE_ARCMT=false \
-DCLANG_ENABLE_STATIC_ANALYZER=false \
-DCLANG_BUILD_EXAMPLES=false \
-DLLVM_ENABLE_BINDINGS=false \
-DLLVM_INSTALL_BINUTILS_SYMLINKS=false \
-DLLVM_INSTALL_CCTOOLS_SYMLINKS=false \
-DLLVM_INCLUDE_EXAMPLES=false \
-DLLVM_INCLUDE_BENCHMARKS=false \
-DLLVM_APPEND_VC_REV=false \
-DLLVM_ENABLE_WARNINGS=false \
-DLLVM_ENABLE_PEDANTIC=false \
-DLLVM_ENABLE_LIBPFM=false \
-DLLVM_BUILD_INSTRUMENTED_COVERAGE=false \
-DLLVM_INSTALL_UTILS=false \
-DLLVM_ENABLE_ASSERTIONS=true
# Compiler currently doesn't work without assertions enabled
make $MAKEJ $MAKE_VERBOSE
# Build Compiler-RT
cd ..
mkdir -p build-compiler-rt
cd build-compiler-rt
cmake ../compiler-rt/ -DCMAKE_TOOLCHAIN_FILE=../compiler-rt/cmake/patmos-clang-toolchain.cmake -DCMAKE_PROGRAM_PATH="$(pwd)/../build/bin" -DCOMPILER_RT_INCLUDE_TESTS=OFF
make $MAKEJ $MAKE_VERBOSE
cd ..
# Build Newlib
cd patmos-newlib
cd ..
mkdir -p build-newlib
cd build-newlib
../patmos-newlib/configure --target=patmos-unknown-unknown-elf AR_FOR_TARGET=ar CC_FOR_TARGET="$(pwd)/../build/bin/clang" CFLAGS_FOR_TARGET="-target patmos-unknown-unknown-elf -O2 -emit-llvm -D__GLIBC_USE\(...\)=0" RANLIB_FOR_TARGET=ranlib LD_FOR_TARGET="$(pwd)/../build/bin/clang"
make $MAKEJ $MAKE_VERBOSE
cd ../build
if $DO_RUN_TESTS; then
make $MAKEJ llc && ./bin/llvm-lit ../llvm/test -v --filter=Patmos
make $MAKEJ ClangPatmosTestDeps && ./bin/llvm-lit ../clang/test -v --filter=Patmos
cd ../build-compiler-rt
./bin/llvm-lit -v test/builtins/Unit/patmos
cd ../build
fi
# Package Everything
make PatmosPackage
# Install
echo "Installing files ..."
mkdir -p $INSTALL_DIR
cp patmos-unknown-unknown-elf/package-temp/patmos-llvm*.tar.gz $INSTALL_DIR/patmos-llvm.tar.gz
tar -xvf $INSTALL_DIR/patmos-llvm.tar.gz --directory=$INSTALL_DIR
rm -rf $INSTALL_DIR/patmos-llvm.tar.gz
}
function make_gold() {
# absolute source dir
local rootdir=$1
# absolute build dir
local builddir=$2
if [ "$BUILD_LTO" == "true" ]; then
run make $MAKEJ $MAKE_VERBOSE all-gold all-binutils
local install_target="install-gold install-binutils"
else
run make $MAKEJ $MAKE_VERBOSE all-gold
local install_target=install-gold
fi
if [ "$INSTALL_SYMLINKS" == "true" ]; then
run mkdir -p $INSTALL_DIR/bin
run ln -sf $builddir/gold/ld-new $INSTALL_DIR/bin/patmos-ld
if [ "$BUILD_LTO" == "true" ]; then
run ln -sf $builddir/binutils/ar $INSTALL_DIR/bin/patmos-ar
run ln -sf $builddir/binutils/nm-new $INSTALL_DIR/bin/patmos-nm
run ln -sf $builddir/binutils/ranlib $INSTALL_DIR/bin/patmos-ranlib
run ln -sf $builddir/binutils/strip-new $INSTALL_DIR/bin/patmos-strip
# bin is required, otherwise auto-loading of plugins does not work!
run mkdir -p $builddir/bin
run mkdir -p $builddir/lib/bfd-plugins
run ln -sf $INSTALL_DIR/lib/LLVMgold.$LIBEXT $builddir/lib/bfd-plugins/
run ln -sf $INSTALL_DIR/lib/libLTO.$LIBEXT $builddir/lib/bfd-plugins/
fi
else
run make $MAKE_VERBOSE $install_target
fi
}
function install_platin() {
# absolute source dir
local rootdir=$1
# absolute build dir
local builddir=$2
echo "Installing platin toolkit .. "
chmod u+x $rootdir/install.sh
run $rootdir/install.sh -i $INSTALL_DIR -b $builddir
}
function install_prebuilt() {
local tool_name=$1
local tool_link=$2
local tar_name="$1.tar.gz"
local tar_link="${tool_link}/releases/latest/download/${tool_name}-"
if [ "$OS_NAME" == "Darwin" ]; then
echo "Detected MacOS"
#if [ "$ARCH_NAME" == "arm64" ]; then
# echo "Detected ARM"
# local tar_link="${tar_link}arm64-apple-darwin"
#else
# echo "Detected x86_64"
local tar_link="${tar_link}x86_64-apple-darwin"
#fi
else
echo "Detected Ubuntu"
local tar_link="${tar_link}x86_64-linux-gnu"
fi
local tar_link="${tar_link}.tar.gz"
echo "Downloading prebuild from: $tar_link"
local tar_path=$INSTALL_DIR/$tar_name
# Download tar
curl -L $tar_link -o $tar_path
echo "Installed files:"
# Extract tar
tar -xvf $tar_path --directory=$INSTALL_DIR
}
function install_simulator() {
echo "Installing Patmos Simulator from Pre-Built Binaries"
install_prebuilt "patmos-simulator" "https://github.com/t-crest/patmos-simulator"
}
function make_llvm1() {
# absolute source dir
local rootdir=$1
# absolute build dir
local builddir=$2
if [ -e build.ninja ] ; then
run ninja $MAKEJ
else
run make $MAKEJ $MAKE_VERBOSE all
fi
echo "Installing files .. "
if [ "$LLVM_USE_CONFIGURE" == "true" ]; then
builddir=$builddir/Debug+Asserts
fi
run mkdir -p $INSTALL_DIR/bin
run mkdir -p $INSTALL_DIR/lib
for file in `find $builddir/bin -type f`; do
filename=`basename $file`
# Not sure how to add a program prefix for cmake install.. so just copy what we need
install $file $INSTALL_DIR/bin/patmos-$filename
done
# symlinks have to be recreated anyway
for file in `find $builddir/bin -type l`; do
filename=`basename $file`
src=$(readlink $file)
run ln -sf patmos-$(basename $src) $INSTALL_DIR/bin/patmos-$filename
done
# install all shared libraries
for file in `find $builddir/lib -name "*.$LIBEXT"`; do
install $file $INSTALL_DIR/lib/
done
# Install system headers
install $builddir/lib/clang $INSTALL_DIR/lib/clang
if [ "$BUILD_LTO" == "true" ]; then
# bin is required, otherwise auto-loading of plugins does not work!
run mkdir -p $INSTALL_DIR/bin
run mkdir -p $INSTALL_DIR/lib/bfd-plugins
run ln -sf ../LLVMgold.$LIBEXT $INSTALL_DIR/lib/bfd-plugins/
run ln -sf ../libLTO.$LIBEXT $INSTALL_DIR/lib/bfd-plugins/
fi
# Update rpaths, since we are not using cmake install
update_rpath llvm
if [ "$DO_RUN_TESTS" == "true" ]; then
echo "Running tests.."
if [ -e build.ninja ] ; then
run ninja check-all
else
run make check-all
fi
fi
}
function install_llvm2() {
echo "Installing Patmos LLVM from Pre-Built Binaries"
install_prebuilt "patmos-llvm" "https://github.com/t-crest/patmos-llvm-project"
}
function make_bench() {
# TODO if we do not have BUILD_SOFTFLOAT=true, then do not build softfloat benchmarks!
run make $MAKEJ $MAKE_VERBOSE all
if [ "$DO_RUN_TESTS" == "true" ]; then
run make test "ARGS='${CTEST_ARGS}'"
fi
}
function make_default() {
run make $MAKEJ $MAKE_VERBOSE all
run make $MAKE_VERBOSE install
}
function make_and_test_default() {
run make $MAKEJ $MAKE_VERBOSE all
run make $MAKE_VERBOSE install
if [ "$DO_RUN_TESTS" == "true" ]; then
run make test "ARGS='${CTEST_ARGS}'"
fi
}
function build_simulator() {
build_cmake simulator make_simulator $(get_build_dir simulator)
}
function build_llvm-project() {
make_llvm-project $(get_build_dir llvm-project)
}
function build_compiler_rt() {
# build dir (relative to root)
local builddir=$1
# target triple to build for
local target=$2
# source repository dir (relative path, always to same compiler-rt checkout, independent of build-dir)
local repo=$(get_repo_dir compiler-rt)
clone_update ${GITHUB_BASEURL}/patmos-compiler-rt.git $repo
build_cmake compiler-rt make_default $builddir \
"-DTRIPLE=${target} -DCMAKE_TOOLCHAIN_FILE=$ROOT_DIR/$repo/cmake/patmos-clang-toolchain.cmake -DCMAKE_PROGRAM_PATH=${INSTALL_DIR}/bin"
}
function build_newlib() {
# build dir (relative to root)
local builddir=$1
# target triple to build for
local target=$2
# source repository dir (relative path, always to same newlib ckeckout, independent of build-dir)
local repo=$(get_repo_dir newlib)
clone_update ${GITHUB_BASEURL}/patmos-newlib.git $repo llvm1
echo "WARNING: Explicitly building newlib will assume the use of the llvm1 compiler (old compiler)."
echo "WARNING: If you do not want to explicitly use the old compiler, do not build newlib manually."
echo "WARNING: The newlib repository will automatically be switched to the old compiler commit (tagged as llvm1)."
# Use a different install script for newlib that does not change the modification time if
# the files did not change.
NEWLIB_ENVVARS="INSTALL='$INSTALL_SH' $NEWLIB_ENVVARS"
build_autoconf newlib make_default $builddir --target=$target AR_FOR_TARGET=${INSTALL_DIR}/bin/$NEWLIB_AR \
RANLIB_FOR_TARGET=${INSTALL_DIR}/bin/$NEWLIB_RANLIB LD_FOR_TARGET=${INSTALL_DIR}/bin/patmos-clang \
READELF_FOR_TARGET=${INSTALL_DIR}/bin/patmos-readelf \
CC_FOR_TARGET=${INSTALL_DIR}/bin/patmos-clang "CFLAGS_FOR_TARGET='-target ${target} -O2 ${NEWLIB_TARGET_CFLAGS}'" "$NEWLIB_ARGS"
}
function build_otawa() {
# build dir (relative to root)
local builddir=$1
# source repository dir (relative path, always do same otawa ckeckout, independent of build-dir)
local repo=$(get_repo_dir otawa)
clone_update ${GITHUB_BASEURL}/otawa.git $repo
# options that need to be passed to otawa build script
local buildopt="-i ${INSTALL_DIR}"
if [ $DO_RECONFIGURE == true ] ; then
buildopt+=" -r";
fi
if [ "$DRYRUN" == "true" ] ; then
buildopt+=" -d";
fi
if [ "$VERBOSE" == "true" ] ; then
buildopt+=" -v";
fi
if [ "$DO_CLEAN" == "true" ] ; then
buildopt+=" -c";
fi
# set repository up and build
run pushd "${repo}" > /dev/null
run git submodule update --init
# do not use run here, since the otawa build script offers similar functions
run misc/build.sh $MAKEJ ${buildopt}
run popd > /dev/null
}
function build_javatools() {
# build directory (might be relative)
local builddir=$ROOT_DIR/$1
# source directory of the main makefile (relative to ROOT_DIR)
local root=$(get_repo_dir patmos)
# absolute path to the java tools source dir
local rootdir=$(abspath $ROOT_DIR/$root)
if [ $DO_CLEAN == true -o ! -e "$builddir" ] ; then
run rm -rf $builddir
run mkdir -p $builddir
fi
# We can only safely use abspath once the path has been created.
buildpath=$(abspath $builddir)
run pushd "${rootdir}" > /dev/null
run make $MAKEJ $MAKE_VERBOSE "JAVATOOLSBUILDDIR='${buildpath}'" "INSTALLDIR='${INSTALL_DIR}'" javatools
run popd > /dev/null
}
function build_scripttools() {
# build directory (might be relative)
local builddir=$ROOT_DIR/$1
# source directory of the main makefile (relative to ROOT_DIR)
local root=$(get_repo_dir patmos)
# absolute path to the script tools source dir
local rootdir=$(abspath $ROOT_DIR/$root)
if [ $DO_CLEAN == true -o ! -e "$builddir" ] ; then
run rm -rf $builddir
run mkdir -p $builddir
fi