Add "makewrapper" operation to build.sh.
[The above changes were suggested by Alan Barrett on current-users@]
Fail if building as non-root unless: UNPRIVED is set, -U is given, or -E
(expert mode) is given.
[Suggested by James Wetterau in private email]
Improve the examples in BUILDING.
parameters, and a list of "operations" defines what to do.
The full usage is show below. Notes:
`-b' has been deprecated (it always occurs now)
`-d' is replaced by "distribution"
`-R rel' onlys sets RELEASEDIR; use "release" to build a release
`-k kern' has been replaced by "kernel=kern"
`-i idir' has been replaced by "install=idir"
-r now occurs before nbmake is rebuilt
Add a copyright (long due!). Rework the code to (a KNF inspired) ShellNF.
Use functions appropriately. Allow `nb' prefix to be easily changed to
something else. Solve world peace (just kidding)
This is part of the (never achievable) goal of attempting to make
NetBSD easier to build...
--8<-- new usage follows --8<--
Usage: build.sh [-EnorUu] [-a arch] [-B buildid] [-D dest] [-j njob] [-M obj]
[-m mach] [-O obj] [-R release] [-T tools] [-V var=[value]]
[-w wrapper] [operation [...] ]
System build operations (all imply "obj" and "tools"):
build Run "make build"
distribution Run "make distribution" (includes etc/ files)
release Run "make release" (includes kernels & distrib media)
Other operations:
obj Run "make obj" (default unless -o)
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')
Options:
-a arch Set MACHINE_ARCH to arch (otherwise deduced from MACHINE)
-B buildId Set BUILDID to buildId
-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)
-R release Set RELEASEDIR to release
-r Remove contents of TOOLDIR and DESTDIR before building
-T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in
the environment, nbmake will be (re)built unconditionally.
-U Set UNPRIVED
-u Set UPDATE
-V v=[val] Set variable `v' to `val'
-w wrapper Create nbmake script as wrapper
(default: ${TOOLDIR}/bin/nbmake-${MACHINE})
(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.
make INSTALLWORLDDIR=installworlddir installworld
after every other operation has completed.
If you want to run this target without rebuilding, use -b as well...
- Cache the output of `uname -s` and `uname -m` for future use.
* When building a kernel with the -k option, make obj in $TOP/etc to
ensure that the correct KERNOBJDIR is created and used. Previously,
KERNOBJDIR could sometimes be an objdir outside the source tree
and sometimes $TOP/sys/arch/$ARCH/compile inside the source tree,
depending on whether or not a complete build had beed done before
the kernel build.
* Renamed KERNCONFNAME to kernconfname, for consistency with what
seems to be a convention that variables local to build.sh (as
opposed to make or environment variables) have lowercase names.
* Renamed the do_buildonlytools and do_buildonlykernel variables to
do_buildtools and do_buildkernel, because the word "only" is no
longer appropriate now that more than one of them can be active
simultaneously.
* Changed a few '|| exit 1' tests to '|| bomb "message"', and added a
few more similar tests.
* Changed all 'echo "===> ..."' to use $runcmd, and added a few more
similar echos. Previously, some used $runcmd and some did not.
kernel using the $TOOLDIR toolchain. If kern doesn't contain `/', it will
be searched for in ${KERNCONFDIR} (typically, sys/arch/${MACHINE}/conf).
- Improve ./build.sh usage.
- Add some examples to the documentation.
This is heavily based on [toolchain/18739] from Alan Barrett <apb@cequrux.com>,
with improvements by me.
Obsolete NBUILDJOBS; build.sh just passes -jN through to make(1),
which inherits it cooperatively through the build tree. Fix
documentation so that it's shown to be deprecated.
If you use build -jN, please save full build logs so that errors due
to missing dependancies can be analyzed and corrected.
* Rewrite src/tools Make logic to work like the rest of the tree wrt
"dependall" and "install". The old "make build" hack is gone.
* Remove the MKTOOLS logic. This was linked to the "make build" hack,
and was only needed because TOOLDIR originally had no writable default.
* Redo the GNU configure/make logic to make it fit reasonably in a
BSD make wrapper. Use new ${.ALLTARGETS} variable to scan for
targets in $(srcdir), and mark them with .MADE: to prevent rebuilding.
* Only build cross tools in src/tools; remove some messy logic in
src/usr.* and src/gnu/usr.* that would do target filename rewriting
(improves consistency and readability).
* Add the ability to build cross gdb at tool build time by setting
MKCROSSGDB (default no) to "yes" in mk.conf.
* Add src/tools/groff and set up paths to work with this cross groff.
build.sh just get lost if they differ from a previous invocation (i.e. letting
MKOBJDIRS get set the first time, -o will get ignored after this unless a
rebuild of the script happens). It's low overhead so this adds little burden
to getting it right.
$TOOLDIR and $DESTDIR in their expanded form.
* Set USETOOLS=yes in the make wrapper script; it's pretty pointless
using the make wrapper unless you're using the host tools.
* In the -t case, make sure to only echo the "make obj" command if -n.
* Set stuff mostly in the environment, not on make(1)'s command line.
This is needed for MACHINE and MACHINE_ARCH (noted by bjh21), and keeps
the mk.conf-overriding-env behavior (suggested by several people).
* Use MAKEFLAGS to make the wrapper script more readable.
* When prepping objdir in tools for the default TOOLDIR value, just make
that objdir; leave the recursive "make obj" for later.
* 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.
quoting, so the commands were thought to be one big word with embedded
whitespace)
* New options:
-O obj Set root of an obj tree; sets MAKEOBJDIR to an appropriate
substitution pattern.
-o Sets MKOBJDIRS=no (otherwise sets MKOBJDIRS=yes)
-u Sets UPDATE
* Don't require DESTDIR when -b is set.
* Add -n option, which prints the commands that would be run by build.sh,
but doesn't run them (much like make's -n option).
* Auto-resolve relative paths for -D, -R, and -T (but not for the
corresponding environment variables).
* Explicitly declare defaults of all shell variables used where feasible,
rather than sprinkling ${varname-value} expansions.
* Prefix shell true/false variables with "do_" to indicate their use as
actual values in shell expressions (like "$do_buildsystem && echo foo").
If a machine is not known, abort.
- Emulate "mkdir -p" for Old "mkdir" programs on some host OS's.
- Add "-a" option to provide MACHINE_ARCH explicitly (for MACHINEs
that are capable of having more than one MACHINE_ARCH, such as sh3
and sparc64)
- Where "getopts" is not available in the shell, try using "getopt".
It's not whitespace compatible, but works in most cases.
- Rename "bmake" to "nbmake" per suggestions.
- When building nbmake, create a temporary directory for the purpose
of holding host compiler objects that might be created in the cwd.
Delete this directory if aborted via sh's "trap".
- Create a wrapper script in $TOOLDIR/bin called "nbmake-$MACHINE",
which can be run by hand for building parts of a cross tree easily.
Use this script when finally starting the build.