2002-09-14 03:27:13 +04:00
|
|
|
#! /usr/bin/env sh
|
2003-02-19 02:59:06 +03:00
|
|
|
# $NetBSD: build.sh,v 1.92 2003/02/18 23:59:06 lukem Exp $
|
2003-01-23 19:24:08 +03:00
|
|
|
#
|
|
|
|
# Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
# by Todd Vierling and Luke Mewburn.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# 3. All advertising materials mentioning features or use of this software
|
|
|
|
# must display the following acknowledgement:
|
|
|
|
# This product includes software developed by the NetBSD
|
|
|
|
# Foundation, Inc. and its contributors.
|
|
|
|
# 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products derived
|
|
|
|
# from this software without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#
|
2001-10-19 06:21:03 +04:00
|
|
|
#
|
|
|
|
# Top level build wrapper, for a system containing no tools.
|
|
|
|
#
|
|
|
|
# This script should run on any POSIX-compliant shell. For systems
|
2001-12-12 00:13:35 +03:00
|
|
|
# with a strange /bin/sh, "ksh" or "bash" may be an ample alternative.
|
2001-10-19 06:21:03 +04:00
|
|
|
#
|
2002-09-14 03:27:13 +04:00
|
|
|
# Note, however, that due to the way the interpreter is invoked above,
|
|
|
|
# if a POSIX-compliant shell is the first in the PATH, you won't have
|
|
|
|
# to take any further action.
|
|
|
|
#
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
progname=${0##*/}
|
Improvements from Alan Barrett (in private email), with minor tweaking:
(Thanks Alan!)
* Before attempting to use KERNOBJDIR, we now need to "make obj" in
${KERNSRCDIR}/${KERNARCHDIR}/compile, not in ${TOP}/etc as used to be
the case.
* Fix one place where getmakevar was invoked unconditionally. It needs
to be conditional on $runcmd != "echo", so that we can rely on the
existence of the new $make executable.
* Add a sanity check to getmakevar, to bomb if a similar error is
introduced in the future.
* Changed the bomb function to print to stderr instead of to stdout, and
to kill the top level shell process. Without this, an attempted bomb
from inside getmakevar did not work properly.
* Moved some duplicated code into a new safe_getmakevar function, which
calls getmakevar if that is safe, or else emits a literal '$' followed
by the variable name.
Improvements from me:
* Always 'trap "exit 1" 1 2 3 15', so the kill in bomb() doesn't cause ugly
output.
2003-01-15 04:49:03 +03:00
|
|
|
toppid=$$
|
2003-01-23 19:24:08 +03:00
|
|
|
trap "exit 1" 1 2 3 15
|
|
|
|
|
2003-01-03 02:11:07 +03:00
|
|
|
bomb()
|
|
|
|
{
|
Improvements from Alan Barrett (in private email), with minor tweaking:
(Thanks Alan!)
* Before attempting to use KERNOBJDIR, we now need to "make obj" in
${KERNSRCDIR}/${KERNARCHDIR}/compile, not in ${TOP}/etc as used to be
the case.
* Fix one place where getmakevar was invoked unconditionally. It needs
to be conditional on $runcmd != "echo", so that we can rely on the
existence of the new $make executable.
* Add a sanity check to getmakevar, to bomb if a similar error is
introduced in the future.
* Changed the bomb function to print to stderr instead of to stdout, and
to kill the top level shell process. Without this, an attempted bomb
from inside getmakevar did not work properly.
* Moved some duplicated code into a new safe_getmakevar function, which
calls getmakevar if that is safe, or else emits a literal '$' followed
by the variable name.
Improvements from me:
* Always 'trap "exit 1" 1 2 3 15', so the kill in bomb() doesn't cause ugly
output.
2003-01-15 04:49:03 +03:00
|
|
|
cat >&2 <<ERRORMESSAGE
|
|
|
|
|
|
|
|
ERROR: $@
|
|
|
|
*** BUILD ABORTED ***
|
|
|
|
ERRORMESSAGE
|
|
|
|
kill $toppid # in case we were invoked from a subshell
|
2001-10-19 06:21:03 +04:00
|
|
|
exit 1
|
|
|
|
}
|
2003-01-02 08:11:12 +03:00
|
|
|
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
initdefaults()
|
|
|
|
{
|
|
|
|
cd "$(dirname $0)"
|
|
|
|
[ -d usr.bin/make ] ||
|
|
|
|
bomb "build.sh must be run from the top source level"
|
|
|
|
[ -f share/mk/bsd.own.mk ] ||
|
|
|
|
bomb "src/share/mk is missing; please re-fetch the source tree"
|
|
|
|
|
|
|
|
uname_s=$(uname -s 2>/dev/null)
|
|
|
|
uname_m=$(uname -m 2>/dev/null)
|
|
|
|
|
|
|
|
# If $PWD is a valid name of the current directory, POSIX mandates
|
|
|
|
# that pwd return it by default which causes problems in the
|
|
|
|
# presence of symlinks. Unsetting PWD is simpler than changing
|
|
|
|
# every occurrence of pwd to use -P.
|
|
|
|
#
|
|
|
|
# XXX Except that doesn't work on Solaris.
|
|
|
|
unset PWD
|
|
|
|
if [ "${uname_s}" = "SunOS" ]; then
|
|
|
|
TOP=$(pwd -P)
|
|
|
|
else
|
|
|
|
TOP=$(pwd)
|
|
|
|
fi
|
2002-12-25 03:42:50 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
# Set defaults.
|
|
|
|
toolprefix=nb
|
|
|
|
MAKEFLAGS=
|
|
|
|
makeenv=
|
|
|
|
makewrapper=
|
|
|
|
runcmd=
|
|
|
|
operations=
|
|
|
|
removedirs=
|
|
|
|
do_expertmode=false
|
|
|
|
do_rebuildmake=false
|
|
|
|
do_removedirs=false
|
|
|
|
|
|
|
|
# do_{operation}=true if given operation is requested.
|
|
|
|
#
|
|
|
|
do_tools=false
|
|
|
|
do_obj=false
|
|
|
|
do_build=false
|
|
|
|
do_distribution=false
|
|
|
|
do_release=false
|
|
|
|
do_kernel=false
|
|
|
|
do_install=false
|
2003-01-26 09:19:12 +03:00
|
|
|
do_sets=false
|
2003-01-23 19:24:08 +03:00
|
|
|
}
|
2001-12-03 11:18:00 +03:00
|
|
|
|
2003-01-03 02:11:07 +03:00
|
|
|
getarch()
|
|
|
|
{
|
2001-10-19 06:21:03 +04:00
|
|
|
# Translate a MACHINE into a default MACHINE_ARCH.
|
2003-01-23 19:24:08 +03:00
|
|
|
#
|
2001-10-19 06:21:03 +04:00
|
|
|
case $MACHINE in
|
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
acorn26|acorn32|cats|netwinder|shark|*arm)
|
|
|
|
MACHINE_ARCH=arm
|
|
|
|
;;
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
sun2)
|
|
|
|
MACHINE_ARCH=m68000
|
|
|
|
;;
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
amiga|atari|cesfic|hp300|sun3|*68k)
|
|
|
|
MACHINE_ARCH=m68k
|
|
|
|
;;
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
mipsco|newsmips|sbmips|sgimips)
|
|
|
|
MACHINE_ARCH=mipseb
|
|
|
|
;;
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
algor|arc|cobalt|evbmips|hpcmips|playstation2|pmax)
|
|
|
|
MACHINE_ARCH=mipsel
|
|
|
|
;;
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
pc532)
|
|
|
|
MACHINE_ARCH=ns32k
|
|
|
|
;;
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
bebox|prep|sandpoint|*ppc)
|
|
|
|
MACHINE_ARCH=powerpc
|
|
|
|
;;
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
evbsh3|mmeye)
|
|
|
|
MACHINE_ARCH=sh3eb
|
|
|
|
;;
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
dreamcast|hpcsh)
|
|
|
|
MACHINE_ARCH=sh3el
|
|
|
|
;;
|
2002-06-10 18:08:05 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
hp700)
|
|
|
|
MACHINE_ARCH=hppa
|
|
|
|
;;
|
|
|
|
|
|
|
|
evbsh5)
|
|
|
|
MACHINE_ARCH=sh5el
|
|
|
|
;;
|
2002-10-02 20:57:29 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
alpha|i386|sparc|sparc64|vax|x86_64)
|
|
|
|
MACHINE_ARCH=$MACHINE
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
bomb "unknown target MACHINE: $MACHINE"
|
|
|
|
;;
|
2001-10-24 06:39:56 +04:00
|
|
|
|
2001-10-19 06:21:03 +04:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2003-01-03 02:11:07 +03:00
|
|
|
validatearch()
|
|
|
|
{
|
2002-03-02 00:06:40 +03:00
|
|
|
# Ensure that the MACHINE_ARCH exists (and is supported by build.sh).
|
2003-01-23 19:24:08 +03:00
|
|
|
#
|
2002-03-02 00:06:40 +03:00
|
|
|
case $MACHINE_ARCH in
|
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
alpha|arm|armeb|hppa|i386|m68000|m68k|mipse[bl]|ns32k|powerpc|sh[35]e[bl]|sparc|sparc64|vax|x86_64)
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
bomb "unknown target MACHINE_ARCH: $MACHINE_ARCH"
|
|
|
|
;;
|
|
|
|
|
2002-03-02 00:06:40 +03:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2003-01-03 02:11:07 +03:00
|
|
|
getmakevar()
|
|
|
|
{
|
Improvements from Alan Barrett (in private email), with minor tweaking:
(Thanks Alan!)
* Before attempting to use KERNOBJDIR, we now need to "make obj" in
${KERNSRCDIR}/${KERNARCHDIR}/compile, not in ${TOP}/etc as used to be
the case.
* Fix one place where getmakevar was invoked unconditionally. It needs
to be conditional on $runcmd != "echo", so that we can rely on the
existence of the new $make executable.
* Add a sanity check to getmakevar, to bomb if a similar error is
introduced in the future.
* Changed the bomb function to print to stderr instead of to stdout, and
to kill the top level shell process. Without this, an attempted bomb
from inside getmakevar did not work properly.
* Moved some duplicated code into a new safe_getmakevar function, which
calls getmakevar if that is safe, or else emits a literal '$' followed
by the variable name.
Improvements from me:
* Always 'trap "exit 1" 1 2 3 15', so the kill in bomb() doesn't cause ugly
output.
2003-01-15 04:49:03 +03:00
|
|
|
[ -x $make ] || bomb "getmakevar $1: $make is not executable"
|
2001-12-04 07:28:23 +03:00
|
|
|
$make -m ${TOP}/share/mk -s -f- _x_ <<EOF
|
Major cleanup and overhaul:
* Allow MACHINE to be set automatically on NetBSD native builds.
Require -m only if the host is not NetBSD.
* Fail if DESTDIR is set to root (/) and the build is not NetBSD native,
or the build is attempting a "make release" (option -R).
* Warn the user if DESTDIR is set to root (/) that the kernel must be up
to date, or else the build might hose the system. Also, do not remove
DESTDIR on -r if it is set to root.
* Fail if TOOLDIR is set to / or empty after checking with nbmake.
* Allow DESTDIR and TOOLDIR to be set in mk.conf and/or by the new default
from <bsd.own.mk>. Note that if -T is not used to set TOOLDIR, and
TOOLDIR is not set in the environment, then nbmake will always be
bootstrapped (rather than looking at nbmake's timestamp). This is
because /bin/sh doesn't know how to get TOOLDIR from mk.conf without
first having nbmake (...which lives in TOOLDIR).
* Do a pass of "make obj" through src/tools before installing nbmake (so
long as -o/MKOBJDIRS=no is not specified). This ensures that objdirs
exist if they are desired, and paves the way for using build.sh to
build all the src/tools without building everything else.
* Add "-w" option, which allows the builder to specify where the nbmake
wrapper shell script should be created. If not specified,
$TOOLDIR/bin/nbmake-$MACHINE is still created as a default.
* Print the values of DESTDIR and TOOLDIR after bootstrapping nbmake,
for informational purposes.
It should now be possible to type just "./build.sh" on a NetBSD-current
host and get a new build in / for the appropriate architecture.
However, building in-place like this has *not* been extensively tested
yet, so be careful.
2001-10-31 22:59:43 +03:00
|
|
|
_x_:
|
|
|
|
echo \${$1}
|
|
|
|
.include <bsd.prog.mk>
|
2002-10-20 19:48:01 +04:00
|
|
|
.include <bsd.kernobj.mk>
|
Major cleanup and overhaul:
* Allow MACHINE to be set automatically on NetBSD native builds.
Require -m only if the host is not NetBSD.
* Fail if DESTDIR is set to root (/) and the build is not NetBSD native,
or the build is attempting a "make release" (option -R).
* Warn the user if DESTDIR is set to root (/) that the kernel must be up
to date, or else the build might hose the system. Also, do not remove
DESTDIR on -r if it is set to root.
* Fail if TOOLDIR is set to / or empty after checking with nbmake.
* Allow DESTDIR and TOOLDIR to be set in mk.conf and/or by the new default
from <bsd.own.mk>. Note that if -T is not used to set TOOLDIR, and
TOOLDIR is not set in the environment, then nbmake will always be
bootstrapped (rather than looking at nbmake's timestamp). This is
because /bin/sh doesn't know how to get TOOLDIR from mk.conf without
first having nbmake (...which lives in TOOLDIR).
* Do a pass of "make obj" through src/tools before installing nbmake (so
long as -o/MKOBJDIRS=no is not specified). This ensures that objdirs
exist if they are desired, and paves the way for using build.sh to
build all the src/tools without building everything else.
* Add "-w" option, which allows the builder to specify where the nbmake
wrapper shell script should be created. If not specified,
$TOOLDIR/bin/nbmake-$MACHINE is still created as a default.
* Print the values of DESTDIR and TOOLDIR after bootstrapping nbmake,
for informational purposes.
It should now be possible to type just "./build.sh" on a NetBSD-current
host and get a new build in / for the appropriate architecture.
However, building in-place like this has *not* been extensively tested
yet, so be careful.
2001-10-31 22:59:43 +03:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
Improvements from Alan Barrett (in private email), with minor tweaking:
(Thanks Alan!)
* Before attempting to use KERNOBJDIR, we now need to "make obj" in
${KERNSRCDIR}/${KERNARCHDIR}/compile, not in ${TOP}/etc as used to be
the case.
* Fix one place where getmakevar was invoked unconditionally. It needs
to be conditional on $runcmd != "echo", so that we can rely on the
existence of the new $make executable.
* Add a sanity check to getmakevar, to bomb if a similar error is
introduced in the future.
* Changed the bomb function to print to stderr instead of to stdout, and
to kill the top level shell process. Without this, an attempted bomb
from inside getmakevar did not work properly.
* Moved some duplicated code into a new safe_getmakevar function, which
calls getmakevar if that is safe, or else emits a literal '$' followed
by the variable name.
Improvements from me:
* Always 'trap "exit 1" 1 2 3 15', so the kill in bomb() doesn't cause ugly
output.
2003-01-15 04:49:03 +03:00
|
|
|
safe_getmakevar()
|
|
|
|
{
|
2003-01-23 19:24:08 +03:00
|
|
|
# getmakevar() doesn't work properly if $make hasn't yet been built,
|
|
|
|
# which can happen when running with the "-n" option.
|
|
|
|
# safe_getmakevar() deals with this by emitting a literal '$'
|
|
|
|
# followed by the variable name, instead of trying to find the
|
|
|
|
# variable's value.
|
|
|
|
#
|
|
|
|
|
Improvements from Alan Barrett (in private email), with minor tweaking:
(Thanks Alan!)
* Before attempting to use KERNOBJDIR, we now need to "make obj" in
${KERNSRCDIR}/${KERNARCHDIR}/compile, not in ${TOP}/etc as used to be
the case.
* Fix one place where getmakevar was invoked unconditionally. It needs
to be conditional on $runcmd != "echo", so that we can rely on the
existence of the new $make executable.
* Add a sanity check to getmakevar, to bomb if a similar error is
introduced in the future.
* Changed the bomb function to print to stderr instead of to stdout, and
to kill the top level shell process. Without this, an attempted bomb
from inside getmakevar did not work properly.
* Moved some duplicated code into a new safe_getmakevar function, which
calls getmakevar if that is safe, or else emits a literal '$' followed
by the variable name.
Improvements from me:
* Always 'trap "exit 1" 1 2 3 15', so the kill in bomb() doesn't cause ugly
output.
2003-01-15 04:49:03 +03:00
|
|
|
if [ -x $make ]; then
|
|
|
|
getmakevar "$1"
|
|
|
|
else
|
|
|
|
echo "\$$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2003-01-03 02:11:07 +03:00
|
|
|
resolvepath()
|
|
|
|
{
|
2001-10-31 01:33:00 +03:00
|
|
|
case $OPTARG in
|
2003-01-23 19:24:08 +03:00
|
|
|
/*)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
OPTARG="$TOP/$OPTARG"
|
|
|
|
;;
|
2001-10-31 01:33:00 +03:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2003-01-03 02:11:07 +03:00
|
|
|
usage()
|
|
|
|
{
|
2003-01-23 19:24:08 +03:00
|
|
|
if [ -n "$*" ]; then
|
|
|
|
echo ""
|
|
|
|
echo "${progname}: $*"
|
|
|
|
fi
|
2002-10-20 19:48:01 +04:00
|
|
|
cat <<_usage_
|
2003-01-23 19:24:08 +03:00
|
|
|
|
|
|
|
Usage: ${progname} [-EnorUu] [-a arch] [-B buildid] [-D dest] [-j njob] [-M obj]
|
|
|
|
[-m mach] [-O obj] [-R release] [-T tools] [-V var=[value]]
|
2003-01-26 08:34:32 +03:00
|
|
|
[-w wrapper] operation [...]
|
2003-01-23 19:24:08 +03:00
|
|
|
|
2003-01-26 08:34:32 +03:00
|
|
|
Build operations (all imply "obj" and "tools"):
|
2003-01-23 19:24:08 +03:00
|
|
|
build Run "make build"
|
2003-01-31 04:38:35 +03:00
|
|
|
distribution Run "make distribution" (includes DESTDIR/etc/ files)
|
2003-01-23 19:24:08 +03:00
|
|
|
release Run "make release" (includes kernels & distrib media)
|
|
|
|
|
|
|
|
Other operations:
|
2003-01-26 09:19:12 +03:00
|
|
|
help Show this message (and exit)
|
2003-02-07 01:19:06 +03:00
|
|
|
makewrapper Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make.
|
|
|
|
(Always done)
|
2003-01-26 08:34:32 +03:00
|
|
|
obj Run "make obj" (default unless -o is used)
|
2003-01-23 19:24:08 +03:00
|
|
|
tools Build and install tools
|
|
|
|
kernel=conf Build kernel with config file \`conf'
|
|
|
|
install=idir Run "make installworld" to \`idir'
|
|
|
|
(useful after 'distribution' or 'release')
|
2003-01-26 16:12:05 +03:00
|
|
|
sets Create distribution sets in RELEASEDIR
|
2003-01-23 19:24:08 +03:00
|
|
|
|
|
|
|
Options:
|
2003-01-22 14:26:11 +03:00
|
|
|
-a arch Set MACHINE_ARCH to arch (otherwise deduced from MACHINE)
|
2003-01-23 19:24:08 +03:00
|
|
|
-B buildId Set BUILDID to buildId
|
2003-01-22 14:26:11 +03:00
|
|
|
-D dest Set DESTDIR to dest
|
|
|
|
-E Set "expert" mode; disables some DESTDIR checks
|
|
|
|
-j njob Run up to njob jobs in parallel; see make(1)
|
|
|
|
-M obj Set obj root directory to obj (sets MAKEOBJDIRPREFIX)
|
|
|
|
-m mach Set MACHINE to mach (not required if NetBSD native)
|
|
|
|
-n Show commands that would be executed, but do not execute them
|
|
|
|
-O obj Set obj root directory to obj (sets a MAKEOBJDIR pattern)
|
|
|
|
-o Set MKOBJDIRS=no (do not create objdirs at start of build)
|
2003-01-23 19:24:08 +03:00
|
|
|
-R release Set RELEASEDIR to release
|
2003-01-22 14:26:11 +03:00
|
|
|
-r Remove contents of TOOLDIR and DESTDIR before building
|
2003-01-23 19:24:08 +03:00
|
|
|
-T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in
|
2003-01-26 08:34:32 +03:00
|
|
|
the environment, ${toolprefix}make will be (re)built unconditionally
|
|
|
|
-U Set UNPRIVED (build without requiring root privileges)
|
|
|
|
-u Set UPDATE (do not run "make clean" first)
|
2003-01-22 14:26:11 +03:00
|
|
|
-V v=[val] Set variable \`v' to \`val'
|
2003-01-23 19:24:08 +03:00
|
|
|
-w wrapper Create ${toolprefix}make script as wrapper
|
2003-01-26 08:34:32 +03:00
|
|
|
(Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE})
|
2003-01-22 14:26:11 +03:00
|
|
|
|
2002-10-20 19:48:01 +04:00
|
|
|
_usage_
|
2001-10-19 06:21:03 +04:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
parseoptions()
|
|
|
|
{
|
|
|
|
opts='a:B:bD:dEhi:j:k:M:m:nO:oR:rT:tUuV:w:'
|
|
|
|
opt_a=no
|
|
|
|
|
|
|
|
if type getopts >/dev/null 2>&1; then
|
|
|
|
# Use POSIX getopts.
|
|
|
|
getoptcmd='getopts $opts opt && opt=-$opt'
|
|
|
|
optargcmd=':'
|
|
|
|
optremcmd='shift $(($OPTIND -1))'
|
|
|
|
else
|
|
|
|
type getopt >/dev/null 2>&1 ||
|
|
|
|
bomb "/bin/sh shell is too old; try ksh or bash"
|
2001-10-19 06:25:48 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
# Use old-style getopt(1) (doesn't handle whitespace in args).
|
|
|
|
args="$(getopt $opts $*)"
|
|
|
|
[ $? = 0 ] || usage
|
|
|
|
set -- $args
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
|
|
|
|
optargcmd='OPTARG="$1"; shift'
|
|
|
|
optremcmd=':'
|
|
|
|
fi
|
2001-10-24 06:39:56 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
# Parse command line options.
|
|
|
|
#
|
|
|
|
while eval $getoptcmd; do
|
|
|
|
case $opt in
|
2001-10-31 01:33:00 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-a)
|
|
|
|
eval $optargcmd
|
|
|
|
MACHINE_ARCH=$OPTARG
|
|
|
|
opt_a=yes
|
|
|
|
;;
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-B)
|
|
|
|
eval $optargcmd
|
|
|
|
BUILDID=$OPTARG
|
|
|
|
;;
|
2002-03-14 21:33:04 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-b)
|
2003-01-26 08:34:32 +03:00
|
|
|
usage "'-b' has been replaced by 'makewrapper'"
|
2003-01-23 19:24:08 +03:00
|
|
|
;;
|
2001-10-31 00:04:05 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-D)
|
|
|
|
eval $optargcmd; resolvepath
|
|
|
|
DESTDIR="$OPTARG"
|
|
|
|
export DESTDIR
|
|
|
|
makeenv="$makeenv DESTDIR"
|
|
|
|
;;
|
2002-12-08 11:42:51 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-d)
|
|
|
|
usage "'-d' has been replaced by 'distribution'"
|
|
|
|
;;
|
2001-11-25 21:35:06 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-E)
|
|
|
|
do_expertmode=true
|
|
|
|
;;
|
2002-12-09 01:14:00 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-i)
|
|
|
|
usage "'-i idir' has been replaced by 'install=idir'"
|
|
|
|
;;
|
2002-12-25 03:42:50 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-j)
|
|
|
|
eval $optargcmd
|
|
|
|
parallel="-j $OPTARG"
|
|
|
|
;;
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-k)
|
|
|
|
usage "'-k conf' has been replaced by 'kernel=conf'"
|
|
|
|
;;
|
2002-10-20 19:48:01 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-M)
|
|
|
|
eval $optargcmd; resolvepath
|
|
|
|
MAKEOBJDIRPREFIX="$OPTARG"
|
|
|
|
export MAKEOBJDIRPREFIX
|
|
|
|
makeobjdir=$OPTARG
|
|
|
|
makeenv="$makeenv MAKEOBJDIRPREFIX"
|
|
|
|
;;
|
2002-12-08 11:42:51 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
# -m overrides MACHINE_ARCH unless "-a" is specified
|
|
|
|
-m)
|
|
|
|
eval $optargcmd
|
|
|
|
MACHINE=$OPTARG
|
|
|
|
[ "$opt_a" != "yes" ] && getarch
|
|
|
|
;;
|
2001-10-19 20:43:47 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-n)
|
|
|
|
runcmd=echo
|
|
|
|
;;
|
2001-10-31 01:33:00 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-O)
|
|
|
|
eval $optargcmd; resolvepath
|
|
|
|
MAKEOBJDIR="\${.CURDIR:C,^$TOP,$OPTARG,}"
|
|
|
|
export MAKEOBJDIR
|
|
|
|
makeobjdir=$OPTARG
|
|
|
|
makeenv="$makeenv MAKEOBJDIR"
|
|
|
|
;;
|
2002-12-08 11:42:51 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-o)
|
|
|
|
MKOBJDIRS=no
|
|
|
|
;;
|
2001-10-31 04:56:10 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-R)
|
|
|
|
eval $optargcmd; resolvepath
|
|
|
|
RELEASEDIR=$OPTARG
|
|
|
|
export RELEASEDIR
|
|
|
|
makeenv="$makeenv RELEASEDIR"
|
|
|
|
;;
|
2002-12-08 11:42:51 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-r)
|
|
|
|
do_removedirs=true
|
|
|
|
do_rebuildmake=true
|
|
|
|
;;
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-T)
|
|
|
|
eval $optargcmd; resolvepath
|
|
|
|
TOOLDIR="$OPTARG"
|
|
|
|
export TOOLDIR
|
|
|
|
;;
|
2002-12-08 11:42:51 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-t)
|
|
|
|
usage "'-t' has been replaced by 'tools'"
|
|
|
|
;;
|
2001-11-01 03:14:17 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-U)
|
|
|
|
UNPRIVED=yes
|
|
|
|
export UNPRIVED
|
|
|
|
makeenv="$makeenv UNPRIVED"
|
|
|
|
;;
|
2002-02-27 16:55:28 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-u)
|
|
|
|
UPDATE=yes
|
|
|
|
export UPDATE
|
|
|
|
makeenv="$makeenv UPDATE"
|
|
|
|
;;
|
Major cleanup and overhaul:
* Allow MACHINE to be set automatically on NetBSD native builds.
Require -m only if the host is not NetBSD.
* Fail if DESTDIR is set to root (/) and the build is not NetBSD native,
or the build is attempting a "make release" (option -R).
* Warn the user if DESTDIR is set to root (/) that the kernel must be up
to date, or else the build might hose the system. Also, do not remove
DESTDIR on -r if it is set to root.
* Fail if TOOLDIR is set to / or empty after checking with nbmake.
* Allow DESTDIR and TOOLDIR to be set in mk.conf and/or by the new default
from <bsd.own.mk>. Note that if -T is not used to set TOOLDIR, and
TOOLDIR is not set in the environment, then nbmake will always be
bootstrapped (rather than looking at nbmake's timestamp). This is
because /bin/sh doesn't know how to get TOOLDIR from mk.conf without
first having nbmake (...which lives in TOOLDIR).
* Do a pass of "make obj" through src/tools before installing nbmake (so
long as -o/MKOBJDIRS=no is not specified). This ensures that objdirs
exist if they are desired, and paves the way for using build.sh to
build all the src/tools without building everything else.
* Add "-w" option, which allows the builder to specify where the nbmake
wrapper shell script should be created. If not specified,
$TOOLDIR/bin/nbmake-$MACHINE is still created as a default.
* Print the values of DESTDIR and TOOLDIR after bootstrapping nbmake,
for informational purposes.
It should now be possible to type just "./build.sh" on a NetBSD-current
host and get a new build in / for the appropriate architecture.
However, building in-place like this has *not* been extensively tested
yet, so be careful.
2001-10-31 22:59:43 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
-V)
|
|
|
|
eval $optargcmd
|
|
|
|
case "${OPTARG}" in
|
2003-01-04 15:55:32 +03:00
|
|
|
# XXX: consider restricting which variables can be changed?
|
2003-01-23 19:24:08 +03:00
|
|
|
[a-zA-Z_][a-zA-Z_0-9]*=*)
|
|
|
|
var=${OPTARG%%=*}
|
|
|
|
value=${OPTARG#*=}
|
|
|
|
eval "${var}=\"${value}\"; export ${var}"
|
|
|
|
makeenv="$makeenv ${var}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage "-V argument must be of the form 'var=[value]'"
|
|
|
|
;;
|
|
|
|
esac
|
2003-01-04 15:55:32 +03:00
|
|
|
;;
|
2003-01-23 19:24:08 +03:00
|
|
|
|
|
|
|
-w)
|
|
|
|
eval $optargcmd; resolvepath
|
|
|
|
makewrapper="$OPTARG"
|
|
|
|
;;
|
|
|
|
|
|
|
|
--)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
|
|
|
|
-'?'|-h)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Validate operations.
|
|
|
|
#
|
|
|
|
eval $optremcmd
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
op=$1; shift
|
|
|
|
operations="$operations $op"
|
|
|
|
|
|
|
|
case "$op" in
|
|
|
|
|
2003-01-26 09:19:12 +03:00
|
|
|
help)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
|
|
|
|
makewrapper|obj|tools|build|distribution|release|sets)
|
2003-01-23 19:24:08 +03:00
|
|
|
;;
|
|
|
|
|
|
|
|
kernel=*)
|
|
|
|
arg=${op#*=}
|
|
|
|
op=${op%%=*}
|
2003-01-26 08:34:32 +03:00
|
|
|
if [ -z "${arg}" ]; then
|
2003-01-23 19:24:08 +03:00
|
|
|
bomb "Must supply a kernel name with \`kernel=...'"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
install=*)
|
|
|
|
arg=${op#*=}
|
|
|
|
op=${op%%=*}
|
2003-01-26 08:34:32 +03:00
|
|
|
if [ -z "${arg}" ]; then
|
2003-01-23 19:24:08 +03:00
|
|
|
bomb "Must supply a directory with \`install=...'"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
2003-01-04 15:55:32 +03:00
|
|
|
*)
|
2003-01-23 19:24:08 +03:00
|
|
|
usage "Unknown operation \`${op}'"
|
|
|
|
;;
|
|
|
|
|
2003-01-04 15:55:32 +03:00
|
|
|
esac
|
2003-01-23 19:24:08 +03:00
|
|
|
eval do_$op=true
|
|
|
|
done
|
2003-01-26 08:34:32 +03:00
|
|
|
if [ -z "${operations}" ]; then
|
|
|
|
usage "Missing operation to perform."
|
|
|
|
fi
|
2003-01-04 15:55:32 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
# Set up MACHINE*. On a NetBSD host, these are allowed to be unset.
|
|
|
|
#
|
|
|
|
if [ -z "$MACHINE" ]; then
|
|
|
|
if [ "${uname_s}" != "NetBSD" ]; then
|
|
|
|
bomb "MACHINE must be set, or -m must be used, for cross builds."
|
|
|
|
fi
|
|
|
|
MACHINE=${uname_m}
|
|
|
|
fi
|
|
|
|
[ -n "$MACHINE_ARCH" ] || getarch
|
|
|
|
validatearch
|
2001-10-31 04:56:10 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
# Set up default make(1) environment.
|
|
|
|
#
|
|
|
|
makeenv="$makeenv TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
|
|
|
|
if [ ! -z "$BUILDID" ]; then
|
|
|
|
makeenv="$makeenv BUILDID"
|
|
|
|
fi
|
|
|
|
MAKEFLAGS="-m $TOP/share/mk $MAKEFLAGS MKOBJDIRS=${MKOBJDIRS-yes}"
|
|
|
|
export MAKEFLAGS MACHINE MACHINE_ARCH
|
|
|
|
}
|
2001-10-19 06:21:03 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
rebuildmake()
|
|
|
|
{
|
|
|
|
# Test make source file timestamps against installed ${toolprefix}make
|
|
|
|
# binary, if TOOLDIR is pre-set.
|
|
|
|
#
|
|
|
|
# Note that we do NOT try to grovel "mk.conf" here to find out if
|
|
|
|
# TOOLDIR is set there, because it can contain make variable
|
|
|
|
# expansions and other stuff only parseable *after* we have a working
|
|
|
|
# ${toolprefix}make. So this logic can only work if the user has
|
|
|
|
# pre-set TOOLDIR in the environment or used the -T option to build.sh.
|
|
|
|
#
|
|
|
|
make="${TOOLDIR-nonexistent}/bin/${toolprefix}make"
|
|
|
|
if [ -x $make ]; then
|
|
|
|
for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
|
|
|
|
if [ $f -nt $make ]; then
|
|
|
|
do_rebuildmake=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
do_rebuildmake=true
|
2001-10-24 06:39:56 +04:00
|
|
|
fi
|
2001-12-04 07:28:23 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
# Build bootstrap ${toolprefix}make if needed.
|
|
|
|
if $do_rebuildmake; then
|
|
|
|
$runcmd echo "===> Bootstrapping ${toolprefix}make"
|
|
|
|
tmpdir="${TMPDIR-/tmp}/nbbuild$$"
|
|
|
|
|
|
|
|
$runcmd mkdir "$tmpdir" || bomb "cannot mkdir: $tmpdir"
|
|
|
|
trap "cd /; rm -r -f \"$tmpdir\"" 0
|
|
|
|
$runcmd cd "$tmpdir"
|
|
|
|
|
|
|
|
$runcmd env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
|
|
|
|
CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
|
|
|
|
"$TOP/tools/make/configure" ||
|
|
|
|
bomb "configure of ${toolprefix}make failed"
|
|
|
|
$runcmd sh buildmake.sh ||
|
|
|
|
bomb "build of ${toolprefix}make failed"
|
|
|
|
|
|
|
|
make="$tmpdir/${toolprefix}make"
|
|
|
|
$runcmd cd "$TOP"
|
|
|
|
$runcmd rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
|
|
|
|
fi
|
|
|
|
}
|
Major cleanup and overhaul:
* Allow MACHINE to be set automatically on NetBSD native builds.
Require -m only if the host is not NetBSD.
* Fail if DESTDIR is set to root (/) and the build is not NetBSD native,
or the build is attempting a "make release" (option -R).
* Warn the user if DESTDIR is set to root (/) that the kernel must be up
to date, or else the build might hose the system. Also, do not remove
DESTDIR on -r if it is set to root.
* Fail if TOOLDIR is set to / or empty after checking with nbmake.
* Allow DESTDIR and TOOLDIR to be set in mk.conf and/or by the new default
from <bsd.own.mk>. Note that if -T is not used to set TOOLDIR, and
TOOLDIR is not set in the environment, then nbmake will always be
bootstrapped (rather than looking at nbmake's timestamp). This is
because /bin/sh doesn't know how to get TOOLDIR from mk.conf without
first having nbmake (...which lives in TOOLDIR).
* Do a pass of "make obj" through src/tools before installing nbmake (so
long as -o/MKOBJDIRS=no is not specified). This ensures that objdirs
exist if they are desired, and paves the way for using build.sh to
build all the src/tools without building everything else.
* Add "-w" option, which allows the builder to specify where the nbmake
wrapper shell script should be created. If not specified,
$TOOLDIR/bin/nbmake-$MACHINE is still created as a default.
* Print the values of DESTDIR and TOOLDIR after bootstrapping nbmake,
for informational purposes.
It should now be possible to type just "./build.sh" on a NetBSD-current
host and get a new build in / for the appropriate architecture.
However, building in-place like this has *not* been extensively tested
yet, so be careful.
2001-10-31 22:59:43 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
validatemakeparams()
|
|
|
|
{
|
|
|
|
if [ "$runcmd" = "echo" ]; then
|
|
|
|
TOOLCHAIN_MISSING=no
|
|
|
|
EXTERNAL_TOOLCHAIN=""
|
|
|
|
else
|
|
|
|
TOOLCHAIN_MISSING=$(getmakevar TOOLCHAIN_MISSING)
|
|
|
|
EXTERNAL_TOOLCHAIN=$(getmakevar EXTERNAL_TOOLCHAIN)
|
|
|
|
fi
|
|
|
|
if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
|
2003-01-26 08:34:32 +03:00
|
|
|
[ -z "${EXTERNAL_TOOLCHAIN}" ]; then
|
2003-01-23 19:24:08 +03:00
|
|
|
$runcmd echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
|
|
|
|
$runcmd echo " MACHINE: ${MACHINE}"
|
|
|
|
$runcmd echo " MACHINE_ARCH: ${MACHINE_ARCH}"
|
|
|
|
$runcmd echo ""
|
|
|
|
$runcmd echo "All builds for this platform should be done via a traditional make"
|
|
|
|
$runcmd echo "If you wish to use an external cross-toolchain, set"
|
|
|
|
$runcmd echo " EXTERNAL_TOOLCHAIN=<path to toolchain root>"
|
|
|
|
$runcmd echo "in either the environment or mk.conf and rerun"
|
|
|
|
$runcmd echo " $progname $*"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If TOOLDIR isn't already set, make objdirs in "tools" in case the
|
|
|
|
# default setting from <bsd.own.mk> is used.
|
|
|
|
#
|
|
|
|
if [ -z "$TOOLDIR" ] && [ "$MKOBJDIRS" != "no" ]; then
|
|
|
|
$runcmd cd tools
|
|
|
|
$runcmd $make -m ${TOP}/share/mk obj NOSUBDIR= ||
|
|
|
|
bomb "make obj failed in tools"
|
|
|
|
$runcmd cd "$TOP"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If setting -M or -O to root an obj dir make sure the base directory
|
|
|
|
# is made before continuing as bsd.own.mk will need this to pick up
|
|
|
|
# _SRC_TOP_OBJ_
|
|
|
|
#
|
|
|
|
if [ "$MKOBJDIRS" != "no" ] && [ ! -z "$makeobjdir" ]; then
|
|
|
|
$runcmd mkdir -p "$makeobjdir"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Find DESTDIR and TOOLDIR.
|
|
|
|
#
|
|
|
|
DESTDIR=$(safe_getmakevar DESTDIR)
|
|
|
|
$runcmd echo "===> DESTDIR path: $DESTDIR"
|
|
|
|
TOOLDIR=$(safe_getmakevar TOOLDIR)
|
|
|
|
$runcmd echo "===> TOOLDIR path: $TOOLDIR"
|
|
|
|
export DESTDIR TOOLDIR
|
|
|
|
|
|
|
|
# Check validity of TOOLDIR and DESTDIR.
|
|
|
|
#
|
|
|
|
if [ -z "$TOOLDIR" ] || [ "$TOOLDIR" = "/" ]; then
|
|
|
|
bomb "TOOLDIR '$TOOLDIR' invalid"
|
|
|
|
fi
|
|
|
|
removedirs="$TOOLDIR"
|
|
|
|
|
|
|
|
if [ -z "$DESTDIR" ] || [ "$DESTDIR" = "/" ]; then
|
|
|
|
if $do_build || $do_distribution || $do_release; then
|
|
|
|
if ! $do_build || \
|
|
|
|
[ "${uname_s}" != "NetBSD" ] || \
|
|
|
|
[ "${uname_m}" != "$MACHINE" ]; then
|
|
|
|
bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'."
|
|
|
|
fi
|
|
|
|
if ! $do_expertmode; then
|
|
|
|
bomb "DESTDIR must != / for non -E (expert) builds"
|
|
|
|
fi
|
|
|
|
$runcmd echo "===> WARNING: Building to /, in expert mode."
|
|
|
|
$runcmd echo "===> This may cause your system to break! Reasons include:"
|
|
|
|
$runcmd echo "===> - your kernel is not up to date"
|
|
|
|
$runcmd echo "===> - the libraries or toolchain have changed"
|
|
|
|
$runcmd echo "===> YOU HAVE BEEN WARNED!"
|
2002-12-09 01:14:00 +03:00
|
|
|
fi
|
2003-01-23 19:24:08 +03:00
|
|
|
else
|
|
|
|
removedirs="$removedirs $DESTDIR"
|
Major cleanup and overhaul:
* Allow MACHINE to be set automatically on NetBSD native builds.
Require -m only if the host is not NetBSD.
* Fail if DESTDIR is set to root (/) and the build is not NetBSD native,
or the build is attempting a "make release" (option -R).
* Warn the user if DESTDIR is set to root (/) that the kernel must be up
to date, or else the build might hose the system. Also, do not remove
DESTDIR on -r if it is set to root.
* Fail if TOOLDIR is set to / or empty after checking with nbmake.
* Allow DESTDIR and TOOLDIR to be set in mk.conf and/or by the new default
from <bsd.own.mk>. Note that if -T is not used to set TOOLDIR, and
TOOLDIR is not set in the environment, then nbmake will always be
bootstrapped (rather than looking at nbmake's timestamp). This is
because /bin/sh doesn't know how to get TOOLDIR from mk.conf without
first having nbmake (...which lives in TOOLDIR).
* Do a pass of "make obj" through src/tools before installing nbmake (so
long as -o/MKOBJDIRS=no is not specified). This ensures that objdirs
exist if they are desired, and paves the way for using build.sh to
build all the src/tools without building everything else.
* Add "-w" option, which allows the builder to specify where the nbmake
wrapper shell script should be created. If not specified,
$TOOLDIR/bin/nbmake-$MACHINE is still created as a default.
* Print the values of DESTDIR and TOOLDIR after bootstrapping nbmake,
for informational purposes.
It should now be possible to type just "./build.sh" on a NetBSD-current
host and get a new build in / for the appropriate architecture.
However, building in-place like this has *not* been extensively tested
yet, so be careful.
2001-10-31 22:59:43 +03:00
|
|
|
fi
|
2003-01-26 08:34:32 +03:00
|
|
|
if $do_build || $do_distribution || $do_release; then
|
|
|
|
if ! $do_expertmode && \
|
|
|
|
[ $(id -u 2>/dev/null) -ne 0 ] &&\
|
|
|
|
[ -z "$UNPRIVED" ] ; then
|
|
|
|
bomb "-U or -E must be set for build as an unprivileged user."
|
|
|
|
fi
|
|
|
|
fi
|
2003-01-23 19:24:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
createmakewrapper()
|
|
|
|
{
|
|
|
|
# Remove the target directories.
|
|
|
|
#
|
|
|
|
if $do_removedirs; then
|
|
|
|
for f in $removedirs; do
|
|
|
|
$runcmd echo "===> Removing $f"
|
|
|
|
$runcmd rm -r -f $f
|
|
|
|
done
|
2002-12-25 03:42:50 +03:00
|
|
|
fi
|
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
# Recreate $TOOLDIR.
|
|
|
|
#
|
|
|
|
$runcmd mkdir -p "$TOOLDIR/bin" || bomb "mkdir of '$TOOLDIR/bin' failed"
|
|
|
|
|
|
|
|
# Install ${toolprefix}make if it was built.
|
|
|
|
#
|
|
|
|
if $do_rebuildmake; then
|
|
|
|
$runcmd rm -f "$TOOLDIR/bin/${toolprefix}make"
|
|
|
|
$runcmd cp $make "$TOOLDIR/bin/${toolprefix}make" ||
|
|
|
|
bomb "failed to install \$TOOLDIR/bin/${toolprefix}make"
|
|
|
|
make="$TOOLDIR/bin/${toolprefix}make"
|
|
|
|
$runcmd echo "===> Created ${make}"
|
|
|
|
$runcmd rm -r -f "$tmpdir"
|
|
|
|
trap 0
|
2002-03-14 21:33:04 +03:00
|
|
|
fi
|
2001-10-24 06:39:56 +04:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
# Build a ${toolprefix}make wrapper script, usable by hand as
|
|
|
|
# well as by build.sh.
|
|
|
|
#
|
|
|
|
if [ -z "$makewrapper" ]; then
|
|
|
|
makewrapper="$TOOLDIR/bin/${toolprefix}make-$MACHINE"
|
|
|
|
if [ ! -z "$BUILDID" ]; then
|
|
|
|
makewrapper="$makewrapper-$BUILDID"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
$runcmd rm -f "$makewrapper"
|
|
|
|
if [ "$runcmd" = "echo" ]; then
|
|
|
|
echo 'cat <<EOF >'$makewrapper
|
|
|
|
makewrapout=
|
|
|
|
else
|
|
|
|
makewrapout=">>\$makewrapper"
|
|
|
|
fi
|
2001-11-02 08:07:22 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
eval cat <<EOF $makewrapout
|
2001-10-24 06:39:56 +04:00
|
|
|
#! /bin/sh
|
|
|
|
# Set proper variables to allow easy "make" building of a NetBSD subtree.
|
2003-02-19 02:59:06 +03:00
|
|
|
# Generated from: \$NetBSD: build.sh,v 1.92 2003/02/18 23:59:06 lukem Exp $
|
2001-10-24 06:39:56 +04:00
|
|
|
#
|
2001-11-02 08:07:22 +03:00
|
|
|
|
|
|
|
EOF
|
2003-01-23 19:24:08 +03:00
|
|
|
for f in $makeenv; do
|
|
|
|
eval echo "$f=\'\$$(echo $f)\'\;\ export\ $f" $makewrapout
|
|
|
|
done
|
|
|
|
eval echo "USETOOLS=yes\; export USETOOLS" $makewrapout
|
2001-11-02 08:07:22 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
eval cat <<EOF $makewrapout
|
2001-11-02 08:07:22 +03:00
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
exec "\$TOOLDIR/bin/${toolprefix}make" \${1+"\$@"}
|
2001-10-24 06:39:56 +04:00
|
|
|
EOF
|
2003-01-23 19:24:08 +03:00
|
|
|
[ "$runcmd" = "echo" ] && echo EOF
|
|
|
|
$runcmd chmod +x "$makewrapper"
|
|
|
|
$runcmd echo "===> Updated ${makewrapper}"
|
|
|
|
}
|
|
|
|
|
|
|
|
buildtools()
|
|
|
|
{
|
|
|
|
if [ "$MKOBJDIRS" != "no" ]; then
|
|
|
|
$runcmd "$makewrapper" $parallel obj-tools ||
|
|
|
|
bomb "failed to make obj-tools"
|
2001-11-01 03:14:17 +03:00
|
|
|
fi
|
2003-01-23 19:24:08 +03:00
|
|
|
$runcmd cd tools
|
2003-01-26 08:34:32 +03:00
|
|
|
if [ -z "$UPDATE" ]; then
|
2003-01-23 19:24:08 +03:00
|
|
|
cleandir=cleandir
|
|
|
|
else
|
|
|
|
cleandir=
|
|
|
|
fi
|
|
|
|
$runcmd "$makewrapper" ${cleandir} dependall install ||
|
|
|
|
bomb "failed to make tools"
|
|
|
|
}
|
|
|
|
|
|
|
|
buildkernel()
|
|
|
|
{
|
|
|
|
kernconf="$1"
|
|
|
|
if ! $do_tools; then
|
|
|
|
# Building tools every time we build a kernel is clearly
|
|
|
|
# unnecessary. We could try to figure out whether rebuilding
|
|
|
|
# the tools is necessary this time, but it doesn't seem worth
|
|
|
|
# the trouble. Instead, we say it's the user's responsibility
|
|
|
|
# to rebuild the tools if necessary.
|
|
|
|
#
|
|
|
|
$runcmd echo "===> Building kernel without building new tools"
|
|
|
|
fi
|
|
|
|
$runcmd echo "===> Building kernel ${kernconf}"
|
|
|
|
if [ "$MKOBJDIRS" != "no" ] && [ ! -z "$makeobjdir" ]; then
|
|
|
|
# The correct value of KERNOBJDIR might
|
|
|
|
# depend on a prior "make obj" in
|
|
|
|
# ${KERNSRCDIR}/${KERNARCHDIR}/compile.
|
|
|
|
#
|
|
|
|
KERNSRCDIR="$(safe_getmakevar KERNSRCDIR)"
|
|
|
|
KERNARCHDIR="$(safe_getmakevar KERNARCHDIR)"
|
|
|
|
$runcmd cd "${KERNSRCDIR}/${KERNARCHDIR}/compile"
|
|
|
|
$runcmd "$makewrapper" obj ||
|
|
|
|
bomb "failed to make obj in ${KERNSRCDIR}/${KERNARCHDIR}/compile"
|
|
|
|
$runcmd cd "$TOP"
|
|
|
|
fi
|
|
|
|
KERNCONFDIR="$(safe_getmakevar KERNCONFDIR)"
|
|
|
|
KERNOBJDIR="$(safe_getmakevar KERNOBJDIR)"
|
|
|
|
case "${kernconf}" in
|
|
|
|
*/*)
|
|
|
|
kernconfpath="${kernconf}"
|
|
|
|
kernconfbase="$(basename "${kernconf}")"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
kernconfpath="${KERNCONFDIR}/${kernconf}"
|
|
|
|
kernconfbase="${kernconf}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
kernbuilddir="${KERNOBJDIR}/${kernconfbase}"
|
|
|
|
$runcmd echo "===> Kernel build directory: ${kernbuilddir}"
|
|
|
|
$runcmd mkdir -p "${kernbuilddir}" ||
|
|
|
|
bomb "cannot mkdir: ${kernbuilddir}"
|
2003-01-26 08:34:32 +03:00
|
|
|
if [ -z "$UPDATE" ]; then
|
2003-01-23 19:24:08 +03:00
|
|
|
$runcmd cd "${kernbuilddir}"
|
|
|
|
$runcmd "$makewrapper" cleandir ||
|
|
|
|
bomb "make cleandir failed in ${kernbuilddir}"
|
|
|
|
$runcmd cd "$TOP"
|
|
|
|
fi
|
|
|
|
$runcmd "${TOOLDIR}/bin/${toolprefix}config" -b "${kernbuilddir}" \
|
|
|
|
-s "${TOP}/sys" "${kernconfpath}" ||
|
|
|
|
bomb "${toolprefix}config failed for ${kernconf}"
|
|
|
|
$runcmd cd "${kernbuilddir}"
|
|
|
|
$runcmd "$makewrapper" depend ||
|
|
|
|
bomb "make depend failed in ${kernbuilddir}"
|
|
|
|
$runcmd "$makewrapper" $parallel all ||
|
|
|
|
bomb "make all failed in ${kernbuilddir}"
|
2003-02-16 07:35:03 +03:00
|
|
|
|
|
|
|
if [ "$runcmd" != "echo" ]; then
|
|
|
|
echo "===> New kernels built:"
|
|
|
|
kernlist=$(awk '$1 == "config" { print $2 }' ${kernconfpath})
|
|
|
|
for kern in ${kernlist:-netbsd}; do
|
|
|
|
[ -f "${kernbuilddir}/${kern}" ] && \
|
|
|
|
echo " ${kernbuilddir}/${kern}"
|
|
|
|
done
|
|
|
|
echo "."
|
|
|
|
fi
|
2003-01-23 19:24:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
installworld()
|
|
|
|
{
|
|
|
|
dir="$1"
|
|
|
|
${runcmd} "$makewrapper" INSTALLWORLDDIR="${dir}" installworld ||
|
|
|
|
bomb "failed to make installworld to ${dir}"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
initdefaults
|
|
|
|
parseoptions "$@"
|
|
|
|
rebuildmake
|
|
|
|
validatemakeparams
|
|
|
|
createmakewrapper
|
|
|
|
|
|
|
|
# Perform the operations.
|
|
|
|
#
|
|
|
|
for op in $operations; do
|
|
|
|
case "$op" in
|
|
|
|
|
2003-01-26 08:34:32 +03:00
|
|
|
makewrapper)
|
|
|
|
# no-op
|
|
|
|
;;
|
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
tools)
|
|
|
|
buildtools
|
2002-10-20 19:48:01 +04:00
|
|
|
;;
|
2003-01-23 19:24:08 +03:00
|
|
|
|
2003-01-26 09:19:12 +03:00
|
|
|
obj|build|distribution|release|sets)
|
2003-01-23 19:24:08 +03:00
|
|
|
${runcmd} "$makewrapper" $parallel $op ||
|
|
|
|
bomb "failed to make $op"
|
|
|
|
;;
|
|
|
|
|
|
|
|
kernel=*)
|
|
|
|
arg=${op#*=}
|
|
|
|
buildkernel "${arg}"
|
|
|
|
;;
|
|
|
|
|
|
|
|
install=*)
|
|
|
|
arg=${op#*=}
|
2003-01-24 04:17:52 +03:00
|
|
|
if [ "${arg}" = "/" ] && \
|
|
|
|
( [ "${uname_s}" != "NetBSD" ] || \
|
|
|
|
[ "${uname_m}" != "$MACHINE" ] ); then
|
|
|
|
bomb "'${op}' must != / for cross builds."
|
|
|
|
fi
|
2003-01-23 19:24:08 +03:00
|
|
|
installworld "${arg}"
|
|
|
|
;;
|
|
|
|
|
2002-10-20 19:48:01 +04:00
|
|
|
*)
|
2003-01-23 19:24:08 +03:00
|
|
|
bomb "Unknown operation \`${op}'"
|
2002-10-20 19:48:01 +04:00
|
|
|
;;
|
2003-01-23 19:24:08 +03:00
|
|
|
|
2002-10-20 19:48:01 +04:00
|
|
|
esac
|
2003-01-23 19:24:08 +03:00
|
|
|
done
|
|
|
|
}
|
2002-12-25 03:42:50 +03:00
|
|
|
|
2003-02-19 02:59:06 +03:00
|
|
|
build_start=$(date)
|
|
|
|
echo "===> ${progname} command: $0 $@"
|
|
|
|
echo "===> ${progname} started: $build_start"
|
|
|
|
|
2003-01-23 19:24:08 +03:00
|
|
|
main "$@"
|
2003-02-19 02:59:06 +03:00
|
|
|
|
|
|
|
echo "===> ${progname} started: $build_start"
|
|
|
|
echo "===> ${progname} ended: $(date)"
|