filesystems: return ENOSYS for REQ_PEEK
[minix3.git] / build.sh
blobbded6a7f76771fb420f018b05b86e7c1e4ae5262
1 #! /usr/bin/env sh
2 # $NetBSD: build.sh,v 1.256 2012/09/29 04:02:42 tsutsui Exp $
4 # Copyright (c) 2001-2011 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, 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
50 # other than $1.
51 case "$1" in
52 "--shelltest")
53 shelltest=true
54 re_exec_allowed=false
55 shift
57 "--no-re-exec")
58 re_exec_allowed=false
59 shift
61 esac
63 # Solaris /bin/sh, and other SVR4 shells, do not support "!".
64 # This is the first feature that we test, because subsequent
65 # tests use "!".
67 if test -z "$errmsg"; then
68 if ( eval '! false' ) >/dev/null 2>&1 ; then
70 else
71 errmsg='Shell does not support "!".'
75 # Does the shell support functions?
77 if test -z "$errmsg"; then
78 if ! (
79 eval 'somefunction() { : ; }'
80 ) >/dev/null 2>&1
81 then
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
95 if ! (
96 eval 'f() { local v=2; }; v=1; f && test x"$v" = x"1"'
97 ) >/dev/null 2>&1
98 then
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
109 if ! (
110 eval 'var=a/b/c ;
111 test x"${var#*/};${var##*/};${var%/*};${var%%/*}" = \
112 x"b/c;c;a/b;a" ;'
113 ) >/dev/null 2>&1
114 then
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
124 if ! (
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"'
127 ) >/dev/null 2>&1
128 then
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
138 if ! (
139 eval 'set -- "a a a" "b b b"; set -- ${1+"$@"};
140 test x"$#;$1;$2" = x"2;a a a;b b b";'
141 ) >/dev/null 2>&1
142 then
143 errmsg='Shell does not support ${1+"$@"}.'
147 # Does the shell support $(...) command substitution?
149 if test -z "$errmsg"; then
150 if ! (
151 eval 'var=$(echo abc); test x"$var" = x"abc"'
152 ) >/dev/null 2>&1
153 then
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
165 if ! (
166 eval 'var=$(case x in x) echo abc;; esac); test x"$var" = x"abc"'
167 ) >/dev/null 2>&1
168 then
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
178 if ! (
179 eval 'type getopts || type getopt'
180 ) >/dev/null 2>&1
181 then
182 errmsg='Shell does not support getopts or getopt.'
187 # If shelltest is true, exit now, reporting whether or not the shell is good.
189 if $shelltest; then
190 if test -n "$errmsg"; then
191 echo >&2 "$0: $errmsg"
192 exit 1
193 else
194 exit 0
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
206 for othershell in \
207 "${HOST_SH}" /usr/xpg4/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
217 then
218 cat <<EOF
219 $0: $errmsg
220 $0: Retrying under $othershell
222 HOST_SH="$othershell"
223 export HOST_SH
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
229 done
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.
236 cat <<EOF
237 $0: $errmsg
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
252 export HOST_SH
253 \${HOST_SH} $0 ...
255 exit 1
259 # }}} End shell feature tests.
262 progname=${0##*/}
263 toppid=$$
264 results=/dev/null
265 tab=' '
266 trap "exit 1" 1 2 3 15
268 bomb()
270 cat >&2 <<ERRORMESSAGE
272 ERROR: $@
273 *** BUILD ABORTED ***
274 ERRORMESSAGE
275 kill ${toppid} # in case we were invoked from a subshell
276 exit 1
280 statusmsg()
282 ${runcmd} echo "===> $@" | tee -a "${results}"
285 statusmsg2()
287 local msg
289 msg="${1}"
290 shift
291 case "${msg}" in
292 ????????????????*) ;;
293 ??????????*) msg="${msg} ";;
294 ?????*) msg="${msg} ";;
295 *) msg="${msg} ";;
296 esac
297 case "${msg}" in
298 ?????????????????????*) ;;
299 ????????????????????) msg="${msg} ";;
300 ???????????????????) msg="${msg} ";;
301 ??????????????????) msg="${msg} ";;
302 ?????????????????) msg="${msg} ";;
303 ????????????????) msg="${msg} ";;
304 esac
305 statusmsg "${msg}$*"
308 warning()
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.
316 find_in_PATH()
318 local prog="$1"
319 local result="${2-"$1"}"
320 local oldIFS="${IFS}"
321 local dir
322 IFS=":"
323 for dir in ${PATH}; do
324 if [ -x "${dir}/${prog}" ]; then
325 result="${dir}/${prog}"
326 break
328 done
329 IFS="${oldIFS}"
330 echo "${result}"
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.
335 set_HOST_SH()
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/xpg4/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.
369 case "${HOST_SH}" in
370 /*) :
372 */*) HOST_SH="${PWD}/${HOST_SH}"
374 *) HOST_SH="$(find_in_PATH "${HOST_SH}")"
376 esac
378 # If we don't have an absolute path by now, bomb.
380 case "${HOST_SH}" in
381 /*) :
383 *) bomb "HOST_SH=\"${HOST_SH}\" is not an absolute path."
385 esac
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."
400 # initdefaults --
401 # Set defaults before parsing command line options.
403 initdefaults()
405 makeenv=
406 makewrapper=
407 makewrappermachine=
408 runcmd=
409 operations=
410 removedirs=
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.
428 unsetmakeenv INFODIR
429 unsetmakeenv LESSCHARSET
430 unsetmakeenv MAKEFLAGS
431 setmakeenv LC_ALL C
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")
447 case "${uname_p}" in
448 ''|unknown|*[^-_A-Za-z0-9]*) uname_p="${uname_m}" ;;
449 esac
451 id_u=$(id -u 2>/dev/null || /usr/xpg4/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.
460 unset PWD
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.
467 set_HOST_SH
468 setmakeenv HOST_SH "${HOST_SH}"
469 setmakeenv BSHELL "${HOST_SH}"
470 setmakeenv CONFIG_SHELL "${HOST_SH}"
472 # Set defaults.
474 toolprefix=nb
476 # Some systems have a small ARG_MAX. -X prevents make(1) from
477 # exporting variables in the environment redundantly.
479 case "${uname_s}" in
480 Darwin | FreeBSD | CYGWIN*)
481 MAKEFLAGS="-X ${MAKEFLAGS}"
483 esac
485 # do_{operation}=true if given operation is requested.
487 do_expertmode=false
488 do_rebuildmake=false
489 do_removedirs=false
490 do_tools=false
491 do_cleandir=false
492 do_obj=false
493 do_build=false
494 do_distribution=false
495 do_release=false
496 do_kernel=false
497 do_releasekernel=false
498 do_modules=false
499 do_installmodules=false
500 do_install=false
501 do_sets=false
502 do_sourcesets=false
503 do_syspkgs=false
504 do_iso_image=false
505 do_iso_image_source=false
506 do_live_image=false
507 do_install_image=false
508 do_params=false
509 do_rump=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
529 ''|/*) ;;
530 *) KERNOBJDIR="${TOP}/${KERNOBJDIR}"
531 setmakeenv KERNOBJDIR "${KERNOBJDIR}"
533 esac
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 "yes"
549 getarch()
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.
555 case "${MACHINE}" in
557 evbearm-e[bl])
558 makewrappermachine=${MACHINE}
559 # MACHINE_ARCH is "arm" or "armeb", not "armel"
560 MACHINE_ARCH=earm${MACHINE##*-}
561 MACHINE_ARCH=${MACHINE_ARCH%el}
562 MACHINE=evbarm
565 evbarm-e[bl])
566 makewrappermachine=${MACHINE}
567 # MACHINE_ARCH is "arm" or "armeb", not "armel"
568 MACHINE_ARCH=arm${MACHINE##*-}
569 MACHINE_ARCH=${MACHINE_ARCH%el}
570 MACHINE=${MACHINE%-e[bl]}
573 evbmips-e[bl]|sbmips-e[bl])
574 makewrappermachine=${MACHINE}
575 MACHINE_ARCH=mips${MACHINE##*-}
576 MACHINE=${MACHINE%-e[bl]}
579 evbmips64-e[bl]|sbmips64-e[bl])
580 makewrappermachine=${MACHINE}
581 MACHINE_ARCH=mips64${MACHINE##*-}
582 MACHINE=${MACHINE%64-e[bl]}
585 evbsh3-e[bl])
586 makewrappermachine=${MACHINE}
587 MACHINE_ARCH=sh3${MACHINE##*-}
588 MACHINE=${MACHINE%-e[bl]}
591 esac
593 # Translate a MACHINE into a default MACHINE_ARCH.
595 case "${MACHINE}" in
597 acorn26|acorn32|cats|hpcarm|iyonix|netwinder|shark|zaurus)
598 MACHINE_ARCH=arm
601 evbarm) # unspecified MACHINE_ARCH gets LE
602 MACHINE_ARCH=${MACHINE_ARCH:=arm}
605 hp700)
606 MACHINE_ARCH=hppa
609 sun2)
610 MACHINE_ARCH=m68000
613 amiga|atari|cesfic|hp300|luna68k|mac68k|mvme68k|news68k|next68k|sun3|x68k)
614 MACHINE_ARCH=m68k
617 evbmips|sbmips) # no default MACHINE_ARCH
620 sgimips64)
621 makewrappermachine=${MACHINE}
622 MACHINE=${MACHINE%64}
623 MACHINE_ARCH=mips64eb
626 ews4800mips|mipsco|newsmips|sgimips|emips)
627 MACHINE_ARCH=mipseb
630 algor64|arc64|cobalt64|pmax64)
631 makewrappermachine=${MACHINE}
632 MACHINE=${MACHINE%64}
633 MACHINE_ARCH=mips64el
636 algor|arc|cobalt|hpcmips|pmax)
637 MACHINE_ARCH=mipsel
640 evbppc64|macppc64|ofppc64)
641 makewrappermachine=${MACHINE}
642 MACHINE=${MACHINE%64}
643 MACHINE_ARCH=powerpc64
646 amigappc|bebox|evbppc|ibmnws|macppc|mvmeppc|ofppc|prep|rs6000|sandpoint)
647 MACHINE_ARCH=powerpc
650 evbsh3) # no default MACHINE_ARCH
653 mmeye)
654 MACHINE_ARCH=sh3eb
657 dreamcast|hpcsh|landisk)
658 MACHINE_ARCH=sh3el
661 amd64)
662 MACHINE_ARCH=x86_64
665 alpha|i386|sparc|sparc64|vax|ia64)
666 MACHINE_ARCH=${MACHINE}
669 i[4-6]86)
670 # LSC FIXME: This is required as uname -m reports the actual machine.
671 # We will be able to remove this once our triple has been cleaned up
672 # (at this time we compile only for i386, and use an incorrect host triple)
673 MACHINE=i386
674 MACHINE_ARCH=i386
678 bomb "Unknown target MACHINE: ${MACHINE}"
681 esac
684 validatearch()
686 # Ensure that the MACHINE_ARCH exists (and is supported by build.sh).
688 case "${MACHINE_ARCH}" in
690 alpha|arm|armeb|earm|earmeb|hppa|i386|m68000|m68k|mipse[bl]|mips64e[bl]|powerpc|powerpc64|sh3e[bl]|sparc|sparc64|vax|x86_64|ia64)
694 bomb "No MACHINE_ARCH provided"
698 bomb "Unknown target MACHINE_ARCH: ${MACHINE_ARCH}"
701 esac
703 # Determine valid MACHINE_ARCHs for MACHINE
705 case "${MACHINE}" in
707 evbarm)
708 arches="arm armeb earm earmeb"
711 cats|iyonix|netwinder|shark|zaurus)
712 arches="arm earm"
715 algor|arc|cobalt|pmax)
716 arches="mipsel mips64el"
719 evbmips|sbmips)
720 arches="mipseb mipsel mips64eb mips64el"
723 sgimips)
724 arches="mipseb mips64eb"
727 evbsh3)
728 arches="sh3eb sh3el"
731 macppc|evbppc|ofppc)
732 arches="powerpc powerpc64"
735 oma="${MACHINE_ARCH}"
736 getarch
737 arches="${MACHINE_ARCH}"
738 MACHINE_ARCH="${oma}"
741 esac
743 # Ensure that MACHINE_ARCH supports MACHINE
745 archok=false
746 for a in ${arches}; do
747 if [ "${a}" = "${MACHINE_ARCH}" ]; then
748 archok=true
749 break
751 done
752 ${archok} ||
753 bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'"
756 # nobomb_getmakevar --
757 # Given the name of a make variable in $1, print make's idea of the
758 # value of that variable, or return 1 if there's an error.
760 nobomb_getmakevar()
762 [ -x "${make}" ] || return 1
763 "${make}" -m ${TOP}/share/mk -s -B -f- _x_ <<EOF || return 1
764 _x_:
765 echo \${$1}
766 # LSC FIXME: We are cross compiling, so overwrite default and build tools
767 USETOOLS:=yes
768 .include <bsd.prog.mk>
769 .include <bsd.kernobj.mk>
773 # bomb_getmakevar --
774 # Given the name of a make variable in $1, print make's idea of the
775 # value of that variable, or bomb if there's an error.
777 bomb_getmakevar()
779 [ -x "${make}" ] || bomb "bomb_getmakevar $1: ${make} is not executable"
780 nobomb_getmakevar "$1" || bomb "bomb_getmakevar $1: ${make} failed"
783 # getmakevar --
784 # Given the name of a make variable in $1, print make's idea of the
785 # value of that variable, or print a literal '$' followed by the
786 # variable name if ${make} is not executable. This is intended for use in
787 # messages that need to be readable even if $make hasn't been built,
788 # such as when build.sh is run with the "-n" option.
790 getmakevar()
792 if [ -x "${make}" ]; then
793 bomb_getmakevar "$1"
794 else
795 echo "\$$1"
799 setmakeenv()
801 eval "$1='$2'; export $1"
802 makeenv="${makeenv} $1"
805 unsetmakeenv()
807 eval "unset $1"
808 makeenv="${makeenv} $1"
811 # Given a variable name in $1, modify the variable in place as follows:
812 # For each space-separated word in the variable, call resolvepath.
813 resolvepaths()
815 local var="$1"
816 local val
817 eval val=\"\${${var}}\"
818 local newval=''
819 local word
820 for word in ${val}; do
821 resolvepath word
822 newval="${newval}${newval:+ }${word}"
823 done
824 eval ${var}=\"\${newval}\"
827 # Given a variable name in $1, modify the variable in place as follows:
828 # Convert possibly-relative path to absolute path by prepending
829 # ${TOP} if necessary. Also delete trailing "/", if any.
830 resolvepath()
832 local var="$1"
833 local val
834 eval val=\"\${${var}}\"
835 case "${val}" in
839 val="${val%/}"
842 val="${TOP}/${val%/}"
844 esac
845 eval ${var}=\"\${val}\"
848 usage()
850 if [ -n "$*" ]; then
851 echo ""
852 echo "${progname}: $*"
854 cat <<_usage_
856 Usage: ${progname} [-EhnorUuxy] [-a arch] [-B buildid] [-C cdextras]
857 [-D dest] [-j njob] [-M obj] [-m mach] [-N noisy]
858 [-O obj] [-R release] [-S seed] [-T tools]
859 [-V var=[value]] [-w wrapper] [-X x11src] [-Y extsrcsrc]
860 [-Z var]
861 operation [...]
863 Build operations (all imply "obj" and "tools"):
864 build Run "make build".
865 distribution Run "make distribution" (includes DESTDIR/etc/ files).
866 release Run "make release" (includes kernels & distrib media).
868 Other operations:
869 help Show this message and exit.
870 makewrapper Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make.
871 Always performed.
872 cleandir Run "make cleandir". [Default unless -u is used]
873 obj Run "make obj". [Default unless -o is used]
874 tools Build and install tools.
875 install=idir Run "make installworld" to \`idir' to install all sets
876 except \`etc'. Useful after "distribution" or "release"
877 kernel=conf Build kernel with config file \`conf'
878 releasekernel=conf Install kernel built by kernel=conf to RELEASEDIR.
879 installmodules=idir Run "make installmodules" to \`idir' to install all
880 kernel modules.
881 modules Build kernel modules.
882 rumptest Do a linktest for rump (for developers).
883 sets Create binary sets in
884 RELEASEDIR/RELEASEMACHINEDIR/binary/sets.
885 DESTDIR should be populated beforehand.
886 sourcesets Create source sets in RELEASEDIR/source/sets.
887 syspkgs Create syspkgs in
888 RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.
889 iso-image Create CD-ROM image in RELEASEDIR/iso.
890 iso-image-source Create CD-ROM image with source in RELEASEDIR/iso.
891 live-image Create bootable live image in
892 RELEASEDIR/RELEASEMACHINEDIR/installation/liveimage.
893 install-image Create bootable installation image in
894 RELEASEDIR/RELEASEMACHINEDIR/installation/installimage.
895 params Display various make(1) parameters.
897 Options:
898 -a arch Set MACHINE_ARCH to arch. [Default: deduced from MACHINE]
899 -B buildid Set BUILDID to buildid.
900 -C cdextras Append cdextras to CDEXTRA variable for inclusion on CD-ROM.
901 -D dest Set DESTDIR to dest. [Default: destdir.MACHINE]
902 -E Set "expert" mode; disables various safety checks.
903 Should not be used without expert knowledge of the build system.
904 -h Print this help message.
905 -j njob Run up to njob jobs in parallel; see make(1) -j.
906 -M obj Set obj root directory to obj; sets MAKEOBJDIRPREFIX.
907 Unsets MAKEOBJDIR.
908 -m mach Set MACHINE to mach; not required if NetBSD native.
909 -N noisy Set the noisyness (MAKEVERBOSE) level of the build:
910 0 Minimal output ("quiet")
911 1 Describe what is occurring
912 2 Describe what is occurring and echo the actual command
913 3 Ignore the effect of the "@" prefix in make commands
914 4 Trace shell commands using the shell's -x flag
915 [Default: 2]
916 -n Show commands that would be executed, but do not execute them.
917 -O obj Set obj root directory to obj; sets a MAKEOBJDIR pattern.
918 Unsets MAKEOBJDIRPREFIX.
919 -o Set MKOBJDIRS=no; do not create objdirs at start of build.
920 -R release Set RELEASEDIR to release. [Default: releasedir]
921 -r Remove contents of TOOLDIR and DESTDIR before building.
922 -S seed Set BUILDSEED to seed. [Default: NetBSD-majorversion]
923 -T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in
924 the environment, ${toolprefix}make will be (re)built
925 unconditionally.
926 -U Set MKUNPRIVED=yes; build without requiring root privileges,
927 install from an UNPRIVED build with proper file permissions.
928 -u Set MKUPDATE=yes; do not run "make cleandir" first.
929 Without this, everything is rebuilt, including the tools.
930 -V var=[value] Set variable \`var' to \`value'.
931 -w wrapper Create ${toolprefix}make script as wrapper.
932 [Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE}]
933 -X x11src Set X11SRCDIR to x11src. [Default: /usr/xsrc]
934 -x Set MKX11=yes; build X11 from X11SRCDIR
935 -Y extsrcsrc Set EXTSRCSRCDIR to extsrcsrc. [Default: /usr/extsrc]
936 -y Set MKEXTSRC=yes; build extsrc from EXTSRCSRCDIR
937 -Z var Unset ("zap") variable \`var'.
939 _usage_
940 exit 1
943 parseoptions()
945 opts='a:B:C:D:Ehj:M:m:N:nO:oR:rS:T:UuV:w:X:xY:yZ:'
946 opt_a=no
948 if type getopts >/dev/null 2>&1; then
949 # Use POSIX getopts.
951 getoptcmd='getopts ${opts} opt && opt=-${opt}'
952 optargcmd=':'
953 optremcmd='shift $((${OPTIND} -1))'
954 else
955 type getopt >/dev/null 2>&1 ||
956 bomb "Shell does not support getopts or getopt"
958 # Use old-style getopt(1) (doesn't handle whitespace in args).
960 args="$(getopt ${opts} $*)"
961 [ $? = 0 ] || usage
962 set -- ${args}
964 getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
965 optargcmd='OPTARG="$1"; shift'
966 optremcmd=':'
969 # Parse command line options.
971 while eval ${getoptcmd}; do
972 case ${opt} in
975 eval ${optargcmd}
976 MACHINE_ARCH=${OPTARG}
977 opt_a=yes
981 eval ${optargcmd}
982 BUILDID=${OPTARG}
986 eval ${optargcmd}; resolvepaths OPTARG
987 CDEXTRA="${CDEXTRA}${CDEXTRA:+ }${OPTARG}"
991 eval ${optargcmd}; resolvepath OPTARG
992 setmakeenv DESTDIR "${OPTARG}"
996 do_expertmode=true
1000 eval ${optargcmd}
1001 parallel="-j ${OPTARG}"
1005 eval ${optargcmd}; resolvepath OPTARG
1006 case "${OPTARG}" in
1007 \$*) usage "-M argument must not begin with '\$'"
1009 *\$*) # can use resolvepath, but can't set TOP_objdir
1010 resolvepath OPTARG
1012 *) resolvepath OPTARG
1013 TOP_objdir="${OPTARG}${TOP}"
1015 esac
1016 unsetmakeenv MAKEOBJDIR
1017 setmakeenv MAKEOBJDIRPREFIX "${OPTARG}"
1020 # -m overrides MACHINE_ARCH unless "-a" is specified
1022 eval ${optargcmd}
1023 MACHINE="${OPTARG}"
1024 [ "${opt_a}" != "yes" ] && getarch
1028 eval ${optargcmd}
1029 case "${OPTARG}" in
1030 0|1|2|3|4)
1031 setmakeenv MAKEVERBOSE "${OPTARG}"
1034 usage "'${OPTARG}' is not a valid value for -N"
1036 esac
1040 runcmd=echo
1044 eval ${optargcmd}
1045 case "${OPTARG}" in
1046 *\$*) usage "-O argument must not contain '\$'"
1048 *) resolvepath OPTARG
1049 TOP_objdir="${OPTARG}"
1051 esac
1052 unsetmakeenv MAKEOBJDIRPREFIX
1053 setmakeenv MAKEOBJDIR "\${.CURDIR:C,^$TOP,$OPTARG,}"
1057 MKOBJDIRS=no
1061 eval ${optargcmd}; resolvepath OPTARG
1062 setmakeenv RELEASEDIR "${OPTARG}"
1066 do_removedirs=true
1067 do_rebuildmake=true
1071 eval ${optargcmd}
1072 setmakeenv BUILDSEED "${OPTARG}"
1076 eval ${optargcmd}; resolvepath OPTARG
1077 TOOLDIR="${OPTARG}"
1078 export TOOLDIR
1082 setmakeenv MKUNPRIVED yes
1086 setmakeenv MKUPDATE yes
1090 eval ${optargcmd}
1091 case "${OPTARG}" in
1092 # XXX: consider restricting which variables can be changed?
1093 [a-zA-Z_][a-zA-Z_0-9]*=*)
1094 setmakeenv "${OPTARG%%=*}" "${OPTARG#*=}"
1097 usage "-V argument must be of the form 'var=[value]'"
1099 esac
1103 eval ${optargcmd}; resolvepath OPTARG
1104 makewrapper="${OPTARG}"
1108 eval ${optargcmd}; resolvepath OPTARG
1109 setmakeenv X11SRCDIR "${OPTARG}"
1113 setmakeenv MKX11 yes
1117 eval ${optargcmd}; resolvepath OPTARG
1118 setmakeenv EXTSRCSRCDIR "${OPTARG}"
1122 setmakeenv MKEXTSRC yes
1126 eval ${optargcmd}
1127 # XXX: consider restricting which variables can be unset?
1128 unsetmakeenv "${OPTARG}"
1132 break
1135 -'?'|-h)
1136 usage
1139 esac
1140 done
1142 # Validate operations.
1144 eval ${optremcmd}
1145 while [ $# -gt 0 ]; do
1146 op=$1; shift
1147 operations="${operations} ${op}"
1149 case "${op}" in
1151 help)
1152 usage
1155 makewrapper|cleandir|obj|tools|build|distribution|release|sets|sourcesets|syspkgs|params)
1158 iso-image)
1159 op=iso_image # used as part of a variable name
1162 iso-image-source)
1163 op=iso_image_source # used as part of a variable name
1166 live-image)
1167 op=live_image # used as part of a variable name
1170 install-image)
1171 op=install_image # used as part of a variable name
1174 kernel=*|releasekernel=*)
1175 arg=${op#*=}
1176 op=${op%%=*}
1177 [ -n "${arg}" ] ||
1178 bomb "Must supply a kernel name with \`${op}=...'"
1181 modules)
1182 op=modules
1185 install=*|installmodules=*)
1186 arg=${op#*=}
1187 op=${op%%=*}
1188 [ -n "${arg}" ] ||
1189 bomb "Must supply a directory with \`install=...'"
1192 rump|rumptest)
1193 op=${op}
1197 usage "Unknown operation \`${op}'"
1200 esac
1201 eval do_${op}=true
1202 done
1203 [ -n "${operations}" ] || usage "Missing operation to perform."
1205 # Set up MACHINE*. On a NetBSD host, these are allowed to be unset.
1207 if [ -z "${MACHINE}" ]; then
1208 [ "${uname_s}" = "Minix" ] ||
1209 bomb "MACHINE must be set, or -m must be used, for cross builds."
1210 MACHINE=${uname_m}
1212 [ -n "${MACHINE_ARCH}" ] || getarch
1213 validatearch
1215 # Set up default make(1) environment.
1217 makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
1218 [ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID"
1219 MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS}"
1220 MAKEFLAGS="${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}"
1221 export MAKEFLAGS MACHINE MACHINE_ARCH
1224 # sanitycheck --
1225 # Sanity check after parsing command line options, before rebuildmake.
1227 sanitycheck()
1229 # If the PATH contains any non-absolute components (including,
1230 # but not limited to, "." or ""), then complain. As an exception,
1231 # allow "" or "." as the last component of the PATH. This is fatal
1232 # if expert mode is not in effect.
1234 local path="${PATH}"
1235 path="${path%:}" # delete trailing ":"
1236 path="${path%:.}" # delete trailing ":."
1237 case ":${path}:/" in
1238 *:[!/]*)
1239 if ${do_expertmode}; then
1240 warning "PATH contains non-absolute components"
1241 else
1242 bomb "PATH environment variable must not" \
1243 "contain non-absolute components"
1246 esac
1249 # print_tooldir_make --
1250 # Try to find and print a path to an existing
1251 # ${TOOLDIR}/bin/${toolprefix}make, for use by rebuildmake() before a
1252 # new version of ${toolprefix}make has been built.
1254 # * If TOOLDIR was set in the environment or on the command line, use
1255 # that value.
1256 # * Otherwise try to guess what TOOLDIR would be if not overridden by
1257 # /etc/mk.conf, and check whether the resulting directory contains
1258 # a copy of ${toolprefix}make (this should work for everybody who
1259 # doesn't override TOOLDIR via /etc/mk.conf);
1260 # * Failing that, search for ${toolprefix}make, nbmake, bmake, or make,
1261 # in the PATH (this might accidentally find a version of make that
1262 # does not understand the syntax used by NetBSD make, and that will
1263 # lead to failure in the next step);
1264 # * If a copy of make was found above, try to use it with
1265 # nobomb_getmakevar to find the correct value for TOOLDIR, and believe the
1266 # result only if it's a directory that already exists;
1267 # * If a value of TOOLDIR was found above, and if
1268 # ${TOOLDIR}/bin/${toolprefix}make exists, print that value.
1270 print_tooldir_make()
1272 local possible_TOP_OBJ
1273 local possible_TOOLDIR
1274 local possible_make
1275 local tooldir_make
1277 if [ -n "${TOOLDIR}" ]; then
1278 echo "${TOOLDIR}/bin/${toolprefix}make"
1279 return 0
1282 # Set host_ostype to something like "NetBSD-4.5.6-i386". This
1283 # is intended to match the HOST_OSTYPE variable in <bsd.own.mk>.
1285 local host_ostype="${uname_s}-$(
1286 echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
1287 )-$(
1288 echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
1291 # Look in a few potential locations for
1292 # ${possible_TOOLDIR}/bin/${toolprefix}make.
1293 # If we find it, then set possible_make.
1295 # In the usual case (without interference from environment
1296 # variables or /etc/mk.conf), <bsd.own.mk> should set TOOLDIR to
1297 # "${_SRC_TOP_OBJ_}/tooldir.${host_ostype}".
1299 # In practice it's difficult to figure out the correct value
1300 # for _SRC_TOP_OBJ_. In the easiest case, when the -M or -O
1301 # options were passed to build.sh, then ${TOP_objdir} will be
1302 # the correct value. We also try a few other possibilities, but
1303 # we do not replicate all the logic of <bsd.obj.mk>.
1305 for possible_TOP_OBJ in \
1306 "${TOP_objdir}" \
1307 "${MAKEOBJDIRPREFIX:+${MAKEOBJDIRPREFIX}${TOP}}" \
1308 "${TOP}" \
1309 "${TOP}/obj" \
1310 "${TOP}/obj.${MACHINE}"
1312 [ -n "${possible_TOP_OBJ}" ] || continue
1313 possible_TOOLDIR="${possible_TOP_OBJ}/tooldir.${host_ostype}"
1314 possible_make="${possible_TOOLDIR}/bin/${toolprefix}make"
1315 if [ -x "${possible_make}" ]; then
1316 break
1317 else
1318 unset possible_make
1320 done
1322 # If the above didn't work, search the PATH for a suitable
1323 # ${toolprefix}make, nbmake, bmake, or make.
1325 : ${possible_make:=$(find_in_PATH ${toolprefix}make '')}
1326 : ${possible_make:=$(find_in_PATH nbmake '')}
1327 : ${possible_make:=$(find_in_PATH bmake '')}
1328 : ${possible_make:=$(find_in_PATH make '')}
1330 # At this point, we don't care whether possible_make is in the
1331 # correct TOOLDIR or not; we simply want it to be usable by
1332 # getmakevar to help us find the correct TOOLDIR.
1334 # Use ${possible_make} with nobomb_getmakevar to try to find
1335 # the value of TOOLDIR. Believe the result only if it's
1336 # a directory that already exists and contains bin/${toolprefix}make.
1338 if [ -x "${possible_make}" ]; then
1339 possible_TOOLDIR="$(
1340 make="${possible_make}" \
1341 nobomb_getmakevar TOOLDIR 2>/dev/null
1343 if [ $? = 0 ] && [ -n "${possible_TOOLDIR}" ] \
1344 && [ -d "${possible_TOOLDIR}" ];
1345 then
1346 tooldir_make="${possible_TOOLDIR}/bin/${toolprefix}make"
1347 if [ -x "${tooldir_make}" ]; then
1348 echo "${tooldir_make}"
1349 return 0
1353 return 1
1356 # rebuildmake --
1357 # Rebuild nbmake in a temporary directory if necessary. Sets $make
1358 # to a path to the nbmake executable. Sets done_rebuildmake=true
1359 # if nbmake was rebuilt.
1361 # There is a cyclic dependency between building nbmake and choosing
1362 # TOOLDIR: TOOLDIR may be affected by settings in /etc/mk.conf, so we
1363 # would like to use getmakevar to get the value of TOOLDIR; but we can't
1364 # use getmakevar before we have an up to date version of nbmake; we
1365 # might already have an up to date version of nbmake in TOOLDIR, but we
1366 # don't yet know where TOOLDIR is.
1368 # The default value of TOOLDIR also depends on the location of the top
1369 # level object directory, so $(getmakevar TOOLDIR) invoked before or
1370 # after making the top level object directory may produce different
1371 # results.
1373 # Strictly speaking, we should do the following:
1375 # 1. build a new version of nbmake in a temporary directory;
1376 # 2. use the temporary nbmake to create the top level obj directory;
1377 # 3. use $(getmakevar TOOLDIR) with the temporary nbmake to
1378 # get the corect value of TOOLDIR;
1379 # 4. move the temporary nbmake to ${TOOLDIR}/bin/nbmake.
1381 # However, people don't like building nbmake unnecessarily if their
1382 # TOOLDIR has not changed since an earlier build. We try to avoid
1383 # rebuilding a temporary version of nbmake by taking some shortcuts to
1384 # guess a value for TOOLDIR, looking for an existing version of nbmake
1385 # in that TOOLDIR, and checking whether that nbmake is newer than the
1386 # sources used to build it.
1388 rebuildmake()
1390 make="$(print_tooldir_make)"
1391 if [ -n "${make}" ] && [ -x "${make}" ]; then
1392 for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
1393 if [ "${f}" -nt "${make}" ]; then
1394 statusmsg "${make} outdated" \
1395 "(older than ${f}), needs building."
1396 do_rebuildmake=true
1397 break
1399 done
1400 else
1401 statusmsg "No \$TOOLDIR/bin/${toolprefix}make, needs building."
1402 do_rebuildmake=true
1405 # Build bootstrap ${toolprefix}make if needed.
1406 if ${do_rebuildmake}; then
1407 statusmsg "Bootstrapping ${toolprefix}make"
1408 ${runcmd} cd "${tmpdir}"
1409 ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
1410 CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
1411 ${HOST_SH} "${TOP}/tools/make/configure" ||
1412 bomb "Configure of ${toolprefix}make failed"
1413 ${runcmd} ${HOST_SH} buildmake.sh ||
1414 bomb "Build of ${toolprefix}make failed"
1415 make="${tmpdir}/${toolprefix}make"
1416 ${runcmd} cd "${TOP}"
1417 ${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
1418 done_rebuildmake=true
1422 # validatemakeparams --
1423 # Perform some late sanity checks, after rebuildmake,
1424 # but before createmakewrapper or any real work.
1426 # Also create the top-level obj directory.
1428 validatemakeparams()
1430 if [ "${runcmd}" = "echo" ]; then
1431 TOOLCHAIN_MISSING=no
1432 EXTERNAL_TOOLCHAIN=""
1433 else
1434 TOOLCHAIN_MISSING=$(bomb_getmakevar TOOLCHAIN_MISSING)
1435 EXTERNAL_TOOLCHAIN=$(bomb_getmakevar EXTERNAL_TOOLCHAIN)
1437 if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
1438 [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
1439 ${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
1440 ${runcmd} echo " MACHINE: ${MACHINE}"
1441 ${runcmd} echo " MACHINE_ARCH: ${MACHINE_ARCH}"
1442 ${runcmd} echo ""
1443 ${runcmd} echo "All builds for this platform should be done via a traditional make"
1444 ${runcmd} echo "If you wish to use an external cross-toolchain, set"
1445 ${runcmd} echo " EXTERNAL_TOOLCHAIN=<path to toolchain root>"
1446 ${runcmd} echo "in either the environment or mk.conf and rerun"
1447 ${runcmd} echo " ${progname} $*"
1448 exit 1
1451 # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE
1452 # These may be set as build.sh options or in "mk.conf".
1453 # Don't export them as they're only used for tests in build.sh.
1455 MKOBJDIRS=$(getmakevar MKOBJDIRS)
1456 MKUNPRIVED=$(getmakevar MKUNPRIVED)
1457 MKUPDATE=$(getmakevar MKUPDATE)
1459 if [ "${MKOBJDIRS}" != "no" ]; then
1460 # Create the top-level object directory.
1462 # "make obj NOSUBDIR=" can handle most cases, but it
1463 # can't handle the case where MAKEOBJDIRPREFIX is set
1464 # while the corresponding directory does not exist
1465 # (rules in <bsd.obj.mk> would abort the build). We
1466 # therefore have to handle the MAKEOBJDIRPREFIX case
1467 # without invoking "make obj". The MAKEOBJDIR case
1468 # could be handled either way, but we choose to handle
1469 # it similarly to MAKEOBJDIRPREFIX.
1471 if [ -n "${TOP_obj}" ]; then
1472 # It must have been set by the "-M" or "-O"
1473 # command line options, so there's no need to
1474 # use getmakevar
1476 elif [ -n "$MAKEOBJDIRPREFIX" ]; then
1477 TOP_obj="$(getmakevar MAKEOBJDIRPREFIX)${TOP}"
1478 elif [ -n "$MAKEOBJDIR" ]; then
1479 TOP_obj="$(getmakevar MAKEOBJDIR)"
1481 if [ -n "$TOP_obj" ]; then
1482 ${runcmd} mkdir -p "${TOP_obj}" ||
1483 bomb "Can't create top level object directory" \
1484 "${TOP_obj}"
1485 else
1486 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1487 bomb "Can't create top level object directory" \
1488 "using make obj"
1491 # make obj in tools to ensure that the objdir for "tools"
1492 # is available.
1494 ${runcmd} cd tools
1495 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1496 bomb "Failed to make obj in tools"
1497 ${runcmd} cd "${TOP}"
1500 # Find TOOLDIR, DESTDIR, and RELEASEDIR, according to getmakevar,
1501 # and bomb if they have changed from the values we had from the
1502 # command line or environment.
1504 # This must be done after creating the top-level object directory.
1506 for var in TOOLDIR DESTDIR RELEASEDIR
1508 eval oldval=\"\$${var}\"
1509 newval="$(getmakevar $var)"
1510 if ! $do_expertmode; then
1511 : ${_SRC_TOP_OBJ_:=$(getmakevar _SRC_TOP_OBJ_)}
1512 case "$var" in
1513 DESTDIR)
1514 : ${newval:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}}
1515 makeenv="${makeenv} DESTDIR"
1517 RELEASEDIR)
1518 : ${newval:=${_SRC_TOP_OBJ_}/releasedir}
1519 makeenv="${makeenv} RELEASEDIR"
1521 esac
1523 if [ -n "$oldval" ] && [ "$oldval" != "$newval" ]; then
1524 bomb "Value of ${var} has changed" \
1525 "(was \"${oldval}\", now \"${newval}\")"
1527 eval ${var}=\"\${newval}\"
1528 eval export ${var}
1529 statusmsg2 "${var} path:" "${newval}"
1530 done
1532 # RELEASEMACHINEDIR is just a subdir name, e.g. "i386".
1533 RELEASEMACHINEDIR=$(getmakevar RELEASEMACHINEDIR)
1535 # Check validity of TOOLDIR and DESTDIR.
1537 if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then
1538 bomb "TOOLDIR '${TOOLDIR}' invalid"
1540 removedirs="${TOOLDIR}"
1542 if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then
1543 if ${do_build} || ${do_distribution} || ${do_release}; then
1544 if ! ${do_build} || \
1545 [ "${uname_s}" != "Minix" ] || \
1546 [ "${uname_m}" != "${MACHINE}" ]; then
1547 bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'."
1549 if ! ${do_expertmode}; then
1550 bomb "DESTDIR must != / for non -E (expert) builds"
1552 statusmsg "WARNING: Building to /, in expert mode."
1553 statusmsg " This may cause your system to break! Reasons include:"
1554 statusmsg " - your kernel is not up to date"
1555 statusmsg " - the libraries or toolchain have changed"
1556 statusmsg " YOU HAVE BEEN WARNED!"
1558 else
1559 removedirs="${removedirs} ${DESTDIR}"
1561 if ${do_build} || ${do_distribution} || ${do_release}; then
1562 if ! ${do_expertmode} && \
1563 [ "$id_u" -ne 0 ] && \
1564 [ "${MKUNPRIVED}" = "no" ] ; then
1565 bomb "-U or -E must be set for build as an unprivileged user."
1568 if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then
1569 bomb "Must set RELEASEDIR with \`releasekernel=...'"
1572 # Install as non-root is a bad idea.
1574 if ${do_install} && [ "$id_u" -ne 0 ] ; then
1575 if ${do_expertmode}; then
1576 warning "Will install as an unprivileged user."
1577 else
1578 bomb "-E must be set for install as an unprivileged user."
1582 # If a previous build.sh run used -U (and therefore created a
1583 # METALOG file), then most subsequent build.sh runs must also
1584 # use -U. If DESTDIR is about to be removed, then don't perform
1585 # this check.
1587 case "${do_removedirs} ${removedirs} " in
1588 true*" ${DESTDIR} "*)
1589 # DESTDIR is about to be removed
1592 if ( ${do_build} || ${do_distribution} || ${do_release} || \
1593 ${do_install} ) && \
1594 [ -e "${DESTDIR}/METALOG" ] && \
1595 [ "${MKUNPRIVED}" = "no" ] ; then
1596 if $do_expertmode; then
1597 warning "A previous build.sh run specified -U."
1598 else
1599 bomb "A previous build.sh run specified -U; you must specify it again now."
1603 esac
1605 # live-image and install-image targets require binary sets
1606 # (actually DESTDIR/etc/mtree/set.* files) built with MKUNPRIVED.
1607 # If release operation is specified with live-image or install-image,
1608 # the release op should be performed with -U for later image ops.
1610 if ${do_release} && ( ${do_live_image} || ${do_install_image} ) && \
1611 [ "${MKUNPRIVED}" = "no" ] ; then
1612 bomb "-U must be specified on building release to create images later."
1617 createmakewrapper()
1619 # Remove the target directories.
1621 if ${do_removedirs}; then
1622 for f in ${removedirs}; do
1623 statusmsg "Removing ${f}"
1624 ${runcmd} rm -r -f "${f}"
1625 done
1628 # Recreate $TOOLDIR.
1630 ${runcmd} mkdir -p "${TOOLDIR}/bin" ||
1631 bomb "mkdir of '${TOOLDIR}/bin' failed"
1633 # If we did not previously rebuild ${toolprefix}make, then
1634 # check whether $make is still valid and the same as the output
1635 # from print_tooldir_make. If not, then rebuild make now. A
1636 # possible reason for this being necessary is that the actual
1637 # value of TOOLDIR might be different from the value guessed
1638 # before the top level obj dir was created.
1640 if ! ${done_rebuildmake} && \
1641 ( [ ! -x "$make" ] || [ "$make" != "$(print_tooldir_make)" ] )
1642 then
1643 rebuildmake
1646 # Install ${toolprefix}make if it was built.
1648 if ${done_rebuildmake}; then
1649 ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make"
1650 ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" ||
1651 bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make"
1652 make="${TOOLDIR}/bin/${toolprefix}make"
1653 statusmsg "Created ${make}"
1656 # Build a ${toolprefix}make wrapper script, usable by hand as
1657 # well as by build.sh.
1659 if [ -z "${makewrapper}" ]; then
1660 makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}"
1661 [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}"
1664 ${runcmd} rm -f "${makewrapper}"
1665 if [ "${runcmd}" = "echo" ]; then
1666 echo 'cat <<EOF >'${makewrapper}
1667 makewrapout=
1668 else
1669 makewrapout=">>\${makewrapper}"
1672 case "${KSH_VERSION:-${SH_VERSION}}" in
1673 *PD\ KSH*|*MIRBSD\ KSH*)
1674 set +o braceexpand
1676 esac
1678 eval cat <<EOF ${makewrapout}
1679 #! ${HOST_SH}
1680 # Set proper variables to allow easy "make" building of a NetBSD subtree.
1681 # Generated from: \$NetBSD: build.sh,v 1.256 2012/09/29 04:02:42 tsutsui Exp $
1682 # with these arguments: ${_args}
1687 for f in ${makeenv}; do
1688 if eval "[ -z \"\${$f}\" -a \"\${${f}-X}\" = \"X\" ]"; then
1689 eval echo "unset ${f}"
1690 else
1691 eval echo "${f}=\'\$$(echo ${f})\'\;\ export\ ${f}"
1693 done
1695 eval cat <<EOF
1696 MAKEWRAPPERMACHINE=${makewrappermachine:-${MACHINE}}; export MAKEWRAPPERMACHINE
1697 USETOOLS=yes; export USETOOLS
1698 # LSC We are cross compiling, so do not install to root!
1699 MKINSTALLBOOT=no; export MKINSTALLBOOT
1700 MKGCC=yes; export MKGCC
1702 } | eval sort -u "${makewrapout}"
1703 eval cat <<EOF "${makewrapout}"
1705 exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
1707 [ "${runcmd}" = "echo" ] && echo EOF
1708 ${runcmd} chmod +x "${makewrapper}"
1709 statusmsg2 "Updated makewrapper:" "${makewrapper}"
1712 make_in_dir()
1714 dir="$1"
1715 op="$2"
1716 ${runcmd} cd "${dir}" ||
1717 bomb "Failed to cd to \"${dir}\""
1718 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1719 bomb "Failed to make ${op} in \"${dir}\""
1720 ${runcmd} cd "${TOP}" ||
1721 bomb "Failed to cd back to \"${TOP}\""
1724 buildtools()
1726 if [ "${MKOBJDIRS}" != "no" ]; then
1727 ${runcmd} "${makewrapper}" ${parallel} obj-tools ||
1728 bomb "Failed to make obj-tools"
1730 if [ "${MKUPDATE}" = "no" ]; then
1731 make_in_dir tools cleandir
1733 make_in_dir tools dependall
1734 make_in_dir tools install
1735 statusmsg "Tools built to ${TOOLDIR}"
1738 getkernelconf()
1740 kernelconf="$1"
1741 if [ "${MKOBJDIRS}" != "no" ]; then
1742 # The correct value of KERNOBJDIR might
1743 # depend on a prior "make obj" in
1744 # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
1746 KERNSRCDIR="$(getmakevar KERNSRCDIR)"
1747 KERNARCHDIR="$(getmakevar KERNARCHDIR)"
1748 make_in_dir "${KERNSRCDIR}/${KERNARCHDIR}/compile" obj
1750 KERNCONFDIR="$(getmakevar KERNCONFDIR)"
1751 KERNOBJDIR="$(getmakevar KERNOBJDIR)"
1752 case "${kernelconf}" in
1753 */*)
1754 kernelconfpath="${kernelconf}"
1755 kernelconfname="${kernelconf##*/}"
1758 kernelconfpath="${KERNCONFDIR}/${kernelconf}"
1759 kernelconfname="${kernelconf}"
1761 esac
1762 kernelbuildpath="${KERNOBJDIR}/${kernelconfname}"
1765 buildkernel()
1767 if ! ${do_tools} && ! ${buildkernelwarned:-false}; then
1768 # Building tools every time we build a kernel is clearly
1769 # unnecessary. We could try to figure out whether rebuilding
1770 # the tools is necessary this time, but it doesn't seem worth
1771 # the trouble. Instead, we say it's the user's responsibility
1772 # to rebuild the tools if necessary.
1774 statusmsg "Building kernel without building new tools"
1775 buildkernelwarned=true
1777 getkernelconf $1
1778 statusmsg2 "Building kernel:" "${kernelconf}"
1779 statusmsg2 "Build directory:" "${kernelbuildpath}"
1780 ${runcmd} mkdir -p "${kernelbuildpath}" ||
1781 bomb "Cannot mkdir: ${kernelbuildpath}"
1782 if [ "${MKUPDATE}" = "no" ]; then
1783 make_in_dir "${kernelbuildpath}" cleandir
1785 [ -x "${TOOLDIR}/bin/${toolprefix}config" ] \
1786 || bomb "${TOOLDIR}/bin/${toolprefix}config does not exist. You need to \"$0 tools\" first."
1787 ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" -b "${kernelbuildpath}" \
1788 -s "${TOP}/sys" "${kernelconfpath}" ||
1789 bomb "${toolprefix}config failed for ${kernelconf}"
1790 make_in_dir "${kernelbuildpath}" depend
1791 make_in_dir "${kernelbuildpath}" all
1793 if [ "${runcmd}" != "echo" ]; then
1794 statusmsg "Kernels built from ${kernelconf}:"
1795 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1796 for kern in ${kernlist:-netbsd}; do
1797 [ -f "${kernelbuildpath}/${kern}" ] && \
1798 echo " ${kernelbuildpath}/${kern}"
1799 done | tee -a "${results}"
1803 releasekernel()
1805 getkernelconf $1
1806 kernelreldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel"
1807 ${runcmd} mkdir -p "${kernelreldir}"
1808 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1809 for kern in ${kernlist:-netbsd}; do
1810 builtkern="${kernelbuildpath}/${kern}"
1811 [ -f "${builtkern}" ] || continue
1812 releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz"
1813 statusmsg2 "Kernel copy:" "${releasekern}"
1814 if [ "${runcmd}" = "echo" ]; then
1815 echo "gzip -c -9 < ${builtkern} > ${releasekern}"
1816 else
1817 gzip -c -9 < "${builtkern}" > "${releasekern}"
1819 done
1822 buildmodules()
1824 setmakeenv MKBINUTILS no
1825 if ! ${do_tools} && ! ${buildmoduleswarned:-false}; then
1826 # Building tools every time we build modules is clearly
1827 # unnecessary as well as a kernel.
1829 statusmsg "Building modules without building new tools"
1830 buildmoduleswarned=true
1833 statusmsg "Building kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
1834 if [ "${MKOBJDIRS}" != "no" ]; then
1835 make_in_dir sys/modules obj
1837 if [ "${MKUPDATE}" = "no" ]; then
1838 make_in_dir sys/modules cleandir
1840 make_in_dir sys/modules dependall
1841 make_in_dir sys/modules install
1843 statusmsg "Successful build of kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
1846 installmodules()
1848 dir="$1"
1849 ${runcmd} "${makewrapper}" INSTALLMODULESDIR="${dir}" installmodules ||
1850 bomb "Failed to make installmodules to ${dir}"
1851 statusmsg "Successful installmodules to ${dir}"
1854 installworld()
1856 dir="$1"
1857 ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld ||
1858 bomb "Failed to make installworld to ${dir}"
1859 statusmsg "Successful installworld to ${dir}"
1862 # Run rump build&link tests.
1864 # To make this feasible for running without having to install includes and
1865 # libraries into destdir (i.e. quick), we only run ld. This is possible
1866 # since the rump kernel is a closed namespace apart from calls to rumpuser.
1867 # Therefore, if ld complains only about rumpuser symbols, rump kernel
1868 # linking was successful.
1870 # We test that rump links with a number of component configurations.
1871 # These attempt to mimic what is encountered in the full build.
1872 # See list below. The list should probably be either autogenerated
1873 # or managed elsewhere; keep it here until a better idea arises.
1875 # Above all, note that THIS IS NOT A SUBSTITUTE FOR A FULL BUILD.
1878 RUMP_LIBSETS='
1879 -lrump,
1880 -lrumpvfs -lrump,
1881 -lrumpvfs -lrumpdev -lrump,
1882 -lrumpnet -lrump,
1883 -lrumpkern_tty -lrumpvfs -lrump,
1884 -lrumpfs_tmpfs -lrumpvfs -lrump,
1885 -lrumpfs_ffs -lrumpfs_msdos -lrumpvfs -lrumpdev_disk -lrumpdev -lrump,
1886 -lrumpnet_virtif -lrumpnet_netinet -lrumpnet_net -lrumpnet -lrump,
1887 -lrumpnet_sockin -lrumpfs_smbfs -lrumpdev_netsmb
1888 -lrumpkern_crypto -lrumpdev -lrumpnet -lrumpvfs -lrump,
1889 -lrumpnet_sockin -lrumpfs_nfs -lrumpnet -lrumpvfs -lrump,
1890 -lrumpdev_cgd -lrumpdev_raidframe -lrumpdev_disk -lrumpdev_rnd
1891 -lrumpdev_dm -lrumpdev -lrumpvfs -lrumpkern_crypto -lrump'
1892 dorump()
1894 local doclean=""
1895 local doobjs=""
1897 # we cannot link libs without building csu, and that leads to lossage
1898 [ "${1}" != "rumptest" ] && bomb 'build.sh rump not yet functional. ' \
1899 'did you mean "rumptest"?'
1901 # create obj and distrib dirs
1902 if [ "${MKOBJDIRS}" != "no" ]; then
1903 make_in_dir "${NETBSDSRCDIR}/etc/mtree" obj
1904 make_in_dir "${NETBSDSRCDIR}/sys/rump" obj
1906 ${runcmd} "${makewrapper}" ${parallel} do-distrib-dirs \
1907 || bomb 'could not create distrib-dirs'
1909 [ "${MKUPDATE}" = "no" ] && doclean="cleandir"
1910 targlist="${doclean} ${doobjs} dependall install"
1911 # optimize: for test we build only static libs (3x test speedup)
1912 if [ "${1}" = "rumptest" ] ; then
1913 setmakeenv NOPIC 1
1914 setmakeenv NOPROFILE 1
1916 for cmd in ${targlist} ; do
1917 make_in_dir "${NETBSDSRCDIR}/sys/rump" ${cmd}
1918 done
1920 # if we just wanted to build & install rump, we're done
1921 [ "${1}" != "rumptest" ] && return
1923 ${runcmd} cd "${NETBSDSRCDIR}/sys/rump/librump/rumpkern" \
1924 || bomb "cd to rumpkern failed"
1925 md_quirks=`${runcmd} "${makewrapper}" -V '${_SYMQUIRK}'`
1926 # one little, two little, three little backslashes ...
1927 md_quirks="$(echo ${md_quirks} | sed 's,\\,\\\\,g'";s/'//g" )"
1928 ${runcmd} cd "${TOP}" || bomb "cd to ${TOP} failed"
1929 tool_ld=`${runcmd} "${makewrapper}" -V '${LD}'`
1931 local oIFS="${IFS}"
1932 IFS=","
1933 for set in ${RUMP_LIBSETS} ; do
1934 IFS="${oIFS}"
1935 ${runcmd} ${tool_ld} -nostdlib -L${DESTDIR}/usr/lib \
1936 -static --whole-archive ${set} 2>&1 -o /tmp/rumptest.$$ | \
1937 awk -v quirks="${md_quirks}" '
1938 /undefined reference/ &&
1939 !/more undefined references.*follow/{
1940 if (match($NF,
1941 "`(rumpuser_|__" quirks ")") == 0)
1942 fails[NR] = $0
1944 /cannot find -l/{fails[NR] = $0}
1945 /cannot open output file/{fails[NR] = $0}
1946 END{
1947 for (x in fails)
1948 print fails[x]
1949 exit x!=0
1951 [ $? -ne 0 ] && bomb "Testlink of rump failed: ${set}"
1952 done
1953 statusmsg "Rump build&link tests successful"
1956 main()
1958 initdefaults
1959 _args=$@
1960 parseoptions "$@"
1962 sanitycheck
1964 build_start=$(date)
1965 statusmsg2 "${progname} command:" "$0 $*"
1966 statusmsg2 "${progname} started:" "${build_start}"
1967 statusmsg2 "MINIX version:" "${DISTRIBVER}"
1968 statusmsg2 "MACHINE:" "${MACHINE}"
1969 statusmsg2 "MACHINE_ARCH:" "${MACHINE_ARCH}"
1970 statusmsg2 "Build platform:" "${uname_s} ${uname_r} ${uname_m}"
1971 statusmsg2 "HOST_SH:" "${HOST_SH}"
1973 rebuildmake
1974 validatemakeparams
1975 createmakewrapper
1977 # Perform the operations.
1979 for op in ${operations}; do
1980 case "${op}" in
1982 makewrapper)
1983 # no-op
1986 tools)
1987 buildtools
1990 sets)
1991 statusmsg "Building sets from pre-populated ${DESTDIR}"
1992 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1993 bomb "Failed to make ${op}"
1994 setdir=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
1995 statusmsg "Built sets to ${setdir}"
1998 cleandir|obj|build|distribution|release|sourcesets|syspkgs|params)
1999 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2000 bomb "Failed to make ${op}"
2001 statusmsg "Successful make ${op}"
2004 iso-image|iso-image-source)
2005 ${runcmd} "${makewrapper}" ${parallel} \
2006 CDEXTRA="$CDEXTRA" ${op} ||
2007 bomb "Failed to make ${op}"
2008 statusmsg "Successful make ${op}"
2011 live-image|install-image)
2012 # install-image and live-image require mtree spec files
2013 # built with UNPRIVED. Assume UNPRIVED build has been
2014 # performed if METALOG file is created in DESTDIR.
2015 if [ ! -e "${DESTDIR}/METALOG" ] ; then
2016 bomb "The release binaries must have been built with -U to create images."
2018 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2019 bomb "Failed to make ${op}"
2020 statusmsg "Successful make ${op}"
2022 kernel=*)
2023 arg=${op#*=}
2024 buildkernel "${arg}"
2027 releasekernel=*)
2028 arg=${op#*=}
2029 releasekernel "${arg}"
2032 modules)
2033 buildmodules
2036 installmodules=*)
2037 arg=${op#*=}
2038 if [ "${arg}" = "/" ] && \
2039 ( [ "${uname_s}" != "Minix" ] || \
2040 [ "${uname_m}" != "${MACHINE}" ] ); then
2041 bomb "'${op}' must != / for cross builds."
2043 installmodules "${arg}"
2046 install=*)
2047 arg=${op#*=}
2048 if [ "${arg}" = "/" ] && \
2049 ( [ "${uname_s}" != "Minix" ] || \
2050 [ "${uname_m}" != "${MACHINE}" ] ); then
2051 bomb "'${op}' must != / for cross builds."
2053 installworld "${arg}"
2056 rump|rumptest)
2057 dorump "${op}"
2061 bomb "Unknown operation \`${op}'"
2064 esac
2065 done
2067 statusmsg2 "${progname} ended:" "$(date)"
2068 if [ -s "${results}" ]; then
2069 echo "===> Summary of results:"
2070 sed -e 's/^===>//;s/^/ /' "${results}"
2071 echo "===> ."
2075 main "$@"