BUILDING revision 1.125
11.104SwizBUILDING(8)                 System Manager's Manual                BUILDING(8)
21.1Stv
31.105SwizNAME
41.122Swiz     BUILDING - Procedure for building NetBSD from source code.
51.1Stv
61.105SwizREQUIREMENTS
71.1Stv     NetBSD is designed to be buildable on most POSIX-compliant host systems.
81.105Swiz     The basic build procedure is the same whether compiling natively (on the
91.105Swiz     same NetBSD architecture) or cross compiling (on another architecture or
101.1Stv     OS).
111.1Stv
121.1Stv     This source tree contains a special subtree, ``tools'', which uses the
131.1Stv     host system to create a build toolchain for the target architecture.  The
141.1Stv     host system must have at least C and C++ compilers in order to create the
151.105Swiz     toolchain (make is not required); all other tools are created as part of
161.53Sreed     the NetBSD build process.  (See the environment variables section below
171.53Sreed     if you need to override or manually select your compilers.)
181.1Stv
191.105SwizFILES
201.105Swiz   Source tree layout
211.105Swiz     doc/BUILDING.mdoc
221.17Swiz                    This document (in -mdoc troff format; the original copy).
231.1Stv
241.105Swiz     BUILDING       This document (in plaintext).
251.1Stv
261.105Swiz     tools/compat/README
271.48Sjmc                    Special notes for cross-hosting a NetBSD build on non-
281.48Sjmc                    NetBSD platforms.
291.48Sjmc
301.105Swiz     Makefile       The main Makefile for NetBSD; should only be run for
311.44Slukem                    native builds with an appropriately up-to-date version of
321.1Stv                    NetBSD make(1).  (For building from out-of-date systems or
331.105Swiz                    on a non-native host, see the build.sh shell script.)
341.1Stv
351.105Swiz     UPDATING       Special notes for updating from an earlier revision of
361.1Stv                    NetBSD.  It is important to read this file before every
371.1Stv                    build of an updated source tree.
381.1Stv
391.105Swiz     build.sh       Bourne-compatible shell script used for building the host
401.1Stv                    build tools and the NetBSD system from scratch.  Can be
411.1Stv                    used for both native and cross builds, and should be used
421.1Stv                    instead of make(1) for any source tree that is updated and
431.1Stv                    recompiled regularly.
441.1Stv
451.105Swiz     crypto/dist/, dist/, gnu/dist/
461.104Swiz                    Sources imported verbatim from third parties, without
471.104Swiz                    mangling the existing build structure.  Other source trees
481.105Swiz                    in bin through usr.sbin use the NetBSD make(1)
491.104Swiz                    ``reachover'' Makefile semantics when building these
501.104Swiz                    programs for a native host.
511.104Swiz
521.106Swiz     external, sys/external
531.106Swiz                    Sources and build infrastructure for components imported
541.106Swiz                    (mostly) unchanged from upstream maintainers, sorted by
551.106Swiz                    applicable license.  This is (slowly) replacing the
561.106Swiz                    crypto/dist, dist, and gnu/dist directories.
571.106Swiz
581.105Swiz     distrib/, etc/
591.104Swiz                    Sources for items used when making a full release
601.105Swiz                    snapshot, such as files installed in DESTDIR/etc on the
611.104Swiz                    destination system, boot media, and release notes.
621.1Stv
631.105Swiz     tests/, regress/
641.70Sdholland                    Regression test harness.  Can be cross-compiled, but only
651.105Swiz                    run natively.  tests/ uses the atf(7) test framework;
661.105Swiz                    regress/ contains older tests that have not yet been
671.70Sdholland                    migrated to atf(7).
681.1Stv
691.105Swiz     sys/           NetBSD kernel sources.
701.1Stv
711.105Swiz     tools/         ``Reachover'' build structure for the host build tools.
721.104Swiz                    This has a special method of determining out-of-date
731.104Swiz                    status.
741.1Stv
751.105Swiz     bin/ ... usr.sbin/
761.1Stv                    Sources to the NetBSD userland (non-kernel) programs.  If
771.1Stv                    any of these directories are missing, they will be skipped
781.1Stv                    during the build.
791.1Stv
801.121Smrg     external/mit/xorg/
811.121Smrg                    ``Reachover'' build structure for modular Xorg; the source
821.121Smrg                    is in X11SRCDIR.
831.49Slukem
841.115Sapb     extsrc/        ``Reachover'' build structure for externally added
851.115Sapb                    programs and libraries; the source is in EXTSRCSRCDIR.
861.115Sapb
871.105Swiz   Build tree layout
881.1Stv     The NetBSD build tree is described in hier(7), and the release layout is
891.1Stv     described in release(7).
901.1Stv
911.105SwizCONFIGURATION
921.105Swiz   Environment variables
931.8Slukem     Several environment variables control the behaviour of NetBSD builds.
941.8Slukem
951.105Swiz     HOST_SH           Path name to a shell available on the host system and
961.96Sapb                       suitable for use during the build.  The NetBSD build
971.96Sapb                       system requires a modern Bourne-like shell with POSIX-
981.96Sapb                       compliant features, and also requires support for the
991.96Sapb                       ``local'' keyword to declare local variables in shell
1001.104Swiz                       functions (which is a widely-implemented but non-
1011.104Swiz                       standardised feature).
1021.96Sapb
1031.96Sapb                       Depending on the host system, a suitable shell may be
1041.105Swiz                       /bin/sh, /usr/xpg4/bin/sh, /bin/ksh (provided it is a
1051.96Sapb                       variant of ksh that supports the ``local'' keyword,
1061.105Swiz                       such as ksh88, but not ksh93), or /usr/local/bin/bash.
1071.96Sapb
1081.105Swiz                       Most parts of the build require HOST_SH to be an
1091.105Swiz                       absolute path; however, build.sh allows it to be a
1101.104Swiz                       simple command name, which will be converted to an
1111.105Swiz                       absolute path by searching the PATH.
1121.58Sapb
1131.105Swiz     HOST_CC           Path name to C compiler used to create the toolchain.
1141.53Sreed
1151.105Swiz     HOST_CXX          Path name to C++ compiler used to create the toolchain.
1161.53Sreed
1171.105Swiz     MACHINE           Machine type, e.g., ``macppc''.
1181.8Slukem
1191.105Swiz     MACHINE_ARCH      Machine architecture, e.g., ``powerpc''.
1201.8Slukem
1211.105Swiz     MAKE              Path name to invoke make(1) as.
1221.8Slukem
1231.105Swiz     MAKEFLAGS         Flags to invoke make(1) with.  Note that build.sh
1241.105Swiz                       ignores the value of MAKEFLAGS passed in the
1251.105Swiz                       environment, but allows MAKEFLAGS to be set via the -V
1261.104Swiz                       option.
1271.8Slukem
1281.105Swiz     MAKEOBJDIR        Directory to use as the .OBJDIR for the current
1291.104Swiz                       directory.  The value is subjected to variable
1301.104Swiz                       expansion by make(1).  Typical usage is to set this
1311.104Swiz                       variable to a value involving the use of
1321.104Swiz                       `${.CURDIR:S...}' or `${.CURDIR:C...}', to derive the
1331.105Swiz                       value of .OBJDIR from the value of .CURDIR.  Used only
1341.105Swiz                       if MAKEOBJDIRPREFIX is not defined.  MAKEOBJDIR can be
1351.105Swiz                       provided only in the environment or via the -O flag of
1361.105Swiz                       build.sh; it cannot usefully be set inside a Makefile,
1371.105Swiz                       including mk.conf or ${MAKECONF}.
1381.8Slukem
1391.105Swiz     MAKEOBJDIRPREFIX  Top level directory of the object directory tree.  The
1401.88Sapb                       value is subjected to variable expansion by make(1).
1411.105Swiz                       build.sh will create the ${MAKEOBJDIRPREFIX} directory
1421.105Swiz                       if necessary, but if make(1) is used without build.sh,
1431.88Sapb                       then rules in <bsd.obj.mk> will abort the build if the
1441.88Sapb                       ${MAKEOBJDIRPREFIX} directory does not exist.  If the
1451.104Swiz                       value is defined and valid, then
1461.105Swiz                       ${MAKEOBJDIRPREFIX}/${.CURDIR} is used as the .OBJDIR
1471.104Swiz                       for the current directory.  The current directory may
1481.105Swiz                       be read only.  MAKEOBJDIRPREFIX can be provided only in
1491.105Swiz                       the environment or via the -M flag of build.sh; it
1501.104Swiz                       cannot usefully be set inside a Makefile, including
1511.105Swiz                       mk.conf or ${MAKECONF}.
1521.104Swiz
1531.105Swiz   "make" variables
1541.104Swiz     Several variables control the behavior of NetBSD builds.  Unless
1551.104Swiz     otherwise specified, these variables may be set in either the process
1561.105Swiz     environment or the make(1) configuration file specified by MAKECONF.
1571.1Stv
1581.107Sapb     BUILDID     Identifier for the build.  If set, this should be a short
1591.107Sapb                 string that is suitable for use as part of a file or
1601.107Sapb                 directory name.  The identifier will be appended to object
1611.107Sapb                 directory names, and can be consulted in the make(1)
1621.104Swiz                 configuration file in order to set additional build
1631.107Sapb                 parameters, such as compiler flags.  It will also be used as
1641.107Sapb                 part of the kernel version string, which can be printed by
1651.107Sapb                 ``uname -v''.
1661.107Sapb
1671.107Sapb                 Default: Unset.
1681.9Sthorpej
1691.108Sapb     BUILDINFO   This may be a multi-line string containing information about
1701.108Sapb                 the build.  This will appear in DESTDIR/etc/release, and it
1711.108Sapb                 will be stored in the buildinfo variable in any kernels that
1721.108Sapb                 are built.  When such kernels are booted, the sysctl(7)
1731.108Sapb                 kern.buildinfo variable will report this value.  The string
1741.108Sapb                 may contain backslash escape sequences, such as ``\\''
1751.108Sapb                 (representing a backslash character) and ``\n'' (representing
1761.108Sapb                 a newline).
1771.108Sapb
1781.108Sapb                 Default: Unset.
1791.108Sapb
1801.105Swiz     BUILDSEED   GCC uses random numbers when compiling C++ code.  This
1811.104Swiz                 variable seeds the gcc random number generator using the
1821.104Swiz                 -frandom-seed flag with this value.  By default, it is set to
1831.104Swiz                 NetBSD-(majorversion).  Using a fixed value causes C++
1841.104Swiz                 binaries to be the same when built from the same sources,
1851.104Swiz                 resulting in identical (reproducible) builds.  Additional
1861.104Swiz                 information is available in the GCC documentation of
1871.104Swiz                 -frandom-seed.
1881.104Swiz
1891.105Swiz     DESTDIR     Directory to contain the built NetBSD system.  If set,
1901.104Swiz                 special options are passed to the compilation tools to
1911.105Swiz                 prevent their default use of the host system's /usr/include,
1921.105Swiz                 /usr/lib, and so forth.  This pathname must be an absolute
1931.105Swiz                 path, and should not end with a slash (/) character.  (For
1941.105Swiz                 installation into the system's root directory, set DESTDIR to
1951.59Sapb                 an empty string, not to ``/'').  The directory must reside on
1961.59Sapb                 a file system which supports long file names and hard links.
1971.1Stv
1981.105Swiz                 Default: Empty string if USETOOLS is ``yes''; unset
1991.104Swiz                 otherwise.
2001.1Stv
2011.105Swiz                 Note: build.sh will provide a default of destdir.MACHINE (in
2021.105Swiz                 the top-level .OBJDIR) unless run in `expert' mode.
2031.30Slukem
2041.115Sapb     EXTSRCSRCDIR
2051.115Sapb                 Directory containing sources of externally added programs and
2061.115Sapb                 libraries.  If specified, must be an absolute path.
2071.115Sapb
2081.115Sapb                 Default: NETBSDRCDIR/../extsrc, if that exists; otherwise
2091.115Sapb                 /usr/extsrc.
2101.115Sapb
2111.105Swiz     MAKECONF    The name of the make(1) configuration file.  Only settable in
2121.105Swiz                 the process environment.
2131.1Stv
2141.105Swiz                 Default: ``/etc/mk.conf''
2151.1Stv
2161.105Swiz     MAKEVERBOSE
2171.45Slukem                 Level of verbosity of status messages.  Supported values:
2181.45Slukem
2191.80Sapb                 0    No descriptive messages or commands executed by make(1)
2201.80Sapb                      are shown.
2211.45Slukem
2221.80Sapb                 1    Brief messages are shown describing what is being done,
2231.104Swiz                      but the actual commands executed by make(1) are not
2241.104Swiz                      displayed.
2251.80Sapb
2261.80Sapb                 2    Descriptive messages are shown as above (prefixed with a
2271.80Sapb                      `#'), and ordinary commands performed by make(1) are
2281.80Sapb                      displayed.
2291.80Sapb
2301.80Sapb                 3    In addition to the above, all commands performed by
2311.80Sapb                      make(1) are displayed, even if they would ordinarily
2321.80Sapb                      have been hidden through use of the ``@'' prefix in the
2331.80Sapb                      relevant makefile.
2341.45Slukem
2351.80Sapb                 4    In addition to the above, commands executed by make(1)
2361.105Swiz                      are traced through use of the sh(1) ``-x'' flag.
2371.45Slukem
2381.105Swiz                 Default: 2
2391.45Slukem
2401.105Swiz     MKCATPAGES  Can be set to ``yes'' or ``no''.  Indicates whether
2411.104Swiz                 preformatted plaintext manual pages will be created during a
2421.104Swiz                 build.
2431.1Stv
2441.105Swiz                 Default: ``no''
2451.1Stv
2461.106Swiz     MKCROSSGDB  Can be set to ``yes'' or ``no''.  Create a cross-gdb as a
2471.106Swiz                 host tool.
2481.106Swiz
2491.106Swiz                 Default: ``no''
2501.106Swiz
2511.105Swiz     MKCRYPTO    Can be set to ``yes'' or ``no''.  Indicates whether
2521.104Swiz                 cryptographic code will be included in a build; provided for
2531.104Swiz                 the benefit of countries that do not allow strong
2541.104Swiz                 cryptography.  Will not affect use of the standard low-
2551.104Swiz                 security password encryption system, crypt(3).
2561.1Stv
2571.105Swiz                 Default: ``yes''
2581.1Stv
2591.106Swiz     MKDEBUG     Can be set to ``yes'' or ``no''.  Indicates whether debug
2601.106Swiz                 information should be generated for all userland binaries
2611.106Swiz                 compiled.  The result is collected as an additional debug.tgz
2621.106Swiz                 and xdebug.tgz set and installed in /usr/libdata/debug.
2631.106Swiz
2641.106Swiz                 Default: ``no''
2651.106Swiz
2661.106Swiz     MKDEBUGLIB  Can be set to ``yes'' or ``no''.  Indicates whether debug
2671.106Swiz                 information (see MKDEBUG) should also be generated for all
2681.106Swiz                 libraries build.
2691.106Swiz
2701.106Swiz                 Default: ``no''
2711.106Swiz
2721.105Swiz     MKDOC       Can be set to ``yes'' or ``no''.  Indicates whether system
2731.105Swiz                 documentation destined for DESTDIR/usr/share/doc will be
2741.44Slukem                 installed during a build.
2751.1Stv
2761.105Swiz                 Default: ``yes''
2771.1Stv
2781.115Sapb     MKEXTSRC    Can be set to ``yes'' or ``no''.  Indicates whether extsrc is
2791.115Sapb                 built from EXTSRCSRCDIR.
2801.115Sapb
2811.115Sapb                 Default: ``no''
2821.115Sapb
2831.105Swiz     MKHTML      Can be set to ``yes'' or ``no''.  Indicates whether
2841.104Swiz                 preformatted HTML manual pages will be built and installed
2851.77Slukem
2861.105Swiz                 Default: ``yes''
2871.77Slukem
2881.105Swiz     MKHOSTOBJ   Can be set to ``yes'' or ``no''.  If set to ``yes'', then for
2891.4Stv                 programs intended to be run on the compile host, the name,
2901.4Stv                 release, and architecture of the host operating system will
2911.4Stv                 be suffixed to the name of the object directory created by
2921.4Stv                 ``make obj''.  (This allows multiple host systems to compile
2931.4Stv                 NetBSD for a single target.)  If set to ``no'', then programs
2941.4Stv                 built to be run on the compile host will use the same object
2951.4Stv                 directory names as programs built to be run on the target.
2961.4Stv
2971.105Swiz                 Default: ``no''
2981.4Stv
2991.105Swiz     MKINFO      Can be set to ``yes'' or ``no''.  Indicates whether GNU Info
3001.1Stv                 files, used for the documentation for most of the compilation
3011.1Stv                 tools, will be created and installed during a build.
3021.1Stv
3031.105Swiz                 Default: ``yes''
3041.1Stv
3051.106Swiz     MKKDEBUG    Can be set to ``yes'' or ``no''.  Force generation of full-
3061.106Swiz                 debug symbol versions of all kernels compiled.  Alongside of
3071.106Swiz                 the netbsd kernel file, an unstripped version netbsd.gdb is
3081.106Swiz                 created.  This is useful if a cross-gdb is built as well (see
3091.106Swiz                 MKCROSSGDB).
3101.106Swiz
3111.106Swiz                 Default: ``no''
3121.106Swiz
3131.105Swiz     MKKMOD      Can be set to ``yes'' or ``no''.  Indicates whether kernel
3141.95Sapb                 modules are built and installed.
3151.95Sapb
3161.105Swiz                 Default: ``yes''
3171.95Sapb
3181.105Swiz     MKLINT      Can be set to ``yes'' or ``no''.  Indicates whether lint(1)
3191.1Stv                 will be run against portions of the NetBSD source code during
3201.1Stv                 the build, and whether lint libraries will be installed into
3211.105Swiz                 DESTDIR/usr/libdata/lint.
3221.1Stv
3231.105Swiz                 Default: ``yes''
3241.1Stv
3251.105Swiz     MKMAN       Can be set to ``yes'' or ``no''.  Indicates whether manual
3261.1Stv                 pages will be installed during a build.
3271.1Stv
3281.105Swiz                 Default: ``yes''
3291.1Stv
3301.105Swiz     MKNLS       Can be set to ``yes'' or ``no''.  Indicates whether Native
3311.44Slukem                 Language System locale zone files will be compiled and
3321.44Slukem                 installed during a build.
3331.1Stv
3341.105Swiz                 Default: ``yes''
3351.1Stv
3361.105Swiz     MKOBJ       Can be set to ``yes'' or ``no''.  Indicates whether object
3371.1Stv                 directories will be created when running ``make obj''.  If
3381.1Stv                 set to ``no'', then all built files will be located inside
3391.1Stv                 the regular source tree.
3401.1Stv
3411.105Swiz                 Default: ``yes''
3421.1Stv
3431.105Swiz                 Note that setting MKOBJ to ``no'' is not recommended and may
3441.70Sdholland                 cause problems when updating the tree with cvs(1).
3451.70Sdholland
3461.105Swiz     MKPIC       Can be set to ``yes'' or ``no''.  Indicates whether shared
3471.1Stv                 objects and libraries will be created and installed during a
3481.1Stv                 build.  If set to ``no'', the entire built system will be
3491.1Stv                 statically linked.
3501.1Stv
3511.105Swiz                 Default: Platform dependent.  As of this writing, all
3521.123Srin                 platforms except m68000 default to ``yes''.
3531.1Stv
3541.105Swiz     MKPICINSTALL
3551.1Stv                 Can be set to ``yes'' or ``no''.  Indicates whether the ar(1)
3561.105Swiz                 format libraries (lib*_pic.a), used to generate shared
3571.44Slukem                 libraries, are installed during a build.
3581.1Stv
3591.105Swiz                 Default: ``yes''
3601.1Stv
3611.105Swiz     MKPROFILE   Can be set to ``yes'' or ``no''.  Indicates whether profiled
3621.105Swiz                 libraries (lib*_p.a) will be built and installed during a
3631.1Stv                 build.
3641.1Stv
3651.105Swiz                 Default: ``yes''; however, some platforms turn off MKPROFILE
3661.1Stv                 by default at times due to toolchain problems with profiled
3671.1Stv                 code.
3681.1Stv
3691.124Schristos     MKREPRO     Can be set to ``yes'' or ``no''.  Create reproducible builds.
3701.100Swiz                 This enables different switches to make two builds from the
3711.100Swiz                 same source tree result in the same build results.
3721.100Swiz
3731.124Schristos                 Default: ``no'' This may be set to ``yes'' by giving build.sh
3741.124Schristos                 the -P option.
3751.100Swiz
3761.122Swiz     MKREPRO_TIMESTAMP
3771.122Swiz                 Unix timestamp.  When MKREPRO is set, the timestamp of all
3781.122Swiz                 files in the sets will be set to this value.
3791.122Swiz
3801.124Schristos                 Default: Unset.  This may be set automatically to the latest
3811.124Schristos                 source tree timestamp using cvslatest(1) by giving build.sh
3821.124Schristos                 the -P option.
3831.122Swiz
3841.105Swiz     MKSHARE     Can be set to ``yes'' or ``no''.  Indicates whether files
3851.105Swiz                 destined to reside in DESTDIR/usr/share will be built and
3861.44Slukem                 installed during a build.  If set to ``no'', then all of
3871.105Swiz                 MKCATPAGES, MKDOC, MKINFO, MKMAN, and MKNLS will be set to
3881.27Slukem                 ``no'' unconditionally.
3891.1Stv
3901.105Swiz                 Default: ``yes''
3911.1Stv
3921.105Swiz     MKSTRIPIDENT
3931.102Sabs                 Can be set to ``yes'' or ``no''.  Indicates whether RCS IDs,
3941.104Swiz                 for use with ident(1), should be stripped from program
3951.104Swiz                 binaries and shared libraries.
3961.78Sapb
3971.105Swiz                 Default: ``no''
3981.78Sapb
3991.125Sozaki     MKSTRIPSYM  Can be set to ``yes'' or ``no''.  Indicates whether all local
4001.125Sozaki                 symbols should be stripped from shared libraries.  If ``yes'',
4011.125Sozaki                 strip all local symbols from shared libraries; the affect is
4021.125Sozaki                 equivalent to -x option of ld(1). If ``no'', strip only
4031.125Sozaki                 temporary local symbols; the affect is equivalent to -X
4041.125Sozaki                 option of ld(1). Keeping non-temporary local symbols such as
4051.125Sozaki                 static function names is useful on using DTrace for userland
4061.125Sozaki                 libraries and getting a backtrace from a rump kernel loading
4071.125Sozaki                 shared libraries.
4081.125Sozaki
4091.125Sozaki                 Default: ``yes''
4101.125Sozaki
4111.105Swiz     MKUNPRIVED  Can be set to ``yes'' or ``no''.  Indicates whether an
4121.104Swiz                 unprivileged install will occur.  The user, group,
4131.104Swiz                 permissions, and file flags, will not be set on the installed
4141.52Sjmc                 items; instead the information will be appended to a file
4151.105Swiz                 called METALOG in DESTDIR.  The contents of METALOG are used
4161.52Sjmc                 during the generation of the distribution tar files to ensure
4171.52Sjmc                 that the appropriate file ownership is stored.
4181.38Slukem
4191.105Swiz                 Default: ``no''
4201.38Slukem
4211.105Swiz     MKUPDATE    Can be set to ``yes'' or ``no''.  Indicates whether all
4221.105Swiz                 install operations intended to write to DESTDIR will compare
4231.38Slukem                 file timestamps before installing, and skip the install phase
4241.44Slukem                 if the destination files are up-to-date.  This also has
4251.44Slukem                 implications on full builds (see next subsection).
4261.38Slukem
4271.105Swiz                 Default: ``no''
4281.38Slukem
4291.105Swiz     MKX11       Can be set to ``yes'' or ``no''.  Indicates whether X11 is
4301.105Swiz                 built from X11SRCDIR.
4311.49Slukem
4321.105Swiz                 Default: ``no''
4331.49Slukem
4341.105Swiz     TOOLDIR     Directory to hold the host tools, once built.  If specified,
4351.59Sapb                 must be an absolute path.  This directory should be unique to
4361.104Swiz                 a given host system and NetBSD source tree.  (However,
4371.105Swiz                 multiple targets may share the same TOOLDIR; the target-
4381.104Swiz                 dependent files have unique names.)  If unset, a default
4391.104Swiz                 based on the uname(1) information of the host platform will
4401.105Swiz                 be created in the .OBJDIR of src.
4411.1Stv
4421.105Swiz                 Default: Unset.
4431.1Stv
4441.105Swiz     USETOOLS    Indicates whether the tools specified by TOOLDIR should be
4451.1Stv                 used as part of a build in progress.  Must be set to ``yes''
4461.1Stv                 if cross-compiling.
4471.1Stv
4481.105Swiz                 yes    Use the tools from TOOLDIR.
4491.1Stv
4501.105Swiz                 no     Do not use the tools from TOOLDIR, but refuse to build
4511.1Stv                        native compilation tool components that are version-
4521.1Stv                        specific for that tool.
4531.1Stv
4541.105Swiz                 never  Do not use the tools from TOOLDIR, even when building
4551.104Swiz                        native tool components.  This is similar to the
4561.105Swiz                        traditional NetBSD build method, but does not verify
4571.104Swiz                        that the compilation tools in use are up-to-date
4581.104Swiz                        enough in order to build the tree successfully.  This
4591.104Swiz                        may cause build or runtime problems when building the
4601.104Swiz                        whole NetBSD source tree.
4611.1Stv
4621.105Swiz                 Default: ``yes'', unless TOOLCHAIN_MISSING is set to ``yes''.
4631.71Sdholland
4641.105Swiz                 USETOOLS is also set to ``no'' when using <bsd.*.mk> outside
4651.71Sdholland                 the NetBSD source tree.
4661.1Stv
4671.121Smrg     X11SRCDIR   Directory containing the modular Xorg source.  If specified,
4681.121Smrg                 must be an absolute path.  The main modular Xorg source is
4691.121Smrg                 found in X11SRCDIR/external/mit.
4701.49Slukem
4711.105Swiz                 Default: NETBSDRCDIR/../xsrc, if that exists; otherwise
4721.105Swiz                 /usr/xsrc.
4731.49Slukem
4741.105Swiz   "make" variables for full builds
4751.7Slukem     These variables only affect the top level ``Makefile'' and do not affect
4761.7Slukem     manually building subtrees of the NetBSD source code.
4771.1Stv
4781.105Swiz     INSTALLWORLDDIR  Location for the ``make installworld'' target to install
4791.59Sapb                      to.  If specified, must be an absolute path.
4801.1Stv
4811.105Swiz                      Default: ``/''
4821.1Stv
4831.105Swiz     MKOBJDIRS        Can be set to ``yes'' or ``no''.  Indicates whether
4841.44Slukem                      object directories will be created automatically (via a
4851.20Slukem                      ``make obj'' pass) at the start of a build.
4861.1Stv
4871.105Swiz                      Default: ``no''
4881.1Stv
4891.105Swiz                      If using build.sh, the default is ``yes''.  This may be
4901.105Swiz                      set back to ``no'' by giving build.sh the -o option.
4911.70Sdholland
4921.105Swiz     MKUPDATE         Can be set to ``yes'' or ``no''.  If set, then in
4931.105Swiz                      addition to the effects described for MKUPDATE=yes
4941.105Swiz                      above, this implies the effects of NOCLEANDIR (i.e.,
4951.104Swiz                      ``make cleandir'' is avoided).
4961.38Slukem
4971.105Swiz                      Default: ``no''
4981.38Slukem
4991.105Swiz                      If using build.sh, this may be set by giving the -u
5001.70Sdholland                      option.
5011.70Sdholland
5021.105Swiz     NBUILDJOBS       Now obsolete.  Use the make(1) option -j, instead.  See
5031.70Sdholland                      below.
5041.1Stv
5051.105Swiz                      Default: Unset.
5061.1Stv
5071.105Swiz     NOCLEANDIR       If set, avoids the ``make cleandir'' phase of a full
5081.20Slukem                      build.  This has the effect of allowing only changed
5091.20Slukem                      files in a source tree to be recompiled.  This can speed
5101.20Slukem                      up builds when updating only a few files in the tree.
5111.1Stv
5121.105Swiz                      Default: Unset.
5131.1Stv
5141.105Swiz                      See also MKUPDATE.
5151.70Sdholland
5161.105Swiz     NODISTRIBDIRS    If set, avoids the ``make distrib-dirs'' phase of a full
5171.105Swiz                      build.  This skips running mtree(8) on DESTDIR, useful
5181.20Slukem                      on systems where building as an unprivileged user, or
5191.20Slukem                      where it is known that the system-wide mtree files have
5201.20Slukem                      not changed.
5211.1Stv
5221.105Swiz                      Default: Unset.
5231.1Stv
5241.105Swiz     NOINCLUDES       If set, avoids the ``make includes'' phase of a full
5251.20Slukem                      build.  This has the effect of preventing make(1) from
5261.44Slukem                      thinking that some programs are out-of-date simply
5271.44Slukem                      because the system include files have changed.  However,
5281.20Slukem                      this option should not be used when updating the entire
5291.20Slukem                      NetBSD source tree arbitrarily; it is suggested to use
5301.105Swiz                      MKUPDATE=yes instead in that case.
5311.1Stv
5321.105Swiz                      Default: Unset.
5331.1Stv
5341.105Swiz     RELEASEDIR       If set, specifies the directory to which a release(7)
5351.20Slukem                      layout will be written at the end of a ``make release''.
5361.59Sapb                      If specified, must be an absolute path.
5371.20Slukem
5381.105Swiz                      Default: Unset.
5391.20Slukem
5401.105Swiz                      Note: build.sh will provide a default of releasedir (in
5411.105Swiz                      the top-level .OBJDIR) unless run in `expert' mode.
5421.30Slukem
5431.105SwizBUILDING
5441.105Swiz   "make" command line options
5451.52Sjmc     This is not a summary of all the options available to make(1); only the
5461.52Sjmc     options used most frequently with NetBSD builds are listed here.
5471.1Stv
5481.105Swiz     -j njob    Run up to njob make(1) subjobs in parallel.  Makefiles should
5491.52Sjmc                use .WAIT or have explicit dependencies as necessary to
5501.74Sapb                enforce build ordering.
5511.10Ssommerfe
5521.105Swiz     -m dir     Specify the default directory for searching for system
5531.104Swiz                Makefile segments, mainly the <bsd.*.mk> files.  When building
5541.104Swiz                any full NetBSD source tree, this should be set to the
5551.104Swiz                ``share/mk'' directory in the source tree.  This is set
5561.104Swiz                automatically when building from the top level, or when using
5571.105Swiz                build.sh.
5581.1Stv
5591.105Swiz     -n         Display the commands that would have been executed, but do not
5601.1Stv                actually execute them.  This will still cause recursion to
5611.1Stv                take place.
5621.1Stv
5631.105Swiz     -V var     Print make(1)'s idea of the value of var.  Does not build any
5641.1Stv                targets.
5651.1Stv
5661.105Swiz     var=value  Set the variable var to value, overriding any setting
5671.105Swiz                specified by the process environment, the MAKECONF
5681.104Swiz                configuration file, or the system Makefile segments.
5691.1Stv
5701.105Swiz   "make" targets
5711.1Stv     These default targets may be built by running make(1) in any subtree of
5721.1Stv     the NetBSD source code.  It is recommended that none of these be used
5731.1Stv     from the top level Makefile; as a specific exception, ``make obj'' and
5741.1Stv     ``make cleandir'' are useful in that context.
5751.1Stv
5761.105Swiz     all        Build programs, libraries, and preformatted documentation.
5771.1Stv
5781.105Swiz     clean      Remove program and library object code files.
5791.1Stv
5801.105Swiz     cleandir   Same as clean, but also remove preformatted documentation,
5811.44Slukem                dependency files generated by ``make depend'', and any other
5821.49Slukem                files known to be created at build time.
5831.1Stv
5841.105Swiz     depend     Create dependency files (.depend) containing more detailed
5851.44Slukem                information about the dependencies of source code on header
5861.1Stv                files.  Allows programs to be recompiled automatically when a
5871.1Stv                dependency changes.
5881.1Stv
5891.105Swiz     dependall  Does a ``make depend'' immediately followed by a ``make all''.
5901.10Ssommerfe                This improves cache locality of the build since both passes
5911.10Ssommerfe                read the source files in their entirety.
5921.1Stv
5931.105Swiz     distclean  Synonym for cleandir.
5941.49Slukem
5951.105Swiz     includes   Build and install system header files.  Typically needed
5961.44Slukem                before any system libraries or programs can be built.
5971.1Stv
5981.105Swiz     install    Install programs, libraries, and documentation into DESTDIR.
5991.105Swiz                Few files will be installed to DESTDIR/dev, DESTDIR/etc,
6001.105Swiz                DESTDIR/root or DESTDIR/var in order to prevent user supplied
6011.27Slukem                configuration data from being overwritten.
6021.1Stv
6031.105Swiz     lint       Run lint(1) against the C source code, where appropriate, and
6041.1Stv                generate system-installed lint libraries.
6051.1Stv
6061.105Swiz     obj        Create object directories to be used for built files, instead
6071.1Stv                of building directly in the source tree.
6081.1Stv
6091.105Swiz     tags       Create ctags(1) searchable function lists usable by the ex(1)
6101.1Stv                and vi(1) text editors.
6111.1Stv
6121.105Swiz   "make" targets for the top level
6131.1Stv     Additional make(1) targets are usable specifically from the top source
6141.1Stv     level to facilitate building the entire NetBSD source tree.
6151.1Stv
6161.105Swiz     build         Build the entire NetBSD system (except the kernel).  This
6171.68Sreed                   orders portions of the source tree such that prerequisites
6181.68Sreed                   will be built in the proper order.
6191.20Slukem
6201.105Swiz     distribution  Do a ``make build'', and then install a full distribution
6211.105Swiz                   (which does not include a kernel) into DESTDIR, including
6221.105Swiz                   files in DESTDIR/dev, DESTDIR/etc, DESTDIR/root and
6231.105Swiz                   DESTDIR/var.
6241.20Slukem
6251.105Swiz     buildworld    As per ``make distribution'', except that it ensures that
6261.105Swiz                   DESTDIR is not the root directory.
6271.20Slukem
6281.105Swiz     installworld  Install the distribution from DESTDIR to INSTALLWORLDDIR,
6291.70Sdholland                   which defaults to the root directory.  Ensures that
6301.105Swiz                   INSTALLWORLDDIR is not the root directory if cross
6311.104Swiz                   compiling.
6321.20Slukem
6331.105Swiz                   The INSTALLSETS environment variable may be set to a space-
6341.95Sapb                   separated list of distribution sets to be installed.  By
6351.95Sapb                   default, all sets except ``etc'' and ``xetc'' are
6361.105Swiz                   installed, so most files in INSTALLWORLDDIR/etc will not be
6371.95Sapb                   installed or modified.
6381.61Sapb
6391.105Swiz                   Note: Before performing this operation with
6401.105Swiz                   INSTALLWORLDDIR=/, it is highly recommended that you
6411.61Sapb                   upgrade your kernel and reboot.  After performing this
6421.61Sapb                   operation, it is recommended that you use etcupdate(8) to
6431.105Swiz                   update files in INSTALLWORLDDIR/etc, and postinstall(8) to
6441.102Sabs                   check for or fix inconsistencies.
6451.20Slukem
6461.105Swiz     sets          Create distribution sets from DESTDIR into
6471.105Swiz                   RELEASEDIR/RELEASEMACHINEDIR/binary/sets.  Should be run
6481.70Sdholland                   after ``make distribution'', as ``make build'' alone does
6491.70Sdholland                   not install all of the required files.
6501.25Slukem
6511.105Swiz     sourcesets    Create source sets of the source tree into
6521.105Swiz                   RELEASEDIR/source/sets.
6531.31Slukem
6541.105Swiz     syspkgs       Create syspkgs from DESTDIR into
6551.105Swiz                   RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.  Should be run
6561.70Sdholland                   after ``make distribution'', as ``make build'' alone does
6571.70Sdholland                   not install all of the required files.
6581.54Sapb
6591.105Swiz     release       Do a ``make distribution'', build kernels, distribution
6601.44Slukem                   media, and install sets (this as per ``make sets''), and
6611.44Slukem                   then package the system into a standard release layout as
6621.105Swiz                   described by release(7).  This requires that RELEASEDIR be
6631.25Slukem                   set (see above).
6641.1Stv
6651.105Swiz     iso-image     Create a NetBSD installation CD-ROM image in the
6661.114Ssnj                   RELEASEDIR/images directory.  The CD-ROM file system will
6671.114Ssnj                   have a layout as described in release(7).
6681.62Sapb
6691.62Sapb                   For most machine types, the CD-ROM will be bootable, and
6701.104Swiz                   will automatically run the sysinst(8) menu-based
6711.104Swiz                   installation program, which can be used to install or
6721.104Swiz                   upgrade a NetBSD system.  Bootable CD-ROMs also contain
6731.104Swiz                   tools that may be useful in repairing a damaged NetBSD
6741.104Swiz                   installation.
6751.62Sapb
6761.62Sapb                   Before ``make iso-image'' is attempted, RELEASEDIR must be
6771.62Sapb                   populated by ``make release'' or equivalent.
6781.62Sapb
6791.62Sapb                   Note that other, smaller, CD-ROM images may be created in
6801.105Swiz                   the RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom
6811.104Swiz                   directory by ``make release''.  These smaller images
6821.104Swiz                   usually contain the same tools as the larger images in
6831.114Ssnj                   RELEASEDIR/images, but do not contain additional content
6841.114Ssnj                   such as the distribution sets.
6851.62Sapb
6861.62Sapb                   Note that the mac68k port still uses an older method of
6871.104Swiz                   creating CD-ROM images.  This requires the mkisofs(1)
6881.104Swiz                   utility, which is not part of NetBSD, but which can be
6891.105Swiz                   installed from pkgsrc/sysutils/cdrtools.
6901.56Sapb
6911.105Swiz     iso-image-source
6921.64Sjnemeth                   Create a NetBSD installation CD-ROM image in the
6931.114Ssnj                   RELEASEDIR/images directory.  The CD-ROM file system will
6941.114Ssnj                   have a layout as described in release(7).  It will have top
6951.64Sjnemeth                   level directories for the machine type and source.
6961.64Sjnemeth
6971.64Sjnemeth                   For most machine types, the CD-ROM will be bootable, and
6981.104Swiz                   will automatically run the sysinst(8) menu-based
6991.104Swiz                   installation program, which can be used to install or
7001.104Swiz                   upgrade a NetBSD system.  Bootable CD-ROMs also contain
7011.104Swiz                   tools that may be useful in repairing a damaged NetBSD
7021.104Swiz                   installation.
7031.64Sjnemeth
7041.64Sjnemeth                   Before ``make iso-image-source'' is attempted, RELEASEDIR
7051.104Swiz                   must be populated by ``make sourcesets release'' or
7061.104Swiz                   equivalent.
7071.64Sjnemeth
7081.64Sjnemeth                   Note that other, smaller, CD-ROM images may be created in
7091.105Swiz                   the RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom
7101.104Swiz                   directory by ``make release''.  These smaller images
7111.104Swiz                   usually contain the same tools as the larger images in
7121.114Ssnj                   RELEASEDIR/images, but do not contain additional content
7131.114Ssnj                   such as the distribution sets.
7141.64Sjnemeth
7151.64Sjnemeth                   Note that the mac68k port still uses an older method of
7161.104Swiz                   creating CD-ROM images.  This requires the mkisofs(1)
7171.104Swiz                   utility, which is not part of NetBSD, but which can be
7181.105Swiz                   installed from pkgsrc/sysutils/cdrtools.
7191.64Sjnemeth
7201.105Swiz     install-image
7211.98Sapb                   Create a bootable NetBSD installation disk image in the
7221.105Swiz                   RELEASEDIR/RELEASEMACHINEDIR/installation/installimage
7231.98Sapb                   directory.  The installation disk image is suitable for
7241.98Sapb                   copying to bootable USB flash memory sticks, etc., for
7251.98Sapb                   machines which are able to boot from such devices.  The
7261.98Sapb                   file system in the bootable disk image will have a layout
7271.98Sapb                   as described in release(7).
7281.97Stsutsui
7291.97Stsutsui                   The installation image is bootable, and will automatically
7301.97Stsutsui                   run the sysinst(8) menu-based installation program, which
7311.98Sapb                   can be used to install or upgrade a NetBSD system.  The
7321.98Sapb                   image also contains tools that may be useful in repairing a
7331.98Sapb                   damaged NetBSD installation.
7341.97Stsutsui
7351.105Swiz                   Before ``make install-image'' is attempted, RELEASEDIR must
7361.98Sapb                   be populated by ``make release'' or equivalent.  The build
7371.105Swiz                   must have been performed with MKUNPRIVED=yes because ``make
7381.105Swiz                   install-image'' relies on information in DESTDIR/METALOG.
7391.97Stsutsui
7401.120Spgoyette     live-image    Create NetBSD live images in the RELEASEDIR/images
7411.104Swiz                   directory.  The live image contains all necessary files to
7421.104Swiz                   boot NetBSD up to multi-user mode, including all files
7431.104Swiz                   which should be extracted during installation, NetBSD
7441.104Swiz                   disklabel, bootloaders, etc.
7451.104Swiz
7461.104Swiz                   The live image is suitable for use as a disk image in
7471.104Swiz                   virtual machine environments such as QEMU, and also useful
7481.104Swiz                   to boot NetBSD from a USB flash memory stick on a real
7491.98Sapb                   machine, without the need for installation.
7501.97Stsutsui
7511.97Stsutsui                   Before ``make live-image'' is attempted, RELEASEDIR must be
7521.99Stsutsui                   populated by ``make release'' or equivalent.  The build
7531.105Swiz                   must have been performed with MKUNPRIVED=yes because ``make
7541.105Swiz                   install-image'' relies on information in DESTDIR/METALOG.
7551.97Stsutsui
7561.105Swiz     regression-tests
7571.20Slukem                   Can only be run after building the regression tests in the
7581.70Sdholland                   directory ``regress''.  Runs those compiled regression
7591.104Swiz                   tests on the local host.  Note that most tests are now
7601.104Swiz                   managed instead using atf(7); this target should probably
7611.104Swiz                   run those as well but currently does not.
7621.1Stv
7631.105Swiz   The "build.sh" script
7641.96Sapb     This script file is a shell script designed to build the entire NetBSD
7651.104Swiz     system on any host with a suitable modern shell and some common
7661.105Swiz     utilities.  The required shell features are described under the HOST_SH
7671.104Swiz     variable.
7681.96Sapb
7691.96Sapb     If a host system's default shell does support the required features, then
7701.96Sapb     we suggest that you explicitly specify a suitable shell using a command
7711.96Sapb     like
7721.96Sapb
7731.105Swiz           /path/to/suitable/shell build.sh [options]
7741.96Sapb
7751.105Swiz     The above command will usually enable build.sh to automatically set
7761.105Swiz     HOST_SH=/path/to/suitable/shell, but if that fails, then the following
7771.96Sapb     set of commands may be used instead:
7781.96Sapb
7791.105Swiz           HOST_SH=/path/to/suitable/shell
7801.96Sapb           export HOST_SH
7811.105Swiz           ${HOST_SH} build.sh [options]
7821.96Sapb
7831.105Swiz     If build.sh detects that it is being executed under an unsuitable shell,
7841.96Sapb     it attempts to exec a suitable shell instead, or prints an error message.
7851.105Swiz     If HOST_SH is not set explicitly, then build.sh sets a default using
7861.96Sapb     heuristics dependent on the host platform, or from the shell under which
7871.105Swiz     build.sh is executed (if that can be determined), or using the first copy
7881.105Swiz     of sh found in PATH.
7891.1Stv
7901.1Stv     All cross-compile builds, and most native builds, of the entire system
7911.105Swiz     should make use of build.sh rather than just running ``make''.  This way,
7921.104Swiz     the make(1) program will be bootstrapped properly, in case the host
7931.104Swiz     system has an older or incompatible ``make'' program.
7941.1Stv
7951.105Swiz     When compiling the entire system via build.sh, many make(1) variables are
7961.1Stv     set for you in order to help encapsulate the build process.  In the list
7971.105Swiz     of options below, variables that are automatically set by build.sh are
7981.1Stv     noted where applicable.
7991.1Stv
8001.105Swiz     The following operations are supported by build.sh:
8011.22Slukem
8021.105Swiz     build         Build the system as per ``make build''.  Before the main
8031.105Swiz                   part of the build commences, this command runs the obj
8041.105Swiz                   operation (unless the -o option is given), ``make
8051.105Swiz                   cleandir'' (unless the -u option is given), and the tools
8061.70Sdholland                   operation.
8071.22Slukem
8081.105Swiz     distribution  Build a full distribution as per ``make distribution''.
8091.105Swiz                   This command first runs the build operation.
8101.22Slukem
8111.105Swiz     release       Build a full release as per ``make release''.  This command
8121.105Swiz                   first runs the distribution operation.
8131.22Slukem
8141.105Swiz     makewrapper   Create the nbmake-MACHINE wrapper.  This operation is
8151.104Swiz                   automatically performed for any of the other operations.
8161.23Slukem
8171.105Swiz     cleandir      Perform ``make cleandir''.
8181.75Slukem
8191.105Swiz     obj           Perform ``make obj''.
8201.22Slukem
8211.105Swiz     tools         Build and install the host tools from src/tools.  This
8221.104Swiz                   command will first run ``make obj'' and ``make cleandir''
8231.105Swiz                   in the tools subdirectory unless the -o or -u options
8241.104Swiz                   (respectively) are given.
8251.22Slukem
8261.105Swiz     install=idir  Install the contents of DESTDIR to idir, using ``make
8271.61Sapb                   installworld''.  Note that files that are part of the
8281.95Sapb                   ``etc'' or ``xetc'' sets will not be installed, unless
8291.95Sapb                   overridden by the INSTALLSETS environment variable.
8301.35Slukem
8311.105Swiz     kernel=kconf  Build a new kernel.  The kconf argument is the name of a
8321.105Swiz                   configuration file suitable for use by config(1).  If kconf
8331.22Slukem                   does not contain any `/' characters, the configuration file
8341.105Swiz                   is expected to be found in the KERNCONFDIR directory, which
8351.105Swiz                   is typically sys/arch/MACHINE/conf.  The new kernel will be
8361.105Swiz                   built in a subdirectory of KERNOBJDIR, which is typically
8371.105Swiz                   sys/arch/MACHINE/compile or an associated object directory.
8381.70Sdholland
8391.105Swiz                   This command does not imply the tools command; run the
8401.105Swiz                   tools command first unless it is certain that the tools
8411.70Sdholland                   already exist and are up to date.
8421.70Sdholland
8431.70Sdholland                   This command will run ``make cleandir'' on the kernel in
8441.105Swiz                   question first unless the -u option is given.
8451.22Slukem
8461.106Swiz     kernel.gdb=kconf
8471.106Swiz                   Build a new kernel with debug information.  Similar to the
8481.106Swiz                   above kernel=kconf operation, but creates a netbsd.gdb file
8491.106Swiz                   alongside of the kernel netbsd, which contains a full
8501.106Swiz                   symbol table and can be used for debugging (for example
8511.106Swiz                   with a cross-gdb built by MKCROSSGDB).
8521.106Swiz
8531.113Suebayasi     kernels       This command will build all kernels defined in port
8541.113Suebayasi                   specific release build procedure.
8551.111Suebayasi
8561.112Suebayasi                   This command internally calls the kernel=kconf operation
8571.112Suebayasi                   for each found kernel configuration file.
8581.111Suebayasi
8591.105Swiz     modules       This command will build kernel modules and install them
8601.105Swiz                   into DESTDIR.
8611.86Sjnemeth
8621.105Swiz     releasekernel=kconf
8631.70Sdholland                   Install a gzip(1)ed copy of the kernel previously built by
8641.105Swiz                   kernel=kconf into
8651.105Swiz                   RELEASEDIR/RELEASEMACHINEDIR/binary/kernel, usually as
8661.105Swiz                   netbsd-kconf.gz, although the ``netbsd'' prefix is
8671.105Swiz                   determined from the ``config'' directives in kconf.
8681.24Slukem
8691.105Swiz     sets          Perform ``make sets''.
8701.31Slukem
8711.105Swiz     sourcesets    Perform ``make sourcesets''.
8721.22Slukem
8731.105Swiz     syspkgs       Perform ``make syspkgs''.
8741.54Sapb
8751.105Swiz     iso-image     Perform ``make iso-image''.
8761.56Sapb
8771.105Swiz     iso-image-source
8781.65Sjnemeth                   Perform ``make iso-image-source''.
8791.65Sjnemeth
8801.105Swiz     install-image
8811.98Sapb                   Perform ``make install-image''.
8821.97Stsutsui
8831.105Swiz     live-image    Perform ``make live-image''.
8841.97Stsutsui
8851.109Sapb     list-arch     Prints a list of valid MACHINE and MACHINE_ARCH settings,
8861.109Sapb                   the default MACHINE_ARCH for each MACHINE, and aliases for
8871.109Sapb                   MACHINE/MACHINE_ARCH pairs, and then exits.  The -m or -a
8881.109Sapb                   options (or both) may be used to specify glob patterns that
8891.109Sapb                   will be used to narrow the list of results; for example,
8901.109Sapb                   ``build.sh -m 'evm*' -a '*arm*' list-arch'' will list all
8911.109Sapb                   known MACHINE/MACHINE_ARCH values in which either MACHINE
8921.109Sapb                   or ALIAS matches the pattern `evb*', and MACHINE_ARCH
8931.109Sapb                   matches the pattern `*arm*'.
8941.109Sapb
8951.105Swiz     The following command line options alter the behaviour of the build.sh
8961.51Swiz     operations described above:
8971.1Stv
8981.109Sapb     -a arch   Set the value of MACHINE_ARCH to arch.  See the -m option for
8991.109Sapb               more information.
9001.9Sthorpej
9011.105Swiz     -B buildid
9021.105Swiz               Set the value of BUILDID to buildid.  This will also append the
9031.67Ssborrill               build identifier to the name of the ``make'' wrapper script so
9041.37Slukem               that the resulting name is of the form
9051.105Swiz               ``nbmake-MACHINE-BUILDID''.
9061.1Stv
9071.105Swiz     -C cdextras
9081.105Swiz               Append cdextras to the CDEXTRA variable, which is a space-
9091.104Swiz               separated list of files or directories that will be added to
9101.104Swiz               the CD-ROM image that may be create by the ``iso-image'' or
9111.87Sapb               ``iso-image-source'' operations.  Files will be added to the
9121.87Sapb               root of the CD-ROM image, whereas directories will be copied
9131.87Sapb               recursively.  If relative paths are specified, they will be
9141.87Sapb               converted to absolute paths before being used.  Multiple paths
9151.105Swiz               may be specified via multiple -C options, or via a single
9161.87Sapb               option whose argument contains multiple space-separated paths.
9171.66Sjnemeth
9181.105Swiz     -D dest   Set the value of DESTDIR to dest.  If a relative path is
9191.104Swiz               specified, it will be converted to an absolute path before
9201.104Swiz               being used.
9211.104Swiz
9221.105Swiz     -E        Set `expert' mode.  This overrides various sanity checks, and
9231.105Swiz               allows: DESTDIR does not have to be set to a non-root path for
9241.105Swiz               builds, and MKUNPRIVED=yes does not have to be set when
9251.104Swiz               building as a non-root user.
9261.23Slukem
9271.105Swiz               Note: It is highly recommended that you know what you are doing
9281.23Slukem               when you use this option.
9291.19Slukem
9301.105Swiz     -h        Print a help message.
9311.51Swiz
9321.105Swiz     -j njob   Run up to njob make(1) subjobs in parallel; passed through to
9331.74Sapb               make(1).  If you see failures for reasons other than running
9341.105Swiz               out of memory while using build.sh with -j, please save
9351.104Swiz               complete build logs so the failures can be analyzed.
9361.74Sapb
9371.105Swiz               To achieve the fastest builds, -j values between (1 + the
9381.104Swiz               number of CPUs) and (2 * the number of CPUs) are recommended.
9391.104Swiz               Use lower values on machines with limited memory or I/O
9401.104Swiz               bandwidth.
9411.104Swiz
9421.105Swiz     -M obj    Set MAKEOBJDIRPREFIX to obj.  Unsets MAKEOBJDIR.  See ``-O
9431.106Swiz               obj'' for more information.
9441.104Swiz
9451.105Swiz               For instance, if the source directory is /usr/src, a setting of
9461.105Swiz               ``-M /usr/obj'' will place build-time files under
9471.105Swiz               /usr/obj/usr/src/bin, /usr/obj/usr/src/lib,
9481.105Swiz               /usr/obj/usr/src/usr.bin, and so forth.
9491.88Sapb
9501.73Sapb               If a relative path is specified, it will be converted to an
9511.105Swiz               absolute path before being used.  build.sh imposes the
9521.105Swiz               restriction that the argument to the -M option must not begin
9531.104Swiz               with a ``$'' (dollar sign) character; otherwise it would be too
9541.104Swiz               difficult to determine whether the value is an absolute or a
9551.104Swiz               relative path.  If the directory does not already exist,
9561.105Swiz               build.sh will create it.
9571.18Slukem
9581.109Sapb     -m mach   Set the value of MACHINE to mach, unless the mach argument is
9591.109Sapb               an alias that refers to a MACHINE/MACHINE_ARCH pair, in which
9601.109Sapb               case both MACHINE and MACHINE_ARCH are set from the alias.
9611.109Sapb               Such aliases are interpreted entirely by build.sh; they are not
9621.109Sapb               used by any other part of the build system.  The MACHINE_ARCH
9631.109Sapb               setting implied by mach will override any value of MACHINE_ARCH
9641.109Sapb               in the process environment, but will not override a value set
9651.109Sapb               by the -a option.  All cross builds require -m, but if unset on
9661.109Sapb               a NetBSD host, the host's value of MACHINE will be detected and
9671.109Sapb               used automatically.
9681.109Sapb
9691.109Sapb               See the list-arch operation for a way to get a list of valid
9701.109Sapb               MACHINE and MACHINE_ARCH settings.
9711.1Stv
9721.105Swiz     -N noiselevel
9731.46Slukem               Set the ``noisyness'' level of the build, by setting
9741.105Swiz               MAKEVERBOSE to noiselevel.
9751.45Slukem
9761.105Swiz     -n        Show the commands that would be executed by build.sh, but do
9771.1Stv               not make any changes.  This is similar in concept to ``make
9781.1Stv               -n''.
9791.1Stv
9801.105Swiz     -O obj    Create an appropriate transform macro for MAKEOBJDIR that will
9811.105Swiz               place the built object files under obj.  Unsets
9821.105Swiz               MAKEOBJDIRPREFIX.
9831.88Sapb
9841.105Swiz               For instance, a setting of ``-O /usr/obj'' will place build-
9851.105Swiz               time files under /usr/obj/bin, /usr/obj/lib, /usr/obj/usr.bin,
9861.88Sapb               and so forth.
9871.88Sapb
9881.88Sapb               If a relative path is specified, it will be converted to an
9891.105Swiz               absolute path before being used.  build.sh imposes the
9901.105Swiz               restriction that the argument to the -O option must not contain
9911.104Swiz               a ``$'' (dollar sign) character.  If the directory does not
9921.105Swiz               already exist, build.sh will create it.
9931.73Sapb
9941.105Swiz               In normal use, exactly one of the -M or -O options should be
9951.105Swiz               specified.  If neither -M nor -O is specified, then a default
9961.78Sapb               object directory will be chosen according to rules in
9971.78Sapb               <bsd.obj.mk>.  Relying on this default is not recommended
9981.78Sapb               because it is determined by complex rules that are influenced
9991.78Sapb               by the values of several variables and by the location of the
10001.78Sapb               source directory.
10011.18Slukem
10021.109Sapb               Note that placing the obj directory location outside of the
10031.109Sapb               default source tree hierarchy makes it easier to manually clear
10041.109Sapb               out old files in the event the ``make cleandir'' operation is
10051.109Sapb               unable to do so.  (See CAVEATS below.)
10061.109Sapb
10071.109Sapb               Note also that use of one of -M or -O is the only means of
10081.109Sapb               building multiple machine architecture userlands from the same
10091.109Sapb               source tree without cleaning between builds (in which case, one
10101.109Sapb               would specify distinct obj locations for each).
10111.109Sapb
10121.105Swiz     -o        Set the value of MKOBJDIRS to ``no''.  Otherwise, it will be
10131.70Sdholland               automatically set to ``yes''.  This default is opposite to the
10141.105Swiz               behaviour when not using build.sh.
10151.1Stv
10161.105Swiz     -R rel    Set the value of RELEASEDIR to rel.  If a relative path is
10171.59Sapb               specified, it will be converted to an absolute path before
10181.59Sapb               being used.
10191.18Slukem
10201.105Swiz     -r        Remove the contents of DESTDIR and TOOLDIR before building
10211.1Stv               (provides a clean starting point).  This will skip deleting
10221.105Swiz               DESTDIR if building on a native system to the root directory.
10231.1Stv
10241.105Swiz     -S seed   Change the value of BUILDSEED to seed.  This should rarely be
10251.72Sperry               necessary.
10261.72Sperry
10271.105Swiz     -T tools  Set the value of TOOLDIR to tools.  If a relative path is
10281.104Swiz               specified, it will be converted to an absolute path before
10291.104Swiz               being used.  If set, the bootstrap ``make'' will only be
10301.104Swiz               rebuilt if the source files for make(1) have changed.
10311.104Swiz
10321.105Swiz     -U        Set MKUNPRIVED=yes.
10331.104Swiz
10341.105Swiz     -u        Set MKUPDATE=yes.
10351.104Swiz
10361.105Swiz     -V var=[value]
10371.105Swiz               Set the environment variable var to an optional value.  This is
10381.105Swiz               propagated to the nbmake wrapper.
10391.105Swiz
10401.105Swiz     -w wrapper
10411.105Swiz               Create the nbmake wrapper script (see below) in a custom
10421.105Swiz               location, specified by wrapper.  This allows, for instance, to
10431.105Swiz               place the wrapper in PATH automatically.  Note that wrapper is
10441.59Sapb               the full name of the file, not just a directory name.  If a
10451.59Sapb               relative path is specified, it will be converted to an absolute
10461.59Sapb               path before being used.
10471.1Stv
10481.105Swiz     -X x11src
10491.105Swiz               Set the value of X11SRCDIR to x11src.  If a relative path is
10501.59Sapb               specified, it will be converted to an absolute path before
10511.59Sapb               being used.
10521.49Slukem
10531.105Swiz     -x        Set MKX11=yes.
10541.49Slukem
10551.115Sapb     -Y extsrcdir
10561.115Sapb               Set the value of EXTSRCSRCDIR to extsrcdir.  If a relative path
10571.115Sapb               is specified, it will be converted to an absolute path before
10581.115Sapb               being used.
10591.115Sapb
10601.115Sapb     -y        Set MKEXTSRC=yes.
10611.115Sapb
10621.105Swiz     -Z var    Unset ("zap") the environment variable var.  This is propagated
10631.105Swiz               to the nbmake wrapper.
10641.40Slukem
10651.105Swiz   The "nbmake-MACHINE" wrapper script
10661.105Swiz     If using the build.sh script to build NetBSD, a nbmake-MACHINE script
10671.105Swiz     will be created in TOOLDIR/bin upon the first build to assist in building
10681.1Stv     subtrees on a cross-compile host.
10691.1Stv
10701.105Swiz     nbmake-MACHINE can be invoked in lieu of make(1), and will instead call
10711.105Swiz     the up-to-date version of ``nbmake'' installed into TOOLDIR/bin with
10721.105Swiz     several key variables pre-set, including MACHINE, MACHINE_ARCH, and
10731.105Swiz     TOOLDIR.  nbmake-MACHINE will also set variables specified with -V, and
10741.105Swiz     unset variables specified with -Z.
10751.40Slukem
10761.105Swiz     This script can be symlinked into a directory listed in PATH, or called
10771.1Stv     with an absolute path.
10781.1Stv
10791.105SwizEXAMPLES
10801.78Sapb     1.   % ./build.sh [options] tools kernel=GENERIC
10811.28Slukem
10821.28Slukem          Build a new toolchain, and use the new toolchain to configure and
10831.28Slukem          build a new GENERIC kernel.
10841.28Slukem
10851.78Sapb     2.   % ./build.sh [options] -U distribution
10861.28Slukem
10871.105Swiz          Using unprivileged mode, build a complete distribution to a DESTDIR
10881.105Swiz          directory that build.sh selects (and will display).
10891.28Slukem
10901.78Sapb     3.   # ./build.sh [options] -U install=/
10911.28Slukem
10921.105Swiz          As root, install to / the distribution that was built by example 2.
10931.105Swiz          Even though this is run as root, -U is required so that the
10941.105Swiz          permissions stored in DESTDIR/METALOG are correctly applied to the
10951.105Swiz          files as they're copied to /.
10961.28Slukem
10971.78Sapb     4.   % ./build.sh [options] -U -u release
10981.28Slukem
10991.105Swiz          Using unprivileged mode, build a complete release to DESTDIR and
11001.105Swiz          RELEASEDIR directories that build.sh selects (and will display).
11011.105Swiz          MKUPDATE=yes (-u) is set to prevent the ``make cleandir'', so that
11021.38Slukem          if this is run after example 2, it doesn't need to redo that portion
11031.38Slukem          of the release build.
11041.16Slukem
11051.105SwizOBSOLETE VARIABLES
11061.105Swiz     NBUILDJOBS  Use the make(1) option -j instead.
11071.15Slukem
11081.105Swiz     USE_NEW_TOOLCHAIN
11091.15Slukem                 The new toolchain is now the default.  To disable, use
11101.105Swiz                 TOOLCHAIN_MISSING=yes.
11111.10Ssommerfe
11121.105SwizSEE ALSO
11131.62Sapb     make(1), hier(7), release(7), etcupdate(8), postinstall(8), sysinst(8),
11141.105Swiz     pkgsrc/sysutils/cdrtools
11151.1Stv
11161.105SwizHISTORY
11171.105Swiz     The build.sh based build scheme was introduced for NetBSD 1.6 as
11181.105Swiz     USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that.
11191.1Stv
11201.109SapbCAVEATS
11211.109Sapb     After significant updates to third-party components in the source tree,
11221.109Sapb     the ``make cleandir'' operation may be insufficient to clean out old
11231.109Sapb     files in object directories.  Instead, one may have to manually remove
11241.109Sapb     the files.  Consult the UPDATING file for notices concerning this.
11251.109Sapb
11261.124SchristosNetBSD                         February 20, 2017                        NetBSD
1127