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