Home | History | Annotate | Line # | Download | only in src
BUILDING revision 1.159
      1 BUILDING(8)                 System Manager's Manual                BUILDING(8)
      2 
      3 NAME
      4      BUILDING - Procedure for building NetBSD from source code
      5 
      6 REQUIREMENTS
      7      NetBSD is designed to be buildable on most POSIX-compliant host systems.
      8      The basic build procedure is the same whether compiling natively (on the
      9      same NetBSD architecture) or cross compiling (on another architecture or
     10      OS).
     11 
     12      This source tree contains the build.sh shell script which supports both
     13      native and cross builds of NetBSD.
     14 
     15      This source tree contains a special subtree, "tools", which uses the host
     16      system to create a build toolchain for the target architecture.  The host
     17      system must have at least C and C++ compilers in order to create the
     18      toolchain (make(1) is not required); all other tools (including make(1)
     19      as nbmake) are created as part of the NetBSD build process.  (See the
     20      Environment variables section below if you need to override or manually
     21      select your compilers.)
     22 
     23      Note: Within this document, cross-references to manual pages are to the
     24      NetBSD manual pages, not the host system manual pages.  The mdoc(7)
     25      source to the NetBSD manual pages can be found within the source tree,
     26      and these and can be formatted with mandoc(1) or nroff(1) if those are
     27      available on the host system.  The NetBSD manual pages are also available
     28      at https://man.netbsd.org
     29 
     30 FILES
     31    Source tree layout
     32      BUILDING       This document (in plaintext).  Generated from
     33                     doc/BUILDING.mdoc.
     34 
     35      Makefile       The main Makefile for NetBSD; should only be run for
     36                     native builds with an appropriately up-to-date version of
     37                     NetBSD make(1).  Intended for expert use with knowledge of
     38                     its shortcomings, it has been superseded by the build.sh
     39                     shell script as the recommended means for building NetBSD.
     40 
     41      UPDATING       Special notes for updating from an earlier revision of
     42                     NetBSD.  It is important to read this file before every
     43                     build of an updated source tree.
     44 
     45      build.sh       Bourne-compatible shell script used for building the host
     46                     build tools and the NetBSD system from scratch.  Can be
     47                     used for both native and cross builds, and should be used
     48                     instead of make(1) as it performs additional checks to
     49                     prevent common issues going undetected, such as building
     50                     with an outdated version of make(1).
     51 
     52      crypto/dist/, dist/, gnu/dist/
     53                     Sources imported verbatim from third parties, without
     54                     mangling the existing build structure.  Other source trees
     55                     in bin through usr.sbin use the NetBSD make(1) "reachover"
     56                     Makefile semantics when building these programs for a
     57                     native host.
     58 
     59      distrib/, etc/
     60                     Sources for items used when making a full release
     61                     snapshot, such as files installed in DESTDIR/etc on the
     62                     destination system, boot media, and release notes.
     63 
     64      doc/BUILDING.mdoc
     65                     The source to this document, in mdoc(7) format.  Used to
     66                     generate BUILDING.
     67 
     68      external/, sys/external/
     69                     Sources and build infrastructure for components imported
     70                     (mostly) unchanged from upstream maintainers, sorted by
     71                     applicable license.  This is (slowly) replacing the
     72                     crypto/dist, dist, and gnu/dist directories.
     73 
     74      external/mit/xorg/
     75                     "Reachover" build structure for modular Xorg; the source
     76                     is in X11SRCDIR.
     77 
     78      mk.conf        Optional source tree specific mk.conf(5), used (if
     79                     present) instead of /etc/mk.conf unless MAKECONF is
     80                     defined.
     81 
     82                     Note: Not part of the NetBSD source repository.
     83 
     84      regress/, tests/
     85                     Regression test harness.  Can be cross-compiled, but only
     86                     run natively.  tests/ uses the atf(7) test framework;
     87                     regress/ contains older tests that have not yet been
     88                     migrated to atf(7).
     89 
     90      sys/           NetBSD kernel sources.
     91 
     92      tools/         "Reachover" build structure for the host build tools.
     93                     This has a special method of determining out-of-date
     94                     status.
     95 
     96      tools/compat/README
     97                     Special notes for cross-hosting a NetBSD build on non-
     98                     NetBSD platforms.
     99 
    100      Other directories including bin/ ... usr.sbin/
    101                     Sources to the NetBSD userland (non-kernel) programs.  If
    102                     any of these directories are missing, they will be skipped
    103                     during the build.
    104 
    105    Build tree layout
    106      The NetBSD build tree is described in hier(7) (whose mdoc(7) source is in
    107      share/man/man7/hier.7), and the release layout is described in release(7)
    108      (whose mdoc(7) source is in share/man/man7/release.7).
    109 
    110 CONFIGURATION
    111    Environment variables
    112      Several environment variables control the behaviour of NetBSD builds.
    113 
    114      HOST_CC         Path name to C compiler used to create the toolchain.
    115 
    116                      Default: "cc".
    117 
    118      HOST_CFLAGS     Flags passed to the host C compiler.
    119 
    120                      Default: "-O".
    121 
    122      HOST_CPPFLAGS   Flags passed to the host C/C++ pre-processor.
    123 
    124                      Default: Unset.
    125 
    126      HOST_CXX        Path name to C++ compiler used to create the toolchain.
    127 
    128                      Default: Unset, but defaults to "c++" where required.
    129 
    130      HOST_CXXFLAGS   Flags passed to the host C++ compiler.
    131 
    132                      Default: Unset.
    133 
    134      HOST_SH         Path name to a shell available on the host system and
    135                      suitable for use during the build.  The NetBSD build
    136                      system requires a modern Bourne-like shell with POSIX-
    137                      compliant features, and also requires support for the
    138                      "local" keyword to declare local variables in shell
    139                      functions (which is a widely-implemented but non-
    140                      standardised feature).
    141 
    142                      Depending on the host system, a suitable shell may be
    143                      /bin/sh, /usr/xpg4/bin/sh, /bin/ksh (provided it is a
    144                      variant of ksh that supports the "local" keyword, such as
    145                      ksh88, but not ksh93), or /usr/local/bin/bash.
    146 
    147                      Most parts of the build require HOST_SH to be an absolute
    148                      path; however, build.sh allows it to be a simple command
    149                      name, which will be converted to an absolute path by
    150                      searching the PATH.
    151 
    152                      Default: "sh".
    153 
    154      INSTALLBOOT_UBOOT_PATHS
    155                      A colon-separated list of search paths used by
    156                      installboot(8) to find U-Boot packages.
    157 
    158                      Default: Unset.
    159 
    160      MACHINE         Machine type, e.g., "macppc".
    161 
    162                      Default: Unset.
    163 
    164      MACHINE_ARCH    Machine architecture, e.g., "powerpc".
    165 
    166                      Default: Unset.
    167 
    168      MAKE            Path name to invoke make(1) as.
    169 
    170                      Default: "make".
    171 
    172      MAKECONF        The name of the make(1) configuration file.  See "make"
    173                      variables and mk.conf(5).
    174 
    175                      Note: Only settable in the process environment.
    176 
    177                      Default: "/etc/mk.conf", although build.sh will set the
    178                      default to the full path to mk.conf if the latter is
    179                      present in the same directory as build.sh.
    180 
    181      MAKEFLAGS       Flags to invoke make(1) with.
    182 
    183                      Note: build.sh ignores the value of MAKEFLAGS passed in
    184                      the environment, but allows MAKEFLAGS to be set via the
    185                      -V option.
    186 
    187                      Default: "-X" on systems with a small ARG_MAX (Cygwin,
    188                      Darwin, FreeBSD); otherwise unset.
    189 
    190      MAKEOBJDIR      Directory to use as the .OBJDIR for the current
    191                      directory.  The value is subjected to variable expansion
    192                      by make(1).  Typical usage is to set this variable to a
    193                      value involving the use of `${.CURDIR:S...}' or
    194                      `${.CURDIR:C...}', to derive the value of .OBJDIR from
    195                      the value of .CURDIR.  Used only if MAKEOBJDIRPREFIX is
    196                      not defined.
    197 
    198                      Note: MAKEOBJDIR can be provided only in the environment
    199                      or via the -O flag of build.sh; it cannot usefully be set
    200                      inside a Makefile, including in mk.conf(5) or MAKECONF.
    201 
    202                      Default: Unset.
    203 
    204      MAKEOBJDIRPREFIX
    205                      Top level directory of the object directory tree.  The
    206                      value is subjected to variable expansion by make(1).
    207                      build.sh will create the ${MAKEOBJDIRPREFIX} directory if
    208                      necessary, but if make(1) is used without build.sh, then
    209                      rules in <bsd.obj.mk> will abort the build if the
    210                      ${MAKEOBJDIRPREFIX} directory does not exist.  If the
    211                      value is defined and valid, then
    212                      ${MAKEOBJDIRPREFIX}/${.CURDIR} is used as the .OBJDIR for
    213                      the current directory.  The current directory may be read
    214                      only.
    215 
    216                      Note: MAKEOBJDIRPREFIX can be provided only in the
    217                      environment or via the -M flag of build.sh; it cannot
    218                      usefully be set inside a Makefile, including in
    219                      mk.conf(5) or MAKECONF.
    220 
    221                      Default: Unset.
    222 
    223      TMPDIR          Top-level directory to store temporary directories used
    224                      by build.sh before paths to other directories such as
    225                      .OBJDIR can be determined.
    226 
    227                      Note: Must support execution of binaries.  I.e., without
    228                      mount(8)'s -o noexec option.
    229 
    230                      Default: "/tmp".
    231 
    232    "make" variables
    233      Variables that control the behavior of NetBSD builds are documented in
    234      mk.conf(5) (whose mdoc(7) source is in share/man/man5/mk.conf.5).
    235 
    236      Unless otherwise specified, these variables may be set in either the
    237      process environment or the make(1) configuration file mk.conf(5)
    238      specified by MAKECONF.
    239 
    240      Note: Variables set in the environment, either directly or via build.sh
    241      options to set specific values in the nbmake-MACHINE wrapper script do
    242      not override variables set in the mk.conf(5) file.  To allow variables in
    243      mk.conf(5) to be overridden by the environment or build.sh options,
    244      define the variables using the "?=" make(1) variable assignment operator.
    245      For example,
    246 
    247            MAKEVERBOSE?=1
    248 
    249 BUILDING
    250    "make" command line options
    251      This is not a summary of all the options available to make(1); only the
    252      options used most frequently with NetBSD builds are listed here.
    253 
    254      -j njob    Run up to njob make(1) subjobs in parallel.  Makefiles should
    255                 use .WAIT or have explicit dependencies as necessary to
    256                 enforce build ordering.
    257 
    258      -m dir     Specify the default directory for searching for system
    259                 Makefile segments, mainly the <bsd.*.mk> files.  When building
    260                 any full NetBSD source tree, this should be set to the
    261                 "share/mk" directory in the source tree.  This is set
    262                 automatically when building from the top level, or when using
    263                 build.sh.
    264 
    265      -n         Show the commands that would have been executed, but do not
    266                 actually execute them.  This will still cause recursion to
    267                 take place.
    268 
    269      -V var     Show make(1)'s idea of the value of var.  Does not build any
    270                 targets.
    271 
    272      var=value  Set the variable var to value, overriding any setting
    273                 specified by the process environment, the MAKECONF
    274                 configuration file, or the system Makefile segments.
    275 
    276    "make" targets
    277      These default targets may be built by running make(1) in any subtree of
    278      the NetBSD source code.  It is recommended that none of these be used
    279      from the top level Makefile; as a specific exception, "make obj" and
    280      "make cleandir" are useful in that context.
    281 
    282      all        Build programs, libraries, and preformatted documentation.
    283 
    284      clean      Remove program and library object code files.
    285 
    286      cleandir   Same as clean, but also remove preformatted documentation,
    287                 dependency files generated by "make depend", and any other
    288                 files known to be created at build time.
    289 
    290      depend     Create dependency files (.depend) containing more detailed
    291                 information about the dependencies of source code on header
    292                 files.  Allows programs to be recompiled automatically when a
    293                 dependency changes.
    294 
    295      dependall  Does a "make depend" immediately followed by a "make all".
    296                 This improves cache locality of the build since both passes
    297                 read the source files in their entirety.
    298 
    299      distclean  Synonym for cleandir.
    300 
    301      includes   Build and install system header files.  Typically needed
    302                 before any system libraries or programs can be built.
    303 
    304      install    Install programs, libraries, and documentation into DESTDIR.
    305                 Few files will be installed to DESTDIR/dev, DESTDIR/etc,
    306                 DESTDIR/root or DESTDIR/var in order to prevent user supplied
    307                 configuration data from being overwritten.
    308 
    309      lint       Run lint(1) against the C source code, where appropriate, and
    310                 generate system-installed lint libraries.
    311 
    312      obj        Create object directories to be used for built files, instead
    313                 of building directly in the source tree.
    314 
    315      tags       Create ctags(1) searchable function lists usable by the ex(1)
    316                 and vi(1) text editors.
    317 
    318    "make" targets for the top level
    319      Additional make(1) targets are usable specifically from the top source
    320      level to facilitate building the entire NetBSD source tree.
    321 
    322      build         Build the entire NetBSD system (except the kernel).  This
    323                    orders portions of the source tree such that prerequisites
    324                    will be built in the proper order.
    325 
    326      distribution  Do a "make build", and then install a full distribution
    327                    (which does not include a kernel) into DESTDIR, including
    328                    files in DESTDIR/dev, DESTDIR/etc, DESTDIR/root and
    329                    DESTDIR/var.
    330 
    331      buildworld    As per "make distribution", except that it ensures that
    332                    DESTDIR is not the root directory.
    333 
    334      installworld  Install the distribution from DESTDIR to INSTALLWORLDDIR,
    335                    which defaults to the root directory.  Ensures that
    336                    INSTALLWORLDDIR is not the root directory if cross
    337                    compiling.
    338 
    339                    The INSTALLSETS environment variable may be set to a space-
    340                    separated list of distribution sets to be installed.  By
    341                    default, all sets except "etc" and "xetc" are installed, so
    342                    most files in INSTALLWORLDDIR/etc will not be installed or
    343                    modified.
    344 
    345                    Note: Before performing this operation with
    346                    INSTALLWORLDDIR=/, it is highly recommended that you
    347                    upgrade your kernel and reboot.  After performing this
    348                    operation, it is recommended that you use etcupdate(8) to
    349                    update files in INSTALLWORLDDIR/etc, and postinstall(8) to
    350                    check for or fix inconsistencies.
    351 
    352      sets          Create distribution sets from DESTDIR into
    353                    RELEASEDIR/RELEASEMACHINEDIR/binary/sets.  Should be run
    354                    after "make distribution", as "make build" alone does not
    355                    install all of the required files.
    356 
    357      sourcesets    Create source sets of the source tree into
    358                    RELEASEDIR/source/sets.
    359 
    360      syspkgs       Create syspkgs from DESTDIR into
    361                    RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.  Should be run
    362                    after "make distribution", as "make build" alone does not
    363                    install all of the required files.
    364 
    365      release       Do a "make distribution", build kernels, distribution
    366                    media, and install sets (this as per "make sets"), and then
    367                    package the system into a standard release layout as
    368                    described by release(7).  This requires that RELEASEDIR be
    369                    set (see above).
    370 
    371      iso-image     Create a NetBSD installation CD-ROM image in the
    372                    RELEASEDIR/images directory.  The CD-ROM file system will
    373                    have a layout as described in release(7).
    374 
    375                    For most machine types, the CD-ROM will be bootable, and
    376                    will automatically run the sysinst(8) menu-based
    377                    installation program, which can be used to install or
    378                    upgrade a NetBSD system.  Bootable CD-ROMs also contain
    379                    tools that may be useful in repairing a damaged NetBSD
    380                    installation.
    381 
    382                    Before "make iso-image" is attempted, RELEASEDIR must be
    383                    populated by "make release" or equivalent.
    384 
    385                    Note: Other, smaller, CD-ROM images may be created in the
    386                    RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom directory
    387                    by "make release".  These smaller images usually contain
    388                    the same tools as the larger images in RELEASEDIR/images,
    389                    but do not contain additional content such as the
    390                    distribution sets.
    391 
    392                    Note: The mac68k port still uses an older method of
    393                    creating CD-ROM images.  This requires the mkisofs(1)
    394                    utility, which is not part of NetBSD, but which can be
    395                    installed from pkgsrc/sysutils/cdrtools.
    396 
    397      iso-image-source
    398                    Create a NetBSD installation CD-ROM image in the
    399                    RELEASEDIR/images directory.  The CD-ROM file system will
    400                    have a layout as described in release(7).  It will have top
    401                    level directories for the machine type and source.
    402 
    403                    For most machine types, the CD-ROM will be bootable, and
    404                    will automatically run the sysinst(8) menu-based
    405                    installation program, which can be used to install or
    406                    upgrade a NetBSD system.  Bootable CD-ROMs also contain
    407                    tools that may be useful in repairing a damaged NetBSD
    408                    installation.
    409 
    410                    Before "make iso-image-source" is attempted, RELEASEDIR
    411                    must be populated by "make sourcesets release" or
    412                    equivalent.
    413 
    414                    Note: Other, smaller, CD-ROM images may be created in the
    415                    RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom directory
    416                    by "make release".  These smaller images usually contain
    417                    the same tools as the larger images in RELEASEDIR/images,
    418                    but do not contain additional content such as the
    419                    distribution sets.
    420 
    421                    Note: The mac68k port still uses an older method of
    422                    creating CD-ROM images.  This requires the mkisofs(1)
    423                    utility, which is not part of NetBSD, but which can be
    424                    installed from pkgsrc/sysutils/cdrtools.
    425 
    426      install-image
    427                    Create a bootable NetBSD installation disk image in the
    428                    RELEASEDIR/images directory.  The installation disk image
    429                    is suitable for copying to bootable USB flash memory
    430                    sticks, etc., for machines which are able to boot from such
    431                    devices.  The file system in the bootable disk image will
    432                    have a layout as described in release(7).
    433 
    434                    The installation image is bootable, and will automatically
    435                    run the sysinst(8) menu-based installation program, which
    436                    can be used to install or upgrade a NetBSD system.  The
    437                    image also contains tools that may be useful in repairing a
    438                    damaged NetBSD installation.
    439 
    440                    Before "make install-image" is attempted, RELEASEDIR must
    441                    be populated by "make release" or equivalent.  The build
    442                    must have been performed with MKUNPRIVED=yes because "make
    443                    install-image" relies on information in DESTDIR/METALOG.
    444 
    445      live-image    Create NetBSD live images in the RELEASEDIR/images
    446                    directory.  The live image contains all necessary files to
    447                    boot NetBSD up to multi-user mode, including all files
    448                    which should be extracted during installation, NetBSD
    449                    disklabel, bootloaders, etc.
    450 
    451                    The live image is suitable for use as a disk image in
    452                    virtual machine environments such as QEMU, and also useful
    453                    to boot NetBSD from a USB flash memory stick on a real
    454                    machine, without the need for installation.
    455 
    456                    Before "make live-image" is attempted, RELEASEDIR must be
    457                    populated by "make release" or equivalent.  The build must
    458                    have been performed with MKUNPRIVED=yes because "make
    459                    install-image" relies on information in DESTDIR/METALOG.
    460 
    461      regression-tests
    462                    Can only be run after building the regression tests in the
    463                    directory "regress".  Runs those compiled regression tests
    464                    on the local host.
    465 
    466                    Note: Most tests are now managed instead using atf(7); this
    467                    target should probably run those as well but currently does
    468                    not.
    469 
    470    The "build.sh" script
    471      This script file is a shell script designed to build the entire NetBSD
    472      system on any host with a suitable modern shell and some common
    473      utilities.  The required shell features are described under the HOST_SH
    474      variable.
    475 
    476      If a host system's default shell does support the required features, then
    477      we suggest that you explicitly specify a suitable shell using a command
    478      like
    479 
    480            /path/to/suitable/shell build.sh [options]
    481 
    482      The above command will usually enable build.sh to automatically set
    483      HOST_SH=/path/to/suitable/shell, but if that fails, then the following
    484      set of commands may be used instead:
    485 
    486            HOST_SH=/path/to/suitable/shell
    487            export HOST_SH
    488            ${HOST_SH} build.sh [options]
    489 
    490      If build.sh detects that it is being executed under an unsuitable shell,
    491      it attempts to exec a suitable shell instead, or shows an error message.
    492      If HOST_SH is not set explicitly, then build.sh sets a default using
    493      heuristics dependent on the host platform, or from the shell under which
    494      build.sh is executed (if that can be determined), or using the first copy
    495      of sh found in PATH.
    496 
    497      All cross-compile builds, and most native builds, of the entire system
    498      should make use of build.sh rather than just running "make".  This way,
    499      the make(1) program will be bootstrapped properly, in case the host
    500      system has an older or incompatible "make" program.
    501 
    502      When compiling the entire system via build.sh, many make(1) variables are
    503      set for you in order to help encapsulate the build process.  In the list
    504      of options below, variables that are automatically set by build.sh are
    505      noted where applicable.
    506 
    507      The following operations are supported by build.sh:
    508 
    509      build         Build the system as per "make build".  Before the main part
    510                    of the build commences, this command runs the obj operation
    511                    (unless the -o option is given), "make cleandir" (unless
    512                    the -u option is given), and the tools operation.
    513 
    514      distribution  Build a full distribution as per "make distribution".  This
    515                    command first runs the build operation.
    516 
    517      release       Build a full release as per "make release".  This command
    518                    first runs the distribution operation.
    519 
    520      help          Show a help message, and exit.
    521 
    522      makewrapper   Create the nbmake-MACHINE wrapper script.  This operation
    523                    is automatically performed for any of the other operations.
    524 
    525      cleandir      Perform "make cleandir".
    526 
    527      obj           Perform "make obj".
    528 
    529      tools         Build and install the host tools from src/tools.  This
    530                    command will first run "make obj" and "make cleandir" in
    531                    the tools subdirectory unless the -o or -u options
    532                    (respectively) are given.
    533 
    534      install=idir  Install the contents of DESTDIR to idir, using "make
    535                    installworld".
    536 
    537                    Note: Files that are part of the "etc" or "xetc" sets will
    538                    not be installed, unless overridden by the INSTALLSETS
    539                    environment variable.
    540 
    541      kernel=kconf  Build a new kernel.  The kconf argument is the name of a
    542                    configuration file suitable for use by config(1).  If kconf
    543                    does not contain any `/' characters, the configuration file
    544                    is expected to be found in the KERNCONFDIR directory, which
    545                    is typically sys/arch/MACHINE/conf.  The new kernel will be
    546                    built in a subdirectory of KERNOBJDIR, which is typically
    547                    sys/arch/MACHINE/compile or an associated object directory.
    548 
    549                    This command does not imply the tools command; run the
    550                    tools command first unless it is certain that the tools
    551                    already exist and are up to date.
    552 
    553                    This command will run "make cleandir" on the kernel in
    554                    question first unless the -u option is given.
    555 
    556      kernel.gdb=kconf
    557                    Build a new kernel with debug information.  Similar to the
    558                    above kernel=kconf operation, but creates a netbsd.gdb file
    559                    alongside of the kernel netbsd, which contains a full
    560                    symbol table and can be used for debugging (for example
    561                    with a cross-gdb built by MKCROSSGDB).
    562 
    563      kernels       This command will build all kernels defined in port
    564                    specific release build procedure.
    565 
    566                    This command internally calls the kernel=kconf operation
    567                    for each found kernel configuration file.
    568 
    569      modules       This command will build kernel modules and install them
    570                    into DESTDIR.
    571 
    572      releasekernel=kconf
    573                    Install a gzip(1)ed copy of the kernel previously built by
    574                    kernel=kconf into
    575                    RELEASEDIR/RELEASEMACHINEDIR/binary/kernel, usually as
    576                    netbsd-kconf.gz, although the "netbsd" prefix is determined
    577                    from the "config" directives in kconf.
    578 
    579      sets          Perform "make sets".
    580 
    581      sourcesets    Perform "make sourcesets".
    582 
    583      syspkgs       Perform "make syspkgs".
    584 
    585      iso-image     Perform "make iso-image".
    586 
    587      iso-image-source
    588                    Perform "make iso-image-source".
    589 
    590      install-image
    591                    Perform "make install-image".
    592 
    593      live-image    Perform "make live-image".
    594 
    595      list-arch     Show a list of valid MACHINE and MACHINE_ARCH settings, the
    596                    default MACHINE_ARCH for each MACHINE, and aliases for
    597                    MACHINE/MACHINE_ARCH pairs, and then exits.  The -m or -a
    598                    options (or both) may be used to specify glob patterns that
    599                    will be used to narrow the list of results; for example,
    600                    "build.sh -m 'evb*' -a '*arm*' list-arch" will list all
    601                    known MACHINE/MACHINE_ARCH values in which either MACHINE
    602                    or ALIAS matches the pattern `evb*', and MACHINE_ARCH
    603                    matches the pattern `*arm*'.
    604 
    605      The following command line options alter the behaviour of the build.sh
    606      operations described above:
    607 
    608      -a arch   Set the value of MACHINE_ARCH to arch.  See the -m option for
    609                more information.
    610 
    611      -B buildid
    612                Set the value of BUILDID to buildid.  This will also append the
    613                build identifier to the name of the nbmake-MACHINE wrapper
    614                script so that the resulting name is of the form
    615                "nbmake-MACHINE-BUILDID".
    616 
    617      -C cdextras
    618                Append cdextras to the CDEXTRA variable, which is a space-
    619                separated list of files or directories that will be added to
    620                the CD-ROM image that may be create by the "iso-image" or
    621                "iso-image-source" operations.  Files will be added to the root
    622                of the CD-ROM image, whereas directories will be copied
    623                recursively.  If relative paths are specified, they will be
    624                converted to absolute paths before being used.  Multiple paths
    625                may be specified via multiple -C options, or via a single
    626                option whose argument contains multiple space-separated paths.
    627 
    628      -c compiler
    629                Select the compiler for the toolchain to build NetBSD and for
    630                inclusion in the NetBSD distribution.  Supported choices:
    631 
    632                      clang
    633 
    634                      gcc [default]
    635 
    636                The compiler used to build the toolchain can be different; see
    637                HOST_CC and HOST_CXX.
    638 
    639      -D dest   Set the value of DESTDIR to dest.  If a relative path is
    640                specified, it will be converted to an absolute path before
    641                being used.
    642 
    643      -E        Set `expert' mode.  This overrides various sanity checks, and
    644                allows: DESTDIR does not have to be set to a non-root path for
    645                builds, and MKUNPRIVED=yes does not have to be set when
    646                building as a non-root user.
    647 
    648                Note: It is highly recommended that you know what you are doing
    649                when you use this option.
    650 
    651      -h        Show a help message, and exit.
    652 
    653      -j njob   Run up to njob make(1) subjobs in parallel; passed through to
    654                make(1).  If you see failures for reasons other than running
    655                out of memory while using build.sh with -j, please save
    656                complete build logs so the failures can be analyzed.
    657 
    658                To achieve the fastest builds, -j values between (1 + the
    659                number of CPUs) and (2 * the number of CPUs) are recommended.
    660                Use lower values on machines with limited memory or I/O
    661                bandwidth.
    662 
    663      -M obj    Set MAKEOBJDIRPREFIX to obj.  Unsets MAKEOBJDIR.  See "-O obj"
    664                for more information.
    665 
    666                For instance, if the source directory is /usr/src, a setting of
    667                "-M /usr/obj" will place build-time files under
    668                /usr/obj/usr/src/bin, /usr/obj/usr/src/lib,
    669                /usr/obj/usr/src/usr.bin, and so forth.
    670 
    671                If a relative path is specified, it will be converted to an
    672                absolute path before being used.  build.sh imposes the
    673                restriction that the argument to the -M option must not begin
    674                with a "$" (dollar sign) character; otherwise it would be too
    675                difficult to determine whether the value is an absolute or a
    676                relative path.  If the directory does not already exist,
    677                build.sh will create it.
    678 
    679      -m mach   Set the value of MACHINE to mach, unless the mach argument is
    680                an alias that refers to a MACHINE/MACHINE_ARCH pair, in which
    681                case both MACHINE and MACHINE_ARCH are set from the alias.
    682                Such aliases are interpreted entirely by build.sh; they are not
    683                used by any other part of the build system.  The MACHINE_ARCH
    684                setting implied by mach will override any value of MACHINE_ARCH
    685                in the process environment, but will not override a value set
    686                by the -a option.  All cross builds require -m, but if unset on
    687                a NetBSD host, the host's value of MACHINE will be detected and
    688                used automatically.
    689 
    690                See the list-arch operation for a way to get a list of valid
    691                MACHINE and MACHINE_ARCH settings.
    692 
    693      -N noiselevel
    694                Set the "noisyness" level of the build, by setting MAKEVERBOSE
    695                to noiselevel.
    696 
    697      -n        Show the commands that would be executed by build.sh, but do
    698                not make any changes.  This is similar in concept to "make -n".
    699 
    700      -O obj    Create an appropriate transform macro for MAKEOBJDIR that will
    701                place the built object files under obj.  Unsets
    702                MAKEOBJDIRPREFIX.
    703 
    704                For instance, a setting of "-O /usr/obj" will place build-time
    705                files under /usr/obj/bin, /usr/obj/lib, /usr/obj/usr.bin, and
    706                so forth.
    707 
    708                If a relative path is specified, it will be converted to an
    709                absolute path before being used.  build.sh imposes the
    710                restriction that the argument to the -O option must not contain
    711                a "$" (dollar sign) character.  If the directory does not
    712                already exist, build.sh will create it.
    713 
    714                In normal use, exactly one of the -M or -O options should be
    715                specified.  If neither -M nor -O is specified, then a default
    716                object directory will be chosen according to rules in
    717                <bsd.obj.mk>.  Relying on this default is not recommended
    718                because it is determined by complex rules that are influenced
    719                by the values of several variables and by the location of the
    720                source directory.
    721 
    722                Note: Placing the obj directory location outside of the default
    723                source tree hierarchy makes it easier to manually clear out old
    724                files in the event the "make cleandir" operation is unable to
    725                do so.  (See CAVEATS below.)
    726 
    727                Note: The use of one of -M or -O is the only means of building
    728                multiple machine architecture userlands from the same source
    729                tree without cleaning between builds (in which case, one would
    730                specify distinct obj locations for each).
    731 
    732      -o        Set the value of MKOBJDIRS to "no".  Otherwise, it will be
    733                automatically set to "yes".  This default is opposite to the
    734                behaviour when not using build.sh.
    735 
    736      -P        Set the value of MKREPRO and MKREPRO_TIMESTAMP to the latest
    737                source CVS timestamp for reproducible builds.
    738 
    739      -R rel    Set the value of RELEASEDIR to rel.  If a relative path is
    740                specified, it will be converted to an absolute path before
    741                being used.
    742 
    743      -r        Remove the contents of DESTDIR and TOOLDIR before building
    744                (provides a clean starting point).  This will skip deleting
    745                DESTDIR if building on a native system to the root directory.
    746 
    747      -S seed   Change the value of BUILDSEED to seed.  This should rarely be
    748                necessary.
    749 
    750      -T tools  Set the value of TOOLDIR to tools.  If a relative path is
    751                specified, it will be converted to an absolute path before
    752                being used.  If set, the bootstrap "make" will only be rebuilt
    753                if the source files for make(1) have changed.
    754 
    755      -U        Set MKUNPRIVED=yes.
    756 
    757      -u        Set MKUPDATE=yes.
    758 
    759      -V var=[value]
    760                Set the environment variable var to an optional value.  This is
    761                propagated to the nbmake-MACHINE wrapper script.
    762 
    763      -w wrapper
    764                Create the nbmake-MACHINE wrapper script (see below) in a
    765                custom location, specified by wrapper.  This allows, for
    766                instance, to place the wrapper script in PATH automatically.
    767 
    768                Note: wrapper is the full name of the file, not just a
    769                directory name.  If a relative path is specified, it will be
    770                converted to an absolute path before being used.
    771 
    772      -X x11src
    773                Set the value of X11SRCDIR to x11src.  If a relative path is
    774                specified, it will be converted to an absolute path before
    775                being used.
    776 
    777      -x        Set MKX11=yes.
    778 
    779      -Z var    Unset ("zap") the environment variable var.  This is propagated
    780                to the nbmake-MACHINE wrapper script.
    781 
    782      -?        Show a help message, and exit.
    783 
    784    The "nbmake-MACHINE" wrapper script
    785      If using the build.sh script to build NetBSD, a nbmake-MACHINE wrapper
    786      script will be created in TOOLDIR/bin upon the first build to assist in
    787      building subtrees on a cross-compile host.
    788 
    789      The nbmake-MACHINE wrapper script can be invoked in lieu of make(1), and
    790      will instead call the up-to-date version of "nbmake" installed into
    791      TOOLDIR/bin with several key variables pre-set, including MACHINE,
    792      MACHINE_ARCH, and TOOLDIR.  nbmake-MACHINE will also set variables
    793      specified with -V, and unset variables specified with -Z.  Note that by
    794      default these variables will not override mk.conf(5); see "make"
    795      variables for more details.
    796 
    797      This wrapper script can be symlinked into a directory listed in PATH, or
    798      called with an absolute path.
    799 
    800 EXAMPLES
    801      1.   % ./build.sh [OPTIONS] tools kernel=GENERIC
    802 
    803           Build a new toolchain, and use the new toolchain to configure and
    804           build a new GENERIC kernel.
    805 
    806      2.   % ./build.sh [OPTIONS] -U distribution
    807 
    808           Using unprivileged mode, build a complete distribution to a DESTDIR
    809           directory that build.sh selects (and will show).
    810 
    811      3.   # ./build.sh [OPTIONS] -U install=/
    812 
    813           As root, install to / the distribution that was built by example 2.
    814           Even though this is run as root, -U is required so that the
    815           permissions stored in DESTDIR/METALOG are correctly applied to the
    816           files as they're copied to /.
    817 
    818      4.   % ./build.sh [OPTIONS] -U -u release
    819 
    820           Using unprivileged mode, build a complete release to DESTDIR and
    821           RELEASEDIR directories that build.sh selects (and will show).
    822           MKUPDATE=yes (-u) is set to prevent the "make cleandir", so that if
    823           this is run after example 2, it doesn't need to redo that portion of
    824           the release build.
    825 
    826 SEE ALSO
    827      config(1), ctags(1), ex(1), gzip(1), lint(1), make(1), mandoc(1),
    828      mkisofs(1), nroff(1), vi(1), mk.conf(5), atf(7), hier(7), mdoc(7),
    829      release(7), etcupdate(8), installboot(8), mount(8), postinstall(8),
    830      sysinst(8), pkgsrc/sysutils/cdrtools
    831 
    832      Note: The NetBSD manual pages are also available at
    833      https://man.netbsd.org
    834 
    835 HISTORY
    836      The build.sh based build scheme was introduced for NetBSD 1.6 as
    837      USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that.
    838 
    839 CAVEATS
    840      After significant updates to third-party components in the source tree,
    841      the "make cleandir" operation may be insufficient to clean out old files
    842      in object directories.  Instead, one may have to manually remove the
    843      files.  Consult the UPDATING file for notices concerning this.
    844 
    845 NetBSD                           July 21, 2023                          NetBSD
    846