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