NetBSD/BUILDING.html

847 lines
22 KiB
HTML

<html>
<head>
<title>
October 29, 2001 BUILDING 8 NetBSD
</title>
<style type="text/css">
<!--
body { margin-left:4%; }
H1 { color: maroon; padding: 4pt; margin-left: -4% }
H2 { color: maroon; padding: 4pt; margin-left: -4% }
H3 { color: maroon; padding: 4pt; margin-left: -4% }
H4 { color: maroon; padding: 4pt; margin-left: -4% }
H5 { color: maroon; padding: 4pt; margin-left: -4% }
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h3>
NAME
</h3>
<b>BUILDING</b>
- Procedure for building
NetBSD
from source code.
<h3>
STATUS
</h3>
This document is a work-in-progress. As such, the information described
here may not match the reality of the build system as of this writing.
Once this document is completely in sync with reality, this paragraph
will be removed.
<p>
Discrepancies between this documentation and the current reality of
implementation are noted specially, as with the note below:
<p>
<em></em><em>Note</em>:
This document applies only to platforms which use the new toolchain as
indicated by the setting of
<b></b><b>USE_NEW_TOOLCHAIN</b>
in
<b></b><b>/etc/mk.conf</b>
or
&lt;bsd.own.mk&gt;.
Platforms which have not yet been switched to the new toolchain should
continue building traditionally, using the notes specified in the file
<b></b><b>UPDATING</b>.
<h3>
REQUIREMENTS
</h3>
NetBSD
is designed to be buildable on most POSIX-compliant host systems.
The basic build procedure is the same whether compiling
<em></em><em>natively</em>
(on the same
NetBSD
architecture) or
<em></em><em>cross</em><em> compiling</em>
(on another architecture or OS).
<p>
This source tree contains a special subtree,
``tools'',
which uses the host system to create a build toolchain for the target
architecture. The host system must have at least C and C++
compilers in order to create the toolchain
<b>(</b><b>make</b>
is not required); all other tools are created as part of the
NetBSD
build process.
<p>
<dl compact><dt><dd>
<pre>
<em></em><em>Note</em>:
A couple host toolchain components are not yet available in the tools
directory. Also, some tools use non-POSIX, non-ANSI C extensions
and need to be standardized. As a result, cross-compiling from
systems other than
NetBSD
is not currently supported.
</pre>
</dl>
<h3>
FILES
</h3>
<h4>
<a name="Source tree layout">
Source tree layout
</a>
</h4>
<dl compact>
<p><dt><b></b><b>BUILDING.mdoc</b><dd>
This document (in -mdoc troff format; the original copy).
<p><dt><b></b><b>BUILDING.html</b><dd>
This document (in formatted HTML).
<p><dt><b></b><b>BUILDING.txt</b><dd>
This document (in plaintext).
<p><dt><b></b><b>Makefile</b><dd>
The main Makefile for
NetBSD;
should only be run for native builds with an appropriately up-to-date
version of
NetBSD
<code>make(1)</code>.
(For building from out-of-date systems or on a non-native host, see the
<b>build.sh</b>
shell script.)
<p><dt><b></b><b>UPDATING</b><dd>
Special notes for updating from an earlier revision of
NetBSD.
It is important to read this file before every build of an updated
source tree.
<p><dt><b></b><b>build.sh</b><dd>
Bourne-compatible shell script used for building the host build tools
and the
NetBSD
system from scratch. Can be used for both native and cross builds, and
should be used instead of
<code>make(1)</code>
for any source tree that is updated and recompiled regularly.
<p><dt><b></b><b>crypto/dist/</b>,<b> dist/</b>,<b> gnu/dist/</b><dd>
Sources imported verbatim from third parties, without mangling the
existing build structure. Other source trees in
<b></b><b>bin</b>
through
<b></b><b>usr.sbin</b>
use the
NetBSD
<code>make(1)</code>
``reachover''
Makefile semantics when building these programs for a native host.
<p><dt><b></b><b>distrib/</b>,<b> etc/</b><dd>
Sources for items used when making a full release snapshot, such as
files installed in
<b></b><b>/etc</b>
on the destination system, boot media, and release notes.
<p><dt><b></b><b>regress/</b><dd>
Regression test harness. Can be cross-compiled, but only run natively.
<p><dt><b></b><b>sys/</b><dd>
NetBSD
kernel sources.
<p><dt><b></b><b>tools/</b><dd>
``Reachover''
build structure for the host build tools. This has a special method of
determining out-of-date status.
<p><dt><b></b><b>bin/</b><b> ...</b><b> usr.sbin/</b><dd>
Sources to the
NetBSD
userland (non-kernel) programs. If any of these directories are
missing, they will be skipped during the build.
</dl>
<h4>
<a name="Build tree layout">
Build tree layout
</a>
</h4>
The
NetBSD
build tree is described in
<code>hier(7)</code>,
and the release layout is described in
<code>release(7)</code>.
<p>
<h3>
CONFIGURATION
</h3>
<h4>
<a name="make variables">
make variables
</a>
</h4>
Several variables control the behavior of
NetBSD
builds. Unless otherwise specified, these variables may be set in
either the process environment or the
<code>make(1)</code>
configuration file specified by
<b></b><b>MAKECONF</b>.
<dl compact>
<p><dt><b></b><b>DESTDIR</b><dd>
Directory to contain the built
NetBSD
system. If set, special options are passed to the compilation tools to
prevent their default use of the host system's
<b></b><b>/usr/include</b>,<b> /usr/lib</b>,
and so forth. This pathname should
<em></em><em>not</em>
end with a slash
(/)
character (for installation into the system's root directory, set
<b></b><b>DESTDIR</b>
to an empty string).
<p>
<em></em><em>Default</em>:
Empty string if
<b></b><b>USETOOLS</b>
is
``yes'';
unset otherwise.
<p><dt><b></b><b>MAKECONF</b><dd>
The name of the
<code>make(1)</code>
configuration file.
<em></em><em>Only</em><em> settable</em><em> in</em><em> the</em><em> process</em><em> environment.</em>
<p>
<em></em><em>Default</em>:
``/etc/mk.conf''
<p><dt><b></b><b>MKCATPAGES</b><dd>
Can be set to
``yes''
or
``no''.
Indicates whether preformatted plaintext manual pages will be created
during a build.
<p>
<em></em><em>Default</em>:
``yes''
<p><dt><b></b><b>MKCRYPTO</b><dd>
Can be set to
``yes''
or
``no''.
Indicates whether cryptographic code will be included in a build;
provided for the benefit of countries that do not allow strong
cryptography. Will not affect use of the standard low-security password
encryption system,
<code>crypt(3)</code>.
<p>
<em></em><em>Default</em>:
``yes''
<p><dt><b></b><b>MKDOC</b><dd>
Can be set to
``yes''
or
``no''.
Indicates whether system documentation destined for
<b></b><b>/usr/share/doc</b>
will be installed during a build.
<p>
<em></em><em>Default</em>:
``yes''
<p><dt><b></b><b>MKINFO</b><dd>
Can be set to
``yes''
or
``no''.
Indicates whether GNU Info files, used for the documentation for
most of the compilation tools, will be created and installed during a
build.
<p>
<em></em><em>Default</em>:
``yes''
<p><dt><b></b><b>MKLINT</b><dd>
Can be set to
``yes''
or
``no''.
Indicates whether
<code>lint(1)</code>
will be run against portions of the
NetBSD
source code during the build, and whether lint libraries will be
installed into
<b></b><b>/usr/libdata/lint</b>.
<p>
<em></em><em>Default</em>:
``yes''
<p><dt><b></b><b>MKMAN</b><dd>
Can be set to
``yes''
or
``no''.
Indicates whether manual pages will be installed during a build.
<p>
<em></em><em>Default</em>:
``yes''
<p><dt><b></b><b>MKNLS</b><dd>
Can be set to
``yes''
or
``no''.
Indicates whether Native Language System locale zone files will be
compiled and installed during a build.
<p>
<em></em><em>Default</em>:
``yes''
<p><dt><b></b><b>MKOBJ</b><dd>
Can be set to
``yes''
or
``no''.
Indicates whether object directories will be created when running
``make obj''.
If set to
``no'',
then all built files will be located inside the regular source tree.
<p>
<em></em><em>Default</em>:
``yes''
<p><dt><b></b><b>MKPIC</b><dd>
Can be set to
``yes''
or
``no''.
Indicates whether shared objects and libraries will be created and
installed during a build. If set to
``no'',
the entire built system will be statically linked.
<p>
<em></em><em>Default</em>:
Platform dependent. As of this writing, all platforms except
<b></b><b>sh3</b>
default to
``yes''.
<p><dt><b></b><b>MKPICINSTALL</b><dd>
Can be set to
``yes''
or
``no''.
Indicates whether the
<code>ar(1)</code>
format libraries
<b></b>(<b>lib*_pic.a</b>),
used to generate shared libraries, are installed during a build.
<p>
<em></em><em>Default</em>:
``yes''
<p><dt><b></b><b>MKPROFILE</b><dd>
Can be set to
``yes''
or
``no''.
Indicates whether profiled libraries
<b></b>(<b>lib*_p.a</b>)
will be built and installed during a build.
<p>
<em></em><em>Default</em>:
``yes'';
however, some platforms turn off
<b></b><b>MKPROFILE</b>
by default at times due to toolchain problems with profiled code.
<p><dt><b></b><b>MKSHARE</b><dd>
Can be set to
``yes''
or
``no''.
Indicates whether files destined to reside in
<b></b><b>/usr/share</b>
will be built and installed during a build. If set to
``no'',
then all of
<b></b><b>MKCATPAGES</b>,<b> MKDOC</b>,<b> MKINFO</b>,<b> MKMAN</b>,
and
<b></b><b>MKNLS</b>
will be set to
``no''
unconditionally.
<p>
<em></em><em>Default</em>:
``yes''
<p><dt><b></b><b>TOOLDIR</b><dd>
Directory to hold the host tools, once built. This directory should be
unique to a given host system and
NetBSD
source tree. (However, multiple targets may share the same
<b></b><b>TOOLDIR</b>;
the target-dependent files have unique names.) Must be set if USETOOLS
is
``yes''.
<p>
<em></em><em>Default</em>:
Unset.
<p><dt><b></b><b>UPDATE</b><dd>
If set, then all install operations intended to write to
<b></b><b>DESTDIR</b>
will compare file timestamps before installing, and skip the install
phase if the destination files are up-to-date. This also has
implications on full builds (see next subsection).
<p>
<em></em><em>Default</em>:
Unset.
<p><dt><b></b><b>USETOOLS</b><dd>
Indicates whether the tools specified by
<b></b><b>TOOLDIR</b>
should be used as part of a build in progress. Must be set to
``yes''
if cross-compiling.
<dl compact>
<p><dt><b></b><b>yes</b><dd>
Use the tools from
<b></b><b>TOOLDIR</b>.
<p><dt><b></b><b>no</b><dd>
Do not use the tools from
<b></b><b>TOOLDIR</b>,
but refuse to build native compilation tool components that are
version-specific for that tool.
<p><dt><b></b><b>never</b><dd>
Do not use the tools from
<b></b><b>TOOLDIR</b>,
even when building native tool components. This is similar to the
traditional
NetBSD
build method, but does
<em></em><em>not</em>
verify that the compilation tools in use are up-to-date enough in order
to build the tree successfully. This may cause build or runtime
problems when building the whole
NetBSD
source tree.
</dl>
<p>
<em></em><em>Default</em>:
``yes''
if building all or part of a whole
NetBSD
source tree (detected automatically);
``no''
otherwise (to preserve traditional semantics of the
&lt;bsd.*.mk&gt;
<code>make(1)</code>
include files).
<p>
<em></em><em>Note</em>:
Currently, the
``no''
option functions similarly to the
``never''
option. Proper checks will be added in the near future to add the
described functionality for version-specific tool components.
</dl>
<h4>
<a name="make variables for full builds">
make variables for full builds
</a>
</h4>
These variables only affect the top level
``Makefile''
and do not manually building subtrees of the
NetBSD
source code.
<dl compact>
<p><dt><b></b><b>MKOBJDIRS</b><dd>
Can be set to
``yes''
or
``no''.
Indicates whether object directories will be created automatically
(via a
``make obj''
pass) at the start of a build.
<p>
<em></em><em>Default</em>:
``yes''
<p><dt><b></b><b>MKTOOLS</b><dd>
Indicates whether the host tools will be built and installed
automatically if they are out-of-date.
<dl compact>
<p><dt><b></b><b>yes</b><dd>
Build tools as needed into
<b></b><b>TOOLDIR</b>,
but only if the tools in question are out-of-date.
<p><dt><b></b><b>no</b><dd>
Do not update the tools in
<b></b><b>TOOLDIR</b>;
halt the build as a safety precaution if tools are out-of-date.
<p><dt><b></b><b>always</b><dd>
Always rebuild the tools in
<b></b><b>TOOLDIR</b>
from scratch during a build. This is similar to the standard
NetBSD
source tree build method, but is not typically required for host tools.
</dl>
<p>
<em></em><em>Default</em>:
``no''
<p><dt><b></b><b>NBUILDJOBS</b><dd>
If set, specifies the number of parallel
<code>make(1)</code>
processes that should be run simultaneously. This can speed up builds
on SMP machines, or machines with much more CPU power than I/O
availability. This should be used
<em></em><em>instead</em>
of the
<code>make(1)</code>
option
<b></b><b>-j</b>,
in order to ensure proper ordering of build components.
<p>
<em></em><em>Default</em>:
Unset.
<p><dt><b></b><b>NOCLEANDIR</b><dd>
If set, avoids the
``make cleandir''
phase of a full build. This has the effect of allowing only changed
files in a source tree to be recompiled. This can speed up builds when
updating only a few files in the tree.
<p>
<em></em><em>Default</em>:
Unset.
<p><dt><b></b><b>NODISTRIBDIRS</b><dd>
If set, avoids the
``make distrib-dirs''
phase of a full build. This skips running
<code>mtree(1)</code>
on
<b></b><b>DESTDIR</b>,
useful on systems where building as an unprivileged user, or where it is
known that the system-wide mtree files have not changed.
<p>
<em></em><em>Default</em>:
Unset.
<p><dt><b></b><b>NOINCLUDES</b><dd>
If set, avoids the
``make includes''
phase of a full build. This has the effect of preventing
<code>make(1)</code>
from thinking that some programs are out-of-date simply because the
system include files have changed. However, this option should not be
used when updating the entire
NetBSD
source tree arbitrarily; it is suggested to use
<b></b><b>UPDATE</b>
in that case.
<p>
<em></em><em>Default</em>:
Unset.
<p><dt><b></b><b>RELEASEDIR</b><dd>
If set, specifies the directory to which a
<code>release(7)</code>
layout will be written at the end of a
``make release''.
<p>
<em></em><em>Default</em>:
Unset.
<p><dt><b></b><b>UPDATE</b><dd>
If set, then in addition to the effects described for UPDATE above, this
implies the effects of
<b></b><b>NOCLEANDIR</b>.
</dl>
<h3>
BUILDING
</h3>
<h4>
<a name="make command line options">
make command line options
</a>
</h4>
This is only a summary of options available to
<code>make(1)</code>;
only the options used most frequently with
NetBSD
builds are listed here.
<dl compact>
<p><dt><b></b><b>-m</b><em></em><em> dir</em><dd>
Specify the default directory for searching for system Makefile
segments, mainly the
&lt;bsd.*.mk&gt;
files. When building any full
NetBSD
source tree, this should be set to the
``share/mk''
directory in the source tree. (This is set automatically when building
from the top level.)
<p><dt><b></b><b>-n</b><dd>
Display the commands that would have been executed, but do not
actually execute them. This will still cause recursion to take place.
<p><dt><b></b><b>-v</b><em></em><em> var</em><dd>
Print
<code>make(1)</code>'s
idea of the value of
<em></em><em>var</em>.
Does not build any targets.
<p><dt><em></em><em>var=value</em><dd>
Set the variable
<em></em><em>var</em>
to
<em></em><em>value</em>,
overriding any setting specified by the process environment, the
<b></b><b>MAKECONF</b>
configuration file, or the system Makefile segments.
</dl>
<h4>
<a name="make targets">
make targets
</a>
</h4>
These default targets may be built by running
<code>make(1)</code>
in any subtree of the
NetBSD
source code. It is recommended that none of these be used from the top
level Makefile; as a specific exception,
``make obj''
and
``make cleandir''
are useful in that context.
<dl compact>
<p><dt><b></b><b>all</b><dd>
Build programs, libraries, and preformatted documentation.
<p><dt><b></b><b>clean</b><dd>
Remove program and library object code files.
<p><dt><b></b><b>cleandir</b><dd>
Same as
<b></b><b>clean</b>,
but also remove preformatted documentation, dependency files generated
by
``make depend'',
and any other files known to be created at build time.
``make distclean''
may be used as a synonym, for familiarity with a similar well-known
convention.
<p><dt><b></b><b>depend</b><dd>
Create dependency files
<b></b>(<b>.depend</b>)
containing more detailed information about the dependencies of source
code on header files. Allows programs to be recompiled automatically
when a dependency changes.
<p><dt><b></b><b>dependall</b><dd>
Does a
``make depend''
immediately followed by a
``make all''.
This combined target recurses as an atomic unit, so that the
``make depend''
phase can participate in
<b></b><b>make</b><b> -j</b>
parallelism.
<p><dt><b></b><b>includes</b><dd>
Build and install system header files. Typically needed before any
system libraries or programs can be built.
<p><dt><b></b><b>install</b><dd>
Install programs, libraries, and documentation into
<b></b><b>DESTDIR</b>.
<p><dt><b></b><b>lint</b><dd>
Run
<code>lint(1)</code>
against the C source code, where appropriate, and generate
system-installed lint libraries.
<p><dt><b></b><b>obj</b><dd>
Create object directories to be used for built files, instead of
building directly in the source tree.
<p><dt><b></b><b>tags</b><dd>
Create
<code>ctags(1)</code>
searchable function lists usable by the
<code>ex(1)</code>
and
<code>vi(1)</code>
text editors.
</dl>
<h4>
<a name="make targets for the top level">
make targets for the top level
</a>
</h4>
Additional
<code>make(1)</code>
targets are usable specifically from the top source level to facilitate
building the entire
NetBSD
source tree.
<dl compact>
<p><dt><b></b><b>build</b><dd>
Build the entire
NetBSD
system. This orders portions of the source tree such that prerequisites
will be built in the proper order.
<p><dt><b></b><b>release</b><dd>
Do a
``make build'',
then package the system into a standard release layout as described by
<code>release(7)</code>.
This requires that
<b></b><b>RELEASEDIR</b>
be set (see above).
<p><dt><b></b><b>regression-tests</b><dd>
Can only be run after building the regression tests in the directory
``regress''.
Runs the compiled regression tests on the local host.
</dl>
<h4>
<a name="The build.sh script">
The build.sh script
</a>
</h4>
This script file is a Bourne shell script designed to build the
entire
NetBSD
system on any host with a Bourne shell in
<b></b><b>/bin/sh</b>,
including many that are not POSIX compliant. Note that if a host
system's
<b></b><b>/bin/sh</b>
is unusually old and broken, the Korn Shell
<b></b>(<b>/bin/ksh</b>),
if available, may be a usable alternative.
<p>
All cross-compile builds, and most native builds, of the entire system
should make use of
<b></b><b>build.sh</b>
rather than just running
``make''.
This way, the
<code>make(1)</code>
program will be bootstrapped properly, in case the host system has an
older or incompatible
``make''
program.
<p>
When compiling the entire system via
<b></b><b>build.sh</b>,
many
<code>make(1)</code>
variables are set for you in order to help encapsulate the build
process. In particular, both
<b></b><b>USETOOLS</b>
and
<b></b><b>MKTOOLS</b>
are set to
``yes'',
and
<b></b><b>MACHINE_ARCH</b>
(if unset) is deduced from the value of
<b></b><b>MACHINE</b>.
<p>
The variables
<b></b><b>DESTDIR</b>,<b> MACHINE</b>,<b> MACHINE_ARCH</b>,
and
<b></b><b>TOOLDIR</b>
are required in order for
<b></b><b>build.sh</b>
to function, and thus they cannot be set in the configuration file
specified by
<b></b><b>MAKECONF</b>.
They may be set either in the process environment, or via command line
options to
<b></b><b>build.sh</b>.
<p>
The following are available command line options that may be supplied to
<b></b><b>build.sh</b>:
<dl compact>
<p><dt><b></b><b>-a</b><em></em><em> arch</em><dd>
Set the value of
<b></b><b>MACHINE_ARCH</b>
to
<em></em><em>arch</em>.
<p><dt><b></b><b>-D</b><em></em><em> dest</em><dd>
Set the value of
<b></b><b>DESTDIR</b>
to
<em></em><em>dest</em>.
<p><dt><b></b><b>-j</b><em></em><em> njob</em><dd>
Set the value of
<b></b><b>NBUILDJOBS</b>
to
<em></em><em>njob</em>.
This provides similar functionality to the familiar
``make -j'',
but preserves the ordering of the top level
``make build''.
<p><dt><b></b><b>-m</b><em></em><em> mach</em><dd>
Set the value of
<b></b><b>MACHINE</b>
to
<em></em><em>mach</em>.
This will also override any value of
<b></b><b>MACHINE_ARCH</b>
in the process environment with a value deduced from
<em></em><em>mach</em>,
unless
<b></b><b>-a</b>
is specified.
<p><dt><b></b><b>-R</b><em></em><em> rel</em><dd>
Set the value of
<b></b><b>RELEASEDIR</b>
to
<em></em><em>rel</em>.
Setting this option will make
<b></b><b>build.sh</b>
run
``make release''
instead of
``make build''.
<p><dt><b></b><b>-r</b><dd>
Remove the contents of
<b></b><b>DESTDIR</b>
and
<b></b><b>TOOLDIR</b>
before building (provides a clean starting point).
<p><dt><b></b><b>-T</b><em></em><em> tools</em><dd>
Set the value of
<b></b><b>TOOLDIR</b>
to
<em></em><em>tools</em>.
</dl>
<h3>
The nbmake-MACHINE wrapper script
</h3>
If using the
<b></b><b>build.sh</b>
script to build
NetBSD,
a
<b></b><b>nbmake-MACHINE</b>
script will be created in
<b></b><b>TOOLDIR/bin</b>
upon the first build to assist in building subtrees on a cross-compile
host.
<p>
<b></b><b>nbmake-MACHINE</b>
can be invoked in lieu of
<code>make(1)</code>,
and will instead call the up-to-date version of
``nbmake''
installed into
<b></b><b>TOOLDIR/bin</b>
with several key variables pre-set, including
<b></b><b>MACHINE</b>,<b> MACHINE_ARCH</b>,
and
<b></b><b>TOOLDIR</b>.
This script can be symlinked into a directory listed in
<b></b><b>PATH</b>,
or called with an absolute path.
<h3>
SEE ALSO
</h3>
<code>make(1)</code>,
<code>hier(7)</code>,
<code>release(7)</code>
<h3>
BUGS
</h3>
Many platforms are not yet using the
<b></b><b>USE_NEW_TOOLCHAIN</b>
system.
<h3>
HISTORY
</h3>
The
<b></b><b>USE_NEW_TOOLCHAIN</b>
based build scheme was introduced in the
``NetBSD-current''
development sources between
NetBSD1.5
and
NetBSD1.6.
</font></body>