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