Annotation of src/build.sh, Revision 1.166
1.67 thorpej 1: #! /usr/bin/env sh
1.166 ! apb 2: # $NetBSD: build.sh,v 1.165 2007/04/02 10:57:36 apb Exp $
1.84 lukem 3: #
1.136 lukem 4: # Copyright (c) 2001-2005 The NetBSD Foundation, Inc.
1.84 lukem 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: # 3. All advertising materials mentioning features or use of this software
19: # must display the following acknowledgement:
20: # This product includes software developed by the NetBSD
21: # Foundation, Inc. and its contributors.
22: # 4. Neither the name of The NetBSD Foundation nor the names of its
23: # contributors may be used to endorse or promote products derived
24: # from this software without specific prior written permission.
25: #
26: # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27: # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28: # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29: # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30: # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31: # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32: # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33: # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34: # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35: # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36: # POSSIBILITY OF SUCH DAMAGE.
37: #
1.1 tv 38: #
39: # Top level build wrapper, for a system containing no tools.
40: #
1.153 apb 41: # This script should run on any POSIX-compliant shell. If the
42: # first "sh" found in the PATH is a POSIX-compliant shell, then
43: # you should not need to take any special action. Otherwise, you
44: # should set the environment variable HOST_SH to a POSIX-compliant
45: # shell, and invoke build.sh with that shell. (Depending on your
46: # system, one of /bin/ksh, /usr/local/bin/bash, or /usr/xpg4/bin/sh
47: # might be a suitable shell.)
1.67 thorpej 48: #
1.1 tv 49:
1.84 lukem 50: progname=${0##*/}
51: toppid=$$
1.98 lukem 52: results=/dev/null
1.82 lukem 53: trap "exit 1" 1 2 3 15
1.84 lukem 54:
1.79 lukem 55: bomb()
56: {
1.82 lukem 57: cat >&2 <<ERRORMESSAGE
58:
59: ERROR: $@
60: *** BUILD ABORTED ***
61: ERRORMESSAGE
1.98 lukem 62: kill ${toppid} # in case we were invoked from a subshell
1.1 tv 63: exit 1
64: }
1.78 lukem 65:
1.84 lukem 66:
1.98 lukem 67: statusmsg()
68: {
69: ${runcmd} echo "===> $@" | tee -a "${results}"
70: }
71:
1.163 apb 72: warning()
73: {
74: statusmsg "Warning: $@"
75: }
76:
1.153 apb 77: # Find a program in the PATH
78: find_in_PATH()
79: {
80: local prog="$1"
81: local oldIFS="${IFS}"
82: local dir
83: IFS=":"
84: for dir in ${PATH}; do
85: if [ -x "${dir}/${prog}" ]; then
86: prog="${dir}/${prog}"
87: break
88: fi
89: done
90: IFS="${oldIFS}"
91: echo "${prog}"
92: }
93:
94: # Try to find a working POSIX shell, and set HOST_SH to refer to it.
95: # Assumes that uname_s, uname_m, and PWD have been set.
96: set_HOST_SH()
97: {
98: # Even if ${HOST_SH} is already defined, we still do the
99: # sanity checks at the end.
100:
101: # Solaris has /usr/xpg4/bin/sh.
102: #
103: [ -z "${HOST_SH}" ] && [ x"${uname_s}" = x"SunOS" ] && \
104: [ -x /usr/xpg4/bin/sh ] && HOST_SH="/usr/xpg4/bin/sh"
105:
106: # Try to get the name of the shell that's running this script,
107: # by parsing the output from "ps". We assume that, if the host
108: # system's ps command supports -o comm at all, it will do so
109: # in the usual way: a one-line header followed by a one-line
110: # result, possibly including trailing white space. And if the
111: # host system's ps command doesn't support -o comm, we assume
112: # that we'll get an error message on stderr and nothing on
113: # stdout. (We don't try to use ps -o 'comm=' to suppress the
114: # header line, because that is less widely supported.)
115: #
116: # If we get the wrong result here, the user can override it by
117: # specifying HOST_SH in the environment.
118: #
119: [ -z "${HOST_SH}" ] && HOST_SH="$(
120: (ps -p $$ -o comm | sed -ne '2s/[ \t]*$//p') 2>/dev/null )"
121:
122: # If nothing above worked, use "sh". We will later find the
123: # first directory in the PATH that has a "sh" program.
124: #
125: [ -z "${HOST_SH}" ] && HOST_SH="sh"
126:
127: # If the result so far is not an absolute path, try to prepend
128: # PWD or search the PATH.
129: #
130: case "${HOST_SH}" in
131: /*) :
132: ;;
133: */*) HOST_SH="${PWD}/${HOST_SH}"
134: ;;
135: *) HOST_SH="$(find_in_PATH "${HOST_SH}")"
136: ;;
137: esac
138:
139: # If we don't have an absolute path by now, bomb.
140: #
141: case "${HOST_SH}" in
142: /*) :
143: ;;
144: *) bomb "HOST_SH=\"${HOST_SH}\" is not an absolute path."
145: ;;
146: esac
147:
148: # If HOST_SH is not executable, bomb.
149: #
150: [ -x "${HOST_SH}" ] ||
151: bomb "HOST_SH=\"${HOST_SH}\" is not executable."
152: }
153:
1.84 lukem 154: initdefaults()
155: {
1.156 dsl 156: [ -d usr.bin/make ] || cd "$(dirname $0)"
1.84 lukem 157: [ -d usr.bin/make ] ||
158: bomb "build.sh must be run from the top source level"
159: [ -f share/mk/bsd.own.mk ] ||
160: bomb "src/share/mk is missing; please re-fetch the source tree"
161:
1.165 apb 162: # Find information about the build platform.
163: #
1.84 lukem 164: uname_s=$(uname -s 2>/dev/null)
1.165 apb 165: uname_r=$(uname -r 2>/dev/null)
1.84 lukem 166: uname_m=$(uname -m 2>/dev/null)
167:
168: # If $PWD is a valid name of the current directory, POSIX mandates
169: # that pwd return it by default which causes problems in the
170: # presence of symlinks. Unsetting PWD is simpler than changing
171: # every occurrence of pwd to use -P.
172: #
1.147 dogcow 173: # XXX Except that doesn't work on Solaris. Or many Linuces.
1.98 lukem 174: #
1.84 lukem 175: unset PWD
1.147 dogcow 176: TOP=$(/bin/pwd -P 2>/dev/null || /bin/pwd 2>/dev/null)
1.84 lukem 177:
1.153 apb 178: # The user can set HOST_SH in the environment, or we try to
179: # guess an appropriate value. Then we set several other
180: # variables from HOST_SH.
181: #
182: set_HOST_SH
183: setmakeenv HOST_SH "${HOST_SH}"
184: setmakeenv BSHELL "${HOST_SH}"
185: setmakeenv CONFIG_SHELL "${HOST_SH}"
186:
1.84 lukem 187: # Set defaults.
1.98 lukem 188: #
1.84 lukem 189: toolprefix=nb
1.98 lukem 190:
1.95 thorpej 191: # Some systems have a small ARG_MAX. -X prevents make(1) from
192: # exporting variables in the environment redundantly.
1.98 lukem 193: #
1.95 thorpej 194: case "${uname_s}" in
1.97 christos 195: Darwin | FreeBSD | CYGWIN*)
1.95 thorpej 196: MAKEFLAGS=-X
197: ;;
198: *)
199: MAKEFLAGS=
200: ;;
201: esac
1.98 lukem 202:
1.84 lukem 203: makeenv=
204: makewrapper=
1.102 lukem 205: makewrappermachine=
1.84 lukem 206: runcmd=
207: operations=
208: removedirs=
209: do_expertmode=false
210: do_rebuildmake=false
211: do_removedirs=false
212:
213: # do_{operation}=true if given operation is requested.
214: #
215: do_tools=false
216: do_obj=false
217: do_build=false
218: do_distribution=false
219: do_release=false
220: do_kernel=false
1.105 lukem 221: do_releasekernel=false
1.84 lukem 222: do_install=false
1.87 lukem 223: do_sets=false
1.100 lukem 224: do_sourcesets=false
1.142 apb 225: do_syspkgs=false
1.146 apb 226: do_iso_image=false
1.107 lukem 227: do_params=false
1.98 lukem 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"
1.116 jmmv 235:
236: # Set source directories
237: #
238: setmakeenv NETBSDSRCDIR "${TOP}"
1.136 lukem 239:
1.165 apb 240: # Find the version of NetBSD
241: #
242: DISTRIBVER="$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh)"
243:
1.136 lukem 244: # Set various environment variables to known defaults,
245: # to minimize (cross-)build problems observed "in the field".
246: #
247: unsetmakeenv INFODIR
1.140 jmc 248: unsetmakeenv LESSCHARSET
1.136 lukem 249: setmakeenv LC_ALL C
1.84 lukem 250: }
1.29 jmc 251:
1.79 lukem 252: getarch()
253: {
1.158 apb 254: # Translate some MACHINE name aliases (known only to build.sh)
255: # into proper MACHINE and MACHINE_ARCH names. Save the alias
256: # name in makewrappermachine.
257: #
258: case "${MACHINE}" in
259:
260: evbarm-e[bl])
261: makewrappermachine=${MACHINE}
262: # MACHINE_ARCH is "arm" or "armeb", not "armel"
263: MACHINE_ARCH=arm${MACHINE##*-}
264: MACHINE_ARCH=${MACHINE_ARCH%el}
265: MACHINE=${MACHINE%-e[bl]}
266: ;;
267:
268: evbmips-e[bl]|sbmips-e[bl])
269: makewrappermachine=${MACHINE}
270: MACHINE_ARCH=mips${MACHINE##*-}
271: MACHINE=${MACHINE%-e[bl]}
272: ;;
273:
274: evbmips64-e[bl]|sbmips64-e[bl])
275: makewrappermachine=${MACHINE}
276: MACHINE_ARCH=mips64${MACHINE##*-}
277: MACHINE=${MACHINE%64-e[bl]}
278: ;;
279:
280: evbsh3-e[bl])
281: makewrappermachine=${MACHINE}
282: MACHINE_ARCH=sh3${MACHINE##*-}
283: MACHINE=${MACHINE%-e[bl]}
284: ;;
285:
286: esac
287:
1.1 tv 288: # Translate a MACHINE into a default MACHINE_ARCH.
1.84 lukem 289: #
1.98 lukem 290: case "${MACHINE}" in
1.1 tv 291:
1.162 briggs 292: acorn26|acorn32|cats|hpcarm|iyonix|netwinder|shark|zaurus)
1.84 lukem 293: MACHINE_ARCH=arm
294: ;;
295:
1.162 briggs 296: evbarm) # unspecified MACHINE_ARCH gets LE
297: MACHINE_ARCH=${MACHINE_ARCH:=arm}
298: ;;
299:
1.98 lukem 300: hp700)
301: MACHINE_ARCH=hppa
302: ;;
303:
1.84 lukem 304: sun2)
305: MACHINE_ARCH=m68000
306: ;;
307:
1.98 lukem 308: amiga|atari|cesfic|hp300|luna68k|mac68k|mvme68k|news68k|next68k|sun3|x68k)
1.84 lukem 309: MACHINE_ARCH=m68k
310: ;;
1.1 tv 311:
1.101 lukem 312: evbmips|sbmips) # no default MACHINE_ARCH
313: ;;
314:
1.141 tsutsui 315: ews4800mips|mipsco|newsmips|sgimips)
1.84 lukem 316: MACHINE_ARCH=mipseb
317: ;;
1.1 tv 318:
1.101 lukem 319: algor|arc|cobalt|hpcmips|playstation2|pmax)
1.84 lukem 320: MACHINE_ARCH=mipsel
321: ;;
1.1 tv 322:
1.84 lukem 323: pc532)
324: MACHINE_ARCH=ns32k
325: ;;
1.1 tv 326:
1.160 matt 327: evbppc64|macppc64)
328: makewrappermachine=${MACHINE}
329: MACHINE=${MACHINE%64}
330: MACHINE_ARCH=powerpc64
331: ;;
332:
1.118 matt 333: amigappc|bebox|evbppc|ibmnws|macppc|mvmeppc|ofppc|pmppc|prep|sandpoint)
1.84 lukem 334: MACHINE_ARCH=powerpc
335: ;;
1.1 tv 336:
1.103 lukem 337: evbsh3) # no default MACHINE_ARCH
338: ;;
339:
340: mmeye)
1.84 lukem 341: MACHINE_ARCH=sh3eb
342: ;;
1.1 tv 343:
1.152 uwe 344: dreamcast|hpcsh|landisk)
1.84 lukem 345: MACHINE_ARCH=sh3el
346: ;;
1.1 tv 347:
1.84 lukem 348: evbsh5)
349: MACHINE_ARCH=sh5el
350: ;;
1.96 fvdl 351: amd64)
352: MACHINE_ARCH=x86_64
353: ;;
1.62 fredette 354:
1.138 skrll 355: alpha|i386|sparc|sparc64|vax|ia64)
1.98 lukem 356: MACHINE_ARCH=${MACHINE}
1.84 lukem 357: ;;
1.69 thorpej 358:
1.84 lukem 359: *)
1.98 lukem 360: bomb "Unknown target MACHINE: ${MACHINE}"
1.84 lukem 361: ;;
1.4 tv 362:
1.1 tv 363: esac
364: }
365:
1.79 lukem 366: validatearch()
367: {
1.47 tv 368: # Ensure that the MACHINE_ARCH exists (and is supported by build.sh).
1.84 lukem 369: #
1.98 lukem 370: case "${MACHINE_ARCH}" in
1.47 tv 371:
1.150 matt 372: alpha|arm|armeb|hppa|i386|m68000|m68k|mipse[bl]|mips64e[bl]|ns32k|powerpc|powerpc64|sh[35]e[bl]|sparc|sparc64|vax|x86_64|ia64)
1.84 lukem 373: ;;
374:
1.101 lukem 375: "")
376: bomb "No MACHINE_ARCH provided"
377: ;;
378:
1.84 lukem 379: *)
1.98 lukem 380: bomb "Unknown target MACHINE_ARCH: ${MACHINE_ARCH}"
381: ;;
382:
383: esac
384:
385: # Determine valid MACHINE_ARCHs for MACHINE
386: #
387: case "${MACHINE}" in
388:
389: evbarm)
390: arches="arm armeb"
391: ;;
392:
393: evbmips|sbmips)
1.150 matt 394: arches="mipseb mipsel mips64eb mips64el"
395: ;;
396:
397: sgimips)
398: arches="mipseb mips64eb"
1.98 lukem 399: ;;
400:
401: evbsh3)
402: arches="sh3eb sh3el"
403: ;;
404:
405: evbsh5)
406: arches="sh5eb sh5el"
407: ;;
408:
1.148 mrg 409: macppc|evbppc)
410: arches="powerpc powerpc64"
411: ;;
1.98 lukem 412: *)
413: oma="${MACHINE_ARCH}"
414: getarch
415: arches="${MACHINE_ARCH}"
416: MACHINE_ARCH="${oma}"
1.84 lukem 417: ;;
418:
1.47 tv 419: esac
1.98 lukem 420:
421: # Ensure that MACHINE_ARCH supports MACHINE
422: #
423: archok=false
424: for a in ${arches}; do
425: if [ "${a}" = "${MACHINE_ARCH}" ]; then
426: archok=true
427: break
428: fi
429: done
430: ${archok} ||
431: bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'"
1.47 tv 432: }
433:
1.98 lukem 434: raw_getmakevar()
1.79 lukem 435: {
1.98 lukem 436: [ -x "${make}" ] || bomb "raw_getmakevar $1: ${make} is not executable"
1.161 apb 437: "${make}" -m ${TOP}/share/mk -s -B -f- _x_ <<EOF || bomb "raw_getmakevar $1: ${make} failed"
1.15 tv 438: _x_:
439: echo \${$1}
440: .include <bsd.prog.mk>
1.70 lukem 441: .include <bsd.kernobj.mk>
1.15 tv 442: EOF
443: }
444:
1.98 lukem 445: getmakevar()
1.82 lukem 446: {
1.98 lukem 447: # raw_getmakevar() doesn't work properly if $make hasn't yet been
448: # built, which can happen when running with the "-n" option.
449: # getmakevar() deals with this by emitting a literal '$'
1.84 lukem 450: # followed by the variable name, instead of trying to find the
451: # variable's value.
452: #
1.98 lukem 453: if [ -x "${make}" ]; then
454: raw_getmakevar "$1"
1.82 lukem 455: else
456: echo "\$$1"
457: fi
458: }
459:
1.109 lukem 460: setmakeenv()
461: {
462: eval "$1='$2'; export $1"
463: makeenv="${makeenv} $1"
464: }
465:
1.111 lukem 466: unsetmakeenv()
467: {
468: eval "unset $1"
469: makeenv="${makeenv} $1"
470: }
471:
1.131 junyoung 472: # Convert possibly-relative path to absolute path by prepending
473: # ${TOP} if necessary. Also delete trailing "/", if any.
1.79 lukem 474: resolvepath()
475: {
1.98 lukem 476: case "${OPTARG}" in
1.131 junyoung 477: /)
478: ;;
1.84 lukem 479: /*)
1.131 junyoung 480: OPTARG="${OPTARG%/}"
1.84 lukem 481: ;;
482: *)
1.131 junyoung 483: OPTARG="${TOP}/${OPTARG%/}"
1.84 lukem 484: ;;
1.10 tv 485: esac
486: }
487:
1.79 lukem 488: usage()
489: {
1.84 lukem 490: if [ -n "$*" ]; then
491: echo ""
492: echo "${progname}: $*"
493: fi
1.70 lukem 494: cat <<_usage_
1.83 lukem 495:
1.127 lukem 496: Usage: ${progname} [-EnorUux] [-a arch] [-B buildid] [-D dest] [-j njob]
1.119 lukem 497: [-M obj] [-m mach] [-N noisy] [-O obj] [-R release] [-T tools]
1.127 lukem 498: [-V var=[value]] [-w wrapper] [-X x11src] [-Z var]
499: operation [...]
1.84 lukem 500:
1.86 lukem 501: Build operations (all imply "obj" and "tools"):
1.125 lukem 502: build Run "make build".
503: distribution Run "make distribution" (includes DESTDIR/etc/ files).
504: release Run "make release" (includes kernels & distrib media).
1.84 lukem 505:
506: Other operations:
1.125 lukem 507: help Show this message and exit.
1.98 lukem 508: makewrapper Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make.
1.125 lukem 509: Always performed.
510: obj Run "make obj". [Default unless -o is used]
511: tools Build and install tools.
512: install=idir Run "make installworld" to \`idir' to install all sets
513: except \`etc'. Useful after "distribution" or "release"
1.105 lukem 514: kernel=conf Build kernel with config file \`conf'
1.125 lukem 515: releasekernel=conf Install kernel built by kernel=conf to RELEASEDIR.
516: sets Create binary sets in RELEASEDIR/MACHINE/binary/sets.
517: DESTDIR should be populated beforehand.
518: sourcesets Create source sets in RELEASEDIR/source/sets.
1.142 apb 519: syspkgs Create syspkgs in RELEASEDIR/MACHINE/binary/syspkgs.
1.146 apb 520: iso-image Create CD-ROM image in RELEASEDIR/MACHINE/installation.
1.125 lukem 521: params Display various make(1) parameters.
1.84 lukem 522:
523: Options:
1.125 lukem 524: -a arch Set MACHINE_ARCH to arch. [Default: deduced from MACHINE]
525: -B buildId Set BUILDID to buildId.
1.119 lukem 526: -D dest Set DESTDIR to dest. [Default: destdir.MACHINE]
1.98 lukem 527: -E Set "expert" mode; disables various safety checks.
1.127 lukem 528: Should not be used without expert knowledge of the build system.
1.129 wiz 529: -h Print this help message.
1.125 lukem 530: -j njob Run up to njob jobs in parallel; see make(1) -j.
531: -M obj Set obj root directory to obj; sets MAKEOBJDIRPREFIX.
1.111 lukem 532: Unsets MAKEOBJDIR.
1.125 lukem 533: -m mach Set MACHINE to mach; not required if NetBSD native.
1.126 lukem 534: -N noisy Set the noisyness (MAKEVERBOSE) level of the build:
1.119 lukem 535: 0 Quiet
536: 1 Operations are described, commands are suppressed
537: 2 Full output
538: [Default: 2]
1.125 lukem 539: -n Show commands that would be executed, but do not execute them.
540: -O obj Set obj root directory to obj; sets a MAKEOBJDIR pattern.
1.111 lukem 541: Unsets MAKEOBJDIRPREFIX.
1.125 lukem 542: -o Set MKOBJDIRS=no; do not create objdirs at start of build.
1.119 lukem 543: -R release Set RELEASEDIR to release. [Default: releasedir]
1.125 lukem 544: -r Remove contents of TOOLDIR and DESTDIR before building.
1.98 lukem 545: -T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in
1.125 lukem 546: the environment, ${toolprefix}make will be (re)built unconditionally.
547: -U Set MKUNPRIVED=yes; build without requiring root privileges,
548: install from an UNPRIVED build with proper file permissions.
549: -u Set MKUPDATE=yes; do not run "make clean" first.
1.98 lukem 550: Without this, everything is rebuilt, including the tools.
1.125 lukem 551: -V v=[val] Set variable \`v' to \`val'.
552: -w wrapper Create ${toolprefix}make script as wrapper.
1.119 lukem 553: [Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE}]
1.127 lukem 554: -X x11src Set X11SRCDIR to x11src. [Default: /usr/xsrc]
555: -x Set MKX11=yes; build X11R6 from X11SRCDIR
1.125 lukem 556: -Z v Unset ("zap") variable \`v'.
1.83 lukem 557:
1.70 lukem 558: _usage_
1.1 tv 559: exit 1
560: }
561:
1.84 lukem 562: parseoptions()
563: {
1.127 lukem 564: opts='a:B:bD:dEhi:j:k:M:m:N:nO:oR:rT:tUuV:w:xX:Z:'
1.84 lukem 565: opt_a=no
566:
567: if type getopts >/dev/null 2>&1; then
568: # Use POSIX getopts.
1.98 lukem 569: #
570: getoptcmd='getopts ${opts} opt && opt=-${opt}'
1.84 lukem 571: optargcmd=':'
1.98 lukem 572: optremcmd='shift $((${OPTIND} -1))'
1.84 lukem 573: else
574: type getopt >/dev/null 2>&1 ||
575: bomb "/bin/sh shell is too old; try ksh or bash"
576:
577: # Use old-style getopt(1) (doesn't handle whitespace in args).
1.98 lukem 578: #
579: args="$(getopt ${opts} $*)"
1.84 lukem 580: [ $? = 0 ] || usage
1.98 lukem 581: set -- ${args}
1.84 lukem 582:
583: getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
584: optargcmd='OPTARG="$1"; shift'
585: optremcmd=':'
586: fi
587:
588: # Parse command line options.
589: #
1.98 lukem 590: while eval ${getoptcmd}; do
591: case ${opt} in
1.84 lukem 592:
593: -a)
1.98 lukem 594: eval ${optargcmd}
595: MACHINE_ARCH=${OPTARG}
1.84 lukem 596: opt_a=yes
597: ;;
598:
599: -B)
1.98 lukem 600: eval ${optargcmd}
601: BUILDID=${OPTARG}
1.84 lukem 602: ;;
603:
604: -b)
1.86 lukem 605: usage "'-b' has been replaced by 'makewrapper'"
1.84 lukem 606: ;;
607:
608: -D)
1.98 lukem 609: eval ${optargcmd}; resolvepath
1.109 lukem 610: setmakeenv DESTDIR "${OPTARG}"
1.84 lukem 611: ;;
612:
613: -d)
614: usage "'-d' has been replaced by 'distribution'"
615: ;;
616:
617: -E)
618: do_expertmode=true
619: ;;
620:
621: -i)
622: usage "'-i idir' has been replaced by 'install=idir'"
623: ;;
624:
625: -j)
1.98 lukem 626: eval ${optargcmd}
627: parallel="-j ${OPTARG}"
1.84 lukem 628: ;;
629:
630: -k)
631: usage "'-k conf' has been replaced by 'kernel=conf'"
632: ;;
633:
634: -M)
1.98 lukem 635: eval ${optargcmd}; resolvepath
636: makeobjdir="${OPTARG}"
1.111 lukem 637: unsetmakeenv MAKEOBJDIR
1.109 lukem 638: setmakeenv MAKEOBJDIRPREFIX "${OPTARG}"
1.84 lukem 639: ;;
640:
641: # -m overrides MACHINE_ARCH unless "-a" is specified
642: -m)
1.98 lukem 643: eval ${optargcmd}
644: MACHINE="${OPTARG}"
645: [ "${opt_a}" != "yes" ] && getarch
1.84 lukem 646: ;;
647:
1.119 lukem 648: -N)
649: eval ${optargcmd}
650: case "${OPTARG}" in
1.121 lukem 651: 0|1|2)
652: setmakeenv MAKEVERBOSE "${OPTARG}"
1.119 lukem 653: ;;
654: *)
655: usage "'${OPTARG}' is not a valid value for -N"
656: ;;
657: esac
658: ;;
659:
1.84 lukem 660: -n)
661: runcmd=echo
662: ;;
663:
664: -O)
1.98 lukem 665: eval ${optargcmd}; resolvepath
666: makeobjdir="${OPTARG}"
1.111 lukem 667: unsetmakeenv MAKEOBJDIRPREFIX
1.109 lukem 668: setmakeenv MAKEOBJDIR "\${.CURDIR:C,^$TOP,$OPTARG,}"
1.84 lukem 669: ;;
670:
671: -o)
672: MKOBJDIRS=no
673: ;;
674:
675: -R)
1.98 lukem 676: eval ${optargcmd}; resolvepath
1.109 lukem 677: setmakeenv RELEASEDIR "${OPTARG}"
1.84 lukem 678: ;;
679:
680: -r)
681: do_removedirs=true
682: do_rebuildmake=true
683: ;;
684:
685: -T)
1.98 lukem 686: eval ${optargcmd}; resolvepath
687: TOOLDIR="${OPTARG}"
1.84 lukem 688: export TOOLDIR
689: ;;
690:
691: -t)
692: usage "'-t' has been replaced by 'tools'"
693: ;;
1.16 thorpej 694:
1.84 lukem 695: -U)
1.109 lukem 696: setmakeenv MKUNPRIVED yes
1.84 lukem 697: ;;
1.44 lukem 698:
1.84 lukem 699: -u)
1.109 lukem 700: setmakeenv MKUPDATE yes
1.84 lukem 701: ;;
1.15 tv 702:
1.84 lukem 703: -V)
1.98 lukem 704: eval ${optargcmd}
1.84 lukem 705: case "${OPTARG}" in
1.80 lukem 706: # XXX: consider restricting which variables can be changed?
1.84 lukem 707: [a-zA-Z_][a-zA-Z_0-9]*=*)
1.109 lukem 708: setmakeenv "${OPTARG%%=*}" "${OPTARG#*=}"
1.84 lukem 709: ;;
710: *)
711: usage "-V argument must be of the form 'var=[value]'"
712: ;;
713: esac
714: ;;
715:
716: -w)
1.98 lukem 717: eval ${optargcmd}; resolvepath
718: makewrapper="${OPTARG}"
1.84 lukem 719: ;;
720:
1.127 lukem 721: -X)
722: eval ${optargcmd}; resolvepath
723: setmakeenv X11SRCDIR "${OPTARG}"
724: ;;
725:
726: -x)
727: setmakeenv MKX11 yes
728: ;;
729:
1.111 lukem 730: -Z)
731: eval ${optargcmd}
732: # XXX: consider restricting which variables can be unset?
733: unsetmakeenv "${OPTARG}"
734: ;;
735:
1.84 lukem 736: --)
737: break
738: ;;
739:
740: -'?'|-h)
741: usage
742: ;;
743:
744: esac
745: done
746:
747: # Validate operations.
748: #
1.98 lukem 749: eval ${optremcmd}
1.84 lukem 750: while [ $# -gt 0 ]; do
751: op=$1; shift
1.98 lukem 752: operations="${operations} ${op}"
1.84 lukem 753:
1.98 lukem 754: case "${op}" in
1.84 lukem 755:
1.87 lukem 756: help)
757: usage
758: ;;
759:
1.142 apb 760: makewrapper|obj|tools|build|distribution|release|sets|sourcesets|syspkgs|params)
1.80 lukem 761: ;;
1.84 lukem 762:
1.146 apb 763: iso-image)
764: op=iso_image # used as part of a variable name
765: ;;
766:
1.105 lukem 767: kernel=*|releasekernel=*)
1.84 lukem 768: arg=${op#*=}
769: op=${op%%=*}
1.98 lukem 770: [ -n "${arg}" ] ||
1.105 lukem 771: bomb "Must supply a kernel name with \`${op}=...'"
1.84 lukem 772: ;;
773:
774: install=*)
775: arg=${op#*=}
776: op=${op%%=*}
1.98 lukem 777: [ -n "${arg}" ] ||
778: bomb "Must supply a directory with \`install=...'"
1.84 lukem 779: ;;
780:
1.80 lukem 781: *)
1.84 lukem 782: usage "Unknown operation \`${op}'"
783: ;;
784:
1.80 lukem 785: esac
1.98 lukem 786: eval do_${op}=true
1.84 lukem 787: done
1.98 lukem 788: [ -n "${operations}" ] || usage "Missing operation to perform."
1.84 lukem 789:
790: # Set up MACHINE*. On a NetBSD host, these are allowed to be unset.
791: #
1.98 lukem 792: if [ -z "${MACHINE}" ]; then
793: [ "${uname_s}" = "NetBSD" ] ||
794: bomb "MACHINE must be set, or -m must be used, for cross builds."
1.84 lukem 795: MACHINE=${uname_m}
796: fi
1.98 lukem 797: [ -n "${MACHINE_ARCH}" ] || getarch
1.84 lukem 798: validatearch
799:
800: # Set up default make(1) environment.
801: #
1.98 lukem 802: makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
803: [ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID"
1.115 jmmv 804: MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}"
1.84 lukem 805: export MAKEFLAGS MACHINE MACHINE_ARCH
806: }
807:
1.163 apb 808: sanitycheck()
809: {
810: # If the PATH contains any non-absolute components (including,
811: # but not limited to, "." or ""), then complain. This is fatal
812: # if expert mode is not in effect.
813: #
814: case ":${PATH}:/" in
815: *:[!/]*)
816: if ${do_expertmode}; then
817: warning "PATH contains non-absolute components"
818: else
1.164 apb 819: bomb "PATH environment variable must not" \
820: "contain non-absolute components"
1.163 apb 821: fi
822: ;;
823: esac
824: }
825:
1.84 lukem 826: rebuildmake()
827: {
828: # Test make source file timestamps against installed ${toolprefix}make
829: # binary, if TOOLDIR is pre-set.
830: #
831: # Note that we do NOT try to grovel "mk.conf" here to find out if
832: # TOOLDIR is set there, because it can contain make variable
833: # expansions and other stuff only parseable *after* we have a working
834: # ${toolprefix}make. So this logic can only work if the user has
835: # pre-set TOOLDIR in the environment or used the -T option to build.sh.
836: #
837: make="${TOOLDIR-nonexistent}/bin/${toolprefix}make"
1.98 lukem 838: if [ -x "${make}" ]; then
1.84 lukem 839: for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
1.98 lukem 840: if [ "${f}" -nt "${make}" ]; then
1.122 lukem 841: statusmsg "${make} outdated (older than ${f}), needs building."
1.84 lukem 842: do_rebuildmake=true
843: break
844: fi
845: done
846: else
1.122 lukem 847: statusmsg "No ${make}, needs building."
1.84 lukem 848: do_rebuildmake=true
849: fi
850:
851: # Build bootstrap ${toolprefix}make if needed.
1.98 lukem 852: if ${do_rebuildmake}; then
853: statusmsg "Bootstrapping ${toolprefix}make"
854: ${runcmd} cd "${tmpdir}"
855: ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
1.84 lukem 856: CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
1.153 apb 857: ${HOST_SH} "${TOP}/tools/make/configure" ||
1.98 lukem 858: bomb "Configure of ${toolprefix}make failed"
1.153 apb 859: ${runcmd} ${HOST_SH} buildmake.sh ||
1.98 lukem 860: bomb "Build of ${toolprefix}make failed"
861: make="${tmpdir}/${toolprefix}make"
862: ${runcmd} cd "${TOP}"
863: ${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
1.84 lukem 864: fi
865: }
866:
867: validatemakeparams()
868: {
1.98 lukem 869: if [ "${runcmd}" = "echo" ]; then
1.84 lukem 870: TOOLCHAIN_MISSING=no
871: EXTERNAL_TOOLCHAIN=""
872: else
1.98 lukem 873: TOOLCHAIN_MISSING=$(raw_getmakevar TOOLCHAIN_MISSING)
874: EXTERNAL_TOOLCHAIN=$(raw_getmakevar EXTERNAL_TOOLCHAIN)
1.84 lukem 875: fi
876: if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
1.86 lukem 877: [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
1.98 lukem 878: ${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
879: ${runcmd} echo " MACHINE: ${MACHINE}"
880: ${runcmd} echo " MACHINE_ARCH: ${MACHINE_ARCH}"
881: ${runcmd} echo ""
882: ${runcmd} echo "All builds for this platform should be done via a traditional make"
883: ${runcmd} echo "If you wish to use an external cross-toolchain, set"
884: ${runcmd} echo " EXTERNAL_TOOLCHAIN=<path to toolchain root>"
885: ${runcmd} echo "in either the environment or mk.conf and rerun"
886: ${runcmd} echo " ${progname} $*"
1.84 lukem 887: exit 1
888: fi
889:
1.120 lukem 890: # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE
891: # These may be set as build.sh options or in "mk.conf".
892: # Don't export them as they're only used for tests in build.sh.
893: #
894: MKOBJDIRS=$(getmakevar MKOBJDIRS)
895: MKUNPRIVED=$(getmakevar MKUNPRIVED)
896: MKUPDATE=$(getmakevar MKUPDATE)
897:
1.106 lukem 898: if [ "${MKOBJDIRS}" != "no" ]; then
899: # If setting -M or -O to the root of an obj dir, make sure
900: # the base directory is made before continuing as <bsd.own.mk>
901: # will need this to pick up _SRC_TOP_OBJ_
902: #
903: if [ ! -z "${makeobjdir}" ]; then
904: ${runcmd} mkdir -p "${makeobjdir}"
905: fi
906:
907: # make obj in tools to ensure that the objdir for the top-level
908: # of the source tree and for "tools" is available, in case the
909: # default TOOLDIR setting from <bsd.own.mk> is used, or the
910: # build.sh default DESTDIR and RELEASEDIR is to be used.
911: #
1.98 lukem 912: ${runcmd} cd tools
913: ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
914: bomb "Failed to make obj in tools"
915: ${runcmd} cd "${TOP}"
1.84 lukem 916: fi
1.80 lukem 917:
1.98 lukem 918: # Find TOOLDIR, DESTDIR, and RELEASEDIR.
1.84 lukem 919: #
1.98 lukem 920: TOOLDIR=$(getmakevar TOOLDIR)
1.105 lukem 921: statusmsg "TOOLDIR path: ${TOOLDIR}"
1.98 lukem 922: DESTDIR=$(getmakevar DESTDIR)
923: RELEASEDIR=$(getmakevar RELEASEDIR)
924: if ! $do_expertmode; then
1.105 lukem 925: _SRC_TOP_OBJ_=$(getmakevar _SRC_TOP_OBJ_)
926: : ${DESTDIR:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}}
927: : ${RELEASEDIR:=${_SRC_TOP_OBJ_}/releasedir}
1.99 lukem 928: makeenv="${makeenv} DESTDIR RELEASEDIR"
1.98 lukem 929: fi
1.99 lukem 930: export TOOLDIR DESTDIR RELEASEDIR
1.105 lukem 931: statusmsg "DESTDIR path: ${DESTDIR}"
932: statusmsg "RELEASEDIR path: ${RELEASEDIR}"
1.84 lukem 933:
934: # Check validity of TOOLDIR and DESTDIR.
935: #
1.98 lukem 936: if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then
937: bomb "TOOLDIR '${TOOLDIR}' invalid"
1.84 lukem 938: fi
1.98 lukem 939: removedirs="${TOOLDIR}"
1.15 tv 940:
1.98 lukem 941: if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then
942: if ${do_build} || ${do_distribution} || ${do_release}; then
943: if ! ${do_build} || \
1.84 lukem 944: [ "${uname_s}" != "NetBSD" ] || \
1.98 lukem 945: [ "${uname_m}" != "${MACHINE}" ]; then
1.84 lukem 946: bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'."
947: fi
1.98 lukem 948: if ! ${do_expertmode}; then
1.84 lukem 949: bomb "DESTDIR must != / for non -E (expert) builds"
950: fi
1.98 lukem 951: statusmsg "WARNING: Building to /, in expert mode."
952: statusmsg " This may cause your system to break! Reasons include:"
953: statusmsg " - your kernel is not up to date"
954: statusmsg " - the libraries or toolchain have changed"
955: statusmsg " YOU HAVE BEEN WARNED!"
1.1 tv 956: fi
1.84 lukem 957: else
1.98 lukem 958: removedirs="${removedirs} ${DESTDIR}"
1.84 lukem 959: fi
1.98 lukem 960: if ${do_build} || ${do_distribution} || ${do_release}; then
961: if ! ${do_expertmode} && \
1.153 apb 962: [ "$(id -u 2>/dev/null)" -ne 0 ] && \
1.124 lukem 963: [ "${MKUNPRIVED}" = "no" ] ; then
1.86 lukem 964: bomb "-U or -E must be set for build as an unprivileged user."
965: fi
966: fi
1.105 lukem 967: if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then
968: bomb "Must set RELEASEDIR with \`releasekernel=...'"
969: fi
1.84 lukem 970: }
1.30 jmc 971:
1.15 tv 972:
1.84 lukem 973: createmakewrapper()
974: {
975: # Remove the target directories.
976: #
1.98 lukem 977: if ${do_removedirs}; then
978: for f in ${removedirs}; do
979: statusmsg "Removing ${f}"
980: ${runcmd} rm -r -f "${f}"
1.84 lukem 981: done
982: fi
1.15 tv 983:
1.84 lukem 984: # Recreate $TOOLDIR.
985: #
1.98 lukem 986: ${runcmd} mkdir -p "${TOOLDIR}/bin" ||
987: bomb "mkdir of '${TOOLDIR}/bin' failed"
1.84 lukem 988:
989: # Install ${toolprefix}make if it was built.
990: #
1.98 lukem 991: if ${do_rebuildmake}; then
992: ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make"
993: ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" ||
994: bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make"
995: make="${TOOLDIR}/bin/${toolprefix}make"
996: statusmsg "Created ${make}"
1.84 lukem 997: fi
1.15 tv 998:
1.84 lukem 999: # Build a ${toolprefix}make wrapper script, usable by hand as
1000: # well as by build.sh.
1001: #
1.98 lukem 1002: if [ -z "${makewrapper}" ]; then
1.102 lukem 1003: makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}"
1.98 lukem 1004: [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}"
1.52 thorpej 1005: fi
1.4 tv 1006:
1.98 lukem 1007: ${runcmd} rm -f "${makewrapper}"
1008: if [ "${runcmd}" = "echo" ]; then
1009: echo 'cat <<EOF >'${makewrapper}
1.84 lukem 1010: makewrapout=
1011: else
1.98 lukem 1012: makewrapout=">>\${makewrapper}"
1.84 lukem 1013: fi
1.18 tv 1014:
1.139 isaki 1015: case "${KSH_VERSION:-${SH_VERSION}}" in
1.149 jnemeth 1016: *PD\ KSH*|*MIRBSD\ KSH*)
1.135 isaki 1017: set +o braceexpand
1018: ;;
1019: esac
1020:
1.98 lukem 1021: eval cat <<EOF ${makewrapout}
1.153 apb 1022: #! ${HOST_SH}
1.4 tv 1023: # Set proper variables to allow easy "make" building of a NetBSD subtree.
1.166 ! apb 1024: # Generated from: \$NetBSD: build.sh,v 1.165 2007/04/02 10:57:36 apb Exp $
1.130 jmc 1025: # with these arguments: ${_args}
1.4 tv 1026: #
1.18 tv 1027: EOF
1.98 lukem 1028: for f in ${makeenv}; do
1.111 lukem 1029: if eval "[ -z \"\${$f}\" -a \"\${${f}-X}\" = \"X\" ]"; then
1030: eval echo "unset ${f}" ${makewrapout}
1031: else
1032: eval echo "${f}=\'\$$(echo ${f})\'\;\ export\ ${f}" ${makewrapout}
1033: fi
1.84 lukem 1034: done
1.18 tv 1035:
1.98 lukem 1036: eval cat <<EOF ${makewrapout}
1.154 dyoung 1037: MAKEWRAPPERMACHINE=${makewrappermachine:-${MACHINE}}; export MAKEWRAPPERMACHINE
1038: USETOOLS=yes; export USETOOLS
1.18 tv 1039:
1.98 lukem 1040: exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
1.4 tv 1041: EOF
1.98 lukem 1042: [ "${runcmd}" = "echo" ] && echo EOF
1043: ${runcmd} chmod +x "${makewrapper}"
1.105 lukem 1044: statusmsg "makewrapper: ${makewrapper}"
1.98 lukem 1045: statusmsg "Updated ${makewrapper}"
1.84 lukem 1046: }
1047:
1048: buildtools()
1049: {
1.98 lukem 1050: if [ "${MKOBJDIRS}" != "no" ]; then
1051: ${runcmd} "${makewrapper}" ${parallel} obj-tools ||
1052: bomb "Failed to make obj-tools"
1.84 lukem 1053: fi
1.98 lukem 1054: ${runcmd} cd tools
1.124 lukem 1055: if [ "${MKUPDATE}" = "no" ]; then
1.144 dsl 1056: ${runcmd} "${makewrapper}" ${parallel} cleandir ||
1057: bomb "Failed to make cleandir tools"
1.84 lukem 1058: fi
1.144 dsl 1059: ${runcmd} "${makewrapper}" ${parallel} dependall ||
1060: bomb "Failed to make dependall tools"
1061: ${runcmd} "${makewrapper}" ${parallel} install ||
1062: bomb "Failed to make install tools"
1.98 lukem 1063: statusmsg "Tools built to ${TOOLDIR}"
1.110 lukem 1064: ${runcmd} cd "${TOP}"
1.84 lukem 1065: }
1.4 tv 1066:
1.105 lukem 1067: getkernelconf()
1.84 lukem 1068: {
1.105 lukem 1069: kernelconf="$1"
1.114 lukem 1070: if [ "${MKOBJDIRS}" != "no" ]; then
1.84 lukem 1071: # The correct value of KERNOBJDIR might
1072: # depend on a prior "make obj" in
1073: # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
1074: #
1.98 lukem 1075: KERNSRCDIR="$(getmakevar KERNSRCDIR)"
1076: KERNARCHDIR="$(getmakevar KERNARCHDIR)"
1077: ${runcmd} cd "${KERNSRCDIR}/${KERNARCHDIR}/compile"
1.143 dsl 1078: ${runcmd} "${makewrapper}" ${parallel} obj ||
1.98 lukem 1079: bomb "Failed to make obj in ${KERNSRCDIR}/${KERNARCHDIR}/compile"
1080: ${runcmd} cd "${TOP}"
1.84 lukem 1081: fi
1.98 lukem 1082: KERNCONFDIR="$(getmakevar KERNCONFDIR)"
1083: KERNOBJDIR="$(getmakevar KERNOBJDIR)"
1.105 lukem 1084: case "${kernelconf}" in
1.84 lukem 1085: */*)
1.105 lukem 1086: kernelconfpath="${kernelconf}"
1087: kernelconfname="${kernelconf##*/}"
1.84 lukem 1088: ;;
1089: *)
1.105 lukem 1090: kernelconfpath="${KERNCONFDIR}/${kernelconf}"
1091: kernelconfname="${kernelconf}"
1.84 lukem 1092: ;;
1093: esac
1.105 lukem 1094: kernelbuildpath="${KERNOBJDIR}/${kernelconfname}"
1095: }
1096:
1097: buildkernel()
1098: {
1099: if ! ${do_tools} && ! ${buildkernelwarned:-false}; then
1100: # Building tools every time we build a kernel is clearly
1101: # unnecessary. We could try to figure out whether rebuilding
1102: # the tools is necessary this time, but it doesn't seem worth
1103: # the trouble. Instead, we say it's the user's responsibility
1104: # to rebuild the tools if necessary.
1105: #
1106: statusmsg "Building kernel without building new tools"
1107: buildkernelwarned=true
1108: fi
1109: getkernelconf $1
1110: statusmsg "Building kernel: ${kernelconf}"
1111: statusmsg "Build directory: ${kernelbuildpath}"
1112: ${runcmd} mkdir -p "${kernelbuildpath}" ||
1113: bomb "Cannot mkdir: ${kernelbuildpath}"
1.124 lukem 1114: if [ "${MKUPDATE}" = "no" ]; then
1.105 lukem 1115: ${runcmd} cd "${kernelbuildpath}"
1.143 dsl 1116: ${runcmd} "${makewrapper}" ${parallel} cleandir ||
1.105 lukem 1117: bomb "Failed to make cleandir in ${kernelbuildpath}"
1.98 lukem 1118: ${runcmd} cd "${TOP}"
1.16 thorpej 1119: fi
1.157 rillig 1120: [ -x "${TOOLDIR}/bin/${toolprefix}config" ] \
1121: || bomb "${TOOLDIR}/bin/${toolprefix}config does not exist. You need to \"$0 tools\" first."
1.105 lukem 1122: ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" -b "${kernelbuildpath}" \
1123: -s "${TOP}/sys" "${kernelconfpath}" ||
1124: bomb "${toolprefix}config failed for ${kernelconf}"
1125: ${runcmd} cd "${kernelbuildpath}"
1.143 dsl 1126: ${runcmd} "${makewrapper}" ${parallel} depend ||
1.105 lukem 1127: bomb "Failed to make depend in ${kernelbuildpath}"
1.98 lukem 1128: ${runcmd} "${makewrapper}" ${parallel} all ||
1.105 lukem 1129: bomb "Failed to make all in ${kernelbuildpath}"
1.98 lukem 1130: ${runcmd} cd "${TOP}"
1.91 lukem 1131:
1.98 lukem 1132: if [ "${runcmd}" != "echo" ]; then
1.105 lukem 1133: statusmsg "Kernels built from ${kernelconf}:"
1134: kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1.91 lukem 1135: for kern in ${kernlist:-netbsd}; do
1.105 lukem 1136: [ -f "${kernelbuildpath}/${kern}" ] && \
1137: echo " ${kernelbuildpath}/${kern}"
1.98 lukem 1138: done | tee -a "${results}"
1.91 lukem 1139: fi
1.84 lukem 1140: }
1141:
1.105 lukem 1142: releasekernel()
1143: {
1144: getkernelconf $1
1145: kernelreldir="${RELEASEDIR}/${MACHINE}/binary/kernel"
1146: ${runcmd} mkdir -p "${kernelreldir}"
1147: kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1148: for kern in ${kernlist:-netbsd}; do
1149: builtkern="${kernelbuildpath}/${kern}"
1150: [ -f "${builtkern}" ] || continue
1151: releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz"
1152: statusmsg "Kernel copy: ${releasekern}"
1153: ${runcmd} gzip -c -9 < "${builtkern}" > "${releasekern}"
1154: done
1155: }
1156:
1.84 lukem 1157: installworld()
1158: {
1159: dir="$1"
1.98 lukem 1160: ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld ||
1161: bomb "Failed to make installworld to ${dir}"
1162: statusmsg "Successful installworld to ${dir}"
1.84 lukem 1163: }
1164:
1165:
1166: main()
1167: {
1168: initdefaults
1.130 jmc 1169: _args=$@
1.84 lukem 1170: parseoptions "$@"
1.93 lukem 1171:
1.163 apb 1172: sanitycheck
1173:
1.93 lukem 1174: build_start=$(date)
1.98 lukem 1175: statusmsg "${progname} command: $0 $@"
1176: statusmsg "${progname} started: ${build_start}"
1.165 apb 1177: statusmsg "NetBSD version: ${DISTRIBVER}"
1178: statusmsg "MACHINE: ${MACHINE}"
1179: statusmsg "MACHINE_ARCH: ${MACHINE_ARCH}"
1180: statusmsg "Build platform: ${uname_s} ${uname_r} ${uname_m}"
1.153 apb 1181: statusmsg "HOST_SH: ${HOST_SH}"
1182:
1.84 lukem 1183: rebuildmake
1184: validatemakeparams
1185: createmakewrapper
1186:
1187: # Perform the operations.
1188: #
1.98 lukem 1189: for op in ${operations}; do
1190: case "${op}" in
1.86 lukem 1191:
1192: makewrapper)
1193: # no-op
1194: ;;
1.84 lukem 1195:
1196: tools)
1197: buildtools
1198: ;;
1199:
1.125 lukem 1200: sets)
1201: statusmsg "Building sets from pre-populated ${DESTDIR}"
1202: ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1203: bomb "Failed to make ${op}"
1204: statusmsg "Successful make ${op}"
1205: ;;
1.142 apb 1206:
1.145 apb 1207: obj|build|distribution|iso-image|release|sourcesets|syspkgs|params)
1.98 lukem 1208: ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1209: bomb "Failed to make ${op}"
1210: statusmsg "Successful make ${op}"
1.84 lukem 1211: ;;
1212:
1213: kernel=*)
1214: arg=${op#*=}
1215: buildkernel "${arg}"
1.105 lukem 1216: ;;
1217:
1218: releasekernel=*)
1219: arg=${op#*=}
1220: releasekernel "${arg}"
1.84 lukem 1221: ;;
1222:
1223: install=*)
1224: arg=${op#*=}
1.85 lukem 1225: if [ "${arg}" = "/" ] && \
1226: ( [ "${uname_s}" != "NetBSD" ] || \
1.98 lukem 1227: [ "${uname_m}" != "${MACHINE}" ] ); then
1.85 lukem 1228: bomb "'${op}' must != / for cross builds."
1229: fi
1.84 lukem 1230: installworld "${arg}"
1.70 lukem 1231: ;;
1.84 lukem 1232:
1.70 lukem 1233: *)
1.84 lukem 1234: bomb "Unknown operation \`${op}'"
1.70 lukem 1235: ;;
1.84 lukem 1236:
1.70 lukem 1237: esac
1.84 lukem 1238: done
1.93 lukem 1239:
1.98 lukem 1240: statusmsg "${progname} ended: $(date)"
1241: if [ -s "${results}" ]; then
1242: echo "===> Summary of results:"
1243: sed -e 's/^===>//;s/^/ /' "${results}"
1244: echo "===> ."
1245: fi
1.84 lukem 1246: }
1247:
1248: main "$@"
CVSweb <webmaster@jp.NetBSD.org>