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