Annotation of src/build.sh, Revision 1.94
1.67 thorpej 1: #! /usr/bin/env sh
1.94 ! lukem 2: # $NetBSD: build.sh,v 1.93 2003/03/04 02:20:28 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.82 lukem 51: trap "exit 1" 1 2 3 15
1.84 lukem 52:
1.79 lukem 53: bomb()
54: {
1.82 lukem 55: cat >&2 <<ERRORMESSAGE
56:
57: ERROR: $@
58: *** BUILD ABORTED ***
59: ERRORMESSAGE
60: kill $toppid # in case we were invoked from a subshell
1.1 tv 61: exit 1
62: }
1.78 lukem 63:
1.84 lukem 64:
65: initdefaults()
66: {
67: cd "$(dirname $0)"
68: [ -d usr.bin/make ] ||
69: bomb "build.sh must be run from the top source level"
70: [ -f share/mk/bsd.own.mk ] ||
71: bomb "src/share/mk is missing; please re-fetch the source tree"
72:
73: uname_s=$(uname -s 2>/dev/null)
74: uname_m=$(uname -m 2>/dev/null)
75:
76: # If $PWD is a valid name of the current directory, POSIX mandates
77: # that pwd return it by default which causes problems in the
78: # presence of symlinks. Unsetting PWD is simpler than changing
79: # every occurrence of pwd to use -P.
80: #
81: # XXX Except that doesn't work on Solaris.
82: unset PWD
83: if [ "${uname_s}" = "SunOS" ]; then
84: TOP=$(pwd -P)
85: else
86: TOP=$(pwd)
87: fi
88:
89: # Set defaults.
90: toolprefix=nb
91: MAKEFLAGS=
92: makeenv=
93: makewrapper=
94: runcmd=
95: operations=
96: removedirs=
97: do_expertmode=false
98: do_rebuildmake=false
99: do_removedirs=false
100:
101: # do_{operation}=true if given operation is requested.
102: #
103: do_tools=false
104: do_obj=false
105: do_build=false
106: do_distribution=false
107: do_release=false
108: do_kernel=false
109: do_install=false
1.87 lukem 110: do_sets=false
1.84 lukem 111: }
1.29 jmc 112:
1.79 lukem 113: getarch()
114: {
1.1 tv 115: # Translate a MACHINE into a default MACHINE_ARCH.
1.84 lukem 116: #
1.1 tv 117: case $MACHINE in
118:
1.84 lukem 119: acorn26|acorn32|cats|netwinder|shark|*arm)
120: MACHINE_ARCH=arm
121: ;;
122:
123: sun2)
124: MACHINE_ARCH=m68000
125: ;;
126:
127: amiga|atari|cesfic|hp300|sun3|*68k)
128: MACHINE_ARCH=m68k
129: ;;
1.1 tv 130:
1.84 lukem 131: mipsco|newsmips|sbmips|sgimips)
132: MACHINE_ARCH=mipseb
133: ;;
1.1 tv 134:
1.84 lukem 135: algor|arc|cobalt|evbmips|hpcmips|playstation2|pmax)
136: MACHINE_ARCH=mipsel
137: ;;
1.1 tv 138:
1.84 lukem 139: pc532)
140: MACHINE_ARCH=ns32k
141: ;;
1.1 tv 142:
1.84 lukem 143: bebox|prep|sandpoint|*ppc)
144: MACHINE_ARCH=powerpc
145: ;;
1.1 tv 146:
1.84 lukem 147: evbsh3|mmeye)
148: MACHINE_ARCH=sh3eb
149: ;;
1.1 tv 150:
1.84 lukem 151: dreamcast|hpcsh)
152: MACHINE_ARCH=sh3el
153: ;;
1.1 tv 154:
1.84 lukem 155: hp700)
156: MACHINE_ARCH=hppa
157: ;;
1.1 tv 158:
1.84 lukem 159: evbsh5)
160: MACHINE_ARCH=sh5el
161: ;;
1.62 fredette 162:
1.84 lukem 163: alpha|i386|sparc|sparc64|vax|x86_64)
164: MACHINE_ARCH=$MACHINE
165: ;;
1.69 thorpej 166:
1.84 lukem 167: *)
168: bomb "unknown target MACHINE: $MACHINE"
169: ;;
1.4 tv 170:
1.1 tv 171: esac
172: }
173:
1.79 lukem 174: validatearch()
175: {
1.47 tv 176: # Ensure that the MACHINE_ARCH exists (and is supported by build.sh).
1.84 lukem 177: #
1.47 tv 178: case $MACHINE_ARCH in
179:
1.84 lukem 180: alpha|arm|armeb|hppa|i386|m68000|m68k|mipse[bl]|ns32k|powerpc|sh[35]e[bl]|sparc|sparc64|vax|x86_64)
181: ;;
182:
183: *)
184: bomb "unknown target MACHINE_ARCH: $MACHINE_ARCH"
185: ;;
186:
1.47 tv 187: esac
188: }
189:
1.79 lukem 190: getmakevar()
191: {
1.82 lukem 192: [ -x $make ] || bomb "getmakevar $1: $make is not executable"
1.30 jmc 193: $make -m ${TOP}/share/mk -s -f- _x_ <<EOF
1.15 tv 194: _x_:
195: echo \${$1}
196: .include <bsd.prog.mk>
1.70 lukem 197: .include <bsd.kernobj.mk>
1.15 tv 198: EOF
199: }
200:
1.82 lukem 201: safe_getmakevar()
202: {
1.84 lukem 203: # getmakevar() doesn't work properly if $make hasn't yet been built,
204: # which can happen when running with the "-n" option.
205: # safe_getmakevar() deals with this by emitting a literal '$'
206: # followed by the variable name, instead of trying to find the
207: # variable's value.
208: #
209:
1.82 lukem 210: if [ -x $make ]; then
211: getmakevar "$1"
212: else
213: echo "\$$1"
214: fi
215: }
216:
1.79 lukem 217: resolvepath()
218: {
1.10 tv 219: case $OPTARG in
1.84 lukem 220: /*)
221: ;;
222: *)
223: OPTARG="$TOP/$OPTARG"
224: ;;
1.10 tv 225: esac
226: }
227:
1.79 lukem 228: usage()
229: {
1.84 lukem 230: if [ -n "$*" ]; then
231: echo ""
232: echo "${progname}: $*"
233: fi
1.70 lukem 234: cat <<_usage_
1.83 lukem 235:
1.84 lukem 236: Usage: ${progname} [-EnorUu] [-a arch] [-B buildid] [-D dest] [-j njob] [-M obj]
237: [-m mach] [-O obj] [-R release] [-T tools] [-V var=[value]]
1.86 lukem 238: [-w wrapper] operation [...]
1.84 lukem 239:
1.86 lukem 240: Build operations (all imply "obj" and "tools"):
1.84 lukem 241: build Run "make build"
1.89 lukem 242: distribution Run "make distribution" (includes DESTDIR/etc/ files)
1.84 lukem 243: release Run "make release" (includes kernels & distrib media)
244:
245: Other operations:
1.87 lukem 246: help Show this message (and exit)
1.90 enami 247: makewrapper Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make.
248: (Always done)
1.86 lukem 249: obj Run "make obj" (default unless -o is used)
1.84 lukem 250: tools Build and install tools
251: kernel=conf Build kernel with config file \`conf'
252: install=idir Run "make installworld" to \`idir'
253: (useful after 'distribution' or 'release')
1.88 lukem 254: sets Create distribution sets in RELEASEDIR
1.84 lukem 255:
256: Options:
1.83 lukem 257: -a arch Set MACHINE_ARCH to arch (otherwise deduced from MACHINE)
1.84 lukem 258: -B buildId Set BUILDID to buildId
1.83 lukem 259: -D dest Set DESTDIR to dest
260: -E Set "expert" mode; disables some DESTDIR checks
261: -j njob Run up to njob jobs in parallel; see make(1)
262: -M obj Set obj root directory to obj (sets MAKEOBJDIRPREFIX)
263: -m mach Set MACHINE to mach (not required if NetBSD native)
264: -n Show commands that would be executed, but do not execute them
265: -O obj Set obj root directory to obj (sets a MAKEOBJDIR pattern)
266: -o Set MKOBJDIRS=no (do not create objdirs at start of build)
1.84 lukem 267: -R release Set RELEASEDIR to release
1.83 lukem 268: -r Remove contents of TOOLDIR and DESTDIR before building
1.84 lukem 269: -T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in
1.86 lukem 270: the environment, ${toolprefix}make will be (re)built unconditionally
271: -U Set UNPRIVED (build without requiring root privileges)
272: -u Set UPDATE (do not run "make clean" first)
1.83 lukem 273: -V v=[val] Set variable \`v' to \`val'
1.84 lukem 274: -w wrapper Create ${toolprefix}make script as wrapper
1.86 lukem 275: (Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE})
1.83 lukem 276:
1.70 lukem 277: _usage_
1.1 tv 278: exit 1
279: }
280:
1.84 lukem 281: parseoptions()
282: {
283: opts='a:B:bD:dEhi:j:k:M:m:nO:oR:rT:tUuV:w:'
284: opt_a=no
285:
286: if type getopts >/dev/null 2>&1; then
287: # Use POSIX getopts.
288: getoptcmd='getopts $opts opt && opt=-$opt'
289: optargcmd=':'
290: optremcmd='shift $(($OPTIND -1))'
291: else
292: type getopt >/dev/null 2>&1 ||
293: bomb "/bin/sh shell is too old; try ksh or bash"
294:
295: # Use old-style getopt(1) (doesn't handle whitespace in args).
296: args="$(getopt $opts $*)"
297: [ $? = 0 ] || usage
298: set -- $args
299:
300: getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
301: optargcmd='OPTARG="$1"; shift'
302: optremcmd=':'
303: fi
304:
305: # Parse command line options.
306: #
307: while eval $getoptcmd; do
308: case $opt in
309:
310: -a)
311: eval $optargcmd
312: MACHINE_ARCH=$OPTARG
313: opt_a=yes
314: ;;
315:
316: -B)
317: eval $optargcmd
318: BUILDID=$OPTARG
319: ;;
320:
321: -b)
1.86 lukem 322: usage "'-b' has been replaced by 'makewrapper'"
1.84 lukem 323: ;;
324:
325: -D)
326: eval $optargcmd; resolvepath
327: DESTDIR="$OPTARG"
328: export DESTDIR
329: makeenv="$makeenv DESTDIR"
330: ;;
331:
332: -d)
333: usage "'-d' has been replaced by 'distribution'"
334: ;;
335:
336: -E)
337: do_expertmode=true
338: ;;
339:
340: -i)
341: usage "'-i idir' has been replaced by 'install=idir'"
342: ;;
343:
344: -j)
345: eval $optargcmd
346: parallel="-j $OPTARG"
347: ;;
348:
349: -k)
350: usage "'-k conf' has been replaced by 'kernel=conf'"
351: ;;
352:
353: -M)
354: eval $optargcmd; resolvepath
355: MAKEOBJDIRPREFIX="$OPTARG"
356: export MAKEOBJDIRPREFIX
357: makeobjdir=$OPTARG
358: makeenv="$makeenv MAKEOBJDIRPREFIX"
359: ;;
360:
361: # -m overrides MACHINE_ARCH unless "-a" is specified
362: -m)
363: eval $optargcmd
364: MACHINE=$OPTARG
365: [ "$opt_a" != "yes" ] && getarch
366: ;;
367:
368: -n)
369: runcmd=echo
370: ;;
371:
372: -O)
373: eval $optargcmd; resolvepath
374: MAKEOBJDIR="\${.CURDIR:C,^$TOP,$OPTARG,}"
375: export MAKEOBJDIR
376: makeobjdir=$OPTARG
377: makeenv="$makeenv MAKEOBJDIR"
378: ;;
379:
380: -o)
381: MKOBJDIRS=no
382: ;;
383:
384: -R)
385: eval $optargcmd; resolvepath
386: RELEASEDIR=$OPTARG
387: export RELEASEDIR
388: makeenv="$makeenv RELEASEDIR"
389: ;;
390:
391: -r)
392: do_removedirs=true
393: do_rebuildmake=true
394: ;;
395:
396: -T)
397: eval $optargcmd; resolvepath
398: TOOLDIR="$OPTARG"
399: export TOOLDIR
400: ;;
401:
402: -t)
403: usage "'-t' has been replaced by 'tools'"
404: ;;
1.16 thorpej 405:
1.84 lukem 406: -U)
407: UNPRIVED=yes
408: export UNPRIVED
409: makeenv="$makeenv UNPRIVED"
410: ;;
1.44 lukem 411:
1.84 lukem 412: -u)
413: UPDATE=yes
414: export UPDATE
415: makeenv="$makeenv UPDATE"
416: ;;
1.15 tv 417:
1.84 lukem 418: -V)
419: eval $optargcmd
420: case "${OPTARG}" in
1.80 lukem 421: # XXX: consider restricting which variables can be changed?
1.84 lukem 422: [a-zA-Z_][a-zA-Z_0-9]*=*)
423: var=${OPTARG%%=*}
424: value=${OPTARG#*=}
425: eval "${var}=\"${value}\"; export ${var}"
426: makeenv="$makeenv ${var}"
427: ;;
428: *)
429: usage "-V argument must be of the form 'var=[value]'"
430: ;;
431: esac
432: ;;
433:
434: -w)
435: eval $optargcmd; resolvepath
436: makewrapper="$OPTARG"
437: ;;
438:
439: --)
440: break
441: ;;
442:
443: -'?'|-h)
444: usage
445: ;;
446:
447: esac
448: done
449:
450: # Validate operations.
451: #
452: eval $optremcmd
453: while [ $# -gt 0 ]; do
454: op=$1; shift
455: operations="$operations $op"
456:
457: case "$op" in
458:
1.87 lukem 459: help)
460: usage
461: ;;
462:
463: makewrapper|obj|tools|build|distribution|release|sets)
1.80 lukem 464: ;;
1.84 lukem 465:
466: kernel=*)
467: arg=${op#*=}
468: op=${op%%=*}
1.86 lukem 469: if [ -z "${arg}" ]; then
1.84 lukem 470: bomb "Must supply a kernel name with \`kernel=...'"
471: fi
472: ;;
473:
474: install=*)
475: arg=${op#*=}
476: op=${op%%=*}
1.86 lukem 477: if [ -z "${arg}" ]; then
1.84 lukem 478: bomb "Must supply a directory with \`install=...'"
479: fi
480: ;;
481:
1.80 lukem 482: *)
1.84 lukem 483: usage "Unknown operation \`${op}'"
484: ;;
485:
1.80 lukem 486: esac
1.84 lukem 487: eval do_$op=true
488: done
1.86 lukem 489: if [ -z "${operations}" ]; then
490: usage "Missing operation to perform."
491: fi
1.84 lukem 492:
493: # Set up MACHINE*. On a NetBSD host, these are allowed to be unset.
494: #
495: if [ -z "$MACHINE" ]; then
496: if [ "${uname_s}" != "NetBSD" ]; then
497: bomb "MACHINE must be set, or -m must be used, for cross builds."
498: fi
499: MACHINE=${uname_m}
500: fi
501: [ -n "$MACHINE_ARCH" ] || getarch
502: validatearch
503:
504: # Set up default make(1) environment.
505: #
506: makeenv="$makeenv TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
507: if [ ! -z "$BUILDID" ]; then
508: makeenv="$makeenv BUILDID"
509: fi
510: MAKEFLAGS="-m $TOP/share/mk $MAKEFLAGS MKOBJDIRS=${MKOBJDIRS-yes}"
511: export MAKEFLAGS MACHINE MACHINE_ARCH
512: }
513:
514: rebuildmake()
515: {
516: # Test make source file timestamps against installed ${toolprefix}make
517: # binary, if TOOLDIR is pre-set.
518: #
519: # Note that we do NOT try to grovel "mk.conf" here to find out if
520: # TOOLDIR is set there, because it can contain make variable
521: # expansions and other stuff only parseable *after* we have a working
522: # ${toolprefix}make. So this logic can only work if the user has
523: # pre-set TOOLDIR in the environment or used the -T option to build.sh.
524: #
525: make="${TOOLDIR-nonexistent}/bin/${toolprefix}make"
526: if [ -x $make ]; then
527: for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
528: if [ $f -nt $make ]; then
529: do_rebuildmake=true
530: break
531: fi
532: done
533: else
534: do_rebuildmake=true
535: fi
536:
537: # Build bootstrap ${toolprefix}make if needed.
538: if $do_rebuildmake; then
539: $runcmd echo "===> Bootstrapping ${toolprefix}make"
540: tmpdir="${TMPDIR-/tmp}/nbbuild$$"
541:
542: $runcmd mkdir "$tmpdir" || bomb "cannot mkdir: $tmpdir"
543: trap "cd /; rm -r -f \"$tmpdir\"" 0
544: $runcmd cd "$tmpdir"
545:
546: $runcmd env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
547: CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
548: "$TOP/tools/make/configure" ||
549: bomb "configure of ${toolprefix}make failed"
550: $runcmd sh buildmake.sh ||
551: bomb "build of ${toolprefix}make failed"
552:
553: make="$tmpdir/${toolprefix}make"
554: $runcmd cd "$TOP"
555: $runcmd rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
556: fi
557: }
558:
559: validatemakeparams()
560: {
561: if [ "$runcmd" = "echo" ]; then
562: TOOLCHAIN_MISSING=no
563: EXTERNAL_TOOLCHAIN=""
564: else
565: TOOLCHAIN_MISSING=$(getmakevar TOOLCHAIN_MISSING)
566: EXTERNAL_TOOLCHAIN=$(getmakevar EXTERNAL_TOOLCHAIN)
567: fi
568: if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
1.86 lukem 569: [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
1.84 lukem 570: $runcmd echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
571: $runcmd echo " MACHINE: ${MACHINE}"
572: $runcmd echo " MACHINE_ARCH: ${MACHINE_ARCH}"
573: $runcmd echo ""
574: $runcmd echo "All builds for this platform should be done via a traditional make"
575: $runcmd echo "If you wish to use an external cross-toolchain, set"
576: $runcmd echo " EXTERNAL_TOOLCHAIN=<path to toolchain root>"
577: $runcmd echo "in either the environment or mk.conf and rerun"
578: $runcmd echo " $progname $*"
579: exit 1
580: fi
581:
582: # If TOOLDIR isn't already set, make objdirs in "tools" in case the
583: # default setting from <bsd.own.mk> is used.
584: #
585: if [ -z "$TOOLDIR" ] && [ "$MKOBJDIRS" != "no" ]; then
586: $runcmd cd tools
587: $runcmd $make -m ${TOP}/share/mk obj NOSUBDIR= ||
588: bomb "make obj failed in tools"
589: $runcmd cd "$TOP"
590: fi
1.80 lukem 591:
1.84 lukem 592: # If setting -M or -O to root an obj dir make sure the base directory
593: # is made before continuing as bsd.own.mk will need this to pick up
594: # _SRC_TOP_OBJ_
595: #
596: if [ "$MKOBJDIRS" != "no" ] && [ ! -z "$makeobjdir" ]; then
597: $runcmd mkdir -p "$makeobjdir"
598: fi
1.12 tv 599:
1.84 lukem 600: # Find DESTDIR and TOOLDIR.
601: #
602: DESTDIR=$(safe_getmakevar DESTDIR)
603: $runcmd echo "===> DESTDIR path: $DESTDIR"
604: TOOLDIR=$(safe_getmakevar TOOLDIR)
605: $runcmd echo "===> TOOLDIR path: $TOOLDIR"
606: export DESTDIR TOOLDIR
607:
608: # Check validity of TOOLDIR and DESTDIR.
609: #
610: if [ -z "$TOOLDIR" ] || [ "$TOOLDIR" = "/" ]; then
611: bomb "TOOLDIR '$TOOLDIR' invalid"
612: fi
613: removedirs="$TOOLDIR"
1.15 tv 614:
1.84 lukem 615: if [ -z "$DESTDIR" ] || [ "$DESTDIR" = "/" ]; then
616: if $do_build || $do_distribution || $do_release; then
617: if ! $do_build || \
618: [ "${uname_s}" != "NetBSD" ] || \
619: [ "${uname_m}" != "$MACHINE" ]; then
620: bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'."
621: fi
622: if ! $do_expertmode; then
623: bomb "DESTDIR must != / for non -E (expert) builds"
624: fi
625: $runcmd echo "===> WARNING: Building to /, in expert mode."
626: $runcmd echo "===> This may cause your system to break! Reasons include:"
627: $runcmd echo "===> - your kernel is not up to date"
628: $runcmd echo "===> - the libraries or toolchain have changed"
629: $runcmd echo "===> YOU HAVE BEEN WARNED!"
1.1 tv 630: fi
1.84 lukem 631: else
632: removedirs="$removedirs $DESTDIR"
633: fi
1.86 lukem 634: if $do_build || $do_distribution || $do_release; then
635: if ! $do_expertmode && \
636: [ $(id -u 2>/dev/null) -ne 0 ] &&\
637: [ -z "$UNPRIVED" ] ; then
638: bomb "-U or -E must be set for build as an unprivileged user."
639: fi
640: fi
1.84 lukem 641: }
1.30 jmc 642:
1.15 tv 643:
1.84 lukem 644: createmakewrapper()
645: {
646: # Remove the target directories.
647: #
648: if $do_removedirs; then
649: for f in $removedirs; do
650: $runcmd echo "===> Removing $f"
651: $runcmd rm -r -f $f
652: done
653: fi
1.15 tv 654:
1.84 lukem 655: # Recreate $TOOLDIR.
656: #
657: $runcmd mkdir -p "$TOOLDIR/bin" || bomb "mkdir of '$TOOLDIR/bin' failed"
658:
659: # Install ${toolprefix}make if it was built.
660: #
661: if $do_rebuildmake; then
662: $runcmd rm -f "$TOOLDIR/bin/${toolprefix}make"
663: $runcmd cp $make "$TOOLDIR/bin/${toolprefix}make" ||
664: bomb "failed to install \$TOOLDIR/bin/${toolprefix}make"
665: make="$TOOLDIR/bin/${toolprefix}make"
666: $runcmd echo "===> Created ${make}"
667: $runcmd rm -r -f "$tmpdir"
668: trap 0
669: fi
1.15 tv 670:
1.84 lukem 671: # Build a ${toolprefix}make wrapper script, usable by hand as
672: # well as by build.sh.
673: #
674: if [ -z "$makewrapper" ]; then
675: makewrapper="$TOOLDIR/bin/${toolprefix}make-$MACHINE"
676: if [ ! -z "$BUILDID" ]; then
677: makewrapper="$makewrapper-$BUILDID"
678: fi
1.52 thorpej 679: fi
1.4 tv 680:
1.84 lukem 681: $runcmd rm -f "$makewrapper"
682: if [ "$runcmd" = "echo" ]; then
683: echo 'cat <<EOF >'$makewrapper
684: makewrapout=
685: else
686: makewrapout=">>\$makewrapper"
687: fi
1.18 tv 688:
1.84 lukem 689: eval cat <<EOF $makewrapout
1.4 tv 690: #! /bin/sh
691: # Set proper variables to allow easy "make" building of a NetBSD subtree.
1.94 ! lukem 692: # Generated from: \$NetBSD: build.sh,v 1.93 2003/03/04 02:20:28 lukem Exp $
1.4 tv 693: #
1.18 tv 694:
695: EOF
1.84 lukem 696: for f in $makeenv; do
697: eval echo "$f=\'\$$(echo $f)\'\;\ export\ $f" $makewrapout
698: done
699: eval echo "USETOOLS=yes\; export USETOOLS" $makewrapout
1.18 tv 700:
1.84 lukem 701: eval cat <<EOF $makewrapout
1.18 tv 702:
1.84 lukem 703: exec "\$TOOLDIR/bin/${toolprefix}make" \${1+"\$@"}
1.4 tv 704: EOF
1.84 lukem 705: [ "$runcmd" = "echo" ] && echo EOF
706: $runcmd chmod +x "$makewrapper"
707: $runcmd echo "===> Updated ${makewrapper}"
708: }
709:
710: buildtools()
711: {
712: if [ "$MKOBJDIRS" != "no" ]; then
713: $runcmd "$makewrapper" $parallel obj-tools ||
714: bomb "failed to make obj-tools"
715: fi
716: $runcmd cd tools
1.86 lukem 717: if [ -z "$UPDATE" ]; then
1.84 lukem 718: cleandir=cleandir
719: else
720: cleandir=
721: fi
722: $runcmd "$makewrapper" ${cleandir} dependall install ||
723: bomb "failed to make tools"
724: }
1.4 tv 725:
1.84 lukem 726: buildkernel()
727: {
728: kernconf="$1"
729: if ! $do_tools; then
730: # Building tools every time we build a kernel is clearly
731: # unnecessary. We could try to figure out whether rebuilding
732: # the tools is necessary this time, but it doesn't seem worth
733: # the trouble. Instead, we say it's the user's responsibility
734: # to rebuild the tools if necessary.
735: #
736: $runcmd echo "===> Building kernel without building new tools"
737: fi
738: $runcmd echo "===> Building kernel ${kernconf}"
739: if [ "$MKOBJDIRS" != "no" ] && [ ! -z "$makeobjdir" ]; then
740: # The correct value of KERNOBJDIR might
741: # depend on a prior "make obj" in
742: # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
743: #
744: KERNSRCDIR="$(safe_getmakevar KERNSRCDIR)"
745: KERNARCHDIR="$(safe_getmakevar KERNARCHDIR)"
746: $runcmd cd "${KERNSRCDIR}/${KERNARCHDIR}/compile"
747: $runcmd "$makewrapper" obj ||
748: bomb "failed to make obj in ${KERNSRCDIR}/${KERNARCHDIR}/compile"
749: $runcmd cd "$TOP"
750: fi
751: KERNCONFDIR="$(safe_getmakevar KERNCONFDIR)"
752: KERNOBJDIR="$(safe_getmakevar KERNOBJDIR)"
753: case "${kernconf}" in
754: */*)
755: kernconfpath="${kernconf}"
756: kernconfbase="$(basename "${kernconf}")"
757: ;;
758: *)
759: kernconfpath="${KERNCONFDIR}/${kernconf}"
760: kernconfbase="${kernconf}"
761: ;;
762: esac
763: kernbuilddir="${KERNOBJDIR}/${kernconfbase}"
764: $runcmd echo "===> Kernel build directory: ${kernbuilddir}"
765: $runcmd mkdir -p "${kernbuilddir}" ||
766: bomb "cannot mkdir: ${kernbuilddir}"
1.86 lukem 767: if [ -z "$UPDATE" ]; then
1.84 lukem 768: $runcmd cd "${kernbuilddir}"
769: $runcmd "$makewrapper" cleandir ||
770: bomb "make cleandir failed in ${kernbuilddir}"
771: $runcmd cd "$TOP"
1.16 thorpej 772: fi
1.84 lukem 773: $runcmd "${TOOLDIR}/bin/${toolprefix}config" -b "${kernbuilddir}" \
774: -s "${TOP}/sys" "${kernconfpath}" ||
775: bomb "${toolprefix}config failed for ${kernconf}"
776: $runcmd cd "${kernbuilddir}"
777: $runcmd "$makewrapper" depend ||
778: bomb "make depend failed in ${kernbuilddir}"
779: $runcmd "$makewrapper" $parallel all ||
780: bomb "make all failed in ${kernbuilddir}"
1.91 lukem 781:
782: if [ "$runcmd" != "echo" ]; then
783: echo "===> New kernels built:"
784: kernlist=$(awk '$1 == "config" { print $2 }' ${kernconfpath})
785: for kern in ${kernlist:-netbsd}; do
786: [ -f "${kernbuilddir}/${kern}" ] && \
787: echo " ${kernbuilddir}/${kern}"
788: done
789: fi
1.84 lukem 790: }
791:
792: installworld()
793: {
794: dir="$1"
795: ${runcmd} "$makewrapper" INSTALLWORLDDIR="${dir}" installworld ||
796: bomb "failed to make installworld to ${dir}"
797: }
798:
799:
800: main()
801: {
802: initdefaults
803: parseoptions "$@"
1.93 lukem 804:
805: build_start=$(date)
806: echo "===> ${progname} command: $0 $@"
807: echo "===> ${progname} started: $build_start"
808:
1.84 lukem 809: rebuildmake
810: validatemakeparams
811: createmakewrapper
812:
813: # Perform the operations.
814: #
815: for op in $operations; do
816: case "$op" in
1.86 lukem 817:
818: makewrapper)
819: # no-op
820: ;;
1.84 lukem 821:
822: tools)
823: buildtools
824: ;;
825:
1.87 lukem 826: obj|build|distribution|release|sets)
1.84 lukem 827: ${runcmd} "$makewrapper" $parallel $op ||
828: bomb "failed to make $op"
829: ;;
830:
831: kernel=*)
832: arg=${op#*=}
833: buildkernel "${arg}"
834: ;;
835:
836: install=*)
837: arg=${op#*=}
1.85 lukem 838: if [ "${arg}" = "/" ] && \
839: ( [ "${uname_s}" != "NetBSD" ] || \
840: [ "${uname_m}" != "$MACHINE" ] ); then
841: bomb "'${op}' must != / for cross builds."
842: fi
1.84 lukem 843: installworld "${arg}"
1.70 lukem 844: ;;
1.84 lukem 845:
1.70 lukem 846: *)
1.84 lukem 847: bomb "Unknown operation \`${op}'"
1.70 lukem 848: ;;
1.84 lukem 849:
1.70 lukem 850: esac
1.84 lukem 851: done
1.93 lukem 852:
853: echo "===> ${progname} started: $build_start"
854: echo "===> ${progname} ended: $(date)"
1.84 lukem 855: }
856:
857: main "$@"
CVSweb <webmaster@jp.NetBSD.org>