BUILDING revision 1.153
11.104SwizBUILDING(8)                 System Manager's Manual                BUILDING(8)
21.1Stv
31.105SwizNAME
41.150Slukem     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.126Swiz     This source tree contains a special subtree, "tools", which uses the host
131.126Swiz     system to create a build toolchain for the target architecture.  The host
141.126Swiz     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.147Slukem     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.151Slukem     BUILDING       This document (in plaintext).  Generated from
221.151Slukem                    doc/BUILDING.mdoc.
231.48Sjmc
241.105Swiz     Makefile       The main Makefile for NetBSD; should only be run for
251.44Slukem                    native builds with an appropriately up-to-date version of
261.142Sandvar                    NetBSD make(1).  Intended for expert use with knowledge of
271.129Ssevan                    its shortcomings, it has been superseded by the build.sh
281.129Ssevan                    shell script as the recommended means for building NetBSD.
291.1Stv
301.105Swiz     UPDATING       Special notes for updating from an earlier revision of
311.1Stv                    NetBSD.  It is important to read this file before every
321.1Stv                    build of an updated source tree.
331.1Stv
341.105Swiz     build.sh       Bourne-compatible shell script used for building the host
351.1Stv                    build tools and the NetBSD system from scratch.  Can be
361.1Stv                    used for both native and cross builds, and should be used
371.129Ssevan                    instead of make(1) as it performs additional checks to
381.129Ssevan                    prevent common issues going undetected, such as building
391.129Ssevan                    with an outdated version of make(1).
401.1Stv
411.105Swiz     crypto/dist/, dist/, gnu/dist/
421.104Swiz                    Sources imported verbatim from third parties, without
431.104Swiz                    mangling the existing build structure.  Other source trees
441.126Swiz                    in bin through usr.sbin use the NetBSD make(1) "reachover"
451.126Swiz                    Makefile semantics when building these programs for a
461.126Swiz                    native host.
471.104Swiz
481.151Slukem     distrib/, etc/
491.151Slukem                    Sources for items used when making a full release
501.151Slukem                    snapshot, such as files installed in DESTDIR/etc on the
511.151Slukem                    destination system, boot media, and release notes.
521.151Slukem
531.151Slukem     doc/BUILDING.mdoc
541.151Slukem                    This document, in -mdoc troff format; the original copy.
551.151Slukem                    Used to generate BUILDING.
561.151Slukem
571.106Swiz     external, sys/external
581.106Swiz                    Sources and build infrastructure for components imported
591.106Swiz                    (mostly) unchanged from upstream maintainers, sorted by
601.106Swiz                    applicable license.  This is (slowly) replacing the
611.106Swiz                    crypto/dist, dist, and gnu/dist directories.
621.106Swiz
631.151Slukem     external/mit/xorg/
641.151Slukem                    "Reachover" build structure for modular Xorg; the source
651.151Slukem                    is in X11SRCDIR.
661.1Stv
671.151Slukem     regress/, tests/
681.70Sdholland                    Regression test harness.  Can be cross-compiled, but only
691.105Swiz                    run natively.  tests/ uses the atf(7) test framework;
701.105Swiz                    regress/ contains older tests that have not yet been
711.70Sdholland                    migrated to atf(7).
721.1Stv
731.105Swiz     sys/           NetBSD kernel sources.
741.1Stv
751.126Swiz     tools/         "Reachover" build structure for the host build tools.
761.104Swiz                    This has a special method of determining out-of-date
771.104Swiz                    status.
781.1Stv
791.151Slukem     tools/compat/README
801.151Slukem                    Special notes for cross-hosting a NetBSD build on non-
811.151Slukem                    NetBSD platforms.
821.151Slukem
831.151Slukem     Other directories including bin/ ... usr.sbin/
841.1Stv                    Sources to the NetBSD userland (non-kernel) programs.  If
851.1Stv                    any of these directories are missing, they will be skipped
861.1Stv                    during the build.
871.1Stv
881.105Swiz   Build tree layout
891.1Stv     The NetBSD build tree is described in hier(7), and the release layout is
901.1Stv     described in release(7).
911.1Stv
921.105SwizCONFIGURATION
931.105Swiz   Environment variables
941.8Slukem     Several environment variables control the behaviour of NetBSD builds.
951.8Slukem
961.152Slukem     HOST_CC         Path name to C compiler used to create the toolchain.
971.58Sapb
981.152Slukem     HOST_CFLAGS     Flags passed to the host C compiler.
991.53Sreed
1001.152Slukem     HOST_CXX        Path name to C++ compiler used to create the toolchain.
1011.137Suwe
1021.152Slukem     HOST_CXXFLAGS   Flags passed to the host C++ compiler.
1031.53Sreed
1041.152Slukem     HOST_SH         Path name to a shell available on the host system and
1051.152Slukem                     suitable for use during the build.  The NetBSD build
1061.152Slukem                     system requires a modern Bourne-like shell with POSIX-
1071.152Slukem                     compliant features, and also requires support for the
1081.152Slukem                     "local" keyword to declare local variables in shell
1091.152Slukem                     functions (which is a widely-implemented but non-
1101.152Slukem                     standardised feature).
1111.152Slukem
1121.152Slukem                     Depending on the host system, a suitable shell may be
1131.152Slukem                     /bin/sh, /usr/xpg4/bin/sh, /bin/ksh (provided it is a
1141.152Slukem                     variant of ksh that supports the "local" keyword, such as
1151.152Slukem                     ksh88, but not ksh93), or /usr/local/bin/bash.
1161.152Slukem
1171.152Slukem                     Most parts of the build require HOST_SH to be an absolute
1181.152Slukem                     path; however, build.sh allows it to be a simple command
1191.152Slukem                     name, which will be converted to an absolute path by
1201.152Slukem                     searching the PATH.
1211.137Suwe
1221.147Slukem     INSTALLBOOT_UBOOT_PATHS
1231.152Slukem                     A colon-separated list of search paths used by
1241.152Slukem                     installboot(8) to find U-Boot packages.
1251.147Slukem
1261.152Slukem     MACHINE         Machine type, e.g., "macppc".
1271.8Slukem
1281.152Slukem     MACHINE_ARCH    Machine architecture, e.g., "powerpc".
1291.8Slukem
1301.152Slukem     MAKE            Path name to invoke make(1) as.
1311.8Slukem
1321.152Slukem     MAKECONF        The name of the make(1) configuration file.  See "make"
1331.152Slukem                     variables and mk.conf(5).
1341.151Slukem
1351.152Slukem                     Note: Only settable in the process environment.
1361.151Slukem
1371.152Slukem                     Default: "/etc/mk.conf"
1381.151Slukem
1391.152Slukem     MAKEFLAGS       Flags to invoke make(1) with.
1401.151Slukem
1411.152Slukem                     Note: build.sh ignores the value of MAKEFLAGS passed in
1421.152Slukem                     the environment, but allows MAKEFLAGS to be set via the
1431.152Slukem                     -V option.
1441.151Slukem
1451.152Slukem     MAKEOBJDIR      Directory to use as the .OBJDIR for the current
1461.152Slukem                     directory.  The value is subjected to variable expansion
1471.152Slukem                     by make(1).  Typical usage is to set this variable to a
1481.152Slukem                     value involving the use of `${.CURDIR:S...}' or
1491.152Slukem                     `${.CURDIR:C...}', to derive the value of .OBJDIR from
1501.152Slukem                     the value of .CURDIR.  Used only if MAKEOBJDIRPREFIX is
1511.152Slukem                     not defined.
1521.151Slukem
1531.152Slukem                     Note: MAKEOBJDIR can be provided only in the environment
1541.152Slukem                     or via the -O flag of build.sh; it cannot usefully be set
1551.152Slukem                     inside a Makefile, including in mk.conf(5) or MAKECONF.
1561.151Slukem
1571.151Slukem     MAKEOBJDIRPREFIX
1581.152Slukem                     Top level directory of the object directory tree.  The
1591.152Slukem                     value is subjected to variable expansion by make(1).
1601.152Slukem                     build.sh will create the ${MAKEOBJDIRPREFIX} directory if
1611.152Slukem                     necessary, but if make(1) is used without build.sh, then
1621.152Slukem                     rules in <bsd.obj.mk> will abort the build if the
1631.152Slukem                     ${MAKEOBJDIRPREFIX} directory does not exist.  If the
1641.152Slukem                     value is defined and valid, then
1651.152Slukem                     ${MAKEOBJDIRPREFIX}/${.CURDIR} is used as the .OBJDIR for
1661.152Slukem                     the current directory.  The current directory may be read
1671.152Slukem                     only.
1681.152Slukem
1691.152Slukem                     Note: MAKEOBJDIRPREFIX can be provided only in the
1701.152Slukem                     environment or via the -M flag of build.sh; it cannot
1711.152Slukem                     usefully be set inside a Makefile, including in
1721.152Slukem                     mk.conf(5) or MAKECONF.
1731.152Slukem
1741.152Slukem     TMPDIR          Top-level directory to store temporary directories used
1751.152Slukem                     by build.sh before paths to other directories such as
1761.152Slukem                     .OBJDIR can be determined.
1771.149Slukem
1781.152Slukem                     Note: Must support execution of binaries.  I.e., without
1791.152Slukem                     mount(8)'s -o noexec option.
1801.149Slukem
1811.152Slukem                     Default: "/tmp".
1821.149Slukem
1831.105Swiz   "make" variables
1841.104Swiz     Several variables control the behavior of NetBSD builds.  Unless
1851.104Swiz     otherwise specified, these variables may be set in either the process
1861.150Slukem     environment or the make(1) configuration file mk.conf(5) specified by
1871.151Slukem     MAKECONF.
1881.151Slukem
1891.151Slukem     This list is not comprehensive; all supported variables and their
1901.151Slukem     defaults are documented in mk.conf(5).
1911.151Slukem
1921.152Slukem     BSDOBJDIR       The real path to the object directory tree for the NetBSD
1931.152Slukem                     source tree.
1941.151Slukem
1951.152Slukem                     Default: "/usr/obj"
1961.151Slukem
1971.152Slukem     BSDSRCDIR       The real path to the NetBSD source tree, if NETBSDSRCDIR
1981.152Slukem                     isn't defined.
1991.151Slukem
2001.152Slukem                     Default: "/usr/src"
2011.152Slukem
2021.152Slukem     BUILDID         Identifier for the build.  If set, this should be a short
2031.152Slukem                     string that is suitable for use as part of a file or
2041.152Slukem                     directory name.  The identifier will be appended to
2051.152Slukem                     object directory names, and can be consulted in the
2061.152Slukem                     make(1) configuration file in order to set additional
2071.152Slukem                     build parameters, such as compiler flags.  It will also
2081.152Slukem                     be used as part of the kernel version string, which can
2091.152Slukem                     be shown by "uname -v".
2101.152Slukem
2111.152Slukem                     Default: Unset.
2121.152Slukem
2131.152Slukem     BUILDINFO       Optional multi-line string containing information about
2141.152Slukem                     the build.  This will appear in DESTDIR/etc/release, and
2151.152Slukem                     it will be stored in the buildinfo variable in any
2161.152Slukem                     kernels that are built.  When such kernels are booted,
2171.152Slukem                     the sysctl(7) kern.buildinfo variable will report this
2181.152Slukem                     value.  The string may contain backslash escape
2191.152Slukem                     sequences, such as "\\" (representing a backslash
2201.152Slukem                     character) and "\n" (representing a newline).
2211.152Slukem
2221.152Slukem                     Default: Unset.
2231.152Slukem
2241.152Slukem     BUILDSEED       g++(1) uses random numbers when compiling C++ code.  This
2251.152Slukem                     variable seeds the g++(1) random number generator using
2261.152Slukem                     -frandom-seed with this value.  By default, it is set to
2271.152Slukem                     "NetBSD-(majorversion)".  Using a fixed value causes C++
2281.152Slukem                     binaries to be the same when built from the same sources,
2291.152Slukem                     resulting in identical (reproducible) builds.  Additional
2301.152Slukem                     information is available in the g++(1) documentation of
2311.152Slukem                     -frandom-seed.
2321.152Slukem
2331.152Slukem                     Default: Unset.
2341.152Slukem
2351.152Slukem     CPUFLAGS        Additional flags to the compiler/assembler to select CPU
2361.152Slukem                     instruction set options, CPU tuning options, etc.
2371.152Slukem
2381.152Slukem                     Default: Unset.
2391.152Slukem
2401.152Slukem     DESTDIR         Directory to contain the built NetBSD system.  If set,
2411.152Slukem                     special options are passed to the compilation tools to
2421.152Slukem                     prevent their default use of the host system's
2431.152Slukem                     /usr/include, /usr/lib, and so forth.  This pathname must
2441.152Slukem                     be an absolute path, and should not end with a slash (/)
2451.152Slukem                     character.  (For installation into the system's root
2461.152Slukem                     directory, set DESTDIR to an empty string, not to "/").
2471.152Slukem                     The directory must reside on a file system which supports
2481.152Slukem                     long file names and hard links.
2491.151Slukem
2501.152Slukem                     Note: build.sh will provide a default of destdir.MACHINE
2511.152Slukem                     (in the top-level .OBJDIR) unless run in `expert' mode.
2521.151Slukem
2531.152Slukem                     Default: Empty string if USETOOLS is "yes"; unset
2541.152Slukem                     otherwise.
2551.151Slukem
2561.151Slukem     EXTERNAL_TOOLCHAIN
2571.152Slukem                     If defined, this variable indicates the root directory of
2581.152Slukem                     an external toolchain which will be used to build the
2591.152Slukem                     tree.  For example, if a platform is a TOOLCHAIN_MISSING
2601.152Slukem                     platform, EXTERNAL_TOOLCHAIN can be used to re-enable the
2611.152Slukem                     cross-compile framework.
2621.151Slukem
2631.152Slukem                     If EXTERNAL_TOOLCHAIN is defined, act as MKGCC=no, since
2641.152Slukem                     the external version of the compiler may not be able to
2651.152Slukem                     build the library components of the in-tree compiler.
2661.151Slukem
2671.152Slukem                     This variable should be used in conjunction with an
2681.152Slukem                     appropriate HAVE_GCC or HAVE_LLVM setting to control the
2691.152Slukem                     compiler flags.
2701.151Slukem
2711.152Slukem                     Note: This variable is not yet used in as many places as
2721.152Slukem                     it should be.  Expect the exact semantics of this
2731.152Slukem                     variable to change in the short term as parts of the
2741.152Slukem                     cross-compile framework continue to be cleaned up.
2751.151Slukem
2761.152Slukem                     Default: Unset.
2771.151Slukem
2781.152Slukem     MAKEVERBOSE     Level of verbosity of status messages.  Supported values:
2791.151Slukem
2801.152Slukem                     0   No descriptive messages or commands executed by
2811.152Slukem                         make(1) are shown.
2821.151Slukem
2831.152Slukem                     1   Brief messages are shown describing what is being
2841.152Slukem                         done, but the actual commands executed by make(1) are
2851.152Slukem                         not shown.
2861.151Slukem
2871.152Slukem                     2   Descriptive messages are shown as above (prefixed
2881.152Slukem                         with a `#'), and ordinary commands performed by
2891.152Slukem                         make(1) are shown.
2901.151Slukem
2911.152Slukem                     3   In addition to the above, all commands performed by
2921.152Slukem                         make(1) are shown, even if they would ordinarily have
2931.152Slukem                         been hidden through use of the "@" prefix in the
2941.152Slukem                         relevant makefile.
2951.151Slukem
2961.152Slukem                     4   In addition to the above, commands executed by
2971.152Slukem                         make(1) are traced through use of the sh(1) "-x"
2981.152Slukem                         flag.
2991.151Slukem
3001.152Slukem                     Default: 2
3011.151Slukem
3021.152Slukem     MKCATPAGES      Can be set to "yes" or "no".  Indicates whether
3031.152Slukem                     preformatted plaintext manual pages will be created and
3041.152Slukem                     installed.
3051.151Slukem
3061.152Slukem                     Forced to "no" if MKMAN=no or MKSHARE=no.
3071.151Slukem
3081.152Slukem                     Default: "no"
3091.151Slukem
3101.152Slukem     MKCROSSGDB      Can be set to "yes" or "no".  Create a cross-gdb as a
3111.152Slukem                     host tool.
3121.1Stv
3131.152Slukem                     Default: "no"
3141.151Slukem
3151.152Slukem     MKDEBUG         Can be set to "yes" or "no".  Indicates whether debug
3161.152Slukem                     information should be generated for all userland
3171.152Slukem                     binaries.  The result is collected as an additional
3181.152Slukem                     debug.tgz and xdebug.tgz set and installed in
3191.152Slukem                     DESTDIR/usr/libdata/debug.
3201.151Slukem
3211.152Slukem                     Forced to "no" if NODEBUG is defined, usually in the
3221.152Slukem                     Makefile before any make(1) .include directives.
3231.151Slukem
3241.152Slukem                     Default: "no"
3251.151Slukem
3261.152Slukem     MKDEBUGKERNEL   Can be set to "yes" or "no".  Indicates whether debugging
3271.152Slukem                     symbols will be built for kernels by default; pretend as
3281.152Slukem                     if makeoptions DEBUG="-g" is specified in kernel
3291.152Slukem                     configuration files.  This will also put the debug kernel
3301.152Slukem                     netbsd.gdb in the kernel sets.  See options(4) for
3311.152Slukem                     details.  This is useful if a cross-gdb is built as well
3321.152Slukem                     (see MKCROSSGDB).
3331.151Slukem
3341.152Slukem                     Default: "no"
3351.151Slukem
3361.152Slukem     MKDEBUGLIB      Can be set to "yes" or "no".  Indicates whether debug
3371.152Slukem                     libraries (lib*_g.a) will be built and installed.  Debug
3381.152Slukem                     libraries are compiled with "-g -DDEBUG".
3391.151Slukem
3401.152Slukem                     Forced to "no" if NODEBUGLIB is defined, usually in the
3411.152Slukem                     Makefile before any make(1) .include directives.
3421.151Slukem
3431.152Slukem                     Default: "no"
3441.151Slukem
3451.152Slukem     MKDEBUGTOOLS    Can be set to "yes" or "no".  Indicates whether debug
3461.152Slukem                     information (lib*_g.a) will be included in the build
3471.152Slukem                     toolchain.
3481.151Slukem
3491.152Slukem                     Default: "no"
3501.107Sapb
3511.152Slukem     MKDOC           Can be set to "yes" or "no".  Indicates whether system
3521.152Slukem                     documentation destined for DESTDIR/usr/share/doc will be
3531.152Slukem                     installed.
3541.151Slukem
3551.152Slukem                     Forced to "no" if NODOC is defined, usually in the
3561.152Slukem                     Makefile before any make(1) .include directives.
3571.151Slukem
3581.152Slukem                     Forced to "no" if MKSHARE=no.
3591.151Slukem
3601.152Slukem                     Default: "yes"
3611.151Slukem
3621.152Slukem     MKHOSTOBJ       Can be set to "yes" or "no".  If set to "yes", then for
3631.152Slukem                     programs intended to be run on the compile host, the
3641.152Slukem                     name, release, and architecture of the host operating
3651.152Slukem                     system will be suffixed to the name of the object
3661.152Slukem                     directory created by "make obj".  (This allows multiple
3671.152Slukem                     host systems to compile NetBSD for a single target.)  If
3681.152Slukem                     set to "no", then programs built to be run on the compile
3691.152Slukem                     host will use the same object directory names as programs
3701.152Slukem                     built to be run on the target.
3711.9Sthorpej
3721.152Slukem                     Default: "no"
3731.108Sapb
3741.152Slukem     MKHTML          Can be set to "yes" or "no".  Indicates whether the HTML
3751.152Slukem                     manual pages are created and installed.  and installed
3761.108Sapb
3771.152Slukem                     Forced to "no" if NOHTML is defined, usually in the
3781.152Slukem                     Makefile before any make(1) .include directives.
3791.104Swiz
3801.152Slukem                     Forced to "no" if MKMAN=no or MKSHARE=no.
3811.138Sthorpej
3821.152Slukem                     Default: "yes"
3831.138Sthorpej
3841.152Slukem     MKINFO          Can be set to "yes" or "no".  Indicates whether GNU Info
3851.152Slukem                     files, used for the documentation for most of the
3861.152Slukem                     compilation tools, will be built and installed.
3871.1Stv
3881.152Slukem                     Forced to "no" if NOINFO is defined, usually in the
3891.152Slukem                     Makefile before any make(1) .include directives.
3901.1Stv
3911.152Slukem                     Forced to "no" if MKSHARE=no.
3921.30Slukem
3931.152Slukem                     Default: "yes"
3941.45Slukem
3951.152Slukem     MKKDEBUG        Deprecated, use MKDEBUGKERNEL.
3961.45Slukem
3971.152Slukem     MKKMOD          Can be set to "yes" or "no".  Indicates whether kernel
3981.152Slukem                     modules are built and installed.
3991.80Sapb
4001.152Slukem                     Default: "no" on or1k; "yes" on other platforms.
4011.80Sapb
4021.152Slukem     MKLINKLIB       Can be set to "yes" or "no".  Indicates whether all of
4031.152Slukem                     the shared library infrastructure will be built and
4041.152Slukem                     installed.  If "no", prevents: installation of the *.a
4051.152Slukem                     libraries, installation of the *_pic.a libraries on PIC
4061.152Slukem                     systems, building of *.a libraries on PIC systems, or
4071.152Slukem                     installation of .so symlinks on ELF systems.
4081.45Slukem
4091.152Slukem                     Forced to "no" if NOLINKLIB is defined, usually in the
4101.152Slukem                     Makefile before any make(1) .include directives.
4111.45Slukem
4121.152Slukem                     If "no", acts as MKLINT=no MKPICINSTALL=no MKPROFILE=no.
4131.45Slukem
4141.152Slukem                     Default: "yes"
4151.140Skamil
4161.152Slukem     MKLINT          Can be set to "yes" or "no".  Indicates whether lint(1)
4171.152Slukem                     will be run against portions of the NetBSD source code
4181.152Slukem                     during the build, and whether lint libraries will be
4191.152Slukem                     installed into DESTDIR/usr/libdata/lint.
4201.140Skamil
4211.152Slukem                     Forced to "no" if NOLINT is defined, usually in the
4221.152Slukem                     Makefile before any make(1) .include directives.
4231.106Swiz
4241.152Slukem                     Forced to "no" if MKLINKLIB=no.
4251.106Swiz
4261.152Slukem                     Default: "no"
4271.106Swiz
4281.152Slukem     MKMAN           Can be set to "yes" or "no".  Indicates whether manual
4291.152Slukem                     pages will be installed.
4301.106Swiz
4311.152Slukem                     Forced to "no" if NOMAN is defined, usually in the
4321.152Slukem                     Makefile before any make(1) .include directives.
4331.106Swiz
4341.152Slukem                     Forced to "no" if MKSHARE=no.
4351.106Swiz
4361.152Slukem                     If "no", acts as MKCATPAGES=no MKHTML=no.
4371.1Stv
4381.152Slukem                     Default: "yes"
4391.1Stv
4401.152Slukem     MKNLS           Can be set to "yes" or "no".  Indicates whether Native
4411.152Slukem                     Language System (NLS) locale zone files will be built and
4421.152Slukem                     installed.
4431.77Slukem
4441.152Slukem                     Forced to "no" if NONLS is defined, usually in the
4451.152Slukem                     Makefile before any make(1) .include directives.
4461.77Slukem
4471.152Slukem                     Forced to "no" if MKSHARE=no.
4481.4Stv
4491.152Slukem                     Default: "yes"
4501.4Stv
4511.152Slukem     MKOBJ           Can be set to "yes" or "no".  Indicates whether object
4521.152Slukem                     directories will be created when running "make obj".  If
4531.152Slukem                     set to "no", then all built files will be located inside
4541.152Slukem                     the regular source tree.
4551.1Stv
4561.152Slukem                     Forced to "no" if NOOBJ is defined, usually in the
4571.152Slukem                     Makefile before any make(1) .include directives.
4581.1Stv
4591.152Slukem                     If "no", acts as MKOBJDIRS=no.
4601.143Slukem
4611.152Slukem                     Note: Setting MKOBJ to "no" is not recommended and may
4621.152Slukem                     cause problems when updating the tree with cvs(1).
4631.143Slukem
4641.152Slukem                     Default: "yes"
4651.95Sapb
4661.152Slukem     MKOBJDIRS       Can be set to "yes" or "no".  Indicates whether object
4671.152Slukem                     directories will be created automatically (via a "make
4681.152Slukem                     obj" pass) at the start of a build.
4691.95Sapb
4701.152Slukem                     Forced to "no" if MKOBJ=no.
4711.1Stv
4721.152Slukem                     Default: "no"
4731.1Stv
4741.152Slukem     MKPIC           Can be set to "yes" or "no".  Indicates whether shared
4751.152Slukem                     objects and libraries will be created and installed.  If
4761.152Slukem                     "no", the entire built system will be statically linked.
4771.1Stv
4781.152Slukem                     Forced to "no" if NOPIC is defined, usually in the
4791.152Slukem                     Makefile before any make(1) .include directives.
4801.1Stv
4811.152Slukem                     If "no", acts as MKPICLIB=no.
4821.1Stv
4831.152Slukem                     Default: "no" on m68000; "yes" on other platforms.
4841.1Stv
4851.152Slukem     MKPICINSTALL    Can be set to "yes" or "no".  Indicates whether the ar(1)
4861.152Slukem                     format libraries (lib*_pic.a), used to generate shared
4871.152Slukem                     libraries, are installed.
4881.1Stv
4891.152Slukem                     Forced to "no" if NOPICINSTALL is defined, usually in the
4901.152Slukem                     Makefile before any make(1) .include directives.
4911.1Stv
4921.152Slukem                     Forced to "no" if MKLINKLIB=no.
4931.70Sdholland
4941.152Slukem                     Default: "no"
4951.1Stv
4961.152Slukem     MKPROFILE       Can be set to "yes" or "no".  Indicates whether profiled
4971.152Slukem                     libraries (lib*_p.a) will be built and installed.
4981.1Stv
4991.152Slukem                     Forced to "no" if NOPROFILE is defined, usually in the
5001.152Slukem                     Makefile before any make(1) .include directives.
5011.1Stv
5021.152Slukem                     Forced to "no" if MKLINKLIB=no.
5031.1Stv
5041.152Slukem                     Default: "no" on or1k, riscv32, and riscv64 (due to
5051.152Slukem                     toolchain problems with profiled code); "yes" on other
5061.152Slukem                     platforms.
5071.1Stv
5081.152Slukem     MKREPRO         Can be set to "yes" or "no".  Indicates whether builds
5091.152Slukem                     are to be reproducible.  If "yes", two builds from the
5101.152Slukem                     same source tree will produce the same build results.
5111.1Stv
5121.152Slukem                     Used as the default for MKARZERO.
5131.100Swiz
5141.152Slukem                     This may be set to "yes" by giving build.sh the -P
5151.152Slukem                     option.
5161.151Slukem
5171.152Slukem                     Default: "no" Can be set to "yes" or "no".
5181.100Swiz
5191.122Swiz     MKREPRO_TIMESTAMP
5201.152Slukem                     Unix timestamp.  When MKREPRO is set, the timestamp of
5211.152Slukem                     all files in the sets will be set to this value.
5221.151Slukem
5231.152Slukem                     This may be set automatically to the latest source tree
5241.152Slukem                     timestamp using cvslatest(1) by giving build.sh the -P
5251.152Slukem                     option.
5261.151Slukem
5271.152Slukem                     Default: Unset.
5281.151Slukem
5291.152Slukem     MKSHARE         Can be set to "yes" or "no".  Indicates whether files
5301.152Slukem                     destined to reside in DESTDIR/usr/share will be built and
5311.152Slukem                     installed.
5321.151Slukem
5331.152Slukem                     Forced to "no" if NOSHARE is defined, usually in the
5341.152Slukem                     Makefile before any make(1) .include directives.
5351.122Swiz
5361.152Slukem                     If "no", acts as MKCATPAGES=no MKDOC=no MKINFO=no
5371.152Slukem                     MKHTML=no MKMAN=no MKNLS=no.
5381.49Slukem
5391.152Slukem                     Default: "yes"
5401.151Slukem
5411.152Slukem     MKSTRIPIDENT    Can be set to "yes" or "no".  Indicates whether RCS IDs,
5421.152Slukem                     for use with ident(1), should be stripped from program
5431.152Slukem                     binaries and shared libraries.
5441.151Slukem
5451.152Slukem                     Default: "no"
5461.151Slukem
5471.152Slukem     MKSTRIPSYM      Can be set to "yes" or "no".  Indicates whether all local
5481.152Slukem                     symbols should be stripped from shared libraries.  If
5491.152Slukem                     "yes", strip all local symbols from shared libraries; the
5501.152Slukem                     affect is equivalent to the -x option of ld(1).  If "no",
5511.152Slukem                     strip only temporary local symbols; the affect is
5521.152Slukem                     equivalent to the -X option of ld(1).  Keeping non-
5531.152Slukem                     temporary local symbols such as static function names is
5541.152Slukem                     useful on using DTrace for userland libraries and getting
5551.152Slukem                     a backtrace from a rump kernel loading shared libraries.
5561.151Slukem
5571.152Slukem                     Default: "yes"
5581.151Slukem
5591.152Slukem     MKUNPRIVED      Can be set to "yes" or "no".  Indicates whether an
5601.152Slukem                     unprivileged install will occur.  The user, group,
5611.152Slukem                     permissions, and file flags, will not be set on the
5621.152Slukem                     installed items; instead the information will be appended
5631.152Slukem                     to a file called METALOG in DESTDIR.  The contents of
5641.152Slukem                     METALOG are used during the generation of the
5651.152Slukem                     distribution tar files to ensure that the appropriate
5661.152Slukem                     file ownership is stored.
5671.151Slukem
5681.152Slukem                     Default: "no"
5691.151Slukem
5701.152Slukem     MKUPDATE        Can be set to "yes" or "no".  Indicates whether all
5711.152Slukem                     install operations intended to write to DESTDIR will
5721.152Slukem                     compare file timestamps before installing, and skip the
5731.152Slukem                     install phase if the destination files are up-to-date.
5741.151Slukem
5751.152Slukem                     Note: This also has implications on full builds (see next
5761.152Slukem                     subsection).
5771.151Slukem
5781.152Slukem                     Default: "no"
5791.151Slukem
5801.152Slukem     MKX11           Can be set to "yes" or "no".  Indicates whether X11 is
5811.152Slukem                     built and installed from X11SRCDIR, and whether the X
5821.152Slukem                     sets will be created.
5831.151Slukem
5841.152Slukem                     Note: If "yes", requires MKINET6=yes.
5851.151Slukem
5861.152Slukem                     Default: "no"
5871.151Slukem
5881.152Slukem     NETBSDSRCDIR    The path to the top level of the NetBSD sources.
5891.152Slukem
5901.152Slukem                     Default: Top level of the NetBSD source tree (as
5911.152Slukem                     determined by the presence of build.sh and tools/) if
5921.152Slukem                     make(1) is run from within that tree; otherwise BSDSRCDIR
5931.152Slukem                     will be used.
5941.151Slukem
5951.151Slukem     TOOLCHAIN_MISSING
5961.152Slukem                     Can be set to "yes" or "no".  If not "no", this indicates
5971.152Slukem                     that the platform "MACHINE_ARCH" being built does not
5981.152Slukem                     have a working in-tree toolchain.
5991.152Slukem
6001.152Slukem                     If not "no", acts as MKBINUTILS=no MKGCC=no MKGDB=no.
6011.152Slukem
6021.152Slukem                     Default: "no"
6031.152Slukem
6041.152Slukem     TOOLDIR         Directory to hold the host tools, once built.  If
6051.152Slukem                     specified, must be an absolute path.  This directory
6061.152Slukem                     should be unique to a given host system and NetBSD source
6071.152Slukem                     tree.  (However, multiple targets may share the same
6081.152Slukem                     TOOLDIR; the target-dependent files have unique names.)
6091.152Slukem                     If unset, a default based on the uname(1) information of
6101.152Slukem                     the host platform will be created in the .OBJDIR of src.
6111.152Slukem
6121.152Slukem                     Default: Unset.
6131.152Slukem
6141.152Slukem     USETOOLS        Can be set to "yes" or "no".  Indicates whether the tools
6151.152Slukem                     specified by TOOLDIR should be used as part of a build in
6161.152Slukem                     progress.  Must be set to "yes" if cross-compiling.
6171.152Slukem
6181.152Slukem                     yes    Use the tools from TOOLDIR.
6191.152Slukem
6201.152Slukem                     no     Do not use the tools from TOOLDIR, but refuse to
6211.152Slukem                            build native compilation tool components that are
6221.152Slukem                            version-specific for that tool.
6231.152Slukem
6241.152Slukem                     never  Do not use the tools from TOOLDIR, even when
6251.152Slukem                            building native tool components.  This is similar
6261.152Slukem                            to the traditional NetBSD build method, but does
6271.152Slukem                            not verify that the compilation tools in use are
6281.152Slukem                            up-to-date enough in order to build the tree
6291.152Slukem                            successfully.  This may cause build or runtime
6301.152Slukem                            problems when building the whole NetBSD source
6311.152Slukem                            tree.
6321.152Slukem
6331.152Slukem                     Default: "no" when using <bsd.*.mk> outside the NetBSD
6341.152Slukem                     source tree (detected automatically) or if
6351.152Slukem                     TOOLCHAIN_MISSING=yes; "yes" otherwise.
6361.152Slukem
6371.152Slukem     X11SRCDIR       Directory containing the modular Xorg source.  If
6381.152Slukem                     specified, must be an absolute path.  The main modular
6391.152Slukem                     Xorg source is found in X11SRCDIR/external/mit.
6401.151Slukem
6411.152Slukem                     Default: NETBSDSRCDIR/../xsrc, if that exists; otherwise
6421.152Slukem                     /usr/xsrc.
6431.49Slukem
6441.105Swiz   "make" variables for full builds
6451.126Swiz     These variables only affect the top level "Makefile" and do not affect
6461.7Slukem     manually building subtrees of the NetBSD source code.
6471.1Stv
6481.147Slukem     INSTALLBOOT_BOARDS
6491.152Slukem                     A list of boards to create bootable images for.  If
6501.152Slukem                     corresponding U-Boot packages are installed, bootable
6511.152Slukem                     images are created as part of a release.  See the
6521.152Slukem                     -o board=name option of installboot(8).
6531.147Slukem
6541.152Slukem     INSTALLWORLDDIR
6551.152Slukem                     Location for the "make installworld" target to install
6561.152Slukem                     to.  If specified, must be an absolute path.
6571.1Stv
6581.152Slukem                     Default: "/"
6591.1Stv
6601.152Slukem     MKOBJDIRS       Can be set to "yes" or "no".  Indicates whether object
6611.152Slukem                     directories will be created automatically (via a "make
6621.152Slukem                     obj" pass) at the start of a build.
6631.1Stv
6641.152Slukem                     Default: "no"
6651.1Stv
6661.152Slukem                     If using build.sh, the default is "yes".  This may be set
6671.152Slukem                     back to "no" by giving build.sh the -o option.
6681.70Sdholland
6691.152Slukem     MKUPDATE        Can be set to "yes" or "no".  If set, then in addition to
6701.152Slukem                     the effects described for MKUPDATE=yes above, this
6711.152Slukem                     implies the effects of NOCLEANDIR (i.e., "make cleandir"
6721.152Slukem                     is avoided).
6731.38Slukem
6741.152Slukem                     Default: "no"
6751.38Slukem
6761.152Slukem                     If using build.sh, this may be set by giving the -u
6771.152Slukem                     option.
6781.70Sdholland
6791.152Slukem     NOCLEANDIR      If set, avoids the "make cleandir" phase of a full build.
6801.152Slukem                     This has the effect of allowing only changed files in a
6811.152Slukem                     source tree to be recompiled.  This can speed up builds
6821.152Slukem                     when updating only a few files in the tree.
6831.1Stv
6841.152Slukem                     Default: Unset.
6851.1Stv
6861.152Slukem                     See also MKUPDATE.
6871.70Sdholland
6881.152Slukem     NODISTRIBDIRS   If set, avoids the "make distrib-dirs" phase of a full
6891.152Slukem                     build.  This skips running mtree(8) on DESTDIR, useful on
6901.152Slukem                     systems where building as an unprivileged user, or where
6911.152Slukem                     it is known that the system-wide mtree files have not
6921.152Slukem                     changed.
6931.1Stv
6941.152Slukem                     Default: Unset.
6951.1Stv
6961.152Slukem     NOINCLUDES      If set, avoids the "make includes" phase of a full build.
6971.152Slukem                     This has the effect of preventing make(1) from thinking
6981.152Slukem                     that some programs are out-of-date simply because the
6991.152Slukem                     system include files have changed.  However, this option
7001.152Slukem                     should not be used when updating the entire NetBSD source
7011.152Slukem                     tree arbitrarily; it is suggested to use MKUPDATE=yes
7021.152Slukem                     instead in that case.
7031.1Stv
7041.152Slukem                     Default: Unset.
7051.1Stv
7061.152Slukem     RELEASEDIR      If set, specifies the directory to which a release(7)
7071.152Slukem                     layout will be written at the end of a "make release".
7081.152Slukem                     If specified, must be an absolute path.
7091.20Slukem
7101.152Slukem                     Note: build.sh will provide a default of releasedir (in
7111.152Slukem                     the top-level .OBJDIR) unless run in `expert' mode.
7121.30Slukem
7131.152Slukem                     Default: Unset.
7141.151Slukem
7151.105SwizBUILDING
7161.105Swiz   "make" command line options
7171.52Sjmc     This is not a summary of all the options available to make(1); only the
7181.52Sjmc     options used most frequently with NetBSD builds are listed here.
7191.1Stv
7201.105Swiz     -j njob    Run up to njob make(1) subjobs in parallel.  Makefiles should
7211.52Sjmc                use .WAIT or have explicit dependencies as necessary to
7221.74Sapb                enforce build ordering.
7231.10Ssommerfe
7241.105Swiz     -m dir     Specify the default directory for searching for system
7251.104Swiz                Makefile segments, mainly the <bsd.*.mk> files.  When building
7261.104Swiz                any full NetBSD source tree, this should be set to the
7271.126Swiz                "share/mk" directory in the source tree.  This is set
7281.104Swiz                automatically when building from the top level, or when using
7291.105Swiz                build.sh.
7301.1Stv
7311.148Slukem     -n         Show the commands that would have been executed, but do not
7321.1Stv                actually execute them.  This will still cause recursion to
7331.1Stv                take place.
7341.1Stv
7351.148Slukem     -V var     Show make(1)'s idea of the value of var.  Does not build any
7361.1Stv                targets.
7371.1Stv
7381.105Swiz     var=value  Set the variable var to value, overriding any setting
7391.105Swiz                specified by the process environment, the MAKECONF
7401.104Swiz                configuration file, or the system Makefile segments.
7411.1Stv
7421.105Swiz   "make" targets
7431.1Stv     These default targets may be built by running make(1) in any subtree of
7441.1Stv     the NetBSD source code.  It is recommended that none of these be used
7451.126Swiz     from the top level Makefile; as a specific exception, "make obj" and
7461.126Swiz     "make cleandir" are useful in that context.
7471.1Stv
7481.105Swiz     all        Build programs, libraries, and preformatted documentation.
7491.1Stv
7501.105Swiz     clean      Remove program and library object code files.
7511.1Stv
7521.105Swiz     cleandir   Same as clean, but also remove preformatted documentation,
7531.126Swiz                dependency files generated by "make depend", and any other
7541.49Slukem                files known to be created at build time.
7551.1Stv
7561.105Swiz     depend     Create dependency files (.depend) containing more detailed
7571.44Slukem                information about the dependencies of source code on header
7581.1Stv                files.  Allows programs to be recompiled automatically when a
7591.1Stv                dependency changes.
7601.1Stv
7611.126Swiz     dependall  Does a "make depend" immediately followed by a "make all".
7621.10Ssommerfe                This improves cache locality of the build since both passes
7631.10Ssommerfe                read the source files in their entirety.
7641.1Stv
7651.105Swiz     distclean  Synonym for cleandir.
7661.49Slukem
7671.105Swiz     includes   Build and install system header files.  Typically needed
7681.44Slukem                before any system libraries or programs can be built.
7691.1Stv
7701.105Swiz     install    Install programs, libraries, and documentation into DESTDIR.
7711.105Swiz                Few files will be installed to DESTDIR/dev, DESTDIR/etc,
7721.105Swiz                DESTDIR/root or DESTDIR/var in order to prevent user supplied
7731.27Slukem                configuration data from being overwritten.
7741.1Stv
7751.105Swiz     lint       Run lint(1) against the C source code, where appropriate, and
7761.1Stv                generate system-installed lint libraries.
7771.1Stv
7781.105Swiz     obj        Create object directories to be used for built files, instead
7791.1Stv                of building directly in the source tree.
7801.1Stv
7811.105Swiz     tags       Create ctags(1) searchable function lists usable by the ex(1)
7821.1Stv                and vi(1) text editors.
7831.1Stv
7841.105Swiz   "make" targets for the top level
7851.1Stv     Additional make(1) targets are usable specifically from the top source
7861.1Stv     level to facilitate building the entire NetBSD source tree.
7871.1Stv
7881.105Swiz     build         Build the entire NetBSD system (except the kernel).  This
7891.68Sreed                   orders portions of the source tree such that prerequisites
7901.68Sreed                   will be built in the proper order.
7911.20Slukem
7921.126Swiz     distribution  Do a "make build", and then install a full distribution
7931.105Swiz                   (which does not include a kernel) into DESTDIR, including
7941.105Swiz                   files in DESTDIR/dev, DESTDIR/etc, DESTDIR/root and
7951.105Swiz                   DESTDIR/var.
7961.20Slukem
7971.126Swiz     buildworld    As per "make distribution", except that it ensures that
7981.105Swiz                   DESTDIR is not the root directory.
7991.20Slukem
8001.105Swiz     installworld  Install the distribution from DESTDIR to INSTALLWORLDDIR,
8011.70Sdholland                   which defaults to the root directory.  Ensures that
8021.105Swiz                   INSTALLWORLDDIR is not the root directory if cross
8031.104Swiz                   compiling.
8041.20Slukem
8051.105Swiz                   The INSTALLSETS environment variable may be set to a space-
8061.95Sapb                   separated list of distribution sets to be installed.  By
8071.126Swiz                   default, all sets except "etc" and "xetc" are installed, so
8081.126Swiz                   most files in INSTALLWORLDDIR/etc will not be installed or
8091.126Swiz                   modified.
8101.61Sapb
8111.105Swiz                   Note: Before performing this operation with
8121.105Swiz                   INSTALLWORLDDIR=/, it is highly recommended that you
8131.61Sapb                   upgrade your kernel and reboot.  After performing this
8141.61Sapb                   operation, it is recommended that you use etcupdate(8) to
8151.105Swiz                   update files in INSTALLWORLDDIR/etc, and postinstall(8) to
8161.102Sabs                   check for or fix inconsistencies.
8171.20Slukem
8181.105Swiz     sets          Create distribution sets from DESTDIR into
8191.105Swiz                   RELEASEDIR/RELEASEMACHINEDIR/binary/sets.  Should be run
8201.126Swiz                   after "make distribution", as "make build" alone does not
8211.126Swiz                   install all of the required files.
8221.25Slukem
8231.105Swiz     sourcesets    Create source sets of the source tree into
8241.105Swiz                   RELEASEDIR/source/sets.
8251.31Slukem
8261.105Swiz     syspkgs       Create syspkgs from DESTDIR into
8271.105Swiz                   RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.  Should be run
8281.126Swiz                   after "make distribution", as "make build" alone does not
8291.126Swiz                   install all of the required files.
8301.54Sapb
8311.126Swiz     release       Do a "make distribution", build kernels, distribution
8321.126Swiz                   media, and install sets (this as per "make sets"), and then
8331.126Swiz                   package the system into a standard release layout as
8341.105Swiz                   described by release(7).  This requires that RELEASEDIR be
8351.25Slukem                   set (see above).
8361.1Stv
8371.105Swiz     iso-image     Create a NetBSD installation CD-ROM image in the
8381.114Ssnj                   RELEASEDIR/images directory.  The CD-ROM file system will
8391.114Ssnj                   have a layout as described in release(7).
8401.62Sapb
8411.62Sapb                   For most machine types, the CD-ROM will be bootable, and
8421.104Swiz                   will automatically run the sysinst(8) menu-based
8431.104Swiz                   installation program, which can be used to install or
8441.104Swiz                   upgrade a NetBSD system.  Bootable CD-ROMs also contain
8451.104Swiz                   tools that may be useful in repairing a damaged NetBSD
8461.104Swiz                   installation.
8471.62Sapb
8481.126Swiz                   Before "make iso-image" is attempted, RELEASEDIR must be
8491.126Swiz                   populated by "make release" or equivalent.
8501.62Sapb
8511.151Slukem                   Note: Other, smaller, CD-ROM images may be created in the
8521.151Slukem                   RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom directory
8531.151Slukem                   by "make release".  These smaller images usually contain
8541.151Slukem                   the same tools as the larger images in RELEASEDIR/images,
8551.151Slukem                   but do not contain additional content such as the
8561.151Slukem                   distribution sets.
8571.62Sapb
8581.151Slukem                   Note: The mac68k port still uses an older method of
8591.104Swiz                   creating CD-ROM images.  This requires the mkisofs(1)
8601.104Swiz                   utility, which is not part of NetBSD, but which can be
8611.105Swiz                   installed from pkgsrc/sysutils/cdrtools.
8621.56Sapb
8631.105Swiz     iso-image-source
8641.64Sjnemeth                   Create a NetBSD installation CD-ROM image in the
8651.114Ssnj                   RELEASEDIR/images directory.  The CD-ROM file system will
8661.114Ssnj                   have a layout as described in release(7).  It will have top
8671.64Sjnemeth                   level directories for the machine type and source.
8681.64Sjnemeth
8691.64Sjnemeth                   For most machine types, the CD-ROM will be bootable, and
8701.104Swiz                   will automatically run the sysinst(8) menu-based
8711.104Swiz                   installation program, which can be used to install or
8721.104Swiz                   upgrade a NetBSD system.  Bootable CD-ROMs also contain
8731.104Swiz                   tools that may be useful in repairing a damaged NetBSD
8741.104Swiz                   installation.
8751.64Sjnemeth
8761.126Swiz                   Before "make iso-image-source" is attempted, RELEASEDIR
8771.126Swiz                   must be populated by "make sourcesets release" or
8781.104Swiz                   equivalent.
8791.64Sjnemeth
8801.151Slukem                   Note: Other, smaller, CD-ROM images may be created in the
8811.151Slukem                   RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom directory
8821.151Slukem                   by "make release".  These smaller images usually contain
8831.151Slukem                   the same tools as the larger images in RELEASEDIR/images,
8841.151Slukem                   but do not contain additional content such as the
8851.151Slukem                   distribution sets.
8861.64Sjnemeth
8871.151Slukem                   Note: The mac68k port still uses an older method of
8881.104Swiz                   creating CD-ROM images.  This requires the mkisofs(1)
8891.104Swiz                   utility, which is not part of NetBSD, but which can be
8901.105Swiz                   installed from pkgsrc/sysutils/cdrtools.
8911.64Sjnemeth
8921.105Swiz     install-image
8931.98Sapb                   Create a bootable NetBSD installation disk image in the
8941.127Splunky                   RELEASEDIR/images directory.  The installation disk image
8951.127Splunky                   is suitable for copying to bootable USB flash memory
8961.127Splunky                   sticks, etc., for machines which are able to boot from such
8971.127Splunky                   devices.  The file system in the bootable disk image will
8981.127Splunky                   have a layout as described in release(7).
8991.97Stsutsui
9001.97Stsutsui                   The installation image is bootable, and will automatically
9011.97Stsutsui                   run the sysinst(8) menu-based installation program, which
9021.98Sapb                   can be used to install or upgrade a NetBSD system.  The
9031.98Sapb                   image also contains tools that may be useful in repairing a
9041.98Sapb                   damaged NetBSD installation.
9051.97Stsutsui
9061.126Swiz                   Before "make install-image" is attempted, RELEASEDIR must
9071.126Swiz                   be populated by "make release" or equivalent.  The build
9081.126Swiz                   must have been performed with MKUNPRIVED=yes because "make
9091.126Swiz                   install-image" relies on information in DESTDIR/METALOG.
9101.97Stsutsui
9111.120Spgoyette     live-image    Create NetBSD live images in the RELEASEDIR/images
9121.104Swiz                   directory.  The live image contains all necessary files to
9131.104Swiz                   boot NetBSD up to multi-user mode, including all files
9141.104Swiz                   which should be extracted during installation, NetBSD
9151.104Swiz                   disklabel, bootloaders, etc.
9161.104Swiz
9171.104Swiz                   The live image is suitable for use as a disk image in
9181.104Swiz                   virtual machine environments such as QEMU, and also useful
9191.104Swiz                   to boot NetBSD from a USB flash memory stick on a real
9201.98Sapb                   machine, without the need for installation.
9211.97Stsutsui
9221.126Swiz                   Before "make live-image" is attempted, RELEASEDIR must be
9231.126Swiz                   populated by "make release" or equivalent.  The build must
9241.126Swiz                   have been performed with MKUNPRIVED=yes because "make
9251.126Swiz                   install-image" relies on information in DESTDIR/METALOG.
9261.97Stsutsui
9271.105Swiz     regression-tests
9281.20Slukem                   Can only be run after building the regression tests in the
9291.126Swiz                   directory "regress".  Runs those compiled regression tests
9301.151Slukem                   on the local host.
9311.151Slukem
9321.151Slukem                   Note: Most tests are now managed instead using atf(7); this
9331.151Slukem                   target should probably run those as well but currently does
9341.151Slukem                   not.
9351.1Stv
9361.105Swiz   The "build.sh" script
9371.96Sapb     This script file is a shell script designed to build the entire NetBSD
9381.104Swiz     system on any host with a suitable modern shell and some common
9391.105Swiz     utilities.  The required shell features are described under the HOST_SH
9401.104Swiz     variable.
9411.96Sapb
9421.96Sapb     If a host system's default shell does support the required features, then
9431.96Sapb     we suggest that you explicitly specify a suitable shell using a command
9441.96Sapb     like
9451.96Sapb
9461.105Swiz           /path/to/suitable/shell build.sh [options]
9471.96Sapb
9481.105Swiz     The above command will usually enable build.sh to automatically set
9491.105Swiz     HOST_SH=/path/to/suitable/shell, but if that fails, then the following
9501.96Sapb     set of commands may be used instead:
9511.96Sapb
9521.105Swiz           HOST_SH=/path/to/suitable/shell
9531.96Sapb           export HOST_SH
9541.105Swiz           ${HOST_SH} build.sh [options]
9551.96Sapb
9561.105Swiz     If build.sh detects that it is being executed under an unsuitable shell,
9571.148Slukem     it attempts to exec a suitable shell instead, or shows an error message.
9581.105Swiz     If HOST_SH is not set explicitly, then build.sh sets a default using
9591.96Sapb     heuristics dependent on the host platform, or from the shell under which
9601.105Swiz     build.sh is executed (if that can be determined), or using the first copy
9611.105Swiz     of sh found in PATH.
9621.1Stv
9631.1Stv     All cross-compile builds, and most native builds, of the entire system
9641.126Swiz     should make use of build.sh rather than just running "make".  This way,
9651.104Swiz     the make(1) program will be bootstrapped properly, in case the host
9661.126Swiz     system has an older or incompatible "make" program.
9671.1Stv
9681.105Swiz     When compiling the entire system via build.sh, many make(1) variables are
9691.1Stv     set for you in order to help encapsulate the build process.  In the list
9701.105Swiz     of options below, variables that are automatically set by build.sh are
9711.1Stv     noted where applicable.
9721.1Stv
9731.105Swiz     The following operations are supported by build.sh:
9741.22Slukem
9751.126Swiz     build         Build the system as per "make build".  Before the main part
9761.126Swiz                   of the build commences, this command runs the obj operation
9771.126Swiz                   (unless the -o option is given), "make cleandir" (unless
9781.126Swiz                   the -u option is given), and the tools operation.
9791.22Slukem
9801.126Swiz     distribution  Build a full distribution as per "make distribution".  This
9811.126Swiz                   command first runs the build operation.
9821.22Slukem
9831.126Swiz     release       Build a full release as per "make release".  This command
9841.105Swiz                   first runs the distribution operation.
9851.22Slukem
9861.148Slukem     help          Show a help message, and exit.
9871.148Slukem
9881.105Swiz     makewrapper   Create the nbmake-MACHINE wrapper.  This operation is
9891.104Swiz                   automatically performed for any of the other operations.
9901.23Slukem
9911.126Swiz     cleandir      Perform "make cleandir".
9921.75Slukem
9931.126Swiz     obj           Perform "make obj".
9941.22Slukem
9951.105Swiz     tools         Build and install the host tools from src/tools.  This
9961.126Swiz                   command will first run "make obj" and "make cleandir" in
9971.126Swiz                   the tools subdirectory unless the -o or -u options
9981.104Swiz                   (respectively) are given.
9991.22Slukem
10001.126Swiz     install=idir  Install the contents of DESTDIR to idir, using "make
10011.151Slukem                   installworld".
10021.151Slukem
10031.151Slukem                   Note: Files that are part of the "etc" or "xetc" sets will
10041.151Slukem                   not be installed, unless overridden by the INSTALLSETS
10051.151Slukem                   environment variable.
10061.35Slukem
10071.105Swiz     kernel=kconf  Build a new kernel.  The kconf argument is the name of a
10081.105Swiz                   configuration file suitable for use by config(1).  If kconf
10091.22Slukem                   does not contain any `/' characters, the configuration file
10101.105Swiz                   is expected to be found in the KERNCONFDIR directory, which
10111.105Swiz                   is typically sys/arch/MACHINE/conf.  The new kernel will be
10121.105Swiz                   built in a subdirectory of KERNOBJDIR, which is typically
10131.105Swiz                   sys/arch/MACHINE/compile or an associated object directory.
10141.70Sdholland
10151.105Swiz                   This command does not imply the tools command; run the
10161.105Swiz                   tools command first unless it is certain that the tools
10171.70Sdholland                   already exist and are up to date.
10181.70Sdholland
10191.126Swiz                   This command will run "make cleandir" on the kernel in
10201.105Swiz                   question first unless the -u option is given.
10211.22Slukem
10221.106Swiz     kernel.gdb=kconf
10231.106Swiz                   Build a new kernel with debug information.  Similar to the
10241.106Swiz                   above kernel=kconf operation, but creates a netbsd.gdb file
10251.106Swiz                   alongside of the kernel netbsd, which contains a full
10261.106Swiz                   symbol table and can be used for debugging (for example
10271.106Swiz                   with a cross-gdb built by MKCROSSGDB).
10281.106Swiz
10291.113Suebayasi     kernels       This command will build all kernels defined in port
10301.113Suebayasi                   specific release build procedure.
10311.111Suebayasi
10321.112Suebayasi                   This command internally calls the kernel=kconf operation
10331.112Suebayasi                   for each found kernel configuration file.
10341.111Suebayasi
10351.105Swiz     modules       This command will build kernel modules and install them
10361.105Swiz                   into DESTDIR.
10371.86Sjnemeth
10381.105Swiz     releasekernel=kconf
10391.70Sdholland                   Install a gzip(1)ed copy of the kernel previously built by
10401.105Swiz                   kernel=kconf into
10411.105Swiz                   RELEASEDIR/RELEASEMACHINEDIR/binary/kernel, usually as
10421.126Swiz                   netbsd-kconf.gz, although the "netbsd" prefix is determined
10431.126Swiz                   from the "config" directives in kconf.
10441.24Slukem
10451.126Swiz     sets          Perform "make sets".
10461.31Slukem
10471.126Swiz     sourcesets    Perform "make sourcesets".
10481.22Slukem
10491.126Swiz     syspkgs       Perform "make syspkgs".
10501.54Sapb
10511.126Swiz     iso-image     Perform "make iso-image".
10521.56Sapb
10531.105Swiz     iso-image-source
10541.126Swiz                   Perform "make iso-image-source".
10551.65Sjnemeth
10561.105Swiz     install-image
10571.126Swiz                   Perform "make install-image".
10581.97Stsutsui
10591.126Swiz     live-image    Perform "make live-image".
10601.97Stsutsui
10611.148Slukem     list-arch     Show a list of valid MACHINE and MACHINE_ARCH settings, the
10621.148Slukem                   default MACHINE_ARCH for each MACHINE, and aliases for
10631.109Sapb                   MACHINE/MACHINE_ARCH pairs, and then exits.  The -m or -a
10641.109Sapb                   options (or both) may be used to specify glob patterns that
10651.109Sapb                   will be used to narrow the list of results; for example,
10661.131Sleot                   "build.sh -m 'evb*' -a '*arm*' list-arch" will list all
10671.109Sapb                   known MACHINE/MACHINE_ARCH values in which either MACHINE
10681.109Sapb                   or ALIAS matches the pattern `evb*', and MACHINE_ARCH
10691.109Sapb                   matches the pattern `*arm*'.
10701.109Sapb
10711.105Swiz     The following command line options alter the behaviour of the build.sh
10721.51Swiz     operations described above:
10731.1Stv
10741.109Sapb     -a arch   Set the value of MACHINE_ARCH to arch.  See the -m option for
10751.109Sapb               more information.
10761.9Sthorpej
10771.105Swiz     -B buildid
10781.105Swiz               Set the value of BUILDID to buildid.  This will also append the
10791.126Swiz               build identifier to the name of the "make" wrapper script so
10801.37Slukem               that the resulting name is of the form
10811.126Swiz               "nbmake-MACHINE-BUILDID".
10821.1Stv
10831.105Swiz     -C cdextras
10841.105Swiz               Append cdextras to the CDEXTRA variable, which is a space-
10851.104Swiz               separated list of files or directories that will be added to
10861.126Swiz               the CD-ROM image that may be create by the "iso-image" or
10871.126Swiz               "iso-image-source" operations.  Files will be added to the root
10881.126Swiz               of the CD-ROM image, whereas directories will be copied
10891.87Sapb               recursively.  If relative paths are specified, they will be
10901.87Sapb               converted to absolute paths before being used.  Multiple paths
10911.105Swiz               may be specified via multiple -C options, or via a single
10921.87Sapb               option whose argument contains multiple space-separated paths.
10931.66Sjnemeth
10941.136Suwe     -c compiler
10951.136Suwe               Select the compiler for the toolchain to build NetBSD and for
10961.136Suwe               inclusion in the NetBSD distribution.  Supported choices:
10971.136Suwe
10981.136Suwe                     clang
10991.136Suwe
11001.136Suwe                     gcc [default]
11011.136Suwe
11021.136Suwe               The compiler used to build the toolchain can be different; see
11031.136Suwe               HOST_CC and HOST_CXX.
11041.136Suwe
11051.105Swiz     -D dest   Set the value of DESTDIR to dest.  If a relative path is
11061.104Swiz               specified, it will be converted to an absolute path before
11071.104Swiz               being used.
11081.104Swiz
11091.105Swiz     -E        Set `expert' mode.  This overrides various sanity checks, and
11101.105Swiz               allows: DESTDIR does not have to be set to a non-root path for
11111.105Swiz               builds, and MKUNPRIVED=yes does not have to be set when
11121.104Swiz               building as a non-root user.
11131.23Slukem
11141.105Swiz               Note: It is highly recommended that you know what you are doing
11151.23Slukem               when you use this option.
11161.19Slukem
11171.148Slukem     -h        Show a help message, and exit.
11181.51Swiz
11191.105Swiz     -j njob   Run up to njob make(1) subjobs in parallel; passed through to
11201.74Sapb               make(1).  If you see failures for reasons other than running
11211.105Swiz               out of memory while using build.sh with -j, please save
11221.104Swiz               complete build logs so the failures can be analyzed.
11231.74Sapb
11241.105Swiz               To achieve the fastest builds, -j values between (1 + the
11251.104Swiz               number of CPUs) and (2 * the number of CPUs) are recommended.
11261.104Swiz               Use lower values on machines with limited memory or I/O
11271.104Swiz               bandwidth.
11281.104Swiz
11291.126Swiz     -M obj    Set MAKEOBJDIRPREFIX to obj.  Unsets MAKEOBJDIR.  See "-O obj"
11301.126Swiz               for more information.
11311.104Swiz
11321.105Swiz               For instance, if the source directory is /usr/src, a setting of
11331.126Swiz               "-M /usr/obj" will place build-time files under
11341.105Swiz               /usr/obj/usr/src/bin, /usr/obj/usr/src/lib,
11351.105Swiz               /usr/obj/usr/src/usr.bin, and so forth.
11361.88Sapb
11371.73Sapb               If a relative path is specified, it will be converted to an
11381.105Swiz               absolute path before being used.  build.sh imposes the
11391.105Swiz               restriction that the argument to the -M option must not begin
11401.126Swiz               with a "$" (dollar sign) character; otherwise it would be too
11411.104Swiz               difficult to determine whether the value is an absolute or a
11421.104Swiz               relative path.  If the directory does not already exist,
11431.105Swiz               build.sh will create it.
11441.18Slukem
11451.109Sapb     -m mach   Set the value of MACHINE to mach, unless the mach argument is
11461.109Sapb               an alias that refers to a MACHINE/MACHINE_ARCH pair, in which
11471.109Sapb               case both MACHINE and MACHINE_ARCH are set from the alias.
11481.109Sapb               Such aliases are interpreted entirely by build.sh; they are not
11491.109Sapb               used by any other part of the build system.  The MACHINE_ARCH
11501.109Sapb               setting implied by mach will override any value of MACHINE_ARCH
11511.109Sapb               in the process environment, but will not override a value set
11521.109Sapb               by the -a option.  All cross builds require -m, but if unset on
11531.109Sapb               a NetBSD host, the host's value of MACHINE will be detected and
11541.109Sapb               used automatically.
11551.109Sapb
11561.109Sapb               See the list-arch operation for a way to get a list of valid
11571.109Sapb               MACHINE and MACHINE_ARCH settings.
11581.1Stv
11591.105Swiz     -N noiselevel
11601.126Swiz               Set the "noisyness" level of the build, by setting MAKEVERBOSE
11611.126Swiz               to noiselevel.
11621.45Slukem
11631.105Swiz     -n        Show the commands that would be executed by build.sh, but do
11641.126Swiz               not make any changes.  This is similar in concept to "make -n".
11651.1Stv
11661.105Swiz     -O obj    Create an appropriate transform macro for MAKEOBJDIR that will
11671.105Swiz               place the built object files under obj.  Unsets
11681.105Swiz               MAKEOBJDIRPREFIX.
11691.88Sapb
11701.126Swiz               For instance, a setting of "-O /usr/obj" will place build-time
11711.126Swiz               files under /usr/obj/bin, /usr/obj/lib, /usr/obj/usr.bin, and
11721.126Swiz               so forth.
11731.88Sapb
11741.88Sapb               If a relative path is specified, it will be converted to an
11751.105Swiz               absolute path before being used.  build.sh imposes the
11761.105Swiz               restriction that the argument to the -O option must not contain
11771.126Swiz               a "$" (dollar sign) character.  If the directory does not
11781.105Swiz               already exist, build.sh will create it.
11791.73Sapb
11801.105Swiz               In normal use, exactly one of the -M or -O options should be
11811.105Swiz               specified.  If neither -M nor -O is specified, then a default
11821.78Sapb               object directory will be chosen according to rules in
11831.78Sapb               <bsd.obj.mk>.  Relying on this default is not recommended
11841.78Sapb               because it is determined by complex rules that are influenced
11851.78Sapb               by the values of several variables and by the location of the
11861.78Sapb               source directory.
11871.18Slukem
11881.151Slukem               Note: Placing the obj directory location outside of the default
11891.151Slukem               source tree hierarchy makes it easier to manually clear out old
11901.151Slukem               files in the event the "make cleandir" operation is unable to
11911.151Slukem               do so.  (See CAVEATS below.)
11921.151Slukem
11931.151Slukem               Note: The use of one of -M or -O is the only means of building
11941.151Slukem               multiple machine architecture userlands from the same source
11951.151Slukem               tree without cleaning between builds (in which case, one would
11961.151Slukem               specify distinct obj locations for each).
11971.109Sapb
11981.126Swiz     -o        Set the value of MKOBJDIRS to "no".  Otherwise, it will be
11991.126Swiz               automatically set to "yes".  This default is opposite to the
12001.105Swiz               behaviour when not using build.sh.
12011.1Stv
12021.148Slukem     -P        Set the value of MKREPRO and MKREPRO_TIMESTAMP to the latest
12031.148Slukem               source CVS timestamp for reproducible builds.
12041.148Slukem
12051.105Swiz     -R rel    Set the value of RELEASEDIR to rel.  If a relative path is
12061.59Sapb               specified, it will be converted to an absolute path before
12071.59Sapb               being used.
12081.18Slukem
12091.105Swiz     -r        Remove the contents of DESTDIR and TOOLDIR before building
12101.1Stv               (provides a clean starting point).  This will skip deleting
12111.105Swiz               DESTDIR if building on a native system to the root directory.
12121.1Stv
12131.105Swiz     -S seed   Change the value of BUILDSEED to seed.  This should rarely be
12141.72Sperry               necessary.
12151.72Sperry
12161.105Swiz     -T tools  Set the value of TOOLDIR to tools.  If a relative path is
12171.104Swiz               specified, it will be converted to an absolute path before
12181.126Swiz               being used.  If set, the bootstrap "make" will only be rebuilt
12191.126Swiz               if the source files for make(1) have changed.
12201.104Swiz
12211.105Swiz     -U        Set MKUNPRIVED=yes.
12221.104Swiz
12231.105Swiz     -u        Set MKUPDATE=yes.
12241.104Swiz
12251.105Swiz     -V var=[value]
12261.105Swiz               Set the environment variable var to an optional value.  This is
12271.105Swiz               propagated to the nbmake wrapper.
12281.105Swiz
12291.105Swiz     -w wrapper
12301.105Swiz               Create the nbmake wrapper script (see below) in a custom
12311.105Swiz               location, specified by wrapper.  This allows, for instance, to
12321.151Slukem               place the wrapper in PATH automatically.
12331.151Slukem
12341.151Slukem               Note: wrapper is the full name of the file, not just a
12351.151Slukem               directory name.  If a relative path is specified, it will be
12361.151Slukem               converted to an absolute path before being used.
12371.1Stv
12381.105Swiz     -X x11src
12391.105Swiz               Set the value of X11SRCDIR to x11src.  If a relative path is
12401.59Sapb               specified, it will be converted to an absolute path before
12411.59Sapb               being used.
12421.49Slukem
12431.105Swiz     -x        Set MKX11=yes.
12441.49Slukem
12451.105Swiz     -Z var    Unset ("zap") the environment variable var.  This is propagated
12461.105Swiz               to the nbmake wrapper.
12471.40Slukem
12481.148Slukem     -?        Show a help message, and exit.
12491.148Slukem
12501.105Swiz   The "nbmake-MACHINE" wrapper script
12511.105Swiz     If using the build.sh script to build NetBSD, a nbmake-MACHINE script
12521.105Swiz     will be created in TOOLDIR/bin upon the first build to assist in building
12531.1Stv     subtrees on a cross-compile host.
12541.1Stv
12551.105Swiz     nbmake-MACHINE can be invoked in lieu of make(1), and will instead call
12561.126Swiz     the up-to-date version of "nbmake" installed into TOOLDIR/bin with
12571.105Swiz     several key variables pre-set, including MACHINE, MACHINE_ARCH, and
12581.105Swiz     TOOLDIR.  nbmake-MACHINE will also set variables specified with -V, and
12591.105Swiz     unset variables specified with -Z.
12601.40Slukem
12611.105Swiz     This script can be symlinked into a directory listed in PATH, or called
12621.1Stv     with an absolute path.
12631.1Stv
12641.105SwizEXAMPLES
12651.151Slukem     1.   % ./build.sh [OPTIONS] tools kernel=GENERIC
12661.28Slukem
12671.28Slukem          Build a new toolchain, and use the new toolchain to configure and
12681.28Slukem          build a new GENERIC kernel.
12691.28Slukem
12701.151Slukem     2.   % ./build.sh [OPTIONS] -U distribution
12711.28Slukem
12721.105Swiz          Using unprivileged mode, build a complete distribution to a DESTDIR
12731.148Slukem          directory that build.sh selects (and will show).
12741.28Slukem
12751.151Slukem     3.   # ./build.sh [OPTIONS] -U install=/
12761.28Slukem
12771.105Swiz          As root, install to / the distribution that was built by example 2.
12781.105Swiz          Even though this is run as root, -U is required so that the
12791.105Swiz          permissions stored in DESTDIR/METALOG are correctly applied to the
12801.105Swiz          files as they're copied to /.
12811.28Slukem
12821.151Slukem     4.   % ./build.sh [OPTIONS] -U -u release
12831.28Slukem
12841.105Swiz          Using unprivileged mode, build a complete release to DESTDIR and
12851.148Slukem          RELEASEDIR directories that build.sh selects (and will show).
12861.126Swiz          MKUPDATE=yes (-u) is set to prevent the "make cleandir", so that if
12871.126Swiz          this is run after example 2, it doesn't need to redo that portion of
12881.126Swiz          the release build.
12891.16Slukem
12901.105SwizOBSOLETE VARIABLES
12911.153Slukem     NBUILDJOBS  Use the build.sh and make(1) option -j instead.
12921.15Slukem
12931.105Swiz     USE_NEW_TOOLCHAIN
12941.15Slukem                 The new toolchain is now the default.  To disable, use
12951.105Swiz                 TOOLCHAIN_MISSING=yes.
12961.10Ssommerfe
12971.105SwizSEE ALSO
12981.151Slukem     ar(1), config(1), ctags(1), cvs(1), cvslatest(1), ex(1), g++(1), gzip(1),
12991.151Slukem     ident(1), ld(1), lint(1), make(1), mkisofs(1), sh(1), uname(1), vi(1),
13001.151Slukem     options(4), mk.conf(5), atf(7), hier(7), release(7), sysctl(7),
13011.151Slukem     etcupdate(8), installboot(8), mount(8), mtree(8), postinstall(8),
13021.151Slukem     sysinst(8), pkgsrc/sysutils/cdrtools
13031.1Stv
13041.105SwizHISTORY
13051.105Swiz     The build.sh based build scheme was introduced for NetBSD 1.6 as
13061.105Swiz     USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that.
13071.1Stv
13081.109SapbCAVEATS
13091.109Sapb     After significant updates to third-party components in the source tree,
13101.126Swiz     the "make cleandir" operation may be insufficient to clean out old files
13111.126Swiz     in object directories.  Instead, one may have to manually remove the
13121.126Swiz     files.  Consult the UPDATING file for notices concerning this.
13131.109Sapb
13141.153SlukemNetBSD                           June 10, 2023                          NetBSD
1315