BUILDING revision 1.152
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     NBUILDJOBS      Now obsolete.  Use the make(1) option -j, instead.  See
6801.152Slukem                     below.
6811.1Stv
6821.152Slukem                     Default: Unset.
6831.1Stv
6841.152Slukem     NOCLEANDIR      If set, avoids the "make cleandir" phase of a full build.
6851.152Slukem                     This has the effect of allowing only changed files in a
6861.152Slukem                     source tree to be recompiled.  This can speed up builds
6871.152Slukem                     when updating only a few files in the tree.
6881.1Stv
6891.152Slukem                     Default: Unset.
6901.1Stv
6911.152Slukem                     See also MKUPDATE.
6921.70Sdholland
6931.152Slukem     NODISTRIBDIRS   If set, avoids the "make distrib-dirs" phase of a full
6941.152Slukem                     build.  This skips running mtree(8) on DESTDIR, useful on
6951.152Slukem                     systems where building as an unprivileged user, or where
6961.152Slukem                     it is known that the system-wide mtree files have not
6971.152Slukem                     changed.
6981.1Stv
6991.152Slukem                     Default: Unset.
7001.1Stv
7011.152Slukem     NOINCLUDES      If set, avoids the "make includes" phase of a full build.
7021.152Slukem                     This has the effect of preventing make(1) from thinking
7031.152Slukem                     that some programs are out-of-date simply because the
7041.152Slukem                     system include files have changed.  However, this option
7051.152Slukem                     should not be used when updating the entire NetBSD source
7061.152Slukem                     tree arbitrarily; it is suggested to use MKUPDATE=yes
7071.152Slukem                     instead in that case.
7081.1Stv
7091.152Slukem                     Default: Unset.
7101.1Stv
7111.152Slukem     RELEASEDIR      If set, specifies the directory to which a release(7)
7121.152Slukem                     layout will be written at the end of a "make release".
7131.152Slukem                     If specified, must be an absolute path.
7141.20Slukem
7151.152Slukem                     Note: build.sh will provide a default of releasedir (in
7161.152Slukem                     the top-level .OBJDIR) unless run in `expert' mode.
7171.30Slukem
7181.152Slukem                     Default: Unset.
7191.151Slukem
7201.105SwizBUILDING
7211.105Swiz   "make" command line options
7221.52Sjmc     This is not a summary of all the options available to make(1); only the
7231.52Sjmc     options used most frequently with NetBSD builds are listed here.
7241.1Stv
7251.105Swiz     -j njob    Run up to njob make(1) subjobs in parallel.  Makefiles should
7261.52Sjmc                use .WAIT or have explicit dependencies as necessary to
7271.74Sapb                enforce build ordering.
7281.10Ssommerfe
7291.105Swiz     -m dir     Specify the default directory for searching for system
7301.104Swiz                Makefile segments, mainly the <bsd.*.mk> files.  When building
7311.104Swiz                any full NetBSD source tree, this should be set to the
7321.126Swiz                "share/mk" directory in the source tree.  This is set
7331.104Swiz                automatically when building from the top level, or when using
7341.105Swiz                build.sh.
7351.1Stv
7361.148Slukem     -n         Show the commands that would have been executed, but do not
7371.1Stv                actually execute them.  This will still cause recursion to
7381.1Stv                take place.
7391.1Stv
7401.148Slukem     -V var     Show make(1)'s idea of the value of var.  Does not build any
7411.1Stv                targets.
7421.1Stv
7431.105Swiz     var=value  Set the variable var to value, overriding any setting
7441.105Swiz                specified by the process environment, the MAKECONF
7451.104Swiz                configuration file, or the system Makefile segments.
7461.1Stv
7471.105Swiz   "make" targets
7481.1Stv     These default targets may be built by running make(1) in any subtree of
7491.1Stv     the NetBSD source code.  It is recommended that none of these be used
7501.126Swiz     from the top level Makefile; as a specific exception, "make obj" and
7511.126Swiz     "make cleandir" are useful in that context.
7521.1Stv
7531.105Swiz     all        Build programs, libraries, and preformatted documentation.
7541.1Stv
7551.105Swiz     clean      Remove program and library object code files.
7561.1Stv
7571.105Swiz     cleandir   Same as clean, but also remove preformatted documentation,
7581.126Swiz                dependency files generated by "make depend", and any other
7591.49Slukem                files known to be created at build time.
7601.1Stv
7611.105Swiz     depend     Create dependency files (.depend) containing more detailed
7621.44Slukem                information about the dependencies of source code on header
7631.1Stv                files.  Allows programs to be recompiled automatically when a
7641.1Stv                dependency changes.
7651.1Stv
7661.126Swiz     dependall  Does a "make depend" immediately followed by a "make all".
7671.10Ssommerfe                This improves cache locality of the build since both passes
7681.10Ssommerfe                read the source files in their entirety.
7691.1Stv
7701.105Swiz     distclean  Synonym for cleandir.
7711.49Slukem
7721.105Swiz     includes   Build and install system header files.  Typically needed
7731.44Slukem                before any system libraries or programs can be built.
7741.1Stv
7751.105Swiz     install    Install programs, libraries, and documentation into DESTDIR.
7761.105Swiz                Few files will be installed to DESTDIR/dev, DESTDIR/etc,
7771.105Swiz                DESTDIR/root or DESTDIR/var in order to prevent user supplied
7781.27Slukem                configuration data from being overwritten.
7791.1Stv
7801.105Swiz     lint       Run lint(1) against the C source code, where appropriate, and
7811.1Stv                generate system-installed lint libraries.
7821.1Stv
7831.105Swiz     obj        Create object directories to be used for built files, instead
7841.1Stv                of building directly in the source tree.
7851.1Stv
7861.105Swiz     tags       Create ctags(1) searchable function lists usable by the ex(1)
7871.1Stv                and vi(1) text editors.
7881.1Stv
7891.105Swiz   "make" targets for the top level
7901.1Stv     Additional make(1) targets are usable specifically from the top source
7911.1Stv     level to facilitate building the entire NetBSD source tree.
7921.1Stv
7931.105Swiz     build         Build the entire NetBSD system (except the kernel).  This
7941.68Sreed                   orders portions of the source tree such that prerequisites
7951.68Sreed                   will be built in the proper order.
7961.20Slukem
7971.126Swiz     distribution  Do a "make build", and then install a full distribution
7981.105Swiz                   (which does not include a kernel) into DESTDIR, including
7991.105Swiz                   files in DESTDIR/dev, DESTDIR/etc, DESTDIR/root and
8001.105Swiz                   DESTDIR/var.
8011.20Slukem
8021.126Swiz     buildworld    As per "make distribution", except that it ensures that
8031.105Swiz                   DESTDIR is not the root directory.
8041.20Slukem
8051.105Swiz     installworld  Install the distribution from DESTDIR to INSTALLWORLDDIR,
8061.70Sdholland                   which defaults to the root directory.  Ensures that
8071.105Swiz                   INSTALLWORLDDIR is not the root directory if cross
8081.104Swiz                   compiling.
8091.20Slukem
8101.105Swiz                   The INSTALLSETS environment variable may be set to a space-
8111.95Sapb                   separated list of distribution sets to be installed.  By
8121.126Swiz                   default, all sets except "etc" and "xetc" are installed, so
8131.126Swiz                   most files in INSTALLWORLDDIR/etc will not be installed or
8141.126Swiz                   modified.
8151.61Sapb
8161.105Swiz                   Note: Before performing this operation with
8171.105Swiz                   INSTALLWORLDDIR=/, it is highly recommended that you
8181.61Sapb                   upgrade your kernel and reboot.  After performing this
8191.61Sapb                   operation, it is recommended that you use etcupdate(8) to
8201.105Swiz                   update files in INSTALLWORLDDIR/etc, and postinstall(8) to
8211.102Sabs                   check for or fix inconsistencies.
8221.20Slukem
8231.105Swiz     sets          Create distribution sets from DESTDIR into
8241.105Swiz                   RELEASEDIR/RELEASEMACHINEDIR/binary/sets.  Should be run
8251.126Swiz                   after "make distribution", as "make build" alone does not
8261.126Swiz                   install all of the required files.
8271.25Slukem
8281.105Swiz     sourcesets    Create source sets of the source tree into
8291.105Swiz                   RELEASEDIR/source/sets.
8301.31Slukem
8311.105Swiz     syspkgs       Create syspkgs from DESTDIR into
8321.105Swiz                   RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.  Should be run
8331.126Swiz                   after "make distribution", as "make build" alone does not
8341.126Swiz                   install all of the required files.
8351.54Sapb
8361.126Swiz     release       Do a "make distribution", build kernels, distribution
8371.126Swiz                   media, and install sets (this as per "make sets"), and then
8381.126Swiz                   package the system into a standard release layout as
8391.105Swiz                   described by release(7).  This requires that RELEASEDIR be
8401.25Slukem                   set (see above).
8411.1Stv
8421.105Swiz     iso-image     Create a NetBSD installation CD-ROM image in the
8431.114Ssnj                   RELEASEDIR/images directory.  The CD-ROM file system will
8441.114Ssnj                   have a layout as described in release(7).
8451.62Sapb
8461.62Sapb                   For most machine types, the CD-ROM will be bootable, and
8471.104Swiz                   will automatically run the sysinst(8) menu-based
8481.104Swiz                   installation program, which can be used to install or
8491.104Swiz                   upgrade a NetBSD system.  Bootable CD-ROMs also contain
8501.104Swiz                   tools that may be useful in repairing a damaged NetBSD
8511.104Swiz                   installation.
8521.62Sapb
8531.126Swiz                   Before "make iso-image" is attempted, RELEASEDIR must be
8541.126Swiz                   populated by "make release" or equivalent.
8551.62Sapb
8561.151Slukem                   Note: Other, smaller, CD-ROM images may be created in the
8571.151Slukem                   RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom directory
8581.151Slukem                   by "make release".  These smaller images usually contain
8591.151Slukem                   the same tools as the larger images in RELEASEDIR/images,
8601.151Slukem                   but do not contain additional content such as the
8611.151Slukem                   distribution sets.
8621.62Sapb
8631.151Slukem                   Note: The mac68k port still uses an older method of
8641.104Swiz                   creating CD-ROM images.  This requires the mkisofs(1)
8651.104Swiz                   utility, which is not part of NetBSD, but which can be
8661.105Swiz                   installed from pkgsrc/sysutils/cdrtools.
8671.56Sapb
8681.105Swiz     iso-image-source
8691.64Sjnemeth                   Create a NetBSD installation CD-ROM image in the
8701.114Ssnj                   RELEASEDIR/images directory.  The CD-ROM file system will
8711.114Ssnj                   have a layout as described in release(7).  It will have top
8721.64Sjnemeth                   level directories for the machine type and source.
8731.64Sjnemeth
8741.64Sjnemeth                   For most machine types, the CD-ROM will be bootable, and
8751.104Swiz                   will automatically run the sysinst(8) menu-based
8761.104Swiz                   installation program, which can be used to install or
8771.104Swiz                   upgrade a NetBSD system.  Bootable CD-ROMs also contain
8781.104Swiz                   tools that may be useful in repairing a damaged NetBSD
8791.104Swiz                   installation.
8801.64Sjnemeth
8811.126Swiz                   Before "make iso-image-source" is attempted, RELEASEDIR
8821.126Swiz                   must be populated by "make sourcesets release" or
8831.104Swiz                   equivalent.
8841.64Sjnemeth
8851.151Slukem                   Note: Other, smaller, CD-ROM images may be created in the
8861.151Slukem                   RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom directory
8871.151Slukem                   by "make release".  These smaller images usually contain
8881.151Slukem                   the same tools as the larger images in RELEASEDIR/images,
8891.151Slukem                   but do not contain additional content such as the
8901.151Slukem                   distribution sets.
8911.64Sjnemeth
8921.151Slukem                   Note: The mac68k port still uses an older method of
8931.104Swiz                   creating CD-ROM images.  This requires the mkisofs(1)
8941.104Swiz                   utility, which is not part of NetBSD, but which can be
8951.105Swiz                   installed from pkgsrc/sysutils/cdrtools.
8961.64Sjnemeth
8971.105Swiz     install-image
8981.98Sapb                   Create a bootable NetBSD installation disk image in the
8991.127Splunky                   RELEASEDIR/images directory.  The installation disk image
9001.127Splunky                   is suitable for copying to bootable USB flash memory
9011.127Splunky                   sticks, etc., for machines which are able to boot from such
9021.127Splunky                   devices.  The file system in the bootable disk image will
9031.127Splunky                   have a layout as described in release(7).
9041.97Stsutsui
9051.97Stsutsui                   The installation image is bootable, and will automatically
9061.97Stsutsui                   run the sysinst(8) menu-based installation program, which
9071.98Sapb                   can be used to install or upgrade a NetBSD system.  The
9081.98Sapb                   image also contains tools that may be useful in repairing a
9091.98Sapb                   damaged NetBSD installation.
9101.97Stsutsui
9111.126Swiz                   Before "make install-image" is attempted, RELEASEDIR must
9121.126Swiz                   be populated by "make release" or equivalent.  The build
9131.126Swiz                   must have been performed with MKUNPRIVED=yes because "make
9141.126Swiz                   install-image" relies on information in DESTDIR/METALOG.
9151.97Stsutsui
9161.120Spgoyette     live-image    Create NetBSD live images in the RELEASEDIR/images
9171.104Swiz                   directory.  The live image contains all necessary files to
9181.104Swiz                   boot NetBSD up to multi-user mode, including all files
9191.104Swiz                   which should be extracted during installation, NetBSD
9201.104Swiz                   disklabel, bootloaders, etc.
9211.104Swiz
9221.104Swiz                   The live image is suitable for use as a disk image in
9231.104Swiz                   virtual machine environments such as QEMU, and also useful
9241.104Swiz                   to boot NetBSD from a USB flash memory stick on a real
9251.98Sapb                   machine, without the need for installation.
9261.97Stsutsui
9271.126Swiz                   Before "make live-image" is attempted, RELEASEDIR must be
9281.126Swiz                   populated by "make release" or equivalent.  The build must
9291.126Swiz                   have been performed with MKUNPRIVED=yes because "make
9301.126Swiz                   install-image" relies on information in DESTDIR/METALOG.
9311.97Stsutsui
9321.105Swiz     regression-tests
9331.20Slukem                   Can only be run after building the regression tests in the
9341.126Swiz                   directory "regress".  Runs those compiled regression tests
9351.151Slukem                   on the local host.
9361.151Slukem
9371.151Slukem                   Note: Most tests are now managed instead using atf(7); this
9381.151Slukem                   target should probably run those as well but currently does
9391.151Slukem                   not.
9401.1Stv
9411.105Swiz   The "build.sh" script
9421.96Sapb     This script file is a shell script designed to build the entire NetBSD
9431.104Swiz     system on any host with a suitable modern shell and some common
9441.105Swiz     utilities.  The required shell features are described under the HOST_SH
9451.104Swiz     variable.
9461.96Sapb
9471.96Sapb     If a host system's default shell does support the required features, then
9481.96Sapb     we suggest that you explicitly specify a suitable shell using a command
9491.96Sapb     like
9501.96Sapb
9511.105Swiz           /path/to/suitable/shell build.sh [options]
9521.96Sapb
9531.105Swiz     The above command will usually enable build.sh to automatically set
9541.105Swiz     HOST_SH=/path/to/suitable/shell, but if that fails, then the following
9551.96Sapb     set of commands may be used instead:
9561.96Sapb
9571.105Swiz           HOST_SH=/path/to/suitable/shell
9581.96Sapb           export HOST_SH
9591.105Swiz           ${HOST_SH} build.sh [options]
9601.96Sapb
9611.105Swiz     If build.sh detects that it is being executed under an unsuitable shell,
9621.148Slukem     it attempts to exec a suitable shell instead, or shows an error message.
9631.105Swiz     If HOST_SH is not set explicitly, then build.sh sets a default using
9641.96Sapb     heuristics dependent on the host platform, or from the shell under which
9651.105Swiz     build.sh is executed (if that can be determined), or using the first copy
9661.105Swiz     of sh found in PATH.
9671.1Stv
9681.1Stv     All cross-compile builds, and most native builds, of the entire system
9691.126Swiz     should make use of build.sh rather than just running "make".  This way,
9701.104Swiz     the make(1) program will be bootstrapped properly, in case the host
9711.126Swiz     system has an older or incompatible "make" program.
9721.1Stv
9731.105Swiz     When compiling the entire system via build.sh, many make(1) variables are
9741.1Stv     set for you in order to help encapsulate the build process.  In the list
9751.105Swiz     of options below, variables that are automatically set by build.sh are
9761.1Stv     noted where applicable.
9771.1Stv
9781.105Swiz     The following operations are supported by build.sh:
9791.22Slukem
9801.126Swiz     build         Build the system as per "make build".  Before the main part
9811.126Swiz                   of the build commences, this command runs the obj operation
9821.126Swiz                   (unless the -o option is given), "make cleandir" (unless
9831.126Swiz                   the -u option is given), and the tools operation.
9841.22Slukem
9851.126Swiz     distribution  Build a full distribution as per "make distribution".  This
9861.126Swiz                   command first runs the build operation.
9871.22Slukem
9881.126Swiz     release       Build a full release as per "make release".  This command
9891.105Swiz                   first runs the distribution operation.
9901.22Slukem
9911.148Slukem     help          Show a help message, and exit.
9921.148Slukem
9931.105Swiz     makewrapper   Create the nbmake-MACHINE wrapper.  This operation is
9941.104Swiz                   automatically performed for any of the other operations.
9951.23Slukem
9961.126Swiz     cleandir      Perform "make cleandir".
9971.75Slukem
9981.126Swiz     obj           Perform "make obj".
9991.22Slukem
10001.105Swiz     tools         Build and install the host tools from src/tools.  This
10011.126Swiz                   command will first run "make obj" and "make cleandir" in
10021.126Swiz                   the tools subdirectory unless the -o or -u options
10031.104Swiz                   (respectively) are given.
10041.22Slukem
10051.126Swiz     install=idir  Install the contents of DESTDIR to idir, using "make
10061.151Slukem                   installworld".
10071.151Slukem
10081.151Slukem                   Note: Files that are part of the "etc" or "xetc" sets will
10091.151Slukem                   not be installed, unless overridden by the INSTALLSETS
10101.151Slukem                   environment variable.
10111.35Slukem
10121.105Swiz     kernel=kconf  Build a new kernel.  The kconf argument is the name of a
10131.105Swiz                   configuration file suitable for use by config(1).  If kconf
10141.22Slukem                   does not contain any `/' characters, the configuration file
10151.105Swiz                   is expected to be found in the KERNCONFDIR directory, which
10161.105Swiz                   is typically sys/arch/MACHINE/conf.  The new kernel will be
10171.105Swiz                   built in a subdirectory of KERNOBJDIR, which is typically
10181.105Swiz                   sys/arch/MACHINE/compile or an associated object directory.
10191.70Sdholland
10201.105Swiz                   This command does not imply the tools command; run the
10211.105Swiz                   tools command first unless it is certain that the tools
10221.70Sdholland                   already exist and are up to date.
10231.70Sdholland
10241.126Swiz                   This command will run "make cleandir" on the kernel in
10251.105Swiz                   question first unless the -u option is given.
10261.22Slukem
10271.106Swiz     kernel.gdb=kconf
10281.106Swiz                   Build a new kernel with debug information.  Similar to the
10291.106Swiz                   above kernel=kconf operation, but creates a netbsd.gdb file
10301.106Swiz                   alongside of the kernel netbsd, which contains a full
10311.106Swiz                   symbol table and can be used for debugging (for example
10321.106Swiz                   with a cross-gdb built by MKCROSSGDB).
10331.106Swiz
10341.113Suebayasi     kernels       This command will build all kernels defined in port
10351.113Suebayasi                   specific release build procedure.
10361.111Suebayasi
10371.112Suebayasi                   This command internally calls the kernel=kconf operation
10381.112Suebayasi                   for each found kernel configuration file.
10391.111Suebayasi
10401.105Swiz     modules       This command will build kernel modules and install them
10411.105Swiz                   into DESTDIR.
10421.86Sjnemeth
10431.105Swiz     releasekernel=kconf
10441.70Sdholland                   Install a gzip(1)ed copy of the kernel previously built by
10451.105Swiz                   kernel=kconf into
10461.105Swiz                   RELEASEDIR/RELEASEMACHINEDIR/binary/kernel, usually as
10471.126Swiz                   netbsd-kconf.gz, although the "netbsd" prefix is determined
10481.126Swiz                   from the "config" directives in kconf.
10491.24Slukem
10501.126Swiz     sets          Perform "make sets".
10511.31Slukem
10521.126Swiz     sourcesets    Perform "make sourcesets".
10531.22Slukem
10541.126Swiz     syspkgs       Perform "make syspkgs".
10551.54Sapb
10561.126Swiz     iso-image     Perform "make iso-image".
10571.56Sapb
10581.105Swiz     iso-image-source
10591.126Swiz                   Perform "make iso-image-source".
10601.65Sjnemeth
10611.105Swiz     install-image
10621.126Swiz                   Perform "make install-image".
10631.97Stsutsui
10641.126Swiz     live-image    Perform "make live-image".
10651.97Stsutsui
10661.148Slukem     list-arch     Show a list of valid MACHINE and MACHINE_ARCH settings, the
10671.148Slukem                   default MACHINE_ARCH for each MACHINE, and aliases for
10681.109Sapb                   MACHINE/MACHINE_ARCH pairs, and then exits.  The -m or -a
10691.109Sapb                   options (or both) may be used to specify glob patterns that
10701.109Sapb                   will be used to narrow the list of results; for example,
10711.131Sleot                   "build.sh -m 'evb*' -a '*arm*' list-arch" will list all
10721.109Sapb                   known MACHINE/MACHINE_ARCH values in which either MACHINE
10731.109Sapb                   or ALIAS matches the pattern `evb*', and MACHINE_ARCH
10741.109Sapb                   matches the pattern `*arm*'.
10751.109Sapb
10761.105Swiz     The following command line options alter the behaviour of the build.sh
10771.51Swiz     operations described above:
10781.1Stv
10791.109Sapb     -a arch   Set the value of MACHINE_ARCH to arch.  See the -m option for
10801.109Sapb               more information.
10811.9Sthorpej
10821.105Swiz     -B buildid
10831.105Swiz               Set the value of BUILDID to buildid.  This will also append the
10841.126Swiz               build identifier to the name of the "make" wrapper script so
10851.37Slukem               that the resulting name is of the form
10861.126Swiz               "nbmake-MACHINE-BUILDID".
10871.1Stv
10881.105Swiz     -C cdextras
10891.105Swiz               Append cdextras to the CDEXTRA variable, which is a space-
10901.104Swiz               separated list of files or directories that will be added to
10911.126Swiz               the CD-ROM image that may be create by the "iso-image" or
10921.126Swiz               "iso-image-source" operations.  Files will be added to the root
10931.126Swiz               of the CD-ROM image, whereas directories will be copied
10941.87Sapb               recursively.  If relative paths are specified, they will be
10951.87Sapb               converted to absolute paths before being used.  Multiple paths
10961.105Swiz               may be specified via multiple -C options, or via a single
10971.87Sapb               option whose argument contains multiple space-separated paths.
10981.66Sjnemeth
10991.136Suwe     -c compiler
11001.136Suwe               Select the compiler for the toolchain to build NetBSD and for
11011.136Suwe               inclusion in the NetBSD distribution.  Supported choices:
11021.136Suwe
11031.136Suwe                     clang
11041.136Suwe
11051.136Suwe                     gcc [default]
11061.136Suwe
11071.136Suwe               The compiler used to build the toolchain can be different; see
11081.136Suwe               HOST_CC and HOST_CXX.
11091.136Suwe
11101.105Swiz     -D dest   Set the value of DESTDIR to dest.  If a relative path is
11111.104Swiz               specified, it will be converted to an absolute path before
11121.104Swiz               being used.
11131.104Swiz
11141.105Swiz     -E        Set `expert' mode.  This overrides various sanity checks, and
11151.105Swiz               allows: DESTDIR does not have to be set to a non-root path for
11161.105Swiz               builds, and MKUNPRIVED=yes does not have to be set when
11171.104Swiz               building as a non-root user.
11181.23Slukem
11191.105Swiz               Note: It is highly recommended that you know what you are doing
11201.23Slukem               when you use this option.
11211.19Slukem
11221.148Slukem     -h        Show a help message, and exit.
11231.51Swiz
11241.105Swiz     -j njob   Run up to njob make(1) subjobs in parallel; passed through to
11251.74Sapb               make(1).  If you see failures for reasons other than running
11261.105Swiz               out of memory while using build.sh with -j, please save
11271.104Swiz               complete build logs so the failures can be analyzed.
11281.74Sapb
11291.105Swiz               To achieve the fastest builds, -j values between (1 + the
11301.104Swiz               number of CPUs) and (2 * the number of CPUs) are recommended.
11311.104Swiz               Use lower values on machines with limited memory or I/O
11321.104Swiz               bandwidth.
11331.104Swiz
11341.126Swiz     -M obj    Set MAKEOBJDIRPREFIX to obj.  Unsets MAKEOBJDIR.  See "-O obj"
11351.126Swiz               for more information.
11361.104Swiz
11371.105Swiz               For instance, if the source directory is /usr/src, a setting of
11381.126Swiz               "-M /usr/obj" will place build-time files under
11391.105Swiz               /usr/obj/usr/src/bin, /usr/obj/usr/src/lib,
11401.105Swiz               /usr/obj/usr/src/usr.bin, and so forth.
11411.88Sapb
11421.73Sapb               If a relative path is specified, it will be converted to an
11431.105Swiz               absolute path before being used.  build.sh imposes the
11441.105Swiz               restriction that the argument to the -M option must not begin
11451.126Swiz               with a "$" (dollar sign) character; otherwise it would be too
11461.104Swiz               difficult to determine whether the value is an absolute or a
11471.104Swiz               relative path.  If the directory does not already exist,
11481.105Swiz               build.sh will create it.
11491.18Slukem
11501.109Sapb     -m mach   Set the value of MACHINE to mach, unless the mach argument is
11511.109Sapb               an alias that refers to a MACHINE/MACHINE_ARCH pair, in which
11521.109Sapb               case both MACHINE and MACHINE_ARCH are set from the alias.
11531.109Sapb               Such aliases are interpreted entirely by build.sh; they are not
11541.109Sapb               used by any other part of the build system.  The MACHINE_ARCH
11551.109Sapb               setting implied by mach will override any value of MACHINE_ARCH
11561.109Sapb               in the process environment, but will not override a value set
11571.109Sapb               by the -a option.  All cross builds require -m, but if unset on
11581.109Sapb               a NetBSD host, the host's value of MACHINE will be detected and
11591.109Sapb               used automatically.
11601.109Sapb
11611.109Sapb               See the list-arch operation for a way to get a list of valid
11621.109Sapb               MACHINE and MACHINE_ARCH settings.
11631.1Stv
11641.105Swiz     -N noiselevel
11651.126Swiz               Set the "noisyness" level of the build, by setting MAKEVERBOSE
11661.126Swiz               to noiselevel.
11671.45Slukem
11681.105Swiz     -n        Show the commands that would be executed by build.sh, but do
11691.126Swiz               not make any changes.  This is similar in concept to "make -n".
11701.1Stv
11711.105Swiz     -O obj    Create an appropriate transform macro for MAKEOBJDIR that will
11721.105Swiz               place the built object files under obj.  Unsets
11731.105Swiz               MAKEOBJDIRPREFIX.
11741.88Sapb
11751.126Swiz               For instance, a setting of "-O /usr/obj" will place build-time
11761.126Swiz               files under /usr/obj/bin, /usr/obj/lib, /usr/obj/usr.bin, and
11771.126Swiz               so forth.
11781.88Sapb
11791.88Sapb               If a relative path is specified, it will be converted to an
11801.105Swiz               absolute path before being used.  build.sh imposes the
11811.105Swiz               restriction that the argument to the -O option must not contain
11821.126Swiz               a "$" (dollar sign) character.  If the directory does not
11831.105Swiz               already exist, build.sh will create it.
11841.73Sapb
11851.105Swiz               In normal use, exactly one of the -M or -O options should be
11861.105Swiz               specified.  If neither -M nor -O is specified, then a default
11871.78Sapb               object directory will be chosen according to rules in
11881.78Sapb               <bsd.obj.mk>.  Relying on this default is not recommended
11891.78Sapb               because it is determined by complex rules that are influenced
11901.78Sapb               by the values of several variables and by the location of the
11911.78Sapb               source directory.
11921.18Slukem
11931.151Slukem               Note: Placing the obj directory location outside of the default
11941.151Slukem               source tree hierarchy makes it easier to manually clear out old
11951.151Slukem               files in the event the "make cleandir" operation is unable to
11961.151Slukem               do so.  (See CAVEATS below.)
11971.151Slukem
11981.151Slukem               Note: The use of one of -M or -O is the only means of building
11991.151Slukem               multiple machine architecture userlands from the same source
12001.151Slukem               tree without cleaning between builds (in which case, one would
12011.151Slukem               specify distinct obj locations for each).
12021.109Sapb
12031.126Swiz     -o        Set the value of MKOBJDIRS to "no".  Otherwise, it will be
12041.126Swiz               automatically set to "yes".  This default is opposite to the
12051.105Swiz               behaviour when not using build.sh.
12061.1Stv
12071.148Slukem     -P        Set the value of MKREPRO and MKREPRO_TIMESTAMP to the latest
12081.148Slukem               source CVS timestamp for reproducible builds.
12091.148Slukem
12101.105Swiz     -R rel    Set the value of RELEASEDIR to rel.  If a relative path is
12111.59Sapb               specified, it will be converted to an absolute path before
12121.59Sapb               being used.
12131.18Slukem
12141.105Swiz     -r        Remove the contents of DESTDIR and TOOLDIR before building
12151.1Stv               (provides a clean starting point).  This will skip deleting
12161.105Swiz               DESTDIR if building on a native system to the root directory.
12171.1Stv
12181.105Swiz     -S seed   Change the value of BUILDSEED to seed.  This should rarely be
12191.72Sperry               necessary.
12201.72Sperry
12211.105Swiz     -T tools  Set the value of TOOLDIR to tools.  If a relative path is
12221.104Swiz               specified, it will be converted to an absolute path before
12231.126Swiz               being used.  If set, the bootstrap "make" will only be rebuilt
12241.126Swiz               if the source files for make(1) have changed.
12251.104Swiz
12261.105Swiz     -U        Set MKUNPRIVED=yes.
12271.104Swiz
12281.105Swiz     -u        Set MKUPDATE=yes.
12291.104Swiz
12301.105Swiz     -V var=[value]
12311.105Swiz               Set the environment variable var to an optional value.  This is
12321.105Swiz               propagated to the nbmake wrapper.
12331.105Swiz
12341.105Swiz     -w wrapper
12351.105Swiz               Create the nbmake wrapper script (see below) in a custom
12361.105Swiz               location, specified by wrapper.  This allows, for instance, to
12371.151Slukem               place the wrapper in PATH automatically.
12381.151Slukem
12391.151Slukem               Note: wrapper is the full name of the file, not just a
12401.151Slukem               directory name.  If a relative path is specified, it will be
12411.151Slukem               converted to an absolute path before being used.
12421.1Stv
12431.105Swiz     -X x11src
12441.105Swiz               Set the value of X11SRCDIR to x11src.  If a relative path is
12451.59Sapb               specified, it will be converted to an absolute path before
12461.59Sapb               being used.
12471.49Slukem
12481.105Swiz     -x        Set MKX11=yes.
12491.49Slukem
12501.105Swiz     -Z var    Unset ("zap") the environment variable var.  This is propagated
12511.105Swiz               to the nbmake wrapper.
12521.40Slukem
12531.148Slukem     -?        Show a help message, and exit.
12541.148Slukem
12551.105Swiz   The "nbmake-MACHINE" wrapper script
12561.105Swiz     If using the build.sh script to build NetBSD, a nbmake-MACHINE script
12571.105Swiz     will be created in TOOLDIR/bin upon the first build to assist in building
12581.1Stv     subtrees on a cross-compile host.
12591.1Stv
12601.105Swiz     nbmake-MACHINE can be invoked in lieu of make(1), and will instead call
12611.126Swiz     the up-to-date version of "nbmake" installed into TOOLDIR/bin with
12621.105Swiz     several key variables pre-set, including MACHINE, MACHINE_ARCH, and
12631.105Swiz     TOOLDIR.  nbmake-MACHINE will also set variables specified with -V, and
12641.105Swiz     unset variables specified with -Z.
12651.40Slukem
12661.105Swiz     This script can be symlinked into a directory listed in PATH, or called
12671.1Stv     with an absolute path.
12681.1Stv
12691.105SwizEXAMPLES
12701.151Slukem     1.   % ./build.sh [OPTIONS] tools kernel=GENERIC
12711.28Slukem
12721.28Slukem          Build a new toolchain, and use the new toolchain to configure and
12731.28Slukem          build a new GENERIC kernel.
12741.28Slukem
12751.151Slukem     2.   % ./build.sh [OPTIONS] -U distribution
12761.28Slukem
12771.105Swiz          Using unprivileged mode, build a complete distribution to a DESTDIR
12781.148Slukem          directory that build.sh selects (and will show).
12791.28Slukem
12801.151Slukem     3.   # ./build.sh [OPTIONS] -U install=/
12811.28Slukem
12821.105Swiz          As root, install to / the distribution that was built by example 2.
12831.105Swiz          Even though this is run as root, -U is required so that the
12841.105Swiz          permissions stored in DESTDIR/METALOG are correctly applied to the
12851.105Swiz          files as they're copied to /.
12861.28Slukem
12871.151Slukem     4.   % ./build.sh [OPTIONS] -U -u release
12881.28Slukem
12891.105Swiz          Using unprivileged mode, build a complete release to DESTDIR and
12901.148Slukem          RELEASEDIR directories that build.sh selects (and will show).
12911.126Swiz          MKUPDATE=yes (-u) is set to prevent the "make cleandir", so that if
12921.126Swiz          this is run after example 2, it doesn't need to redo that portion of
12931.126Swiz          the release build.
12941.16Slukem
12951.105SwizOBSOLETE VARIABLES
12961.105Swiz     NBUILDJOBS  Use the make(1) option -j instead.
12971.15Slukem
12981.105Swiz     USE_NEW_TOOLCHAIN
12991.15Slukem                 The new toolchain is now the default.  To disable, use
13001.105Swiz                 TOOLCHAIN_MISSING=yes.
13011.10Ssommerfe
13021.105SwizSEE ALSO
13031.151Slukem     ar(1), config(1), ctags(1), cvs(1), cvslatest(1), ex(1), g++(1), gzip(1),
13041.151Slukem     ident(1), ld(1), lint(1), make(1), mkisofs(1), sh(1), uname(1), vi(1),
13051.151Slukem     options(4), mk.conf(5), atf(7), hier(7), release(7), sysctl(7),
13061.151Slukem     etcupdate(8), installboot(8), mount(8), mtree(8), postinstall(8),
13071.151Slukem     sysinst(8), pkgsrc/sysutils/cdrtools
13081.1Stv
13091.105SwizHISTORY
13101.105Swiz     The build.sh based build scheme was introduced for NetBSD 1.6 as
13111.105Swiz     USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that.
13121.1Stv
13131.109SapbCAVEATS
13141.109Sapb     After significant updates to third-party components in the source tree,
13151.126Swiz     the "make cleandir" operation may be insufficient to clean out old files
13161.126Swiz     in object directories.  Instead, one may have to manually remove the
13171.126Swiz     files.  Consult the UPDATING file for notices concerning this.
13181.109Sapb
13191.152SlukemNetBSD                           June 5, 2023                           NetBSD
1320