-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·1416 lines (1243 loc) · 36.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.197 2008/08/22 23:41:24 lukem Exp $
#
# Copyright (c) 2001-2008 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, for a system containing no tools.
#
# This script should run on any POSIX-compliant shell. If the
# first "sh" found in the PATH is a POSIX-compliant shell, then
# you should not need to take any special action. Otherwise, you
# should set the environment variable HOST_SH to a POSIX-compliant
# shell, and invoke build.sh with that shell. (Depending on your
# system, one of /bin/ksh, /usr/local/bin/bash, or /usr/xpg4/bin/sh
# might be a suitable shell.)
#
progname=${0##*/}
toppid=$$
results=/dev/null
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
}
statusmsg()
{
${runcmd} echo "===> $@" | tee -a "${results}"
}
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/[ \t]*$//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."
}
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"
# Find information about the build platform. Note that "uname -p"
# is not part of POSIX, but NetBSD's uname -p prints MACHINE_ARCH,
# while uname -m prints MACHINE.
#
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 || uname -m 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_install=false
do_sets=false
do_sourcesets=false
do_syspkgs=false
do_iso_image=false
do_iso_image_source=false
do_params=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}"
# Determine top-level obj directory.
# Defaults to the top-level source directory.
# If $MAKEOBJDIRPREFIX is set in the environment, use it.
# We can't check $MAKEOBJDIR since that may be a make(1)
# expression that we can't evaluate at this time.
#
TOP_objdir="${TOP}"
if [ -n "${MAKEOBJDIRPREFIX}" ]; then
TOP_objdir="${MAKEOBJDIRPREFIX}${TOP}"
elif [ -n "${MAKEOBJDIR}" ]; then
warning "Can't parse \$(MAKEOBJDIR) \"$MAKEOBJDIR\" to determine top objdir"
fi
# 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 various environment variables to known defaults,
# to minimize (cross-)build problems observed "in the field".
#
unsetmakeenv INFODIR
unsetmakeenv LESSCHARSET
setmakeenv LC_ALL C
}
getarch()
{
# Translate some MACHINE name aliases (known only to build.sh)
# into proper MACHINE and MACHINE_ARCH names. Save the alias
# name in makewrappermachine.
#
case "${MACHINE}" in
evbarm-e[bl])
makewrappermachine=${MACHINE}
# MACHINE_ARCH is "arm" or "armeb", not "armel"
MACHINE_ARCH=arm${MACHINE##*-}
MACHINE_ARCH=${MACHINE_ARCH%el}
MACHINE=${MACHINE%-e[bl]}
;;
evbmips-e[bl]|sbmips-e[bl])
makewrappermachine=${MACHINE}
MACHINE_ARCH=mips${MACHINE##*-}
MACHINE=${MACHINE%-e[bl]}
;;
evbmips64-e[bl]|sbmips64-e[bl])
makewrappermachine=${MACHINE}
MACHINE_ARCH=mips64${MACHINE##*-}
MACHINE=${MACHINE%64-e[bl]}
;;
evbsh3-e[bl])
makewrappermachine=${MACHINE}
MACHINE_ARCH=sh3${MACHINE##*-}
MACHINE=${MACHINE%-e[bl]}
;;
esac
# Translate a MACHINE into a default MACHINE_ARCH.
#
case "${MACHINE}" in
acorn26|acorn32|cats|hpcarm|iyonix|netwinder|shark|zaurus)
MACHINE_ARCH=arm
;;
evbarm) # unspecified MACHINE_ARCH gets LE
MACHINE_ARCH=${MACHINE_ARCH:=arm}
;;
hp700)
MACHINE_ARCH=hppa
;;
sun2)
MACHINE_ARCH=m68000
;;
amiga|atari|cesfic|hp300|luna68k|mac68k|mvme68k|news68k|next68k|sun3|x68k)
MACHINE_ARCH=m68k
;;
evbmips|sbmips) # no default MACHINE_ARCH
;;
ews4800mips|mipsco|newsmips|sgimips)
MACHINE_ARCH=mipseb
;;
algor|arc|cobalt|hpcmips|playstation2|pmax)
MACHINE_ARCH=mipsel
;;
evbppc64|macppc64|ofppc64)
makewrappermachine=${MACHINE}
MACHINE=${MACHINE%64}
MACHINE_ARCH=powerpc64
;;
amigappc|bebox|evbppc|ibmnws|macppc|mvmeppc|ofppc|prep|rs6000|sandpoint)
MACHINE_ARCH=powerpc
;;
evbsh3) # no default MACHINE_ARCH
;;
mmeye)
MACHINE_ARCH=sh3eb
;;
dreamcast|hpcsh|landisk)
MACHINE_ARCH=sh3el
;;
amd64)
MACHINE_ARCH=x86_64
;;
alpha|i386|sparc|sparc64|vax|ia64)
MACHINE_ARCH=${MACHINE}
;;
*)
bomb "Unknown target MACHINE: ${MACHINE}"
;;
esac
}
validatearch()
{
# Ensure that the MACHINE_ARCH exists (and is supported by build.sh).
#
case "${MACHINE_ARCH}" in
alpha|arm|armeb|hppa|i386|m68000|m68k|mipse[bl]|mips64e[bl]|powerpc|powerpc64|sh3e[bl]|sparc|sparc64|vax|x86_64|ia64)
;;
"")
bomb "No MACHINE_ARCH provided"
;;
*)
bomb "Unknown target MACHINE_ARCH: ${MACHINE_ARCH}"
;;
esac
# Determine valid MACHINE_ARCHs for MACHINE
#
case "${MACHINE}" in
evbarm)
arches="arm armeb"
;;
evbmips|sbmips)
arches="mipseb mipsel mips64eb mips64el"
;;
sgimips)
arches="mipseb mips64eb"
;;
evbsh3)
arches="sh3eb sh3el"
;;
macppc|evbppc|ofppc)
arches="powerpc powerpc64"
;;
*)
oma="${MACHINE_ARCH}"
getarch
arches="${MACHINE_ARCH}"
MACHINE_ARCH="${oma}"
;;
esac
# Ensure that MACHINE_ARCH supports MACHINE
#
archok=false
for a in ${arches}; do
if [ "${a}" = "${MACHINE_ARCH}" ]; then
archok=true
break
fi
done
${archok} ||
bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'"
}
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
}
raw_getmakevar()
{
[ -x "${make}" ] || bomb "raw_getmakevar $1: ${make} is not executable"
nobomb_getmakevar "$1" || bomb "raw_getmakevar $1: ${make} failed"
}
getmakevar()
{
# raw_getmakevar() doesn't work properly if $make hasn't yet been
# built, which can happen when running with the "-n" option.
# getmakevar() deals with this by emitting a literal '$'
# followed by the variable name, instead of trying to find the
# variable's value.
#
if [ -x "${make}" ]; then
raw_getmakevar "$1"
else
echo "\$$1"
fi
}
setmakeenv()
{
eval "$1='$2'; export $1"
makeenv="${makeenv} $1"
}
unsetmakeenv()
{
eval "unset $1"
makeenv="${makeenv} $1"
}
# Convert possibly-relative paths to absolute paths by prepending
# ${TOP} if necessary. Also delete trailing "/", if any.
resolvepaths()
{
_OPTARG=
for oa in ${OPTARG}; do
case "${oa}" in
/)
;;
/*)
oa="${oa%/}"
;;
*)
oa="${TOP}/${oa%/}"
;;
esac
_OPTARG="${_OPTARG} ${oa}"
done
OPTARG="${_OPTARG}"
}
# Convert possibly-relative path to absolute path by prepending
# ${TOP} if necessary. Also delete trailing "/", if any.
resolvepath()
{
case "${OPTARG}" in
/)
;;
/*)
OPTARG="${OPTARG%/}"
;;
*)
OPTARG="${TOP}/${OPTARG%/}"
;;
esac
}
usage()
{
if [ -n "$*" ]; then
echo ""
echo "${progname}: $*"
fi
cat <<_usage_
Usage: ${progname} [-EnorUux] [-a arch] [-B buildid] [-C cdextras]
[-D dest] [-j njob] [-M obj] [-m mach] [-N noisy]
[-O obj] [-R release] [-S seed] [-T tools]
[-V var=[value]] [-w wrapper] [-X x11src] [-Z var]
operation [...]
Build operations (all imply "obj" and "tools"):
build Run "make build".
distribution Run "make distribution" (includes DESTDIR/etc/ files).
release Run "make release" (includes kernels & distrib media).
Other operations:
help Show this message and exit.
makewrapper Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make.
Always performed.
cleandir Run "make cleandir". [Default unless -u is used]
obj Run "make obj". [Default unless -o is used]
tools Build and install tools.
install=idir Run "make installworld" to \`idir' to install all sets
except \`etc'. Useful after "distribution" or "release"
kernel=conf Build kernel with config file \`conf'
releasekernel=conf Install kernel built by kernel=conf to RELEASEDIR.
sets Create binary sets in
RELEASEDIR/RELEASEMACHINEDIR/binary/sets.
DESTDIR should be populated beforehand.
sourcesets Create source sets in RELEASEDIR/source/sets.
syspkgs Create syspkgs in
RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.
iso-image Create CD-ROM image in RELEASEDIR/iso.
iso-image-source Create CD-ROM image with source in RELEASEDIR/iso.
params Display various make(1) parameters.
Options:
-a arch Set MACHINE_ARCH to arch. [Default: deduced from MACHINE]
-B buildId Set BUILDID to buildId.
-C cdextras Set CDEXTRA to cdextras
-D dest Set DESTDIR to dest. [Default: destdir.MACHINE]
-E Set "expert" mode; disables various safety checks.
Should not be used without expert knowledge of the build system.
-h Print this help message.
-j njob Run up to njob jobs in parallel; see make(1) -j.
-M obj Set obj root directory to obj; sets MAKEOBJDIRPREFIX.
Unsets MAKEOBJDIR.
-m mach Set MACHINE to mach; not required if NetBSD native.
-N noisy Set the noisyness (MAKEVERBOSE) level of the build:
0 Quiet
1 Operations are described, commands are suppressed
2 Full output
[Default: 2]
-n Show commands that would be executed, but do not execute them.
-O obj Set obj root directory to obj; sets a MAKEOBJDIR pattern.
Unsets MAKEOBJDIRPREFIX.
-o Set MKOBJDIRS=no; do not create objdirs at start of build.
-R release Set RELEASEDIR to release. [Default: releasedir]
-r Remove contents of TOOLDIR and DESTDIR before building.
-S seed Set BUILDSEED to seed. [Default: NetBSD-majorversion]
-T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in
the environment, ${toolprefix}make will be (re)built unconditionally.
-U Set MKUNPRIVED=yes; build without requiring root privileges,
install from an UNPRIVED build with proper file permissions.
-u Set MKUPDATE=yes; do not run "make cleandir" first.
Without this, everything is rebuilt, including the tools.
-V v=[val] Set variable \`v' to \`val'.
-w wrapper Create ${toolprefix}make script as wrapper.
[Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE}]
-X x11src Set X11SRCDIR to x11src. [Default: /usr/xsrc]
-x Set MKX11=yes; build X11R6 from X11SRCDIR
-Z v Unset ("zap") variable \`v'.
_usage_
exit 1
}
parseoptions()
{
opts='a:B:C:D:Ehj:M:m:N:nO:oR:rS:T:UuV:w:xX:Z:'
opt_a=no
if type getopts >/dev/null 2>&1; then
# Use POSIX getopts.
#
getoptcmd='getopts ${opts} opt && opt=-${opt}'
optargcmd=':'
optremcmd='shift $((${OPTIND} -1))'
else
type getopt >/dev/null 2>&1 ||
bomb "/bin/sh shell is too old; try ksh or bash"
# Use old-style getopt(1) (doesn't handle whitespace in args).
#
args="$(getopt ${opts} $*)"
[ $? = 0 ] || usage
set -- ${args}
getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
optargcmd='OPTARG="$1"; shift'
optremcmd=':'
fi
# Parse command line options.
#
while eval ${getoptcmd}; do
case ${opt} in
-a)
eval ${optargcmd}
MACHINE_ARCH=${OPTARG}
opt_a=yes
;;
-B)
eval ${optargcmd}
BUILDID=${OPTARG}
;;
-C)
eval ${optargcmd}; resolvepaths
iso_dir=${OPTARG}
;;
-D)
eval ${optargcmd}; resolvepath
setmakeenv DESTDIR "${OPTARG}"
;;
-E)
do_expertmode=true
;;
-j)
eval ${optargcmd}
parallel="-j ${OPTARG}"
;;
-M)
eval ${optargcmd}; resolvepath
TOP_objdir="${OPTARG}${TOP}"
unsetmakeenv MAKEOBJDIR
setmakeenv MAKEOBJDIRPREFIX "${OPTARG}"
;;
# -m overrides MACHINE_ARCH unless "-a" is specified
-m)
eval ${optargcmd}
MACHINE="${OPTARG}"
[ "${opt_a}" != "yes" ] && getarch
;;
-N)
eval ${optargcmd}
case "${OPTARG}" in
0|1|2)
setmakeenv MAKEVERBOSE "${OPTARG}"
;;
*)
usage "'${OPTARG}' is not a valid value for -N"
;;
esac
;;
-n)
runcmd=echo
;;
-O)
eval ${optargcmd}; resolvepath
TOP_objdir="${OPTARG}"
unsetmakeenv MAKEOBJDIRPREFIX
setmakeenv MAKEOBJDIR "\${.CURDIR:C,^$TOP,$OPTARG,}"
;;
-o)
MKOBJDIRS=no
;;
-R)
eval ${optargcmd}; resolvepath
setmakeenv RELEASEDIR "${OPTARG}"
;;
-r)
do_removedirs=true
do_rebuildmake=true
;;
-S)
eval ${optargcmd}
setmakeenv BUILDSEED "${OPTARG}"
;;
-T)
eval ${optargcmd}; resolvepath
TOOLDIR="${OPTARG}"
export TOOLDIR
;;
-U)
setmakeenv MKUNPRIVED yes
;;
-u)
setmakeenv MKUPDATE yes
;;
-V)
eval ${optargcmd}
case "${OPTARG}" in
# XXX: consider restricting which variables can be changed?
[a-zA-Z_][a-zA-Z_0-9]*=*)
setmakeenv "${OPTARG%%=*}" "${OPTARG#*=}"
;;
*)
usage "-V argument must be of the form 'var=[value]'"
;;
esac
;;
-w)
eval ${optargcmd}; resolvepath
makewrapper="${OPTARG}"
;;
-X)
eval ${optargcmd}; resolvepath
setmakeenv X11SRCDIR "${OPTARG}"
;;
-x)
setmakeenv MKX11 yes
;;
-Z)
eval ${optargcmd}
# XXX: consider restricting which variables can be unset?
unsetmakeenv "${OPTARG}"
;;
--)
break
;;
-'?'|-h)
usage
;;
esac
done
# Validate operations.
#
eval ${optremcmd}
while [ $# -gt 0 ]; do
op=$1; shift
operations="${operations} ${op}"
case "${op}" in
help)
usage
;;
makewrapper|cleandir|obj|tools|build|distribution|release|sets|sourcesets|syspkgs|params)
;;
iso-image)
op=iso_image # used as part of a variable name
;;
iso-image-source)
op=iso_image_source # used as part of a variable name
;;
kernel=*|releasekernel=*)
arg=${op#*=}
op=${op%%=*}
[ -n "${arg}" ] ||
bomb "Must supply a kernel name with \`${op}=...'"
;;
install=*)
arg=${op#*=}
op=${op%%=*}
[ -n "${arg}" ] ||
bomb "Must supply a directory with \`install=...'"
;;
*)
usage "Unknown operation \`${op}'"
;;
esac
eval do_${op}=true
done
[ -n "${operations}" ] || usage "Missing operation to perform."
# Set up MACHINE*. On a NetBSD host, these are allowed to be unset.
#
if [ -z "${MACHINE}" ]; then
[ "${uname_s}" = "NetBSD" ] ||
bomb "MACHINE must be set, or -m must be used, for cross builds."
MACHINE=${uname_m}
fi
[ -n "${MACHINE_ARCH}" ] || getarch
validatearch
# Set up default make(1) environment.
#
makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
[ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID"
MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}"
export MAKEFLAGS MACHINE MACHINE_ARCH
}
sanitycheck()
{
# If the PATH contains any non-absolute components (including,
# but not limited to, "." or ""), then complain. As an exception,
# allow "" or "." as the last component of the PATH. This is fatal
# if expert mode is not in effect.
#
local path="${PATH}"
path="${path%:}" # delete trailing ":"
path="${path%:.}" # delete trailing ":."
case ":${path}:/" in
*:[!/]*)
if ${do_expertmode}; then
warning "PATH contains non-absolute components"
else
bomb "PATH environment variable must not" \
"contain non-absolute components"
fi
;;
esac
}
# Try to set a value for TOOLDIR. This is difficult because of a cyclic
# dependency: TOOLDIR may be affected by settings in /etc/mk.conf, so
# we would like to use getmakevar to get the value of TOOLDIR, but we
# can't use getmakevar before we have an up to date version of nbmake;
# we might already have an up to date version of nbmake in TOOLDIR, but
# we don't yet know where TOOLDIR is.
#
# In principle, we could break the cycle by building a copy of nbmake
# in a temporary directory. However, people who use the default value
# of TOOLDIR do not like to have nbmake rebuilt every time they run
# build.sh.
#
# We try to please everybody as follows:
#
# * If TOOLDIR was set in the environment or on the command line, use
# that value.
# * Otherwise try to guess what TOOLDIR would be if not overridden by
# /etc/mk.conf, and check whether the resulting directory contains
# a copy of ${toolprefix}make (this should work for everybody who
# doesn't override TOOLDIR via /etc/mk.conf);
# * Failing that, search for ${toolprefix}make, nbmake, bmake, or make,
# in the PATH (this might accidentally find a non-NetBSD version of
# make, which will lead to failure in the next step);
# * If a copy of make was found above, try to use it with
# nobomb_getmakevar to find the correct value for TOOLDIR;
# * If all else fails, leave TOOLDIR unset. Our caller is expected to
# be able to cope with this.
#
try_set_TOOLDIR()
{
[ -n "${TOOLDIR}" ] && return
# Set guess_TOOLDIR, in the same way that <bsd.own.mk> would set
# TOOLDIR if /etc/mk.conf isn't interfering.
local host_ostype="${uname_s}-$(
echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
)-$(
echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
)"
local guess_TOOLDIR="${TOP_objdir}/tooldir.${host_ostype}"
# Look for a suitable ${toolprefix}make, nbmake, bmake, or make.
guess_make="${guess_TOOLDIR}/bin/${toolprefix}make"
[ -x "${guess_make}" ] || guess_make=""
: ${guess_make:=$(find_in_PATH ${toolprefix}make '')}
: ${guess_make:=$(find_in_PATH nbmake '')}
: ${guess_make:=$(find_in_PATH bmake '')}
: ${guess_make:=$(find_in_PATH make '')}
# Use ${guess_make} with nobomb_getmakevar
if [ -x "${guess_make}" ]; then
TOOLDIR=$(make="${guess_make}" nobomb_getmakevar TOOLDIR)
[ $? -eq 0 -a -n "${TOOLDIR}" ] || unset TOOLDIR
fi
}
rebuildmake()
{
# Test make source file timestamps against installed ${toolprefix}make
# binary, if TOOLDIR is pre-set or if try_set_TOOLDIR can set it.
#
try_set_TOOLDIR
make="${TOOLDIR-nonexistent}/bin/${toolprefix}make"
if [ -x "${make}" ]; then
for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
if [ "${f}" -nt "${make}" ]; then
statusmsg "${make} outdated (older than ${f}), needs building."
do_rebuildmake=true
break
fi
done
else
statusmsg "No ${make}, needs building."
do_rebuildmake=true
fi
# Build bootstrap ${toolprefix}make if needed.
if ${do_rebuildmake}; then
statusmsg "Bootstrapping ${toolprefix}make"
${runcmd} cd "${tmpdir}"
${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
${HOST_SH} "${TOP}/tools/make/configure" ||
bomb "Configure of ${toolprefix}make failed"
${runcmd} ${HOST_SH} buildmake.sh ||
bomb "Build of ${toolprefix}make failed"
make="${tmpdir}/${toolprefix}make"
${runcmd} cd "${TOP}"
${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
fi
}
validatemakeparams()
{
if [ "${runcmd}" = "echo" ]; then
TOOLCHAIN_MISSING=no
EXTERNAL_TOOLCHAIN=""
else
TOOLCHAIN_MISSING=$(raw_getmakevar TOOLCHAIN_MISSING)
EXTERNAL_TOOLCHAIN=$(raw_getmakevar EXTERNAL_TOOLCHAIN)
fi
if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
[ -z "${EXTERNAL_TOOLCHAIN}" ]; then
${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
${runcmd} echo " MACHINE: ${MACHINE}"
${runcmd} echo " MACHINE_ARCH: ${MACHINE_ARCH}"
${runcmd} echo ""
${runcmd} echo "All builds for this platform should be done via a traditional make"
${runcmd} echo "If you wish to use an external cross-toolchain, set"
${runcmd} echo " EXTERNAL_TOOLCHAIN=<path to toolchain root>"
${runcmd} echo "in either the environment or mk.conf and rerun"
${runcmd} echo " ${progname} $*"
exit 1
fi
# Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE
# These may be set as build.sh options or in "mk.conf".
# Don't export them as they're only used for tests in build.sh.
#
MKOBJDIRS=$(getmakevar MKOBJDIRS)
MKUNPRIVED=$(getmakevar MKUNPRIVED)
MKUPDATE=$(getmakevar MKUPDATE)
if [ "${MKOBJDIRS}" != "no" ]; then
# Try to create the top level object directory before
# running "make obj", otherwise <bsd.own.mk> will not
# set the correct value for _SRC_TOP_OBJ_.
#
# If either -M or -O was specified, then we have the
# directory name already.
#
# If neither -M nor -O was specified, then try to get
# the directory name from bsd.obj.mk's __usrobjdir
# variable, which is set using complex rules. This
# works only if TOP = /usr/src.
#