forked from jsonn/src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·2309 lines (2104 loc) · 64.8 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
#! /usr/bin/env sh
# $NetBSD: build.sh,v 1.306 2015/02/01 18:49:25 christos Exp $
#
# Copyright (c) 2001-2011 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Todd Vierling and Luke Mewburn.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#
# Top level build wrapper, to build or cross-build NetBSD.
#
#
# {{{ Begin shell feature tests.
#
# We try to determine whether or not this script is being run under
# a shell that supports the features that we use. If not, we try to
# re-exec the script under another shell. If we can't find another
# suitable shell, then we print a message and exit.
#
errmsg='' # error message, if not empty
shelltest=false # if true, exit after testing the shell
re_exec_allowed=true # if true, we may exec under another shell
# Parse special command line options in $1. These special options are
# for internal use only, are not documented, and are not valid anywhere
# other than $1.
case "$1" in
"--shelltest")
shelltest=true
re_exec_allowed=false
shift
;;
"--no-re-exec")
re_exec_allowed=false
shift
;;
esac
# Solaris /bin/sh, and other SVR4 shells, do not support "!".
# This is the first feature that we test, because subsequent
# tests use "!".
#
if test -z "$errmsg"; then
if ( eval '! false' ) >/dev/null 2>&1 ; then
:
else
errmsg='Shell does not support "!".'
fi
fi
# Does the shell support functions?
#
if test -z "$errmsg"; then
if ! (
eval 'somefunction() { : ; }'
) >/dev/null 2>&1
then
errmsg='Shell does not support functions.'
fi
fi
# Does the shell support the "local" keyword for variables in functions?
#
# Local variables are not required by SUSv3, but some scripts run during
# the NetBSD build use them.
#
# ksh93 fails this test; it uses an incompatible syntax involving the
# keywords 'function' and 'typeset'.
#
if test -z "$errmsg"; then
if ! (
eval 'f() { local v=2; }; v=1; f && test x"$v" = x"1"'
) >/dev/null 2>&1
then
errmsg='Shell does not support the "local" keyword in functions.'
fi
fi
# Does the shell support ${var%suffix}, ${var#prefix}, and their variants?
#
# We don't bother testing for ${var+value}, ${var-value}, or their variants,
# since shells without those are sure to fail other tests too.
#
if test -z "$errmsg"; then
if ! (
eval 'var=a/b/c ;
test x"${var#*/};${var##*/};${var%/*};${var%%/*}" = \
x"b/c;c;a/b;a" ;'
) >/dev/null 2>&1
then
errmsg='Shell does not support "${var%suffix}" or "${var#prefix}".'
fi
fi
# Does the shell support IFS?
#
# zsh in normal mode (as opposed to "emulate sh" mode) fails this test.
#
if test -z "$errmsg"; then
if ! (
eval 'IFS=: ; v=":a b::c" ; set -- $v ; IFS=+ ;
test x"$#;$1,$2,$3,$4;$*" = x"4;,a b,,c;+a b++c"'
) >/dev/null 2>&1
then
errmsg='Shell does not support IFS word splitting.'
fi
fi
# Does the shell support ${1+"$@"}?
#
# Some versions of zsh fail this test, even in "emulate sh" mode.
#
if test -z "$errmsg"; then
if ! (
eval 'set -- "a a a" "b b b"; set -- ${1+"$@"};
test x"$#;$1;$2" = x"2;a a a;b b b";'
) >/dev/null 2>&1
then
errmsg='Shell does not support ${1+"$@"}.'
fi
fi
# Does the shell support $(...) command substitution?
#
if test -z "$errmsg"; then
if ! (
eval 'var=$(echo abc); test x"$var" = x"abc"'
) >/dev/null 2>&1
then
errmsg='Shell does not support "$(...)" command substitution.'
fi
fi
# Does the shell support $(...) command substitution with
# unbalanced parentheses?
#
# Some shells known to fail this test are: NetBSD /bin/ksh (as of 2009-12),
# bash-3.1, pdksh-5.2.14, zsh-4.2.7 in "emulate sh" mode.
#
if test -z "$errmsg"; then
if ! (
eval 'var=$(case x in x) echo abc;; esac); test x"$var" = x"abc"'
) >/dev/null 2>&1
then
# XXX: This test is ignored because so many shells fail it; instead,
# the NetBSD build avoids using the problematic construct.
: ignore 'Shell does not support "$(...)" with unbalanced ")".'
fi
fi
# Does the shell support getopts or getopt?
#
if test -z "$errmsg"; then
if ! (
eval 'type getopts || type getopt'
) >/dev/null 2>&1
then
errmsg='Shell does not support getopts or getopt.'
fi
fi
#
# If shelltest is true, exit now, reporting whether or not the shell is good.
#
if $shelltest; then
if test -n "$errmsg"; then
echo >&2 "$0: $errmsg"
exit 1
else
exit 0
fi
fi
#
# If the shell was bad, try to exec a better shell, or report an error.
#
# Loops are broken by passing an extra "--no-re-exec" flag to the new
# instance of this script.
#
if test -n "$errmsg"; then
if $re_exec_allowed; then
for othershell in \
"${HOST_SH}" /usr/xpg4/bin/sh ksh ksh88 mksh pdksh dash bash
# NOTE: some shells known not to work are:
# any shell using csh syntax;
# Solaris /bin/sh (missing many modern features);
# ksh93 (incompatible syntax for local variables);
# zsh (many differences, unless run in compatibility mode).
do
test -n "$othershell" || continue
if eval 'type "$othershell"' >/dev/null 2>&1 \
&& "$othershell" "$0" --shelltest >/dev/null 2>&1
then
cat <<EOF
$0: $errmsg
$0: Retrying under $othershell
EOF
HOST_SH="$othershell"
export HOST_SH
exec $othershell "$0" --no-re-exec "$@" # avoid ${1+"$@"}
fi
# If HOST_SH was set, but failed the test above,
# then give up without trying any other shells.
test x"${othershell}" = x"${HOST_SH}" && break
done
fi
#
# If we get here, then the shell is bad, and we either could not
# find a replacement, or were not allowed to try a replacement.
#
cat <<EOF
$0: $errmsg
The NetBSD build system requires a shell that supports modern POSIX
features, as well as the "local" keyword in functions (which is a
widely-implemented but non-standardised feature).
Please re-run this script under a suitable shell. For example:
/path/to/suitable/shell $0 ...
The above command will usually enable build.sh to automatically set
HOST_SH=/path/to/suitable/shell, but if that fails, then you may also
need to explicitly set the HOST_SH environment variable, as follows:
HOST_SH=/path/to/suitable/shell
export HOST_SH
\${HOST_SH} $0 ...
EOF
exit 1
fi
#
# }}} End shell feature tests.
#
progname=${0##*/}
toppid=$$
results=/dev/null
tab=' '
nl='
'
trap "exit 1" 1 2 3 15
bomb()
{
cat >&2 <<ERRORMESSAGE
ERROR: $@
*** BUILD ABORTED ***
ERRORMESSAGE
kill ${toppid} # in case we were invoked from a subshell
exit 1
}
# Quote args to make them safe in the shell.
# Usage: quotedlist="$(shell_quote args...)"
#
# After building up a quoted list, use it by evaling it inside
# double quotes, like this:
# eval "set -- $quotedlist"
# or like this:
# eval "\$command $quotedlist \$filename"
#
shell_quote()
{(
local result=''
local arg qarg
LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
for arg in "$@" ; do
case "${arg}" in
'')
qarg="''"
;;
*[!-./a-zA-Z0-9]*)
# Convert each embedded ' to '\'',
# then insert ' at the beginning of the first line,
# and append ' at the end of the last line.
# Finally, elide unnecessary '' pairs at the
# beginning and end of the result and as part of
# '\'''\'' sequences that result from multiple
# adjacent quotes in he input.
qarg="$(printf "%s\n" "$arg" | \
${SED:-sed} -e "s/'/'\\\\''/g" \
-e "1s/^/'/" -e "\$s/\$/'/" \
-e "1s/^''//" -e "\$s/''\$//" \
-e "s/'''/'/g"
)"
;;
*)
# Arg is not the empty string, and does not contain
# any unsafe characters. Leave it unchanged for
# readability.
qarg="${arg}"
;;
esac
result="${result}${result:+ }${qarg}"
done
printf "%s\n" "$result"
)}
statusmsg()
{
${runcmd} echo "===> $@" | tee -a "${results}"
}
statusmsg2()
{
local msg
msg="${1}"
shift
case "${msg}" in
????????????????*) ;;
??????????*) msg="${msg} ";;
?????*) msg="${msg} ";;
*) msg="${msg} ";;
esac
case "${msg}" in
?????????????????????*) ;;
????????????????????) msg="${msg} ";;
???????????????????) msg="${msg} ";;
??????????????????) msg="${msg} ";;
?????????????????) msg="${msg} ";;
????????????????) msg="${msg} ";;
esac
statusmsg "${msg}$*"
}
warning()
{
statusmsg "Warning: $@"
}
# Find a program in the PATH, and print the result. If not found,
# print a default. If $2 is defined (even if it is an empty string),
# then that is the default; otherwise, $1 is used as the default.
find_in_PATH()
{
local prog="$1"
local result="${2-"$1"}"
local oldIFS="${IFS}"
local dir
IFS=":"
for dir in ${PATH}; do
if [ -x "${dir}/${prog}" ]; then
result="${dir}/${prog}"
break
fi
done
IFS="${oldIFS}"
echo "${result}"
}
# Try to find a working POSIX shell, and set HOST_SH to refer to it.
# Assumes that uname_s, uname_m, and PWD have been set.
set_HOST_SH()
{
# Even if ${HOST_SH} is already defined, we still do the
# sanity checks at the end.
# Solaris has /usr/xpg4/bin/sh.
#
[ -z "${HOST_SH}" ] && [ x"${uname_s}" = x"SunOS" ] && \
[ -x /usr/xpg4/bin/sh ] && HOST_SH="/usr/xpg4/bin/sh"
# Try to get the name of the shell that's running this script,
# by parsing the output from "ps". We assume that, if the host
# system's ps command supports -o comm at all, it will do so
# in the usual way: a one-line header followed by a one-line
# result, possibly including trailing white space. And if the
# host system's ps command doesn't support -o comm, we assume
# that we'll get an error message on stderr and nothing on
# stdout. (We don't try to use ps -o 'comm=' to suppress the
# header line, because that is less widely supported.)
#
# If we get the wrong result here, the user can override it by
# specifying HOST_SH in the environment.
#
[ -z "${HOST_SH}" ] && HOST_SH="$(
(ps -p $$ -o comm | sed -ne "2s/[ ${tab}]*\$//p") 2>/dev/null )"
# If nothing above worked, use "sh". We will later find the
# first directory in the PATH that has a "sh" program.
#
[ -z "${HOST_SH}" ] && HOST_SH="sh"
# If the result so far is not an absolute path, try to prepend
# PWD or search the PATH.
#
case "${HOST_SH}" in
/*) :
;;
*/*) HOST_SH="${PWD}/${HOST_SH}"
;;
*) HOST_SH="$(find_in_PATH "${HOST_SH}")"
;;
esac
# If we don't have an absolute path by now, bomb.
#
case "${HOST_SH}" in
/*) :
;;
*) bomb "HOST_SH=\"${HOST_SH}\" is not an absolute path."
;;
esac
# If HOST_SH is not executable, bomb.
#
[ -x "${HOST_SH}" ] ||
bomb "HOST_SH=\"${HOST_SH}\" is not executable."
# If HOST_SH fails tests, bomb.
# ("$0" may be a path that is no longer valid, because we have
# performed "cd $(dirname $0)", so don't use $0 here.)
#
"${HOST_SH}" build.sh --shelltest ||
bomb "HOST_SH=\"${HOST_SH}\" failed functionality tests."
}
# initdefaults --
# Set defaults before parsing command line options.
#
initdefaults()
{
makeenv=
makewrapper=
makewrappermachine=
runcmd=
operations=
removedirs=
[ -d usr.bin/make ] || cd "$(dirname $0)"
[ -d usr.bin/make ] ||
bomb "build.sh must be run from the top source level"
[ -f share/mk/bsd.own.mk ] ||
bomb "src/share/mk is missing; please re-fetch the source tree"
# Set various environment variables to known defaults,
# to minimize (cross-)build problems observed "in the field".
#
# LC_ALL=C must be set before we try to parse the output from
# any command. Other variables are set (or unset) here, before
# we parse command line arguments.
#
# These variables can be overridden via "-V var=value" if
# you know what you are doing.
#
unsetmakeenv INFODIR
unsetmakeenv LESSCHARSET
unsetmakeenv MAKEFLAGS
unsetmakeenv TERMINFO
setmakeenv LC_ALL C
# Find information about the build platform. This should be
# kept in sync with _HOST_OSNAME, _HOST_OSREL, and _HOST_ARCH
# variables in share/mk/bsd.sys.mk.
#
# Note that "uname -p" is not part of POSIX, but we want uname_p
# to be set to the host MACHINE_ARCH, if possible. On systems
# where "uname -p" fails, prints "unknown", or prints a string
# that does not look like an identifier, fall back to using the
# output from "uname -m" instead.
#
uname_s=$(uname -s 2>/dev/null)
uname_r=$(uname -r 2>/dev/null)
uname_m=$(uname -m 2>/dev/null)
uname_p=$(uname -p 2>/dev/null || echo "unknown")
case "${uname_p}" in
''|unknown|*[^-_A-Za-z0-9]*) uname_p="${uname_m}" ;;
esac
id_u=$(id -u 2>/dev/null || /usr/xpg4/bin/id -u 2>/dev/null)
# If $PWD is a valid name of the current directory, POSIX mandates
# that pwd return it by default which causes problems in the
# presence of symlinks. Unsetting PWD is simpler than changing
# every occurrence of pwd to use -P.
#
# XXX Except that doesn't work on Solaris. Or many Linuces.
#
unset PWD
TOP=$(/bin/pwd -P 2>/dev/null || /bin/pwd 2>/dev/null)
# The user can set HOST_SH in the environment, or we try to
# guess an appropriate value. Then we set several other
# variables from HOST_SH.
#
set_HOST_SH
setmakeenv HOST_SH "${HOST_SH}"
setmakeenv BSHELL "${HOST_SH}"
setmakeenv CONFIG_SHELL "${HOST_SH}"
# Set defaults.
#
toolprefix=nb
# Some systems have a small ARG_MAX. -X prevents make(1) from
# exporting variables in the environment redundantly.
#
case "${uname_s}" in
Darwin | FreeBSD | CYGWIN*)
MAKEFLAGS="-X ${MAKEFLAGS}"
;;
esac
# do_{operation}=true if given operation is requested.
#
do_expertmode=false
do_rebuildmake=false
do_removedirs=false
do_tools=false
do_cleandir=false
do_obj=false
do_build=false
do_distribution=false
do_release=false
do_kernel=false
do_releasekernel=false
do_kernels=false
do_modules=false
do_installmodules=false
do_install=false
do_sets=false
do_sourcesets=false
do_syspkgs=false
do_iso_image=false
do_iso_image_source=false
do_live_image=false
do_install_image=false
do_disk_image=false
do_params=false
do_rump=false
# done_{operation}=true if given operation has been done.
#
done_rebuildmake=false
# Create scratch directory
#
tmpdir="${TMPDIR-/tmp}/nbbuild$$"
mkdir "${tmpdir}" || bomb "Cannot mkdir: ${tmpdir}"
trap "cd /; rm -r -f \"${tmpdir}\"" 0
results="${tmpdir}/build.sh.results"
# Set source directories
#
setmakeenv NETBSDSRCDIR "${TOP}"
# Make sure KERNOBJDIR is an absolute path if defined
#
case "${KERNOBJDIR}" in
''|/*) ;;
*) KERNOBJDIR="${TOP}/${KERNOBJDIR}"
setmakeenv KERNOBJDIR "${KERNOBJDIR}"
;;
esac
# Find the version of NetBSD
#
DISTRIBVER="$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh)"
# Set the BUILDSEED to NetBSD-"N"
#
setmakeenv BUILDSEED "NetBSD-$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh -m)"
# Set MKARZERO to "yes"
#
setmakeenv MKARZERO "yes"
}
# valid_MACHINE_ARCH -- A multi-line string, listing all valid
# MACHINE/MACHINE_ARCH pairs.
#
# Each line contains a MACHINE and MACHINE_ARCH value, an optional ALIAS
# which may be used to refer to the MACHINE/MACHINE_ARCH pair, and an
# optional DEFAULT or NO_DEFAULT keyword.
#
# When a MACHINE corresponds to multiple possible values of
# MACHINE_ARCH, then this table should list all allowed combinations.
# If the MACHINE is associated with a default MACHINE_ARCH (to be
# used when the user specifies the MACHINE but fails to specify the
# MACHINE_ARCH), then one of the lines should have the "DEFAULT"
# keyword. If there is no default MACHINE_ARCH for a particular
# MACHINE, then there should be a line with the "NO_DEFAULT" keyword,
# and with a blank MACHINE_ARCH.
#
valid_MACHINE_ARCH='
MACHINE=acorn26 MACHINE_ARCH=arm
MACHINE=acorn32 MACHINE_ARCH=arm
MACHINE=algor MACHINE_ARCH=mips64el ALIAS=algor64
MACHINE=algor MACHINE_ARCH=mipsel DEFAULT
MACHINE=alpha MACHINE_ARCH=alpha
MACHINE=amd64 MACHINE_ARCH=x86_64
MACHINE=amiga MACHINE_ARCH=m68k
MACHINE=amigappc MACHINE_ARCH=powerpc
MACHINE=arc MACHINE_ARCH=mips64el ALIAS=arc64
MACHINE=arc MACHINE_ARCH=mipsel DEFAULT
MACHINE=atari MACHINE_ARCH=m68k
MACHINE=bebox MACHINE_ARCH=powerpc
MACHINE=cats MACHINE_ARCH=arm ALIAS=ocats
MACHINE=cats MACHINE_ARCH=earmv4 ALIAS=ecats DEFAULT
MACHINE=cesfic MACHINE_ARCH=m68k
MACHINE=cobalt MACHINE_ARCH=mips64el ALIAS=cobalt64
MACHINE=cobalt MACHINE_ARCH=mipsel DEFAULT
MACHINE=dreamcast MACHINE_ARCH=sh3el
MACHINE=emips MACHINE_ARCH=mipseb
MACHINE=epoc32 MACHINE_ARCH=arm
MACHINE=evbarm MACHINE_ARCH=arm ALIAS=evboarm-el
MACHINE=evbarm MACHINE_ARCH=armeb ALIAS=evboarm-eb
MACHINE=evbarm MACHINE_ARCH=earm ALIAS=evbearm-el DEFAULT
MACHINE=evbarm MACHINE_ARCH=earmeb ALIAS=evbearm-eb
MACHINE=evbarm MACHINE_ARCH=earmhf ALIAS=evbearmhf-el
MACHINE=evbarm MACHINE_ARCH=earmhfeb ALIAS=evbearmhf-eb
MACHINE=evbarm MACHINE_ARCH=earmv4 ALIAS=evbearmv4-el
MACHINE=evbarm MACHINE_ARCH=earmv4eb ALIAS=evbearmv4-eb
MACHINE=evbarm MACHINE_ARCH=earmv5 ALIAS=evbearmv5-el
MACHINE=evbarm MACHINE_ARCH=earmv5eb ALIAS=evbearmv5-eb
MACHINE=evbarm MACHINE_ARCH=earmv6 ALIAS=evbearmv6-el
MACHINE=evbarm MACHINE_ARCH=earmv6hf ALIAS=evbearmv6hf-el
MACHINE=evbarm MACHINE_ARCH=earmv6eb ALIAS=evbearmv6-eb
MACHINE=evbarm MACHINE_ARCH=earmv6hfeb ALIAS=evbearmv6hf-eb
MACHINE=evbarm MACHINE_ARCH=earmv7 ALIAS=evbearmv7-el
MACHINE=evbarm MACHINE_ARCH=earmv7eb ALIAS=evbearmv7-eb
MACHINE=evbarm MACHINE_ARCH=earmv7hf ALIAS=evbearmv7hf-el
MACHINE=evbarm MACHINE_ARCH=earmv7hfeb ALIAS=evbearmv7hf-eb
MACHINE=evbarm64 MACHINE_ARCH=aarch64 ALIAS=evbarm64-el
MACHINE=evbarm64 MACHINE_ARCH=aarch64eb ALIAS=evbarm64-eb
MACHINE=evbcf MACHINE_ARCH=coldfire
MACHINE=evbmips MACHINE_ARCH= NO_DEFAULT
MACHINE=evbmips MACHINE_ARCH=mips64eb ALIAS=evbmips64-eb
MACHINE=evbmips MACHINE_ARCH=mips64el ALIAS=evbmips64-el
MACHINE=evbmips MACHINE_ARCH=mipseb ALIAS=evbmips-eb
MACHINE=evbmips MACHINE_ARCH=mipsel ALIAS=evbmips-el
MACHINE=evbppc MACHINE_ARCH=powerpc DEFAULT
MACHINE=evbppc MACHINE_ARCH=powerpc64 ALIAS=evbppc64
MACHINE=evbsh3 MACHINE_ARCH= NO_DEFAULT
MACHINE=evbsh3 MACHINE_ARCH=sh3eb ALIAS=evbsh3-eb
MACHINE=evbsh3 MACHINE_ARCH=sh3el ALIAS=evbsh3-el
MACHINE=ews4800mips MACHINE_ARCH=mipseb
MACHINE=hp300 MACHINE_ARCH=m68k
MACHINE=hppa MACHINE_ARCH=hppa
MACHINE=hpcarm MACHINE_ARCH=arm ALIAS=hpcoarm
MACHINE=hpcarm MACHINE_ARCH=earmv4 ALIAS=hpcearm DEFAULT
MACHINE=hpcmips MACHINE_ARCH=mipsel
MACHINE=hpcsh MACHINE_ARCH=sh3el
MACHINE=i386 MACHINE_ARCH=i386
MACHINE=ia64 MACHINE_ARCH=ia64
MACHINE=ibmnws MACHINE_ARCH=powerpc
MACHINE=iyonix MACHINE_ARCH=arm ALIAS=oiyonix
MACHINE=iyonix MACHINE_ARCH=earm ALIAS=eiyonix DEFAULT
MACHINE=landisk MACHINE_ARCH=sh3el
MACHINE=luna68k MACHINE_ARCH=m68k
MACHINE=mac68k MACHINE_ARCH=m68k
MACHINE=macppc MACHINE_ARCH=powerpc DEFAULT
MACHINE=macppc MACHINE_ARCH=powerpc64 ALIAS=macppc64
MACHINE=mipsco MACHINE_ARCH=mipseb
MACHINE=mmeye MACHINE_ARCH=sh3eb
MACHINE=mvme68k MACHINE_ARCH=m68k
MACHINE=mvmeppc MACHINE_ARCH=powerpc
MACHINE=netwinder MACHINE_ARCH=arm ALIAS=onetwinder
MACHINE=netwinder MACHINE_ARCH=earmv4 ALIAS=enetwinder DEFAULT
MACHINE=news68k MACHINE_ARCH=m68k
MACHINE=newsmips MACHINE_ARCH=mipseb
MACHINE=next68k MACHINE_ARCH=m68k
MACHINE=ofppc MACHINE_ARCH=powerpc DEFAULT
MACHINE=ofppc MACHINE_ARCH=powerpc64 ALIAS=ofppc64
MACHINE=or1k MACHINE_ARCH=or1k
MACHINE=playstation2 MACHINE_ARCH=mipsel
MACHINE=pmax MACHINE_ARCH=mips64el ALIAS=pmax64
MACHINE=pmax MACHINE_ARCH=mipsel DEFAULT
MACHINE=prep MACHINE_ARCH=powerpc
MACHINE=riscv MACHINE_ARCH=riscv64 ALIAS=riscv64 DEFAULT
MACHINE=riscv MACHINE_ARCH=riscv32 ALIAS=riscv32
MACHINE=rs6000 MACHINE_ARCH=powerpc
MACHINE=sandpoint MACHINE_ARCH=powerpc
MACHINE=sbmips MACHINE_ARCH= NO_DEFAULT
MACHINE=sbmips MACHINE_ARCH=mips64eb ALIAS=sbmips64-eb
MACHINE=sbmips MACHINE_ARCH=mips64el ALIAS=sbmips64-el
MACHINE=sbmips MACHINE_ARCH=mipseb ALIAS=sbmips-eb
MACHINE=sbmips MACHINE_ARCH=mipsel ALIAS=sbmips-el
MACHINE=sgimips MACHINE_ARCH=mips64eb ALIAS=sgimips64
MACHINE=sgimips MACHINE_ARCH=mipseb DEFAULT
MACHINE=shark MACHINE_ARCH=arm ALIAS=oshark
MACHINE=shark MACHINE_ARCH=earmv4 ALIAS=eshark DEFAULT
MACHINE=sparc MACHINE_ARCH=sparc
MACHINE=sparc64 MACHINE_ARCH=sparc64
MACHINE=sun2 MACHINE_ARCH=m68000
MACHINE=sun3 MACHINE_ARCH=m68k
MACHINE=vax MACHINE_ARCH=vax
MACHINE=x68k MACHINE_ARCH=m68k
MACHINE=zaurus MACHINE_ARCH=arm ALIAS=ozaurus
MACHINE=zaurus MACHINE_ARCH=earm ALIAS=ezaurus DEFAULT
'
# getarch -- find the default MACHINE_ARCH for a MACHINE,
# or convert an alias to a MACHINE/MACHINE_ARCH pair.
#
# Saves the original value of MACHINE in makewrappermachine before
# alias processing.
#
# Sets MACHINE and MACHINE_ARCH if the input MACHINE value is
# recognised as an alias, or recognised as a machine that has a default
# MACHINE_ARCH (or that has only one possible MACHINE_ARCH).
#
# Leaves MACHINE and MACHINE_ARCH unchanged if MACHINE is recognised
# as being associated with multiple MACHINE_ARCH values with no default.
#
# Bombs if MACHINE is not recognised.
#
getarch()
{
local IFS
local found=""
local line
IFS="${nl}"
makewrappermachine="${MACHINE}"
for line in ${valid_MACHINE_ARCH}; do
line="${line%%#*}" # ignore comments
line="$( IFS=" ${tab}" ; echo $line )" # normalise white space
case "${line} " in
" ")
# skip blank lines or comment lines
continue
;;
*" ALIAS=${MACHINE} "*)
# Found a line with a matching ALIAS=<alias>.
found="$line"
break
;;
"MACHINE=${MACHINE} "*" NO_DEFAULT"*)
# Found an explicit "NO_DEFAULT" for this MACHINE.
found="$line"
break
;;
"MACHINE=${MACHINE} "*" DEFAULT"*)
# Found an explicit "DEFAULT" for this MACHINE.
found="$line"
break
;;
"MACHINE=${MACHINE} "*)
# Found a line for this MACHINE. If it's the
# first such line, then tentatively accept it.
# If it's not the first matching line, then
# remember that there was more than one match.
case "$found" in
'') found="$line" ;;
*) found="MULTIPLE_MATCHES" ;;
esac
;;
esac
done
case "$found" in
*NO_DEFAULT*|*MULTIPLE_MATCHES*)
# MACHINE is OK, but MACHINE_ARCH is still unknown
return
;;
"MACHINE="*" MACHINE_ARCH="*)
# Obey the MACHINE= and MACHINE_ARCH= parts of the line.
IFS=" "
for frag in ${found}; do
case "$frag" in
MACHINE=*|MACHINE_ARCH=*)
eval "$frag"
;;
esac
done
;;
*)
bomb "Unknown target MACHINE: ${MACHINE}"
;;
esac
}
# validatearch -- check that the MACHINE/MACHINE_ARCH pair is supported.
#
# Bombs if the pair is not supported.
#
validatearch()
{
local IFS
local line
local foundpair=false foundmachine=false foundarch=false
case "${MACHINE_ARCH}" in
"")
bomb "No MACHINE_ARCH provided"
;;
esac
IFS="${nl}"
for line in ${valid_MACHINE_ARCH}; do
line="${line%%#*}" # ignore comments
line="$( IFS=" ${tab}" ; echo $line )" # normalise white space
case "${line} " in
" ")
# skip blank lines or comment lines
continue
;;
"MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH} "*)
foundpair=true
;;
"MACHINE=${MACHINE} "*)
foundmachine=true
;;
*"MACHINE_ARCH=${MACHINE_ARCH} "*)
foundarch=true
;;
esac
done
case "${foundpair}:${foundmachine}:${foundarch}" in
true:*)
: OK
;;
*:false:*)
bomb "Unknown target MACHINE: ${MACHINE}"
;;
*:*:false)
bomb "Unknown target MACHINE_ARCH: ${MACHINE_ARCH}"
;;
*)
bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'"
;;
esac
}
# listarch -- list valid MACHINE/MACHINE_ARCH/ALIAS values,
# optionally restricted to those where the MACHINE and/or MACHINE_ARCH
# match specifed glob patterns.
#
listarch()
{
local machglob="$1" archglob="$2"
local IFS
local wildcard="*"
local line xline frag
local line_matches_machine line_matches_arch
local found=false
# Empty machglob or archglob should match anything
: "${machglob:=${wildcard}}"
: "${archglob:=${wildcard}}"
IFS="${nl}"
for line in ${valid_MACHINE_ARCH}; do
line="${line%%#*}" # ignore comments
xline="$( IFS=" ${tab}" ; echo $line )" # normalise white space
[ -z "${xline}" ] && continue # skip blank or comment lines
line_matches_machine=false
line_matches_arch=false
IFS=" "
for frag in ${xline}; do
case "${frag}" in
MACHINE=${machglob})
line_matches_machine=true ;;
ALIAS=${machglob})
line_matches_machine=true ;;
MACHINE_ARCH=${archglob})
line_matches_arch=true ;;
esac
done
if $line_matches_machine && $line_matches_arch; then
found=true
echo "$line"
fi
done
if ! $found; then
echo >&2 "No match for" \
"MACHINE=${machglob} MACHINE_ARCH=${archglob}"
return 1
fi
return 0
}
# nobomb_getmakevar --
# Given the name of a make variable in $1, print make's idea of the
# value of that variable, or return 1 if there's an error.
#
nobomb_getmakevar()
{
[ -x "${make}" ] || return 1
"${make}" -m ${TOP}/share/mk -s -B -f- _x_ <<EOF || return 1
_x_:
echo \${$1}
.include <bsd.prog.mk>
.include <bsd.kernobj.mk>
EOF
}
# bomb_getmakevar --
# Given the name of a make variable in $1, print make's idea of the
# value of that variable, or bomb if there's an error.
#
bomb_getmakevar()
{
[ -x "${make}" ] || bomb "bomb_getmakevar $1: ${make} is not executable"
nobomb_getmakevar "$1" || bomb "bomb_getmakevar $1: ${make} failed"
}
# getmakevar --
# Given the name of a make variable in $1, print make's idea of the
# value of that variable, or print a literal '$' followed by the
# variable name if ${make} is not executable. This is intended for use in
# messages that need to be readable even if $make hasn't been built,
# such as when build.sh is run with the "-n" option.
#
getmakevar()
{
if [ -x "${make}" ]; then
bomb_getmakevar "$1"
else
echo "\$$1"
fi
}
setmakeenv()
{
eval "$1='$2'; export $1"
makeenv="${makeenv} $1"
}
unsetmakeenv()
{
eval "unset $1"
makeenv="${makeenv} $1"
}
# Given a variable name in $1, modify the variable in place as follows:
# For each space-separated word in the variable, call resolvepath.
resolvepaths()
{
local var="$1"
local val
eval val=\"\${${var}}\"
local newval=''
local word
for word in ${val}; do
resolvepath word
newval="${newval}${newval:+ }${word}"
done
eval ${var}=\"\${newval}\"
}
# Given a variable name in $1, modify the variable in place as follows:
# Convert possibly-relative path to absolute path by prepending
# ${TOP} if necessary. Also delete trailing "/", if any.
resolvepath()
{
local var="$1"
local val
eval val=\"\${${var}}\"
case "${val}" in
/)
;;
/*)
val="${val%/}"
;;
*)
val="${TOP}/${val%/}"
;;
esac
eval ${var}=\"\${val}\"
}
usage()
{
if [ -n "$*" ]; then