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