build.sh revision 1.251.2.2 1 #! /usr/bin/env sh
2 # $NetBSD: build.sh,v 1.251.2.2 2012/10/30 18:46:04 yamt Exp $
3 #
4 # Copyright (c) 2001-2011 The NetBSD Foundation, Inc.
5 # All rights reserved.
6 #
7 # This code is derived from software contributed to The NetBSD Foundation
8 # by Todd Vierling and Luke Mewburn.
9 #
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
12 # are met:
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 #
31 #
32 # Top level build wrapper, to build or cross-build NetBSD.
33 #
34
35 #
36 # {{{ Begin shell feature tests.
37 #
38 # We try to determine whether or not this script is being run under
39 # a shell that supports the features that we use. If not, we try to
40 # re-exec the script under another shell. If we can't find another
41 # suitable shell, then we print a message and exit.
42 #
43
44 errmsg='' # error message, if not empty
45 shelltest=false # if true, exit after testing the shell
46 re_exec_allowed=true # if true, we may exec under another shell
47
48 # Parse special command line options in $1. These special options are
49 # for internal use only, are not documented, and are not valid anywhere
50 # other than $1.
51 case "$1" in
52 "--shelltest")
53 shelltest=true
54 re_exec_allowed=false
55 shift
56 ;;
57 "--no-re-exec")
58 re_exec_allowed=false
59 shift
60 ;;
61 esac
62
63 # Solaris /bin/sh, and other SVR4 shells, do not support "!".
64 # This is the first feature that we test, because subsequent
65 # tests use "!".
66 #
67 if test -z "$errmsg"; then
68 if ( eval '! false' ) >/dev/null 2>&1 ; then
69 :
70 else
71 errmsg='Shell does not support "!".'
72 fi
73 fi
74
75 # Does the shell support functions?
76 #
77 if test -z "$errmsg"; then
78 if ! (
79 eval 'somefunction() { : ; }'
80 ) >/dev/null 2>&1
81 then
82 errmsg='Shell does not support functions.'
83 fi
84 fi
85
86 # Does the shell support the "local" keyword for variables in functions?
87 #
88 # Local variables are not required by SUSv3, but some scripts run during
89 # the NetBSD build use them.
90 #
91 # ksh93 fails this test; it uses an incompatible syntax involving the
92 # keywords 'function' and 'typeset'.
93 #
94 if test -z "$errmsg"; then
95 if ! (
96 eval 'f() { local v=2; }; v=1; f && test x"$v" = x"1"'
97 ) >/dev/null 2>&1
98 then
99 errmsg='Shell does not support the "local" keyword in functions.'
100 fi
101 fi
102
103 # Does the shell support ${var%suffix}, ${var#prefix}, and their variants?
104 #
105 # We don't bother testing for ${var+value}, ${var-value}, or their variants,
106 # since shells without those are sure to fail other tests too.
107 #
108 if test -z "$errmsg"; then
109 if ! (
110 eval 'var=a/b/c ;
111 test x"${var#*/};${var##*/};${var%/*};${var%%/*}" = \
112 x"b/c;c;a/b;a" ;'
113 ) >/dev/null 2>&1
114 then
115 errmsg='Shell does not support "${var%suffix}" or "${var#prefix}".'
116 fi
117 fi
118
119 # Does the shell support IFS?
120 #
121 # zsh in normal mode (as opposed to "emulate sh" mode) fails this test.
122 #
123 if test -z "$errmsg"; then
124 if ! (
125 eval 'IFS=: ; v=":a b::c" ; set -- $v ; IFS=+ ;
126 test x"$#;$1,$2,$3,$4;$*" = x"4;,a b,,c;+a b++c"'
127 ) >/dev/null 2>&1
128 then
129 errmsg='Shell does not support IFS word splitting.'
130 fi
131 fi
132
133 # Does the shell support ${1+"$@"}?
134 #
135 # Some versions of zsh fail this test, even in "emulate sh" mode.
136 #
137 if test -z "$errmsg"; then
138 if ! (
139 eval 'set -- "a a a" "b b b"; set -- ${1+"$@"};
140 test x"$#;$1;$2" = x"2;a a a;b b b";'
141 ) >/dev/null 2>&1
142 then
143 errmsg='Shell does not support ${1+"$@"}.'
144 fi
145 fi
146
147 # Does the shell support $(...) command substitution?
148 #
149 if test -z "$errmsg"; then
150 if ! (
151 eval 'var=$(echo abc); test x"$var" = x"abc"'
152 ) >/dev/null 2>&1
153 then
154 errmsg='Shell does not support "$(...)" command substitution.'
155 fi
156 fi
157
158 # Does the shell support $(...) command substitution with
159 # unbalanced parentheses?
160 #
161 # Some shells known to fail this test are: NetBSD /bin/ksh (as of 2009-12),
162 # bash-3.1, pdksh-5.2.14, zsh-4.2.7 in "emulate sh" mode.
163 #
164 if test -z "$errmsg"; then
165 if ! (
166 eval 'var=$(case x in x) echo abc;; esac); test x"$var" = x"abc"'
167 ) >/dev/null 2>&1
168 then
169 # XXX: This test is ignored because so many shells fail it; instead,
170 # the NetBSD build avoids using the problematic construct.
171 : ignore 'Shell does not support "$(...)" with unbalanced ")".'
172 fi
173 fi
174
175 # Does the shell support getopts or getopt?
176 #
177 if test -z "$errmsg"; then
178 if ! (
179 eval 'type getopts || type getopt'
180 ) >/dev/null 2>&1
181 then
182 errmsg='Shell does not support getopts or getopt.'
183 fi
184 fi
185
186 #
187 # If shelltest is true, exit now, reporting whether or not the shell is good.
188 #
189 if $shelltest; then
190 if test -n "$errmsg"; then
191 echo >&2 "$0: $errmsg"
192 exit 1
193 else
194 exit 0
195 fi
196 fi
197
198 #
199 # If the shell was bad, try to exec a better shell, or report an error.
200 #
201 # Loops are broken by passing an extra "--no-re-exec" flag to the new
202 # instance of this script.
203 #
204 if test -n "$errmsg"; then
205 if $re_exec_allowed; then
206 for othershell in \
207 "${HOST_SH}" /usr/xpg4/bin/sh ksh ksh88 mksh pdksh bash dash
208 # NOTE: some shells known not to work are:
209 # any shell using csh syntax;
210 # Solaris /bin/sh (missing many modern features);
211 # ksh93 (incompatible syntax for local variables);
212 # zsh (many differences, unless run in compatibility mode).
213 do
214 test -n "$othershell" || continue
215 if eval 'type "$othershell"' >/dev/null 2>&1 \
216 && "$othershell" "$0" --shelltest >/dev/null 2>&1
217 then
218 cat <<EOF
219 $0: $errmsg
220 $0: Retrying under $othershell
221 EOF
222 HOST_SH="$othershell"
223 export HOST_SH
224 exec $othershell "$0" --no-re-exec "$@" # avoid ${1+"$@"}
225 fi
226 # If HOST_SH was set, but failed the test above,
227 # then give up without trying any other shells.
228 test x"${othershell}" = x"${HOST_SH}" && break
229 done
230 fi
231
232 #
233 # If we get here, then the shell is bad, and we either could not
234 # find a replacement, or were not allowed to try a replacement.
235 #
236 cat <<EOF
237 $0: $errmsg
238
239 The NetBSD build system requires a shell that supports modern POSIX
240 features, as well as the "local" keyword in functions (which is a
241 widely-implemented but non-standardised feature).
242
243 Please re-run this script under a suitable shell. For example:
244
245 /path/to/suitable/shell $0 ...
246
247 The above command will usually enable build.sh to automatically set
248 HOST_SH=/path/to/suitable/shell, but if that fails, then you may also
249 need to explicitly set the HOST_SH environment variable, as follows:
250
251 HOST_SH=/path/to/suitable/shell
252 export HOST_SH
253 \${HOST_SH} $0 ...
254 EOF
255 exit 1
256 fi
257
258 #
259 # }}} End shell feature tests.
260 #
261
262 progname=${0##*/}
263 toppid=$$
264 results=/dev/null
265 tab=' '
266 trap "exit 1" 1 2 3 15
267
268 bomb()
269 {
270 cat >&2 <<ERRORMESSAGE
271
272 ERROR: $@
273 *** BUILD ABORTED ***
274 ERRORMESSAGE
275 kill ${toppid} # in case we were invoked from a subshell
276 exit 1
277 }
278
279
280 statusmsg()
281 {
282 ${runcmd} echo "===> $@" | tee -a "${results}"
283 }
284
285 statusmsg2()
286 {
287 local msg
288
289 msg="${1}"
290 shift
291 case "${msg}" in
292 ????????????????*) ;;
293 ??????????*) msg="${msg} ";;
294 ?????*) msg="${msg} ";;
295 *) msg="${msg} ";;
296 esac
297 case "${msg}" in
298 ?????????????????????*) ;;
299 ????????????????????) msg="${msg} ";;
300 ???????????????????) msg="${msg} ";;
301 ??????????????????) msg="${msg} ";;
302 ?????????????????) msg="${msg} ";;
303 ????????????????) msg="${msg} ";;
304 esac
305 statusmsg "${msg}$*"
306 }
307
308 warning()
309 {
310 statusmsg "Warning: $@"
311 }
312
313 # Find a program in the PATH, and print the result. If not found,
314 # print a default. If $2 is defined (even if it is an empty string),
315 # then that is the default; otherwise, $1 is used as the default.
316 find_in_PATH()
317 {
318 local prog="$1"
319 local result="${2-"$1"}"
320 local oldIFS="${IFS}"
321 local dir
322 IFS=":"
323 for dir in ${PATH}; do
324 if [ -x "${dir}/${prog}" ]; then
325 result="${dir}/${prog}"
326 break
327 fi
328 done
329 IFS="${oldIFS}"
330 echo "${result}"
331 }
332
333 # Try to find a working POSIX shell, and set HOST_SH to refer to it.
334 # Assumes that uname_s, uname_m, and PWD have been set.
335 set_HOST_SH()
336 {
337 # Even if ${HOST_SH} is already defined, we still do the
338 # sanity checks at the end.
339
340 # Solaris has /usr/xpg4/bin/sh.
341 #
342 [ -z "${HOST_SH}" ] && [ x"${uname_s}" = x"SunOS" ] && \
343 [ -x /usr/xpg4/bin/sh ] && HOST_SH="/usr/xpg4/bin/sh"
344
345 # Try to get the name of the shell that's running this script,
346 # by parsing the output from "ps". We assume that, if the host
347 # system's ps command supports -o comm at all, it will do so
348 # in the usual way: a one-line header followed by a one-line
349 # result, possibly including trailing white space. And if the
350 # host system's ps command doesn't support -o comm, we assume
351 # that we'll get an error message on stderr and nothing on
352 # stdout. (We don't try to use ps -o 'comm=' to suppress the
353 # header line, because that is less widely supported.)
354 #
355 # If we get the wrong result here, the user can override it by
356 # specifying HOST_SH in the environment.
357 #
358 [ -z "${HOST_SH}" ] && HOST_SH="$(
359 (ps -p $$ -o comm | sed -ne "2s/[ ${tab}]*\$//p") 2>/dev/null )"
360
361 # If nothing above worked, use "sh". We will later find the
362 # first directory in the PATH that has a "sh" program.
363 #
364 [ -z "${HOST_SH}" ] && HOST_SH="sh"
365
366 # If the result so far is not an absolute path, try to prepend
367 # PWD or search the PATH.
368 #
369 case "${HOST_SH}" in
370 /*) :
371 ;;
372 */*) HOST_SH="${PWD}/${HOST_SH}"
373 ;;
374 *) HOST_SH="$(find_in_PATH "${HOST_SH}")"
375 ;;
376 esac
377
378 # If we don't have an absolute path by now, bomb.
379 #
380 case "${HOST_SH}" in
381 /*) :
382 ;;
383 *) bomb "HOST_SH=\"${HOST_SH}\" is not an absolute path."
384 ;;
385 esac
386
387 # If HOST_SH is not executable, bomb.
388 #
389 [ -x "${HOST_SH}" ] ||
390 bomb "HOST_SH=\"${HOST_SH}\" is not executable."
391
392 # If HOST_SH fails tests, bomb.
393 # ("$0" may be a path that is no longer valid, because we have
394 # performed "cd $(dirname $0)", so don't use $0 here.)
395 #
396 "${HOST_SH}" build.sh --shelltest ||
397 bomb "HOST_SH=\"${HOST_SH}\" failed functionality tests."
398 }
399
400 # initdefaults --
401 # Set defaults before parsing command line options.
402 #
403 initdefaults()
404 {
405 makeenv=
406 makewrapper=
407 makewrappermachine=
408 runcmd=
409 operations=
410 removedirs=
411
412 [ -d usr.bin/make ] || cd "$(dirname $0)"
413 [ -d usr.bin/make ] ||
414 bomb "build.sh must be run from the top source level"
415 [ -f share/mk/bsd.own.mk ] ||
416 bomb "src/share/mk is missing; please re-fetch the source tree"
417
418 # Set various environment variables to known defaults,
419 # to minimize (cross-)build problems observed "in the field".
420 #
421 # LC_ALL=C must be set before we try to parse the output from
422 # any command. Other variables are set (or unset) here, before
423 # we parse command line arguments.
424 #
425 # These variables can be overridden via "-V var=value" if
426 # you know what you are doing.
427 #
428 unsetmakeenv INFODIR
429 unsetmakeenv LESSCHARSET
430 unsetmakeenv MAKEFLAGS
431 setmakeenv LC_ALL C
432
433 # Find information about the build platform. This should be
434 # kept in sync with _HOST_OSNAME, _HOST_OSREL, and _HOST_ARCH
435 # variables in share/mk/bsd.sys.mk.
436 #
437 # Note that "uname -p" is not part of POSIX, but we want uname_p
438 # to be set to the host MACHINE_ARCH, if possible. On systems
439 # where "uname -p" fails, prints "unknown", or prints a string
440 # that does not look like an identifier, fall back to using the
441 # output from "uname -m" instead.
442 #
443 uname_s=$(uname -s 2>/dev/null)
444 uname_r=$(uname -r 2>/dev/null)
445 uname_m=$(uname -m 2>/dev/null)
446 uname_p=$(uname -p 2>/dev/null || echo "unknown")
447 case "${uname_p}" in
448 ''|unknown|*[^-_A-Za-z0-9]*) uname_p="${uname_m}" ;;
449 esac
450
451 id_u=$(id -u 2>/dev/null || /usr/xpg4/bin/id -u 2>/dev/null)
452
453 # If $PWD is a valid name of the current directory, POSIX mandates
454 # that pwd return it by default which causes problems in the
455 # presence of symlinks. Unsetting PWD is simpler than changing
456 # every occurrence of pwd to use -P.
457 #
458 # XXX Except that doesn't work on Solaris. Or many Linuces.
459 #
460 unset PWD
461 TOP=$(/bin/pwd -P 2>/dev/null || /bin/pwd 2>/dev/null)
462
463 # The user can set HOST_SH in the environment, or we try to
464 # guess an appropriate value. Then we set several other
465 # variables from HOST_SH.
466 #
467 set_HOST_SH
468 setmakeenv HOST_SH "${HOST_SH}"
469 setmakeenv BSHELL "${HOST_SH}"
470 setmakeenv CONFIG_SHELL "${HOST_SH}"
471
472 # Set defaults.
473 #
474 toolprefix=nb
475
476 # Some systems have a small ARG_MAX. -X prevents make(1) from
477 # exporting variables in the environment redundantly.
478 #
479 case "${uname_s}" in
480 Darwin | FreeBSD | CYGWIN*)
481 MAKEFLAGS="-X ${MAKEFLAGS}"
482 ;;
483 esac
484
485 # do_{operation}=true if given operation is requested.
486 #
487 do_expertmode=false
488 do_rebuildmake=false
489 do_removedirs=false
490 do_tools=false
491 do_cleandir=false
492 do_obj=false
493 do_build=false
494 do_distribution=false
495 do_release=false
496 do_kernel=false
497 do_releasekernel=false
498 do_modules=false
499 do_installmodules=false
500 do_install=false
501 do_sets=false
502 do_sourcesets=false
503 do_syspkgs=false
504 do_iso_image=false
505 do_iso_image_source=false
506 do_live_image=false
507 do_install_image=false
508 do_params=false
509 do_rump=false
510
511 # done_{operation}=true if given operation has been done.
512 #
513 done_rebuildmake=false
514
515 # Create scratch directory
516 #
517 tmpdir="${TMPDIR-/tmp}/nbbuild$$"
518 mkdir "${tmpdir}" || bomb "Cannot mkdir: ${tmpdir}"
519 trap "cd /; rm -r -f \"${tmpdir}\"" 0
520 results="${tmpdir}/build.sh.results"
521
522 # Set source directories
523 #
524 setmakeenv NETBSDSRCDIR "${TOP}"
525
526 # Make sure KERNOBJDIR is an absolute path if defined
527 #
528 case "${KERNOBJDIR}" in
529 ''|/*) ;;
530 *) KERNOBJDIR="${TOP}/${KERNOBJDIR}"
531 setmakeenv KERNOBJDIR "${KERNOBJDIR}"
532 ;;
533 esac
534
535 # Find the version of NetBSD
536 #
537 DISTRIBVER="$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh)"
538
539 # Set the BUILDSEED to NetBSD-"N"
540 #
541 setmakeenv BUILDSEED "NetBSD-$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh -m)"
542
543 # Set MKARZERO to "yes"
544 #
545 setmakeenv MKARZERO "yes"
546
547 }
548
549 getarch()
550 {
551 # Translate some MACHINE name aliases (known only to build.sh)
552 # into proper MACHINE and MACHINE_ARCH names. Save the alias
553 # name in makewrappermachine.
554 #
555 case "${MACHINE}" in
556
557 evbearm-e[bl])
558 makewrappermachine=${MACHINE}
559 # MACHINE_ARCH is "arm" or "armeb", not "armel"
560 MACHINE_ARCH=earm${MACHINE##*-}
561 MACHINE_ARCH=${MACHINE_ARCH%el}
562 MACHINE=evbarm
563 ;;
564
565 evbarm-e[bl])
566 makewrappermachine=${MACHINE}
567 # MACHINE_ARCH is "arm" or "armeb", not "armel"
568 MACHINE_ARCH=arm${MACHINE##*-}
569 MACHINE_ARCH=${MACHINE_ARCH%el}
570 MACHINE=${MACHINE%-e[bl]}
571 ;;
572
573 evbmips-e[bl]|sbmips-e[bl])
574 makewrappermachine=${MACHINE}
575 MACHINE_ARCH=mips${MACHINE##*-}
576 MACHINE=${MACHINE%-e[bl]}
577 ;;
578
579 evbmips64-e[bl]|sbmips64-e[bl])
580 makewrappermachine=${MACHINE}
581 MACHINE_ARCH=mips64${MACHINE##*-}
582 MACHINE=${MACHINE%64-e[bl]}
583 ;;
584
585 evbsh3-e[bl])
586 makewrappermachine=${MACHINE}
587 MACHINE_ARCH=sh3${MACHINE##*-}
588 MACHINE=${MACHINE%-e[bl]}
589 ;;
590
591 esac
592
593 # Translate a MACHINE into a default MACHINE_ARCH.
594 #
595 case "${MACHINE}" in
596
597 acorn26|acorn32|cats|hpcarm|iyonix|netwinder|shark|zaurus)
598 MACHINE_ARCH=arm
599 ;;
600
601 evbarm) # unspecified MACHINE_ARCH gets LE
602 MACHINE_ARCH=${MACHINE_ARCH:=arm}
603 ;;
604
605 hp700)
606 MACHINE_ARCH=hppa
607 ;;
608
609 sun2)
610 MACHINE_ARCH=m68000
611 ;;
612
613 amiga|atari|cesfic|hp300|luna68k|mac68k|mvme68k|news68k|next68k|sun3|x68k)
614 MACHINE_ARCH=m68k
615 ;;
616
617 evbmips|sbmips) # no default MACHINE_ARCH
618 ;;
619
620 sgimips64)
621 makewrappermachine=${MACHINE}
622 MACHINE=${MACHINE%64}
623 MACHINE_ARCH=mips64eb
624 ;;
625
626 ews4800mips|mipsco|newsmips|sgimips|emips)
627 MACHINE_ARCH=mipseb
628 ;;
629
630 algor64|arc64|cobalt64|pmax64)
631 makewrappermachine=${MACHINE}
632 MACHINE=${MACHINE%64}
633 MACHINE_ARCH=mips64el
634 ;;
635
636 algor|arc|cobalt|hpcmips|pmax)
637 MACHINE_ARCH=mipsel
638 ;;
639
640 evbppc64|macppc64|ofppc64)
641 makewrappermachine=${MACHINE}
642 MACHINE=${MACHINE%64}
643 MACHINE_ARCH=powerpc64
644 ;;
645
646 amigappc|bebox|evbppc|ibmnws|macppc|mvmeppc|ofppc|prep|rs6000|sandpoint)
647 MACHINE_ARCH=powerpc
648 ;;
649
650 evbsh3) # no default MACHINE_ARCH
651 ;;
652
653 mmeye)
654 MACHINE_ARCH=sh3eb
655 ;;
656
657 dreamcast|hpcsh|landisk)
658 MACHINE_ARCH=sh3el
659 ;;
660
661 amd64)
662 MACHINE_ARCH=x86_64
663 ;;
664
665 alpha|i386|sparc|sparc64|vax|ia64)
666 MACHINE_ARCH=${MACHINE}
667 ;;
668
669 *)
670 bomb "Unknown target MACHINE: ${MACHINE}"
671 ;;
672
673 esac
674 }
675
676 validatearch()
677 {
678 # Ensure that the MACHINE_ARCH exists (and is supported by build.sh).
679 #
680 case "${MACHINE_ARCH}" in
681
682 alpha|arm|armeb|earm|earmeb|hppa|i386|m68000|m68k|mipse[bl]|mips64e[bl]|powerpc|powerpc64|sh3e[bl]|sparc|sparc64|vax|x86_64|ia64)
683 ;;
684
685 "")
686 bomb "No MACHINE_ARCH provided"
687 ;;
688
689 *)
690 bomb "Unknown target MACHINE_ARCH: ${MACHINE_ARCH}"
691 ;;
692
693 esac
694
695 # Determine valid MACHINE_ARCHs for MACHINE
696 #
697 case "${MACHINE}" in
698
699 evbarm)
700 arches="arm armeb earm earmeb"
701 ;;
702
703 cats|iyonix|netwinder|shark|zaurus)
704 arches="arm earm"
705 ;;
706
707 algor|arc|cobalt|pmax)
708 arches="mipsel mips64el"
709 ;;
710
711 evbmips|sbmips)
712 arches="mipseb mipsel mips64eb mips64el"
713 ;;
714
715 sgimips)
716 arches="mipseb mips64eb"
717 ;;
718
719 evbsh3)
720 arches="sh3eb sh3el"
721 ;;
722
723 macppc|evbppc|ofppc)
724 arches="powerpc powerpc64"
725 ;;
726 *)
727 oma="${MACHINE_ARCH}"
728 getarch
729 arches="${MACHINE_ARCH}"
730 MACHINE_ARCH="${oma}"
731 ;;
732
733 esac
734
735 # Ensure that MACHINE_ARCH supports MACHINE
736 #
737 archok=false
738 for a in ${arches}; do
739 if [ "${a}" = "${MACHINE_ARCH}" ]; then
740 archok=true
741 break
742 fi
743 done
744 ${archok} ||
745 bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'"
746 }
747
748 # nobomb_getmakevar --
749 # Given the name of a make variable in $1, print make's idea of the
750 # value of that variable, or return 1 if there's an error.
751 #
752 nobomb_getmakevar()
753 {
754 [ -x "${make}" ] || return 1
755 "${make}" -m ${TOP}/share/mk -s -B -f- _x_ <<EOF || return 1
756 _x_:
757 echo \${$1}
758 .include <bsd.prog.mk>
759 .include <bsd.kernobj.mk>
760 EOF
761 }
762
763 # bomb_getmakevar --
764 # Given the name of a make variable in $1, print make's idea of the
765 # value of that variable, or bomb if there's an error.
766 #
767 bomb_getmakevar()
768 {
769 [ -x "${make}" ] || bomb "bomb_getmakevar $1: ${make} is not executable"
770 nobomb_getmakevar "$1" || bomb "bomb_getmakevar $1: ${make} failed"
771 }
772
773 # getmakevar --
774 # Given the name of a make variable in $1, print make's idea of the
775 # value of that variable, or print a literal '$' followed by the
776 # variable name if ${make} is not executable. This is intended for use in
777 # messages that need to be readable even if $make hasn't been built,
778 # such as when build.sh is run with the "-n" option.
779 #
780 getmakevar()
781 {
782 if [ -x "${make}" ]; then
783 bomb_getmakevar "$1"
784 else
785 echo "\$$1"
786 fi
787 }
788
789 setmakeenv()
790 {
791 eval "$1='$2'; export $1"
792 makeenv="${makeenv} $1"
793 }
794
795 unsetmakeenv()
796 {
797 eval "unset $1"
798 makeenv="${makeenv} $1"
799 }
800
801 # Given a variable name in $1, modify the variable in place as follows:
802 # For each space-separated word in the variable, call resolvepath.
803 resolvepaths()
804 {
805 local var="$1"
806 local val
807 eval val=\"\${${var}}\"
808 local newval=''
809 local word
810 for word in ${val}; do
811 resolvepath word
812 newval="${newval}${newval:+ }${word}"
813 done
814 eval ${var}=\"\${newval}\"
815 }
816
817 # Given a variable name in $1, modify the variable in place as follows:
818 # Convert possibly-relative path to absolute path by prepending
819 # ${TOP} if necessary. Also delete trailing "/", if any.
820 resolvepath()
821 {
822 local var="$1"
823 local val
824 eval val=\"\${${var}}\"
825 case "${val}" in
826 /)
827 ;;
828 /*)
829 val="${val%/}"
830 ;;
831 *)
832 val="${TOP}/${val%/}"
833 ;;
834 esac
835 eval ${var}=\"\${val}\"
836 }
837
838 usage()
839 {
840 if [ -n "$*" ]; then
841 echo ""
842 echo "${progname}: $*"
843 fi
844 cat <<_usage_
845
846 Usage: ${progname} [-EhnorUuxy] [-a arch] [-B buildid] [-C cdextras]
847 [-D dest] [-j njob] [-M obj] [-m mach] [-N noisy]
848 [-O obj] [-R release] [-S seed] [-T tools]
849 [-V var=[value]] [-w wrapper] [-X x11src] [-Y extsrcsrc]
850 [-Z var]
851 operation [...]
852
853 Build operations (all imply "obj" and "tools"):
854 build Run "make build".
855 distribution Run "make distribution" (includes DESTDIR/etc/ files).
856 release Run "make release" (includes kernels & distrib media).
857
858 Other operations:
859 help Show this message and exit.
860 makewrapper Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make.
861 Always performed.
862 cleandir Run "make cleandir". [Default unless -u is used]
863 obj Run "make obj". [Default unless -o is used]
864 tools Build and install tools.
865 install=idir Run "make installworld" to \`idir' to install all sets
866 except \`etc'. Useful after "distribution" or "release"
867 kernel=conf Build kernel with config file \`conf'
868 releasekernel=conf Install kernel built by kernel=conf to RELEASEDIR.
869 installmodules=idir Run "make installmodules" to \`idir' to install all
870 kernel modules.
871 modules Build kernel modules.
872 rumptest Do a linktest for rump (for developers).
873 sets Create binary sets in
874 RELEASEDIR/RELEASEMACHINEDIR/binary/sets.
875 DESTDIR should be populated beforehand.
876 sourcesets Create source sets in RELEASEDIR/source/sets.
877 syspkgs Create syspkgs in
878 RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.
879 iso-image Create CD-ROM image in RELEASEDIR/iso.
880 iso-image-source Create CD-ROM image with source in RELEASEDIR/iso.
881 live-image Create bootable live image in
882 RELEASEDIR/RELEASEMACHINEDIR/installation/liveimage.
883 install-image Create bootable installation image in
884 RELEASEDIR/RELEASEMACHINEDIR/installation/installimage.
885 params Display various make(1) parameters.
886
887 Options:
888 -a arch Set MACHINE_ARCH to arch. [Default: deduced from MACHINE]
889 -B buildid Set BUILDID to buildid.
890 -C cdextras Append cdextras to CDEXTRA variable for inclusion on CD-ROM.
891 -D dest Set DESTDIR to dest. [Default: destdir.MACHINE]
892 -E Set "expert" mode; disables various safety checks.
893 Should not be used without expert knowledge of the build system.
894 -h Print this help message.
895 -j njob Run up to njob jobs in parallel; see make(1) -j.
896 -M obj Set obj root directory to obj; sets MAKEOBJDIRPREFIX.
897 Unsets MAKEOBJDIR.
898 -m mach Set MACHINE to mach; not required if NetBSD native.
899 -N noisy Set the noisyness (MAKEVERBOSE) level of the build:
900 0 Minimal output ("quiet")
901 1 Describe what is occurring
902 2 Describe what is occurring and echo the actual command
903 3 Ignore the effect of the "@" prefix in make commands
904 4 Trace shell commands using the shell's -x flag
905 [Default: 2]
906 -n Show commands that would be executed, but do not execute them.
907 -O obj Set obj root directory to obj; sets a MAKEOBJDIR pattern.
908 Unsets MAKEOBJDIRPREFIX.
909 -o Set MKOBJDIRS=no; do not create objdirs at start of build.
910 -R release Set RELEASEDIR to release. [Default: releasedir]
911 -r Remove contents of TOOLDIR and DESTDIR before building.
912 -S seed Set BUILDSEED to seed. [Default: NetBSD-majorversion]
913 -T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in
914 the environment, ${toolprefix}make will be (re)built
915 unconditionally.
916 -U Set MKUNPRIVED=yes; build without requiring root privileges,
917 install from an UNPRIVED build with proper file permissions.
918 -u Set MKUPDATE=yes; do not run "make cleandir" first.
919 Without this, everything is rebuilt, including the tools.
920 -V var=[value] Set variable \`var' to \`value'.
921 -w wrapper Create ${toolprefix}make script as wrapper.
922 [Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE}]
923 -X x11src Set X11SRCDIR to x11src. [Default: /usr/xsrc]
924 -x Set MKX11=yes; build X11 from X11SRCDIR
925 -Y extsrcsrc Set EXTSRCSRCDIR to extsrcsrc. [Default: /usr/extsrc]
926 -y Set MKEXTSRC=yes; build extsrc from EXTSRCSRCDIR
927 -Z var Unset ("zap") variable \`var'.
928
929 _usage_
930 exit 1
931 }
932
933 parseoptions()
934 {
935 opts='a:B:C:D:Ehj:M:m:N:nO:oR:rS:T:UuV:w:X:xY:yZ:'
936 opt_a=no
937
938 if type getopts >/dev/null 2>&1; then
939 # Use POSIX getopts.
940 #
941 getoptcmd='getopts ${opts} opt && opt=-${opt}'
942 optargcmd=':'
943 optremcmd='shift $((${OPTIND} -1))'
944 else
945 type getopt >/dev/null 2>&1 ||
946 bomb "Shell does not support getopts or getopt"
947
948 # Use old-style getopt(1) (doesn't handle whitespace in args).
949 #
950 args="$(getopt ${opts} $*)"
951 [ $? = 0 ] || usage
952 set -- ${args}
953
954 getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
955 optargcmd='OPTARG="$1"; shift'
956 optremcmd=':'
957 fi
958
959 # Parse command line options.
960 #
961 while eval ${getoptcmd}; do
962 case ${opt} in
963
964 -a)
965 eval ${optargcmd}
966 MACHINE_ARCH=${OPTARG}
967 opt_a=yes
968 ;;
969
970 -B)
971 eval ${optargcmd}
972 BUILDID=${OPTARG}
973 ;;
974
975 -C)
976 eval ${optargcmd}; resolvepaths OPTARG
977 CDEXTRA="${CDEXTRA}${CDEXTRA:+ }${OPTARG}"
978 ;;
979
980 -D)
981 eval ${optargcmd}; resolvepath OPTARG
982 setmakeenv DESTDIR "${OPTARG}"
983 ;;
984
985 -E)
986 do_expertmode=true
987 ;;
988
989 -j)
990 eval ${optargcmd}
991 parallel="-j ${OPTARG}"
992 ;;
993
994 -M)
995 eval ${optargcmd}; resolvepath OPTARG
996 case "${OPTARG}" in
997 \$*) usage "-M argument must not begin with '\$'"
998 ;;
999 *\$*) # can use resolvepath, but can't set TOP_objdir
1000 resolvepath OPTARG
1001 ;;
1002 *) resolvepath OPTARG
1003 TOP_objdir="${OPTARG}${TOP}"
1004 ;;
1005 esac
1006 unsetmakeenv MAKEOBJDIR
1007 setmakeenv MAKEOBJDIRPREFIX "${OPTARG}"
1008 ;;
1009
1010 # -m overrides MACHINE_ARCH unless "-a" is specified
1011 -m)
1012 eval ${optargcmd}
1013 MACHINE="${OPTARG}"
1014 [ "${opt_a}" != "yes" ] && getarch
1015 ;;
1016
1017 -N)
1018 eval ${optargcmd}
1019 case "${OPTARG}" in
1020 0|1|2|3|4)
1021 setmakeenv MAKEVERBOSE "${OPTARG}"
1022 ;;
1023 *)
1024 usage "'${OPTARG}' is not a valid value for -N"
1025 ;;
1026 esac
1027 ;;
1028
1029 -n)
1030 runcmd=echo
1031 ;;
1032
1033 -O)
1034 eval ${optargcmd}
1035 case "${OPTARG}" in
1036 *\$*) usage "-O argument must not contain '\$'"
1037 ;;
1038 *) resolvepath OPTARG
1039 TOP_objdir="${OPTARG}"
1040 ;;
1041 esac
1042 unsetmakeenv MAKEOBJDIRPREFIX
1043 setmakeenv MAKEOBJDIR "\${.CURDIR:C,^$TOP,$OPTARG,}"
1044 ;;
1045
1046 -o)
1047 MKOBJDIRS=no
1048 ;;
1049
1050 -R)
1051 eval ${optargcmd}; resolvepath OPTARG
1052 setmakeenv RELEASEDIR "${OPTARG}"
1053 ;;
1054
1055 -r)
1056 do_removedirs=true
1057 do_rebuildmake=true
1058 ;;
1059
1060 -S)
1061 eval ${optargcmd}
1062 setmakeenv BUILDSEED "${OPTARG}"
1063 ;;
1064
1065 -T)
1066 eval ${optargcmd}; resolvepath OPTARG
1067 TOOLDIR="${OPTARG}"
1068 export TOOLDIR
1069 ;;
1070
1071 -U)
1072 setmakeenv MKUNPRIVED yes
1073 ;;
1074
1075 -u)
1076 setmakeenv MKUPDATE yes
1077 ;;
1078
1079 -V)
1080 eval ${optargcmd}
1081 case "${OPTARG}" in
1082 # XXX: consider restricting which variables can be changed?
1083 [a-zA-Z_][a-zA-Z_0-9]*=*)
1084 setmakeenv "${OPTARG%%=*}" "${OPTARG#*=}"
1085 ;;
1086 *)
1087 usage "-V argument must be of the form 'var=[value]'"
1088 ;;
1089 esac
1090 ;;
1091
1092 -w)
1093 eval ${optargcmd}; resolvepath OPTARG
1094 makewrapper="${OPTARG}"
1095 ;;
1096
1097 -X)
1098 eval ${optargcmd}; resolvepath OPTARG
1099 setmakeenv X11SRCDIR "${OPTARG}"
1100 ;;
1101
1102 -x)
1103 setmakeenv MKX11 yes
1104 ;;
1105
1106 -Y)
1107 eval ${optargcmd}; resolvepath OPTARG
1108 setmakeenv EXTSRCSRCDIR "${OPTARG}"
1109 ;;
1110
1111 -y)
1112 setmakeenv MKEXTSRC yes
1113 ;;
1114
1115 -Z)
1116 eval ${optargcmd}
1117 # XXX: consider restricting which variables can be unset?
1118 unsetmakeenv "${OPTARG}"
1119 ;;
1120
1121 --)
1122 break
1123 ;;
1124
1125 -'?'|-h)
1126 usage
1127 ;;
1128
1129 esac
1130 done
1131
1132 # Validate operations.
1133 #
1134 eval ${optremcmd}
1135 while [ $# -gt 0 ]; do
1136 op=$1; shift
1137 operations="${operations} ${op}"
1138
1139 case "${op}" in
1140
1141 help)
1142 usage
1143 ;;
1144
1145 makewrapper|cleandir|obj|tools|build|distribution|release|sets|sourcesets|syspkgs|params)
1146 ;;
1147
1148 iso-image)
1149 op=iso_image # used as part of a variable name
1150 ;;
1151
1152 iso-image-source)
1153 op=iso_image_source # used as part of a variable name
1154 ;;
1155
1156 live-image)
1157 op=live_image # used as part of a variable name
1158 ;;
1159
1160 install-image)
1161 op=install_image # used as part of a variable name
1162 ;;
1163
1164 kernel=*|releasekernel=*)
1165 arg=${op#*=}
1166 op=${op%%=*}
1167 [ -n "${arg}" ] ||
1168 bomb "Must supply a kernel name with \`${op}=...'"
1169 ;;
1170
1171 modules)
1172 op=modules
1173 ;;
1174
1175 install=*|installmodules=*)
1176 arg=${op#*=}
1177 op=${op%%=*}
1178 [ -n "${arg}" ] ||
1179 bomb "Must supply a directory with \`install=...'"
1180 ;;
1181
1182 rump|rumptest)
1183 op=${op}
1184 ;;
1185
1186 *)
1187 usage "Unknown operation \`${op}'"
1188 ;;
1189
1190 esac
1191 eval do_${op}=true
1192 done
1193 [ -n "${operations}" ] || usage "Missing operation to perform."
1194
1195 # Set up MACHINE*. On a NetBSD host, these are allowed to be unset.
1196 #
1197 if [ -z "${MACHINE}" ]; then
1198 [ "${uname_s}" = "NetBSD" ] ||
1199 bomb "MACHINE must be set, or -m must be used, for cross builds."
1200 MACHINE=${uname_m}
1201 fi
1202 [ -n "${MACHINE_ARCH}" ] || getarch
1203 validatearch
1204
1205 # Set up default make(1) environment.
1206 #
1207 makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
1208 [ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID"
1209 MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS}"
1210 MAKEFLAGS="${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}"
1211 export MAKEFLAGS MACHINE MACHINE_ARCH
1212 }
1213
1214 # sanitycheck --
1215 # Sanity check after parsing command line options, before rebuildmake.
1216 #
1217 sanitycheck()
1218 {
1219 # If the PATH contains any non-absolute components (including,
1220 # but not limited to, "." or ""), then complain. As an exception,
1221 # allow "" or "." as the last component of the PATH. This is fatal
1222 # if expert mode is not in effect.
1223 #
1224 local path="${PATH}"
1225 path="${path%:}" # delete trailing ":"
1226 path="${path%:.}" # delete trailing ":."
1227 case ":${path}:/" in
1228 *:[!/]*)
1229 if ${do_expertmode}; then
1230 warning "PATH contains non-absolute components"
1231 else
1232 bomb "PATH environment variable must not" \
1233 "contain non-absolute components"
1234 fi
1235 ;;
1236 esac
1237 }
1238
1239 # print_tooldir_make --
1240 # Try to find and print a path to an existing
1241 # ${TOOLDIR}/bin/${toolprefix}make, for use by rebuildmake() before a
1242 # new version of ${toolprefix}make has been built.
1243 #
1244 # * If TOOLDIR was set in the environment or on the command line, use
1245 # that value.
1246 # * Otherwise try to guess what TOOLDIR would be if not overridden by
1247 # /etc/mk.conf, and check whether the resulting directory contains
1248 # a copy of ${toolprefix}make (this should work for everybody who
1249 # doesn't override TOOLDIR via /etc/mk.conf);
1250 # * Failing that, search for ${toolprefix}make, nbmake, bmake, or make,
1251 # in the PATH (this might accidentally find a version of make that
1252 # does not understand the syntax used by NetBSD make, and that will
1253 # lead to failure in the next step);
1254 # * If a copy of make was found above, try to use it with
1255 # nobomb_getmakevar to find the correct value for TOOLDIR, and believe the
1256 # result only if it's a directory that already exists;
1257 # * If a value of TOOLDIR was found above, and if
1258 # ${TOOLDIR}/bin/${toolprefix}make exists, print that value.
1259 #
1260 print_tooldir_make()
1261 {
1262 local possible_TOP_OBJ
1263 local possible_TOOLDIR
1264 local possible_make
1265 local tooldir_make
1266
1267 if [ -n "${TOOLDIR}" ]; then
1268 echo "${TOOLDIR}/bin/${toolprefix}make"
1269 return 0
1270 fi
1271
1272 # Set host_ostype to something like "NetBSD-4.5.6-i386". This
1273 # is intended to match the HOST_OSTYPE variable in <bsd.own.mk>.
1274 #
1275 local host_ostype="${uname_s}-$(
1276 echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
1277 )-$(
1278 echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
1279 )"
1280
1281 # Look in a few potential locations for
1282 # ${possible_TOOLDIR}/bin/${toolprefix}make.
1283 # If we find it, then set possible_make.
1284 #
1285 # In the usual case (without interference from environment
1286 # variables or /etc/mk.conf), <bsd.own.mk> should set TOOLDIR to
1287 # "${_SRC_TOP_OBJ_}/tooldir.${host_ostype}".
1288 #
1289 # In practice it's difficult to figure out the correct value
1290 # for _SRC_TOP_OBJ_. In the easiest case, when the -M or -O
1291 # options were passed to build.sh, then ${TOP_objdir} will be
1292 # the correct value. We also try a few other possibilities, but
1293 # we do not replicate all the logic of <bsd.obj.mk>.
1294 #
1295 for possible_TOP_OBJ in \
1296 "${TOP_objdir}" \
1297 "${MAKEOBJDIRPREFIX:+${MAKEOBJDIRPREFIX}${TOP}}" \
1298 "${TOP}" \
1299 "${TOP}/obj" \
1300 "${TOP}/obj.${MACHINE}"
1301 do
1302 [ -n "${possible_TOP_OBJ}" ] || continue
1303 possible_TOOLDIR="${possible_TOP_OBJ}/tooldir.${host_ostype}"
1304 possible_make="${possible_TOOLDIR}/bin/${toolprefix}make"
1305 if [ -x "${possible_make}" ]; then
1306 break
1307 else
1308 unset possible_make
1309 fi
1310 done
1311
1312 # If the above didn't work, search the PATH for a suitable
1313 # ${toolprefix}make, nbmake, bmake, or make.
1314 #
1315 : ${possible_make:=$(find_in_PATH ${toolprefix}make '')}
1316 : ${possible_make:=$(find_in_PATH nbmake '')}
1317 : ${possible_make:=$(find_in_PATH bmake '')}
1318 : ${possible_make:=$(find_in_PATH make '')}
1319
1320 # At this point, we don't care whether possible_make is in the
1321 # correct TOOLDIR or not; we simply want it to be usable by
1322 # getmakevar to help us find the correct TOOLDIR.
1323 #
1324 # Use ${possible_make} with nobomb_getmakevar to try to find
1325 # the value of TOOLDIR. Believe the result only if it's
1326 # a directory that already exists and contains bin/${toolprefix}make.
1327 #
1328 if [ -x "${possible_make}" ]; then
1329 possible_TOOLDIR="$(
1330 make="${possible_make}" \
1331 nobomb_getmakevar TOOLDIR 2>/dev/null
1332 )"
1333 if [ $? = 0 ] && [ -n "${possible_TOOLDIR}" ] \
1334 && [ -d "${possible_TOOLDIR}" ];
1335 then
1336 tooldir_make="${possible_TOOLDIR}/bin/${toolprefix}make"
1337 if [ -x "${tooldir_make}" ]; then
1338 echo "${tooldir_make}"
1339 return 0
1340 fi
1341 fi
1342 fi
1343 return 1
1344 }
1345
1346 # rebuildmake --
1347 # Rebuild nbmake in a temporary directory if necessary. Sets $make
1348 # to a path to the nbmake executable. Sets done_rebuildmake=true
1349 # if nbmake was rebuilt.
1350 #
1351 # There is a cyclic dependency between building nbmake and choosing
1352 # TOOLDIR: TOOLDIR may be affected by settings in /etc/mk.conf, so we
1353 # would like to use getmakevar to get the value of TOOLDIR; but we can't
1354 # use getmakevar before we have an up to date version of nbmake; we
1355 # might already have an up to date version of nbmake in TOOLDIR, but we
1356 # don't yet know where TOOLDIR is.
1357 #
1358 # The default value of TOOLDIR also depends on the location of the top
1359 # level object directory, so $(getmakevar TOOLDIR) invoked before or
1360 # after making the top level object directory may produce different
1361 # results.
1362 #
1363 # Strictly speaking, we should do the following:
1364 #
1365 # 1. build a new version of nbmake in a temporary directory;
1366 # 2. use the temporary nbmake to create the top level obj directory;
1367 # 3. use $(getmakevar TOOLDIR) with the temporary nbmake to
1368 # get the corect value of TOOLDIR;
1369 # 4. move the temporary nbmake to ${TOOLDIR}/bin/nbmake.
1370 #
1371 # However, people don't like building nbmake unnecessarily if their
1372 # TOOLDIR has not changed since an earlier build. We try to avoid
1373 # rebuilding a temporary version of nbmake by taking some shortcuts to
1374 # guess a value for TOOLDIR, looking for an existing version of nbmake
1375 # in that TOOLDIR, and checking whether that nbmake is newer than the
1376 # sources used to build it.
1377 #
1378 rebuildmake()
1379 {
1380 make="$(print_tooldir_make)"
1381 if [ -n "${make}" ] && [ -x "${make}" ]; then
1382 for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
1383 if [ "${f}" -nt "${make}" ]; then
1384 statusmsg "${make} outdated" \
1385 "(older than ${f}), needs building."
1386 do_rebuildmake=true
1387 break
1388 fi
1389 done
1390 else
1391 statusmsg "No \$TOOLDIR/bin/${toolprefix}make, needs building."
1392 do_rebuildmake=true
1393 fi
1394
1395 # Build bootstrap ${toolprefix}make if needed.
1396 if ${do_rebuildmake}; then
1397 statusmsg "Bootstrapping ${toolprefix}make"
1398 ${runcmd} cd "${tmpdir}"
1399 ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
1400 CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
1401 ${HOST_SH} "${TOP}/tools/make/configure" ||
1402 bomb "Configure of ${toolprefix}make failed"
1403 ${runcmd} ${HOST_SH} buildmake.sh ||
1404 bomb "Build of ${toolprefix}make failed"
1405 make="${tmpdir}/${toolprefix}make"
1406 ${runcmd} cd "${TOP}"
1407 ${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
1408 done_rebuildmake=true
1409 fi
1410 }
1411
1412 # validatemakeparams --
1413 # Perform some late sanity checks, after rebuildmake,
1414 # but before createmakewrapper or any real work.
1415 #
1416 # Creates the top-level obj directory, because that
1417 # is needed by some of the sanity checks.
1418 #
1419 # Prints status messages reporting the values of several variables.
1420 #
1421 validatemakeparams()
1422 {
1423 # MAKECONF (which defaults to /etc/mk.conf in share/mk/bsd.own.mk)
1424 # can affect many things, so mention it in an early status message.
1425 #
1426 MAKECONF=$(getmakevar MAKECONF)
1427 if [ -e "${MAKECONF}" ]; then
1428 statusmsg2 "MAKECONF file:" "${MAKECONF}"
1429 else
1430 statusmsg2 "MAKECONF file:" "${MAKECONF} (File not found)"
1431 fi
1432
1433 if [ "${runcmd}" = "echo" ]; then
1434 TOOLCHAIN_MISSING=no
1435 EXTERNAL_TOOLCHAIN=""
1436 else
1437 TOOLCHAIN_MISSING=$(bomb_getmakevar TOOLCHAIN_MISSING)
1438 EXTERNAL_TOOLCHAIN=$(bomb_getmakevar EXTERNAL_TOOLCHAIN)
1439 fi
1440 if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
1441 [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
1442 ${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
1443 ${runcmd} echo " MACHINE: ${MACHINE}"
1444 ${runcmd} echo " MACHINE_ARCH: ${MACHINE_ARCH}"
1445 ${runcmd} echo ""
1446 ${runcmd} echo "All builds for this platform should be done via a traditional make"
1447 ${runcmd} echo "If you wish to use an external cross-toolchain, set"
1448 ${runcmd} echo " EXTERNAL_TOOLCHAIN=<path to toolchain root>"
1449 ${runcmd} echo "in either the environment or mk.conf and rerun"
1450 ${runcmd} echo " ${progname} $*"
1451 exit 1
1452 fi
1453
1454 # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE
1455 # These may be set as build.sh options or in "mk.conf".
1456 # Don't export them as they're only used for tests in build.sh.
1457 #
1458 MKOBJDIRS=$(getmakevar MKOBJDIRS)
1459 MKUNPRIVED=$(getmakevar MKUNPRIVED)
1460 MKUPDATE=$(getmakevar MKUPDATE)
1461
1462 if [ "${MKOBJDIRS}" != "no" ]; then
1463 # Create the top-level object directory.
1464 #
1465 # "make obj NOSUBDIR=" can handle most cases, but it
1466 # can't handle the case where MAKEOBJDIRPREFIX is set
1467 # while the corresponding directory does not exist
1468 # (rules in <bsd.obj.mk> would abort the build). We
1469 # therefore have to handle the MAKEOBJDIRPREFIX case
1470 # without invoking "make obj". The MAKEOBJDIR case
1471 # could be handled either way, but we choose to handle
1472 # it similarly to MAKEOBJDIRPREFIX.
1473 #
1474 if [ -n "${TOP_obj}" ]; then
1475 # It must have been set by the "-M" or "-O"
1476 # command line options, so there's no need to
1477 # use getmakevar
1478 :
1479 elif [ -n "$MAKEOBJDIRPREFIX" ]; then
1480 TOP_obj="$(getmakevar MAKEOBJDIRPREFIX)${TOP}"
1481 elif [ -n "$MAKEOBJDIR" ]; then
1482 TOP_obj="$(getmakevar MAKEOBJDIR)"
1483 fi
1484 if [ -n "$TOP_obj" ]; then
1485 ${runcmd} mkdir -p "${TOP_obj}" ||
1486 bomb "Can't create top level object directory" \
1487 "${TOP_obj}"
1488 else
1489 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1490 bomb "Can't create top level object directory" \
1491 "using make obj"
1492 fi
1493
1494 # make obj in tools to ensure that the objdir for "tools"
1495 # is available.
1496 #
1497 ${runcmd} cd tools
1498 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1499 bomb "Failed to make obj in tools"
1500 ${runcmd} cd "${TOP}"
1501 fi
1502
1503 # Find TOOLDIR, DESTDIR, and RELEASEDIR, according to getmakevar,
1504 # and bomb if they have changed from the values we had from the
1505 # command line or environment.
1506 #
1507 # This must be done after creating the top-level object directory.
1508 #
1509 for var in TOOLDIR DESTDIR RELEASEDIR
1510 do
1511 eval oldval=\"\$${var}\"
1512 newval="$(getmakevar $var)"
1513 if ! $do_expertmode; then
1514 : ${_SRC_TOP_OBJ_:=$(getmakevar _SRC_TOP_OBJ_)}
1515 case "$var" in
1516 DESTDIR)
1517 : ${newval:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}}
1518 makeenv="${makeenv} DESTDIR"
1519 ;;
1520 RELEASEDIR)
1521 : ${newval:=${_SRC_TOP_OBJ_}/releasedir}
1522 makeenv="${makeenv} RELEASEDIR"
1523 ;;
1524 esac
1525 fi
1526 if [ -n "$oldval" ] && [ "$oldval" != "$newval" ]; then
1527 bomb "Value of ${var} has changed" \
1528 "(was \"${oldval}\", now \"${newval}\")"
1529 fi
1530 eval ${var}=\"\${newval}\"
1531 eval export ${var}
1532 statusmsg2 "${var} path:" "${newval}"
1533 done
1534
1535 # RELEASEMACHINEDIR is just a subdir name, e.g. "i386".
1536 RELEASEMACHINEDIR=$(getmakevar RELEASEMACHINEDIR)
1537
1538 # Check validity of TOOLDIR and DESTDIR.
1539 #
1540 if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then
1541 bomb "TOOLDIR '${TOOLDIR}' invalid"
1542 fi
1543 removedirs="${TOOLDIR}"
1544
1545 if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then
1546 if ${do_build} || ${do_distribution} || ${do_release}; then
1547 if ! ${do_build} || \
1548 [ "${uname_s}" != "NetBSD" ] || \
1549 [ "${uname_m}" != "${MACHINE}" ]; then
1550 bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'."
1551 fi
1552 if ! ${do_expertmode}; then
1553 bomb "DESTDIR must != / for non -E (expert) builds"
1554 fi
1555 statusmsg "WARNING: Building to /, in expert mode."
1556 statusmsg " This may cause your system to break! Reasons include:"
1557 statusmsg " - your kernel is not up to date"
1558 statusmsg " - the libraries or toolchain have changed"
1559 statusmsg " YOU HAVE BEEN WARNED!"
1560 fi
1561 else
1562 removedirs="${removedirs} ${DESTDIR}"
1563 fi
1564 if ${do_build} || ${do_distribution} || ${do_release}; then
1565 if ! ${do_expertmode} && \
1566 [ "$id_u" -ne 0 ] && \
1567 [ "${MKUNPRIVED}" = "no" ] ; then
1568 bomb "-U or -E must be set for build as an unprivileged user."
1569 fi
1570 fi
1571 if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then
1572 bomb "Must set RELEASEDIR with \`releasekernel=...'"
1573 fi
1574
1575 # Install as non-root is a bad idea.
1576 #
1577 if ${do_install} && [ "$id_u" -ne 0 ] ; then
1578 if ${do_expertmode}; then
1579 warning "Will install as an unprivileged user."
1580 else
1581 bomb "-E must be set for install as an unprivileged user."
1582 fi
1583 fi
1584
1585 # If a previous build.sh run used -U (and therefore created a
1586 # METALOG file), then most subsequent build.sh runs must also
1587 # use -U. If DESTDIR is about to be removed, then don't perform
1588 # this check.
1589 #
1590 case "${do_removedirs} ${removedirs} " in
1591 true*" ${DESTDIR} "*)
1592 # DESTDIR is about to be removed
1593 ;;
1594 *)
1595 if ( ${do_build} || ${do_distribution} || ${do_release} || \
1596 ${do_install} ) && \
1597 [ -e "${DESTDIR}/METALOG" ] && \
1598 [ "${MKUNPRIVED}" = "no" ] ; then
1599 if $do_expertmode; then
1600 warning "A previous build.sh run specified -U."
1601 else
1602 bomb "A previous build.sh run specified -U; you must specify it again now."
1603 fi
1604 fi
1605 ;;
1606 esac
1607
1608 # live-image and install-image targets require binary sets
1609 # (actually DESTDIR/etc/mtree/set.* files) built with MKUNPRIVED.
1610 # If release operation is specified with live-image or install-image,
1611 # the release op should be performed with -U for later image ops.
1612 #
1613 if ${do_release} && ( ${do_live_image} || ${do_install_image} ) && \
1614 [ "${MKUNPRIVED}" = "no" ] ; then
1615 bomb "-U must be specified on building release to create images later."
1616 fi
1617 }
1618
1619
1620 createmakewrapper()
1621 {
1622 # Remove the target directories.
1623 #
1624 if ${do_removedirs}; then
1625 for f in ${removedirs}; do
1626 statusmsg "Removing ${f}"
1627 ${runcmd} rm -r -f "${f}"
1628 done
1629 fi
1630
1631 # Recreate $TOOLDIR.
1632 #
1633 ${runcmd} mkdir -p "${TOOLDIR}/bin" ||
1634 bomb "mkdir of '${TOOLDIR}/bin' failed"
1635
1636 # If we did not previously rebuild ${toolprefix}make, then
1637 # check whether $make is still valid and the same as the output
1638 # from print_tooldir_make. If not, then rebuild make now. A
1639 # possible reason for this being necessary is that the actual
1640 # value of TOOLDIR might be different from the value guessed
1641 # before the top level obj dir was created.
1642 #
1643 if ! ${done_rebuildmake} && \
1644 ( [ ! -x "$make" ] || [ "$make" != "$(print_tooldir_make)" ] )
1645 then
1646 rebuildmake
1647 fi
1648
1649 # Install ${toolprefix}make if it was built.
1650 #
1651 if ${done_rebuildmake}; then
1652 ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make"
1653 ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" ||
1654 bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make"
1655 make="${TOOLDIR}/bin/${toolprefix}make"
1656 statusmsg "Created ${make}"
1657 fi
1658
1659 # Build a ${toolprefix}make wrapper script, usable by hand as
1660 # well as by build.sh.
1661 #
1662 if [ -z "${makewrapper}" ]; then
1663 makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}"
1664 [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}"
1665 fi
1666
1667 ${runcmd} rm -f "${makewrapper}"
1668 if [ "${runcmd}" = "echo" ]; then
1669 echo 'cat <<EOF >'${makewrapper}
1670 makewrapout=
1671 else
1672 makewrapout=">>\${makewrapper}"
1673 fi
1674
1675 case "${KSH_VERSION:-${SH_VERSION}}" in
1676 *PD\ KSH*|*MIRBSD\ KSH*)
1677 set +o braceexpand
1678 ;;
1679 esac
1680
1681 eval cat <<EOF ${makewrapout}
1682 #! ${HOST_SH}
1683 # Set proper variables to allow easy "make" building of a NetBSD subtree.
1684 # Generated from: \$NetBSD: build.sh,v 1.251.2.2 2012/10/30 18:46:04 yamt Exp $
1685 # with these arguments: ${_args}
1686 #
1687
1688 EOF
1689 {
1690 for f in ${makeenv}; do
1691 if eval "[ -z \"\${$f}\" -a \"\${${f}-X}\" = \"X\" ]"; then
1692 eval echo "unset ${f}"
1693 else
1694 eval echo "${f}=\'\$$(echo ${f})\'\;\ export\ ${f}"
1695 fi
1696 done
1697
1698 eval cat <<EOF
1699 MAKEWRAPPERMACHINE=${makewrappermachine:-${MACHINE}}; export MAKEWRAPPERMACHINE
1700 USETOOLS=yes; export USETOOLS
1701 EOF
1702 } | eval sort -u "${makewrapout}"
1703 eval cat <<EOF "${makewrapout}"
1704
1705 exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
1706 EOF
1707 [ "${runcmd}" = "echo" ] && echo EOF
1708 ${runcmd} chmod +x "${makewrapper}"
1709 statusmsg2 "Updated makewrapper:" "${makewrapper}"
1710 }
1711
1712 make_in_dir()
1713 {
1714 dir="$1"
1715 op="$2"
1716 ${runcmd} cd "${dir}" ||
1717 bomb "Failed to cd to \"${dir}\""
1718 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1719 bomb "Failed to make ${op} in \"${dir}\""
1720 ${runcmd} cd "${TOP}" ||
1721 bomb "Failed to cd back to \"${TOP}\""
1722 }
1723
1724 buildtools()
1725 {
1726 if [ "${MKOBJDIRS}" != "no" ]; then
1727 ${runcmd} "${makewrapper}" ${parallel} obj-tools ||
1728 bomb "Failed to make obj-tools"
1729 fi
1730 if [ "${MKUPDATE}" = "no" ]; then
1731 make_in_dir tools cleandir
1732 fi
1733 make_in_dir tools dependall
1734 make_in_dir tools install
1735 statusmsg "Tools built to ${TOOLDIR}"
1736 }
1737
1738 getkernelconf()
1739 {
1740 kernelconf="$1"
1741 if [ "${MKOBJDIRS}" != "no" ]; then
1742 # The correct value of KERNOBJDIR might
1743 # depend on a prior "make obj" in
1744 # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
1745 #
1746 KERNSRCDIR="$(getmakevar KERNSRCDIR)"
1747 KERNARCHDIR="$(getmakevar KERNARCHDIR)"
1748 make_in_dir "${KERNSRCDIR}/${KERNARCHDIR}/compile" obj
1749 fi
1750 KERNCONFDIR="$(getmakevar KERNCONFDIR)"
1751 KERNOBJDIR="$(getmakevar KERNOBJDIR)"
1752 case "${kernelconf}" in
1753 */*)
1754 kernelconfpath="${kernelconf}"
1755 kernelconfname="${kernelconf##*/}"
1756 ;;
1757 *)
1758 kernelconfpath="${KERNCONFDIR}/${kernelconf}"
1759 kernelconfname="${kernelconf}"
1760 ;;
1761 esac
1762 kernelbuildpath="${KERNOBJDIR}/${kernelconfname}"
1763 }
1764
1765 buildkernel()
1766 {
1767 if ! ${do_tools} && ! ${buildkernelwarned:-false}; then
1768 # Building tools every time we build a kernel is clearly
1769 # unnecessary. We could try to figure out whether rebuilding
1770 # the tools is necessary this time, but it doesn't seem worth
1771 # the trouble. Instead, we say it's the user's responsibility
1772 # to rebuild the tools if necessary.
1773 #
1774 statusmsg "Building kernel without building new tools"
1775 buildkernelwarned=true
1776 fi
1777 getkernelconf $1
1778 statusmsg2 "Building kernel:" "${kernelconf}"
1779 statusmsg2 "Build directory:" "${kernelbuildpath}"
1780 ${runcmd} mkdir -p "${kernelbuildpath}" ||
1781 bomb "Cannot mkdir: ${kernelbuildpath}"
1782 if [ "${MKUPDATE}" = "no" ]; then
1783 make_in_dir "${kernelbuildpath}" cleandir
1784 fi
1785 [ -x "${TOOLDIR}/bin/${toolprefix}config" ] \
1786 || bomb "${TOOLDIR}/bin/${toolprefix}config does not exist. You need to \"$0 tools\" first."
1787 ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" -b "${kernelbuildpath}" \
1788 -s "${TOP}/sys" "${kernelconfpath}" ||
1789 bomb "${toolprefix}config failed for ${kernelconf}"
1790 make_in_dir "${kernelbuildpath}" depend
1791 make_in_dir "${kernelbuildpath}" all
1792
1793 if [ "${runcmd}" != "echo" ]; then
1794 statusmsg "Kernels built from ${kernelconf}:"
1795 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1796 for kern in ${kernlist:-netbsd}; do
1797 [ -f "${kernelbuildpath}/${kern}" ] && \
1798 echo " ${kernelbuildpath}/${kern}"
1799 done | tee -a "${results}"
1800 fi
1801 }
1802
1803 releasekernel()
1804 {
1805 getkernelconf $1
1806 kernelreldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel"
1807 ${runcmd} mkdir -p "${kernelreldir}"
1808 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1809 for kern in ${kernlist:-netbsd}; do
1810 builtkern="${kernelbuildpath}/${kern}"
1811 [ -f "${builtkern}" ] || continue
1812 releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz"
1813 statusmsg2 "Kernel copy:" "${releasekern}"
1814 if [ "${runcmd}" = "echo" ]; then
1815 echo "gzip -c -9 < ${builtkern} > ${releasekern}"
1816 else
1817 gzip -c -9 < "${builtkern}" > "${releasekern}"
1818 fi
1819 done
1820 }
1821
1822 buildmodules()
1823 {
1824 setmakeenv MKBINUTILS no
1825 if ! ${do_tools} && ! ${buildmoduleswarned:-false}; then
1826 # Building tools every time we build modules is clearly
1827 # unnecessary as well as a kernel.
1828 #
1829 statusmsg "Building modules without building new tools"
1830 buildmoduleswarned=true
1831 fi
1832
1833 statusmsg "Building kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
1834 if [ "${MKOBJDIRS}" != "no" ]; then
1835 make_in_dir sys/modules obj
1836 fi
1837 if [ "${MKUPDATE}" = "no" ]; then
1838 make_in_dir sys/modules cleandir
1839 fi
1840 make_in_dir sys/modules dependall
1841 make_in_dir sys/modules install
1842
1843 statusmsg "Successful build of kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
1844 }
1845
1846 installmodules()
1847 {
1848 dir="$1"
1849 ${runcmd} "${makewrapper}" INSTALLMODULESDIR="${dir}" installmodules ||
1850 bomb "Failed to make installmodules to ${dir}"
1851 statusmsg "Successful installmodules to ${dir}"
1852 }
1853
1854 installworld()
1855 {
1856 dir="$1"
1857 ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld ||
1858 bomb "Failed to make installworld to ${dir}"
1859 statusmsg "Successful installworld to ${dir}"
1860 }
1861
1862 # Run rump build&link tests.
1863 #
1864 # To make this feasible for running without having to install includes and
1865 # libraries into destdir (i.e. quick), we only run ld. This is possible
1866 # since the rump kernel is a closed namespace apart from calls to rumpuser.
1867 # Therefore, if ld complains only about rumpuser symbols, rump kernel
1868 # linking was successful.
1869 #
1870 # We test that rump links with a number of component configurations.
1871 # These attempt to mimic what is encountered in the full build.
1872 # See list below. The list should probably be either autogenerated
1873 # or managed elsewhere; keep it here until a better idea arises.
1874 #
1875 # Above all, note that THIS IS NOT A SUBSTITUTE FOR A FULL BUILD.
1876 #
1877
1878 RUMP_LIBSETS='
1879 -lrump,
1880 -lrumpvfs -lrump,
1881 -lrumpvfs -lrumpdev -lrump,
1882 -lrumpnet -lrump,
1883 -lrumpkern_tty -lrumpvfs -lrump,
1884 -lrumpfs_tmpfs -lrumpvfs -lrump,
1885 -lrumpfs_ffs -lrumpfs_msdos -lrumpvfs -lrumpdev_disk -lrumpdev -lrump,
1886 -lrumpnet_virtif -lrumpnet_netinet -lrumpnet_net -lrumpnet -lrump,
1887 -lrumpnet_sockin -lrumpfs_smbfs -lrumpdev_netsmb
1888 -lrumpkern_crypto -lrumpdev -lrumpnet -lrumpvfs -lrump,
1889 -lrumpnet_sockin -lrumpfs_nfs -lrumpnet -lrumpvfs -lrump,
1890 -lrumpdev_cgd -lrumpdev_raidframe -lrumpdev_disk -lrumpdev_rnd
1891 -lrumpdev_dm -lrumpdev -lrumpvfs -lrumpkern_crypto -lrump'
1892 dorump()
1893 {
1894 local doclean=""
1895 local doobjs=""
1896
1897 # we cannot link libs without building csu, and that leads to lossage
1898 [ "${1}" != "rumptest" ] && bomb 'build.sh rump not yet functional. ' \
1899 'did you mean "rumptest"?'
1900
1901 # create obj and distrib dirs
1902 if [ "${MKOBJDIRS}" != "no" ]; then
1903 make_in_dir "${NETBSDSRCDIR}/etc/mtree" obj
1904 make_in_dir "${NETBSDSRCDIR}/sys/rump" obj
1905 fi
1906 ${runcmd} "${makewrapper}" ${parallel} do-distrib-dirs \
1907 || bomb 'could not create distrib-dirs'
1908
1909 [ "${MKUPDATE}" = "no" ] && doclean="cleandir"
1910 targlist="${doclean} ${doobjs} dependall install"
1911 # optimize: for test we build only static libs (3x test speedup)
1912 if [ "${1}" = "rumptest" ] ; then
1913 setmakeenv NOPIC 1
1914 setmakeenv NOPROFILE 1
1915 fi
1916 for cmd in ${targlist} ; do
1917 make_in_dir "${NETBSDSRCDIR}/sys/rump" ${cmd}
1918 done
1919
1920 # if we just wanted to build & install rump, we're done
1921 [ "${1}" != "rumptest" ] && return
1922
1923 ${runcmd} cd "${NETBSDSRCDIR}/sys/rump/librump/rumpkern" \
1924 || bomb "cd to rumpkern failed"
1925 md_quirks=`${runcmd} "${makewrapper}" -V '${_SYMQUIRK}'`
1926 # one little, two little, three little backslashes ...
1927 md_quirks="$(echo ${md_quirks} | sed 's,\\,\\\\,g'";s/'//g" )"
1928 ${runcmd} cd "${TOP}" || bomb "cd to ${TOP} failed"
1929 tool_ld=`${runcmd} "${makewrapper}" -V '${LD}'`
1930
1931 local oIFS="${IFS}"
1932 IFS=","
1933 for set in ${RUMP_LIBSETS} ; do
1934 IFS="${oIFS}"
1935 ${runcmd} ${tool_ld} -nostdlib -L${DESTDIR}/usr/lib \
1936 -static --whole-archive ${set} 2>&1 -o /tmp/rumptest.$$ | \
1937 awk -v quirks="${md_quirks}" '
1938 /undefined reference/ &&
1939 !/more undefined references.*follow/{
1940 if (match($NF,
1941 "`(rumpuser_|__" quirks ")") == 0)
1942 fails[NR] = $0
1943 }
1944 /cannot find -l/{fails[NR] = $0}
1945 /cannot open output file/{fails[NR] = $0}
1946 END{
1947 for (x in fails)
1948 print fails[x]
1949 exit x!=0
1950 }'
1951 [ $? -ne 0 ] && bomb "Testlink of rump failed: ${set}"
1952 done
1953 statusmsg "Rump build&link tests successful"
1954 }
1955
1956 main()
1957 {
1958 initdefaults
1959 _args=$@
1960 parseoptions "$@"
1961
1962 sanitycheck
1963
1964 build_start=$(date)
1965 statusmsg2 "${progname} command:" "$0 $*"
1966 statusmsg2 "${progname} started:" "${build_start}"
1967 statusmsg2 "NetBSD version:" "${DISTRIBVER}"
1968 statusmsg2 "MACHINE:" "${MACHINE}"
1969 statusmsg2 "MACHINE_ARCH:" "${MACHINE_ARCH}"
1970 statusmsg2 "Build platform:" "${uname_s} ${uname_r} ${uname_m}"
1971 statusmsg2 "HOST_SH:" "${HOST_SH}"
1972
1973 rebuildmake
1974 validatemakeparams
1975 createmakewrapper
1976
1977 # Perform the operations.
1978 #
1979 for op in ${operations}; do
1980 case "${op}" in
1981
1982 makewrapper)
1983 # no-op
1984 ;;
1985
1986 tools)
1987 buildtools
1988 ;;
1989
1990 sets)
1991 statusmsg "Building sets from pre-populated ${DESTDIR}"
1992 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1993 bomb "Failed to make ${op}"
1994 setdir=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
1995 statusmsg "Built sets to ${setdir}"
1996 ;;
1997
1998 cleandir|obj|build|distribution|release|sourcesets|syspkgs|params)
1999 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2000 bomb "Failed to make ${op}"
2001 statusmsg "Successful make ${op}"
2002 ;;
2003
2004 iso-image|iso-image-source)
2005 ${runcmd} "${makewrapper}" ${parallel} \
2006 CDEXTRA="$CDEXTRA" ${op} ||
2007 bomb "Failed to make ${op}"
2008 statusmsg "Successful make ${op}"
2009 ;;
2010
2011 live-image|install-image)
2012 # install-image and live-image require mtree spec files
2013 # built with UNPRIVED. Assume UNPRIVED build has been
2014 # performed if METALOG file is created in DESTDIR.
2015 if [ ! -e "${DESTDIR}/METALOG" ] ; then
2016 bomb "The release binaries must have been built with -U to create images."
2017 fi
2018 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2019 bomb "Failed to make ${op}"
2020 statusmsg "Successful make ${op}"
2021 ;;
2022 kernel=*)
2023 arg=${op#*=}
2024 buildkernel "${arg}"
2025 ;;
2026
2027 releasekernel=*)
2028 arg=${op#*=}
2029 releasekernel "${arg}"
2030 ;;
2031
2032 modules)
2033 buildmodules
2034 ;;
2035
2036 installmodules=*)
2037 arg=${op#*=}
2038 if [ "${arg}" = "/" ] && \
2039 ( [ "${uname_s}" != "NetBSD" ] || \
2040 [ "${uname_m}" != "${MACHINE}" ] ); then
2041 bomb "'${op}' must != / for cross builds."
2042 fi
2043 installmodules "${arg}"
2044 ;;
2045
2046 install=*)
2047 arg=${op#*=}
2048 if [ "${arg}" = "/" ] && \
2049 ( [ "${uname_s}" != "NetBSD" ] || \
2050 [ "${uname_m}" != "${MACHINE}" ] ); then
2051 bomb "'${op}' must != / for cross builds."
2052 fi
2053 installworld "${arg}"
2054 ;;
2055
2056 rump|rumptest)
2057 dorump "${op}"
2058 ;;
2059
2060 *)
2061 bomb "Unknown operation \`${op}'"
2062 ;;
2063
2064 esac
2065 done
2066
2067 statusmsg2 "${progname} ended:" "$(date)"
2068 if [ -s "${results}" ]; then
2069 echo "===> Summary of results:"
2070 sed -e 's/^===>//;s/^/ /' "${results}"
2071 echo "===> ."
2072 fi
2073 }
2074
2075 main "$@"
2076