build.sh revision 1.194 1 #! /usr/bin/env sh
2 # $NetBSD: build.sh,v 1.194 2008/08/16 00:10:04 lukem Exp $
3 #
4 # Copyright (c) 2001-2008 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, for a system containing no tools.
33 #
34 # This script should run on any POSIX-compliant shell. If the
35 # first "sh" found in the PATH is a POSIX-compliant shell, then
36 # you should not need to take any special action. Otherwise, you
37 # should set the environment variable HOST_SH to a POSIX-compliant
38 # shell, and invoke build.sh with that shell. (Depending on your
39 # system, one of /bin/ksh, /usr/local/bin/bash, or /usr/xpg4/bin/sh
40 # might be a suitable shell.)
41 #
42
43 progname=${0##*/}
44 toppid=$$
45 results=/dev/null
46 trap "exit 1" 1 2 3 15
47
48 bomb()
49 {
50 cat >&2 <<ERRORMESSAGE
51
52 ERROR: $@
53 *** BUILD ABORTED ***
54 ERRORMESSAGE
55 kill ${toppid} # in case we were invoked from a subshell
56 exit 1
57 }
58
59
60 statusmsg()
61 {
62 ${runcmd} echo "===> $@" | tee -a "${results}"
63 }
64
65 warning()
66 {
67 statusmsg "Warning: $@"
68 }
69
70 # Find a program in the PATH, and print the result. If not found,
71 # print a default. If $2 is defined (even if it is an empty string),
72 # then that is the default; otherwise, $1 is used as the default.
73 find_in_PATH()
74 {
75 local prog="$1"
76 local result="${2-"$1"}"
77 local oldIFS="${IFS}"
78 local dir
79 IFS=":"
80 for dir in ${PATH}; do
81 if [ -x "${dir}/${prog}" ]; then
82 result="${dir}/${prog}"
83 break
84 fi
85 done
86 IFS="${oldIFS}"
87 echo "${result}"
88 }
89
90 # Try to find a working POSIX shell, and set HOST_SH to refer to it.
91 # Assumes that uname_s, uname_m, and PWD have been set.
92 set_HOST_SH()
93 {
94 # Even if ${HOST_SH} is already defined, we still do the
95 # sanity checks at the end.
96
97 # Solaris has /usr/xpg4/bin/sh.
98 #
99 [ -z "${HOST_SH}" ] && [ x"${uname_s}" = x"SunOS" ] && \
100 [ -x /usr/xpg4/bin/sh ] && HOST_SH="/usr/xpg4/bin/sh"
101
102 # Try to get the name of the shell that's running this script,
103 # by parsing the output from "ps". We assume that, if the host
104 # system's ps command supports -o comm at all, it will do so
105 # in the usual way: a one-line header followed by a one-line
106 # result, possibly including trailing white space. And if the
107 # host system's ps command doesn't support -o comm, we assume
108 # that we'll get an error message on stderr and nothing on
109 # stdout. (We don't try to use ps -o 'comm=' to suppress the
110 # header line, because that is less widely supported.)
111 #
112 # If we get the wrong result here, the user can override it by
113 # specifying HOST_SH in the environment.
114 #
115 [ -z "${HOST_SH}" ] && HOST_SH="$(
116 (ps -p $$ -o comm | sed -ne '2s/[ \t]*$//p') 2>/dev/null )"
117
118 # If nothing above worked, use "sh". We will later find the
119 # first directory in the PATH that has a "sh" program.
120 #
121 [ -z "${HOST_SH}" ] && HOST_SH="sh"
122
123 # If the result so far is not an absolute path, try to prepend
124 # PWD or search the PATH.
125 #
126 case "${HOST_SH}" in
127 /*) :
128 ;;
129 */*) HOST_SH="${PWD}/${HOST_SH}"
130 ;;
131 *) HOST_SH="$(find_in_PATH "${HOST_SH}")"
132 ;;
133 esac
134
135 # If we don't have an absolute path by now, bomb.
136 #
137 case "${HOST_SH}" in
138 /*) :
139 ;;
140 *) bomb "HOST_SH=\"${HOST_SH}\" is not an absolute path."
141 ;;
142 esac
143
144 # If HOST_SH is not executable, bomb.
145 #
146 [ -x "${HOST_SH}" ] ||
147 bomb "HOST_SH=\"${HOST_SH}\" is not executable."
148 }
149
150 initdefaults()
151 {
152 makeenv=
153 makewrapper=
154 makewrappermachine=
155 runcmd=
156 operations=
157 removedirs=
158
159 [ -d usr.bin/make ] || cd "$(dirname $0)"
160 [ -d usr.bin/make ] ||
161 bomb "build.sh must be run from the top source level"
162 [ -f share/mk/bsd.own.mk ] ||
163 bomb "src/share/mk is missing; please re-fetch the source tree"
164
165 # Find information about the build platform. Note that "uname -p"
166 # is not part of POSIX, but NetBSD's uname -p prints MACHINE_ARCH,
167 # while uname -m prints MACHINE.
168 #
169 uname_s=$(uname -s 2>/dev/null)
170 uname_r=$(uname -r 2>/dev/null)
171 uname_m=$(uname -m 2>/dev/null)
172 uname_p=$(uname -p 2>/dev/null || uname -m 2>/dev/null)
173
174 # If $PWD is a valid name of the current directory, POSIX mandates
175 # that pwd return it by default which causes problems in the
176 # presence of symlinks. Unsetting PWD is simpler than changing
177 # every occurrence of pwd to use -P.
178 #
179 # XXX Except that doesn't work on Solaris. Or many Linuces.
180 #
181 unset PWD
182 TOP=$(/bin/pwd -P 2>/dev/null || /bin/pwd 2>/dev/null)
183
184 # The user can set HOST_SH in the environment, or we try to
185 # guess an appropriate value. Then we set several other
186 # variables from HOST_SH.
187 #
188 set_HOST_SH
189 setmakeenv HOST_SH "${HOST_SH}"
190 setmakeenv BSHELL "${HOST_SH}"
191 setmakeenv CONFIG_SHELL "${HOST_SH}"
192
193 # Set defaults.
194 #
195 toolprefix=nb
196
197 # Some systems have a small ARG_MAX. -X prevents make(1) from
198 # exporting variables in the environment redundantly.
199 #
200 case "${uname_s}" in
201 Darwin | FreeBSD | CYGWIN*)
202 MAKEFLAGS=-X
203 ;;
204 *)
205 MAKEFLAGS=
206 ;;
207 esac
208
209 # do_{operation}=true if given operation is requested.
210 #
211 do_expertmode=false
212 do_rebuildmake=false
213 do_removedirs=false
214 do_tools=false
215 do_obj=false
216 do_build=false
217 do_distribution=false
218 do_release=false
219 do_kernel=false
220 do_releasekernel=false
221 do_install=false
222 do_sets=false
223 do_sourcesets=false
224 do_syspkgs=false
225 do_iso_image=false
226 do_iso_image_source=false
227 do_params=false
228
229 # Create scratch directory
230 #
231 tmpdir="${TMPDIR-/tmp}/nbbuild$$"
232 mkdir "${tmpdir}" || bomb "Cannot mkdir: ${tmpdir}"
233 trap "cd /; rm -r -f \"${tmpdir}\"" 0
234 results="${tmpdir}/build.sh.results"
235
236 # Set source directories
237 #
238 setmakeenv NETBSDSRCDIR "${TOP}"
239
240 # Determine top-level obj directory.
241 # Defaults to the top-level source directory.
242 # If $MAKEOBJDIRPREFIX is set in the environment, use it.
243 # We can't check $MAKEOBJDIR since that may be a make(1)
244 # expression that we can't evaluate at this time.
245 #
246 TOP_objdir="${TOP}"
247 if [ -n "${MAKEOBJDIRPREFIX}" ]; then
248 TOP_objdir="${MAKEOBJDIRPREFIX}${TOP}"
249 elif [ -n "${MAKEOBJDIR}" ]; then
250 warning "Can't parse \$(MAKEOBJDIR) \"$MAKEOBJDIR\" to determine top objdir"
251 fi
252
253 # Find the version of NetBSD
254 #
255 DISTRIBVER="$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh)"
256
257 # Set the BUILDSEED to NetBSD-"N"
258 #
259 setmakeenv BUILDSEED "NetBSD-$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh -m)"
260
261 # Set various environment variables to known defaults,
262 # to minimize (cross-)build problems observed "in the field".
263 #
264 unsetmakeenv INFODIR
265 unsetmakeenv LESSCHARSET
266 setmakeenv LC_ALL C
267 }
268
269 getarch()
270 {
271 # Translate some MACHINE name aliases (known only to build.sh)
272 # into proper MACHINE and MACHINE_ARCH names. Save the alias
273 # name in makewrappermachine.
274 #
275 case "${MACHINE}" in
276
277 evbarm-e[bl])
278 makewrappermachine=${MACHINE}
279 # MACHINE_ARCH is "arm" or "armeb", not "armel"
280 MACHINE_ARCH=arm${MACHINE##*-}
281 MACHINE_ARCH=${MACHINE_ARCH%el}
282 MACHINE=${MACHINE%-e[bl]}
283 ;;
284
285 evbmips-e[bl]|sbmips-e[bl])
286 makewrappermachine=${MACHINE}
287 MACHINE_ARCH=mips${MACHINE##*-}
288 MACHINE=${MACHINE%-e[bl]}
289 ;;
290
291 evbmips64-e[bl]|sbmips64-e[bl])
292 makewrappermachine=${MACHINE}
293 MACHINE_ARCH=mips64${MACHINE##*-}
294 MACHINE=${MACHINE%64-e[bl]}
295 ;;
296
297 evbsh3-e[bl])
298 makewrappermachine=${MACHINE}
299 MACHINE_ARCH=sh3${MACHINE##*-}
300 MACHINE=${MACHINE%-e[bl]}
301 ;;
302
303 esac
304
305 # Translate a MACHINE into a default MACHINE_ARCH.
306 #
307 case "${MACHINE}" in
308
309 acorn26|acorn32|cats|hpcarm|iyonix|netwinder|shark|zaurus)
310 MACHINE_ARCH=arm
311 ;;
312
313 evbarm) # unspecified MACHINE_ARCH gets LE
314 MACHINE_ARCH=${MACHINE_ARCH:=arm}
315 ;;
316
317 hp700)
318 MACHINE_ARCH=hppa
319 ;;
320
321 sun2)
322 MACHINE_ARCH=m68000
323 ;;
324
325 amiga|atari|cesfic|hp300|luna68k|mac68k|mvme68k|news68k|next68k|sun3|x68k)
326 MACHINE_ARCH=m68k
327 ;;
328
329 evbmips|sbmips) # no default MACHINE_ARCH
330 ;;
331
332 ews4800mips|mipsco|newsmips|sgimips)
333 MACHINE_ARCH=mipseb
334 ;;
335
336 algor|arc|cobalt|hpcmips|playstation2|pmax)
337 MACHINE_ARCH=mipsel
338 ;;
339
340 evbppc64|macppc64|ofppc64)
341 makewrappermachine=${MACHINE}
342 MACHINE=${MACHINE%64}
343 MACHINE_ARCH=powerpc64
344 ;;
345
346 amigappc|bebox|evbppc|ibmnws|macppc|mvmeppc|ofppc|prep|rs6000|sandpoint)
347 MACHINE_ARCH=powerpc
348 ;;
349
350 evbsh3) # no default MACHINE_ARCH
351 ;;
352
353 mmeye)
354 MACHINE_ARCH=sh3eb
355 ;;
356
357 dreamcast|hpcsh|landisk)
358 MACHINE_ARCH=sh3el
359 ;;
360
361 amd64)
362 MACHINE_ARCH=x86_64
363 ;;
364
365 alpha|i386|sparc|sparc64|vax|ia64)
366 MACHINE_ARCH=${MACHINE}
367 ;;
368
369 *)
370 bomb "Unknown target MACHINE: ${MACHINE}"
371 ;;
372
373 esac
374 }
375
376 validatearch()
377 {
378 # Ensure that the MACHINE_ARCH exists (and is supported by build.sh).
379 #
380 case "${MACHINE_ARCH}" in
381
382 alpha|arm|armeb|hppa|i386|m68000|m68k|mipse[bl]|mips64e[bl]|powerpc|powerpc64|sh3e[bl]|sparc|sparc64|vax|x86_64|ia64)
383 ;;
384
385 "")
386 bomb "No MACHINE_ARCH provided"
387 ;;
388
389 *)
390 bomb "Unknown target MACHINE_ARCH: ${MACHINE_ARCH}"
391 ;;
392
393 esac
394
395 # Determine valid MACHINE_ARCHs for MACHINE
396 #
397 case "${MACHINE}" in
398
399 evbarm)
400 arches="arm armeb"
401 ;;
402
403 evbmips|sbmips)
404 arches="mipseb mipsel mips64eb mips64el"
405 ;;
406
407 sgimips)
408 arches="mipseb mips64eb"
409 ;;
410
411 evbsh3)
412 arches="sh3eb sh3el"
413 ;;
414
415 macppc|evbppc|ofppc)
416 arches="powerpc powerpc64"
417 ;;
418 *)
419 oma="${MACHINE_ARCH}"
420 getarch
421 arches="${MACHINE_ARCH}"
422 MACHINE_ARCH="${oma}"
423 ;;
424
425 esac
426
427 # Ensure that MACHINE_ARCH supports MACHINE
428 #
429 archok=false
430 for a in ${arches}; do
431 if [ "${a}" = "${MACHINE_ARCH}" ]; then
432 archok=true
433 break
434 fi
435 done
436 ${archok} ||
437 bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'"
438 }
439
440 nobomb_getmakevar()
441 {
442 [ -x "${make}" ] || return 1
443 "${make}" -m ${TOP}/share/mk -s -B -f- _x_ <<EOF || return 1
444 _x_:
445 echo \${$1}
446 .include <bsd.prog.mk>
447 .include <bsd.kernobj.mk>
448 EOF
449 }
450
451 raw_getmakevar()
452 {
453 [ -x "${make}" ] || bomb "raw_getmakevar $1: ${make} is not executable"
454 nobomb_getmakevar "$1" || bomb "raw_getmakevar $1: ${make} failed"
455 }
456
457 getmakevar()
458 {
459 # raw_getmakevar() doesn't work properly if $make hasn't yet been
460 # built, which can happen when running with the "-n" option.
461 # getmakevar() deals with this by emitting a literal '$'
462 # followed by the variable name, instead of trying to find the
463 # variable's value.
464 #
465 if [ -x "${make}" ]; then
466 raw_getmakevar "$1"
467 else
468 echo "\$$1"
469 fi
470 }
471
472 setmakeenv()
473 {
474 eval "$1='$2'; export $1"
475 makeenv="${makeenv} $1"
476 }
477
478 unsetmakeenv()
479 {
480 eval "unset $1"
481 makeenv="${makeenv} $1"
482 }
483
484 # Convert possibly-relative paths to absolute paths by prepending
485 # ${TOP} if necessary. Also delete trailing "/", if any.
486 resolvepaths()
487 {
488 _OPTARG=
489 for oa in ${OPTARG}; do
490 case "${oa}" in
491 /)
492 ;;
493 /*)
494 oa="${oa%/}"
495 ;;
496 *)
497 oa="${TOP}/${oa%/}"
498 ;;
499 esac
500 _OPTARG="${_OPTARG} ${oa}"
501 done
502 OPTARG="${_OPTARG}"
503 }
504
505 # Convert possibly-relative path to absolute path by prepending
506 # ${TOP} if necessary. Also delete trailing "/", if any.
507 resolvepath()
508 {
509 case "${OPTARG}" in
510 /)
511 ;;
512 /*)
513 OPTARG="${OPTARG%/}"
514 ;;
515 *)
516 OPTARG="${TOP}/${OPTARG%/}"
517 ;;
518 esac
519 }
520
521 usage()
522 {
523 if [ -n "$*" ]; then
524 echo ""
525 echo "${progname}: $*"
526 fi
527 cat <<_usage_
528
529 Usage: ${progname} [-EnorUux] [-a arch] [-B buildid] [-C cdextras]
530 [-D dest] [-j njob] [-M obj] [-m mach] [-N noisy]
531 [-O obj] [-R release] [-S seed] [-T tools]
532 [-V var=[value]] [-w wrapper] [-X x11src] [-Z var]
533 operation [...]
534
535 Build operations (all imply "obj" and "tools"):
536 build Run "make build".
537 distribution Run "make distribution" (includes DESTDIR/etc/ files).
538 release Run "make release" (includes kernels & distrib media).
539
540 Other operations:
541 help Show this message and exit.
542 makewrapper Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make.
543 Always performed.
544 obj Run "make obj". [Default unless -o is used]
545 tools Build and install tools.
546 install=idir Run "make installworld" to \`idir' to install all sets
547 except \`etc'. Useful after "distribution" or "release"
548 kernel=conf Build kernel with config file \`conf'
549 releasekernel=conf Install kernel built by kernel=conf to RELEASEDIR.
550 sets Create binary sets in
551 RELEASEDIR/RELEASEMACHINEDIR/binary/sets.
552 DESTDIR should be populated beforehand.
553 sourcesets Create source sets in RELEASEDIR/source/sets.
554 syspkgs Create syspkgs in
555 RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.
556 iso-image Create CD-ROM image in RELEASEDIR/iso.
557 iso-image-source Create CD-ROM image with source in RELEASEDIR/iso.
558 params Display various make(1) parameters.
559
560 Options:
561 -a arch Set MACHINE_ARCH to arch. [Default: deduced from MACHINE]
562 -B buildId Set BUILDID to buildId.
563 -C cdextras Set CDEXTRA to cdextras
564 -D dest Set DESTDIR to dest. [Default: destdir.MACHINE]
565 -E Set "expert" mode; disables various safety checks.
566 Should not be used without expert knowledge of the build system.
567 -h Print this help message.
568 -j njob Run up to njob jobs in parallel; see make(1) -j.
569 -M obj Set obj root directory to obj; sets MAKEOBJDIRPREFIX.
570 Unsets MAKEOBJDIR.
571 -m mach Set MACHINE to mach; not required if NetBSD native.
572 -N noisy Set the noisyness (MAKEVERBOSE) level of the build:
573 0 Quiet
574 1 Operations are described, commands are suppressed
575 2 Full output
576 [Default: 2]
577 -n Show commands that would be executed, but do not execute them.
578 -O obj Set obj root directory to obj; sets a MAKEOBJDIR pattern.
579 Unsets MAKEOBJDIRPREFIX.
580 -o Set MKOBJDIRS=no; do not create objdirs at start of build.
581 -R release Set RELEASEDIR to release. [Default: releasedir]
582 -r Remove contents of TOOLDIR and DESTDIR before building.
583 -S seed Set BUILDSEED to seed. [Default: NetBSD-majorversion]
584 -T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in
585 the environment, ${toolprefix}make will be (re)built unconditionally.
586 -U Set MKUNPRIVED=yes; build without requiring root privileges,
587 install from an UNPRIVED build with proper file permissions.
588 -u Set MKUPDATE=yes; do not run "make cleandir" first.
589 Without this, everything is rebuilt, including the tools.
590 -V v=[val] Set variable \`v' to \`val'.
591 -w wrapper Create ${toolprefix}make script as wrapper.
592 [Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE}]
593 -X x11src Set X11SRCDIR to x11src. [Default: /usr/xsrc]
594 -x Set MKX11=yes; build X11R6 from X11SRCDIR
595 -Z v Unset ("zap") variable \`v'.
596
597 _usage_
598 exit 1
599 }
600
601 parseoptions()
602 {
603 opts='a:B:bC:D:dEhi:j:k:M:m:N:nO:oR:rS:T:tUuV:w:xX:Z:'
604 opt_a=no
605
606 if type getopts >/dev/null 2>&1; then
607 # Use POSIX getopts.
608 #
609 getoptcmd='getopts ${opts} opt && opt=-${opt}'
610 optargcmd=':'
611 optremcmd='shift $((${OPTIND} -1))'
612 else
613 type getopt >/dev/null 2>&1 ||
614 bomb "/bin/sh shell is too old; try ksh or bash"
615
616 # Use old-style getopt(1) (doesn't handle whitespace in args).
617 #
618 args="$(getopt ${opts} $*)"
619 [ $? = 0 ] || usage
620 set -- ${args}
621
622 getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
623 optargcmd='OPTARG="$1"; shift'
624 optremcmd=':'
625 fi
626
627 # Parse command line options.
628 #
629 while eval ${getoptcmd}; do
630 case ${opt} in
631
632 -a)
633 eval ${optargcmd}
634 MACHINE_ARCH=${OPTARG}
635 opt_a=yes
636 ;;
637
638 -B)
639 eval ${optargcmd}
640 BUILDID=${OPTARG}
641 ;;
642
643 -b)
644 usage "'-b' has been replaced by 'makewrapper'"
645 ;;
646
647 -C)
648 eval ${optargcmd}; resolvepaths
649 iso_dir=${OPTARG}
650 ;;
651
652 -D)
653 eval ${optargcmd}; resolvepath
654 setmakeenv DESTDIR "${OPTARG}"
655 ;;
656
657 -d)
658 usage "'-d' has been replaced by 'distribution'"
659 ;;
660
661 -E)
662 do_expertmode=true
663 ;;
664
665 -i)
666 usage "'-i idir' has been replaced by 'install=idir'"
667 ;;
668
669 -j)
670 eval ${optargcmd}
671 parallel="-j ${OPTARG}"
672 ;;
673
674 -k)
675 usage "'-k conf' has been replaced by 'kernel=conf'"
676 ;;
677
678 -M)
679 eval ${optargcmd}; resolvepath
680 TOP_objdir="${OPTARG}${TOP}"
681 unsetmakeenv MAKEOBJDIR
682 setmakeenv MAKEOBJDIRPREFIX "${OPTARG}"
683 ;;
684
685 # -m overrides MACHINE_ARCH unless "-a" is specified
686 -m)
687 eval ${optargcmd}
688 MACHINE="${OPTARG}"
689 [ "${opt_a}" != "yes" ] && getarch
690 ;;
691
692 -N)
693 eval ${optargcmd}
694 case "${OPTARG}" in
695 0|1|2)
696 setmakeenv MAKEVERBOSE "${OPTARG}"
697 ;;
698 *)
699 usage "'${OPTARG}' is not a valid value for -N"
700 ;;
701 esac
702 ;;
703
704 -n)
705 runcmd=echo
706 ;;
707
708 -O)
709 eval ${optargcmd}; resolvepath
710 TOP_objdir="${OPTARG}"
711 unsetmakeenv MAKEOBJDIRPREFIX
712 setmakeenv MAKEOBJDIR "\${.CURDIR:C,^$TOP,$OPTARG,}"
713 ;;
714
715 -o)
716 MKOBJDIRS=no
717 ;;
718
719 -R)
720 eval ${optargcmd}; resolvepath
721 setmakeenv RELEASEDIR "${OPTARG}"
722 ;;
723
724 -r)
725 do_removedirs=true
726 do_rebuildmake=true
727 ;;
728
729 -S)
730 eval ${optargcmd}
731 setmakeenv BUILDSEED "${OPTARG}"
732 ;;
733
734 -T)
735 eval ${optargcmd}; resolvepath
736 TOOLDIR="${OPTARG}"
737 export TOOLDIR
738 ;;
739
740 -t)
741 usage "'-t' has been replaced by 'tools'"
742 ;;
743
744 -U)
745 setmakeenv MKUNPRIVED yes
746 ;;
747
748 -u)
749 setmakeenv MKUPDATE yes
750 ;;
751
752 -V)
753 eval ${optargcmd}
754 case "${OPTARG}" in
755 # XXX: consider restricting which variables can be changed?
756 [a-zA-Z_][a-zA-Z_0-9]*=*)
757 setmakeenv "${OPTARG%%=*}" "${OPTARG#*=}"
758 ;;
759 *)
760 usage "-V argument must be of the form 'var=[value]'"
761 ;;
762 esac
763 ;;
764
765 -w)
766 eval ${optargcmd}; resolvepath
767 makewrapper="${OPTARG}"
768 ;;
769
770 -X)
771 eval ${optargcmd}; resolvepath
772 setmakeenv X11SRCDIR "${OPTARG}"
773 ;;
774
775 -x)
776 setmakeenv MKX11 yes
777 ;;
778
779 -Z)
780 eval ${optargcmd}
781 # XXX: consider restricting which variables can be unset?
782 unsetmakeenv "${OPTARG}"
783 ;;
784
785 --)
786 break
787 ;;
788
789 -'?'|-h)
790 usage
791 ;;
792
793 esac
794 done
795
796 # Validate operations.
797 #
798 eval ${optremcmd}
799 while [ $# -gt 0 ]; do
800 op=$1; shift
801 operations="${operations} ${op}"
802
803 case "${op}" in
804
805 help)
806 usage
807 ;;
808
809 makewrapper|obj|tools|build|distribution|release|sets|sourcesets|syspkgs|params)
810 ;;
811
812 iso-image)
813 op=iso_image # used as part of a variable name
814 ;;
815
816 iso-image-source)
817 op=iso_image_source # used as part of a variable name
818 ;;
819
820 kernel=*|releasekernel=*)
821 arg=${op#*=}
822 op=${op%%=*}
823 [ -n "${arg}" ] ||
824 bomb "Must supply a kernel name with \`${op}=...'"
825 ;;
826
827 install=*)
828 arg=${op#*=}
829 op=${op%%=*}
830 [ -n "${arg}" ] ||
831 bomb "Must supply a directory with \`install=...'"
832 ;;
833
834 *)
835 usage "Unknown operation \`${op}'"
836 ;;
837
838 esac
839 eval do_${op}=true
840 done
841 [ -n "${operations}" ] || usage "Missing operation to perform."
842
843 # Set up MACHINE*. On a NetBSD host, these are allowed to be unset.
844 #
845 if [ -z "${MACHINE}" ]; then
846 [ "${uname_s}" = "NetBSD" ] ||
847 bomb "MACHINE must be set, or -m must be used, for cross builds."
848 MACHINE=${uname_m}
849 fi
850 [ -n "${MACHINE_ARCH}" ] || getarch
851 validatearch
852
853 # Set up default make(1) environment.
854 #
855 makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
856 [ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID"
857 MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}"
858 export MAKEFLAGS MACHINE MACHINE_ARCH
859 }
860
861 sanitycheck()
862 {
863 # If the PATH contains any non-absolute components (including,
864 # but not limited to, "." or ""), then complain. As an exception,
865 # allow "" or "." as the last component of the PATH. This is fatal
866 # if expert mode is not in effect.
867 #
868 local path="${PATH}"
869 path="${path%:}" # delete trailing ":"
870 path="${path%:.}" # delete trailing ":."
871 case ":${path}:/" in
872 *:[!/]*)
873 if ${do_expertmode}; then
874 warning "PATH contains non-absolute components"
875 else
876 bomb "PATH environment variable must not" \
877 "contain non-absolute components"
878 fi
879 ;;
880 esac
881 }
882
883 # Try to set a value for TOOLDIR. This is difficult because of a cyclic
884 # dependency: TOOLDIR may be affected by settings in /etc/mk.conf, so
885 # we would like to use getmakevar to get the value of TOOLDIR, but we
886 # can't use getmakevar before we have an up to date version of nbmake;
887 # we might already have an up to date version of nbmake in TOOLDIR, but
888 # we don't yet know where TOOLDIR is.
889 #
890 # In principle, we could break the cycle by building a copy of nbmake
891 # in a temporary directory. However, people who use the default value
892 # of TOOLDIR do not like to have nbmake rebuilt every time they run
893 # build.sh.
894 #
895 # We try to please everybody as follows:
896 #
897 # * If TOOLDIR was set in the environment or on the command line, use
898 # that value.
899 # * Otherwise try to guess what TOOLDIR would be if not overridden by
900 # /etc/mk.conf, and check whether the resulting directory contains
901 # a copy of ${toolprefix}make (this should work for everybody who
902 # doesn't override TOOLDIR via /etc/mk.conf);
903 # * Failing that, search for ${toolprefix}make, nbmake, bmake, or make,
904 # in the PATH (this might accidentally find a non-NetBSD version of
905 # make, which will lead to failure in the next step);
906 # * If a copy of make was found above, try to use it with
907 # nobomb_getmakevar to find the correct value for TOOLDIR;
908 # * If all else fails, leave TOOLDIR unset. Our caller is expected to
909 # be able to cope with this.
910 #
911 try_set_TOOLDIR()
912 {
913 [ -n "${TOOLDIR}" ] && return
914
915 # Set guess_TOOLDIR, in the same way that <bsd.own.mk> would set
916 # TOOLDIR if /etc/mk.conf isn't interfering.
917 local host_ostype="${uname_s}-$(
918 echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
919 )-$(
920 echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
921 )"
922 local guess_TOOLDIR="${TOP_objdir}/tooldir.${host_ostype}"
923
924 # Look for a suitable ${toolprefix}make, nbmake, bmake, or make.
925 guess_make="${guess_TOOLDIR}/bin/${toolprefix}make"
926 [ -x "${guess_make}" ] || guess_make=""
927 : ${guess_make:=$(find_in_PATH ${toolprefix}make '')}
928 : ${guess_make:=$(find_in_PATH nbmake '')}
929 : ${guess_make:=$(find_in_PATH bmake '')}
930 : ${guess_make:=$(find_in_PATH make '')}
931
932 # Use ${guess_make} with nobomb_getmakevar
933 if [ -x "${guess_make}" ]; then
934 TOOLDIR=$(make="${guess_make}" nobomb_getmakevar TOOLDIR)
935 [ $? -eq 0 -a -n "${TOOLDIR}" ] || unset TOOLDIR
936 fi
937 }
938
939 rebuildmake()
940 {
941 # Test make source file timestamps against installed ${toolprefix}make
942 # binary, if TOOLDIR is pre-set or if try_set_TOOLDIR can set it.
943 #
944 try_set_TOOLDIR
945 make="${TOOLDIR-nonexistent}/bin/${toolprefix}make"
946 if [ -x "${make}" ]; then
947 for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
948 if [ "${f}" -nt "${make}" ]; then
949 statusmsg "${make} outdated (older than ${f}), needs building."
950 do_rebuildmake=true
951 break
952 fi
953 done
954 else
955 statusmsg "No ${make}, needs building."
956 do_rebuildmake=true
957 fi
958
959 # Build bootstrap ${toolprefix}make if needed.
960 if ${do_rebuildmake}; then
961 statusmsg "Bootstrapping ${toolprefix}make"
962 ${runcmd} cd "${tmpdir}"
963 ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
964 CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
965 ${HOST_SH} "${TOP}/tools/make/configure" ||
966 bomb "Configure of ${toolprefix}make failed"
967 ${runcmd} ${HOST_SH} buildmake.sh ||
968 bomb "Build of ${toolprefix}make failed"
969 make="${tmpdir}/${toolprefix}make"
970 ${runcmd} cd "${TOP}"
971 ${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
972 fi
973 }
974
975 validatemakeparams()
976 {
977 if [ "${runcmd}" = "echo" ]; then
978 TOOLCHAIN_MISSING=no
979 EXTERNAL_TOOLCHAIN=""
980 else
981 TOOLCHAIN_MISSING=$(raw_getmakevar TOOLCHAIN_MISSING)
982 EXTERNAL_TOOLCHAIN=$(raw_getmakevar EXTERNAL_TOOLCHAIN)
983 fi
984 if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
985 [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
986 ${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
987 ${runcmd} echo " MACHINE: ${MACHINE}"
988 ${runcmd} echo " MACHINE_ARCH: ${MACHINE_ARCH}"
989 ${runcmd} echo ""
990 ${runcmd} echo "All builds for this platform should be done via a traditional make"
991 ${runcmd} echo "If you wish to use an external cross-toolchain, set"
992 ${runcmd} echo " EXTERNAL_TOOLCHAIN=<path to toolchain root>"
993 ${runcmd} echo "in either the environment or mk.conf and rerun"
994 ${runcmd} echo " ${progname} $*"
995 exit 1
996 fi
997
998 # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE
999 # These may be set as build.sh options or in "mk.conf".
1000 # Don't export them as they're only used for tests in build.sh.
1001 #
1002 MKOBJDIRS=$(getmakevar MKOBJDIRS)
1003 MKUNPRIVED=$(getmakevar MKUNPRIVED)
1004 MKUPDATE=$(getmakevar MKUPDATE)
1005
1006 if [ "${MKOBJDIRS}" != "no" ]; then
1007 # Try to create the top level object directory before
1008 # running "make obj", otherwise <bsd.own.mk> will not
1009 # set the correct value for _SRC_TOP_OBJ_.
1010 #
1011 # If either -M or -O was specified, then we have the
1012 # directory name already.
1013 #
1014 # If neither -M nor -O was specified, then try to get
1015 # the directory name from bsd.obj.mk's __usrobjdir
1016 # variable, which is set using complex rules. This
1017 # works only if TOP = /usr/src.
1018 #
1019 top_obj_dir="${TOP_objdir}"
1020 if [ -z "${top_obj_dir}" ]; then
1021 if [ "$TOP" = "/usr/src" ]; then
1022 top_obj_dir="$(getmakevar __usrobjdir)"
1023 # else __usrobjdir is not actually used
1024 fi
1025
1026 fi
1027 case "$top_obj_dir" in
1028 */*)
1029 ${runcmd} mkdir -p "${top_obj_dir}" \
1030 || bomb "Can't create object" \
1031 "directory ${top_obj_dir}"
1032 ;;
1033 *)
1034 # We don't know what the top level object
1035 # directory should be, so we can't create it.
1036 # A nonexistant directory might cause an error
1037 # when we "make obj" later, but we ignore it for
1038 # now.
1039 ;;
1040 esac
1041
1042 # make obj in tools to ensure that the objdir for the top-level
1043 # of the source tree and for "tools" is available, in case the
1044 # default TOOLDIR setting from <bsd.own.mk> is used, or the
1045 # build.sh default DESTDIR and RELEASEDIR is to be used.
1046 #
1047 ${runcmd} cd tools
1048 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1049 bomb "Failed to make obj in tools"
1050 ${runcmd} cd "${TOP}"
1051 fi
1052
1053 # Find TOOLDIR, DESTDIR, RELEASEDIR, and RELEASEMACHINEDIR.
1054 #
1055 TOOLDIR=$(getmakevar TOOLDIR)
1056 statusmsg "TOOLDIR path: ${TOOLDIR}"
1057 DESTDIR=$(getmakevar DESTDIR)
1058 RELEASEDIR=$(getmakevar RELEASEDIR)
1059 RELEASEMACHINEDIR=$(getmakevar RELEASEMACHINEDIR)
1060 if ! $do_expertmode; then
1061 _SRC_TOP_OBJ_=$(getmakevar _SRC_TOP_OBJ_)
1062 : ${DESTDIR:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}}
1063 : ${RELEASEDIR:=${_SRC_TOP_OBJ_}/releasedir}
1064 makeenv="${makeenv} DESTDIR RELEASEDIR"
1065 fi
1066 export TOOLDIR DESTDIR RELEASEDIR
1067 statusmsg "DESTDIR path: ${DESTDIR}"
1068 statusmsg "RELEASEDIR path: ${RELEASEDIR}"
1069
1070 # Check validity of TOOLDIR and DESTDIR.
1071 #
1072 if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then
1073 bomb "TOOLDIR '${TOOLDIR}' invalid"
1074 fi
1075 removedirs="${TOOLDIR}"
1076
1077 if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then
1078 if ${do_build} || ${do_distribution} || ${do_release}; then
1079 if ! ${do_build} || \
1080 [ "${uname_s}" != "NetBSD" ] || \
1081 [ "${uname_m}" != "${MACHINE}" ]; then
1082 bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'."
1083 fi
1084 if ! ${do_expertmode}; then
1085 bomb "DESTDIR must != / for non -E (expert) builds"
1086 fi
1087 statusmsg "WARNING: Building to /, in expert mode."
1088 statusmsg " This may cause your system to break! Reasons include:"
1089 statusmsg " - your kernel is not up to date"
1090 statusmsg " - the libraries or toolchain have changed"
1091 statusmsg " YOU HAVE BEEN WARNED!"
1092 fi
1093 else
1094 removedirs="${removedirs} ${DESTDIR}"
1095 fi
1096 if ${do_build} || ${do_distribution} || ${do_release}; then
1097 if ! ${do_expertmode} && \
1098 [ "$(id -u 2>/dev/null)" -ne 0 ] && \
1099 [ "${MKUNPRIVED}" = "no" ] ; then
1100 bomb "-U or -E must be set for build as an unprivileged user."
1101 fi
1102 fi
1103 if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then
1104 bomb "Must set RELEASEDIR with \`releasekernel=...'"
1105 fi
1106
1107 # Install as non-root is a bad idea.
1108 #
1109 if ${do_install} && [ "$(id -u 2>/dev/null)" -ne 0 ] ; then
1110 if ${do_expertmode}; then
1111 warning "Will install as an unprivileged user."
1112 else
1113 bomb "-E must be set for install as an unprivileged user."
1114 fi
1115 fi
1116
1117 # If a previous build.sh run used -U (and therefore created a
1118 # METALOG file), then most subsequent build.sh runs must also
1119 # use -U. If DESTDIR is about to be removed, then don't perform
1120 # this check.
1121 #
1122 case "${do_removedirs} ${removedirs} " in
1123 true*" ${DESTDIR} "*)
1124 # DESTDIR is about to be removed
1125 ;;
1126 *)
1127 if ( ${do_build} || ${do_distribution} || ${do_release} || \
1128 ${do_install} ) && \
1129 [ -e "${DESTDIR}/METALOG" ] && \
1130 [ "${MKUNPRIVED}" = "no" ] ; then
1131 if $do_expertmode; then
1132 warning "A previous build.sh run specified -U."
1133 else
1134 bomb "A previous build.sh run specified -U; you must specify it again now."
1135 fi
1136 fi
1137 ;;
1138 esac
1139 }
1140
1141
1142 createmakewrapper()
1143 {
1144 # Remove the target directories.
1145 #
1146 if ${do_removedirs}; then
1147 for f in ${removedirs}; do
1148 statusmsg "Removing ${f}"
1149 ${runcmd} rm -r -f "${f}"
1150 done
1151 fi
1152
1153 # Recreate $TOOLDIR.
1154 #
1155 ${runcmd} mkdir -p "${TOOLDIR}/bin" ||
1156 bomb "mkdir of '${TOOLDIR}/bin' failed"
1157
1158 # Install ${toolprefix}make if it was built.
1159 #
1160 if ${do_rebuildmake}; then
1161 ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make"
1162 ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" ||
1163 bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make"
1164 make="${TOOLDIR}/bin/${toolprefix}make"
1165 statusmsg "Created ${make}"
1166 fi
1167
1168 # Build a ${toolprefix}make wrapper script, usable by hand as
1169 # well as by build.sh.
1170 #
1171 if [ -z "${makewrapper}" ]; then
1172 makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}"
1173 [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}"
1174 fi
1175
1176 ${runcmd} rm -f "${makewrapper}"
1177 if [ "${runcmd}" = "echo" ]; then
1178 echo 'cat <<EOF >'${makewrapper}
1179 makewrapout=
1180 else
1181 makewrapout=">>\${makewrapper}"
1182 fi
1183
1184 case "${KSH_VERSION:-${SH_VERSION}}" in
1185 *PD\ KSH*|*MIRBSD\ KSH*)
1186 set +o braceexpand
1187 ;;
1188 esac
1189
1190 eval cat <<EOF ${makewrapout}
1191 #! ${HOST_SH}
1192 # Set proper variables to allow easy "make" building of a NetBSD subtree.
1193 # Generated from: \$NetBSD: build.sh,v 1.194 2008/08/16 00:10:04 lukem Exp $
1194 # with these arguments: ${_args}
1195 #
1196
1197 EOF
1198 {
1199 for f in ${makeenv}; do
1200 if eval "[ -z \"\${$f}\" -a \"\${${f}-X}\" = \"X\" ]"; then
1201 eval echo "unset ${f}"
1202 else
1203 eval echo "${f}=\'\$$(echo ${f})\'\;\ export\ ${f}"
1204 fi
1205 done
1206
1207 eval cat <<EOF
1208 MAKEWRAPPERMACHINE=${makewrappermachine:-${MACHINE}}; export MAKEWRAPPERMACHINE
1209 USETOOLS=yes; export USETOOLS
1210 EOF
1211 } | eval sort -u "${makewrapout}"
1212 eval cat <<EOF "${makewrapout}"
1213
1214 exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
1215 EOF
1216 [ "${runcmd}" = "echo" ] && echo EOF
1217 ${runcmd} chmod +x "${makewrapper}"
1218 statusmsg "makewrapper: ${makewrapper}"
1219 statusmsg "Updated ${makewrapper}"
1220 }
1221
1222 buildtools()
1223 {
1224 if [ "${MKOBJDIRS}" != "no" ]; then
1225 ${runcmd} "${makewrapper}" ${parallel} obj-tools ||
1226 bomb "Failed to make obj-tools"
1227 fi
1228 ${runcmd} cd tools
1229 if [ "${MKUPDATE}" = "no" ]; then
1230 ${runcmd} "${makewrapper}" ${parallel} cleandir ||
1231 bomb "Failed to make cleandir tools"
1232 fi
1233 ${runcmd} "${makewrapper}" ${parallel} dependall ||
1234 bomb "Failed to make dependall tools"
1235 ${runcmd} "${makewrapper}" ${parallel} install ||
1236 bomb "Failed to make install tools"
1237 statusmsg "Tools built to ${TOOLDIR}"
1238 ${runcmd} cd "${TOP}"
1239 }
1240
1241 getkernelconf()
1242 {
1243 kernelconf="$1"
1244 if [ "${MKOBJDIRS}" != "no" ]; then
1245 # The correct value of KERNOBJDIR might
1246 # depend on a prior "make obj" in
1247 # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
1248 #
1249 KERNSRCDIR="$(getmakevar KERNSRCDIR)"
1250 KERNARCHDIR="$(getmakevar KERNARCHDIR)"
1251 ${runcmd} cd "${KERNSRCDIR}/${KERNARCHDIR}/compile"
1252 ${runcmd} "${makewrapper}" ${parallel} obj ||
1253 bomb "Failed to make obj in ${KERNSRCDIR}/${KERNARCHDIR}/compile"
1254 ${runcmd} cd "${TOP}"
1255 fi
1256 KERNCONFDIR="$(getmakevar KERNCONFDIR)"
1257 KERNOBJDIR="$(getmakevar KERNOBJDIR)"
1258 case "${kernelconf}" in
1259 */*)
1260 kernelconfpath="${kernelconf}"
1261 kernelconfname="${kernelconf##*/}"
1262 ;;
1263 *)
1264 kernelconfpath="${KERNCONFDIR}/${kernelconf}"
1265 kernelconfname="${kernelconf}"
1266 ;;
1267 esac
1268 kernelbuildpath="${KERNOBJDIR}/${kernelconfname}"
1269 }
1270
1271 buildkernel()
1272 {
1273 if ! ${do_tools} && ! ${buildkernelwarned:-false}; then
1274 # Building tools every time we build a kernel is clearly
1275 # unnecessary. We could try to figure out whether rebuilding
1276 # the tools is necessary this time, but it doesn't seem worth
1277 # the trouble. Instead, we say it's the user's responsibility
1278 # to rebuild the tools if necessary.
1279 #
1280 statusmsg "Building kernel without building new tools"
1281 buildkernelwarned=true
1282 fi
1283 getkernelconf $1
1284 statusmsg "Building kernel: ${kernelconf}"
1285 statusmsg "Build directory: ${kernelbuildpath}"
1286 ${runcmd} mkdir -p "${kernelbuildpath}" ||
1287 bomb "Cannot mkdir: ${kernelbuildpath}"
1288 if [ "${MKUPDATE}" = "no" ]; then
1289 ${runcmd} cd "${kernelbuildpath}"
1290 ${runcmd} "${makewrapper}" ${parallel} cleandir ||
1291 bomb "Failed to make cleandir in ${kernelbuildpath}"
1292 ${runcmd} cd "${TOP}"
1293 fi
1294 [ -x "${TOOLDIR}/bin/${toolprefix}config" ] \
1295 || bomb "${TOOLDIR}/bin/${toolprefix}config does not exist. You need to \"$0 tools\" first."
1296 ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" -b "${kernelbuildpath}" \
1297 -s "${TOP}/sys" "${kernelconfpath}" ||
1298 bomb "${toolprefix}config failed for ${kernelconf}"
1299 ${runcmd} cd "${kernelbuildpath}"
1300 ${runcmd} "${makewrapper}" ${parallel} depend ||
1301 bomb "Failed to make depend in ${kernelbuildpath}"
1302 ${runcmd} "${makewrapper}" ${parallel} all ||
1303 bomb "Failed to make all in ${kernelbuildpath}"
1304 ${runcmd} cd "${TOP}"
1305
1306 if [ "${runcmd}" != "echo" ]; then
1307 statusmsg "Kernels built from ${kernelconf}:"
1308 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1309 for kern in ${kernlist:-netbsd}; do
1310 [ -f "${kernelbuildpath}/${kern}" ] && \
1311 echo " ${kernelbuildpath}/${kern}"
1312 done | tee -a "${results}"
1313 fi
1314 }
1315
1316 releasekernel()
1317 {
1318 getkernelconf $1
1319 kernelreldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel"
1320 ${runcmd} mkdir -p "${kernelreldir}"
1321 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1322 for kern in ${kernlist:-netbsd}; do
1323 builtkern="${kernelbuildpath}/${kern}"
1324 [ -f "${builtkern}" ] || continue
1325 releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz"
1326 statusmsg "Kernel copy: ${releasekern}"
1327 ${runcmd} gzip -c -9 < "${builtkern}" > "${releasekern}"
1328 done
1329 }
1330
1331 installworld()
1332 {
1333 dir="$1"
1334 ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld ||
1335 bomb "Failed to make installworld to ${dir}"
1336 statusmsg "Successful installworld to ${dir}"
1337 }
1338
1339
1340 main()
1341 {
1342 initdefaults
1343 _args=$@
1344 parseoptions "$@"
1345
1346 sanitycheck
1347
1348 build_start=$(date)
1349 statusmsg "${progname} command: $0 $@"
1350 statusmsg "${progname} started: ${build_start}"
1351 statusmsg "NetBSD version: ${DISTRIBVER}"
1352 statusmsg "MACHINE: ${MACHINE}"
1353 statusmsg "MACHINE_ARCH: ${MACHINE_ARCH}"
1354 statusmsg "Build platform: ${uname_s} ${uname_r} ${uname_m}"
1355 statusmsg "HOST_SH: ${HOST_SH}"
1356
1357 rebuildmake
1358 validatemakeparams
1359 createmakewrapper
1360
1361 # Perform the operations.
1362 #
1363 for op in ${operations}; do
1364 case "${op}" in
1365
1366 makewrapper)
1367 # no-op
1368 ;;
1369
1370 tools)
1371 buildtools
1372 ;;
1373
1374 sets)
1375 statusmsg "Building sets from pre-populated ${DESTDIR}"
1376 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1377 bomb "Failed to make ${op}"
1378 setdir=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
1379 statusmsg "Built sets to ${setdir}"
1380 ;;
1381
1382 obj|build|distribution|release|sourcesets|syspkgs|params)
1383 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1384 bomb "Failed to make ${op}"
1385 statusmsg "Successful make ${op}"
1386 ;;
1387
1388 iso-image|iso-image-source)
1389 ${runcmd} "${makewrapper}" ${parallel} \
1390 CDEXTRA="$iso_dir" ${op} ||
1391 bomb "Failed to make ${op}"
1392 statusmsg "Successful make ${op}"
1393 ;;
1394
1395 kernel=*)
1396 arg=${op#*=}
1397 buildkernel "${arg}"
1398 ;;
1399
1400 releasekernel=*)
1401 arg=${op#*=}
1402 releasekernel "${arg}"
1403 ;;
1404
1405 install=*)
1406 arg=${op#*=}
1407 if [ "${arg}" = "/" ] && \
1408 ( [ "${uname_s}" != "NetBSD" ] || \
1409 [ "${uname_m}" != "${MACHINE}" ] ); then
1410 bomb "'${op}' must != / for cross builds."
1411 fi
1412 installworld "${arg}"
1413 ;;
1414
1415 *)
1416 bomb "Unknown operation \`${op}'"
1417 ;;
1418
1419 esac
1420 done
1421
1422 statusmsg "${progname} ended: $(date)"
1423 if [ -s "${results}" ]; then
1424 echo "===> Summary of results:"
1425 sed -e 's/^===>//;s/^/ /' "${results}"
1426 echo "===> ."
1427 fi
1428 }
1429
1430 main "$@"
1431