BUILDING revision 1.151
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.151Slukem     HOST_CC          Path name to C compiler used to create the toolchain.
971.58Sapb
981.151Slukem     HOST_CFLAGS      Flags passed to the host C compiler.
991.53Sreed
1001.151Slukem     HOST_CXX         Path name to C++ compiler used to create the toolchain.
1011.137Suwe
1021.151Slukem     HOST_CXXFLAGS    Flags passed to the host C++ compiler.
1031.53Sreed
1041.151Slukem     HOST_SH          Path name to a shell available on the host system and
1051.151Slukem                      suitable for use during the build.  The NetBSD build
1061.151Slukem                      system requires a modern Bourne-like shell with POSIX-
1071.151Slukem                      compliant features, and also requires support for the
1081.151Slukem                      "local" keyword to declare local variables in shell
1091.151Slukem                      functions (which is a widely-implemented but non-
1101.151Slukem                      standardised feature).
1111.151Slukem
1121.151Slukem                      Depending on the host system, a suitable shell may be
1131.151Slukem                      /bin/sh, /usr/xpg4/bin/sh, /bin/ksh (provided it is a
1141.151Slukem                      variant of ksh that supports the "local" keyword, such
1151.151Slukem                      as ksh88, but not ksh93), or /usr/local/bin/bash.
1161.151Slukem
1171.151Slukem                      Most parts of the build require HOST_SH to be an
1181.151Slukem                      absolute path; however, build.sh allows it to be a
1191.151Slukem                      simple command name, which will be converted to an
1201.151Slukem                      absolute path by searching the PATH.
1211.137Suwe
1221.147Slukem     INSTALLBOOT_UBOOT_PATHS
1231.151Slukem                      A colon-separated list of search paths used by
1241.151Slukem                      installboot(8) to find U-Boot packages.
1251.147Slukem
1261.151Slukem     MACHINE          Machine type, e.g., "macppc".
1271.8Slukem
1281.151Slukem     MACHINE_ARCH     Machine architecture, e.g., "powerpc".
1291.8Slukem
1301.151Slukem     MAKE             Path name to invoke make(1) as.
1311.8Slukem
1321.151Slukem     MAKECONF         The name of the make(1) configuration file.  See "make"
1331.151Slukem                      variables and mk.conf(5).
1341.151Slukem
1351.151Slukem                      Note: Only settable in the process environment.
1361.151Slukem
1371.151Slukem                      Default: "/etc/mk.conf"
1381.151Slukem
1391.151Slukem     MAKEFLAGS        Flags to invoke make(1) with.
1401.151Slukem
1411.151Slukem                      Note: build.sh ignores the value of MAKEFLAGS passed in
1421.151Slukem                      the environment, but allows MAKEFLAGS to be set via the
1431.151Slukem                      -V option.
1441.151Slukem
1451.151Slukem     MAKEOBJDIR       Directory to use as the .OBJDIR for the current
1461.151Slukem                      directory.  The value is subjected to variable expansion
1471.151Slukem                      by make(1).  Typical usage is to set this variable to a
1481.151Slukem                      value involving the use of `${.CURDIR:S...}' or
1491.151Slukem                      `${.CURDIR:C...}', to derive the value of .OBJDIR from
1501.151Slukem                      the value of .CURDIR.  Used only if MAKEOBJDIRPREFIX is
1511.151Slukem                      not defined.
1521.151Slukem
1531.151Slukem                      Note: MAKEOBJDIR can be provided only in the environment
1541.151Slukem                      or via the -O flag of build.sh; it cannot usefully be
1551.151Slukem                      set inside a Makefile, including in mk.conf(5) or
1561.151Slukem                      MAKECONF.
1571.151Slukem
1581.151Slukem     MAKEOBJDIRPREFIX
1591.151Slukem                      Top level directory of the object directory tree.  The
1601.151Slukem                      value is subjected to variable expansion by make(1).
1611.151Slukem                      build.sh will create the ${MAKEOBJDIRPREFIX} directory
1621.151Slukem                      if necessary, but if make(1) is used without build.sh,
1631.151Slukem                      then rules in <bsd.obj.mk> will abort the build if the
1641.151Slukem                      ${MAKEOBJDIRPREFIX} directory does not exist.  If the
1651.151Slukem                      value is defined and valid, then
1661.151Slukem                      ${MAKEOBJDIRPREFIX}/${.CURDIR} is used as the .OBJDIR
1671.151Slukem                      for the current directory.  The current directory may be
1681.151Slukem                      read only.
1691.151Slukem
1701.151Slukem                      Note: MAKEOBJDIRPREFIX can be provided only in the
1711.151Slukem                      environment or via the -M flag of build.sh; it cannot
1721.151Slukem                      usefully be set inside a Makefile, including in
1731.151Slukem                      mk.conf(5) or MAKECONF.
1741.151Slukem
1751.151Slukem     TMPDIR           Top-level directory to store temporary directories used
1761.151Slukem                      by build.sh before paths to other directories such as
1771.151Slukem                      .OBJDIR can be determined.
1781.149Slukem
1791.151Slukem                      Note: Must support execution of binaries.  I.e., without
1801.151Slukem                      mount(8)'s -o noexec option.
1811.149Slukem
1821.151Slukem                      Default: "/tmp".
1831.149Slukem
1841.105Swiz   "make" variables
1851.104Swiz     Several variables control the behavior of NetBSD builds.  Unless
1861.104Swiz     otherwise specified, these variables may be set in either the process
1871.150Slukem     environment or the make(1) configuration file mk.conf(5) specified by
1881.151Slukem     MAKECONF.
1891.151Slukem
1901.151Slukem     This list is not comprehensive; all supported variables and their
1911.151Slukem     defaults are documented in mk.conf(5).
1921.151Slukem
1931.151Slukem     BSDOBJDIR        The real path to the object directory tree for the
1941.151Slukem                      NetBSD source tree.
1951.151Slukem
1961.151Slukem                      Default: "/usr/obj"
1971.151Slukem
1981.151Slukem     BSDSRCDIR        The real path to the NetBSD source tree, if NETBSDSRCDIR
1991.151Slukem                      isn't defined.
2001.151Slukem
2011.151Slukem                      Default: "/usr/src"
2021.151Slukem
2031.151Slukem     BUILDID          Identifier for the build.  If set, this should be a
2041.151Slukem                      short string that is suitable for use as part of a file
2051.151Slukem                      or directory name.  The identifier will be appended to
2061.151Slukem                      object directory names, and can be consulted in the
2071.151Slukem                      make(1) configuration file in order to set additional
2081.151Slukem                      build parameters, such as compiler flags.  It will also
2091.151Slukem                      be used as part of the kernel version string, which can
2101.151Slukem                      be shown by "uname -v".
2111.151Slukem
2121.151Slukem                      Default: Unset.
2131.151Slukem
2141.151Slukem     BUILDINFO        Optional multi-line string containing information about
2151.151Slukem                      the build.  This will appear in DESTDIR/etc/release, and
2161.151Slukem                      it will be stored in the buildinfo variable in any
2171.151Slukem                      kernels that are built.  When such kernels are booted,
2181.151Slukem                      the sysctl(7) kern.buildinfo variable will report this
2191.151Slukem                      value.  The string may contain backslash escape
2201.151Slukem                      sequences, such as "\\" (representing a backslash
2211.151Slukem                      character) and "\n" (representing a newline).
2221.151Slukem
2231.151Slukem                      Default: Unset.
2241.151Slukem
2251.151Slukem     BUILDSEED        g++(1) uses random numbers when compiling C++ code.
2261.151Slukem                      This variable seeds the g++(1) random number generator
2271.151Slukem                      using -frandom-seed with this value.  By default, it is
2281.151Slukem                      set to "NetBSD-(majorversion)".  Using a fixed value
2291.151Slukem                      causes C++ binaries to be the same when built from the
2301.151Slukem                      same sources, resulting in identical (reproducible)
2311.151Slukem                      builds.  Additional information is available in the
2321.151Slukem                      g++(1) documentation of -frandom-seed.
2331.151Slukem
2341.151Slukem                      Default: Unset.
2351.151Slukem
2361.151Slukem     CPUFLAGS         Additional flags to the compiler/assembler to select CPU
2371.151Slukem                      instruction set options, CPU tuning options, etc.
2381.151Slukem
2391.151Slukem                      Default: Unset.
2401.151Slukem
2411.151Slukem     DESTDIR          Directory to contain the built NetBSD system.  If set,
2421.151Slukem                      special options are passed to the compilation tools to
2431.151Slukem                      prevent their default use of the host system's
2441.151Slukem                      /usr/include, /usr/lib, and so forth.  This pathname
2451.151Slukem                      must be an absolute path, and should not end with a
2461.151Slukem                      slash (/) character.  (For installation into the
2471.151Slukem                      system's root directory, set DESTDIR to an empty string,
2481.151Slukem                      not to "/").  The directory must reside on a file system
2491.151Slukem                      which supports long file names and hard links.
2501.151Slukem
2511.151Slukem                      Note: build.sh will provide a default of destdir.MACHINE
2521.151Slukem                      (in the top-level .OBJDIR) unless run in `expert' mode.
2531.151Slukem
2541.151Slukem                      Default: Empty string if USETOOLS is "yes"; unset
2551.151Slukem                      otherwise.
2561.151Slukem
2571.151Slukem     EXTERNAL_TOOLCHAIN
2581.151Slukem                      If defined, this variable indicates the root directory
2591.151Slukem                      of an external toolchain which will be used to build the
2601.151Slukem                      tree.  For example, if a platform is a TOOLCHAIN_MISSING
2611.151Slukem                      platform, EXTERNAL_TOOLCHAIN can be used to re-enable
2621.151Slukem                      the cross-compile framework.
2631.151Slukem
2641.151Slukem                      If EXTERNAL_TOOLCHAIN is defined, act as MKGCC=no, since
2651.151Slukem                      the external version of the compiler may not be able to
2661.151Slukem                      build the library components of the in-tree compiler.
2671.151Slukem
2681.151Slukem                      This variable should be used in conjunction with an
2691.151Slukem                      appropriate HAVE_GCC or HAVE_LLVM setting to control the
2701.151Slukem                      compiler flags.
2711.151Slukem
2721.151Slukem                      Note: This variable is not yet used in as many places as
2731.151Slukem                      it should be.  Expect the exact semantics of this
2741.151Slukem                      variable to change in the short term as parts of the
2751.151Slukem                      cross-compile framework continue to be cleaned up.
2761.151Slukem
2771.151Slukem                      Default: Unset.
2781.151Slukem
2791.151Slukem     MAKEVERBOSE      Level of verbosity of status messages.  Supported
2801.151Slukem                      values:
2811.151Slukem
2821.151Slukem                      0   No descriptive messages or commands executed by
2831.151Slukem                          make(1) are shown.
2841.151Slukem
2851.151Slukem                      1   Brief messages are shown describing what is being
2861.151Slukem                          done, but the actual commands executed by make(1)
2871.151Slukem                          are not shown.
2881.151Slukem
2891.151Slukem                      2   Descriptive messages are shown as above (prefixed
2901.151Slukem                          with a `#'), and ordinary commands performed by
2911.151Slukem                          make(1) are shown.
2921.151Slukem
2931.151Slukem                      3   In addition to the above, all commands performed by
2941.151Slukem                          make(1) are shown, even if they would ordinarily
2951.151Slukem                          have been hidden through use of the "@" prefix in
2961.151Slukem                          the relevant makefile.
2971.151Slukem
2981.151Slukem                      4   In addition to the above, commands executed by
2991.151Slukem                          make(1) are traced through use of the sh(1) "-x"
3001.151Slukem                          flag.
3011.151Slukem
3021.151Slukem                      Default: 2
3031.151Slukem
3041.151Slukem     MKCATPAGES       Can be set to "yes" or "no".  Indicates whether
3051.151Slukem                      preformatted plaintext manual pages will be created and
3061.151Slukem                      installed.
3071.151Slukem
3081.151Slukem                      Forced to "no" if MKMAN=no or MKSHARE=no.
3091.151Slukem
3101.151Slukem                      Default: "no"
3111.151Slukem
3121.151Slukem     MKCROSSGDB       Can be set to "yes" or "no".  Create a cross-gdb as a
3131.151Slukem                      host tool.
3141.1Stv
3151.151Slukem                      Default: "no"
3161.151Slukem
3171.151Slukem     MKDEBUG          Can be set to "yes" or "no".  Indicates whether debug
3181.151Slukem                      information should be generated for all userland
3191.151Slukem                      binaries.  The result is collected as an additional
3201.151Slukem                      debug.tgz and xdebug.tgz set and installed in
3211.151Slukem                      DESTDIR/usr/libdata/debug.
3221.151Slukem
3231.151Slukem                      Forced to "no" if NODEBUG is defined, usually in the
3241.151Slukem                      Makefile before any make(1) .include directives.
3251.151Slukem
3261.151Slukem                      Default: "no"
3271.151Slukem
3281.151Slukem     MKDEBUGKERNEL    Can be set to "yes" or "no".  Indicates whether
3291.151Slukem                      debugging symbols will be built for kernels by default;
3301.151Slukem                      pretend as if makeoptions DEBUG="-g" is specified in
3311.151Slukem                      kernel configuration files.  This will also put the
3321.151Slukem                      debug kernel netbsd.gdb in the kernel sets.  See
3331.151Slukem                      options(4) for details.  This is useful if a cross-gdb
3341.151Slukem                      is built as well (see MKCROSSGDB).
3351.151Slukem
3361.151Slukem                      Default: "no"
3371.151Slukem
3381.151Slukem     MKDEBUGLIB       Can be set to "yes" or "no".  Indicates whether debug
3391.151Slukem                      libraries (lib*_g.a) will be built and installed.  Debug
3401.151Slukem                      libraries are compiled with "-g -DDEBUG".
3411.151Slukem
3421.151Slukem                      Forced to "no" if NODEBUGLIB is defined, usually in the
3431.151Slukem                      Makefile before any make(1) .include directives.
3441.151Slukem
3451.151Slukem                      Default: "no"
3461.151Slukem
3471.151Slukem     MKDEBUGTOOLS     Can be set to "yes" or "no".  Indicates whether debug
3481.151Slukem                      information (lib*_g.a) will be included in the build
3491.151Slukem                      toolchain.
3501.151Slukem
3511.151Slukem                      Default: "no"
3521.107Sapb
3531.151Slukem     MKDOC            Can be set to "yes" or "no".  Indicates whether system
3541.151Slukem                      documentation destined for DESTDIR/usr/share/doc will be
3551.151Slukem                      installed.
3561.151Slukem
3571.151Slukem                      Forced to "no" if NODOC is defined, usually in the
3581.151Slukem                      Makefile before any make(1) .include directives.
3591.151Slukem
3601.151Slukem                      Forced to "no" if MKSHARE=no.
3611.151Slukem
3621.151Slukem                      Default: "yes"
3631.151Slukem
3641.151Slukem     MKHOSTOBJ        Can be set to "yes" or "no".  If set to "yes", then for
3651.151Slukem                      programs intended to be run on the compile host, the
3661.151Slukem                      name, release, and architecture of the host operating
3671.151Slukem                      system will be suffixed to the name of the object
3681.151Slukem                      directory created by "make obj".  (This allows multiple
3691.151Slukem                      host systems to compile NetBSD for a single target.)  If
3701.151Slukem                      set to "no", then programs built to be run on the
3711.151Slukem                      compile host will use the same object directory names as
3721.151Slukem                      programs built to be run on the target.
3731.9Sthorpej
3741.151Slukem                      Default: "no"
3751.108Sapb
3761.151Slukem     MKHTML           Can be set to "yes" or "no".  Indicates whether the HTML
3771.151Slukem                      manual pages are created and installed.  and installed
3781.108Sapb
3791.151Slukem                      Forced to "no" if NOHTML is defined, usually in the
3801.151Slukem                      Makefile before any make(1) .include directives.
3811.104Swiz
3821.151Slukem                      Forced to "no" if MKMAN=no or MKSHARE=no.
3831.138Sthorpej
3841.151Slukem                      Default: "yes"
3851.138Sthorpej
3861.151Slukem     MKINFO           Can be set to "yes" or "no".  Indicates whether GNU Info
3871.151Slukem                      files, used for the documentation for most of the
3881.151Slukem                      compilation tools, will be built and installed.
3891.1Stv
3901.151Slukem                      Forced to "no" if NOINFO is defined, usually in the
3911.151Slukem                      Makefile before any make(1) .include directives.
3921.1Stv
3931.151Slukem                      Forced to "no" if MKSHARE=no.
3941.30Slukem
3951.151Slukem                      Default: "yes"
3961.45Slukem
3971.151Slukem     MKKDEBUG         Deprecated, use MKDEBUGKERNEL.
3981.45Slukem
3991.151Slukem     MKKMOD           Can be set to "yes" or "no".  Indicates whether kernel
4001.151Slukem                      modules are built and installed.
4011.80Sapb
4021.151Slukem                      Default: "no" on or1k; "yes" on other platforms.
4031.80Sapb
4041.151Slukem     MKLINKLIB        Can be set to "yes" or "no".  Indicates whether all of
4051.151Slukem                      the shared library infrastructure will be built and
4061.151Slukem                      installed.  If "no", prevents: installation of the *.a
4071.151Slukem                      libraries, installation of the *_pic.a libraries on PIC
4081.151Slukem                      systems, building of *.a libraries on PIC systems, or
4091.151Slukem                      installation of .so symlinks on ELF systems.
4101.45Slukem
4111.151Slukem                      Forced to "no" if NOLINKLIB is defined, usually in the
4121.151Slukem                      Makefile before any make(1) .include directives.
4131.45Slukem
4141.151Slukem                      If "no", acts as MKLINT=no MKPICINSTALL=no MKPROFILE=no.
4151.45Slukem
4161.151Slukem                      Default: "yes"
4171.140Skamil
4181.151Slukem     MKLINT           Can be set to "yes" or "no".  Indicates whether lint(1)
4191.151Slukem                      will be run against portions of the NetBSD source code
4201.151Slukem                      during the build, and whether lint libraries will be
4211.151Slukem                      installed into DESTDIR/usr/libdata/lint.
4221.140Skamil
4231.151Slukem                      Forced to "no" if NOLINT is defined, usually in the
4241.151Slukem                      Makefile before any make(1) .include directives.
4251.106Swiz
4261.151Slukem                      Forced to "no" if MKLINKLIB=no.
4271.106Swiz
4281.151Slukem                      Default: "no"
4291.106Swiz
4301.151Slukem     MKMAN            Can be set to "yes" or "no".  Indicates whether manual
4311.151Slukem                      pages will be installed.
4321.106Swiz
4331.151Slukem                      Forced to "no" if NOMAN is defined, usually in the
4341.151Slukem                      Makefile before any make(1) .include directives.
4351.106Swiz
4361.151Slukem                      Forced to "no" if MKSHARE=no.
4371.106Swiz
4381.151Slukem                      If "no", acts as MKCATPAGES=no MKHTML=no.
4391.1Stv
4401.151Slukem                      Default: "yes"
4411.1Stv
4421.151Slukem     MKNLS            Can be set to "yes" or "no".  Indicates whether Native
4431.151Slukem                      Language System (NLS) locale zone files will be built
4441.151Slukem                      and installed.
4451.77Slukem
4461.151Slukem                      Forced to "no" if NONLS is defined, usually in the
4471.151Slukem                      Makefile before any make(1) .include directives.
4481.77Slukem
4491.151Slukem                      Forced to "no" if MKSHARE=no.
4501.4Stv
4511.151Slukem                      Default: "yes"
4521.4Stv
4531.151Slukem     MKOBJ            Can be set to "yes" or "no".  Indicates whether object
4541.151Slukem                      directories will be created when running "make obj".  If
4551.151Slukem                      set to "no", then all built files will be located inside
4561.151Slukem                      the regular source tree.
4571.1Stv
4581.151Slukem                      Forced to "no" if NOOBJ is defined, usually in the
4591.151Slukem                      Makefile before any make(1) .include directives.
4601.1Stv
4611.151Slukem                      If "no", acts as MKOBJDIRS=no.
4621.143Slukem
4631.151Slukem                      Note: Setting MKOBJ to "no" is not recommended and may
4641.151Slukem                      cause problems when updating the tree with cvs(1).
4651.143Slukem
4661.151Slukem                      Default: "yes"
4671.95Sapb
4681.151Slukem     MKOBJDIRS        Can be set to "yes" or "no".  Indicates whether object
4691.151Slukem                      directories will be created automatically (via a "make
4701.151Slukem                      obj" pass) at the start of a build.
4711.95Sapb
4721.151Slukem                      Forced to "no" if MKOBJ=no.
4731.1Stv
4741.151Slukem                      Default: "no"
4751.1Stv
4761.151Slukem     MKPIC            Can be set to "yes" or "no".  Indicates whether shared
4771.151Slukem                      objects and libraries will be created and installed.  If
4781.151Slukem                      "no", the entire built system will be statically linked.
4791.1Stv
4801.151Slukem                      Forced to "no" if NOPIC is defined, usually in the
4811.151Slukem                      Makefile before any make(1) .include directives.
4821.1Stv
4831.151Slukem                      If "no", acts as MKPICLIB=no.
4841.1Stv
4851.151Slukem                      Default: "no" on m68000; "yes" on other platforms.
4861.1Stv
4871.151Slukem     MKPICINSTALL     Can be set to "yes" or "no".  Indicates whether the
4881.151Slukem                      ar(1) format libraries (lib*_pic.a), used to generate
4891.151Slukem                      shared libraries, are installed.
4901.1Stv
4911.151Slukem                      Forced to "no" if NOPICINSTALL is defined, usually in
4921.151Slukem                      the Makefile before any make(1) .include directives.
4931.1Stv
4941.151Slukem                      Forced to "no" if MKLINKLIB=no.
4951.70Sdholland
4961.151Slukem                      Default: "no"
4971.1Stv
4981.151Slukem     MKPROFILE        Can be set to "yes" or "no".  Indicates whether profiled
4991.151Slukem                      libraries (lib*_p.a) will be built and installed.
5001.1Stv
5011.151Slukem                      Forced to "no" if NOPROFILE is defined, usually in the
5021.151Slukem                      Makefile before any make(1) .include directives.
5031.1Stv
5041.151Slukem                      Forced to "no" if MKLINKLIB=no.
5051.1Stv
5061.151Slukem                      Default: "no" on or1k, riscv32, and riscv64 (due to
5071.151Slukem                      toolchain problems with profiled code); "yes" on other
5081.151Slukem                      platforms.
5091.1Stv
5101.151Slukem     MKREPRO          Can be set to "yes" or "no".  Indicates whether builds
5111.151Slukem                      are to be reproducible.  If "yes", two builds from the
5121.151Slukem                      same source tree will produce the same build results.
5131.1Stv
5141.151Slukem                      Used as the default for MKARZERO.
5151.100Swiz
5161.151Slukem                      This may be set to "yes" by giving build.sh the -P
5171.151Slukem                      option.
5181.151Slukem
5191.151Slukem                      Default: "no" Can be set to "yes" or "no".
5201.100Swiz
5211.122Swiz     MKREPRO_TIMESTAMP
5221.151Slukem                      Unix timestamp.  When MKREPRO is set, the timestamp of
5231.151Slukem                      all files in the sets will be set to this value.
5241.151Slukem
5251.151Slukem                      This may be set automatically to the latest source tree
5261.151Slukem                      timestamp using cvslatest(1) by giving build.sh the -P
5271.151Slukem                      option.
5281.151Slukem
5291.151Slukem                      Default: Unset.
5301.151Slukem
5311.151Slukem     MKSHARE          Can be set to "yes" or "no".  Indicates whether files
5321.151Slukem                      destined to reside in DESTDIR/usr/share will be built
5331.151Slukem                      and installed.
5341.151Slukem
5351.151Slukem                      Forced to "no" if NOSHARE is defined, usually in the
5361.151Slukem                      Makefile before any make(1) .include directives.
5371.122Swiz
5381.151Slukem                      If "no", acts as MKCATPAGES=no MKDOC=no MKINFO=no
5391.151Slukem                      MKHTML=no MKMAN=no MKNLS=no.
5401.49Slukem
5411.151Slukem                      Default: "yes"
5421.151Slukem
5431.151Slukem     MKSTRIPIDENT     Can be set to "yes" or "no".  Indicates whether RCS IDs,
5441.151Slukem                      for use with ident(1), should be stripped from program
5451.151Slukem                      binaries and shared libraries.
5461.151Slukem
5471.151Slukem                      Default: "no"
5481.151Slukem
5491.151Slukem     MKSTRIPSYM       Can be set to "yes" or "no".  Indicates whether all
5501.151Slukem                      local symbols should be stripped from shared libraries.
5511.151Slukem                      If "yes", strip all local symbols from shared libraries;
5521.151Slukem                      the affect is equivalent to the -x option of ld(1).  If
5531.151Slukem                      "no", strip only temporary local symbols; the affect is
5541.151Slukem                      equivalent to the -X option of ld(1).  Keeping non-
5551.151Slukem                      temporary local symbols such as static function names is
5561.151Slukem                      useful on using DTrace for userland libraries and
5571.151Slukem                      getting a backtrace from a rump kernel loading shared
5581.151Slukem                      libraries.
5591.151Slukem
5601.151Slukem                      Default: "yes"
5611.151Slukem
5621.151Slukem     MKUNPRIVED       Can be set to "yes" or "no".  Indicates whether an
5631.151Slukem                      unprivileged install will occur.  The user, group,
5641.151Slukem                      permissions, and file flags, will not be set on the
5651.151Slukem                      installed items; instead the information will be
5661.151Slukem                      appended to a file called METALOG in DESTDIR.  The
5671.151Slukem                      contents of METALOG are used during the generation of
5681.151Slukem                      the distribution tar files to ensure that the
5691.151Slukem                      appropriate file ownership is stored.
5701.151Slukem
5711.151Slukem                      Default: "no"
5721.151Slukem
5731.151Slukem     MKUPDATE         Can be set to "yes" or "no".  Indicates whether all
5741.151Slukem                      install operations intended to write to DESTDIR will
5751.151Slukem                      compare file timestamps before installing, and skip the
5761.151Slukem                      install phase if the destination files are up-to-date.
5771.151Slukem
5781.151Slukem                      Note: This also has implications on full builds (see
5791.151Slukem                      next subsection).
5801.151Slukem
5811.151Slukem                      Default: "no"
5821.151Slukem
5831.151Slukem     MKX11            Can be set to "yes" or "no".  Indicates whether X11 is
5841.151Slukem                      built and installed from X11SRCDIR.
5851.151Slukem
5861.151Slukem                      Default: "no"
5871.151Slukem
5881.151Slukem     NETBSDSRCDIR     The path to the top level of the NetBSD sources.
5891.151Slukem
5901.151Slukem                      Default: Top level of the NetBSD source tree (as
5911.151Slukem                      determined by the presence of build.sh and tools/) if
5921.151Slukem                      make(1) is run from within that tree; otherwise
5931.151Slukem                      BSDSRCDIR will be used.
5941.151Slukem
5951.151Slukem     TOOLCHAIN_MISSING
5961.151Slukem                      Can be set to "yes" or "no".  If not "no", this
5971.151Slukem                      indicates that the platform "MACHINE_ARCH" being built
5981.151Slukem                      does not have a working in-tree toolchain.
5991.151Slukem
6001.151Slukem                      If not "no", acts as MKBINUTILS=no MKGCC=no MKGDB=no.
6011.151Slukem
6021.151Slukem                      Default: "no"
6031.151Slukem
6041.151Slukem     TOOLDIR          Directory to hold the host tools, once built.  If
6051.151Slukem                      specified, must be an absolute path.  This directory
6061.151Slukem                      should be unique to a given host system and NetBSD
6071.151Slukem                      source tree.  (However, multiple targets may share the
6081.151Slukem                      same TOOLDIR; the target-dependent files have unique
6091.151Slukem                      names.)  If unset, a default based on the uname(1)
6101.151Slukem                      information of the host platform will be created in the
6111.151Slukem                      .OBJDIR of src.
6121.151Slukem
6131.151Slukem                      Default: Unset.
6141.151Slukem
6151.151Slukem     USETOOLS         Can be set to "yes" or "no".  Indicates whether the
6161.151Slukem                      tools specified by TOOLDIR should be used as part of a
6171.151Slukem                      build in progress.  Must be set to "yes" if cross-
6181.151Slukem                      compiling.
6191.151Slukem
6201.151Slukem                      yes    Use the tools from TOOLDIR.
6211.151Slukem
6221.151Slukem                      no     Do not use the tools from TOOLDIR, but refuse to
6231.151Slukem                             build native compilation tool components that are
6241.151Slukem                             version-specific for that tool.
6251.151Slukem
6261.151Slukem                      never  Do not use the tools from TOOLDIR, even when
6271.151Slukem                             building native tool components.  This is similar
6281.151Slukem                             to the traditional NetBSD build method, but does
6291.151Slukem                             not verify that the compilation tools in use are
6301.151Slukem                             up-to-date enough in order to build the tree
6311.151Slukem                             successfully.  This may cause build or runtime
6321.151Slukem                             problems when building the whole NetBSD source
6331.151Slukem                             tree.
6341.151Slukem
6351.151Slukem                      Default: "no" when using <bsd.*.mk> outside the NetBSD
6361.151Slukem                      source tree (detected automatically) or if
6371.151Slukem                      TOOLCHAIN_MISSING=yes; "yes" otherwise.
6381.151Slukem
6391.151Slukem     X11SRCDIR        Directory containing the modular Xorg source.  If
6401.151Slukem                      specified, must be an absolute path.  The main modular
6411.151Slukem                      Xorg source is found in X11SRCDIR/external/mit.
6421.151Slukem
6431.151Slukem                      Default: NETBSDSRCDIR/../xsrc, if that exists; otherwise
6441.151Slukem                      /usr/xsrc.
6451.49Slukem
6461.105Swiz   "make" variables for full builds
6471.126Swiz     These variables only affect the top level "Makefile" and do not affect
6481.7Slukem     manually building subtrees of the NetBSD source code.
6491.1Stv
6501.147Slukem     INSTALLBOOT_BOARDS
6511.147Slukem                      A list of boards to create bootable images for.  If
6521.147Slukem                      corresponding U-Boot packages are installed, bootable
6531.147Slukem                      images are created as part of a release.  See the
6541.147Slukem                      -o board=name option of installboot(8).
6551.147Slukem
6561.126Swiz     INSTALLWORLDDIR  Location for the "make installworld" target to install
6571.59Sapb                      to.  If specified, must be an absolute path.
6581.1Stv
6591.126Swiz                      Default: "/"
6601.1Stv
6611.126Swiz     MKOBJDIRS        Can be set to "yes" or "no".  Indicates whether object
6621.126Swiz                      directories will be created automatically (via a "make
6631.126Swiz                      obj" pass) at the start of a build.
6641.1Stv
6651.126Swiz                      Default: "no"
6661.1Stv
6671.126Swiz                      If using build.sh, the default is "yes".  This may be
6681.126Swiz                      set back to "no" by giving build.sh the -o option.
6691.70Sdholland
6701.126Swiz     MKUPDATE         Can be set to "yes" or "no".  If set, then in addition
6711.126Swiz                      to the effects described for MKUPDATE=yes above, this
6721.126Swiz                      implies the effects of NOCLEANDIR (i.e., "make cleandir"
6731.126Swiz                      is avoided).
6741.38Slukem
6751.126Swiz                      Default: "no"
6761.38Slukem
6771.105Swiz                      If using build.sh, this may be set by giving the -u
6781.70Sdholland                      option.
6791.70Sdholland
6801.105Swiz     NBUILDJOBS       Now obsolete.  Use the make(1) option -j, instead.  See
6811.70Sdholland                      below.
6821.1Stv
6831.105Swiz                      Default: Unset.
6841.1Stv
6851.126Swiz     NOCLEANDIR       If set, avoids the "make cleandir" phase of a full
6861.20Slukem                      build.  This has the effect of allowing only changed
6871.20Slukem                      files in a source tree to be recompiled.  This can speed
6881.20Slukem                      up builds when updating only a few files in the tree.
6891.1Stv
6901.105Swiz                      Default: Unset.
6911.1Stv
6921.105Swiz                      See also MKUPDATE.
6931.70Sdholland
6941.126Swiz     NODISTRIBDIRS    If set, avoids the "make distrib-dirs" phase of a full
6951.105Swiz                      build.  This skips running mtree(8) on DESTDIR, useful
6961.20Slukem                      on systems where building as an unprivileged user, or
6971.20Slukem                      where it is known that the system-wide mtree files have
6981.20Slukem                      not changed.
6991.1Stv
7001.105Swiz                      Default: Unset.
7011.1Stv
7021.126Swiz     NOINCLUDES       If set, avoids the "make includes" phase of a full
7031.20Slukem                      build.  This has the effect of preventing make(1) from
7041.44Slukem                      thinking that some programs are out-of-date simply
7051.44Slukem                      because the system include files have changed.  However,
7061.20Slukem                      this option should not be used when updating the entire
7071.20Slukem                      NetBSD source tree arbitrarily; it is suggested to use
7081.105Swiz                      MKUPDATE=yes instead in that case.
7091.1Stv
7101.105Swiz                      Default: Unset.
7111.1Stv
7121.105Swiz     RELEASEDIR       If set, specifies the directory to which a release(7)
7131.126Swiz                      layout will be written at the end of a "make release".
7141.59Sapb                      If specified, must be an absolute path.
7151.20Slukem
7161.105Swiz                      Note: build.sh will provide a default of releasedir (in
7171.105Swiz                      the top-level .OBJDIR) unless run in `expert' mode.
7181.30Slukem
7191.151Slukem                      Default: Unset.
7201.151Slukem
7211.105SwizBUILDING
7221.105Swiz   "make" command line options
7231.52Sjmc     This is not a summary of all the options available to make(1); only the
7241.52Sjmc     options used most frequently with NetBSD builds are listed here.
7251.1Stv
7261.105Swiz     -j njob    Run up to njob make(1) subjobs in parallel.  Makefiles should
7271.52Sjmc                use .WAIT or have explicit dependencies as necessary to
7281.74Sapb                enforce build ordering.
7291.10Ssommerfe
7301.105Swiz     -m dir     Specify the default directory for searching for system
7311.104Swiz                Makefile segments, mainly the <bsd.*.mk> files.  When building
7321.104Swiz                any full NetBSD source tree, this should be set to the
7331.126Swiz                "share/mk" directory in the source tree.  This is set
7341.104Swiz                automatically when building from the top level, or when using
7351.105Swiz                build.sh.
7361.1Stv
7371.148Slukem     -n         Show the commands that would have been executed, but do not
7381.1Stv                actually execute them.  This will still cause recursion to
7391.1Stv                take place.
7401.1Stv
7411.148Slukem     -V var     Show make(1)'s idea of the value of var.  Does not build any
7421.1Stv                targets.
7431.1Stv
7441.105Swiz     var=value  Set the variable var to value, overriding any setting
7451.105Swiz                specified by the process environment, the MAKECONF
7461.104Swiz                configuration file, or the system Makefile segments.
7471.1Stv
7481.105Swiz   "make" targets
7491.1Stv     These default targets may be built by running make(1) in any subtree of
7501.1Stv     the NetBSD source code.  It is recommended that none of these be used
7511.126Swiz     from the top level Makefile; as a specific exception, "make obj" and
7521.126Swiz     "make cleandir" are useful in that context.
7531.1Stv
7541.105Swiz     all        Build programs, libraries, and preformatted documentation.
7551.1Stv
7561.105Swiz     clean      Remove program and library object code files.
7571.1Stv
7581.105Swiz     cleandir   Same as clean, but also remove preformatted documentation,
7591.126Swiz                dependency files generated by "make depend", and any other
7601.49Slukem                files known to be created at build time.
7611.1Stv
7621.105Swiz     depend     Create dependency files (.depend) containing more detailed
7631.44Slukem                information about the dependencies of source code on header
7641.1Stv                files.  Allows programs to be recompiled automatically when a
7651.1Stv                dependency changes.
7661.1Stv
7671.126Swiz     dependall  Does a "make depend" immediately followed by a "make all".
7681.10Ssommerfe                This improves cache locality of the build since both passes
7691.10Ssommerfe                read the source files in their entirety.
7701.1Stv
7711.105Swiz     distclean  Synonym for cleandir.
7721.49Slukem
7731.105Swiz     includes   Build and install system header files.  Typically needed
7741.44Slukem                before any system libraries or programs can be built.
7751.1Stv
7761.105Swiz     install    Install programs, libraries, and documentation into DESTDIR.
7771.105Swiz                Few files will be installed to DESTDIR/dev, DESTDIR/etc,
7781.105Swiz                DESTDIR/root or DESTDIR/var in order to prevent user supplied
7791.27Slukem                configuration data from being overwritten.
7801.1Stv
7811.105Swiz     lint       Run lint(1) against the C source code, where appropriate, and
7821.1Stv                generate system-installed lint libraries.
7831.1Stv
7841.105Swiz     obj        Create object directories to be used for built files, instead
7851.1Stv                of building directly in the source tree.
7861.1Stv
7871.105Swiz     tags       Create ctags(1) searchable function lists usable by the ex(1)
7881.1Stv                and vi(1) text editors.
7891.1Stv
7901.105Swiz   "make" targets for the top level
7911.1Stv     Additional make(1) targets are usable specifically from the top source
7921.1Stv     level to facilitate building the entire NetBSD source tree.
7931.1Stv
7941.105Swiz     build         Build the entire NetBSD system (except the kernel).  This
7951.68Sreed                   orders portions of the source tree such that prerequisites
7961.68Sreed                   will be built in the proper order.
7971.20Slukem
7981.126Swiz     distribution  Do a "make build", and then install a full distribution
7991.105Swiz                   (which does not include a kernel) into DESTDIR, including
8001.105Swiz                   files in DESTDIR/dev, DESTDIR/etc, DESTDIR/root and
8011.105Swiz                   DESTDIR/var.
8021.20Slukem
8031.126Swiz     buildworld    As per "make distribution", except that it ensures that
8041.105Swiz                   DESTDIR is not the root directory.
8051.20Slukem
8061.105Swiz     installworld  Install the distribution from DESTDIR to INSTALLWORLDDIR,
8071.70Sdholland                   which defaults to the root directory.  Ensures that
8081.105Swiz                   INSTALLWORLDDIR is not the root directory if cross
8091.104Swiz                   compiling.
8101.20Slukem
8111.105Swiz                   The INSTALLSETS environment variable may be set to a space-
8121.95Sapb                   separated list of distribution sets to be installed.  By
8131.126Swiz                   default, all sets except "etc" and "xetc" are installed, so
8141.126Swiz                   most files in INSTALLWORLDDIR/etc will not be installed or
8151.126Swiz                   modified.
8161.61Sapb
8171.105Swiz                   Note: Before performing this operation with
8181.105Swiz                   INSTALLWORLDDIR=/, it is highly recommended that you
8191.61Sapb                   upgrade your kernel and reboot.  After performing this
8201.61Sapb                   operation, it is recommended that you use etcupdate(8) to
8211.105Swiz                   update files in INSTALLWORLDDIR/etc, and postinstall(8) to
8221.102Sabs                   check for or fix inconsistencies.
8231.20Slukem
8241.105Swiz     sets          Create distribution sets from DESTDIR into
8251.105Swiz                   RELEASEDIR/RELEASEMACHINEDIR/binary/sets.  Should be run
8261.126Swiz                   after "make distribution", as "make build" alone does not
8271.126Swiz                   install all of the required files.
8281.25Slukem
8291.105Swiz     sourcesets    Create source sets of the source tree into
8301.105Swiz                   RELEASEDIR/source/sets.
8311.31Slukem
8321.105Swiz     syspkgs       Create syspkgs from DESTDIR into
8331.105Swiz                   RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.  Should be run
8341.126Swiz                   after "make distribution", as "make build" alone does not
8351.126Swiz                   install all of the required files.
8361.54Sapb
8371.126Swiz     release       Do a "make distribution", build kernels, distribution
8381.126Swiz                   media, and install sets (this as per "make sets"), and then
8391.126Swiz                   package the system into a standard release layout as
8401.105Swiz                   described by release(7).  This requires that RELEASEDIR be
8411.25Slukem                   set (see above).
8421.1Stv
8431.105Swiz     iso-image     Create a NetBSD installation CD-ROM image in the
8441.114Ssnj                   RELEASEDIR/images directory.  The CD-ROM file system will
8451.114Ssnj                   have a layout as described in release(7).
8461.62Sapb
8471.62Sapb                   For most machine types, the CD-ROM will be bootable, and
8481.104Swiz                   will automatically run the sysinst(8) menu-based
8491.104Swiz                   installation program, which can be used to install or
8501.104Swiz                   upgrade a NetBSD system.  Bootable CD-ROMs also contain
8511.104Swiz                   tools that may be useful in repairing a damaged NetBSD
8521.104Swiz                   installation.
8531.62Sapb
8541.126Swiz                   Before "make iso-image" is attempted, RELEASEDIR must be
8551.126Swiz                   populated by "make release" or equivalent.
8561.62Sapb
8571.151Slukem                   Note: Other, smaller, CD-ROM images may be created in the
8581.151Slukem                   RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom directory
8591.151Slukem                   by "make release".  These smaller images usually contain
8601.151Slukem                   the same tools as the larger images in RELEASEDIR/images,
8611.151Slukem                   but do not contain additional content such as the
8621.151Slukem                   distribution sets.
8631.62Sapb
8641.151Slukem                   Note: The mac68k port still uses an older method of
8651.104Swiz                   creating CD-ROM images.  This requires the mkisofs(1)
8661.104Swiz                   utility, which is not part of NetBSD, but which can be
8671.105Swiz                   installed from pkgsrc/sysutils/cdrtools.
8681.56Sapb
8691.105Swiz     iso-image-source
8701.64Sjnemeth                   Create a NetBSD installation CD-ROM image in the
8711.114Ssnj                   RELEASEDIR/images directory.  The CD-ROM file system will
8721.114Ssnj                   have a layout as described in release(7).  It will have top
8731.64Sjnemeth                   level directories for the machine type and source.
8741.64Sjnemeth
8751.64Sjnemeth                   For most machine types, the CD-ROM will be bootable, and
8761.104Swiz                   will automatically run the sysinst(8) menu-based
8771.104Swiz                   installation program, which can be used to install or
8781.104Swiz                   upgrade a NetBSD system.  Bootable CD-ROMs also contain
8791.104Swiz                   tools that may be useful in repairing a damaged NetBSD
8801.104Swiz                   installation.
8811.64Sjnemeth
8821.126Swiz                   Before "make iso-image-source" is attempted, RELEASEDIR
8831.126Swiz                   must be populated by "make sourcesets release" or
8841.104Swiz                   equivalent.
8851.64Sjnemeth
8861.151Slukem                   Note: Other, smaller, CD-ROM images may be created in the
8871.151Slukem                   RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom directory
8881.151Slukem                   by "make release".  These smaller images usually contain
8891.151Slukem                   the same tools as the larger images in RELEASEDIR/images,
8901.151Slukem                   but do not contain additional content such as the
8911.151Slukem                   distribution sets.
8921.64Sjnemeth
8931.151Slukem                   Note: The mac68k port still uses an older method of
8941.104Swiz                   creating CD-ROM images.  This requires the mkisofs(1)
8951.104Swiz                   utility, which is not part of NetBSD, but which can be
8961.105Swiz                   installed from pkgsrc/sysutils/cdrtools.
8971.64Sjnemeth
8981.105Swiz     install-image
8991.98Sapb                   Create a bootable NetBSD installation disk image in the
9001.127Splunky                   RELEASEDIR/images directory.  The installation disk image
9011.127Splunky                   is suitable for copying to bootable USB flash memory
9021.127Splunky                   sticks, etc., for machines which are able to boot from such
9031.127Splunky                   devices.  The file system in the bootable disk image will
9041.127Splunky                   have a layout as described in release(7).
9051.97Stsutsui
9061.97Stsutsui                   The installation image is bootable, and will automatically
9071.97Stsutsui                   run the sysinst(8) menu-based installation program, which
9081.98Sapb                   can be used to install or upgrade a NetBSD system.  The
9091.98Sapb                   image also contains tools that may be useful in repairing a
9101.98Sapb                   damaged NetBSD installation.
9111.97Stsutsui
9121.126Swiz                   Before "make install-image" is attempted, RELEASEDIR must
9131.126Swiz                   be populated by "make release" or equivalent.  The build
9141.126Swiz                   must have been performed with MKUNPRIVED=yes because "make
9151.126Swiz                   install-image" relies on information in DESTDIR/METALOG.
9161.97Stsutsui
9171.120Spgoyette     live-image    Create NetBSD live images in the RELEASEDIR/images
9181.104Swiz                   directory.  The live image contains all necessary files to
9191.104Swiz                   boot NetBSD up to multi-user mode, including all files
9201.104Swiz                   which should be extracted during installation, NetBSD
9211.104Swiz                   disklabel, bootloaders, etc.
9221.104Swiz
9231.104Swiz                   The live image is suitable for use as a disk image in
9241.104Swiz                   virtual machine environments such as QEMU, and also useful
9251.104Swiz                   to boot NetBSD from a USB flash memory stick on a real
9261.98Sapb                   machine, without the need for installation.
9271.97Stsutsui
9281.126Swiz                   Before "make live-image" is attempted, RELEASEDIR must be
9291.126Swiz                   populated by "make release" or equivalent.  The build must
9301.126Swiz                   have been performed with MKUNPRIVED=yes because "make
9311.126Swiz                   install-image" relies on information in DESTDIR/METALOG.
9321.97Stsutsui
9331.105Swiz     regression-tests
9341.20Slukem                   Can only be run after building the regression tests in the
9351.126Swiz                   directory "regress".  Runs those compiled regression tests
9361.151Slukem                   on the local host.
9371.151Slukem
9381.151Slukem                   Note: Most tests are now managed instead using atf(7); this
9391.151Slukem                   target should probably run those as well but currently does
9401.151Slukem                   not.
9411.1Stv
9421.105Swiz   The "build.sh" script
9431.96Sapb     This script file is a shell script designed to build the entire NetBSD
9441.104Swiz     system on any host with a suitable modern shell and some common
9451.105Swiz     utilities.  The required shell features are described under the HOST_SH
9461.104Swiz     variable.
9471.96Sapb
9481.96Sapb     If a host system's default shell does support the required features, then
9491.96Sapb     we suggest that you explicitly specify a suitable shell using a command
9501.96Sapb     like
9511.96Sapb
9521.105Swiz           /path/to/suitable/shell build.sh [options]
9531.96Sapb
9541.105Swiz     The above command will usually enable build.sh to automatically set
9551.105Swiz     HOST_SH=/path/to/suitable/shell, but if that fails, then the following
9561.96Sapb     set of commands may be used instead:
9571.96Sapb
9581.105Swiz           HOST_SH=/path/to/suitable/shell
9591.96Sapb           export HOST_SH
9601.105Swiz           ${HOST_SH} build.sh [options]
9611.96Sapb
9621.105Swiz     If build.sh detects that it is being executed under an unsuitable shell,
9631.148Slukem     it attempts to exec a suitable shell instead, or shows an error message.
9641.105Swiz     If HOST_SH is not set explicitly, then build.sh sets a default using
9651.96Sapb     heuristics dependent on the host platform, or from the shell under which
9661.105Swiz     build.sh is executed (if that can be determined), or using the first copy
9671.105Swiz     of sh found in PATH.
9681.1Stv
9691.1Stv     All cross-compile builds, and most native builds, of the entire system
9701.126Swiz     should make use of build.sh rather than just running "make".  This way,
9711.104Swiz     the make(1) program will be bootstrapped properly, in case the host
9721.126Swiz     system has an older or incompatible "make" program.
9731.1Stv
9741.105Swiz     When compiling the entire system via build.sh, many make(1) variables are
9751.1Stv     set for you in order to help encapsulate the build process.  In the list
9761.105Swiz     of options below, variables that are automatically set by build.sh are
9771.1Stv     noted where applicable.
9781.1Stv
9791.105Swiz     The following operations are supported by build.sh:
9801.22Slukem
9811.126Swiz     build         Build the system as per "make build".  Before the main part
9821.126Swiz                   of the build commences, this command runs the obj operation
9831.126Swiz                   (unless the -o option is given), "make cleandir" (unless
9841.126Swiz                   the -u option is given), and the tools operation.
9851.22Slukem
9861.126Swiz     distribution  Build a full distribution as per "make distribution".  This
9871.126Swiz                   command first runs the build operation.
9881.22Slukem
9891.126Swiz     release       Build a full release as per "make release".  This command
9901.105Swiz                   first runs the distribution operation.
9911.22Slukem
9921.148Slukem     help          Show a help message, and exit.
9931.148Slukem
9941.105Swiz     makewrapper   Create the nbmake-MACHINE wrapper.  This operation is
9951.104Swiz                   automatically performed for any of the other operations.
9961.23Slukem
9971.126Swiz     cleandir      Perform "make cleandir".
9981.75Slukem
9991.126Swiz     obj           Perform "make obj".
10001.22Slukem
10011.105Swiz     tools         Build and install the host tools from src/tools.  This
10021.126Swiz                   command will first run "make obj" and "make cleandir" in
10031.126Swiz                   the tools subdirectory unless the -o or -u options
10041.104Swiz                   (respectively) are given.
10051.22Slukem
10061.126Swiz     install=idir  Install the contents of DESTDIR to idir, using "make
10071.151Slukem                   installworld".
10081.151Slukem
10091.151Slukem                   Note: Files that are part of the "etc" or "xetc" sets will
10101.151Slukem                   not be installed, unless overridden by the INSTALLSETS
10111.151Slukem                   environment variable.
10121.35Slukem
10131.105Swiz     kernel=kconf  Build a new kernel.  The kconf argument is the name of a
10141.105Swiz                   configuration file suitable for use by config(1).  If kconf
10151.22Slukem                   does not contain any `/' characters, the configuration file
10161.105Swiz                   is expected to be found in the KERNCONFDIR directory, which
10171.105Swiz                   is typically sys/arch/MACHINE/conf.  The new kernel will be
10181.105Swiz                   built in a subdirectory of KERNOBJDIR, which is typically
10191.105Swiz                   sys/arch/MACHINE/compile or an associated object directory.
10201.70Sdholland
10211.105Swiz                   This command does not imply the tools command; run the
10221.105Swiz                   tools command first unless it is certain that the tools
10231.70Sdholland                   already exist and are up to date.
10241.70Sdholland
10251.126Swiz                   This command will run "make cleandir" on the kernel in
10261.105Swiz                   question first unless the -u option is given.
10271.22Slukem
10281.106Swiz     kernel.gdb=kconf
10291.106Swiz                   Build a new kernel with debug information.  Similar to the
10301.106Swiz                   above kernel=kconf operation, but creates a netbsd.gdb file
10311.106Swiz                   alongside of the kernel netbsd, which contains a full
10321.106Swiz                   symbol table and can be used for debugging (for example
10331.106Swiz                   with a cross-gdb built by MKCROSSGDB).
10341.106Swiz
10351.113Suebayasi     kernels       This command will build all kernels defined in port
10361.113Suebayasi                   specific release build procedure.
10371.111Suebayasi
10381.112Suebayasi                   This command internally calls the kernel=kconf operation
10391.112Suebayasi                   for each found kernel configuration file.
10401.111Suebayasi
10411.105Swiz     modules       This command will build kernel modules and install them
10421.105Swiz                   into DESTDIR.
10431.86Sjnemeth
10441.105Swiz     releasekernel=kconf
10451.70Sdholland                   Install a gzip(1)ed copy of the kernel previously built by
10461.105Swiz                   kernel=kconf into
10471.105Swiz                   RELEASEDIR/RELEASEMACHINEDIR/binary/kernel, usually as
10481.126Swiz                   netbsd-kconf.gz, although the "netbsd" prefix is determined
10491.126Swiz                   from the "config" directives in kconf.
10501.24Slukem
10511.126Swiz     sets          Perform "make sets".
10521.31Slukem
10531.126Swiz     sourcesets    Perform "make sourcesets".
10541.22Slukem
10551.126Swiz     syspkgs       Perform "make syspkgs".
10561.54Sapb
10571.126Swiz     iso-image     Perform "make iso-image".
10581.56Sapb
10591.105Swiz     iso-image-source
10601.126Swiz                   Perform "make iso-image-source".
10611.65Sjnemeth
10621.105Swiz     install-image
10631.126Swiz                   Perform "make install-image".
10641.97Stsutsui
10651.126Swiz     live-image    Perform "make live-image".
10661.97Stsutsui
10671.148Slukem     list-arch     Show a list of valid MACHINE and MACHINE_ARCH settings, the
10681.148Slukem                   default MACHINE_ARCH for each MACHINE, and aliases for
10691.109Sapb                   MACHINE/MACHINE_ARCH pairs, and then exits.  The -m or -a
10701.109Sapb                   options (or both) may be used to specify glob patterns that
10711.109Sapb                   will be used to narrow the list of results; for example,
10721.131Sleot                   "build.sh -m 'evb*' -a '*arm*' list-arch" will list all
10731.109Sapb                   known MACHINE/MACHINE_ARCH values in which either MACHINE
10741.109Sapb                   or ALIAS matches the pattern `evb*', and MACHINE_ARCH
10751.109Sapb                   matches the pattern `*arm*'.
10761.109Sapb
10771.105Swiz     The following command line options alter the behaviour of the build.sh
10781.51Swiz     operations described above:
10791.1Stv
10801.109Sapb     -a arch   Set the value of MACHINE_ARCH to arch.  See the -m option for
10811.109Sapb               more information.
10821.9Sthorpej
10831.105Swiz     -B buildid
10841.105Swiz               Set the value of BUILDID to buildid.  This will also append the
10851.126Swiz               build identifier to the name of the "make" wrapper script so
10861.37Slukem               that the resulting name is of the form
10871.126Swiz               "nbmake-MACHINE-BUILDID".
10881.1Stv
10891.105Swiz     -C cdextras
10901.105Swiz               Append cdextras to the CDEXTRA variable, which is a space-
10911.104Swiz               separated list of files or directories that will be added to
10921.126Swiz               the CD-ROM image that may be create by the "iso-image" or
10931.126Swiz               "iso-image-source" operations.  Files will be added to the root
10941.126Swiz               of the CD-ROM image, whereas directories will be copied
10951.87Sapb               recursively.  If relative paths are specified, they will be
10961.87Sapb               converted to absolute paths before being used.  Multiple paths
10971.105Swiz               may be specified via multiple -C options, or via a single
10981.87Sapb               option whose argument contains multiple space-separated paths.
10991.66Sjnemeth
11001.136Suwe     -c compiler
11011.136Suwe               Select the compiler for the toolchain to build NetBSD and for
11021.136Suwe               inclusion in the NetBSD distribution.  Supported choices:
11031.136Suwe
11041.136Suwe                     clang
11051.136Suwe
11061.136Suwe                     gcc [default]
11071.136Suwe
11081.136Suwe               The compiler used to build the toolchain can be different; see
11091.136Suwe               HOST_CC and HOST_CXX.
11101.136Suwe
11111.105Swiz     -D dest   Set the value of DESTDIR to dest.  If a relative path is
11121.104Swiz               specified, it will be converted to an absolute path before
11131.104Swiz               being used.
11141.104Swiz
11151.105Swiz     -E        Set `expert' mode.  This overrides various sanity checks, and
11161.105Swiz               allows: DESTDIR does not have to be set to a non-root path for
11171.105Swiz               builds, and MKUNPRIVED=yes does not have to be set when
11181.104Swiz               building as a non-root user.
11191.23Slukem
11201.105Swiz               Note: It is highly recommended that you know what you are doing
11211.23Slukem               when you use this option.
11221.19Slukem
11231.148Slukem     -h        Show a help message, and exit.
11241.51Swiz
11251.105Swiz     -j njob   Run up to njob make(1) subjobs in parallel; passed through to
11261.74Sapb               make(1).  If you see failures for reasons other than running
11271.105Swiz               out of memory while using build.sh with -j, please save
11281.104Swiz               complete build logs so the failures can be analyzed.
11291.74Sapb
11301.105Swiz               To achieve the fastest builds, -j values between (1 + the
11311.104Swiz               number of CPUs) and (2 * the number of CPUs) are recommended.
11321.104Swiz               Use lower values on machines with limited memory or I/O
11331.104Swiz               bandwidth.
11341.104Swiz
11351.126Swiz     -M obj    Set MAKEOBJDIRPREFIX to obj.  Unsets MAKEOBJDIR.  See "-O obj"
11361.126Swiz               for more information.
11371.104Swiz
11381.105Swiz               For instance, if the source directory is /usr/src, a setting of
11391.126Swiz               "-M /usr/obj" will place build-time files under
11401.105Swiz               /usr/obj/usr/src/bin, /usr/obj/usr/src/lib,
11411.105Swiz               /usr/obj/usr/src/usr.bin, and so forth.
11421.88Sapb
11431.73Sapb               If a relative path is specified, it will be converted to an
11441.105Swiz               absolute path before being used.  build.sh imposes the
11451.105Swiz               restriction that the argument to the -M option must not begin
11461.126Swiz               with a "$" (dollar sign) character; otherwise it would be too
11471.104Swiz               difficult to determine whether the value is an absolute or a
11481.104Swiz               relative path.  If the directory does not already exist,
11491.105Swiz               build.sh will create it.
11501.18Slukem
11511.109Sapb     -m mach   Set the value of MACHINE to mach, unless the mach argument is
11521.109Sapb               an alias that refers to a MACHINE/MACHINE_ARCH pair, in which
11531.109Sapb               case both MACHINE and MACHINE_ARCH are set from the alias.
11541.109Sapb               Such aliases are interpreted entirely by build.sh; they are not
11551.109Sapb               used by any other part of the build system.  The MACHINE_ARCH
11561.109Sapb               setting implied by mach will override any value of MACHINE_ARCH
11571.109Sapb               in the process environment, but will not override a value set
11581.109Sapb               by the -a option.  All cross builds require -m, but if unset on
11591.109Sapb               a NetBSD host, the host's value of MACHINE will be detected and
11601.109Sapb               used automatically.
11611.109Sapb
11621.109Sapb               See the list-arch operation for a way to get a list of valid
11631.109Sapb               MACHINE and MACHINE_ARCH settings.
11641.1Stv
11651.105Swiz     -N noiselevel
11661.126Swiz               Set the "noisyness" level of the build, by setting MAKEVERBOSE
11671.126Swiz               to noiselevel.
11681.45Slukem
11691.105Swiz     -n        Show the commands that would be executed by build.sh, but do
11701.126Swiz               not make any changes.  This is similar in concept to "make -n".
11711.1Stv
11721.105Swiz     -O obj    Create an appropriate transform macro for MAKEOBJDIR that will
11731.105Swiz               place the built object files under obj.  Unsets
11741.105Swiz               MAKEOBJDIRPREFIX.
11751.88Sapb
11761.126Swiz               For instance, a setting of "-O /usr/obj" will place build-time
11771.126Swiz               files under /usr/obj/bin, /usr/obj/lib, /usr/obj/usr.bin, and
11781.126Swiz               so forth.
11791.88Sapb
11801.88Sapb               If a relative path is specified, it will be converted to an
11811.105Swiz               absolute path before being used.  build.sh imposes the
11821.105Swiz               restriction that the argument to the -O option must not contain
11831.126Swiz               a "$" (dollar sign) character.  If the directory does not
11841.105Swiz               already exist, build.sh will create it.
11851.73Sapb
11861.105Swiz               In normal use, exactly one of the -M or -O options should be
11871.105Swiz               specified.  If neither -M nor -O is specified, then a default
11881.78Sapb               object directory will be chosen according to rules in
11891.78Sapb               <bsd.obj.mk>.  Relying on this default is not recommended
11901.78Sapb               because it is determined by complex rules that are influenced
11911.78Sapb               by the values of several variables and by the location of the
11921.78Sapb               source directory.
11931.18Slukem
11941.151Slukem               Note: Placing the obj directory location outside of the default
11951.151Slukem               source tree hierarchy makes it easier to manually clear out old
11961.151Slukem               files in the event the "make cleandir" operation is unable to
11971.151Slukem               do so.  (See CAVEATS below.)
11981.151Slukem
11991.151Slukem               Note: The use of one of -M or -O is the only means of building
12001.151Slukem               multiple machine architecture userlands from the same source
12011.151Slukem               tree without cleaning between builds (in which case, one would
12021.151Slukem               specify distinct obj locations for each).
12031.109Sapb
12041.126Swiz     -o        Set the value of MKOBJDIRS to "no".  Otherwise, it will be
12051.126Swiz               automatically set to "yes".  This default is opposite to the
12061.105Swiz               behaviour when not using build.sh.
12071.1Stv
12081.148Slukem     -P        Set the value of MKREPRO and MKREPRO_TIMESTAMP to the latest
12091.148Slukem               source CVS timestamp for reproducible builds.
12101.148Slukem
12111.105Swiz     -R rel    Set the value of RELEASEDIR to rel.  If a relative path is
12121.59Sapb               specified, it will be converted to an absolute path before
12131.59Sapb               being used.
12141.18Slukem
12151.105Swiz     -r        Remove the contents of DESTDIR and TOOLDIR before building
12161.1Stv               (provides a clean starting point).  This will skip deleting
12171.105Swiz               DESTDIR if building on a native system to the root directory.
12181.1Stv
12191.105Swiz     -S seed   Change the value of BUILDSEED to seed.  This should rarely be
12201.72Sperry               necessary.
12211.72Sperry
12221.105Swiz     -T tools  Set the value of TOOLDIR to tools.  If a relative path is
12231.104Swiz               specified, it will be converted to an absolute path before
12241.126Swiz               being used.  If set, the bootstrap "make" will only be rebuilt
12251.126Swiz               if the source files for make(1) have changed.
12261.104Swiz
12271.105Swiz     -U        Set MKUNPRIVED=yes.
12281.104Swiz
12291.105Swiz     -u        Set MKUPDATE=yes.
12301.104Swiz
12311.105Swiz     -V var=[value]
12321.105Swiz               Set the environment variable var to an optional value.  This is
12331.105Swiz               propagated to the nbmake wrapper.
12341.105Swiz
12351.105Swiz     -w wrapper
12361.105Swiz               Create the nbmake wrapper script (see below) in a custom
12371.105Swiz               location, specified by wrapper.  This allows, for instance, to
12381.151Slukem               place the wrapper in PATH automatically.
12391.151Slukem
12401.151Slukem               Note: wrapper is the full name of the file, not just a
12411.151Slukem               directory name.  If a relative path is specified, it will be
12421.151Slukem               converted to an absolute path before being used.
12431.1Stv
12441.105Swiz     -X x11src
12451.105Swiz               Set the value of X11SRCDIR to x11src.  If a relative path is
12461.59Sapb               specified, it will be converted to an absolute path before
12471.59Sapb               being used.
12481.49Slukem
12491.105Swiz     -x        Set MKX11=yes.
12501.49Slukem
12511.105Swiz     -Z var    Unset ("zap") the environment variable var.  This is propagated
12521.105Swiz               to the nbmake wrapper.
12531.40Slukem
12541.148Slukem     -?        Show a help message, and exit.
12551.148Slukem
12561.105Swiz   The "nbmake-MACHINE" wrapper script
12571.105Swiz     If using the build.sh script to build NetBSD, a nbmake-MACHINE script
12581.105Swiz     will be created in TOOLDIR/bin upon the first build to assist in building
12591.1Stv     subtrees on a cross-compile host.
12601.1Stv
12611.105Swiz     nbmake-MACHINE can be invoked in lieu of make(1), and will instead call
12621.126Swiz     the up-to-date version of "nbmake" installed into TOOLDIR/bin with
12631.105Swiz     several key variables pre-set, including MACHINE, MACHINE_ARCH, and
12641.105Swiz     TOOLDIR.  nbmake-MACHINE will also set variables specified with -V, and
12651.105Swiz     unset variables specified with -Z.
12661.40Slukem
12671.105Swiz     This script can be symlinked into a directory listed in PATH, or called
12681.1Stv     with an absolute path.
12691.1Stv
12701.105SwizEXAMPLES
12711.151Slukem     1.   % ./build.sh [OPTIONS] tools kernel=GENERIC
12721.28Slukem
12731.28Slukem          Build a new toolchain, and use the new toolchain to configure and
12741.28Slukem          build a new GENERIC kernel.
12751.28Slukem
12761.151Slukem     2.   % ./build.sh [OPTIONS] -U distribution
12771.28Slukem
12781.105Swiz          Using unprivileged mode, build a complete distribution to a DESTDIR
12791.148Slukem          directory that build.sh selects (and will show).
12801.28Slukem
12811.151Slukem     3.   # ./build.sh [OPTIONS] -U install=/
12821.28Slukem
12831.105Swiz          As root, install to / the distribution that was built by example 2.
12841.105Swiz          Even though this is run as root, -U is required so that the
12851.105Swiz          permissions stored in DESTDIR/METALOG are correctly applied to the
12861.105Swiz          files as they're copied to /.
12871.28Slukem
12881.151Slukem     4.   % ./build.sh [OPTIONS] -U -u release
12891.28Slukem
12901.105Swiz          Using unprivileged mode, build a complete release to DESTDIR and
12911.148Slukem          RELEASEDIR directories that build.sh selects (and will show).
12921.126Swiz          MKUPDATE=yes (-u) is set to prevent the "make cleandir", so that if
12931.126Swiz          this is run after example 2, it doesn't need to redo that portion of
12941.126Swiz          the release build.
12951.16Slukem
12961.105SwizOBSOLETE VARIABLES
12971.105Swiz     NBUILDJOBS  Use the make(1) option -j instead.
12981.15Slukem
12991.105Swiz     USE_NEW_TOOLCHAIN
13001.15Slukem                 The new toolchain is now the default.  To disable, use
13011.105Swiz                 TOOLCHAIN_MISSING=yes.
13021.10Ssommerfe
13031.105SwizSEE ALSO
13041.151Slukem     ar(1), config(1), ctags(1), cvs(1), cvslatest(1), ex(1), g++(1), gzip(1),
13051.151Slukem     ident(1), ld(1), lint(1), make(1), mkisofs(1), sh(1), uname(1), vi(1),
13061.151Slukem     options(4), mk.conf(5), atf(7), hier(7), release(7), sysctl(7),
13071.151Slukem     etcupdate(8), installboot(8), mount(8), mtree(8), postinstall(8),
13081.151Slukem     sysinst(8), pkgsrc/sysutils/cdrtools
13091.1Stv
13101.105SwizHISTORY
13111.105Swiz     The build.sh based build scheme was introduced for NetBSD 1.6 as
13121.105Swiz     USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that.
13131.1Stv
13141.109SapbCAVEATS
13151.109Sapb     After significant updates to third-party components in the source tree,
13161.126Swiz     the "make cleandir" operation may be insufficient to clean out old files
13171.126Swiz     in object directories.  Instead, one may have to manually remove the
13181.126Swiz     files.  Consult the UPDATING file for notices concerning this.
13191.109Sapb
13201.151SlukemNetBSD                           June 4, 2023                           NetBSD
1321