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