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