2 # $NetBSD: build.sh,v 1.254 2012/02/26 20:32:40 tsutsui Exp $
4 # Copyright (c) 2001-2011 The NetBSD Foundation, Inc.
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
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, to build or cross-build NetBSD.
36 # {{{ Begin shell feature tests.
38 # We try to determine whether or not this script is being run under
39 # a shell that supports the features that we use. If not, we try to
40 # re-exec the script under another shell. If we can't find another
41 # suitable shell, then we print a message and exit.
44 errmsg
='' # error message, if not empty
45 shelltest
=false
# if true, exit after testing the shell
46 re_exec_allowed
=true
# if true, we may exec under another shell
48 # Parse special command line options in $1. These special options are
49 # for internal use only, are not documented, and are not valid anywhere
63 # Solaris /bin/sh, and other SVR4 shells, do not support "!".
64 # This is the first feature that we test, because subsequent
67 if test -z "$errmsg"; then
68 if ( eval '! false' ) >/dev
/null
2>&1 ; then
71 errmsg
='Shell does not support "!".'
75 # Does the shell support functions?
77 if test -z "$errmsg"; then
79 eval 'somefunction() { : ; }'
82 errmsg
='Shell does not support functions.'
86 # Does the shell support the "local" keyword for variables in functions?
88 # Local variables are not required by SUSv3, but some scripts run during
89 # the NetBSD build use them.
91 # ksh93 fails this test; it uses an incompatible syntax involving the
92 # keywords 'function' and 'typeset'.
94 if test -z "$errmsg"; then
96 eval 'f() { local v=2; }; v=1; f && test x"$v" = x"1"'
99 errmsg
='Shell does not support the "local" keyword in functions.'
103 # Does the shell support ${var%suffix}, ${var#prefix}, and their variants?
105 # We don't bother testing for ${var+value}, ${var-value}, or their variants,
106 # since shells without those are sure to fail other tests too.
108 if test -z "$errmsg"; then
111 test x"${var#*/};${var##*/};${var%/*};${var%%/*}" = \
115 errmsg
='Shell does not support "${var%suffix}" or "${var#prefix}".'
119 # Does the shell support IFS?
121 # zsh in normal mode (as opposed to "emulate sh" mode) fails this test.
123 if test -z "$errmsg"; then
125 eval 'IFS=: ; v=":a b::c" ; set -- $v ; IFS=+ ;
126 test x"$#;$1,$2,$3,$4;$*" = x"4;,a b,,c;+a b++c"'
129 errmsg
='Shell does not support IFS word splitting.'
133 # Does the shell support ${1+"$@"}?
135 # Some versions of zsh fail this test, even in "emulate sh" mode.
137 if test -z "$errmsg"; then
139 eval 'set -- "a a a" "b b b"; set -- ${1+"$@"};
140 test x"$#;$1;$2" = x"2;a a a;b b b";'
143 errmsg
='Shell does not support ${1+"$@"}.'
147 # Does the shell support $(...) command substitution?
149 if test -z "$errmsg"; then
151 eval 'var=$(echo abc); test x"$var" = x"abc"'
154 errmsg
='Shell does not support "$(...)" command substitution.'
158 # Does the shell support $(...) command substitution with
159 # unbalanced parentheses?
161 # Some shells known to fail this test are: NetBSD /bin/ksh (as of 2009-12),
162 # bash-3.1, pdksh-5.2.14, zsh-4.2.7 in "emulate sh" mode.
164 if test -z "$errmsg"; then
166 eval 'var=$(case x in x) echo abc;; esac); test x"$var" = x"abc"'
169 # XXX: This test is ignored because so many shells fail it; instead,
170 # the NetBSD build avoids using the problematic construct.
171 : ignore
'Shell does not support "$(...)" with unbalanced ")".'
175 # Does the shell support getopts or getopt?
177 if test -z "$errmsg"; then
179 eval 'type getopts || type getopt'
182 errmsg
='Shell does not support getopts or getopt.'
187 # If shelltest is true, exit now, reporting whether or not the shell is good.
190 if test -n "$errmsg"; then
191 echo >&2 "$0: $errmsg"
199 # If the shell was bad, try to exec a better shell, or report an error.
201 # Loops are broken by passing an extra "--no-re-exec" flag to the new
202 # instance of this script.
204 if test -n "$errmsg"; then
205 if $re_exec_allowed; then
207 "${HOST_SH}" /usr
/xpg
4/bin
/sh ksh ksh88 mksh pdksh bash dash
208 # NOTE: some shells known not to work are:
209 # any shell using csh syntax;
210 # Solaris /bin/sh (missing many modern features);
211 # ksh93 (incompatible syntax for local variables);
212 # zsh (many differences, unless run in compatibility mode).
214 test -n "$othershell" ||
continue
215 if eval 'type "$othershell"' >/dev
/null
2>&1 \
216 && "$othershell" "$0" --shelltest >/dev
/null
2>&1
220 $0: Retrying under $othershell
222 HOST_SH
="$othershell"
224 exec $othershell "$0" --no-re-exec "$@" # avoid ${1+"$@"}
226 # If HOST_SH was set, but failed the test above,
227 # then give up without trying any other shells.
228 test x
"${othershell}" = x
"${HOST_SH}" && break
233 # If we get here, then the shell is bad, and we either could not
234 # find a replacement, or were not allowed to try a replacement.
239 The NetBSD build system requires a shell that supports modern POSIX
240 features, as well as the "local" keyword in functions (which is a
241 widely-implemented but non-standardised feature).
243 Please re-run this script under a suitable shell. For example:
245 /path/to/suitable/shell $0 ...
247 The above command will usually enable build.sh to automatically set
248 HOST_SH=/path/to/suitable/shell, but if that fails, then you may also
249 need to explicitly set the HOST_SH environment variable, as follows:
251 HOST_SH=/path/to/suitable/shell
259 # }}} End shell feature tests.
266 trap "exit 1" 1 2 3 15
270 cat >&2 <<ERRORMESSAGE
273 *** BUILD ABORTED ***
275 kill ${toppid} # in case we were invoked from a subshell
282 ${runcmd} echo "===> $@" |
tee -a "${results}"
292 ????????????????
*) ;;
293 ??????????
*) msg
="${msg} ";;
294 ?????
*) msg
="${msg} ";;
298 ?????????????????????
*) ;;
299 ????????????????????
) msg
="${msg} ";;
300 ???????????????????
) msg
="${msg} ";;
301 ??????????????????
) msg
="${msg} ";;
302 ?????????????????
) msg
="${msg} ";;
303 ????????????????
) msg
="${msg} ";;
310 statusmsg
"Warning: $@"
313 # Find a program in the PATH, and print the result. If not found,
314 # print a default. If $2 is defined (even if it is an empty string),
315 # then that is the default; otherwise, $1 is used as the default.
319 local result
="${2-"$1"}"
320 local oldIFS
="${IFS}"
323 for dir
in ${PATH}; do
324 if [ -x "${dir}/${prog}" ]; then
325 result
="${dir}/${prog}"
333 # Try to find a working POSIX shell, and set HOST_SH to refer to it.
334 # Assumes that uname_s, uname_m, and PWD have been set.
337 # Even if ${HOST_SH} is already defined, we still do the
338 # sanity checks at the end.
340 # Solaris has /usr/xpg4/bin/sh.
342 [ -z "${HOST_SH}" ] && [ x
"${uname_s}" = x
"SunOS" ] && \
343 [ -x /usr
/xpg
4/bin
/sh
] && HOST_SH
="/usr/xpg4/bin/sh"
345 # Try to get the name of the shell that's running this script,
346 # by parsing the output from "ps". We assume that, if the host
347 # system's ps command supports -o comm at all, it will do so
348 # in the usual way: a one-line header followed by a one-line
349 # result, possibly including trailing white space. And if the
350 # host system's ps command doesn't support -o comm, we assume
351 # that we'll get an error message on stderr and nothing on
352 # stdout. (We don't try to use ps -o 'comm=' to suppress the
353 # header line, because that is less widely supported.)
355 # If we get the wrong result here, the user can override it by
356 # specifying HOST_SH in the environment.
358 [ -z "${HOST_SH}" ] && HOST_SH
="$(
359 (ps -p $$ -o comm | sed -ne "2s
/[ ${tab}]*\$
//p
") 2>/dev/null )"
361 # If nothing above worked, use "sh". We will later find the
362 # first directory in the PATH that has a "sh" program.
364 [ -z "${HOST_SH}" ] && HOST_SH
="sh"
366 # If the result so far is not an absolute path, try to prepend
367 # PWD or search the PATH.
372 */*) HOST_SH
="${PWD}/${HOST_SH}"
374 *) HOST_SH
="$(find_in_PATH "${HOST_SH}")"
378 # If we don't have an absolute path by now, bomb.
383 *) bomb
"HOST_SH=\"${HOST_SH}\" is not an absolute path."
387 # If HOST_SH is not executable, bomb.
389 [ -x "${HOST_SH}" ] ||
390 bomb
"HOST_SH=\"${HOST_SH}\" is not executable."
392 # If HOST_SH fails tests, bomb.
393 # ("$0" may be a path that is no longer valid, because we have
394 # performed "cd $(dirname $0)", so don't use $0 here.)
396 "${HOST_SH}" build.sh
--shelltest ||
397 bomb
"HOST_SH=\"${HOST_SH}\" failed functionality tests."
401 # Set defaults before parsing command line options.
412 [ -d usr.bin
/make ] ||
cd "$(dirname $0)"
413 [ -d usr.bin
/make ] ||
414 bomb
"build.sh must be run from the top source level"
415 [ -f share
/mk
/bsd.own.mk
] ||
416 bomb
"src/share/mk is missing; please re-fetch the source tree"
418 # Set various environment variables to known defaults,
419 # to minimize (cross-)build problems observed "in the field".
421 # LC_ALL=C must be set before we try to parse the output from
422 # any command. Other variables are set (or unset) here, before
423 # we parse command line arguments.
425 # These variables can be overridden via "-V var=value" if
426 # you know what you are doing.
429 unsetmakeenv LESSCHARSET
430 unsetmakeenv MAKEFLAGS
433 # Find information about the build platform. This should be
434 # kept in sync with _HOST_OSNAME, _HOST_OSREL, and _HOST_ARCH
435 # variables in share/mk/bsd.sys.mk.
437 # Note that "uname -p" is not part of POSIX, but we want uname_p
438 # to be set to the host MACHINE_ARCH, if possible. On systems
439 # where "uname -p" fails, prints "unknown", or prints a string
440 # that does not look like an identifier, fall back to using the
441 # output from "uname -m" instead.
443 uname_s
=$
(uname
-s 2>/dev
/null
)
444 uname_r
=$
(uname
-r 2>/dev
/null
)
445 uname_m
=$
(uname
-m 2>/dev
/null
)
446 uname_p
=$
(uname
-p 2>/dev
/null ||
echo "unknown")
448 ''|unknown|
*[^
-_A-Za-z0-9]*) uname_p
="${uname_m}" ;;
451 id_u
=$
(id
-u 2>/dev
/null ||
/usr
/xpg
4/bin
/id
-u 2>/dev
/null
)
453 # If $PWD is a valid name of the current directory, POSIX mandates
454 # that pwd return it by default which causes problems in the
455 # presence of symlinks. Unsetting PWD is simpler than changing
456 # every occurrence of pwd to use -P.
458 # XXX Except that doesn't work on Solaris. Or many Linuces.
461 TOP
=$
(/bin
/pwd -P 2>/dev
/null ||
/bin
/pwd 2>/dev
/null
)
463 # The user can set HOST_SH in the environment, or we try to
464 # guess an appropriate value. Then we set several other
465 # variables from HOST_SH.
468 setmakeenv HOST_SH
"${HOST_SH}"
469 setmakeenv BSHELL
"${HOST_SH}"
470 setmakeenv CONFIG_SHELL
"${HOST_SH}"
476 # Some systems have a small ARG_MAX. -X prevents make(1) from
477 # exporting variables in the environment redundantly.
480 Darwin | FreeBSD | CYGWIN
*)
481 MAKEFLAGS
="-X ${MAKEFLAGS}"
485 # do_{operation}=true if given operation is requested.
494 do_distribution
=false
497 do_releasekernel
=false
499 do_installmodules
=false
505 do_iso_image_source
=false
507 do_install_image
=false
511 # done_{operation}=true if given operation has been done.
513 done_rebuildmake
=false
515 # Create scratch directory
517 tmpdir
="${TMPDIR-/tmp}/nbbuild$$"
518 mkdir
"${tmpdir}" || bomb
"Cannot mkdir: ${tmpdir}"
519 trap "cd /; rm -r -f \"${tmpdir}\"" 0
520 results
="${tmpdir}/build.sh.results"
522 # Set source directories
524 setmakeenv NETBSDSRCDIR
"${TOP}"
526 # Make sure KERNOBJDIR is an absolute path if defined
528 case "${KERNOBJDIR}" in
530 *) KERNOBJDIR
="${TOP}/${KERNOBJDIR}"
531 setmakeenv KERNOBJDIR
"${KERNOBJDIR}"
535 # Find the version of NetBSD
537 DISTRIBVER
="$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh)"
539 # Set the BUILDSEED to NetBSD-"N"
541 setmakeenv BUILDSEED
"MINIX-$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh -m)"
543 # Set MKARZERO to "yes"
545 setmakeenv MKARZERO
"no"
551 # Translate some MACHINE name aliases (known only to build.sh)
552 # into proper MACHINE and MACHINE_ARCH names. Save the alias
553 # name in makewrappermachine.
558 makewrappermachine
=${MACHINE}
559 # MACHINE_ARCH is "arm" or "armeb", not "armel"
560 MACHINE_ARCH
=arm
${MACHINE##*-}
561 MACHINE_ARCH
=${MACHINE_ARCH%el}
562 MACHINE
=${MACHINE%-e[bl]}
565 evbmips-e
[bl
]|sbmips-e
[bl
])
566 makewrappermachine
=${MACHINE}
567 MACHINE_ARCH
=mips
${MACHINE##*-}
568 MACHINE
=${MACHINE%-e[bl]}
571 evbmips64-e
[bl
]|sbmips64-e
[bl
])
572 makewrappermachine
=${MACHINE}
573 MACHINE_ARCH
=mips64
${MACHINE##*-}
574 MACHINE
=${MACHINE%64-e[bl]}
578 makewrappermachine
=${MACHINE}
579 MACHINE_ARCH
=sh3
${MACHINE##*-}
580 MACHINE
=${MACHINE%-e[bl]}
585 # Translate a MACHINE into a default MACHINE_ARCH.
589 acorn26|acorn32|cats|hpcarm|iyonix|netwinder|shark|zaurus
)
593 evbarm
) # unspecified MACHINE_ARCH gets LE
594 MACHINE_ARCH
=${MACHINE_ARCH:=arm}
605 amiga|atari|cesfic|hp300|luna68k|mac68k|mvme68k|news68k|next68k|sun3|x68k
)
609 evbmips|sbmips
) # no default MACHINE_ARCH
613 makewrappermachine
=${MACHINE}
614 MACHINE
=${MACHINE%64}
615 MACHINE_ARCH
=mips64eb
618 ews4800mips|mipsco|newsmips|sgimips|emips
)
622 algor64|arc64|cobalt64|pmax64
)
623 makewrappermachine
=${MACHINE}
624 MACHINE
=${MACHINE%64}
625 MACHINE_ARCH
=mips64el
628 algor|arc|cobalt|hpcmips|pmax
)
632 evbppc64|macppc64|ofppc64
)
633 makewrappermachine
=${MACHINE}
634 MACHINE
=${MACHINE%64}
635 MACHINE_ARCH
=powerpc64
638 amigappc|bebox|evbppc|ibmnws|macppc|mvmeppc|ofppc|prep|rs6000|sandpoint
)
642 evbsh3
) # no default MACHINE_ARCH
649 dreamcast|hpcsh|landisk
)
657 alpha|i386|sparc|sparc64|vax|ia64
)
658 MACHINE_ARCH
=${MACHINE}
662 bomb
"Unknown target MACHINE: ${MACHINE}"
670 # Ensure that the MACHINE_ARCH exists (and is supported by build.sh).
672 case "${MACHINE_ARCH}" in
674 alpha|arm|armeb|hppa|i386|m68000|m68k|mipse
[bl
]|mips64e
[bl
]|powerpc|powerpc64|sh3e
[bl
]|sparc|sparc64|vax|x86_64|ia64
)
678 bomb
"No MACHINE_ARCH provided"
682 bomb
"Unknown target MACHINE_ARCH: ${MACHINE_ARCH}"
687 # Determine valid MACHINE_ARCHs for MACHINE
695 algor|arc|cobalt|pmax
)
696 arches
="mipsel mips64el"
700 arches
="mipseb mipsel mips64eb mips64el"
704 arches
="mipseb mips64eb"
712 arches
="powerpc powerpc64"
715 oma
="${MACHINE_ARCH}"
717 arches
="${MACHINE_ARCH}"
718 MACHINE_ARCH
="${oma}"
723 # Ensure that MACHINE_ARCH supports MACHINE
726 for a
in ${arches}; do
727 if [ "${a}" = "${MACHINE_ARCH}" ]; then
733 bomb
"MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'"
736 # nobomb_getmakevar --
737 # Given the name of a make variable in $1, print make's idea of the
738 # value of that variable, or return 1 if there's an error.
742 [ -x "${make}" ] ||
return 1
743 "${make}" -m ${TOP}/share
/mk
-s -B -f- _x_
<<EOF || return 1
746 .include <bsd.prog.mk>
747 .include <bsd.kernobj.mk>
752 # Given the name of a make variable in $1, print make's idea of the
753 # value of that variable, or bomb if there's an error.
757 [ -x "${make}" ] || bomb
"bomb_getmakevar $1: ${make} is not executable"
758 nobomb_getmakevar
"$1" || bomb
"bomb_getmakevar $1: ${make} failed"
762 # Given the name of a make variable in $1, print make's idea of the
763 # value of that variable, or print a literal '$' followed by the
764 # variable name if ${make} is not executable. This is intended for use in
765 # messages that need to be readable even if $make hasn't been built,
766 # such as when build.sh is run with the "-n" option.
770 if [ -x "${make}" ]; then
779 eval "$1='$2'; export $1"
780 makeenv
="${makeenv} $1"
786 makeenv
="${makeenv} $1"
789 # Given a variable name in $1, modify the variable in place as follows:
790 # For each space-separated word in the variable, call resolvepath.
795 eval val
=\"\
${${var}}\"
798 for word
in ${val}; do
800 newval
="${newval}${newval:+ }${word}"
802 eval ${var}=\"\
${newval}\"
805 # Given a variable name in $1, modify the variable in place as follows:
806 # Convert possibly-relative path to absolute path by prepending
807 # ${TOP} if necessary. Also delete trailing "/", if any.
812 eval val
=\"\
${${var}}\"
820 val
="${TOP}/${val%/}"
823 eval ${var}=\"\
${val}\"
830 echo "${progname}: $*"
834 Usage: ${progname} [-EhnorUuxy] [-a arch] [-B buildid] [-C cdextras]
835 [-D dest] [-j njob] [-M obj] [-m mach] [-N noisy]
836 [-O obj] [-R release] [-S seed] [-T tools]
837 [-V var=[value]] [-w wrapper] [-X x11src] [-Y extsrcsrc]
841 Build operations (all imply "obj" and "tools"):
842 build Run "make build".
843 distribution Run "make distribution" (includes DESTDIR/etc/ files).
844 release Run "make release" (includes kernels & distrib media).
847 help Show this message and exit.
848 makewrapper Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make.
850 cleandir Run "make cleandir". [Default unless -u is used]
851 obj Run "make obj". [Default unless -o is used]
852 tools Build and install tools.
853 install=idir Run "make installworld" to \`idir' to install all sets
854 except \`etc'. Useful after "distribution" or "release"
855 kernel=conf Build kernel with config file \`conf'
856 releasekernel=conf Install kernel built by kernel=conf to RELEASEDIR.
857 installmodules=idir Run "make installmodules" to \`idir' to install all
859 modules Build kernel modules.
860 rumptest Do a linktest for rump (for developers).
861 sets Create binary sets in
862 RELEASEDIR/RELEASEMACHINEDIR/binary/sets.
863 DESTDIR should be populated beforehand.
864 sourcesets Create source sets in RELEASEDIR/source/sets.
865 syspkgs Create syspkgs in
866 RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.
867 iso-image Create CD-ROM image in RELEASEDIR/iso.
868 iso-image-source Create CD-ROM image with source in RELEASEDIR/iso.
869 live-image Create bootable live image in
870 RELEASEDIR/RELEASEMACHINEDIR/installation/liveimage.
871 install-image Create bootable installation image in
872 RELEASEDIR/RELEASEMACHINEDIR/installation/installimage.
873 params Display various make(1) parameters.
876 -a arch Set MACHINE_ARCH to arch. [Default: deduced from MACHINE]
877 -B buildid Set BUILDID to buildid.
878 -C cdextras Append cdextras to CDEXTRA variable for inclusion on CD-ROM.
879 -D dest Set DESTDIR to dest. [Default: destdir.MACHINE]
880 -E Set "expert" mode; disables various safety checks.
881 Should not be used without expert knowledge of the build system.
882 -h Print this help message.
883 -j njob Run up to njob jobs in parallel; see make(1) -j.
884 -M obj Set obj root directory to obj; sets MAKEOBJDIRPREFIX.
886 -m mach Set MACHINE to mach; not required if NetBSD native.
887 -N noisy Set the noisyness (MAKEVERBOSE) level of the build:
888 0 Minimal output ("quiet")
889 1 Describe what is occurring
890 2 Describe what is occurring and echo the actual command
891 3 Ignore the effect of the "@" prefix in make commands
892 4 Trace shell commands using the shell's -x flag
894 -n Show commands that would be executed, but do not execute them.
895 -O obj Set obj root directory to obj; sets a MAKEOBJDIR pattern.
896 Unsets MAKEOBJDIRPREFIX.
897 -o Set MKOBJDIRS=no; do not create objdirs at start of build.
898 -R release Set RELEASEDIR to release. [Default: releasedir]
899 -r Remove contents of TOOLDIR and DESTDIR before building.
900 -S seed Set BUILDSEED to seed. [Default: NetBSD-majorversion]
901 -T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in
902 the environment, ${toolprefix}make will be (re)built
904 -U Set MKUNPRIVED=yes; build without requiring root privileges,
905 install from an UNPRIVED build with proper file permissions.
906 -u Set MKUPDATE=yes; do not run "make cleandir" first.
907 Without this, everything is rebuilt, including the tools.
908 -V var=[value] Set variable \`var' to \`value'.
909 -w wrapper Create ${toolprefix}make script as wrapper.
910 [Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE}]
911 -X x11src Set X11SRCDIR to x11src. [Default: /usr/xsrc]
912 -x Set MKX11=yes; build X11 from X11SRCDIR
913 -Y extsrcsrc Set EXTSRCSRCDIR to extsrcsrc. [Default: /usr/extsrc]
914 -y Set MKEXTSRC=yes; build extsrc from EXTSRCSRCDIR
915 -Z var Unset ("zap") variable \`var'.
923 opts
='a:B:C:D:Ehj:M:m:N:nO:oR:rS:T:UuV:w:X:xY:yZ:'
926 if type getopts >/dev
/null
2>&1; then
929 getoptcmd
='getopts ${opts} opt && opt=-${opt}'
931 optremcmd
='shift $((${OPTIND} -1))'
933 type getopt
>/dev
/null
2>&1 ||
934 bomb
"Shell does not support getopts or getopt"
936 # Use old-style getopt(1) (doesn't handle whitespace in args).
938 args
="$(getopt ${opts} $*)"
942 getoptcmd
='[ $# -gt 0 ] && opt="$1" && shift'
943 optargcmd
='OPTARG="$1"; shift'
947 # Parse command line options.
949 while eval ${getoptcmd}; do
954 MACHINE_ARCH
=${OPTARG}
964 eval ${optargcmd}; resolvepaths OPTARG
965 CDEXTRA
="${CDEXTRA}${CDEXTRA:+ }${OPTARG}"
969 eval ${optargcmd}; resolvepath OPTARG
970 setmakeenv DESTDIR
"${OPTARG}"
979 parallel
="-j ${OPTARG}"
983 eval ${optargcmd}; resolvepath OPTARG
985 \$
*) usage
"-M argument must not begin with '\$'"
987 *\$
*) # can use resolvepath, but can't set TOP_objdir
990 *) resolvepath OPTARG
991 TOP_objdir
="${OPTARG}${TOP}"
994 unsetmakeenv MAKEOBJDIR
995 setmakeenv MAKEOBJDIRPREFIX
"${OPTARG}"
998 # -m overrides MACHINE_ARCH unless "-a" is specified
1002 [ "${opt_a}" != "yes" ] && getarch
1009 setmakeenv MAKEVERBOSE
"${OPTARG}"
1012 usage
"'${OPTARG}' is not a valid value for -N"
1024 *\$
*) usage
"-O argument must not contain '\$'"
1026 *) resolvepath OPTARG
1027 TOP_objdir
="${OPTARG}"
1030 unsetmakeenv MAKEOBJDIRPREFIX
1031 setmakeenv MAKEOBJDIR
"\${.CURDIR:C,^$TOP,$OPTARG,}"
1039 eval ${optargcmd}; resolvepath OPTARG
1040 setmakeenv RELEASEDIR
"${OPTARG}"
1050 setmakeenv BUILDSEED
"${OPTARG}"
1054 eval ${optargcmd}; resolvepath OPTARG
1060 setmakeenv MKUNPRIVED
yes
1064 setmakeenv MKUPDATE
yes
1070 # XXX: consider restricting which variables can be changed?
1071 [a-zA-Z_
][a-zA-Z_0-9
]*=*)
1072 setmakeenv
"${OPTARG%%=*}" "${OPTARG#*=}"
1075 usage
"-V argument must be of the form 'var=[value]'"
1081 eval ${optargcmd}; resolvepath OPTARG
1082 makewrapper
="${OPTARG}"
1086 eval ${optargcmd}; resolvepath OPTARG
1087 setmakeenv X11SRCDIR
"${OPTARG}"
1091 setmakeenv MKX11
yes
1095 eval ${optargcmd}; resolvepath OPTARG
1096 setmakeenv EXTSRCSRCDIR
"${OPTARG}"
1100 setmakeenv MKEXTSRC
yes
1105 # XXX: consider restricting which variables can be unset?
1106 unsetmakeenv
"${OPTARG}"
1120 # Validate operations.
1123 while [ $# -gt 0 ]; do
1125 operations
="${operations} ${op}"
1133 makewrapper|cleandir|obj|tools|build|distribution|release|sets|sourcesets|syspkgs|params
)
1137 op
=iso_image
# used as part of a variable name
1141 op
=iso_image_source
# used as part of a variable name
1145 op
=live_image
# used as part of a variable name
1149 op
=install_image
# used as part of a variable name
1152 kernel
=*|releasekernel
=*)
1156 bomb
"Must supply a kernel name with \`${op}=...'"
1163 install=*|installmodules
=*)
1167 bomb
"Must supply a directory with \`install=...'"
1175 usage
"Unknown operation \`${op}'"
1181 [ -n "${operations}" ] || usage
"Missing operation to perform."
1183 # Set up MACHINE*. On a NetBSD host, these are allowed to be unset.
1185 if [ -z "${MACHINE}" ]; then
1186 [ "${uname_s}" = "Minix" ] ||
1187 bomb
"MACHINE must be set, or -m must be used, for cross builds."
1190 [ -n "${MACHINE_ARCH}" ] || getarch
1193 # Set up default make(1) environment.
1195 makeenv
="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
1196 [ -z "${BUILDID}" ] || makeenv
="${makeenv} BUILDID"
1197 MAKEFLAGS
="-de -m ${TOP}/share/mk ${MAKEFLAGS}"
1198 MAKEFLAGS
="${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}"
1200 export MAKEFLAGS MACHINE MACHINE_ARCH BUILDSH
1204 # Sanity check after parsing command line options, before rebuildmake.
1208 # If the PATH contains any non-absolute components (including,
1209 # but not limited to, "." or ""), then complain. As an exception,
1210 # allow "" or "." as the last component of the PATH. This is fatal
1211 # if expert mode is not in effect.
1213 local path
="${PATH}"
1214 path
="${path%:}" # delete trailing ":"
1215 path
="${path%:.}" # delete trailing ":."
1216 case ":${path}:/" in
1218 if ${do_expertmode}; then
1219 warning
"PATH contains non-absolute components"
1221 bomb
"PATH environment variable must not" \
1222 "contain non-absolute components"
1228 # print_tooldir_make --
1229 # Try to find and print a path to an existing
1230 # ${TOOLDIR}/bin/${toolprefix}make, for use by rebuildmake() before a
1231 # new version of ${toolprefix}make has been built.
1233 # * If TOOLDIR was set in the environment or on the command line, use
1235 # * Otherwise try to guess what TOOLDIR would be if not overridden by
1236 # /etc/mk.conf, and check whether the resulting directory contains
1237 # a copy of ${toolprefix}make (this should work for everybody who
1238 # doesn't override TOOLDIR via /etc/mk.conf);
1239 # * Failing that, search for ${toolprefix}make, nbmake, bmake, or make,
1240 # in the PATH (this might accidentally find a version of make that
1241 # does not understand the syntax used by NetBSD make, and that will
1242 # lead to failure in the next step);
1243 # * If a copy of make was found above, try to use it with
1244 # nobomb_getmakevar to find the correct value for TOOLDIR, and believe the
1245 # result only if it's a directory that already exists;
1246 # * If a value of TOOLDIR was found above, and if
1247 # ${TOOLDIR}/bin/${toolprefix}make exists, print that value.
1249 print_tooldir_make
()
1251 local possible_TOP_OBJ
1252 local possible_TOOLDIR
1256 if [ -n "${TOOLDIR}" ]; then
1257 echo "${TOOLDIR}/bin/${toolprefix}make"
1261 # Set host_ostype to something like "NetBSD-4.5.6-i386". This
1262 # is intended to match the HOST_OSTYPE variable in <bsd.own.mk>.
1264 local host_ostype
="${uname_s}-$(
1265 echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
1267 echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
1270 # Look in a few potential locations for
1271 # ${possible_TOOLDIR}/bin/${toolprefix}make.
1272 # If we find it, then set possible_make.
1274 # In the usual case (without interference from environment
1275 # variables or /etc/mk.conf), <bsd.own.mk> should set TOOLDIR to
1276 # "${_SRC_TOP_OBJ_}/tooldir.${host_ostype}".
1278 # In practice it's difficult to figure out the correct value
1279 # for _SRC_TOP_OBJ_. In the easiest case, when the -M or -O
1280 # options were passed to build.sh, then ${TOP_objdir} will be
1281 # the correct value. We also try a few other possibilities, but
1282 # we do not replicate all the logic of <bsd.obj.mk>.
1284 for possible_TOP_OBJ
in \
1286 "${MAKEOBJDIRPREFIX:+${MAKEOBJDIRPREFIX}${TOP}}" \
1289 "${TOP}/obj.${MACHINE}"
1291 [ -n "${possible_TOP_OBJ}" ] ||
continue
1292 possible_TOOLDIR
="${possible_TOP_OBJ}/tooldir.${host_ostype}"
1293 possible_make
="${possible_TOOLDIR}/bin/${toolprefix}make"
1294 if [ -x "${possible_make}" ]; then
1301 # If the above didn't work, search the PATH for a suitable
1302 # ${toolprefix}make, nbmake, bmake, or make.
1304 : ${possible_make:=$(find_in_PATH ${toolprefix}make '')}
1305 : ${possible_make:=$(find_in_PATH nbmake '')}
1306 : ${possible_make:=$(find_in_PATH bmake '')}
1307 : ${possible_make:=$(find_in_PATH make '')}
1309 # At this point, we don't care whether possible_make is in the
1310 # correct TOOLDIR or not; we simply want it to be usable by
1311 # getmakevar to help us find the correct TOOLDIR.
1313 # Use ${possible_make} with nobomb_getmakevar to try to find
1314 # the value of TOOLDIR. Believe the result only if it's
1315 # a directory that already exists and contains bin/${toolprefix}make.
1317 if [ -x "${possible_make}" ]; then
1318 possible_TOOLDIR
="$(
1319 make="${possible_make}" \
1320 nobomb_getmakevar TOOLDIR 2>/dev/null
1322 if [ $?
= 0 ] && [ -n "${possible_TOOLDIR}" ] \
1323 && [ -d "${possible_TOOLDIR}" ];
1325 tooldir_make
="${possible_TOOLDIR}/bin/${toolprefix}make"
1326 if [ -x "${tooldir_make}" ]; then
1327 echo "${tooldir_make}"
1336 # Rebuild nbmake in a temporary directory if necessary. Sets $make
1337 # to a path to the nbmake executable. Sets done_rebuildmake=true
1338 # if nbmake was rebuilt.
1340 # There is a cyclic dependency between building nbmake and choosing
1341 # TOOLDIR: TOOLDIR may be affected by settings in /etc/mk.conf, so we
1342 # would like to use getmakevar to get the value of TOOLDIR; but we can't
1343 # use getmakevar before we have an up to date version of nbmake; we
1344 # might already have an up to date version of nbmake in TOOLDIR, but we
1345 # don't yet know where TOOLDIR is.
1347 # The default value of TOOLDIR also depends on the location of the top
1348 # level object directory, so $(getmakevar TOOLDIR) invoked before or
1349 # after making the top level object directory may produce different
1352 # Strictly speaking, we should do the following:
1354 # 1. build a new version of nbmake in a temporary directory;
1355 # 2. use the temporary nbmake to create the top level obj directory;
1356 # 3. use $(getmakevar TOOLDIR) with the temporary nbmake to
1357 # get the corect value of TOOLDIR;
1358 # 4. move the temporary nbmake to ${TOOLDIR}/bin/nbmake.
1360 # However, people don't like building nbmake unnecessarily if their
1361 # TOOLDIR has not changed since an earlier build. We try to avoid
1362 # rebuilding a temporary version of nbmake by taking some shortcuts to
1363 # guess a value for TOOLDIR, looking for an existing version of nbmake
1364 # in that TOOLDIR, and checking whether that nbmake is newer than the
1365 # sources used to build it.
1369 make="$(print_tooldir_make)"
1370 if [ -n "${make}" ] && [ -x "${make}" ]; then
1371 for f
in usr.bin
/make
/*.
[ch
] usr.bin
/make
/lst.lib
/*.
[ch
]; do
1372 if [ "${f}" -nt "${make}" ]; then
1373 statusmsg
"${make} outdated" \
1374 "(older than ${f}), needs building."
1380 statusmsg
"No \$TOOLDIR/bin/${toolprefix}make, needs building."
1384 # Build bootstrap ${toolprefix}make if needed.
1385 if ${do_rebuildmake}; then
1386 statusmsg
"Bootstrapping ${toolprefix}make"
1387 ${runcmd} cd "${tmpdir}"
1388 ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
1389 CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
1390 ${HOST_SH} "${TOP}/tools
/make
/configure
" ||
1391 bomb "Configure of
${toolprefix}make failed
"
1392 ${runcmd} ${HOST_SH} buildmake.sh ||
1393 bomb "Build of
${toolprefix}make failed
"
1394 make="${tmpdir}/${toolprefix}make"
1395 ${runcmd} cd "${TOP}"
1396 ${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
1397 done_rebuildmake=true
1401 # validatemakeparams --
1402 # Perform some late sanity checks, after rebuildmake,
1403 # but before createmakewrapper or any real work.
1405 # Also create the top-level obj directory.
1407 validatemakeparams()
1409 if [ "${runcmd}" = "echo" ]; then
1410 TOOLCHAIN_MISSING=no
1411 EXTERNAL_TOOLCHAIN=""
1413 TOOLCHAIN_MISSING=$(bomb_getmakevar TOOLCHAIN_MISSING)
1414 EXTERNAL_TOOLCHAIN=$(bomb_getmakevar EXTERNAL_TOOLCHAIN)
1416 if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
1417 [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
1418 ${runcmd} echo "ERROR
: build.sh
(in-tree cross-toolchain
) is not yet available
for"
1419 ${runcmd} echo " MACHINE
: ${MACHINE}"
1420 ${runcmd} echo " MACHINE_ARCH
: ${MACHINE_ARCH}"
1422 ${runcmd} echo "All builds
for this platform should be
done via a traditional
make"
1423 ${runcmd} echo "If you wish to use an external cross-toolchain
, set"
1424 ${runcmd} echo " EXTERNAL_TOOLCHAIN
=<path to toolchain root
>"
1425 ${runcmd} echo "in either the environment or mk.conf and rerun
"
1426 ${runcmd} echo " ${progname} $
*"
1430 # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE
1431 # These may be set as build.sh options or in "mk.conf
".
1432 # Don't export them as they're only used for tests in build.sh.
1434 MKOBJDIRS=$(getmakevar MKOBJDIRS)
1435 MKUNPRIVED=$(getmakevar MKUNPRIVED)
1436 MKUPDATE=$(getmakevar MKUPDATE)
1438 if [ "${MKOBJDIRS}" != "no
" ]; then
1439 # Create the top-level object directory.
1441 # "make obj NOSUBDIR
=" can handle most cases, but it
1442 # can't handle the case where MAKEOBJDIRPREFIX is set
1443 # while the corresponding directory does not exist
1444 # (rules in <bsd.obj.mk> would abort the build). We
1445 # therefore have to handle the MAKEOBJDIRPREFIX case
1446 # without invoking "make obj
". The MAKEOBJDIR case
1447 # could be handled either way, but we choose to handle
1448 # it similarly to MAKEOBJDIRPREFIX.
1450 if [ -n "${TOP_obj}" ]; then
1451 # It must have been set by the "-M" or "-O"
1452 # command line options, so there's no need to
1455 elif [ -n "$MAKEOBJDIRPREFIX" ]; then
1456 TOP_obj="$
(getmakevar MAKEOBJDIRPREFIX
)${TOP}"
1457 elif [ -n "$MAKEOBJDIR" ]; then
1458 TOP_obj="$
(getmakevar MAKEOBJDIR
)"
1460 if [ -n "$TOP_obj" ]; then
1461 ${runcmd} mkdir -p "${TOP_obj}" ||
1462 bomb "Can
't create top level object directory" \
1465 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1466 bomb "Can't create top level object directory
" \
1470 # make obj in tools to ensure that the objdir for "tools
"
1474 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1475 bomb "Failed to
make obj
in tools
"
1476 ${runcmd} cd "${TOP}"
1479 # Find TOOLDIR, DESTDIR, and RELEASEDIR, according to getmakevar,
1480 # and bomb if they have changed from the values we had from the
1481 # command line or environment.
1483 # This must be done after creating the top-level object directory.
1485 for var in TOOLDIR DESTDIR RELEASEDIR
1487 eval oldval=\"\$${var}\"
1488 newval="$
(getmakevar
$var)"
1489 if ! $do_expertmode; then
1490 : ${_SRC_TOP_OBJ_:=$(getmakevar _SRC_TOP_OBJ_)}
1493 : ${newval:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}}
1494 makeenv="${makeenv} DESTDIR
"
1497 : ${newval:=${_SRC_TOP_OBJ_}/releasedir}
1498 makeenv="${makeenv} RELEASEDIR
"
1502 if [ -n "$oldval" ] && [ "$oldval" != "$newval" ]; then
1503 bomb "Value of
${var} has changed
" \
1504 "(was
\"${oldval}\", now
\"${newval}\")"
1506 eval ${var}=\"\${newval}\"
1508 statusmsg2 "${var} path
:" "${newval}"
1511 # RELEASEMACHINEDIR is just a subdir name, e.g. "i386
".
1512 RELEASEMACHINEDIR=$(getmakevar RELEASEMACHINEDIR)
1514 # Check validity of TOOLDIR and DESTDIR.
1516 if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then
1517 bomb "TOOLDIR
'${TOOLDIR}' invalid
"
1519 removedirs="${TOOLDIR}"
1521 if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then
1522 if ${do_build} || ${do_distribution} || ${do_release}; then
1523 if ! ${do_build} || \
1524 [ "${uname_s}" != "NetBSD
" ] || \
1525 [ "${uname_m}" != "${MACHINE}" ]; then
1526 bomb "DESTDIR must
!= / for cross builds
, or
${progname} 'distribution' or
'release'.
"
1528 if ! ${do_expertmode}; then
1529 bomb "DESTDIR must
!= / for non
-E (expert
) builds
"
1531 statusmsg "WARNING
: Building to
/, in expert mode.
"
1532 statusmsg " This may cause your system to
break! Reasons include
:"
1533 statusmsg " - your kernel is not up to
date"
1534 statusmsg " - the libraries or toolchain have changed
"
1535 statusmsg " YOU HAVE BEEN WARNED
!"
1538 removedirs="${removedirs} ${DESTDIR}"
1540 if ${do_build} || ${do_distribution} || ${do_release}; then
1541 if ! ${do_expertmode} && \
1542 [ "$id_u" -ne 0 ] && \
1543 [ "${MKUNPRIVED}" = "no
" ] ; then
1544 bomb "-U or
-E must be
set for build as an unprivileged user.
"
1547 if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then
1548 bomb "Must
set RELEASEDIR with \
`releasekernel=...'"
1551 # Install as non-root is a bad idea.
1553 if ${do_install} && [ "$id_u" -ne 0 ] ; then
1554 if ${do_expertmode}; then
1555 warning "Will install as an unprivileged user."
1557 bomb "-E must be set for install as an unprivileged user."
1561 # If a previous build.sh run used -U (and therefore created a
1562 # METALOG file), then most subsequent build.sh runs must also
1563 # use -U. If DESTDIR is about to be removed, then don't perform
1566 case "${do_removedirs} ${removedirs} " in
1567 true*" ${DESTDIR} "*)
1568 # DESTDIR is about to be removed
1571 if ( ${do_build} || ${do_distribution} || ${do_release} || \
1572 ${do_install} ) && \
1573 [ -e "${DESTDIR}/METALOG" ] && \
1574 [ "${MKUNPRIVED}" = "no" ] ; then
1575 if $do_expertmode; then
1576 warning "A previous build.sh run specified -U."
1578 bomb "A previous build.sh run specified -U; you must specify it again now."
1584 # live-image and install-image targets require binary sets
1585 # (actually DESTDIR/etc/mtree/set.* files) built with MKUNPRIVED.
1586 # If release operation is specified with live-image or install-image,
1587 # the release op should be performed with -U for later image ops.
1589 if ${do_release} && ( ${do_live_image} || ${do_install_image} ) && \
1590 [ "${MKUNPRIVED}" = "no" ] ; then
1591 bomb "-U must be specified on building release to create images later."
1598 # Remove the target directories.
1600 if ${do_removedirs}; then
1601 for f in ${removedirs}; do
1602 statusmsg "Removing ${f}"
1603 ${runcmd} rm -r -f "${f}"
1607 # Recreate $TOOLDIR.
1609 ${runcmd} mkdir -p "${TOOLDIR}/bin" ||
1610 bomb "mkdir of '${TOOLDIR}/bin' failed"
1612 # If we did not previously rebuild ${toolprefix}make, then
1613 # check whether $make is still valid and the same as the output
1614 # from print_tooldir_make. If not, then rebuild make now. A
1615 # possible reason for this being necessary is that the actual
1616 # value of TOOLDIR might be different from the value guessed
1617 # before the top level obj dir was created.
1619 if ! ${done_rebuildmake} && \
1620 ( [ ! -x "$make" ] || [ "$make" != "$(print_tooldir_make)" ] )
1625 # Install ${toolprefix}make if it was built.
1627 if ${done_rebuildmake}; then
1628 ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make"
1629 ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" ||
1630 bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make"
1631 make="${TOOLDIR}/bin/${toolprefix}make"
1632 statusmsg "Created ${make}"
1635 # Build a ${toolprefix}make wrapper script, usable by hand as
1636 # well as by build.sh.
1638 if [ -z "${makewrapper}" ]; then
1639 makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}"
1640 [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}"
1643 ${runcmd} rm -f "${makewrapper}"
1644 if [ "${runcmd}" = "echo" ]; then
1645 echo 'cat <<EOF >'${makewrapper}
1648 makewrapout=">>\${makewrapper}"
1651 case "${KSH_VERSION:-${SH_VERSION}}" in
1652 *PD\ KSH*|*MIRBSD\ KSH*)
1657 eval cat <<EOF ${makewrapout}
1659 # Set proper variables to allow easy "make" building of a NetBSD subtree.
1660 # Generated from: \$NetBSD: build.sh,v 1.254 2012/02/26 20:32:40 tsutsui Exp $
1661 # with these arguments: ${_args}
1666 for f in ${makeenv}; do
1667 if eval "[ -z \"\${$f}\" -a \"\${${f}-X}\" = \"X\" ]"; then
1668 eval echo "unset ${f}"
1670 eval echo "${f}=\'\$$(echo ${f})\'\;\ export\ ${f}"
1675 MAKEWRAPPERMACHINE=${makewrappermachine:-${MACHINE}}; export MAKEWRAPPERMACHINE
1676 USETOOLS=yes; export USETOOLS
1677 MKINSTALLBOOT=no; export MKINSTALLBOOT
1679 } | eval sort -u "${makewrapout}"
1680 eval cat <<EOF "${makewrapout}"
1682 exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
1684 [ "${runcmd}" = "echo" ] && echo EOF
1685 ${runcmd} chmod +x "${makewrapper}"
1686 statusmsg2 "Updated makewrapper:" "${makewrapper}"
1693 ${runcmd} cd "${dir}" ||
1694 bomb "Failed to cd to \"${dir}\""
1695 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1696 bomb "Failed to make ${op} in \"${dir}\""
1697 ${runcmd} cd "${TOP}" ||
1698 bomb "Failed to cd back to \"${TOP}\""
1703 # if [ "${MKOBJDIRS}" != "no" ]; then
1704 # ${runcmd} "${makewrapper}" ${parallel} obj-tools ||
1705 # bomb "Failed to make obj-tools"
1707 if [ "${MKUPDATE}" = "no" ]; then
1708 make_in_dir tools cleandir
1710 make_in_dir tools dependall
1711 make_in_dir tools install
1712 statusmsg "Tools built to ${TOOLDIR}"
1718 if [ "${MKOBJDIRS}" != "no" ]; then
1719 # The correct value of KERNOBJDIR might
1720 # depend on a prior "make obj" in
1721 # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
1723 KERNSRCDIR="$(getmakevar KERNSRCDIR)"
1724 KERNARCHDIR="$(getmakevar KERNARCHDIR)"
1725 make_in_dir "${KERNSRCDIR}/${KERNARCHDIR}/compile" obj
1727 KERNCONFDIR="$(getmakevar KERNCONFDIR)"
1728 KERNOBJDIR="$(getmakevar KERNOBJDIR)"
1729 case "${kernelconf}" in
1731 kernelconfpath="${kernelconf}"
1732 kernelconfname="${kernelconf##*/}"
1735 kernelconfpath="${KERNCONFDIR}/${kernelconf}"
1736 kernelconfname="${kernelconf}"
1739 kernelbuildpath="${KERNOBJDIR}/${kernelconfname}"
1744 if ! ${do_tools} && ! ${buildkernelwarned:-false}; then
1745 # Building tools every time we build a kernel is clearly
1746 # unnecessary. We could try to figure out whether rebuilding
1747 # the tools is necessary this time, but it doesn't seem worth
1748 # the trouble. Instead, we say it's the user's responsibility
1749 # to rebuild the tools if necessary.
1751 statusmsg "Building kernel without building new tools"
1752 buildkernelwarned=true
1755 statusmsg2 "Building kernel:" "${kernelconf}"
1756 statusmsg2 "Build directory:" "${kernelbuildpath}"
1757 ${runcmd} mkdir -p "${kernelbuildpath}" ||
1758 bomb "Cannot mkdir: ${kernelbuildpath}"
1759 if [ "${MKUPDATE}" = "no" ]; then
1760 make_in_dir "${kernelbuildpath}" cleandir
1762 [ -x "${TOOLDIR}/bin/${toolprefix}config" ] \
1763 || bomb "${TOOLDIR}/bin/${toolprefix}config does not exist. You need to \"$0 tools\" first."
1764 ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" -b "${kernelbuildpath}" \
1765 -s "${TOP}/sys" "${kernelconfpath}" ||
1766 bomb "${toolprefix}config failed for ${kernelconf}"
1767 make_in_dir "${kernelbuildpath}" depend
1768 make_in_dir "${kernelbuildpath}" all
1770 if [ "${runcmd}" != "echo" ]; then
1771 statusmsg "Kernels built from ${kernelconf}:"
1772 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1773 for kern in ${kernlist:-netbsd}; do
1774 [ -f "${kernelbuildpath}/${kern}" ] && \
1775 echo " ${kernelbuildpath}/${kern}"
1776 done | tee -a "${results}"
1783 kernelreldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel"
1784 ${runcmd} mkdir -p "${kernelreldir}"
1785 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1786 for kern in ${kernlist:-netbsd}; do
1787 builtkern="${kernelbuildpath}/${kern}"
1788 [ -f "${builtkern}" ] || continue
1789 releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz"
1790 statusmsg2 "Kernel copy:" "${releasekern}"
1791 if [ "${runcmd}" = "echo" ]; then
1792 echo "gzip -c -9 < ${builtkern} > ${releasekern}"
1794 gzip -c -9 < "${builtkern}" > "${releasekern}"
1801 setmakeenv MKBINUTILS no
1802 if ! ${do_tools} && ! ${buildmoduleswarned:-false}; then
1803 # Building tools every time we build modules is clearly
1804 # unnecessary as well as a kernel.
1806 statusmsg "Building modules without building new tools"
1807 buildmoduleswarned=true
1810 statusmsg "Building kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
1811 if [ "${MKOBJDIRS}" != "no" ]; then
1812 make_in_dir sys/modules obj ||
1813 bomb "Failed to make obj in sys/modules"
1815 if [ "${MKUPDATE}" = "no" ]; then
1816 make_in_dir sys/modules cleandir
1818 ${runcmd} "${makewrapper}" ${parallel} do-sys-modules ||
1819 bomb "Failed to make do-sys-modules"
1821 statusmsg "Successful build of kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
1827 ${runcmd} "${makewrapper}" INSTALLMODULESDIR="${dir}" installmodules ||
1828 bomb "Failed to make installmodules to ${dir}"
1829 statusmsg "Successful installmodules to ${dir}"
1835 ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld ||
1836 bomb "Failed to make installworld to ${dir}"
1837 statusmsg "Successful installworld to ${dir}"
1840 # Run rump build&link tests.
1842 # To make this feasible for running without having to install includes and
1843 # libraries into destdir (i.e. quick), we only run ld. This is possible
1844 # since the rump kernel is a closed namespace apart from calls to rumpuser.
1845 # Therefore, if ld complains only about rumpuser symbols, rump kernel
1846 # linking was successful.
1848 # We test that rump links with a number of component configurations.
1849 # These attempt to mimic what is encountered in the full build.
1850 # See list below. The list should probably be either autogenerated
1851 # or managed elsewhere; keep it here until a better idea arises.
1853 # Above all, note that THIS IS NOT A SUBSTITUTE FOR A FULL BUILD.
1859 -lrumpvfs -lrumpdev -lrump,
1861 -lrumpkern_tty -lrumpvfs -lrump,
1862 -lrumpfs_tmpfs -lrumpvfs -lrump,
1863 -lrumpfs_ffs -lrumpfs_msdos -lrumpvfs -lrumpdev_disk -lrumpdev -lrump,
1864 -lrumpnet_virtif -lrumpnet_netinet -lrumpnet_net -lrumpnet -lrump,
1865 -lrumpnet_sockin -lrumpfs_smbfs -lrumpdev_netsmb
1866 -lrumpkern_crypto -lrumpdev -lrumpnet -lrumpvfs -lrump,
1867 -lrumpnet_sockin -lrumpfs_nfs -lrumpnet -lrumpvfs -lrump,
1868 -lrumpdev_cgd -lrumpdev_raidframe -lrumpdev_disk -lrumpdev_rnd
1869 -lrumpdev_dm -lrumpdev -lrumpvfs -lrumpkern_crypto -lrump'
1875 # we cannot link libs without building csu, and that leads to lossage
1876 [ "${1}" != "rumptest" ] && bomb 'build.sh rump not yet functional. ' \
1877 'did you mean "rumptest"?'
1879 # create obj and distrib dirs
1880 if [ "${MKOBJDIRS}" != "no" ]; then
1881 make_in_dir "${NETBSDSRCDIR}/etc/mtree" obj
1882 make_in_dir "${NETBSDSRCDIR}/sys/rump" obj
1884 ${runcmd} "${makewrapper}" ${parallel} do-distrib-dirs \
1885 || bomb 'could not create distrib-dirs'
1887 [ "${MKUPDATE}" = "no" ] && doclean="cleandir"
1888 targlist="${doclean} ${doobjs} dependall install"
1889 # optimize: for test we build only static libs (3x test speedup)
1890 if [ "${1}" = "rumptest" ] ; then
1892 setmakeenv NOPROFILE 1
1894 for cmd in ${targlist} ; do
1895 make_in_dir "${NETBSDSRCDIR}/sys/rump" ${cmd}
1898 # if we just wanted to build & install rump, we're done
1899 [ "${1}" != "rumptest" ] && return
1901 ${runcmd} cd "${NETBSDSRCDIR}/sys/rump/librump/rumpkern" \
1902 || bomb "cd to rumpkern failed"
1903 md_quirks=`${runcmd} "${makewrapper}" -V '${_SYMQUIRK}'`
1904 # one little, two little, three little backslashes ...
1905 md_quirks="$(echo ${md_quirks} | sed 's
,\\,\\\\,g
'";s/'//g
" )"
1906 ${runcmd} cd "${TOP}" || bomb "cd to ${TOP} failed
"
1907 tool_ld=`${runcmd} "${makewrapper}" -V '${LD}'`
1911 for set in ${RUMP_LIBSETS} ; do
1913 ${runcmd} ${tool_ld} -nostdlib -L${DESTDIR}/usr/lib \
1914 -static --whole-archive ${set} 2>&1 -o /tmp/rumptest.$$ | \
1915 awk -v quirks="${md_quirks}" '
1916 /undefined reference/ &&
1917 !/more undefined references.*follow/{
1919 "`(rumpuser_|__" quirks ")") == 0)
1922 /cannot find -l/{fails[NR] = $0}
1923 /cannot open output file/{fails[NR] = $0}
1929 [ $? -ne 0 ] && bomb "Testlink of rump failed: ${set}"
1931 statusmsg "Rump build&link tests successful"
1943 statusmsg2 "${progname} command:" "$0 $*"
1944 statusmsg2 "${progname} started:" "${build_start}"
1945 statusmsg2 "MINIX version:" "${DISTRIBVER}"
1946 statusmsg2 "MACHINE:" "${MACHINE}"
1947 statusmsg2 "MACHINE_ARCH:" "${MACHINE_ARCH}"
1948 statusmsg2 "Build platform:" "${uname_s} ${uname_r} ${uname_m}"
1949 statusmsg2 "HOST_SH:" "${HOST_SH}"
1955 # Perform the operations.
1957 for op in ${operations}; do
1969 statusmsg "Building sets from pre-populated ${DESTDIR}"
1970 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1971 bomb "Failed to make ${op}"
1972 setdir=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
1973 statusmsg "Built sets to ${setdir}"
1976 cleandir|obj|build|distribution|release|sourcesets|syspkgs|params)
1977 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1978 bomb "Failed to make ${op}"
1979 statusmsg "Successful make ${op}"
1982 iso-image|iso-image-source)
1983 ${runcmd} "${makewrapper}" ${parallel} \
1984 CDEXTRA="$CDEXTRA" ${op} ||
1985 bomb "Failed to make ${op}"
1986 statusmsg "Successful make ${op}"
1989 live-image|install-image)
1990 # install-image and live-image require mtree spec files
1991 # built with UNPRIVED. Assume UNPRIVED build has been
1992 # performed if METALOG file is created in DESTDIR.
1993 if [ ! -e "${DESTDIR}/METALOG" ] ; then
1994 bomb "The release binaries must have been built with -U to create images."
1996 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1997 bomb "Failed to make ${op}"
1998 statusmsg "Successful make ${op}"
2002 buildkernel "${arg}"
2007 releasekernel "${arg}"
2016 if [ "${arg}" = "/" ] && \
2017 ( [ "${uname_s}" != "NetBSD" ] || \
2018 [ "${uname_m}" != "${MACHINE}" ] ); then
2019 bomb "'${op}' must != / for cross builds."
2021 installmodules "${arg}"
2026 if [ "${arg}" = "/" ] && \
2027 ( [ "${uname_s}" != "NetBSD" ] || \
2028 [ "${uname_m}" != "${MACHINE}" ] ); then
2029 bomb "'${op}' must != / for cross builds."
2031 installworld "${arg}"
2039 bomb "Unknown operation \`${op}'"
2045 statusmsg2 "${progname} ended:" "$(date)"
2046 if [ -s "${results}" ]; then
2047 echo "===> Summary of results:"
2048 sed -e 's
/^
===>//;s
/^
/ /' "${results}"