Annotation of src/build.sh, Revision 1.112
1.67 thorpej 1: #! /usr/bin/env sh
1.112 ! sommerfe 2: # $NetBSD: build.sh,v 1.111 2003/07/29 10:07:15 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.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.98 lukem 187: amigappc|bebox|evbppc|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.84 lukem 344: Usage: ${progname} [-EnorUu] [-a arch] [-B buildid] [-D dest] [-j njob] [-M obj]
1.98 lukem 345: [-m mach] [-O obj] [-R release] [-T tools] [-V var=[value]]
1.111 lukem 346: [-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.102 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)
377: -n Show commands that would be executed, but do not execute them
1.111 lukem 378: -O obj Set obj root directory to obj (sets a MAKEOBJDIR pattern).
379: Unsets MAKEOBJDIRPREFIX.
1.98 lukem 380: -o Set MKOBJDIRS=no (do not create objdirs at start of build)
1.102 lukem 381: -R release Set RELEASEDIR to release. (Default: releasedir)
1.98 lukem 382: -r Remove contents of TOOLDIR and DESTDIR before building
383: -T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in
384: the environment, ${toolprefix}make will be (re)built unconditionally
1.112 ! sommerfe 385: -U Set MKUNPRIVED=yes (build without requiring root privileges;
! 386: install from an UNPRIVED build with proper file permissions)
1.108 lukem 387: -u Set MKUPDATE=yes (do not run "make clean" first).
1.98 lukem 388: Without this, everything is rebuilt, including the tools.
389: -V v=[val] Set variable \`v' to \`val'
390: -w wrapper Create ${toolprefix}make script as wrapper
391: (Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE})
1.111 lukem 392: -Z v Unset ("zap") variable \`v'
1.83 lukem 393:
1.70 lukem 394: _usage_
1.1 tv 395: exit 1
396: }
397:
1.84 lukem 398: parseoptions()
399: {
1.111 lukem 400: opts='a:B:bD:dEhi:j:k:M:m:nO:oR:rT:tUuV:w:Z:'
1.84 lukem 401: opt_a=no
402:
403: if type getopts >/dev/null 2>&1; then
404: # Use POSIX getopts.
1.98 lukem 405: #
406: getoptcmd='getopts ${opts} opt && opt=-${opt}'
1.84 lukem 407: optargcmd=':'
1.98 lukem 408: optremcmd='shift $((${OPTIND} -1))'
1.84 lukem 409: else
410: type getopt >/dev/null 2>&1 ||
411: bomb "/bin/sh shell is too old; try ksh or bash"
412:
413: # Use old-style getopt(1) (doesn't handle whitespace in args).
1.98 lukem 414: #
415: args="$(getopt ${opts} $*)"
1.84 lukem 416: [ $? = 0 ] || usage
1.98 lukem 417: set -- ${args}
1.84 lukem 418:
419: getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
420: optargcmd='OPTARG="$1"; shift'
421: optremcmd=':'
422: fi
423:
424: # Parse command line options.
425: #
1.98 lukem 426: while eval ${getoptcmd}; do
427: case ${opt} in
1.84 lukem 428:
429: -a)
1.98 lukem 430: eval ${optargcmd}
431: MACHINE_ARCH=${OPTARG}
1.84 lukem 432: opt_a=yes
433: ;;
434:
435: -B)
1.98 lukem 436: eval ${optargcmd}
437: BUILDID=${OPTARG}
1.84 lukem 438: ;;
439:
440: -b)
1.86 lukem 441: usage "'-b' has been replaced by 'makewrapper'"
1.84 lukem 442: ;;
443:
444: -D)
1.98 lukem 445: eval ${optargcmd}; resolvepath
1.109 lukem 446: setmakeenv DESTDIR "${OPTARG}"
1.84 lukem 447: ;;
448:
449: -d)
450: usage "'-d' has been replaced by 'distribution'"
451: ;;
452:
453: -E)
454: do_expertmode=true
455: ;;
456:
457: -i)
458: usage "'-i idir' has been replaced by 'install=idir'"
459: ;;
460:
461: -j)
1.98 lukem 462: eval ${optargcmd}
463: parallel="-j ${OPTARG}"
1.84 lukem 464: ;;
465:
466: -k)
467: usage "'-k conf' has been replaced by 'kernel=conf'"
468: ;;
469:
470: -M)
1.98 lukem 471: eval ${optargcmd}; resolvepath
472: makeobjdir="${OPTARG}"
1.111 lukem 473: unsetmakeenv MAKEOBJDIR
1.109 lukem 474: setmakeenv MAKEOBJDIRPREFIX "${OPTARG}"
1.84 lukem 475: ;;
476:
477: # -m overrides MACHINE_ARCH unless "-a" is specified
478: -m)
1.98 lukem 479: eval ${optargcmd}
480: MACHINE="${OPTARG}"
481: [ "${opt_a}" != "yes" ] && getarch
1.84 lukem 482: ;;
483:
484: -n)
485: runcmd=echo
486: ;;
487:
488: -O)
1.98 lukem 489: eval ${optargcmd}; resolvepath
490: makeobjdir="${OPTARG}"
1.111 lukem 491: unsetmakeenv MAKEOBJDIRPREFIX
1.109 lukem 492: setmakeenv MAKEOBJDIR "\${.CURDIR:C,^$TOP,$OPTARG,}"
1.84 lukem 493: ;;
494:
495: -o)
496: MKOBJDIRS=no
497: ;;
498:
499: -R)
1.98 lukem 500: eval ${optargcmd}; resolvepath
1.109 lukem 501: setmakeenv RELEASEDIR "${OPTARG}"
1.84 lukem 502: ;;
503:
504: -r)
505: do_removedirs=true
506: do_rebuildmake=true
507: ;;
508:
509: -T)
1.98 lukem 510: eval ${optargcmd}; resolvepath
511: TOOLDIR="${OPTARG}"
1.84 lukem 512: export TOOLDIR
513: ;;
514:
515: -t)
516: usage "'-t' has been replaced by 'tools'"
517: ;;
1.16 thorpej 518:
1.84 lukem 519: -U)
1.109 lukem 520: setmakeenv MKUNPRIVED yes
1.84 lukem 521: ;;
1.44 lukem 522:
1.84 lukem 523: -u)
1.109 lukem 524: setmakeenv MKUPDATE yes
1.84 lukem 525: ;;
1.15 tv 526:
1.84 lukem 527: -V)
1.98 lukem 528: eval ${optargcmd}
1.84 lukem 529: case "${OPTARG}" in
1.80 lukem 530: # XXX: consider restricting which variables can be changed?
1.84 lukem 531: [a-zA-Z_][a-zA-Z_0-9]*=*)
1.109 lukem 532: setmakeenv "${OPTARG%%=*}" "${OPTARG#*=}"
1.84 lukem 533: ;;
534: *)
535: usage "-V argument must be of the form 'var=[value]'"
536: ;;
537: esac
538: ;;
539:
540: -w)
1.98 lukem 541: eval ${optargcmd}; resolvepath
542: makewrapper="${OPTARG}"
1.84 lukem 543: ;;
544:
1.111 lukem 545: -Z)
546: eval ${optargcmd}
547: # XXX: consider restricting which variables can be unset?
548: unsetmakeenv "${OPTARG}"
549: ;;
550:
1.84 lukem 551: --)
552: break
553: ;;
554:
555: -'?'|-h)
556: usage
557: ;;
558:
559: esac
560: done
561:
562: # Validate operations.
563: #
1.98 lukem 564: eval ${optremcmd}
1.84 lukem 565: while [ $# -gt 0 ]; do
566: op=$1; shift
1.98 lukem 567: operations="${operations} ${op}"
1.84 lukem 568:
1.98 lukem 569: case "${op}" in
1.84 lukem 570:
1.87 lukem 571: help)
572: usage
573: ;;
574:
1.107 lukem 575: makewrapper|obj|tools|build|distribution|release|sets|sourcesets|params)
1.80 lukem 576: ;;
1.84 lukem 577:
1.105 lukem 578: kernel=*|releasekernel=*)
1.84 lukem 579: arg=${op#*=}
580: op=${op%%=*}
1.98 lukem 581: [ -n "${arg}" ] ||
1.105 lukem 582: bomb "Must supply a kernel name with \`${op}=...'"
1.84 lukem 583: ;;
584:
585: install=*)
586: arg=${op#*=}
587: op=${op%%=*}
1.98 lukem 588: [ -n "${arg}" ] ||
589: bomb "Must supply a directory with \`install=...'"
1.84 lukem 590: ;;
591:
1.80 lukem 592: *)
1.84 lukem 593: usage "Unknown operation \`${op}'"
594: ;;
595:
1.80 lukem 596: esac
1.98 lukem 597: eval do_${op}=true
1.84 lukem 598: done
1.98 lukem 599: [ -n "${operations}" ] || usage "Missing operation to perform."
1.84 lukem 600:
601: # Set up MACHINE*. On a NetBSD host, these are allowed to be unset.
602: #
1.98 lukem 603: if [ -z "${MACHINE}" ]; then
604: [ "${uname_s}" = "NetBSD" ] ||
605: bomb "MACHINE must be set, or -m must be used, for cross builds."
1.84 lukem 606: MACHINE=${uname_m}
607: fi
1.98 lukem 608: [ -n "${MACHINE_ARCH}" ] || getarch
1.84 lukem 609: validatearch
610:
611: # Set up default make(1) environment.
612: #
1.109 lukem 613: setmakeenv LC_ALL C
1.98 lukem 614: makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
615: [ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID"
616: MAKEFLAGS="-m ${TOP}/share/mk ${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}"
1.84 lukem 617: export MAKEFLAGS MACHINE MACHINE_ARCH
618: }
619:
620: rebuildmake()
621: {
622: # Test make source file timestamps against installed ${toolprefix}make
623: # binary, if TOOLDIR is pre-set.
624: #
625: # Note that we do NOT try to grovel "mk.conf" here to find out if
626: # TOOLDIR is set there, because it can contain make variable
627: # expansions and other stuff only parseable *after* we have a working
628: # ${toolprefix}make. So this logic can only work if the user has
629: # pre-set TOOLDIR in the environment or used the -T option to build.sh.
630: #
631: make="${TOOLDIR-nonexistent}/bin/${toolprefix}make"
1.98 lukem 632: if [ -x "${make}" ]; then
1.84 lukem 633: for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
1.98 lukem 634: if [ "${f}" -nt "${make}" ]; then
1.84 lukem 635: do_rebuildmake=true
636: break
637: fi
638: done
639: else
640: do_rebuildmake=true
641: fi
642:
643: # Build bootstrap ${toolprefix}make if needed.
1.98 lukem 644: if ${do_rebuildmake}; then
645: statusmsg "Bootstrapping ${toolprefix}make"
646: ${runcmd} cd "${tmpdir}"
647: ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
1.84 lukem 648: CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
1.98 lukem 649: "${TOP}/tools/make/configure" ||
650: bomb "Configure of ${toolprefix}make failed"
651: ${runcmd} sh buildmake.sh ||
652: bomb "Build of ${toolprefix}make failed"
653: make="${tmpdir}/${toolprefix}make"
654: ${runcmd} cd "${TOP}"
655: ${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
1.84 lukem 656: fi
657: }
658:
659: validatemakeparams()
660: {
1.98 lukem 661: if [ "${runcmd}" = "echo" ]; then
1.84 lukem 662: TOOLCHAIN_MISSING=no
663: EXTERNAL_TOOLCHAIN=""
664: else
1.98 lukem 665: TOOLCHAIN_MISSING=$(raw_getmakevar TOOLCHAIN_MISSING)
666: EXTERNAL_TOOLCHAIN=$(raw_getmakevar EXTERNAL_TOOLCHAIN)
1.84 lukem 667: fi
668: if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
1.86 lukem 669: [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
1.98 lukem 670: ${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
671: ${runcmd} echo " MACHINE: ${MACHINE}"
672: ${runcmd} echo " MACHINE_ARCH: ${MACHINE_ARCH}"
673: ${runcmd} echo ""
674: ${runcmd} echo "All builds for this platform should be done via a traditional make"
675: ${runcmd} echo "If you wish to use an external cross-toolchain, set"
676: ${runcmd} echo " EXTERNAL_TOOLCHAIN=<path to toolchain root>"
677: ${runcmd} echo "in either the environment or mk.conf and rerun"
678: ${runcmd} echo " ${progname} $*"
1.84 lukem 679: exit 1
680: fi
681:
1.106 lukem 682: if [ "${MKOBJDIRS}" != "no" ]; then
683: # If setting -M or -O to the root of an obj dir, make sure
684: # the base directory is made before continuing as <bsd.own.mk>
685: # will need this to pick up _SRC_TOP_OBJ_
686: #
687: if [ ! -z "${makeobjdir}" ]; then
688: ${runcmd} mkdir -p "${makeobjdir}"
689: fi
690:
691: # make obj in tools to ensure that the objdir for the top-level
692: # of the source tree and for "tools" is available, in case the
693: # default TOOLDIR setting from <bsd.own.mk> is used, or the
694: # build.sh default DESTDIR and RELEASEDIR is to be used.
695: #
1.98 lukem 696: ${runcmd} cd tools
697: ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
698: bomb "Failed to make obj in tools"
699: ${runcmd} cd "${TOP}"
1.84 lukem 700: fi
1.80 lukem 701:
1.105 lukem 702: statusmsg "MACHINE: ${MACHINE}"
703: statusmsg "MACHINE_ARCH: ${MACHINE_ARCH}"
1.98 lukem 704:
705: # Find TOOLDIR, DESTDIR, and RELEASEDIR.
1.84 lukem 706: #
1.98 lukem 707: TOOLDIR=$(getmakevar TOOLDIR)
1.105 lukem 708: statusmsg "TOOLDIR path: ${TOOLDIR}"
1.98 lukem 709: DESTDIR=$(getmakevar DESTDIR)
710: RELEASEDIR=$(getmakevar RELEASEDIR)
711: if ! $do_expertmode; then
1.105 lukem 712: _SRC_TOP_OBJ_=$(getmakevar _SRC_TOP_OBJ_)
713: : ${DESTDIR:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}}
714: : ${RELEASEDIR:=${_SRC_TOP_OBJ_}/releasedir}
1.99 lukem 715: makeenv="${makeenv} DESTDIR RELEASEDIR"
1.98 lukem 716: fi
1.99 lukem 717: export TOOLDIR DESTDIR RELEASEDIR
1.105 lukem 718: statusmsg "DESTDIR path: ${DESTDIR}"
719: statusmsg "RELEASEDIR path: ${RELEASEDIR}"
1.84 lukem 720:
721: # Check validity of TOOLDIR and DESTDIR.
722: #
1.98 lukem 723: if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then
724: bomb "TOOLDIR '${TOOLDIR}' invalid"
1.84 lukem 725: fi
1.98 lukem 726: removedirs="${TOOLDIR}"
1.15 tv 727:
1.98 lukem 728: if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then
729: if ${do_build} || ${do_distribution} || ${do_release}; then
730: if ! ${do_build} || \
1.84 lukem 731: [ "${uname_s}" != "NetBSD" ] || \
1.98 lukem 732: [ "${uname_m}" != "${MACHINE}" ]; then
1.84 lukem 733: bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'."
734: fi
1.98 lukem 735: if ! ${do_expertmode}; then
1.84 lukem 736: bomb "DESTDIR must != / for non -E (expert) builds"
737: fi
1.98 lukem 738: statusmsg "WARNING: Building to /, in expert mode."
739: statusmsg " This may cause your system to break! Reasons include:"
740: statusmsg " - your kernel is not up to date"
741: statusmsg " - the libraries or toolchain have changed"
742: statusmsg " YOU HAVE BEEN WARNED!"
1.1 tv 743: fi
1.84 lukem 744: else
1.98 lukem 745: removedirs="${removedirs} ${DESTDIR}"
1.84 lukem 746: fi
1.98 lukem 747: if ${do_build} || ${do_distribution} || ${do_release}; then
748: if ! ${do_expertmode} && \
1.108 lukem 749: [ $(id -u 2>/dev/null) -ne 0 ] && \
750: [ -z "${MKUNPRIVED}" ] ; then
1.86 lukem 751: bomb "-U or -E must be set for build as an unprivileged user."
752: fi
753: fi
1.105 lukem 754: if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then
755: bomb "Must set RELEASEDIR with \`releasekernel=...'"
756: fi
1.84 lukem 757: }
1.30 jmc 758:
1.15 tv 759:
1.84 lukem 760: createmakewrapper()
761: {
762: # Remove the target directories.
763: #
1.98 lukem 764: if ${do_removedirs}; then
765: for f in ${removedirs}; do
766: statusmsg "Removing ${f}"
767: ${runcmd} rm -r -f "${f}"
1.84 lukem 768: done
769: fi
1.15 tv 770:
1.84 lukem 771: # Recreate $TOOLDIR.
772: #
1.98 lukem 773: ${runcmd} mkdir -p "${TOOLDIR}/bin" ||
774: bomb "mkdir of '${TOOLDIR}/bin' failed"
1.84 lukem 775:
776: # Install ${toolprefix}make if it was built.
777: #
1.98 lukem 778: if ${do_rebuildmake}; then
779: ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make"
780: ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" ||
781: bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make"
782: make="${TOOLDIR}/bin/${toolprefix}make"
783: statusmsg "Created ${make}"
1.84 lukem 784: fi
1.15 tv 785:
1.84 lukem 786: # Build a ${toolprefix}make wrapper script, usable by hand as
787: # well as by build.sh.
788: #
1.98 lukem 789: if [ -z "${makewrapper}" ]; then
1.102 lukem 790: makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}"
1.98 lukem 791: [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}"
1.52 thorpej 792: fi
1.4 tv 793:
1.98 lukem 794: ${runcmd} rm -f "${makewrapper}"
795: if [ "${runcmd}" = "echo" ]; then
796: echo 'cat <<EOF >'${makewrapper}
1.84 lukem 797: makewrapout=
798: else
1.98 lukem 799: makewrapout=">>\${makewrapper}"
1.84 lukem 800: fi
1.18 tv 801:
1.98 lukem 802: eval cat <<EOF ${makewrapout}
1.4 tv 803: #! /bin/sh
804: # Set proper variables to allow easy "make" building of a NetBSD subtree.
1.112 ! sommerfe 805: # Generated from: \$NetBSD: build.sh,v 1.111 2003/07/29 10:07:15 lukem Exp $
1.4 tv 806: #
1.18 tv 807:
808: EOF
1.98 lukem 809: for f in ${makeenv}; do
1.111 lukem 810: if eval "[ -z \"\${$f}\" -a \"\${${f}-X}\" = \"X\" ]"; then
811: eval echo "unset ${f}" ${makewrapout}
812: else
813: eval echo "${f}=\'\$$(echo ${f})\'\;\ export\ ${f}" ${makewrapout}
814: fi
1.84 lukem 815: done
1.98 lukem 816: eval echo "USETOOLS=yes\; export USETOOLS" ${makewrapout}
1.18 tv 817:
1.98 lukem 818: eval cat <<EOF ${makewrapout}
1.18 tv 819:
1.98 lukem 820: exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
1.4 tv 821: EOF
1.98 lukem 822: [ "${runcmd}" = "echo" ] && echo EOF
823: ${runcmd} chmod +x "${makewrapper}"
1.105 lukem 824: statusmsg "makewrapper: ${makewrapper}"
1.98 lukem 825: statusmsg "Updated ${makewrapper}"
1.84 lukem 826: }
827:
828: buildtools()
829: {
1.98 lukem 830: if [ "${MKOBJDIRS}" != "no" ]; then
831: ${runcmd} "${makewrapper}" ${parallel} obj-tools ||
832: bomb "Failed to make obj-tools"
1.84 lukem 833: fi
1.98 lukem 834: ${runcmd} cd tools
1.108 lukem 835: if [ -z "${MKUPDATE}" ]; then
1.84 lukem 836: cleandir=cleandir
837: else
838: cleandir=
839: fi
1.98 lukem 840: ${runcmd} "${makewrapper}" ${cleandir} dependall install ||
841: bomb "Failed to make tools"
842: statusmsg "Tools built to ${TOOLDIR}"
1.110 lukem 843: ${runcmd} cd "${TOP}"
1.84 lukem 844: }
1.4 tv 845:
1.105 lukem 846: getkernelconf()
1.84 lukem 847: {
1.105 lukem 848: kernelconf="$1"
1.98 lukem 849: if [ "${MKOBJDIRS}" != "no" ] && [ ! -z "${makeobjdir}" ]; then
1.84 lukem 850: # The correct value of KERNOBJDIR might
851: # depend on a prior "make obj" in
852: # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
853: #
1.98 lukem 854: KERNSRCDIR="$(getmakevar KERNSRCDIR)"
855: KERNARCHDIR="$(getmakevar KERNARCHDIR)"
856: ${runcmd} cd "${KERNSRCDIR}/${KERNARCHDIR}/compile"
857: ${runcmd} "${makewrapper}" obj ||
858: bomb "Failed to make obj in ${KERNSRCDIR}/${KERNARCHDIR}/compile"
859: ${runcmd} cd "${TOP}"
1.84 lukem 860: fi
1.98 lukem 861: KERNCONFDIR="$(getmakevar KERNCONFDIR)"
862: KERNOBJDIR="$(getmakevar KERNOBJDIR)"
1.105 lukem 863: case "${kernelconf}" in
1.84 lukem 864: */*)
1.105 lukem 865: kernelconfpath="${kernelconf}"
866: kernelconfname="${kernelconf##*/}"
1.84 lukem 867: ;;
868: *)
1.105 lukem 869: kernelconfpath="${KERNCONFDIR}/${kernelconf}"
870: kernelconfname="${kernelconf}"
1.84 lukem 871: ;;
872: esac
1.105 lukem 873: kernelbuildpath="${KERNOBJDIR}/${kernelconfname}"
874: }
875:
876: buildkernel()
877: {
878: if ! ${do_tools} && ! ${buildkernelwarned:-false}; then
879: # Building tools every time we build a kernel is clearly
880: # unnecessary. We could try to figure out whether rebuilding
881: # the tools is necessary this time, but it doesn't seem worth
882: # the trouble. Instead, we say it's the user's responsibility
883: # to rebuild the tools if necessary.
884: #
885: statusmsg "Building kernel without building new tools"
886: buildkernelwarned=true
887: fi
888: getkernelconf $1
889: statusmsg "Building kernel: ${kernelconf}"
890: statusmsg "Build directory: ${kernelbuildpath}"
891: ${runcmd} mkdir -p "${kernelbuildpath}" ||
892: bomb "Cannot mkdir: ${kernelbuildpath}"
1.108 lukem 893: if [ -z "${MKUPDATE}" ]; then
1.105 lukem 894: ${runcmd} cd "${kernelbuildpath}"
1.98 lukem 895: ${runcmd} "${makewrapper}" cleandir ||
1.105 lukem 896: bomb "Failed to make cleandir in ${kernelbuildpath}"
1.98 lukem 897: ${runcmd} cd "${TOP}"
1.16 thorpej 898: fi
1.105 lukem 899: ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" -b "${kernelbuildpath}" \
900: -s "${TOP}/sys" "${kernelconfpath}" ||
901: bomb "${toolprefix}config failed for ${kernelconf}"
902: ${runcmd} cd "${kernelbuildpath}"
1.98 lukem 903: ${runcmd} "${makewrapper}" depend ||
1.105 lukem 904: bomb "Failed to make depend in ${kernelbuildpath}"
1.98 lukem 905: ${runcmd} "${makewrapper}" ${parallel} all ||
1.105 lukem 906: bomb "Failed to make all in ${kernelbuildpath}"
1.98 lukem 907: ${runcmd} cd "${TOP}"
1.91 lukem 908:
1.98 lukem 909: if [ "${runcmd}" != "echo" ]; then
1.105 lukem 910: statusmsg "Kernels built from ${kernelconf}:"
911: kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1.91 lukem 912: for kern in ${kernlist:-netbsd}; do
1.105 lukem 913: [ -f "${kernelbuildpath}/${kern}" ] && \
914: echo " ${kernelbuildpath}/${kern}"
1.98 lukem 915: done | tee -a "${results}"
1.91 lukem 916: fi
1.84 lukem 917: }
918:
1.105 lukem 919: releasekernel()
920: {
921: getkernelconf $1
922: kernelreldir="${RELEASEDIR}/${MACHINE}/binary/kernel"
923: ${runcmd} mkdir -p "${kernelreldir}"
924: kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
925: for kern in ${kernlist:-netbsd}; do
926: builtkern="${kernelbuildpath}/${kern}"
927: [ -f "${builtkern}" ] || continue
928: releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz"
929: statusmsg "Kernel copy: ${releasekern}"
930: ${runcmd} gzip -c -9 < "${builtkern}" > "${releasekern}"
931: done
932: }
933:
1.84 lukem 934: installworld()
935: {
936: dir="$1"
1.98 lukem 937: ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld ||
938: bomb "Failed to make installworld to ${dir}"
939: statusmsg "Successful installworld to ${dir}"
1.84 lukem 940: }
941:
942:
943: main()
944: {
945: initdefaults
946: parseoptions "$@"
1.93 lukem 947:
948: build_start=$(date)
1.98 lukem 949: statusmsg "${progname} command: $0 $@"
950: statusmsg "${progname} started: ${build_start}"
1.93 lukem 951:
1.84 lukem 952: rebuildmake
953: validatemakeparams
954: createmakewrapper
955:
956: # Perform the operations.
957: #
1.98 lukem 958: for op in ${operations}; do
959: case "${op}" in
1.86 lukem 960:
961: makewrapper)
962: # no-op
963: ;;
1.84 lukem 964:
965: tools)
966: buildtools
967: ;;
968:
1.107 lukem 969: obj|build|distribution|release|sets|sourcesets|params)
1.98 lukem 970: ${runcmd} "${makewrapper}" ${parallel} ${op} ||
971: bomb "Failed to make ${op}"
972: statusmsg "Successful make ${op}"
1.84 lukem 973: ;;
974:
975: kernel=*)
976: arg=${op#*=}
977: buildkernel "${arg}"
1.105 lukem 978: ;;
979:
980: releasekernel=*)
981: arg=${op#*=}
982: releasekernel "${arg}"
1.84 lukem 983: ;;
984:
985: install=*)
986: arg=${op#*=}
1.85 lukem 987: if [ "${arg}" = "/" ] && \
988: ( [ "${uname_s}" != "NetBSD" ] || \
1.98 lukem 989: [ "${uname_m}" != "${MACHINE}" ] ); then
1.85 lukem 990: bomb "'${op}' must != / for cross builds."
991: fi
1.84 lukem 992: installworld "${arg}"
1.70 lukem 993: ;;
1.84 lukem 994:
1.70 lukem 995: *)
1.84 lukem 996: bomb "Unknown operation \`${op}'"
1.70 lukem 997: ;;
1.84 lukem 998:
1.70 lukem 999: esac
1.84 lukem 1000: done
1.93 lukem 1001:
1.104 lukem 1002: statusmsg "${progname} started: ${build_start}"
1.98 lukem 1003: statusmsg "${progname} ended: $(date)"
1004: if [ -s "${results}" ]; then
1005: echo "===> Summary of results:"
1006: sed -e 's/^===>//;s/^/ /' "${results}"
1007: echo "===> ."
1008: fi
1.84 lukem 1009: }
1010:
1011: main "$@"
CVSweb <webmaster@jp.NetBSD.org>