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