No empty .Rs/.Re
[netbsd-mini2440.git] / build.sh
blob94cc941be42cbcdce1eae7e120bf1d384466f8ad
1 #! /usr/bin/env sh
2 # $NetBSD: build.sh,v 1.225 2009/12/17 15:30:37 matt Exp $
4 # Copyright (c) 2001-2009 The NetBSD Foundation, Inc.
5 # All rights reserved.
7 # This code is derived from software contributed to The NetBSD Foundation
8 # by Todd Vierling and Luke Mewburn.
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.
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.
32 # Top level build wrapper, for a system containing no tools.
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.)
43 progname=${0##*/}
44 toppid=$$
45 results=/dev/null
46 tab=' '
47 trap "exit 1" 1 2 3 15
49 bomb()
51 cat >&2 <<ERRORMESSAGE
53 ERROR: $@
54 *** BUILD ABORTED ***
55 ERRORMESSAGE
56 kill ${toppid} # in case we were invoked from a subshell
57 exit 1
61 statusmsg()
63 ${runcmd} echo "===> $@" | tee -a "${results}"
66 warning()
68 statusmsg "Warning: $@"
71 # Find a program in the PATH, and print the result. If not found,
72 # print a default. If $2 is defined (even if it is an empty string),
73 # then that is the default; otherwise, $1 is used as the default.
74 find_in_PATH()
76 local prog="$1"
77 local result="${2-"$1"}"
78 local oldIFS="${IFS}"
79 local dir
80 IFS=":"
81 for dir in ${PATH}; do
82 if [ -x "${dir}/${prog}" ]; then
83 result="${dir}/${prog}"
84 break
86 done
87 IFS="${oldIFS}"
88 echo "${result}"
91 # Try to find a working POSIX shell, and set HOST_SH to refer to it.
92 # Assumes that uname_s, uname_m, and PWD have been set.
93 set_HOST_SH()
95 # Even if ${HOST_SH} is already defined, we still do the
96 # sanity checks at the end.
98 # Solaris has /usr/xpg4/bin/sh.
100 [ -z "${HOST_SH}" ] && [ x"${uname_s}" = x"SunOS" ] && \
101 [ -x /usr/xpg4/bin/sh ] && HOST_SH="/usr/xpg4/bin/sh"
103 # Try to get the name of the shell that's running this script,
104 # by parsing the output from "ps". We assume that, if the host
105 # system's ps command supports -o comm at all, it will do so
106 # in the usual way: a one-line header followed by a one-line
107 # result, possibly including trailing white space. And if the
108 # host system's ps command doesn't support -o comm, we assume
109 # that we'll get an error message on stderr and nothing on
110 # stdout. (We don't try to use ps -o 'comm=' to suppress the
111 # header line, because that is less widely supported.)
113 # If we get the wrong result here, the user can override it by
114 # specifying HOST_SH in the environment.
116 [ -z "${HOST_SH}" ] && HOST_SH="$(
117 (ps -p $$ -o comm | sed -ne "2s/[ ${tab}]*\$//p") 2>/dev/null )"
119 # If nothing above worked, use "sh". We will later find the
120 # first directory in the PATH that has a "sh" program.
122 [ -z "${HOST_SH}" ] && HOST_SH="sh"
124 # If the result so far is not an absolute path, try to prepend
125 # PWD or search the PATH.
127 case "${HOST_SH}" in
128 /*) :
130 */*) HOST_SH="${PWD}/${HOST_SH}"
132 *) HOST_SH="$(find_in_PATH "${HOST_SH}")"
134 esac
136 # If we don't have an absolute path by now, bomb.
138 case "${HOST_SH}" in
139 /*) :
141 *) bomb "HOST_SH=\"${HOST_SH}\" is not an absolute path."
143 esac
145 # If HOST_SH is not executable, bomb.
147 [ -x "${HOST_SH}" ] ||
148 bomb "HOST_SH=\"${HOST_SH}\" is not executable."
151 initdefaults()
153 makeenv=
154 makewrapper=
155 makewrappermachine=
156 runcmd=
157 operations=
158 removedirs=
160 [ -d usr.bin/make ] || cd "$(dirname $0)"
161 [ -d usr.bin/make ] ||
162 bomb "build.sh must be run from the top source level"
163 [ -f share/mk/bsd.own.mk ] ||
164 bomb "src/share/mk is missing; please re-fetch the source tree"
166 # Set LC_ALL=C before we try to parse the output from any command
167 setmakeenv LC_ALL C
169 # Find information about the build platform. This should be
170 # kept in sync with _HOST_OSNAME, _HOST_OSREL, and _HOST_ARCH
171 # variables in share/mk/bsd.sys.mk.
173 # Note that "uname -p" is not part of POSIX, but we want uname_p
174 # to be set to the host MACHINE_ARCH, if possible. On systems
175 # where "uname -p" fails, prints "unknown", or prints a string
176 # that does not look like an identifier, fall back to using the
177 # output from "uname -m" instead.
179 uname_s=$(uname -s 2>/dev/null)
180 uname_r=$(uname -r 2>/dev/null)
181 uname_m=$(uname -m 2>/dev/null)
182 uname_p=$(uname -p 2>/dev/null || echo "unknown")
183 case "${uname_p}" in
184 ''|unknown|*[^-_A-Za-z0-9]*) uname_p="${uname_m}" ;;
185 esac
187 id_u=$(id -u 2>/dev/null || /usr/xpg4/bin/id -u 2>/dev/null)
189 # If $PWD is a valid name of the current directory, POSIX mandates
190 # that pwd return it by default which causes problems in the
191 # presence of symlinks. Unsetting PWD is simpler than changing
192 # every occurrence of pwd to use -P.
194 # XXX Except that doesn't work on Solaris. Or many Linuces.
196 unset PWD
197 TOP=$(/bin/pwd -P 2>/dev/null || /bin/pwd 2>/dev/null)
199 # The user can set HOST_SH in the environment, or we try to
200 # guess an appropriate value. Then we set several other
201 # variables from HOST_SH.
203 set_HOST_SH
204 setmakeenv HOST_SH "${HOST_SH}"
205 setmakeenv BSHELL "${HOST_SH}"
206 setmakeenv CONFIG_SHELL "${HOST_SH}"
208 # Set defaults.
210 toolprefix=nb
212 # Some systems have a small ARG_MAX. -X prevents make(1) from
213 # exporting variables in the environment redundantly.
215 case "${uname_s}" in
216 Darwin | FreeBSD | CYGWIN*)
217 MAKEFLAGS=-X
220 MAKEFLAGS=
222 esac
224 # do_{operation}=true if given operation is requested.
226 do_expertmode=false
227 do_rebuildmake=false
228 do_removedirs=false
229 do_tools=false
230 do_cleandir=false
231 do_obj=false
232 do_build=false
233 do_distribution=false
234 do_release=false
235 do_kernel=false
236 do_releasekernel=false
237 do_modules=false
238 do_install=false
239 do_sets=false
240 do_sourcesets=false
241 do_syspkgs=false
242 do_iso_image=false
243 do_iso_image_source=false
244 do_params=false
245 do_rump=false
247 # done_{operation}=true if given operation has been done.
249 done_rebuildmake=false
251 # Create scratch directory
253 tmpdir="${TMPDIR-/tmp}/nbbuild$$"
254 mkdir "${tmpdir}" || bomb "Cannot mkdir: ${tmpdir}"
255 trap "cd /; rm -r -f \"${tmpdir}\"" 0
256 results="${tmpdir}/build.sh.results"
258 # Set source directories
260 setmakeenv NETBSDSRCDIR "${TOP}"
262 # Find the version of NetBSD
264 DISTRIBVER="$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh)"
266 # Set the BUILDSEED to NetBSD-"N"
268 setmakeenv BUILDSEED "NetBSD-$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh -m)"
270 # Set MKARZERO to "yes"
272 setmakeenv MKARZERO "yes"
274 # Set various environment variables to known defaults,
275 # to minimize (cross-)build problems observed "in the field".
277 unsetmakeenv INFODIR
278 unsetmakeenv LESSCHARSET
281 getarch()
283 # Translate some MACHINE name aliases (known only to build.sh)
284 # into proper MACHINE and MACHINE_ARCH names. Save the alias
285 # name in makewrappermachine.
287 case "${MACHINE}" in
289 evbarm-e[bl])
290 makewrappermachine=${MACHINE}
291 # MACHINE_ARCH is "arm" or "armeb", not "armel"
292 MACHINE_ARCH=arm${MACHINE##*-}
293 MACHINE_ARCH=${MACHINE_ARCH%el}
294 MACHINE=${MACHINE%-e[bl]}
297 evbmips-e[bl]|sbmips-e[bl])
298 makewrappermachine=${MACHINE}
299 MACHINE_ARCH=mips${MACHINE##*-}
300 MACHINE=${MACHINE%-e[bl]}
303 evbmips64-e[bl]|sbmips64-e[bl])
304 makewrappermachine=${MACHINE}
305 MACHINE_ARCH=mips64${MACHINE##*-}
306 MACHINE=${MACHINE%64-e[bl]}
309 evbsh3-e[bl])
310 makewrappermachine=${MACHINE}
311 MACHINE_ARCH=sh3${MACHINE##*-}
312 MACHINE=${MACHINE%-e[bl]}
315 esac
317 # Translate a MACHINE into a default MACHINE_ARCH.
319 case "${MACHINE}" in
321 acorn26|acorn32|cats|hpcarm|iyonix|netwinder|shark|zaurus)
322 MACHINE_ARCH=arm
325 evbarm) # unspecified MACHINE_ARCH gets LE
326 MACHINE_ARCH=${MACHINE_ARCH:=arm}
329 hp700)
330 MACHINE_ARCH=hppa
333 sun2)
334 MACHINE_ARCH=m68000
337 amiga|atari|cesfic|hp300|luna68k|mac68k|mvme68k|news68k|next68k|sun3|x68k)
338 MACHINE_ARCH=m68k
341 evbmips|sbmips) # no default MACHINE_ARCH
344 sgimips64)
345 makewrappermachine=${MACHINE}
346 MACHINE=${MACHINE%64}
347 MACHINE_ARCH=mips64eb
350 ews4800mips|mipsco|newsmips|sgimips)
351 MACHINE_ARCH=mipseb
354 algor64|cobalt64|pmax64)
355 makewrappermachine=${MACHINE}
356 MACHINE=${MACHINE%64}
357 MACHINE_ARCH=mips64el
360 algor|arc|cobalt|hpcmips|pmax)
361 MACHINE_ARCH=mipsel
364 evbppc64|macppc64|ofppc64)
365 makewrappermachine=${MACHINE}
366 MACHINE=${MACHINE%64}
367 MACHINE_ARCH=powerpc64
370 amigappc|bebox|evbppc|ibmnws|macppc|mvmeppc|ofppc|prep|rs6000|sandpoint)
371 MACHINE_ARCH=powerpc
374 evbsh3) # no default MACHINE_ARCH
377 mmeye)
378 MACHINE_ARCH=sh3eb
381 dreamcast|hpcsh|landisk)
382 MACHINE_ARCH=sh3el
385 amd64)
386 MACHINE_ARCH=x86_64
389 alpha|i386|sparc|sparc64|vax|ia64)
390 MACHINE_ARCH=${MACHINE}
394 bomb "Unknown target MACHINE: ${MACHINE}"
397 esac
400 validatearch()
402 # Ensure that the MACHINE_ARCH exists (and is supported by build.sh).
404 case "${MACHINE_ARCH}" in
406 alpha|arm|armeb|hppa|i386|m68000|m68k|mipse[bl]|mips64e[bl]|powerpc|powerpc64|sh3e[bl]|sparc|sparc64|vax|x86_64|ia64)
410 bomb "No MACHINE_ARCH provided"
414 bomb "Unknown target MACHINE_ARCH: ${MACHINE_ARCH}"
417 esac
419 # Determine valid MACHINE_ARCHs for MACHINE
421 case "${MACHINE}" in
423 evbarm)
424 arches="arm armeb"
427 algor|cobalt|pmax)
428 arches="mipsel mips64el"
431 evbmips|sbmips)
432 arches="mipseb mipsel mips64eb mips64el"
435 sgimips)
436 arches="mipseb mips64eb"
439 evbsh3)
440 arches="sh3eb sh3el"
443 macppc|evbppc|ofppc)
444 arches="powerpc powerpc64"
447 oma="${MACHINE_ARCH}"
448 getarch
449 arches="${MACHINE_ARCH}"
450 MACHINE_ARCH="${oma}"
453 esac
455 # Ensure that MACHINE_ARCH supports MACHINE
457 archok=false
458 for a in ${arches}; do
459 if [ "${a}" = "${MACHINE_ARCH}" ]; then
460 archok=true
461 break
463 done
464 ${archok} ||
465 bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'"
468 # nobomb_getmakevar --
469 # Given the name of a make variable in $1, print make's idea of the
470 # value of that variable, or return 1 if there's an error.
472 nobomb_getmakevar()
474 [ -x "${make}" ] || return 1
475 "${make}" -m ${TOP}/share/mk -s -B -f- _x_ <<EOF || return 1
476 _x_:
477 echo \${$1}
478 .include <bsd.prog.mk>
479 .include <bsd.kernobj.mk>
483 # nobomb_getmakevar --
484 # Given the name of a make variable in $1, print make's idea of the
485 # value of that variable, or bomb if there's an error.
487 bomb_getmakevar()
489 [ -x "${make}" ] || bomb "bomb_getmakevar $1: ${make} is not executable"
490 nobomb_getmakevar "$1" || bomb "bomb_getmakevar $1: ${make} failed"
493 # nobomb_getmakevar --
494 # Given the name of a make variable in $1, print make's idea of the
495 # value of that variable, or print a literal '$' followed by the
496 # variable name if ${make} is not executable. This is intended for use in
497 # messages that need to be readable even if $make hasn't been built,
498 # such as when build.sh is run with the "-n" option.
500 getmakevar()
502 if [ -x "${make}" ]; then
503 bomb_getmakevar "$1"
504 else
505 echo "\$$1"
509 setmakeenv()
511 eval "$1='$2'; export $1"
512 makeenv="${makeenv} $1"
515 unsetmakeenv()
517 eval "unset $1"
518 makeenv="${makeenv} $1"
521 # Given a variable name in $1, modify the variable in place as follows:
522 # For each space-separated word in the variable, call resolvepath.
523 resolvepaths()
525 local var="$1"
526 local val
527 eval val=\"\${${var}}\"
528 local newval=''
529 local word
530 for word in ${val}; do
531 resolvepath word
532 newval="${newval}${newval:+ }${word}"
533 done
534 eval ${var}=\"\${newval}\"
537 # Given a variable name in $1, modify the variable in place as follows:
538 # Convert possibly-relative path to absolute path by prepending
539 # ${TOP} if necessary. Also delete trailing "/", if any.
540 resolvepath()
542 local var="$1"
543 local val
544 eval val=\"\${${var}}\"
545 case "${val}" in
549 val="${val%/}"
552 val="${TOP}/${val%/}"
554 esac
555 eval ${var}=\"\${val}\"
558 usage()
560 if [ -n "$*" ]; then
561 echo ""
562 echo "${progname}: $*"
564 cat <<_usage_
566 Usage: ${progname} [-EnorUux] [-a arch] [-B buildid] [-C cdextras]
567 [-D dest] [-j njob] [-M obj] [-m mach] [-N noisy]
568 [-O obj] [-R release] [-S seed] [-T tools]
569 [-V var=[value]] [-w wrapper] [-X x11src] [-Y extsrcsrc]
570 [-Z var]
571 operation [...]
573 Build operations (all imply "obj" and "tools"):
574 build Run "make build".
575 distribution Run "make distribution" (includes DESTDIR/etc/ files).
576 release Run "make release" (includes kernels & distrib media).
578 Other operations:
579 help Show this message and exit.
580 makewrapper Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make.
581 Always performed.
582 cleandir Run "make cleandir". [Default unless -u is used]
583 obj Run "make obj". [Default unless -o is used]
584 tools Build and install tools.
585 install=idir Run "make installworld" to \`idir' to install all sets
586 except \`etc'. Useful after "distribution" or "release"
587 kernel=conf Build kernel with config file \`conf'
588 releasekernel=conf Install kernel built by kernel=conf to RELEASEDIR.
589 modules Build kernel modules.
590 rumptest Do a linktest for rump (for developers).
591 sets Create binary sets in
592 RELEASEDIR/RELEASEMACHINEDIR/binary/sets.
593 DESTDIR should be populated beforehand.
594 sourcesets Create source sets in RELEASEDIR/source/sets.
595 syspkgs Create syspkgs in
596 RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.
597 iso-image Create CD-ROM image in RELEASEDIR/iso.
598 iso-image-source Create CD-ROM image with source in RELEASEDIR/iso.
599 params Display various make(1) parameters.
601 Options:
602 -a arch Set MACHINE_ARCH to arch. [Default: deduced from MACHINE]
603 -B buildId Set BUILDID to buildId.
604 -C cdextras Append cdextras to CDEXTRA variable for inclusion on CD-ROM.
605 -D dest Set DESTDIR to dest. [Default: destdir.MACHINE]
606 -E Set "expert" mode; disables various safety checks.
607 Should not be used without expert knowledge of the build system.
608 -h Print this help message.
609 -j njob Run up to njob jobs in parallel; see make(1) -j.
610 -M obj Set obj root directory to obj; sets MAKEOBJDIRPREFIX.
611 Unsets MAKEOBJDIR.
612 -m mach Set MACHINE to mach; not required if NetBSD native.
613 -N noisy Set the noisyness (MAKEVERBOSE) level of the build:
614 0 Minimal output ("quiet")
615 1 Describe what is occurring
616 2 Describe what is occurring and echo the actual command
617 3 Ignore the effect of the "@" prefix in make commands
618 4 Trace shell commands using the shell's -x flag
619 [Default: 2]
620 -n Show commands that would be executed, but do not execute them.
621 -O obj Set obj root directory to obj; sets a MAKEOBJDIR pattern.
622 Unsets MAKEOBJDIRPREFIX.
623 -o Set MKOBJDIRS=no; do not create objdirs at start of build.
624 -R release Set RELEASEDIR to release. [Default: releasedir]
625 -r Remove contents of TOOLDIR and DESTDIR before building.
626 -S seed Set BUILDSEED to seed. [Default: NetBSD-majorversion]
627 -T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in
628 the environment, ${toolprefix}make will be (re)built unconditionally.
629 -U Set MKUNPRIVED=yes; build without requiring root privileges,
630 install from an UNPRIVED build with proper file permissions.
631 -u Set MKUPDATE=yes; do not run "make cleandir" first.
632 Without this, everything is rebuilt, including the tools.
633 -V v=[val] Set variable \`v' to \`val'.
634 -w wrapper Create ${toolprefix}make script as wrapper.
635 [Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE}]
636 -X x11src Set X11SRCDIR to x11src. [Default: /usr/xsrc]
637 -x Set MKX11=yes; build X11 from X11SRCDIR
638 -Y extsrcsrc
639 Set EXTSRCSRCDIR to extsrcsrc. [Default: /usr/extsrc]
640 -y Set MKEXTSRC=yes; build extsrc from EXTSRCSRCDIR
641 -Z v Unset ("zap") variable \`v'.
643 _usage_
644 exit 1
647 parseoptions()
649 opts='a:B:C:D:Ehj:M:m:N:nO:oR:rS:T:UuV:w:xX:yY:Z:'
650 opt_a=no
652 if type getopts >/dev/null 2>&1; then
653 # Use POSIX getopts.
655 getoptcmd='getopts ${opts} opt && opt=-${opt}'
656 optargcmd=':'
657 optremcmd='shift $((${OPTIND} -1))'
658 else
659 type getopt >/dev/null 2>&1 ||
660 bomb "/bin/sh shell is too old; try ksh or bash"
662 # Use old-style getopt(1) (doesn't handle whitespace in args).
664 args="$(getopt ${opts} $*)"
665 [ $? = 0 ] || usage
666 set -- ${args}
668 getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
669 optargcmd='OPTARG="$1"; shift'
670 optremcmd=':'
673 # Parse command line options.
675 while eval ${getoptcmd}; do
676 case ${opt} in
679 eval ${optargcmd}
680 MACHINE_ARCH=${OPTARG}
681 opt_a=yes
685 eval ${optargcmd}
686 BUILDID=${OPTARG}
690 eval ${optargcmd}; resolvepaths OPTARG
691 CDEXTRA="${CDEXTRA}${CDEXTRA:+ }${OPTARG}"
695 eval ${optargcmd}; resolvepath OPTARG
696 setmakeenv DESTDIR "${OPTARG}"
700 do_expertmode=true
704 eval ${optargcmd}
705 parallel="-j ${OPTARG}"
709 eval ${optargcmd}; resolvepath OPTARG
710 case "${OPTARG}" in
711 \$*) usage "-M argument must not begin with '$'"
713 *\$*) # can use resolvepath, but can't set TOP_objdir
714 resolvepath OPTARG
716 *) resolvepath OPTARG
717 TOP_objdir="${OPTARG}${TOP}"
719 esac
720 unsetmakeenv MAKEOBJDIR
721 setmakeenv MAKEOBJDIRPREFIX "${OPTARG}"
724 # -m overrides MACHINE_ARCH unless "-a" is specified
726 eval ${optargcmd}
727 MACHINE="${OPTARG}"
728 [ "${opt_a}" != "yes" ] && getarch
732 eval ${optargcmd}
733 case "${OPTARG}" in
734 0|1|2|3|4)
735 setmakeenv MAKEVERBOSE "${OPTARG}"
738 usage "'${OPTARG}' is not a valid value for -N"
740 esac
744 runcmd=echo
748 eval ${optargcmd}
749 case "${OPTARG}" in
750 *\$*) usage "-O argument must not contain '$'"
752 *) resolvepath OPTARG
753 TOP_objdir="${OPTARG}"
755 esac
756 unsetmakeenv MAKEOBJDIRPREFIX
757 setmakeenv MAKEOBJDIR "\${.CURDIR:C,^$TOP,$OPTARG,}"
761 MKOBJDIRS=no
765 eval ${optargcmd}; resolvepath OPTARG
766 setmakeenv RELEASEDIR "${OPTARG}"
770 do_removedirs=true
771 do_rebuildmake=true
775 eval ${optargcmd}
776 setmakeenv BUILDSEED "${OPTARG}"
780 eval ${optargcmd}; resolvepath OPTARG
781 TOOLDIR="${OPTARG}"
782 export TOOLDIR
786 setmakeenv MKUNPRIVED yes
790 setmakeenv MKUPDATE yes
794 eval ${optargcmd}
795 case "${OPTARG}" in
796 # XXX: consider restricting which variables can be changed?
797 [a-zA-Z_][a-zA-Z_0-9]*=*)
798 setmakeenv "${OPTARG%%=*}" "${OPTARG#*=}"
801 usage "-V argument must be of the form 'var=[value]'"
803 esac
807 eval ${optargcmd}; resolvepath OPTARG
808 makewrapper="${OPTARG}"
812 eval ${optargcmd}; resolvepath OPTARG
813 setmakeenv X11SRCDIR "${OPTARG}"
817 setmakeenv MKX11 yes
821 eval ${optargcmd}; resolvepath OPTARG
822 setmakeenv EXTSRCSRCDIR "${OPTARG}"
826 setmakeenv MKEXTSRC yes
830 eval ${optargcmd}
831 # XXX: consider restricting which variables can be unset?
832 unsetmakeenv "${OPTARG}"
836 break
839 -'?'|-h)
840 usage
843 esac
844 done
846 # Validate operations.
848 eval ${optremcmd}
849 while [ $# -gt 0 ]; do
850 op=$1; shift
851 operations="${operations} ${op}"
853 case "${op}" in
855 help)
856 usage
859 makewrapper|cleandir|obj|tools|build|distribution|release|sets|sourcesets|syspkgs|params)
862 iso-image)
863 op=iso_image # used as part of a variable name
866 iso-image-source)
867 op=iso_image_source # used as part of a variable name
870 kernel=*|releasekernel=*)
871 arg=${op#*=}
872 op=${op%%=*}
873 [ -n "${arg}" ] ||
874 bomb "Must supply a kernel name with \`${op}=...'"
877 modules)
878 op=modules
881 install=*)
882 arg=${op#*=}
883 op=${op%%=*}
884 [ -n "${arg}" ] ||
885 bomb "Must supply a directory with \`install=...'"
888 rump|rumptest)
889 op=${op}
893 usage "Unknown operation \`${op}'"
896 esac
897 eval do_${op}=true
898 done
899 [ -n "${operations}" ] || usage "Missing operation to perform."
901 # Set up MACHINE*. On a NetBSD host, these are allowed to be unset.
903 if [ -z "${MACHINE}" ]; then
904 [ "${uname_s}" = "NetBSD" ] ||
905 bomb "MACHINE must be set, or -m must be used, for cross builds."
906 MACHINE=${uname_m}
908 [ -n "${MACHINE_ARCH}" ] || getarch
909 validatearch
911 # Set up default make(1) environment.
913 makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
914 [ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID"
915 MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}"
916 export MAKEFLAGS MACHINE MACHINE_ARCH
919 sanitycheck()
921 # If the PATH contains any non-absolute components (including,
922 # but not limited to, "." or ""), then complain. As an exception,
923 # allow "" or "." as the last component of the PATH. This is fatal
924 # if expert mode is not in effect.
926 local path="${PATH}"
927 path="${path%:}" # delete trailing ":"
928 path="${path%:.}" # delete trailing ":."
929 case ":${path}:/" in
930 *:[!/]*)
931 if ${do_expertmode}; then
932 warning "PATH contains non-absolute components"
933 else
934 bomb "PATH environment variable must not" \
935 "contain non-absolute components"
938 esac
941 # print_tooldir_make --
942 # Try to find and print a path to an existing
943 # ${TOOLDIR}/bin/${toolprefix}make, for use by rebuildmake() before a
944 # new version of ${toolprefix}make has been built.
946 # * If TOOLDIR was set in the environment or on the command line, use
947 # that value.
948 # * Otherwise try to guess what TOOLDIR would be if not overridden by
949 # /etc/mk.conf, and check whether the resulting directory contains
950 # a copy of ${toolprefix}make (this should work for everybody who
951 # doesn't override TOOLDIR via /etc/mk.conf);
952 # * Failing that, search for ${toolprefix}make, nbmake, bmake, or make,
953 # in the PATH (this might accidentally find a non-NetBSD version of
954 # make, which will lead to failure in the next step);
955 # * If a copy of make was found above, try to use it with
956 # nobomb_getmakevar to find the correct value for TOOLDIR, and believe the
957 # result only if it's a directory that already exists;
958 # * If a value of TOOLDIR was found above, and if
959 # ${TOOLDIR}/bin/${toolprefix}make exists, print that value.
961 print_tooldir_make()
963 local possible_TOP_OBJ
964 local possible_TOOLDIR
965 local possible_make
966 local tooldir_make
968 if [ -n "${TOOLDIR}" ]; then
969 echo "${TOOLDIR}/bin/${toolprefix}make"
970 return 0
973 # Set host_ostype to something like "NetBSD-4.5.6-i386". This
974 # is intended to match the HOST_OSTYPE variable in <bsd.own.mk>.
976 local host_ostype="${uname_s}-$(
977 echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
978 )-$(
979 echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
982 # Look in a few potential locations for
983 # ${possible_TOOLDIR}/bin/${toolprefix}make.
984 # If we find it, then set possible_make.
986 # In the usual case (without interference from environment
987 # variables or /etc/mk.conf), <bsd.own.mk> should set TOOLDIR to
988 # "${_SRC_TOP_OBJ_}/tooldir.${host_ostype}".
990 # In practice it's difficult to figure out the correct value
991 # for _SRC_TOP_OBJ_. In the easiest case, when the -M or -O
992 # options were passed to build.sh, then ${TOP_objdir} will be
993 # the correct value. We also try a few other possibilities, but
994 # we do not replicate all the logic of <bsd.obj.mk>.
996 for possible_TOP_OBJ in \
997 "${TOP_objdir}" \
998 "${MAKEOBJDIRPREFIX:+${MAKEOBJDIRPREFIX}${TOP}}" \
999 "${TOP}" \
1000 "${TOP}/obj" \
1001 "${TOP}/obj.${MACHINE}"
1003 [ -n "${possible_TOP_OBJ}" ] || continue
1004 possible_TOOLDIR="${possible_TOP_OBJ}/tooldir.${host_ostype}"
1005 possible_make="${possible_TOOLDIR}/bin/${toolprefix}make"
1006 if [ -x "${possible_make}" ]; then
1007 break
1008 else
1009 unset possible_make
1011 done
1013 # If the above didn't work, search the PATH for a suitable
1014 # ${toolprefix}make, nbmake, bmake, or make.
1016 : ${possible_make:=$(find_in_PATH ${toolprefix}make '')}
1017 : ${possible_make:=$(find_in_PATH nbmake '')}
1018 : ${possible_make:=$(find_in_PATH bmake '')}
1019 : ${possible_make:=$(find_in_PATH make '')}
1021 # At this point, we don't care whether possible_make is in the
1022 # correct TOOLDIR or not; we simply want it to be usable by
1023 # getmakevar to help us find the correct TOOLDIR.
1025 # Use ${possible_make} with nobomb_getmakevar to try to find
1026 # the value of TOOLDIR. Believe the result only if it's
1027 # a directory that already exists and contains bin/${toolprefix}make.
1029 if [ -x "${possible_make}" ]; then
1030 possible_TOOLDIR="$(
1031 make="${possible_make}" nobomb_getmakevar TOOLDIR
1033 if [ $? = 0 ] && [ -n "${possible_TOOLDIR}" ] \
1034 && [ -d "${possible_TOOLDIR}" ];
1035 then
1036 tooldir_make="${possible_TOOLDIR}/bin/${toolprefix}make"
1037 if [ -x "${tooldir_make}" ]; then
1038 echo "${tooldir_make}"
1039 return 0
1043 return 1
1046 # rebuildmake --
1047 # Rebuild nbmake in a temporary directory if necessary. Sets $make
1048 # to a path to the nbmake executable. Sets done_rebuildmake=true
1049 # if nbmake was rebuilt.
1051 # There is a cyclic dependency between building nbmake and choosing
1052 # TOOLDIR: TOOLDIR may be affected by settings in /etc/mk.conf, so we
1053 # would like to use getmakevar to get the value of TOOLDIR; but we can't
1054 # use getmakevar before we have an up to date version of nbmake; we
1055 # might already have an up to date version of nbmake in TOOLDIR, but we
1056 # don't yet know where TOOLDIR is.
1058 # The default value of TOOLDIR also depends on the location of the top
1059 # level object directory, so $(getmakevar TOOLDIR) invoked before or
1060 # after making the top level object directory may produce different
1061 # results.
1063 # Strictly speaking, we should do the following:
1065 # 1. build a new version of nbmake in a temporary directory;
1066 # 2. use the temporary nbmake to create the top level obj directory;
1067 # 3. use $(getmakevar TOOLDIR) with the temporary nbmake to
1068 # get the corect value of TOOLDIR;
1069 # 4. move the temporary nbmake to ${TOOLDIR}/bin/nbmake.
1071 # However, people don't like building nbmake unnecessarily if their
1072 # TOOLDIR has not changed since an earlier build. We try to avoid
1073 # rebuilding a temporary version of nbmake by taking some shortcuts to
1074 # guess a value for TOOLDIR, looking for an existing version of nbmake
1075 # in that TOOLDIR, and checking whether that nbmake is newer than the
1076 # sources used to build it.
1078 rebuildmake()
1080 make="$(print_tooldir_make)"
1081 if [ -n "${make}" ] && [ -x "${make}" ]; then
1082 for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
1083 if [ "${f}" -nt "${make}" ]; then
1084 statusmsg "${make} outdated" \
1085 "(older than ${f}), needs building."
1086 do_rebuildmake=true
1087 break
1089 done
1090 else
1091 statusmsg "No \$TOOLDIR/bin/${toolprefix}make, needs building."
1092 do_rebuildmake=true
1095 # Build bootstrap ${toolprefix}make if needed.
1096 if ${do_rebuildmake}; then
1097 statusmsg "Bootstrapping ${toolprefix}make"
1098 ${runcmd} cd "${tmpdir}"
1099 ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
1100 CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
1101 ${HOST_SH} "${TOP}/tools/make/configure" ||
1102 bomb "Configure of ${toolprefix}make failed"
1103 ${runcmd} ${HOST_SH} buildmake.sh ||
1104 bomb "Build of ${toolprefix}make failed"
1105 make="${tmpdir}/${toolprefix}make"
1106 ${runcmd} cd "${TOP}"
1107 ${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
1108 done_rebuildmake=true
1112 validatemakeparams()
1114 if [ "${runcmd}" = "echo" ]; then
1115 TOOLCHAIN_MISSING=no
1116 EXTERNAL_TOOLCHAIN=""
1117 else
1118 TOOLCHAIN_MISSING=$(bomb_getmakevar TOOLCHAIN_MISSING)
1119 EXTERNAL_TOOLCHAIN=$(bomb_getmakevar EXTERNAL_TOOLCHAIN)
1121 if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
1122 [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
1123 ${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
1124 ${runcmd} echo " MACHINE: ${MACHINE}"
1125 ${runcmd} echo " MACHINE_ARCH: ${MACHINE_ARCH}"
1126 ${runcmd} echo ""
1127 ${runcmd} echo "All builds for this platform should be done via a traditional make"
1128 ${runcmd} echo "If you wish to use an external cross-toolchain, set"
1129 ${runcmd} echo " EXTERNAL_TOOLCHAIN=<path to toolchain root>"
1130 ${runcmd} echo "in either the environment or mk.conf and rerun"
1131 ${runcmd} echo " ${progname} $*"
1132 exit 1
1135 # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE
1136 # These may be set as build.sh options or in "mk.conf".
1137 # Don't export them as they're only used for tests in build.sh.
1139 MKOBJDIRS=$(getmakevar MKOBJDIRS)
1140 MKUNPRIVED=$(getmakevar MKUNPRIVED)
1141 MKUPDATE=$(getmakevar MKUPDATE)
1143 if [ "${MKOBJDIRS}" != "no" ]; then
1144 # Create the top-level object directory.
1146 # "make obj NOSUBDIR=" can handle most cases, but it
1147 # can't handle the case where MAKEOBJDIRPREFIX is set
1148 # while the corresponding directory does not exist
1149 # (rules in <bsd.obj.mk> would abort the build). We
1150 # therefore have to handle the MAKEOBJDIRPREFIX case
1151 # without invoking "make obj". The MAKEOBJDIR case
1152 # could be handled either way, but we choose to handle
1153 # it similarly to MAKEOBJDIRPREFIX.
1155 if [ -n "${TOP_obj}" ]; then
1156 # It must have been set by the "-M" or "-O"
1157 # command line options, so there's no need to
1158 # use getmakevar
1160 elif [ -n "$MAKEOBJDIRPREFIX" ]; then
1161 TOP_obj="$(getmakevar MAKEOBJDIRPREFIX)${TOP}"
1162 elif [ -n "$MAKEOBJDIR" ]; then
1163 TOP_obj="$(getmakevar MAKEOBJDIR)"
1165 if [ -n "$TOP_obj" ]; then
1166 ${runcmd} mkdir -p "${TOP_obj}" ||
1167 bomb "Can't create top level object directory" \
1168 "${TOP_obj}"
1169 else
1170 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1171 bomb "Can't create top level object directory" \
1172 "using make obj"
1175 # make obj in tools to ensure that the objdir for "tools"
1176 # is available.
1178 ${runcmd} cd tools
1179 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1180 bomb "Failed to make obj in tools"
1181 ${runcmd} cd "${TOP}"
1184 # Find TOOLDIR, DESTDIR, and RELEASEDIR, according to getmakevar,
1185 # and bomb if they have changed from the values we had from the
1186 # command line or environment.
1188 # This must be done after creating the top-level object directory.
1190 for var in TOOLDIR DESTDIR RELEASEDIR
1192 eval oldval=\"\$${var}\"
1193 newval="$(getmakevar $var)"
1194 if ! $do_expertmode; then
1195 : ${_SRC_TOP_OBJ_:=$(getmakevar _SRC_TOP_OBJ_)}
1196 case "$var" in
1197 DESTDIR)
1198 : ${newval:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}}
1199 makeenv="${makeenv} DESTDIR"
1201 RELEASEDIR)
1202 : ${newval:=${_SRC_TOP_OBJ_}/releasedir}
1203 makeenv="${makeenv} RELEASEDIR"
1205 esac
1207 if [ -n "$oldval" ] && [ "$oldval" != "$newval" ]; then
1208 bomb "Value of ${var} has changed" \
1209 "(was \"${oldval}\", now \"${newval}\")"
1211 eval ${var}=\"\${newval}\"
1212 eval export ${var}
1213 statusmsg "${var} path: ${newval}"
1214 done
1216 # RELEASEMACHINEDIR is just a subdir name, e.g. "i386".
1217 RELEASEMACHINEDIR=$(getmakevar RELEASEMACHINEDIR)
1219 # Check validity of TOOLDIR and DESTDIR.
1221 if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then
1222 bomb "TOOLDIR '${TOOLDIR}' invalid"
1224 removedirs="${TOOLDIR}"
1226 if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then
1227 if ${do_build} || ${do_distribution} || ${do_release}; then
1228 if ! ${do_build} || \
1229 [ "${uname_s}" != "NetBSD" ] || \
1230 [ "${uname_m}" != "${MACHINE}" ]; then
1231 bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'."
1233 if ! ${do_expertmode}; then
1234 bomb "DESTDIR must != / for non -E (expert) builds"
1236 statusmsg "WARNING: Building to /, in expert mode."
1237 statusmsg " This may cause your system to break! Reasons include:"
1238 statusmsg " - your kernel is not up to date"
1239 statusmsg " - the libraries or toolchain have changed"
1240 statusmsg " YOU HAVE BEEN WARNED!"
1242 else
1243 removedirs="${removedirs} ${DESTDIR}"
1245 if ${do_build} || ${do_distribution} || ${do_release}; then
1246 if ! ${do_expertmode} && \
1247 [ "$id_u" -ne 0 ] && \
1248 [ "${MKUNPRIVED}" = "no" ] ; then
1249 bomb "-U or -E must be set for build as an unprivileged user."
1252 if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then
1253 bomb "Must set RELEASEDIR with \`releasekernel=...'"
1256 # Install as non-root is a bad idea.
1258 if ${do_install} && [ "$id_u" -ne 0 ] ; then
1259 if ${do_expertmode}; then
1260 warning "Will install as an unprivileged user."
1261 else
1262 bomb "-E must be set for install as an unprivileged user."
1266 # If a previous build.sh run used -U (and therefore created a
1267 # METALOG file), then most subsequent build.sh runs must also
1268 # use -U. If DESTDIR is about to be removed, then don't perform
1269 # this check.
1271 case "${do_removedirs} ${removedirs} " in
1272 true*" ${DESTDIR} "*)
1273 # DESTDIR is about to be removed
1276 if ( ${do_build} || ${do_distribution} || ${do_release} || \
1277 ${do_install} ) && \
1278 [ -e "${DESTDIR}/METALOG" ] && \
1279 [ "${MKUNPRIVED}" = "no" ] ; then
1280 if $do_expertmode; then
1281 warning "A previous build.sh run specified -U."
1282 else
1283 bomb "A previous build.sh run specified -U; you must specify it again now."
1287 esac
1291 createmakewrapper()
1293 # Remove the target directories.
1295 if ${do_removedirs}; then
1296 for f in ${removedirs}; do
1297 statusmsg "Removing ${f}"
1298 ${runcmd} rm -r -f "${f}"
1299 done
1302 # Recreate $TOOLDIR.
1304 ${runcmd} mkdir -p "${TOOLDIR}/bin" ||
1305 bomb "mkdir of '${TOOLDIR}/bin' failed"
1307 # If we did not previously rebuild ${toolprefix}make, then
1308 # check whether $make is still valid and the same as the output
1309 # from print_tooldir_make. If not, then rebuild make now. A
1310 # possible reason for this being necessary is that the actual
1311 # value of TOOLDIR might be different from the value guessed
1312 # before the top level obj dir was created.
1314 if ! ${done_rebuildmake} && \
1315 ( [ ! -x "$make" ] || [ "$make" != "$(print_tooldir_make)" ] )
1316 then
1317 rebuildmake
1320 # Install ${toolprefix}make if it was built.
1322 if ${done_rebuildmake}; then
1323 ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make"
1324 ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" ||
1325 bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make"
1326 make="${TOOLDIR}/bin/${toolprefix}make"
1327 statusmsg "Created ${make}"
1330 # Build a ${toolprefix}make wrapper script, usable by hand as
1331 # well as by build.sh.
1333 if [ -z "${makewrapper}" ]; then
1334 makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}"
1335 [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}"
1338 ${runcmd} rm -f "${makewrapper}"
1339 if [ "${runcmd}" = "echo" ]; then
1340 echo 'cat <<EOF >'${makewrapper}
1341 makewrapout=
1342 else
1343 makewrapout=">>\${makewrapper}"
1346 case "${KSH_VERSION:-${SH_VERSION}}" in
1347 *PD\ KSH*|*MIRBSD\ KSH*)
1348 set +o braceexpand
1350 esac
1352 eval cat <<EOF ${makewrapout}
1353 #! ${HOST_SH}
1354 # Set proper variables to allow easy "make" building of a NetBSD subtree.
1355 # Generated from: \$NetBSD: build.sh,v 1.225 2009/12/17 15:30:37 matt Exp $
1356 # with these arguments: ${_args}
1361 for f in ${makeenv}; do
1362 if eval "[ -z \"\${$f}\" -a \"\${${f}-X}\" = \"X\" ]"; then
1363 eval echo "unset ${f}"
1364 else
1365 eval echo "${f}=\'\$$(echo ${f})\'\;\ export\ ${f}"
1367 done
1369 eval cat <<EOF
1370 MAKEWRAPPERMACHINE=${makewrappermachine:-${MACHINE}}; export MAKEWRAPPERMACHINE
1371 USETOOLS=yes; export USETOOLS
1373 } | eval sort -u "${makewrapout}"
1374 eval cat <<EOF "${makewrapout}"
1376 exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
1378 [ "${runcmd}" = "echo" ] && echo EOF
1379 ${runcmd} chmod +x "${makewrapper}"
1380 statusmsg "makewrapper: ${makewrapper}"
1381 statusmsg "Updated ${makewrapper}"
1384 make_in_dir()
1386 dir="$1"
1387 op="$2"
1388 ${runcmd} cd "${dir}" ||
1389 bomb "Failed to cd to \"${dir}\""
1390 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1391 bomb "Failed to make ${op} in \"${dir}\""
1392 ${runcmd} cd "${TOP}" ||
1393 bomb "Failed to cd back to \"${TOP}\""
1396 buildtools()
1398 if [ "${MKOBJDIRS}" != "no" ]; then
1399 ${runcmd} "${makewrapper}" ${parallel} obj-tools ||
1400 bomb "Failed to make obj-tools"
1402 if [ "${MKUPDATE}" = "no" ]; then
1403 make_in_dir tools cleandir
1405 make_in_dir tools dependall
1406 make_in_dir tools install
1407 statusmsg "Tools built to ${TOOLDIR}"
1410 getkernelconf()
1412 kernelconf="$1"
1413 if [ "${MKOBJDIRS}" != "no" ]; then
1414 # The correct value of KERNOBJDIR might
1415 # depend on a prior "make obj" in
1416 # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
1418 KERNSRCDIR="$(getmakevar KERNSRCDIR)"
1419 KERNARCHDIR="$(getmakevar KERNARCHDIR)"
1420 make_in_dir "${KERNSRCDIR}/${KERNARCHDIR}/compile" obj
1422 KERNCONFDIR="$(getmakevar KERNCONFDIR)"
1423 KERNOBJDIR="$(getmakevar KERNOBJDIR)"
1424 case "${kernelconf}" in
1425 */*)
1426 kernelconfpath="${kernelconf}"
1427 kernelconfname="${kernelconf##*/}"
1430 kernelconfpath="${KERNCONFDIR}/${kernelconf}"
1431 kernelconfname="${kernelconf}"
1433 esac
1434 kernelbuildpath="${KERNOBJDIR}/${kernelconfname}"
1437 buildkernel()
1439 if ! ${do_tools} && ! ${buildkernelwarned:-false}; then
1440 # Building tools every time we build a kernel is clearly
1441 # unnecessary. We could try to figure out whether rebuilding
1442 # the tools is necessary this time, but it doesn't seem worth
1443 # the trouble. Instead, we say it's the user's responsibility
1444 # to rebuild the tools if necessary.
1446 statusmsg "Building kernel without building new tools"
1447 buildkernelwarned=true
1449 getkernelconf $1
1450 statusmsg "Building kernel: ${kernelconf}"
1451 statusmsg "Build directory: ${kernelbuildpath}"
1452 ${runcmd} mkdir -p "${kernelbuildpath}" ||
1453 bomb "Cannot mkdir: ${kernelbuildpath}"
1454 if [ "${MKUPDATE}" = "no" ]; then
1455 make_in_dir "${kernelbuildpath}" cleandir
1457 [ -x "${TOOLDIR}/bin/${toolprefix}config" ] \
1458 || bomb "${TOOLDIR}/bin/${toolprefix}config does not exist. You need to \"$0 tools\" first."
1459 ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" -b "${kernelbuildpath}" \
1460 -s "${TOP}/sys" "${kernelconfpath}" ||
1461 bomb "${toolprefix}config failed for ${kernelconf}"
1462 make_in_dir "${kernelbuildpath}" depend
1463 make_in_dir "${kernelbuildpath}" all
1465 if [ "${runcmd}" != "echo" ]; then
1466 statusmsg "Kernels built from ${kernelconf}:"
1467 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1468 for kern in ${kernlist:-netbsd}; do
1469 [ -f "${kernelbuildpath}/${kern}" ] && \
1470 echo " ${kernelbuildpath}/${kern}"
1471 done | tee -a "${results}"
1475 releasekernel()
1477 getkernelconf $1
1478 kernelreldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel"
1479 ${runcmd} mkdir -p "${kernelreldir}"
1480 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1481 for kern in ${kernlist:-netbsd}; do
1482 builtkern="${kernelbuildpath}/${kern}"
1483 [ -f "${builtkern}" ] || continue
1484 releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz"
1485 statusmsg "Kernel copy: ${releasekern}"
1486 if [ "${runcmd}" = "echo" ]; then
1487 echo "gzip -c -9 < ${builtkern} > ${releasekern}"
1488 else
1489 gzip -c -9 < "${builtkern}" > "${releasekern}"
1491 done
1494 buildmodules()
1496 if ! ${do_tools} && ! ${buildmoduleswarned:-false}; then
1497 # Building tools every time we build modules is clearly
1498 # unnecessary as well as a kernel.
1500 statusmsg "Building modules without building new tools"
1501 buildmoduleswarned=true
1504 statusmsg "Building kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
1505 if [ "${MKOBJDIRS}" != "no" ]; then
1506 make_in_dir sys/modules obj ||
1507 bomb "Failed to make obj in sys/modules"
1509 if [ "${MKUPDATE}" = "no" ]; then
1510 make_in_dir sys/modules cleandir
1512 ${runcmd} "${makewrapper}" ${parallel} do-sys-modules ||
1513 bomb "Failed to make do-sys-modules"
1515 statusmsg "Successful built kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
1518 installworld()
1520 dir="$1"
1521 ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld ||
1522 bomb "Failed to make installworld to ${dir}"
1523 statusmsg "Successful installworld to ${dir}"
1526 # Run rump build&link tests.
1528 # To make this feasible for running without having to install includes and
1529 # libraries into destdir (i.e. quick), we only run ld. This is possible
1530 # since the rump kernel is a closed namespace apart from calls to rumpuser.
1531 # Therefore, if ld complains only about rumpuser symbols, rump kernel
1532 # linking was successful.
1534 # We test that rump links with a number of component configurations.
1535 # These attempt to mimic what is encountered in the full build.
1536 # See list below. The list should probably be either autogenerated
1537 # or managed elsewhere. But keep it here until a better idea arises.
1539 # Above all, note that THIS IS NOT A SUBSTITUTE FOR A FULL BUILD.
1542 RUMP_LIBSETS='
1543 -lrump,
1544 -lrumpvfs -lrump,
1545 -lrumpfs_tmpfs -lrumpvfs -lrump,
1546 -lrumpfs_ffs -lrumpfs_msdosfs -lrumpvfs -lrump,
1547 -lrumpnet_virtif -lrumpnet_netinet -lrumpnet_net -lrumpnet -lrump,
1548 -lrumpnet_sockin -lrumpfs_smbfs -lrumpdev_netsmb
1549 -lrumpcrypto -lrumpdev -lrumpnet -lrumpvfs -lrump,
1550 -lrumpnet_sockin -lrumpfs_nfs -lrumpnet -lrumpvfs -lrump,
1551 -lrumpdev_cgd -lrumpdev_raidframe -lrumpdev_disk -lrumpdev_rnd
1552 -lrumpdev -lrumpvfs -lrumpcrypto -lrump'
1553 dorump()
1555 local doclean=""
1556 local doobjs=""
1558 # we cannot link libs without building csu, and that leads to lossage
1559 [ "${1}" != "rumptest" ] && bomb 'build.sh rump not yet functional. ' \
1560 'did you mean "rumptest"?'
1562 [ "${MKUPDATE}" = "no" ] && doclean="cleandir"
1563 [ "${MKOBJDIRS}" = "no" ] || doobjs="obj"
1564 ${runcmd} "${makewrapper}" ${parallel} do-distrib-dirs
1566 targlist="${doclean} ${doobjs} dependall install"
1567 setmakeenv NORUMPUSER 1
1568 # optimize: for test we build only static libs (3x test speedup)
1569 if [ "${1}" = "rumptest" ] ; then
1570 setmakeenv NOPIC 1
1571 setmakeenv NOPROFILE 1
1573 for cmd in ${targlist} ; do
1574 make_in_dir "${NETBSDSRCDIR}/sys/rump" ${cmd}
1575 done
1577 # if we just wanted to build & install rump, we're done
1578 [ "${1}" != "rumptest" ] && return
1580 ${runcmd} cd "${NETBSDSRCDIR}/sys/rump/librump/rumpkern" \
1581 || bomb "cd to rumpkern failed"
1582 md_quirks=`${runcmd} "${makewrapper}" -V '${_SYMQUIRK}'`
1583 # one little, two little, three little backslashes ...
1584 md_quirks="`echo ${md_quirks} | sed 's,\\\,\\\\\\\,g'";s/'//g" `"
1585 ${runcmd} cd "${TOP}" || bomb "cd to ${TOP} failed"
1586 tool_ld=`${runcmd} "${makewrapper}" -V '${LD}'`
1588 local oIFS="${IFS}"
1589 IFS=","
1590 for set in ${RUMP_LIBSETS} ; do
1591 IFS="${oIFS}"
1592 ${runcmd} ${tool_ld} -nostdlib -L${DESTDIR}/usr/lib \
1593 -static --whole-archive ${set} 2>&1 | \
1594 awk -v quirks="${md_quirks}" '
1595 /undefined reference/ &&
1596 !/more undefined references.*follow/{
1597 if (match($NF,
1598 "`(rumpuser_|__" quirks ")") == 0)
1599 fails[NR] = $0
1601 END{
1602 for (x in fails)
1603 print fails[x]
1604 exit x!=0
1606 [ $? -ne 0 ] && bomb "Testlink of rump failed: ${set}"
1607 done
1608 statusmsg "Rump build&link tests successful"
1611 main()
1613 initdefaults
1614 _args=$@
1615 parseoptions "$@"
1617 sanitycheck
1619 build_start=$(date)
1620 statusmsg "${progname} command: $0 $@"
1621 statusmsg "${progname} started: ${build_start}"
1622 statusmsg "NetBSD version: ${DISTRIBVER}"
1623 statusmsg "MACHINE: ${MACHINE}"
1624 statusmsg "MACHINE_ARCH: ${MACHINE_ARCH}"
1625 statusmsg "Build platform: ${uname_s} ${uname_r} ${uname_m}"
1626 statusmsg "HOST_SH: ${HOST_SH}"
1628 rebuildmake
1629 validatemakeparams
1630 createmakewrapper
1632 # Perform the operations.
1634 for op in ${operations}; do
1635 case "${op}" in
1637 makewrapper)
1638 # no-op
1641 tools)
1642 buildtools
1645 sets)
1646 statusmsg "Building sets from pre-populated ${DESTDIR}"
1647 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1648 bomb "Failed to make ${op}"
1649 setdir=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
1650 statusmsg "Built sets to ${setdir}"
1653 cleandir|obj|build|distribution|release|sourcesets|syspkgs|params)
1654 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1655 bomb "Failed to make ${op}"
1656 statusmsg "Successful make ${op}"
1659 iso-image|iso-image-source)
1660 ${runcmd} "${makewrapper}" ${parallel} \
1661 CDEXTRA="$CDEXTRA" ${op} ||
1662 bomb "Failed to make ${op}"
1663 statusmsg "Successful make ${op}"
1666 kernel=*)
1667 arg=${op#*=}
1668 buildkernel "${arg}"
1671 releasekernel=*)
1672 arg=${op#*=}
1673 releasekernel "${arg}"
1676 modules)
1677 buildmodules
1680 install=*)
1681 arg=${op#*=}
1682 if [ "${arg}" = "/" ] && \
1683 ( [ "${uname_s}" != "NetBSD" ] || \
1684 [ "${uname_m}" != "${MACHINE}" ] ); then
1685 bomb "'${op}' must != / for cross builds."
1687 installworld "${arg}"
1690 rump|rumptest)
1691 dorump "${op}"
1695 bomb "Unknown operation \`${op}'"
1698 esac
1699 done
1701 statusmsg "${progname} ended: $(date)"
1702 if [ -s "${results}" ]; then
1703 echo "===> Summary of results:"
1704 sed -e 's/^===>//;s/^/ /' "${results}"
1705 echo "===> ."
1709 main "$@"