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