-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadt
executable file
·1066 lines (994 loc) · 36.5 KB
/
adt
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 --
set -o pipefail
# We may be called from a different directory to where we reside. We have to CD
# into the resident directory first!
cd $(dirname ${BASH_SOURCE[0]})
do_build=0
just_preq=0
do_clone_only=0
do_tests=0
do_clean_tests=0
TEST_PATTERN=
use_this_adtools=0
gcc_ver=11 # default
coreutils_ver=5.2
binutils_ver=2.23.2
SDK_VERSION=54.16
args=
session_prefix=
gcc_path=
CORES=$(nproc)
session_was_cached=0
ignore_depends=0
adtools_repo_loc="https://github.com/AmigaLabs/adtools.git"
adtools_repo_branch=master
just_continue=0
no_cache=0
DEBUG_MAKE=0
readonly ORIG_DIR="$(pwd)"
readonly ADTOOLS_DIR=adt_adtools
readonly TESTS_DIR=tests
readonly SCRIPT_INVOCATION=1
readonly RUN_ALL_SCRIPT=run_all.script
readonly RUN_ALL_LINUX_SCRIPT=run_all_linux.script
readonly EXECUTE_SCRIPT=user.script
readonly SESSION_CACHE="${ORIG_DIR}/.adt_session.cache"
readonly ADT_LOG_FILE=adt.log
prev_session_cache="${SESSION_CACHE}_$(date +%s).bak"
BUILD_DIR=build
FINAL_LHA=
BASE_DIR=
CROSS_PREFIX=
ADTOOLS_MOD_SCRIPT=
DO_NATIVE_COMPILER=0
USE_FULL_SDK=0
ENHANCER_LOC=""
function _sep
{
echo "-------------------------------------------------------------------------------"
}
# $1: Message
function _info
{
echo "### INFO: ${1}"
}
# $1: Message
function _warn
{
echo "### WARN: ${1}" 1>&2
}
# $1: Message
# $2: Unique Error Code
# $3: If set to anything then also requests the user to manually remove ${BASE_DIR}
function _error
{
echo "### GURU MEDITATION ERROR (CODE: ${2}): ${1}" 1>&2
if [[ -n "${3}" ]]
then
_warn "For this error it is recommended to remove \"${BASE_DIR}\" before starting again"
fi
if (( session_was_cached ))
then
_info "Cached settings:"
obtain_adt_last_proj DO_NOT_SOURCE
fi
exit "${2}"
}
#
function generate_adt_last_proj
{
cat > "${SESSION_CACHE}.tmp" <<EOF
use_this_adtools="${use_this_adtools}"
gcc_ver="${gcc_ver}"
binutils_ver="${binutils_ver}"
coreutils_ver="${coreutils_ver}"
session_prefix="${session_prefix}"
gcc_path="${gcc_path}"
adtools_repo_loc="${adtools_repo_loc}"
adtools_repo_branch="${adtools_repo_branch}"
# ADTOOLS_MOD_SCRIPT="${ADTOOLS_MOD_SCRIPT}"
SDK_VERSION="${SDK_VERSION}"
CROSS_PREFIX="${CROSS_PREFIX}"
export SDK_VERSION
export CROSS_PREFIX
EOF
if [[ -f "${SESSION_CACHE}" ]]
then
# Do not overwrite / create a BAK in the case that there is no difference!
if ! diff "${SESSION_CACHE}" "${SESSION_CACHE}.tmp" 1>/dev/null 2>&1
then
_warn "Overwriting previously cached session. Previous session file backed up to: \"${prev_session_cache}\""
cp "${SESSION_CACHE}" "${prev_session_cache}"
mv "${SESSION_CACHE}.tmp" "${SESSION_CACHE}"
fi
else
mv "${SESSION_CACHE}.tmp" "${SESSION_CACHE}"
fi
session_was_cached=1
}
# $1: If set to anything then do not source the cached settings
function obtain_adt_last_proj
{
if [[ -f "${SESSION_CACHE}" ]]
then
if (( $# == 0 ))
then
source "${SESSION_CACHE}" && _info "Using cached settings from last invocation"
fi
_info ""
_info "Settings Begin"
while read setting
do
_info ">>> ${setting}"
done < "${SESSION_CACHE}"
_info "Settings End"
_info ""
else
_error "No previous settings were cached" 103
fi
}
function _usage
{
cat << EOF
Usage: adt [OPTIONS] [ACTIONS] [EXPORT] (one, and only one, action is always required)
OPTIONS:
[-x] [ [-p <PREFIX>] | [-o <PATH>] ] [-u] [-k <NUM>] [-i] [-y] [-d]
ACTIONS:
===
BUILD ADTOOLS:
-b [-q] [-r "<REPO [BRANCH]>"] [-g <VER>] [-n <VER>] [-s <VER>] [-m <FILE>] [-a] [-X]
===
TESTS:
-t [-S <PAT>] [-l "<CLIB(s)>"] [-z "<LINK_TYPE>"] [-h]
===
CLEAN:
-c | -C
===
CHECK REQUISITES FOR BUILDING:
-j
===
EXPORT:
[VAR[=VAL] ...]
^
A string of environment variables with optional values that are exported.
For example, "./adt -t THREAD_IMPL=pthread LIBS=-lpthread" results in
THREAD_IMPL and LIBS being exported for potential use in Makefiles. Note
that EXPORT is not cached.
Note on EXPORT:
This is useful when you want to use a different CLIB4 branch, or set makefile
variables for the ADTOOLS makefile. For instance, CLIB4_SHA1 can be exported
to use a specific CLIB4 branch. See the TL;DR section below.
[x] cached proj: Use the variables stored from the previous build action
session for this action. This is useful when a complex
build was invoked before containing many options so
that they do not need to be remembered. This cache file
is only updated on a build action which requires a new
build of ADTOOLS. For example, if a build action such
as "-b -s 53.30 -g 10 -p beta10" was provided then
running the tests for that session is as easy as
"-x -t", or, making a modification to the cross
compiler source files and wanting to build the cross
compiler again is as easy as "-x -b"
!! NOTE !! : This option must be the first option provided. Not all
arguments are cached. See below
[p] prefix : Sets the prefix of the build, test or clean session.
This may be useful if you wish to build another version
of ADTOOLS and/or perform tests on another version. The
value should be the name of the ADTOOLS build directory
!! NOTE !! : It is important to use this option when invoking a
build, test or clean action so as to ensure operation
on the expected session/prefix. Rather than supplying
this option you can just set an environment variable
named ADTOOLS_PREFIX which will have the same effect as
supplying -p <PREFIX>. Alternatively, use the -x option
which will retrieve the previous session's settings
[o] gcc path : This is a deviation to the principle of this repository
because the idea is that everything is self-contained
inside the directory you have cloned this repository
to. But, if desired, you can supply this option with a
path and the cross-compiler will be installed into that
location. For example, -o /usr/amiga/gcc. But,
everything else will remain self-contained and the
cloning of ADTOOLS will still be self-contained, only
the installation of the cross compiler will be put into
<PATH>
!! NOTE !! : Rather than supplying this option you can just set an
environment variable named ADTOOLS_GCC_PATH which will
have the same effect as supplying -o <PATH>.
Alternatively, use the -x option which will retrieve
the previous session's settings. Like the -p option,
you will need to provide this option if you want to
build the tests for a build of ADTOOLS that was built
with this option, unless the -x option is used, or the
variables described above are set in the environment
[u] use_adtools: Use the ADTOOLS that is already on the existing path
for building the tests or use this when performing a
clean of a build of ADTOOLS. In the case ADTOOLS was
built by using the -o option, you will need to add the
cross-compiler to the path and then use this option
along with -t
[k] cores : Number of cores/jobs to pass to Makefiles
(DEFAULT: the result of the command NPROC)
!! NOTE !! : This option is NOT cached
[i] ignore dep : Ignore dependency checker routine
!! NOTE !! : This option is NOT cached
[y] auto answer: Automatically answer script questions with whatever
answer will result in script progression where safe to
do so
!! NOTE !! : This option is NOT cached
[d] don't cache: Do not update the cache for this invocation
!! NOTE !! : This option is NOT cached
[b] build : Clones and builds ADTOOLS in-place respecting the
additionally supplied options. The in-place location is
the folder named "<PREFIX>build". If the directory
already exists then this script invokes a build in the
already existing in-place ADTOOLS without firstly
performing a clean
[q] Don't build: ADTOOLS is cloned, as normal, and, any modification
script is applied and then this script quits without
building ADTOOLS
!! NOTE !! : This option is NOT cached
[r] repo : The repository location of ADTOOLS. <REPO> is the
location to clone from in the case you have forked
from the original location and BRANCH is switched to
if supplied
(DEFAULT: ${adtools_repo_loc})
!! NOTE !! : In the case you specify BRANCH you must quote the
option argument. For example
-r "https://myRepo/ MY_BRANCH"
[g] gcc : Selects the version of GCC to use when building
in-place ADTOOLS (DEFAULT: 11)
[n] binutils : Selects the version of BINUTILS to use when building
in-place ADTOOLS (DEFAULT: 2.23.2)
[s] SDK : Selects the version of the SDK to use when building
in-place ADTOOLS (DEFAULT: 54.16)
[m] mod script : Invoke the script named <FILE> after cloning ADTOOLS
but before building ADTOOLS. This allows modifications
to things like the native-build/makefile or whatever is
desired before building ADTOOLS. This is only invoked
if the ADTOOLS repository has not yet been cloned. The
script should reside in the same directory as this
script (the adt script). There is also an example mod
script named "adtools_mod"
[a] nativebuild: After building the cross compiler, also build a
native compiler. This will require a directory:
\`/gcc/' which is owned by the user:
sudo mkdir /gcc/
sudo chown <user>:<user> /gcc/
where user is the value of the command
\`whoami'. The distribution will be available as an LHA
file
[X] full SDK : After building the cross compiler, install the full SDK
into the build directory. When building a compiler, only
the necessary components of the SDK are installed, this
option provides a way to install the remaining. This is
limited to copying over all files/folder under Local and
Include. If an environment variable named ENHANCER_LOC
(this variable should include the file name of the
Ehnancer archive file, itself) is also supplied in the
EXPORTS then as well as extracting the SDK parts, the
enhancer archive's SDK parts are also extracted and
copied
[t] tests : Builds all of the tests under the "tests" folder.
Logging of each build of each variant is appended to
the log file. This will implicitly clean out all the
build files at the end, finally leeaving the test LHA
file
[S] pattern : Only perform a test build on the test(s) that match the
pattern in <PAT>. <PAT> should represent a substring
since globbing is automatically added
!! NOTE !! : This option is NOT cached
[l] C LIBS : : Provide a list of the C libraries for which you want to
test (DEFAULT: newlib clib2 clib4)
!! NOTE !! : This option is NOT cached
[z] LINK TYPE : Provide a list of the link type for which you want to
test (DEFAULT: static dynamic)
!! NOTE !! : This option is NOT cached
[h] debug make : Enable some more debugging information in the case of
errors when running the makefile for a test
!! NOTE !! : This option is NOT cached
[c] clean_tests: Performs a clean on all tests
[C] clean_build: Performs a clean on the in-place ADTOOLS which will
also remove the built cross-compiler binaries. In the
case that you are using a cross-compiler outside of the
the self-contained directory then it is not recommended
to use this option without strict consideration
[j] Just preqs : Just check the prequisite libraries to build ADTOOLS.
This is useful to see which libraries may be needed on
your current system.
TL;DR:
1. If you just want to build an ADTOOLS cross-compiler then run the
following:
./adt -b
2. If you just want to build an ADTOOLS native-compiler that can be
tranferred to the AmigaOne machine (note that this MUST also build a
cross-compiler):
./adt -b -a
3. WRT. EXPORT, if you want to build ADTOOLS using a specific CLIB4 branch,
say, the "development" branch, with GCC 6:
./adt -b -g 6 CLIB_SHA1=development
4. If you want to perform 1. but also have the full SDK headers and libraries
as well as the Enhancer headers and libraries, then:
./adt -b -X ENHANCER_LOC=/home/user/Downloads/enhancer_software_2.2.lha
ENHANCER_LOC is not needed and without it just the SDK headers and
libraries are extracted
5. If you just want to check that you have all the necessary dependencies to
build the cross-compiler / native-compiler. Note that this does not check
the version of GCC and GCC 14 is known to generate errors due to warnings:
./adt -j
6. Then, if you want to build all of the tests:
./adt -t
EOF
}
function SETUP_PATHS
{
# Allow for the case that the user has just directly specified the
# full path to the BUILD_DIR for `session_prefix'. This is
# convenient because you can then just use TAB completion without
# needed to remove the "build" manually at the end!
if [[ -n "${session_prefix}" ]]
then
# Need to make this relative to the directory containing this script
#
# The user may have provided a some paths and we know that all prefixes
# must exist in the same directory as this script so just take the
# basename
session_prefix="$(basename "${session_prefix}")"
if [[ ! -d "${session_prefix}build" ]]
then
if [[ -d "${session_prefix}" ]]
then
BUILD_DIR="${session_prefix}"
else
# If the above fails and we get here then the user has
# either provided a bad prefix or we are building a
# new cross compiler.
BUILD_DIR="${session_prefix}build"
fi
else
BUILD_DIR="${session_prefix}build"
fi
fi
FINAL_LHA="${session_prefix}adt_tests.lha"
BASE_DIR="${ORIG_DIR}/${BUILD_DIR}"
if [[ -z "${CROSS_PREFIX}" ]]
then
CROSS_PREFIX="${BASE_DIR}/adt_build"
else
# Do not set it since we must be in the situation where the user has provided the "-x" option
# which should use the value in the cache file.
:
fi
# Rather than correctly applying logic above to check if the
# gcc_path should be honoured, just perform a one-shot change to
# the necessary variables right here!
#
# The -o option is a total hack and should not be used!
if [[ -n "${gcc_path}" ]]
then
# Strip the / suffix off if one exists and assume that it does not have multiple trailing /
if [[ "${gcc_path: -1}" == / ]]
then
gcc_path="${gcc_path::-1}"
fi
if [[ -n "${session_prefix}" ]]
then
_error "The prefix (-p) option cannot be used in conjunction with a user defined gcc_path option (-o)" 101
fi
CROSS_PREFIX="${gcc_path}"
BASE_DIR="${ORIG_DIR}/$(echo "${gcc_path}" | sed 's,/,_,g' )build"
FINAL_LHA="$(echo "${gcc_path}" | sed 's,/,_,g' )adt_tests.lha"
elif (( use_this_adtools ))
then
# For cross-compilers on the path, we will use the compiler as
# BASE_DIR, this allows the testing framework to run the tests
# and apply the clean_stamp rules only if clean_stamp does not
# yet exist, or if the cross-compiler on the PATH has been
# updated outside the context of this repo
BASE_DIR="$(which ppc-amigaos-gcc)"
fi
}
function CHECK_DEPENDS
{
local _continue=1
local _selection
local _packages=(
"libgmp-dev"
"libmpc-dev"
"libmpfr-dev"
"bison"
"flex"
"texinfo"
"wdiff"
"python3-argcomplete"
"python3-mako"
)
# We print this out regardless of the package management system so
# that in the case that dpkg is NOT being used, the user has an
# idea of which packages to manually install
_info "Checking for the following required packages:"
for package in "${_packages[@]}"
do
_info "- ${package}"
done
if [[ ! "$(lha --version 2>&1)" =~ "LHa for UNIX version" ]]
then
_warn "Unexpected or no version of \"LHA\". Please use \"https://github.com/jca02266/lha. Build it and install it.\""
_continue=0
fi
# Only supporting dpkg for now
if [[ $(dpkg-query --version 1>/dev/null 2>&1 && echo $?) ]]
then
for package in "${_packages[@]}"
do
# You can have a 32-bit version and 64-bit version, meaning
# that you can get something like installedinstalled. Let's
# be lax about this check:
if ! [[ $(dpkg-query --showformat '${db:Status-Status}' --show "${package}" 2>/dev/null) =~ installed ]]
then
# Python3 packages may also be installed via pip
if [[ "$package" =~ python3 ]]
then
python3 -m pip list 2>/dev/null | grep -q "${package:8}" && continue
fi
_warn "Package \"${package}\" does not seem to be installed and it is required to build ADTOOLS"
_continue=0
else
if [[ "${package}" = "texinfo" ]]
then
# Check the version of texinfo since at least version 7.1 is known to be too strict
if (( $(dpkg -l | grep texinfo | grep -Eo "[0-9]+\.[0-9]+" | cut -f1 -d.) >= 7 ))
then
_warn "textinfo version 7 and above may not succeed. Continue ([y]/n)?"
if (( !just_continue ))
then
read _selection
if [[ "${_selection}" != y ]]
then
_error "Not continuing due to a too high version of textinfo" 213 1
fi
fi
fi
fi
fi
done
else
_warn "Prebuild dependency checking is only supported with \"dpkg\". Dependency checks ignored."
_continue=0
fi
if (( !_continue ))
then
if (( just_preq ))
then
_info "Dependency check was not clean"
else
_info "Dependency check was not clean. Continue ([y]/n)?"
if (( !just_continue ))
then
read _selection
if [[ "${_selection}" != y ]]
then
_error "Not continuing due to issues with the dependency checker" 207 1
fi
fi
fi
else
_info "Dependency check OKAY"
fi
}
function BUILD
{
local INFO_STRING="[$(date)] Building ADTOOLS from repository \"${adtools_repo_loc}\" (branch \"${adtools_repo_branch}\"), using GCC version \"${gcc_ver}\", BINUTILS version \"${binutils_ver}\", COREUTILS version \"${coreutils_ver}\" (only relevant when building a native compiler), SDK version \"${SDK_VERSION}\", CROSS_PREFIX (installation location of the cross-compiler) \"${CROSS_PREFIX}\". Built with environment variables: \"${args}\""
local _cloneLoc="${BASE_DIR}/${ADTOOLS_DIR}"
if [[ -n "${gcc_path}" ]]
then
_cloneLoc="${BASE_DIR}"
fi
if [[ ! -d "${BASE_DIR}" ]]
then
if (( !ignore_depends ))
then
# TODO: Return a value from the function instead and raise error here
CHECK_DEPENDS
fi
local native_gcc=
# We also need g++
{ which gcc && which g++ ; } 1>/dev/null 2>&1
if (( !${?} ))
then
native_gcc="$(gcc -dumpmachine)"
if [[ "${native_gcc}" == "x86_64-linux-gnu" ]]
then
native_gcc=
fi
else
native_gcc=error
fi
if [[ -n "${native_gcc}" ]]
then
if [[ "${native_gcc}" == error ]]
then
_error "No native compiler exists to build ADTOOLS. Both \"gcc\" and \"g++\" are needed and only the GNU COMPILER COLLECTION (GCC) is supported" 30
else
_warn "Native Compiler architecture is \"${native_gcc}\" which is not supported but continuing anyway"
fi
fi
# Check the version of gcc:
if (( $(gcc --version | sed -n 's/.* \([0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/p' | cut -f1 -d.) >= 14 ))
then
_warn "GCC version 14 (and probably above) are known to not build the cross compiler due to strict warnings as errors. Continue ([y]/n)?"
if (( !just_continue ))
then
read _selection
if [[ "${_selection}" != y ]]
then
_error "Not continuing due to build machine using GCC 14 or above" 212
fi
fi
fi
if (( DO_NATIVE_COMPILER ))
then
if ! [[ -d /gcc/ && $(touch /gcc/tmp && rm /gcc/tmp && echo $?) ]]
then
_error "Building a native compiler requires a directory, /gcc/ with write permissions" 211
fi
fi
_info "Building ADTOOLS..."
mkdir "${BASE_DIR}"
cd "${BASE_DIR}"
git clone "${adtools_repo_loc}" "${ADTOOLS_DIR}" || _error "Unable to clone ADTOOLS repo" 201 1
cd "${ADTOOLS_DIR}"
if [[ -n "${adtools_repo_branch}" ]]
then
git checkout "${adtools_repo_branch}" || _error "Unable to checkout: \"${adtools_repo_branch}\"" 301 1
fi
# Check that the user has configured git email/username; especially
# since ADTOOLS silently just does not apply the patches if this
# information is not there and then binutils fails to build with someone
# nebulous errors!
git config user.email 1>/dev/null 2>&1 || \
_error "Git has no user.email configured. This will lead to errors in building ADTOOLS" 208 1
git config user.name 1>/dev/null 2>&1 || \
_error "Git has no user.name configured. This will lead to errors in building ADTOOLS" 209 1
# TODO: gild does not return a NON-ZERO exit status, so these
# ORs are pretty useless unfortunately.
#
# Right now, GCC version 4.9 causes an issue since the remote
# branch hash is not found in upstream.
git submodule init || _error "Unable to initialise submodules in ADTOOLS repo" 202 1
git submodule update || _error "Unable to update submodules in ADTOOLS repo" 203 1
gild/bin/gild checkout binutils "${binutils_ver}" || _error "Unable to clone binutils in ADTOOLS repo" 204 1
gild/bin/gild checkout gcc "${gcc_ver}" || _error "Unable to clone gcc in ADTOOLS repo" 205 1
if (( DO_NATIVE_COMPILER ))
then
gild/bin/gild checkout coreutils ${coreutils_ver} || _error "Unable to clone coreutils in ADTOOLS repo" 210 1
fi
# Performs the modification (if any) that are provided in the
# following script
if [[ -n "${ADTOOLS_MOD_SCRIPT}" ]]
then
"${ORIG_DIR}/${ADTOOLS_MOD_SCRIPT}" || _error "Modification script to ADTOOLS failed" 206 1
fi
# Clear any of these variables in the unlikely event they are set. If not, then
# they are picked up during the building ADTOOLS and they may not point to the
# native gcc that we just tested for before.
export CC=
export CFLAGS=
export CXX=
export CXXFLAGS=
export CPPFLAGS=
export AR=
export AS=
export LD=
export RANLIB=
export READELF=
# Store this session's settings
if (( !no_cache ))
then
generate_adt_last_proj
fi
# Quit now if we do not want to build ADTOOLS
if (( do_clone_only ))
then
_info "Your build directory (where the ADTOOLS repository and its source was cloned to) is: \"${_cloneLoc}\""
_info "Since you supplied the -q option, ADTOOLS has only been cloned and modified"
return
fi
else
if (( do_clone_only ))
then
_error "The -q option implies no building. No further action will be taken" 31
fi
cd "${BASE_DIR}/${ADTOOLS_DIR}"
# In the case that we just performed a clean (-C), then we do
# not want to be asked about this
if [[ -d "${CROSS_PREFIX}" ]]
then
local _selection=
_info "Assuming you want to build the cross compiler"
_info "Did you make any changes to the CLIB4 source files? (y/[n])?"
if (( !just_continue ))
then
read _selection
if [[ "${_selection}" == y ]]
then
rm -f "${BASE_DIR}/${ADTOOLS_DIR}/native-build/clib4-cross-done-"*
fi
fi
_info "Did you make any changes to the BINUTILS source files? (y/[n])?"
if (( !just_continue ))
then
read _selection
if [[ "${_selection}" == y ]]
then
rm -f "${BASE_DIR}/${ADTOOLS_DIR}/native-build/binutils-cross-done-"*
fi
fi
rm -f "${BASE_DIR}/${ADTOOLS_DIR}/native-build/gcc-cross-done-"*
fi
fi
if [[ -n "${gcc_path}" ]]
then
which ppc-amigaos-gcc 1>/dev/null 2>&1 && _warn "Already found a cross compiler on the path. "\
"Since you used the -o option then this script assumes this is expected"
fi
sleep 5 # let the user at least notice if there were some messages
LOG_FILE="${BASE_DIR}/${ADT_LOG_FILE}"
echo "####################" >> "${LOG_FILE}"
echo "${INFO_STRING}" >> "${LOG_FILE}"
echo "####################" >> "${LOG_FILE}"
if [[ -n "${ADTOOLS_MOD_SCRIPT}" ]]
then
echo "ADTOOLS was modified with script \"${ADTOOLS_MOD_SCRIPT}\" whose contents, indented by 4 spaces, follows:" >> "${LOG_FILE}"
while read line
do
echo " ${line}" >> "${LOG_FILE}"
done < "${ORIG_DIR}/${ADTOOLS_MOD_SCRIPT}"
fi
BUILD_CMD="make -O -j${CORES} -C native-build/ gcc-cross 2>&1 | "\
"tee -a \"${LOG_FILE}\""
echo "####################" >> "${LOG_FILE}"
echo "RUNNING COMMAND: ${BUILD_CMD}" >> "${LOG_FILE}"
echo "####################" >> "${LOG_FILE}"
eval "${BUILD_CMD} || _error \"The ADTOOLS build failed. See the log file: \"${LOG_FILE}\"\" 40"
# Update the timestamp so that the test framework knows whether it should rebuild the tests.
# Of course, this dir will be touched even if there was nothing to update in ADTOOLS.
touch "${BASE_DIR}"
if (( DO_NATIVE_COMPILER ))
then
BUILD_CMD="make -O -j${CORES} -C native-build/ native-install 2>&1 | "\
"tee -a \"${LOG_FILE}\""
echo "####################" >> "${LOG_FILE}"
echo "RUNNING COMMAND: ${BUILD_CMD}" >> "${LOG_FILE}"
echo "####################" >> "${LOG_FILE}"
eval "${BUILD_CMD} || _error \"The ADTOOLS native compiler build failed. See the log file: \"${LOG_FILE}\"\" 41"
BUILD_CMD="make -O -j${CORES} -C native-build/ native-dist 2>&1 | "\
"tee -a \"${LOG_FILE}\""
echo "####################" >> "${LOG_FILE}"
echo "RUNNING COMMAND: ${BUILD_CMD}" >> "${LOG_FILE}"
echo "####################" >> "${LOG_FILE}"
eval "${BUILD_CMD} || _error \"The ADTOOLS native compiler final distribution failed. See the log file: \"${LOG_FILE}\"\" 42"
fi
if (( USE_FULL_SDK ))
then
_info "Installing the full SDK contents into: \"${CROSS_PREFIX}\""
local curr_dir="$(pwd)"
test -d /tmp/__tmp.SDK/ && rm -rf /tmp/__tmp.SDK/
mkdir -p /tmp/__tmp.SDK/
cp "${_cloneLoc}"/native-build/downloads/SDK*.lha /tmp/__tmp.SDK/
cd /tmp/__tmp.SDK/
lha xf -q2 *.lha
cd SDK_Install
# Assuming no spaces in names:
for l in *.lha ; do lha xf -q2 $l ; done
# We are only interested in those files under [Ll]ocal and
# [Ii]nclude. We assume that Local and Include are the only folder that
# have potential difference in capitalisation
#
# TODO: BTW, [Ss]ource also exists, but this is probably not an issue
cp -r local "${CROSS_PREFIX}"/ppc-amigaos/SDK/
cp -r Local/* "${CROSS_PREFIX}"/ppc-amigaos/SDK/local/
cp -r include/* "${CROSS_PREFIX}"/ppc-amigaos/SDK/include/
cp -r Include/* "${CROSS_PREFIX}"/ppc-amigaos/SDK/include/
cd "${curr_dir}"
rm -rf /tmp/__tmp.SDK
# Also do the same thing for Enhancer, if it was supplied as an export
if [[ -n "${ENHANCER_LOC}" ]]
then
_info "Installing the Enhancer SDK contents into: \"${CROSS_PREFIX}\""
mkdir -p /tmp/__tmp.SDK/
cp "${ENHANCER_LOC}" /tmp/__tmp.SDK/
cd /tmp/__tmp.SDK/
lha xf -q2 *.lha
cd */Installation_Files/
for d in $(find SDK -mindepth 1 -maxdepth 1 -type d)
do
test -d "$d"/local && cp -r "$d"/local/* "${CROSS_PREFIX}"/ppc-amigaos/SDK/local/
test -d "$d"/Local && cp -r "$d"/Local/* "${CROSS_PREFIX}"/ppc-amigaos/SDK/local/
test -d "$d"/include && cp -r "$d"/include/* "${CROSS_PREFIX}"/ppc-amigaos/SDK/include/
test -d "$d/"Include && cp -r "$d"/Include/* "${CROSS_PREFIX}"/ppc-amigaos/SDK/include/
done
cd "${curr_dir}"
rm -rf /tmp/__tmp.SDK/
fi
test -d "${CROSS_PREFIX}"/ppc-amigaos/SDK/local/source && rm -rf "${CROSS_PREFIX}"/ppc-amigaos/SDK/local/source
test -d "${CROSS_PREFIX}"/ppc-amigaos/SDK/local/Source && rm -rf "${CROSS_PREFIX}"/ppc-amigaos/SDK/local/Source
fi
_info "Finished building ADTOOLS. If there were no errors then:"
_info "The build directory (where the ADTOOLS repository and its source was cloned to) is: \"${_cloneLoc}\""
_info "The installation directory (where the cross compiler was INSTALLED to) is: \"${CROSS_PREFIX}\""
if (( DO_NATIVE_COMPILER ))
then
_info "The native compiler is at location: \"$(pwd)/native-build\""
ls -l native-build/*.lha
fi
_info "The full log file is at: \"${LOG_FILE}\""
}
function TESTS
{
# Arbitrary check
which ppc-amigaos-gcc 1>/dev/null 2>&1 || _error "Expected to find the cross-compiler on the path."\
" You may have forgotten to set the prefix with option -p or build the cross compiler or specify the"\
"-u option or use the -x option to retain your previously cached settings" 50
rm -f "${FINAL_LHA}"
make -s -C "${TESTS_DIR}" clean
_info "Using cross-compiler: $(which ppc-amigaos-gcc)"
_info "If errors occur the look at the relevant log file in the test directory"
_sep
_info "Building tests..."
make -s -C "${TESTS_DIR}" all || _error "An error occurred while trying to build the tests" 120
_info "Finished building tests..."
_sep
_info "\"${FINAL_LHA}\" can be copied to an AmigaOne machine. Extract it and run: \"execute run_all.script\"."
_info "By default, the script extracts everything, appropriately, and executes a script, \"user.script\""
_info "which acts on each variant. The \"run_all.script\" is designed to be re-run again. Alternatively,"
_info "copy over the individual test/variant LHA. If your tests relies on clib4.library and you do not use"
_info "the \"user.script\" then you will have to ensure that clib4.library is available in LIBS: manually"
_info "or in the current program path of the executable"
_info ""
_info "In the case that you want to extract on a linux machine then extract and run \"run_all_linux.script\""
_info ""
_info "NOTE! Do not expect all builds to pass for tests. It may be expected that some fail. Inspect the logs for"
_info " more information"
}
if (( $# == 0 ))
then
_usage
_error "No options provided" 10
fi
seen_non_x_opt=0
while getopts xp:o:uk:iydbjqr:g:n:s:m:aXtS:l:z:hcC opt
do
if [[ "${opt}" != x ]] ; then seen_non_x_opt=1 ; fi
case "${opt}" in
x)
if (( seen_non_x_opt ))
then
# This allows options from the cache file to be further overriden
_error "-x must be the first option to this script" 102
fi
obtain_adt_last_proj
;;
p)
session_prefix="${OPTARG}"
;;
o)
gcc_path="${OPTARG}"
;;
u)
use_this_adtools=1
;;
k)
CORES="${OPTARG}"
;;
i)
ignore_depends=1
;;
y)
just_continue=1
;;
d)
no_cache=1;
;;
b)
do_build=1
;;
j)
just_preq=1
;;
q)
do_clone_only=1
;;
r)
repo_branch=(${OPTARG})
adtools_repo_loc="${repo_branch[0]}"
if (( ${#repo_branch[@]} > 1 ))
then
adtools_repo_branch="${repo_branch[1]}"
fi
;;
g)
gcc_ver="${OPTARG}"
;;
n)
binutils_ver="${OPTARG}"
;;
s)
SDK_VERSION="${OPTARG}"
;;
m)
ADTOOLS_MOD_SCRIPT="${OPTARG}"
;;
a)
DO_NATIVE_COMPILER=1
;;
X)
USE_FULL_SDK=1
;;
t)
do_tests=1
;;
S)
TEST_PATTERN="${OPTARG}"
export TEST_PATTERN
;;
l)
C_LIB_LIST=
if [[ ${OPTARG} =~ newlib ]]
then
C_LIB_LIST="\"newlib\""
fi
if [[ ${OPTARG} =~ clib2 ]]
then
C_LIB_LIST="${C_LIB_LIST} \"clib2\""
fi
if [[ ${OPTARG} =~ clib4 ]]
then
C_LIB_LIST="${C_LIB_LIST} \"clib4\""
fi
if [[ -z ${C_LIB_LIST} ]]
then
_error "-l can only take \"newlib\" and/or \"clib2\" and/or \"clib4\" as arguments" 106
fi
export C_LIB_LIST
;;
z)
LINKER_TYPE_LIST=
if [[ ${OPTARG} =~ static ]]
then
LINKER_TYPE_LIST="\"\""
fi
if [[ ${OPTARG} =~ dynamic ]]
then
LINKER_TYPE_LIST="${LINKER_TYPE_LIST} \"-use-dynld\""
fi
if [[ -z ${LINKER_TYPE_LIST} ]]
then
_error "-z can only take \"dynamic\" and/or \"static\" as arguments" 104
fi
export LINKER_TYPE_LIST
;;
h)
DEBUG_MAKE=1
export DEBUG_MAKE
;;
c)
do_clean_tests=1
;;
C)
do_clean_build=1
;;
*)
_usage
_error "Invalid option" 105
;;
esac
done
shift $((OPTIND - 1))
args="${@}"
# Check if the user simply wants to install prerequisite libraries for ADTOOLS
if (( just_preq ))
then
CHECK_DEPENDS
exit 0
fi
# Check for any influential environment variables before continuing
if [[ -n "${ADTOOLS_PREFIX}" ]]
then
session_prefix="${ADTOOLS_PREFIX}"
fi
if [[ -n "${ADTOOLS_GCC_PATH}" ]]
then
gcc_path="${ADTOOLS_GCC_PATH}"
fi
SETUP_PATHS
if (( do_build && do_tests ))
then
_error "Building the tests and building ADTOOLS is mutually exclusive" 20
fi
if (( !do_build && !do_tests && !do_clean_tests && !do_clean_build ))
then
_error "No action performed" 80
fi
if (( !do_clean_tests && !do_clean_build ))
then
if (( use_this_adtools ))
then
this_adtools="$(dirname $(which ppc-amigaos-gcc) 2>/dev/null)"
if [[ -z "${this_adtools}" ]]
then
_error "Desired ADTOOLS cross-compiler not found on PATH" 70
fi
CROSS_PREFIX="${this_adtools}/../"
_info "The -u option was used. Assuming that \"CROSS_PREFIX=${CROSS_PREFIX}\""
else
# unless we are using the deviation -o option!
if [[ -z "${gcc_path}" ]]
then
which ppc-amigaos-gcc 1>/dev/null 2>&1 && \
_warn "Did not expect to find a cross-compiler on the path"
fi
fi
fi