BUILDING revision 1.144
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
19FILES
20   Source tree layout
21     doc/BUILDING.mdoc
22                    This document (in -mdoc troff format; the original copy).
23
24     BUILDING       This document (in plaintext).
25
26     tools/compat/README
27                    Special notes for cross-hosting a NetBSD build on non-
28                    NetBSD platforms.
29
30     Makefile       The main Makefile for NetBSD; should only be run for
31                    native builds with an appropriately up-to-date version of
32                    NetBSD make(1).  Intended for expert use with knowledge of
33                    its shortcomings, it has been superseded by the build.sh
34                    shell script as the recommended means for building NetBSD.
35
36     UPDATING       Special notes for updating from an earlier revision of
37                    NetBSD.  It is important to read this file before every
38                    build of an updated source tree.
39
40     build.sh       Bourne-compatible shell script used for building the host
41                    build tools and the NetBSD system from scratch.  Can be
42                    used for both native and cross builds, and should be used
43                    instead of make(1) as it performs additional checks to
44                    prevent common issues going undetected, such as building
45                    with an outdated version of make(1).
46
47     crypto/dist/, dist/, gnu/dist/
48                    Sources imported verbatim from third parties, without
49                    mangling the existing build structure.  Other source trees
50                    in bin through usr.sbin use the NetBSD make(1) "reachover"
51                    Makefile semantics when building these programs for a
52                    native host.
53
54     external, sys/external
55                    Sources and build infrastructure for components imported
56                    (mostly) unchanged from upstream maintainers, sorted by
57                    applicable license.  This is (slowly) replacing the
58                    crypto/dist, dist, and gnu/dist directories.
59
60     distrib/, etc/
61                    Sources for items used when making a full release
62                    snapshot, such as files installed in DESTDIR/etc on the
63                    destination system, boot media, and release notes.
64
65     tests/, regress/
66                    Regression test harness.  Can be cross-compiled, but only
67                    run natively.  tests/ uses the atf(7) test framework;
68                    regress/ contains older tests that have not yet been
69                    migrated to atf(7).
70
71     sys/           NetBSD kernel sources.
72
73     tools/         "Reachover" build structure for the host build tools.
74                    This has a special method of determining out-of-date
75                    status.
76
77     bin/ ... usr.sbin/
78                    Sources to the NetBSD userland (non-kernel) programs.  If
79                    any of these directories are missing, they will be skipped
80                    during the build.
81
82     external/mit/xorg/
83                    "Reachover" build structure for modular Xorg; the source
84                    is in X11SRCDIR.
85
86   Build tree layout
87     The NetBSD build tree is described in hier(7), and the release layout is
88     described in release(7).
89
90CONFIGURATION
91   Environment variables
92     Several environment variables control the behaviour of NetBSD builds.
93
94     HOST_SH           Path name to a shell available on the host system and
95                       suitable for use during the build.  The NetBSD build
96                       system requires a modern Bourne-like shell with POSIX-
97                       compliant features, and also requires support for the
98                       "local" keyword to declare local variables in shell
99                       functions (which is a widely-implemented but non-
100                       standardised feature).
101
102                       Depending on the host system, a suitable shell may be
103                       /bin/sh, /usr/xpg4/bin/sh, /bin/ksh (provided it is a
104                       variant of ksh that supports the "local" keyword, such
105                       as ksh88, but not ksh93), or /usr/local/bin/bash.
106
107                       Most parts of the build require HOST_SH to be an
108                       absolute path; however, build.sh allows it to be a
109                       simple command name, which will be converted to an
110                       absolute path by searching the PATH.
111
112     HOST_CC           Path name to C compiler used to create the toolchain.
113
114     HOST_CFLAGS       Flags passed to the host C compiler.
115
116     HOST_CXX          Path name to C++ compiler used to create the toolchain.
117
118     HOST_CXXFLAGS     Flags passed to the host C++ compiler.
119
120     MACHINE           Machine type, e.g., "macppc".
121
122     MACHINE_ARCH      Machine architecture, e.g., "powerpc".
123
124     MAKE              Path name to invoke make(1) as.
125
126     MAKEFLAGS         Flags to invoke make(1) with.  Note that build.sh
127                       ignores the value of MAKEFLAGS passed in the
128                       environment, but allows MAKEFLAGS to be set via the -V
129                       option.
130
131     MAKEOBJDIR        Directory to use as the .OBJDIR for the current
132                       directory.  The value is subjected to variable
133                       expansion by make(1).  Typical usage is to set this
134                       variable to a value involving the use of
135                       `${.CURDIR:S...}' or `${.CURDIR:C...}', to derive the
136                       value of .OBJDIR from the value of .CURDIR.  Used only
137                       if MAKEOBJDIRPREFIX is not defined.  MAKEOBJDIR can be
138                       provided only in the environment or via the -O flag of
139                       build.sh; it cannot usefully be set inside a Makefile,
140                       including mk.conf or ${MAKECONF}.
141
142     MAKEOBJDIRPREFIX  Top level directory of the object directory tree.  The
143                       value is subjected to variable expansion by make(1).
144                       build.sh will create the ${MAKEOBJDIRPREFIX} directory
145                       if necessary, but if make(1) is used without build.sh,
146                       then rules in <bsd.obj.mk> will abort the build if the
147                       ${MAKEOBJDIRPREFIX} directory does not exist.  If the
148                       value is defined and valid, then
149                       ${MAKEOBJDIRPREFIX}/${.CURDIR} is used as the .OBJDIR
150                       for the current directory.  The current directory may
151                       be read only.  MAKEOBJDIRPREFIX can be provided only in
152                       the environment or via the -M flag of build.sh; it
153                       cannot usefully be set inside a Makefile, including
154                       mk.conf or ${MAKECONF}.
155
156     INSTALLBOOT_UBOOT_PATHS
157                       A colon-separated list of search paths used by
158                       installboot to find U-Boot packages; see
159                       installboot(8).  If appropriate U-Boot packages
160                       are installed, bootable images are created as
161                       part of a release.
162
163   "make" variables
164     Several variables control the behavior of NetBSD builds.  Unless
165     otherwise specified, these variables may be set in either the process
166     environment or the make(1) configuration file specified by MAKECONF.
167
168     BUILDID     Identifier for the build.  If set, this should be a short
169                 string that is suitable for use as part of a file or
170                 directory name.  The identifier will be appended to object
171                 directory names, and can be consulted in the make(1)
172                 configuration file in order to set additional build
173                 parameters, such as compiler flags.  It will also be used as
174                 part of the kernel version string, which can be printed by
175                 "uname -v".
176
177                 Default: Unset.
178
179     BUILDINFO   This may be a multi-line string containing information about
180                 the build.  This will appear in DESTDIR/etc/release, and it
181                 will be stored in the buildinfo variable in any kernels that
182                 are built.  When such kernels are booted, the sysctl(7)
183                 kern.buildinfo variable will report this value.  The string
184                 may contain backslash escape sequences, such as "\\"
185                 (representing a backslash character) and "\n" (representing a
186                 newline).
187
188                 Default: Unset.
189
190     BUILDSEED   GCC uses random numbers when compiling C++ code.  This
191                 variable seeds the gcc random number generator using the
192                 -frandom-seed flag with this value.  By default, it is set to
193                 NetBSD-(majorversion).  Using a fixed value causes C++
194                 binaries to be the same when built from the same sources,
195                 resulting in identical (reproducible) builds.  Additional
196                 information is available in the GCC documentation of
197                 -frandom-seed.
198
199     CPUFLAGS    Additional flags to the compiler/assembler to select CPU
200                 instruction set options, CPU tuning options, etc.
201
202                 Default: Unset.
203
204     DESTDIR     Directory to contain the built NetBSD system.  If set,
205                 special options are passed to the compilation tools to
206                 prevent their default use of the host system's /usr/include,
207                 /usr/lib, and so forth.  This pathname must be an absolute
208                 path, and should not end with a slash (/) character.  (For
209                 installation into the system's root directory, set DESTDIR to
210                 an empty string, not to "/").  The directory must reside on a
211                 file system which supports long file names and hard links.
212
213                 Default: Empty string if USETOOLS is "yes"; unset otherwise.
214
215                 Note: build.sh will provide a default of destdir.MACHINE (in
216                 the top-level .OBJDIR) unless run in `expert' mode.
217
218     MAKECONF    The name of the make(1) configuration file.  Only settable in
219                 the process environment.
220
221                 Default: "/etc/mk.conf"
222
223     MAKEVERBOSE
224                 Level of verbosity of status messages.  Supported values:
225
226                 0    No descriptive messages or commands executed by make(1)
227                      are shown.
228
229                 1    Brief messages are shown describing what is being done,
230                      but the actual commands executed by make(1) are not
231                      displayed.
232
233                 2    Descriptive messages are shown as above (prefixed with a
234                      `#'), and ordinary commands performed by make(1) are
235                      displayed.
236
237                 3    In addition to the above, all commands performed by
238                      make(1) are displayed, even if they would ordinarily
239                      have been hidden through use of the "@" prefix in the
240                      relevant makefile.
241
242                 4    In addition to the above, commands executed by make(1)
243                      are traced through use of the sh(1) "-x" flag.
244
245                 Default: 2
246
247     MKCATPAGES  Can be set to "yes" or "no".  Indicates whether preformatted
248                 plaintext manual pages will be created during a build.
249
250                 Default: "no"
251
252     MKCROSSGDB  Can be set to "yes" or "no".  Create a cross-gdb as a host
253                 tool.
254
255                 Default: "no"
256
257     MKDEBUG     Can be set to "yes" or "no".  Indicates whether debug
258                 information should be generated for all userland binaries
259                 compiled.  The result is collected as an additional debug.tgz
260                 and xdebug.tgz set and installed in /usr/libdata/debug.
261
262                 Default: "no"
263
264     MKDEBUGLIB  Can be set to "yes" or "no".  Indicates whether debug
265                 information (see MKDEBUG) should also be generated for all
266                 libraries built.
267
268                 Default: "no"
269
270     MKDOC       Can be set to "yes" or "no".  Indicates whether system
271                 documentation destined for DESTDIR/usr/share/doc will be
272                 installed during a build.
273
274                 Default: "yes"
275
276     MKHTML      Can be set to "yes" or "no".  Indicates whether preformatted
277                 HTML manual pages will be built and installed
278
279                 Default: "yes"
280
281     MKHOSTOBJ   Can be set to "yes" or "no".  If set to "yes", then for
282                 programs intended to be run on the compile host, the name,
283                 release, and architecture of the host operating system will
284                 be suffixed to the name of the object directory created by
285                 "make obj".  (This allows multiple host systems to compile
286                 NetBSD for a single target.)  If set to "no", then programs
287                 built to be run on the compile host will use the same object
288                 directory names as programs built to be run on the target.
289
290                 Default: "no"
291
292     MKINFO      Can be set to "yes" or "no".  Indicates whether GNU Info
293                 files will be created and installed during a build.  GNU Info
294                 files are used for providing documentation by most of the
295                 compilation tools.
296
297                 Default: "yes"
298
299     MKKDEBUG    Can be set to "yes" or "no".  Force generation of full-debug
300                 symbol versions of all kernels compiled.  Alongside of the
301                 netbsd kernel file, an unstripped version netbsd.gdb is
302                 created.  This is useful if a cross-gdb is built as well (see
303                 MKCROSSGDB).
304
305                 Default: "no"
306
307     MKKMOD      Can be set to "yes" or "no".  Indicates whether kernel
308                 modules are built and installed.
309
310                 Default: "yes"
311
312     MKLINT      Can be set to "yes" or "no".  Indicates whether lint(1) will
313                 be run against portions of the NetBSD source code during the
314                 build, and whether lint libraries will be installed into
315                 DESTDIR/usr/libdata/lint.
316
317                 Default: "yes"
318
319     MKMAN       Can be set to "yes" or "no".  Indicates whether manual pages
320                 will be installed during a build.
321
322                 Default: "yes"
323
324     MKNLS       Can be set to "yes" or "no".  Indicates whether Native
325                 Language System locale zone files will be compiled and
326                 installed during a build.
327
328                 Default: "yes"
329
330     MKOBJ       Can be set to "yes" or "no".  Indicates whether object
331                 directories will be created when running "make obj".  If set
332                 to "no", then all built files will be located inside the
333                 regular source tree.
334
335                 Default: "yes"
336
337                 Note that setting MKOBJ to "no" is not recommended and may
338                 cause problems when updating the tree with cvs(1).
339
340     MKPIC       Can be set to "yes" or "no".  Indicates whether shared
341                 objects and libraries will be created and installed during a
342                 build.  If set to "no", the entire built system will be
343                 statically linked.
344
345                 Default: Platform dependent.  As of this writing, all
346                 platforms except m68000 default to "yes".
347
348     MKPICINSTALL
349                 Can be set to "yes" or "no".  Indicates whether the ar(1)
350                 format libraries (lib*_pic.a), used to generate shared
351                 libraries, are installed during a build.
352
353                 Default: "yes"
354
355     MKPROFILE   Can be set to "yes" or "no".  Indicates whether profiled
356                 libraries (lib*_p.a) will be built and installed during a
357                 build.
358
359                 Default: "yes"; however, some platforms turn off MKPROFILE by
360                 default at times due to toolchain problems with profiled
361                 code.
362
363     MKREPRO     Can be set to "yes" or "no".  Create reproducible builds.
364                 This enables different switches to make two builds from the
365                 same source tree result in the same build results.
366
367                 Default: "no" This may be set to "yes" by giving build.sh the
368                 -P option.
369
370     MKREPRO_TIMESTAMP
371                 Unix timestamp.  When MKREPRO is set, the timestamp of all
372                 files in the sets will be set to this value.
373
374                 Default: Unset.  This may be set automatically to the latest
375                 source tree timestamp using cvslatest(1) by giving build.sh
376                 the -P option.
377
378     MKSHARE     Can be set to "yes" or "no".  Indicates whether files
379                 destined to reside in DESTDIR/usr/share will be built and
380                 installed during a build.  If set to "no", then all of
381                 MKCATPAGES, MKDOC, MKINFO, MKMAN, and MKNLS will be set to
382                 "no" unconditionally.
383
384                 Default: "yes"
385
386     MKSTRIPIDENT
387                 Can be set to "yes" or "no".  Indicates whether RCS IDs, for
388                 use with ident(1), should be stripped from program binaries
389                 and shared libraries.
390
391                 Default: "no"
392
393     MKSTRIPSYM  Can be set to "yes" or "no".  Indicates whether all local
394                 symbols should be stripped from shared libraries.  If "yes",
395                 strip all local symbols from shared libraries; the affect is
396                 equivalent to the -x option of ld(1).  If "no", strip only
397                 temporary local symbols; the affect is equivalent to the -X
398                 option of ld(1).  Keeping non-temporary local symbols such as
399                 static function names is useful on using DTrace for userland
400                 libraries and getting a backtrace from a rump kernel loading
401                 shared libraries.
402
403                 Default: "yes"
404
405     MKUNPRIVED  Can be set to "yes" or "no".  Indicates whether an
406                 unprivileged install will occur.  The user, group,
407                 permissions, and file flags, will not be set on the installed
408                 items; instead the information will be appended to a file
409                 called METALOG in DESTDIR.  The contents of METALOG are used
410                 during the generation of the distribution tar files to ensure
411                 that the appropriate file ownership is stored.
412
413                 Default: "no"
414
415     MKUPDATE    Can be set to "yes" or "no".  Indicates whether all install
416                 operations intended to write to DESTDIR will compare file
417                 timestamps before installing, and skip the install phase if
418                 the destination files are up-to-date.  This also has
419                 implications on full builds (see next subsection).
420
421                 Default: "no"
422
423     MKX11       Can be set to "yes" or "no".  Indicates whether X11 is built
424                 from X11SRCDIR.
425
426                 Default: "no"
427
428     TOOLDIR     Directory to hold the host tools, once built.  If specified,
429                 must be an absolute path.  This directory should be unique to
430                 a given host system and NetBSD source tree.  (However,
431                 multiple targets may share the same TOOLDIR; the target-
432                 dependent files have unique names.)  If unset, a default
433                 based on the uname(1) information of the host platform will
434                 be created in the .OBJDIR of src.
435
436                 Default: Unset.
437
438     USETOOLS    Indicates whether the tools specified by TOOLDIR should be
439                 used as part of a build in progress.  Must be set to "yes" if
440                 cross-compiling.
441
442                 yes    Use the tools from TOOLDIR.
443
444                 no     Do not use the tools from TOOLDIR, but refuse to build
445                        native compilation tool components that are version-
446                        specific for that tool.
447
448                 never  Do not use the tools from TOOLDIR, even when building
449                        native tool components.  This is similar to the
450                        traditional NetBSD build method, but does not verify
451                        that the compilation tools in use are up-to-date
452                        enough in order to build the tree successfully.  This
453                        may cause build or runtime problems when building the
454                        whole NetBSD source tree.
455
456                 Default: "yes", unless TOOLCHAIN_MISSING is set to "yes".
457
458                 USETOOLS is also set to "no" when using <bsd.*.mk> outside
459                 the NetBSD source tree.
460
461     X11SRCDIR   Directory containing the modular Xorg source.  If specified,
462                 must be an absolute path.  The main modular Xorg source is
463                 found in X11SRCDIR/external/mit.
464
465                 Default: NETBSDSRCDIR/../xsrc, if that exists; otherwise
466                 /usr/xsrc.
467
468   "make" variables for full builds
469     These variables only affect the top level "Makefile" and do not affect
470     manually building subtrees of the NetBSD source code.
471
472     INSTALLWORLDDIR  Location for the "make installworld" target to install
473                      to.  If specified, must be an absolute path.
474
475                      Default: "/"
476
477     MKOBJDIRS        Can be set to "yes" or "no".  Indicates whether object
478                      directories will be created automatically (via a "make
479                      obj" pass) at the start of a build.
480
481                      Default: "no"
482
483                      If using build.sh, the default is "yes".  This may be
484                      set back to "no" by giving build.sh the -o option.
485
486     MKUPDATE         Can be set to "yes" or "no".  If set, then in addition
487                      to the effects described for MKUPDATE=yes above, this
488                      implies the effects of NOCLEANDIR (i.e., "make cleandir"
489                      is avoided).
490
491                      Default: "no"
492
493                      If using build.sh, this may be set by giving the -u
494                      option.
495
496     NBUILDJOBS       Now obsolete.  Use the make(1) option -j, instead.  See
497                      below.
498
499                      Default: Unset.
500
501     NOCLEANDIR       If set, avoids the "make cleandir" phase of a full
502                      build.  This has the effect of allowing only changed
503                      files in a source tree to be recompiled.  This can speed
504                      up builds when updating only a few files in the tree.
505
506                      Default: Unset.
507
508                      See also MKUPDATE.
509
510     NODISTRIBDIRS    If set, avoids the "make distrib-dirs" phase of a full
511                      build.  This skips running mtree(8) on DESTDIR, useful
512                      on systems where building as an unprivileged user, or
513                      where it is known that the system-wide mtree files have
514                      not changed.
515
516                      Default: Unset.
517
518     NOINCLUDES       If set, avoids the "make includes" phase of a full
519                      build.  This has the effect of preventing make(1) from
520                      thinking that some programs are out-of-date simply
521                      because the system include files have changed.  However,
522                      this option should not be used when updating the entire
523                      NetBSD source tree arbitrarily; it is suggested to use
524                      MKUPDATE=yes instead in that case.
525
526                      Default: Unset.
527
528     RELEASEDIR       If set, specifies the directory to which a release(7)
529                      layout will be written at the end of a "make release".
530                      If specified, must be an absolute path.
531
532                      Default: Unset.
533
534                      Note: build.sh will provide a default of releasedir (in
535                      the top-level .OBJDIR) unless run in `expert' mode.
536
537BUILDING
538   "make" command line options
539     This is not a summary of all the options available to make(1); only the
540     options used most frequently with NetBSD builds are listed here.
541
542     -j njob    Run up to njob make(1) subjobs in parallel.  Makefiles should
543                use .WAIT or have explicit dependencies as necessary to
544                enforce build ordering.
545
546     -m dir     Specify the default directory for searching for system
547                Makefile segments, mainly the <bsd.*.mk> files.  When building
548                any full NetBSD source tree, this should be set to the
549                "share/mk" directory in the source tree.  This is set
550                automatically when building from the top level, or when using
551                build.sh.
552
553     -n         Display the commands that would have been executed, but do not
554                actually execute them.  This will still cause recursion to
555                take place.
556
557     -V var     Print make(1)'s idea of the value of var.  Does not build any
558                targets.
559
560     var=value  Set the variable var to value, overriding any setting
561                specified by the process environment, the MAKECONF
562                configuration file, or the system Makefile segments.
563
564   "make" targets
565     These default targets may be built by running make(1) in any subtree of
566     the NetBSD source code.  It is recommended that none of these be used
567     from the top level Makefile; as a specific exception, "make obj" and
568     "make cleandir" are useful in that context.
569
570     all        Build programs, libraries, and preformatted documentation.
571
572     clean      Remove program and library object code files.
573
574     cleandir   Same as clean, but also remove preformatted documentation,
575                dependency files generated by "make depend", and any other
576                files known to be created at build time.
577
578     depend     Create dependency files (.depend) containing more detailed
579                information about the dependencies of source code on header
580                files.  Allows programs to be recompiled automatically when a
581                dependency changes.
582
583     dependall  Does a "make depend" immediately followed by a "make all".
584                This improves cache locality of the build since both passes
585                read the source files in their entirety.
586
587     distclean  Synonym for cleandir.
588
589     includes   Build and install system header files.  Typically needed
590                before any system libraries or programs can be built.
591
592     install    Install programs, libraries, and documentation into DESTDIR.
593                Few files will be installed to DESTDIR/dev, DESTDIR/etc,
594                DESTDIR/root or DESTDIR/var in order to prevent user supplied
595                configuration data from being overwritten.
596
597     lint       Run lint(1) against the C source code, where appropriate, and
598                generate system-installed lint libraries.
599
600     obj        Create object directories to be used for built files, instead
601                of building directly in the source tree.
602
603     tags       Create ctags(1) searchable function lists usable by the ex(1)
604                and vi(1) text editors.
605
606   "make" targets for the top level
607     Additional make(1) targets are usable specifically from the top source
608     level to facilitate building the entire NetBSD source tree.
609
610     build         Build the entire NetBSD system (except the kernel).  This
611                   orders portions of the source tree such that prerequisites
612                   will be built in the proper order.
613
614     distribution  Do a "make build", and then install a full distribution
615                   (which does not include a kernel) into DESTDIR, including
616                   files in DESTDIR/dev, DESTDIR/etc, DESTDIR/root and
617                   DESTDIR/var.
618
619     buildworld    As per "make distribution", except that it ensures that
620                   DESTDIR is not the root directory.
621
622     installworld  Install the distribution from DESTDIR to INSTALLWORLDDIR,
623                   which defaults to the root directory.  Ensures that
624                   INSTALLWORLDDIR is not the root directory if cross
625                   compiling.
626
627                   The INSTALLSETS environment variable may be set to a space-
628                   separated list of distribution sets to be installed.  By
629                   default, all sets except "etc" and "xetc" are installed, so
630                   most files in INSTALLWORLDDIR/etc will not be installed or
631                   modified.
632
633                   Note: Before performing this operation with
634                   INSTALLWORLDDIR=/, it is highly recommended that you
635                   upgrade your kernel and reboot.  After performing this
636                   operation, it is recommended that you use etcupdate(8) to
637                   update files in INSTALLWORLDDIR/etc, and postinstall(8) to
638                   check for or fix inconsistencies.
639
640     sets          Create distribution sets from DESTDIR into
641                   RELEASEDIR/RELEASEMACHINEDIR/binary/sets.  Should be run
642                   after "make distribution", as "make build" alone does not
643                   install all of the required files.
644
645     sourcesets    Create source sets of the source tree into
646                   RELEASEDIR/source/sets.
647
648     syspkgs       Create syspkgs from DESTDIR into
649                   RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.  Should be run
650                   after "make distribution", as "make build" alone does not
651                   install all of the required files.
652
653     release       Do a "make distribution", build kernels, distribution
654                   media, and install sets (this as per "make sets"), and then
655                   package the system into a standard release layout as
656                   described by release(7).  This requires that RELEASEDIR be
657                   set (see above).
658
659     iso-image     Create a NetBSD installation CD-ROM image in the
660                   RELEASEDIR/images directory.  The CD-ROM file system will
661                   have a layout as described in release(7).
662
663                   For most machine types, the CD-ROM will be bootable, and
664                   will automatically run the sysinst(8) menu-based
665                   installation program, which can be used to install or
666                   upgrade a NetBSD system.  Bootable CD-ROMs also contain
667                   tools that may be useful in repairing a damaged NetBSD
668                   installation.
669
670                   Before "make iso-image" is attempted, RELEASEDIR must be
671                   populated by "make release" or equivalent.
672
673                   Note that other, smaller, CD-ROM images may be created in
674                   the RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom
675                   directory by "make release".  These smaller images usually
676                   contain the same tools as the larger images in
677                   RELEASEDIR/images, but do not contain additional content
678                   such as the distribution sets.
679
680                   Note that the mac68k port still uses an older method of
681                   creating CD-ROM images.  This requires the mkisofs(1)
682                   utility, which is not part of NetBSD, but which can be
683                   installed from pkgsrc/sysutils/cdrtools.
684
685     iso-image-source
686                   Create a NetBSD installation CD-ROM image in the
687                   RELEASEDIR/images directory.  The CD-ROM file system will
688                   have a layout as described in release(7).  It will have top
689                   level directories for the machine type and source.
690
691                   For most machine types, the CD-ROM will be bootable, and
692                   will automatically run the sysinst(8) menu-based
693                   installation program, which can be used to install or
694                   upgrade a NetBSD system.  Bootable CD-ROMs also contain
695                   tools that may be useful in repairing a damaged NetBSD
696                   installation.
697
698                   Before "make iso-image-source" is attempted, RELEASEDIR
699                   must be populated by "make sourcesets release" or
700                   equivalent.
701
702                   Note that other, smaller, CD-ROM images may be created in
703                   the RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom
704                   directory by "make release".  These smaller images usually
705                   contain the same tools as the larger images in
706                   RELEASEDIR/images, but do not contain additional content
707                   such as the distribution sets.
708
709                   Note that the mac68k port still uses an older method of
710                   creating CD-ROM images.  This requires the mkisofs(1)
711                   utility, which is not part of NetBSD, but which can be
712                   installed from pkgsrc/sysutils/cdrtools.
713
714     install-image
715                   Create a bootable NetBSD installation disk image in the
716                   RELEASEDIR/images directory.  The installation disk image
717                   is suitable for copying to bootable USB flash memory
718                   sticks, etc., for machines which are able to boot from such
719                   devices.  The file system in the bootable disk image will
720                   have a layout as described in release(7).
721
722                   The installation image is bootable, and will automatically
723                   run the sysinst(8) menu-based installation program, which
724                   can be used to install or upgrade a NetBSD system.  The
725                   image also contains tools that may be useful in repairing a
726                   damaged NetBSD installation.
727
728                   Before "make install-image" is attempted, RELEASEDIR must
729                   be populated by "make release" or equivalent.  The build
730                   must have been performed with MKUNPRIVED=yes because "make
731                   install-image" relies on information in DESTDIR/METALOG.
732
733     live-image    Create NetBSD live images in the RELEASEDIR/images
734                   directory.  The live image contains all necessary files to
735                   boot NetBSD up to multi-user mode, including all files
736                   which should be extracted during installation, NetBSD
737                   disklabel, bootloaders, etc.
738
739                   The live image is suitable for use as a disk image in
740                   virtual machine environments such as QEMU, and also useful
741                   to boot NetBSD from a USB flash memory stick on a real
742                   machine, without the need for installation.
743
744                   Before "make live-image" is attempted, RELEASEDIR must be
745                   populated by "make release" or equivalent.  The build must
746                   have been performed with MKUNPRIVED=yes because "make
747                   install-image" relies on information in DESTDIR/METALOG.
748
749     regression-tests
750                   Can only be run after building the regression tests in the
751                   directory "regress".  Runs those compiled regression tests
752                   on the local host.  Note that most tests are now managed
753                   instead using atf(7); this target should probably run those
754                   as well but currently does not.
755
756   The "build.sh" script
757     This script file is a shell script designed to build the entire NetBSD
758     system on any host with a suitable modern shell and some common
759     utilities.  The required shell features are described under the HOST_SH
760     variable.
761
762     If a host system's default shell does support the required features, then
763     we suggest that you explicitly specify a suitable shell using a command
764     like
765
766           /path/to/suitable/shell build.sh [options]
767
768     The above command will usually enable build.sh to automatically set
769     HOST_SH=/path/to/suitable/shell, but if that fails, then the following
770     set of commands may be used instead:
771
772           HOST_SH=/path/to/suitable/shell
773           export HOST_SH
774           ${HOST_SH} build.sh [options]
775
776     If build.sh detects that it is being executed under an unsuitable shell,
777     it attempts to exec a suitable shell instead, or prints an error message.
778     If HOST_SH is not set explicitly, then build.sh sets a default using
779     heuristics dependent on the host platform, or from the shell under which
780     build.sh is executed (if that can be determined), or using the first copy
781     of sh found in PATH.
782
783     All cross-compile builds, and most native builds, of the entire system
784     should make use of build.sh rather than just running "make".  This way,
785     the make(1) program will be bootstrapped properly, in case the host
786     system has an older or incompatible "make" program.
787
788     When compiling the entire system via build.sh, many make(1) variables are
789     set for you in order to help encapsulate the build process.  In the list
790     of options below, variables that are automatically set by build.sh are
791     noted where applicable.
792
793     The following operations are supported by build.sh:
794
795     build         Build the system as per "make build".  Before the main part
796                   of the build commences, this command runs the obj operation
797                   (unless the -o option is given), "make cleandir" (unless
798                   the -u option is given), and the tools operation.
799
800     distribution  Build a full distribution as per "make distribution".  This
801                   command first runs the build operation.
802
803     release       Build a full release as per "make release".  This command
804                   first runs the distribution operation.
805
806     makewrapper   Create the nbmake-MACHINE wrapper.  This operation is
807                   automatically performed for any of the other operations.
808
809     cleandir      Perform "make cleandir".
810
811     obj           Perform "make obj".
812
813     tools         Build and install the host tools from src/tools.  This
814                   command will first run "make obj" and "make cleandir" in
815                   the tools subdirectory unless the -o or -u options
816                   (respectively) are given.
817
818     install=idir  Install the contents of DESTDIR to idir, using "make
819                   installworld".  Note that files that are part of the "etc"
820                   or "xetc" sets will not be installed, unless overridden by
821                   the INSTALLSETS environment variable.
822
823     kernel=kconf  Build a new kernel.  The kconf argument is the name of a
824                   configuration file suitable for use by config(1).  If kconf
825                   does not contain any `/' characters, the configuration file
826                   is expected to be found in the KERNCONFDIR directory, which
827                   is typically sys/arch/MACHINE/conf.  The new kernel will be
828                   built in a subdirectory of KERNOBJDIR, which is typically
829                   sys/arch/MACHINE/compile or an associated object directory.
830
831                   This command does not imply the tools command; run the
832                   tools command first unless it is certain that the tools
833                   already exist and are up to date.
834
835                   This command will run "make cleandir" on the kernel in
836                   question first unless the -u option is given.
837
838     kernel.gdb=kconf
839                   Build a new kernel with debug information.  Similar to the
840                   above kernel=kconf operation, but creates a netbsd.gdb file
841                   alongside of the kernel netbsd, which contains a full
842                   symbol table and can be used for debugging (for example
843                   with a cross-gdb built by MKCROSSGDB).
844
845     kernels       This command will build all kernels defined in port
846                   specific release build procedure.
847
848                   This command internally calls the kernel=kconf operation
849                   for each found kernel configuration file.
850
851     modules       This command will build kernel modules and install them
852                   into DESTDIR.
853
854     releasekernel=kconf
855                   Install a gzip(1)ed copy of the kernel previously built by
856                   kernel=kconf into
857                   RELEASEDIR/RELEASEMACHINEDIR/binary/kernel, usually as
858                   netbsd-kconf.gz, although the "netbsd" prefix is determined
859                   from the "config" directives in kconf.
860
861     sets          Perform "make sets".
862
863     sourcesets    Perform "make sourcesets".
864
865     syspkgs       Perform "make syspkgs".
866
867     iso-image     Perform "make iso-image".
868
869     iso-image-source
870                   Perform "make iso-image-source".
871
872     install-image
873                   Perform "make install-image".
874
875     live-image    Perform "make live-image".
876
877     list-arch     Prints a list of valid MACHINE and MACHINE_ARCH settings,
878                   the default MACHINE_ARCH for each MACHINE, and aliases for
879                   MACHINE/MACHINE_ARCH pairs, and then exits.  The -m or -a
880                   options (or both) may be used to specify glob patterns that
881                   will be used to narrow the list of results; for example,
882                   "build.sh -m 'evb*' -a '*arm*' list-arch" will list all
883                   known MACHINE/MACHINE_ARCH values in which either MACHINE
884                   or ALIAS matches the pattern `evb*', and MACHINE_ARCH
885                   matches the pattern `*arm*'.
886
887     The following command line options alter the behaviour of the build.sh
888     operations described above:
889
890     -a arch   Set the value of MACHINE_ARCH to arch.  See the -m option for
891               more information.
892
893     -B buildid
894               Set the value of BUILDID to buildid.  This will also append the
895               build identifier to the name of the "make" wrapper script so
896               that the resulting name is of the form
897               "nbmake-MACHINE-BUILDID".
898
899     -C cdextras
900               Append cdextras to the CDEXTRA variable, which is a space-
901               separated list of files or directories that will be added to
902               the CD-ROM image that may be create by the "iso-image" or
903               "iso-image-source" operations.  Files will be added to the root
904               of the CD-ROM image, whereas directories will be copied
905               recursively.  If relative paths are specified, they will be
906               converted to absolute paths before being used.  Multiple paths
907               may be specified via multiple -C options, or via a single
908               option whose argument contains multiple space-separated paths.
909
910     -c compiler
911               Select the compiler for the toolchain to build NetBSD and for
912               inclusion in the NetBSD distribution.  Supported choices:
913
914                     clang
915
916                     gcc [default]
917
918               The compiler used to build the toolchain can be different; see
919               HOST_CC and HOST_CXX.
920
921     -D dest   Set the value of DESTDIR to dest.  If a relative path is
922               specified, it will be converted to an absolute path before
923               being used.
924
925     -E        Set `expert' mode.  This overrides various sanity checks, and
926               allows: DESTDIR does not have to be set to a non-root path for
927               builds, and MKUNPRIVED=yes does not have to be set when
928               building as a non-root user.
929
930               Note: It is highly recommended that you know what you are doing
931               when you use this option.
932
933     -h        Print a help message.
934
935     -j njob   Run up to njob make(1) subjobs in parallel; passed through to
936               make(1).  If you see failures for reasons other than running
937               out of memory while using build.sh with -j, please save
938               complete build logs so the failures can be analyzed.
939
940               To achieve the fastest builds, -j values between (1 + the
941               number of CPUs) and (2 * the number of CPUs) are recommended.
942               Use lower values on machines with limited memory or I/O
943               bandwidth.
944
945     -M obj    Set MAKEOBJDIRPREFIX to obj.  Unsets MAKEOBJDIR.  See "-O obj"
946               for more information.
947
948               For instance, if the source directory is /usr/src, a setting of
949               "-M /usr/obj" will place build-time files under
950               /usr/obj/usr/src/bin, /usr/obj/usr/src/lib,
951               /usr/obj/usr/src/usr.bin, and so forth.
952
953               If a relative path is specified, it will be converted to an
954               absolute path before being used.  build.sh imposes the
955               restriction that the argument to the -M option must not begin
956               with a "$" (dollar sign) character; otherwise it would be too
957               difficult to determine whether the value is an absolute or a
958               relative path.  If the directory does not already exist,
959               build.sh will create it.
960
961     -m mach   Set the value of MACHINE to mach, unless the mach argument is
962               an alias that refers to a MACHINE/MACHINE_ARCH pair, in which
963               case both MACHINE and MACHINE_ARCH are set from the alias.
964               Such aliases are interpreted entirely by build.sh; they are not
965               used by any other part of the build system.  The MACHINE_ARCH
966               setting implied by mach will override any value of MACHINE_ARCH
967               in the process environment, but will not override a value set
968               by the -a option.  All cross builds require -m, but if unset on
969               a NetBSD host, the host's value of MACHINE will be detected and
970               used automatically.
971
972               See the list-arch operation for a way to get a list of valid
973               MACHINE and MACHINE_ARCH settings.
974
975     -N noiselevel
976               Set the "noisyness" level of the build, by setting MAKEVERBOSE
977               to noiselevel.
978
979     -n        Show the commands that would be executed by build.sh, but do
980               not make any changes.  This is similar in concept to "make -n".
981
982     -O obj    Create an appropriate transform macro for MAKEOBJDIR that will
983               place the built object files under obj.  Unsets
984               MAKEOBJDIRPREFIX.
985
986               For instance, a setting of "-O /usr/obj" will place build-time
987               files under /usr/obj/bin, /usr/obj/lib, /usr/obj/usr.bin, and
988               so forth.
989
990               If a relative path is specified, it will be converted to an
991               absolute path before being used.  build.sh imposes the
992               restriction that the argument to the -O option must not contain
993               a "$" (dollar sign) character.  If the directory does not
994               already exist, build.sh will create it.
995
996               In normal use, exactly one of the -M or -O options should be
997               specified.  If neither -M nor -O is specified, then a default
998               object directory will be chosen according to rules in
999               <bsd.obj.mk>.  Relying on this default is not recommended
1000               because it is determined by complex rules that are influenced
1001               by the values of several variables and by the location of the
1002               source directory.
1003
1004               Note that placing the obj directory location outside of the
1005               default source tree hierarchy makes it easier to manually clear
1006               out old files in the event the "make cleandir" operation is
1007               unable to do so.  (See CAVEATS below.)
1008
1009               Note also that use of one of -M or -O is the only means of
1010               building multiple machine architecture userlands from the same
1011               source tree without cleaning between builds (in which case, one
1012               would specify distinct obj locations for each).
1013
1014     -o        Set the value of MKOBJDIRS to "no".  Otherwise, it will be
1015               automatically set to "yes".  This default is opposite to the
1016               behaviour when not using build.sh.
1017
1018     -R rel    Set the value of RELEASEDIR to rel.  If a relative path is
1019               specified, it will be converted to an absolute path before
1020               being used.
1021
1022     -r        Remove the contents of DESTDIR and TOOLDIR before building
1023               (provides a clean starting point).  This will skip deleting
1024               DESTDIR if building on a native system to the root directory.
1025
1026     -S seed   Change the value of BUILDSEED to seed.  This should rarely be
1027               necessary.
1028
1029     -T tools  Set the value of TOOLDIR to tools.  If a relative path is
1030               specified, it will be converted to an absolute path before
1031               being used.  If set, the bootstrap "make" will only be rebuilt
1032               if the source files for make(1) have changed.
1033
1034     -U        Set MKUNPRIVED=yes.
1035
1036     -u        Set MKUPDATE=yes.
1037
1038     -V var=[value]
1039               Set the environment variable var to an optional value.  This is
1040               propagated to the nbmake wrapper.
1041
1042     -w wrapper
1043               Create the nbmake wrapper script (see below) in a custom
1044               location, specified by wrapper.  This allows, for instance, to
1045               place the wrapper in PATH automatically.  Note that wrapper is
1046               the full name of the file, not just a directory name.  If a
1047               relative path is specified, it will be converted to an absolute
1048               path before being used.
1049
1050     -X x11src
1051               Set the value of X11SRCDIR to x11src.  If a relative path is
1052               specified, it will be converted to an absolute path before
1053               being used.
1054
1055     -x        Set MKX11=yes.
1056
1057     -Z var    Unset ("zap") the environment variable var.  This is propagated
1058               to the nbmake wrapper.
1059
1060   The "nbmake-MACHINE" wrapper script
1061     If using the build.sh script to build NetBSD, a nbmake-MACHINE script
1062     will be created in TOOLDIR/bin upon the first build to assist in building
1063     subtrees on a cross-compile host.
1064
1065     nbmake-MACHINE can be invoked in lieu of make(1), and will instead call
1066     the up-to-date version of "nbmake" installed into TOOLDIR/bin with
1067     several key variables pre-set, including MACHINE, MACHINE_ARCH, and
1068     TOOLDIR.  nbmake-MACHINE will also set variables specified with -V, and
1069     unset variables specified with -Z.
1070
1071     This script can be symlinked into a directory listed in PATH, or called
1072     with an absolute path.
1073
1074EXAMPLES
1075     1.   % ./build.sh [options] tools kernel=GENERIC
1076
1077          Build a new toolchain, and use the new toolchain to configure and
1078          build a new GENERIC kernel.
1079
1080     2.   % ./build.sh [options] -U distribution
1081
1082          Using unprivileged mode, build a complete distribution to a DESTDIR
1083          directory that build.sh selects (and will display).
1084
1085     3.   # ./build.sh [options] -U install=/
1086
1087          As root, install to / the distribution that was built by example 2.
1088          Even though this is run as root, -U is required so that the
1089          permissions stored in DESTDIR/METALOG are correctly applied to the
1090          files as they're copied to /.
1091
1092     4.   % ./build.sh [options] -U -u release
1093
1094          Using unprivileged mode, build a complete release to DESTDIR and
1095          RELEASEDIR directories that build.sh selects (and will display).
1096          MKUPDATE=yes (-u) is set to prevent the "make cleandir", so that if
1097          this is run after example 2, it doesn't need to redo that portion of
1098          the release build.
1099
1100OBSOLETE VARIABLES
1101     NBUILDJOBS  Use the make(1) option -j instead.
1102
1103     USE_NEW_TOOLCHAIN
1104                 The new toolchain is now the default.  To disable, use
1105                 TOOLCHAIN_MISSING=yes.
1106
1107SEE ALSO
1108     make(1), hier(7), release(7), etcupdate(8), postinstall(8), sysinst(8),
1109     pkgsrc/sysutils/cdrtools
1110
1111HISTORY
1112     The build.sh based build scheme was introduced for NetBSD 1.6 as
1113     USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that.
1114
1115CAVEATS
1116     After significant updates to third-party components in the source tree,
1117     the "make cleandir" operation may be insufficient to clean out old files
1118     in object directories.  Instead, one may have to manually remove the
1119     files.  Consult the UPDATING file for notices concerning this.
1120
1121NetBSD                         October 13, 2020                         NetBSD
1122