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