xref: /netbsd-src/doc/BUILDING.mdoc (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1.\"	$NetBSD: BUILDING.mdoc,v 1.100 2014/06/14 12:20:17 apb Exp $
2.\"
3.\" Copyright (c) 2001-2011 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Todd Vierling and Luke Mewburn.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.\" NOTE: After changing this file, run "make regen" in the src/doc
31.\" directory, and check in both src/BUILDING and src/doc/BUILDING.mdoc.
32.\"
33.\" Toolchain prefix for commands
34.ds toolprefix nb
35.
36.Dd June 14, 2014
37.Dt BUILDING 8
38.Os NetBSD
39.
40.Sh NAME
41.
42.Nm BUILDING
43.Nd Procedure for building
44.Nx
45from source code.
46.
47.Sh REQUIREMENTS
48.
49.Nx
50is designed to be buildable on most POSIX-compliant host systems.
51The basic build procedure is the same whether compiling
52.Em natively
53(on the same
54.Nx
55architecture) or
56.Em cross compiling
57(on another architecture or OS).
58.Pp
59This source tree contains a special subtree,
60.Dq tools ,
61which uses the host system to create a build toolchain for the target
62architecture.
63The host system must have at least C and C++
64compilers in order to create the toolchain
65.Nm ( make
66is not required); all other tools are created as part of the
67.Nx
68build process.
69(See the environment variables section below if you need
70to override or manually select your compilers.)
71.
72.Sh FILES
73.
74.Ss Source tree layout
75.
76.Bl -tag -width "BUILDING.mdoc"
77.It Pa doc/BUILDING.mdoc
78This document (in -mdoc troff format; the original copy).
79.It Pa BUILDING
80This document (in plaintext).
81.It Pa tools/compat/README
82Special notes for cross-hosting a NetBSD build on non-NetBSD platforms.
83.It Pa Makefile
84The main Makefile for
85.Nx ;
86should only be run for native builds with an appropriately up-to-date
87version of
88.Nx
89.Xr make 1 .
90(For building from out-of-date systems or on a non-native host, see the
91.Nm build.sh
92shell script.)
93.It Pa UPDATING
94Special notes for updating from an earlier revision of
95.Nx .
96It is important to read this file before every build of an updated
97source tree.
98.It Pa build.sh
99Bourne-compatible shell script used for building the host build tools
100and the
101.Nx
102system from scratch.
103Can be used for both native and cross builds, and should be used instead of
104.Xr make 1
105for any source tree that is updated and recompiled regularly.
106.It Pa crypto/dist/ , dist/ , gnu/dist/
107Sources imported verbatim from third parties, without mangling the
108existing build structure.
109Other source trees in
110.Sy bin
111through
112.Sy usr.sbin
113use the
114.Nx
115.Xr make 1
116.Dq reachover
117Makefile semantics when building these programs for a native host.
118.It Pa external , sys/external
119Sources and build infrastructure for components imported (mostly) unchanged
120from upstream maintainers, sorted by applicable license.
121This is (slowly) replacing the
122.Pa crypto/dist ,
123.Pa dist ,
124and
125.Pa gnu/dist
126directories.
127.It Pa distrib/ , etc/
128Sources for items used when making a full release snapshot, such as
129files installed in
130.Sy DESTDIR Ns Pa /etc
131on the destination system, boot media, and release notes.
132.It Pa tests/ , regress/
133Regression test harness.
134Can be cross-compiled, but only run natively.
135.Pa tests/
136uses the
137.Xr atf 7
138test framework;
139.Pa regress/
140contains older tests that have not yet been migrated to
141.Xr atf 7 .
142.It Pa sys/
143.Nx
144kernel sources.
145.It Pa tools/
146.Dq Reachover
147build structure for the host build tools.
148This has a special method of determining out-of-date status.
149.It Pa bin/ ... usr.sbin/
150Sources to the
151.Nx
152userland (non-kernel) programs.
153If any of these directories are missing, they will be skipped during the build.
154.It Pa x11/
155.Dq Reachover
156build structure for X11R6; the source is in
157.Sy X11SRCDIR .
158.El
159.
160.Ss Build tree layout
161.
162The
163.Nx
164build tree is described in
165.Xr hier 7 ,
166and the release layout is described in
167.Xr release 7 .
168.
169.Sh CONFIGURATION
170.
171.Ss Environment variables
172.
173Several environment variables control the behaviour of
174.Nx
175builds.
176.
177.Bl -tag -width "MAKEOBJDIRPREFIX"
178.
179.
180.It Sy HOST_SH
181Path name to a shell available on the host system
182and suitable for use during the build.
183The
184.Nx
185build system requires a modern Bourne-like shell
186with POSIX-compliant features,
187and also requires support for the
188.Dq local
189keyword to declare local variables in shell functions
190(which is a widely-implemented but non-standardised feature).
191.Pp
192Depending on the host system, a suitable shell may be
193.Pa /bin/sh ,
194.Pa /usr/xpg4/bin/sh ,
195.Pa /bin/ksh
196(provided it is a variant of ksh that supports the
197.Dq local
198keyword,
199such as ksh88, but not ksh93),
200or
201.Pa /usr/local/bin/bash .
202.Pp
203Most parts of the build require
204.Sy HOST_SH
205to be an absolute path; however,
206.Nm build.sh
207allows it to be a simple command name, which will be converted
208to an absolute path by searching the
209.Sy PATH .
210.
211.It Sy HOST_CC
212Path name to C compiler used to create the toolchain.
213.
214.It Sy HOST_CXX
215Path name to C++ compiler used to create the toolchain.
216.
217.It Sy MACHINE
218Machine type, e.g.,
219.Dq macppc .
220.
221.It Sy MACHINE_ARCH
222Machine architecture, e.g.,
223.Dq powerpc .
224.
225.It Sy MAKE
226Path name to invoke
227.Xr make 1
228as.
229.
230.It Sy MAKEFLAGS
231Flags to invoke
232.Xr make 1
233with.
234Note that
235.Sy build.sh
236ignores the value of
237.Sy MAKEFLAGS
238passed in the environment, but allows
239.Sy MAKEFLAGS
240to be set via the
241.Fl V
242option.
243.
244.It Sy MAKEOBJDIR
245Directory to use as the
246.Sy .OBJDIR
247for the current directory.
248The value is subjected to variable expansion by
249.Xr make 1 .
250Typical usage is to set this variable to a value involving the use of
251.Sq ${.CURDIR:S...}
252or
253.Sq ${.CURDIR:C...} ,
254to derive the value of
255.Sy .OBJDIR
256from the value of
257.Sy .CURDIR .
258Used only if
259.Sy MAKEOBJDIRPREFIX
260is not defined.
261.Sy MAKEOBJDIR
262can be provided only in the environment or via the
263.Fl O
264flag of
265.Nm build.sh ;
266it cannot usefully be set inside a Makefile, including
267.Pa mk.conf
268or
269.Sy ${MAKECONF} .
270.
271.It Sy MAKEOBJDIRPREFIX
272Top level directory of the object directory tree.
273The value is subjected to variable expansion by
274.Xr make 1 .
275.Sy build.sh
276will create the
277${MAKEOBJDIRPREFIX}
278directory if necessary, but if
279.Xr make 1
280is used without
281.Sy build.sh ,
282then rules in
283.Aq bsd.obj.mk
284will abort the build if the
285${MAKEOBJDIRPREFIX}
286directory does not exist.
287If the value is defined and valid, then
288${MAKEOBJDIRPREFIX}/${.CURDIR}
289is used as the
290.Sy .OBJDIR
291for the current directory.
292The current directory may be read only.
293.Sy MAKEOBJDIRPREFIX
294can be provided only in the environment or via the
295.Fl M
296flag of
297.Nm build.sh ;
298it cannot usefully be set inside a Makefile, including
299.Pa mk.conf
300or
301.Sy ${MAKECONF} .
302.
303.El
304.
305.Ss \*qmake\*q variables
306.
307.de YorN
308Can be set to
309.Dq yes
310or
311.Dq no .
312..
313.de DFLT
314.Pp
315.Em Default :
316..
317.de DFLTu
318.DFLT
319Unset.
320..
321.de DFLTy
322.DFLT
323.Dq yes
324..
325.de DFLTn
326.DFLT
327.Dq no
328..
329Several variables control the behavior of
330.Nx
331builds.
332Unless otherwise specified, these variables may be set in
333either the process environment or the
334.Xr make 1
335configuration file specified by
336.Sy MAKECONF .
337.
338.Bl -tag -width "MKCATPAGES"
339.
340.It Sy BUILDID
341Identifier for the build.
342If set, this should be a short string that is suitable for use as
343part of a file or directory name.
344The identifier will be appended to
345object directory names, and can be consulted in the
346.Xr make 1
347configuration file in order to set additional build parameters,
348such as compiler flags.
349It will also be used as part of the kernel version string,
350which can be printed by
351.Dq Li uname \-v .
352.DFLTu
353.
354.It Sy BUILDSEED
355GCC uses random numbers when compiling C++ code.
356This variable seeds the gcc random number generator using
357the -frandom-seed flag with this value.
358By default, it is set to NetBSD-(majorversion).
359Using a fixed value causes C++ binaries to be the same when
360built from the same sources, resulting in identical (reproducible) builds.
361Additional information is available in the GCC
362documentation of -frandom-seed.
363.
364.It Sy DESTDIR
365Directory to contain the built
366.Nx
367system.
368If set, special options are passed to the compilation tools to
369prevent their default use of the host system's
370.Pa /usr/include , /usr/lib ,
371and so forth.
372This pathname must be an absolute path, and should
373.Em not
374end with a slash
375.Pq /
376character.
377(For installation into the system's root directory, set
378.Sy DESTDIR
379to an empty string, not to
380.Dq / ) .
381The directory must reside on a file system which supports long file
382names and hard links.
383.DFLT
384Empty string if
385.Sy USETOOLS
386is
387.Dq yes ;
388unset otherwise.
389.Pp
390.Em Note :
391.Sy build.sh
392will provide a default of
393.Pa destdir. Ns Sy MACHINE
394(in the top-level
395.Sy .OBJDIR )
396unless run in
397.Sq expert
398mode.
399.
400.It Sy MAKECONF
401The name of the
402.Xr make 1
403configuration file.
404.Em Only settable in the process environment.
405.DFLT
406.Dq /etc/mk.conf
407.
408.It Sy MAKEVERBOSE
409Level of verbosity of status messages.
410Supported values:
411.Bl -tag -width xxx
412.It 0
413No descriptive messages or commands executed by
414.Xr make 1
415are shown.
416.It 1
417Brief messages are shown describing what is being done,
418but the actual commands executed by
419.Xr make 1
420are not displayed.
421.It 2
422Descriptive messages are shown as above (prefixed with a
423.Sq # ) ,
424and ordinary commands performed by
425.Xr make 1
426are displayed.
427.It 3
428In addition to the above, all commands performed by
429.Xr make 1
430are displayed, even if they would ordinarily have been hidden
431through use of the
432.Dq \&@
433prefix in the relevant makefile.
434.It 4
435In addition to the above, commands executed by
436.Xr make 1
437are traced through use of the
438.Xr sh 1
439.Dq Fl x
440flag.
441.El
442.DFLT
4432
444.
445.It Sy MKCATPAGES
446.YorN
447Indicates whether preformatted plaintext manual pages will be created
448during a build.
449.DFLTn
450.
451.It Sy MKCROSSGDB
452.YorN
453Create a cross-gdb as a host tool.
454.DFLTn
455.
456.It Sy MKCRYPTO
457.YorN
458Indicates whether cryptographic code will be included in a build;
459provided for the benefit of countries that do not allow strong
460cryptography.
461Will not affect use of the standard low-security password encryption system,
462.Xr crypt 3 .
463.DFLTy
464.
465.It Sy MKDEBUG
466.YorN
467Indicates whether debug information should be generated for all userland
468binaries compiled.
469The result is collected as an additional
470.Sy debug.tgz
471and
472.Sy xdebug.tgz
473set and installed in
474.Pa /usr/libdata/debug .
475.DFLTn
476.
477.It Sy MKDEBUGLIB
478.YorN
479Indicates whether debug information (see
480.Sy MKDEBUG )
481should also be generated for all libraries build.
482.DFLTn
483.
484.It Sy MKDOC
485.YorN
486Indicates whether system documentation destined for
487.Sy DESTDIR Ns Pa /usr/share/doc
488will be installed during a build.
489.DFLTy
490.
491.It Sy MKHTML
492.YorN
493Indicates whether preformatted HTML manual pages will be built
494and installed
495.DFLTy
496.
497.It Sy MKHOSTOBJ
498.YorN
499If set to
500.Dq yes ,
501then for programs intended to be run on the compile host,
502the name, release, and architecture of the host operating system
503will be suffixed to the name of the object directory created by
504.Dq make obj .
505(This allows multiple host systems to compile NetBSD for a single target.)
506If set to
507.Dq no ,
508then programs built to be run on the compile host will use the same
509object directory names as programs built to be run on the target.
510.DFLTn
511.
512.It Sy MKINFO
513.YorN
514Indicates whether GNU Info files, used for the documentation for
515most of the compilation tools, will be created and installed during a
516build.
517.DFLTy
518.
519.It Sy MKKDEBUG
520.YorN
521Force generation of full-debug symbol versions of all kernels compiled.
522Alongside of the
523.Pa netbsd
524kernel file, an unstripped version
525.Pa netbsd.gdb
526is created.
527This is useful if a cross-gdb is built as well (see
528.Sy MKCROSSGDB ) .
529.DFLTn
530.
531.It Sy MKKMOD
532.YorN
533Indicates whether kernel modules are built and installed.
534.DFLTy
535.
536.It Sy MKLINT
537.YorN
538Indicates whether
539.Xr lint 1
540will be run against portions of the
541.Nx
542source code during the build, and whether lint libraries will be
543installed into
544.Sy DESTDIR Ns Pa /usr/libdata/lint .
545.DFLTy
546.
547.It Sy MKMAN
548.YorN
549Indicates whether manual pages will be installed during a build.
550.DFLTy
551.
552.It Sy MKNLS
553.YorN
554Indicates whether Native Language System locale zone files will be
555compiled and installed during a build.
556.DFLTy
557.
558.It Sy MKOBJ
559.YorN
560Indicates whether object directories will be created when running
561.Dq make obj .
562If set to
563.Dq no ,
564then all built files will be located inside the regular source tree.
565.DFLTy
566.Pp
567Note that setting
568.Sy MKOBJ
569to
570.Dq no
571is not recommended and may cause problems when updating the tree with
572.Xr cvs 1 .
573.
574.It Sy MKPIC
575.YorN
576Indicates whether shared objects and libraries will be created and
577installed during a build.
578If set to
579.Dq no ,
580the entire built system will be statically linked.
581.DFLT
582Platform dependent.
583As of this writing, all platforms except
584.Sy sh3
585default to
586.Dq yes .
587.
588.It Sy MKPICINSTALL
589.YorN
590Indicates whether the
591.Xr ar 1
592format libraries
593.Sy ( lib*_pic.a ) ,
594used to generate shared libraries, are installed during a build.
595.DFLTy
596.
597.It Sy MKPROFILE
598.YorN
599Indicates whether profiled libraries
600.Sy ( lib*_p.a )
601will be built and installed during a build.
602.DFLT
603.Dq yes ;
604however, some platforms turn off
605.Sy MKPROFILE
606by default at times due to toolchain problems with profiled code.
607.
608.It Sy MKREPRO
609.YorN
610Create reproducable builds.
611This enables different switches to make two builds from the same
612source tree result in the same build results.
613.DFLTn
614.
615.It Sy MKSHARE
616.YorN
617Indicates whether files destined to reside in
618.Sy DESTDIR Ns Pa /usr/share
619will be built and installed during a build.
620If set to
621.Dq no ,
622then all of
623.Sy MKCATPAGES , MKDOC , MKINFO , MKMAN ,
624and
625.Sy MKNLS
626will be set to
627.Dq no
628unconditionally.
629.DFLTy
630.
631.It Sy MKSTRIPIDENT
632.YorN
633Indicates whether RCS IDs, for use with
634.Xr ident 1 ,
635should be stripped from program binaries and shared libraries.
636.DFLTn
637.
638.It Sy MKUNPRIVED
639.YorN
640Indicates whether an unprivileged install will occur.
641The user, group, permissions, and file flags, will not be set on
642the installed items; instead the information will be appended to
643a file called
644.Pa METALOG
645in
646.Sy DESTDIR .
647The contents of
648.Pa METALOG
649are used during the generation of the distribution tar files to ensure
650that the appropriate file ownership is stored.
651.DFLTn
652.
653.It Sy MKUPDATE
654.YorN
655Indicates whether all install operations intended to write to
656.Sy DESTDIR
657will compare file timestamps before installing, and skip the install
658phase if the destination files are up-to-date.
659This also has implications on full builds (see next subsection).
660.DFLTn
661.
662.It Sy MKX11
663.YorN
664Indicates whether X11 is built from
665.Sy X11SRCDIR .
666.DFLTn
667.
668.It Sy TOOLDIR
669Directory to hold the host tools, once built.
670If specified, must be an absolute path.
671This directory should be unique to a given host system and
672.Nx
673source tree.
674(However, multiple targets may share the same
675.Sy TOOLDIR ;
676the target-dependent files have unique names.)  If unset, a default based
677on the
678.Xr uname 1
679information of the host platform will be created in the
680.Sy .OBJDIR
681of
682.Pa src .
683.DFLTu
684.
685.It Sy USETOOLS
686Indicates whether the tools specified by
687.Sy TOOLDIR
688should be used as part of a build in progress.
689Must be set to
690.Dq yes
691if cross-compiling.
692.Bl -tag -width "never"
693.It Sy yes
694Use the tools from
695.Sy TOOLDIR .
696.It Sy no
697Do not use the tools from
698.Sy TOOLDIR ,
699but refuse to build native compilation tool components that are
700version-specific for that tool.
701.It Sy never
702Do not use the tools from
703.Sy TOOLDIR ,
704even when building native tool components.
705This is similar to the traditional
706.Nx
707build method, but does
708.Em not
709verify that the compilation tools in use are up-to-date enough in order
710to build the tree successfully.
711This may cause build or runtime problems when building the whole
712.Nx
713source tree.
714.El
715.DFLT
716.Dq yes ,
717unless
718.Sy TOOLCHAIN_MISSING
719is set to
720.Dq yes .
721.Pp
722.Sy USETOOLS
723is also set to
724.Dq no
725when using
726.Aq bsd.*.mk
727outside the
728.Nx
729source tree.
730.
731.It Sy X11SRCDIR
732Directory containing the X11R6 source.
733If specified, must be an absolute path.
734The main X11R6 source is found in
735.Sy X11SRCDIR Ns Pa /xfree/xc .
736.DFLT
737.Sy NETBSDRCDIR Ns Pa /../xsrc ,
738if that exists; otherwise
739.Pa /usr/xsrc .
740.
741.It Sy X11FLAVOUR
742The style of X11 cross-built, set to either
743.Dq Xorg
744or
745.Dq XFree86 .
746.DFLT
747.Dq Xorg
748on amd64, i386, macppc, shark and sparc64 platforms,
749.Dq XFree86
750on everything else.
751.
752.El
753.
754.Ss \*qmake\*q variables for full builds
755These variables only affect the top level
756.Dq Makefile
757and do not affect manually building subtrees of the
758.Nx
759source code.
760.
761.Bl -tag -width "INSTALLWORLDDIR"
762.
763.It Sy INSTALLWORLDDIR
764Location for the
765.Dq make installworld
766target to install to.
767If specified, must be an absolute path.
768.DFLT
769.Dq /
770.
771.It Sy MKOBJDIRS
772.YorN
773Indicates whether object directories will be created automatically
774(via a
775.Dq make obj
776pass) at the start of a build.
777.DFLTn
778.Pp
779If using
780.Sy build.sh ,
781the default is
782.Dq yes .
783This may be set back to
784.Dq no
785by giving
786.Sy build.sh
787the
788.Fl o
789option.
790.
791.It Sy MKUPDATE
792.YorN
793If set, then in addition to the effects described for
794.Sy MKUPDATE=yes
795above, this implies the effects of
796.Sy NOCLEANDIR
797(i.e.,
798.Dq make cleandir
799is avoided).
800.DFLTn
801.Pp
802If using
803.Sy build.sh ,
804this may be set by giving the
805.Fl u
806option.
807.
808.It Sy NBUILDJOBS
809Now obsolete.
810Use the
811.Xr make 1
812option
813.Fl j ,
814instead.
815See below.
816.DFLTu
817.
818.It Sy NOCLEANDIR
819If set, avoids the
820.Dq make cleandir
821phase of a full build.
822This has the effect of allowing only changed
823files in a source tree to be recompiled.
824This can speed up builds when updating only a few files in the tree.
825.DFLTu
826.Pp
827See also
828.Sy MKUPDATE .
829.
830.It Sy NODISTRIBDIRS
831If set, avoids the
832.Dq make distrib-dirs
833phase of a full build.
834This skips running
835.Xr mtree 8
836on
837.Sy DESTDIR ,
838useful on systems where building as an unprivileged user, or where it is
839known that the system-wide mtree files have not changed.
840.DFLTu
841.
842.It Sy NOINCLUDES
843If set, avoids the
844.Dq make includes
845phase of a full build.
846This has the effect of preventing
847.Xr make 1
848from thinking that some programs are out-of-date simply because the
849system include files have changed.
850However, this option should not be used when updating the entire
851.Nx
852source tree arbitrarily; it is suggested to use
853.Sy MKUPDATE=yes
854instead in that case.
855.DFLTu
856.
857.It Sy RELEASEDIR
858If set, specifies the directory to which a
859.Xr release 7
860layout will be written at the end of a
861.Dq make release .
862If specified, must be an absolute path.
863.DFLTu
864.Pp
865.Em Note :
866.Sy build.sh
867will provide a default of
868.Pa releasedir
869(in the top-level
870.Sy .OBJDIR )
871unless run in
872.Sq expert
873mode.
874.
875.El
876.
877.Sh BUILDING
878.
879.Ss \*qmake\*q command line options
880This is not a summary of all the options available to
881.Xr make 1 ;
882only the options used most frequently with
883.Nx
884builds are listed here.
885.
886.Bl -tag -width "var=value"
887.
888.It Fl j Ar njob
889Run up to
890.Ar njob
891.Xr make 1
892subjobs in parallel.
893Makefiles should use .WAIT or have explicit dependencies
894as necessary to enforce build ordering.
895.
896.It Fl m Ar dir
897Specify the default directory for searching for system Makefile
898segments, mainly the
899.Aq bsd.*.mk
900files.
901When building any full
902.Nx
903source tree, this should be set to the
904.Dq Pa share/mk
905directory in the source tree.
906This is set automatically when building from the top level, or when using
907.Sy build.sh .
908.
909.It Fl n
910Display the commands that would have been executed, but do not
911actually execute them.
912This will still cause recursion to take place.
913.
914.It Fl V Ar var
915Print
916.Xr make 1 Ns 's
917idea of the value of
918.Ar var .
919Does not build any targets.
920.
921.It Em var=value
922Set the variable
923.Em var
924to
925.Em value ,
926overriding any setting specified by the process environment, the
927.Sy MAKECONF
928configuration file, or the system Makefile segments.
929.
930.El
931.
932.Ss \*qmake\*q targets
933.
934These default targets may be built by running
935.Xr make 1
936in any subtree of the
937.Nx
938source code.
939It is recommended that none of these be used from the top
940level Makefile; as a specific exception,
941.Dq make obj
942and
943.Dq make cleandir
944are useful in that context.
945.
946.Bl -tag -width "dependall"
947.
948.It Sy all
949Build programs, libraries, and preformatted documentation.
950.
951.It Sy clean
952Remove program and library object code files.
953.
954.It Sy cleandir
955Same as
956.Sy clean ,
957but also remove preformatted documentation, dependency files generated
958by
959.Dq make depend ,
960and any other files known to be created at build time.
961.
962.It Sy depend
963Create dependency files
964.Sy ( .depend )
965containing more detailed information about the dependencies of source
966code on header files.
967Allows programs to be recompiled automatically when a dependency changes.
968.
969.It Sy dependall
970Does a
971.Dq make depend
972immediately followed by a
973.Dq make all .
974This improves cache locality of the build since both passes read the source
975files in their entirety.
976.
977.It Sy distclean
978Synonym for
979.Sy cleandir .
980.
981.It Sy includes
982Build and install system header files.
983Typically needed before any system libraries or programs can be built.
984.
985.It Sy install
986Install programs, libraries, and documentation into
987.Sy DESTDIR .
988Few files will be installed to
989.Sy DESTDIR Ns Pa /dev ,
990.Sy DESTDIR Ns Pa /etc ,
991.Sy DESTDIR Ns Pa /root
992or
993.Sy DESTDIR Ns Pa /var
994in order to prevent user supplied configuration data from being overwritten.
995.It Sy lint
996Run
997.Xr lint 1
998against the C source code, where appropriate, and generate
999system-installed lint libraries.
1000.
1001.It Sy obj
1002Create object directories to be used for built files, instead of
1003building directly in the source tree.
1004.
1005.It Sy tags
1006Create
1007.Xr ctags 1
1008searchable function lists usable by the
1009.Xr ex 1
1010and
1011.Xr vi 1
1012text editors.
1013.
1014.El
1015.
1016.Ss \*qmake\*q targets for the top level
1017.
1018Additional
1019.Xr make 1
1020targets are usable specifically from the top source level to facilitate
1021building the entire
1022.Nx
1023source tree.
1024.
1025.Bl -tag -width "distribution"
1026.
1027.It Sy build
1028Build the entire
1029.Nx
1030system (except the kernel).
1031This orders portions of the source tree such that prerequisites
1032will be built in the proper order.
1033.
1034.It Sy distribution
1035Do a
1036.Dq make build ,
1037and then install a full distribution (which does not include a kernel) into
1038.Sy DESTDIR ,
1039including files in
1040.Sy DESTDIR Ns Pa /dev ,
1041.Sy DESTDIR Ns Pa /etc ,
1042.Sy DESTDIR Ns Pa /root
1043and
1044.Sy DESTDIR Ns Pa /var .
1045.
1046.It Sy buildworld
1047As per
1048.Dq make distribution ,
1049except that it ensures that
1050.Sy DESTDIR
1051is not the root directory.
1052.
1053.It Sy installworld
1054Install the distribution from
1055.Sy DESTDIR
1056to
1057.Sy INSTALLWORLDDIR ,
1058which defaults to the root directory.
1059Ensures that
1060.Sy INSTALLWORLDDIR
1061is not the root directory if cross compiling.
1062.Pp
1063The
1064.Sy INSTALLSETS
1065environment variable may be set to a space-separated list of
1066distribution sets to be installed.
1067By default, all sets except
1068.Dq etc
1069and
1070.Dq xetc
1071are installed, so most files in
1072.Sy INSTALLWORLDDIR Ns Pa /etc
1073will not be installed or modified.
1074.Pp
1075.Em Note :
1076Before performing this operation with
1077.Sy INSTALLWORLDDIR Ns = Ns Pa / ,
1078it is highly recommended that you upgrade your kernel and reboot.
1079After performing this operation,
1080it is recommended that you use
1081.Xr etcupdate 8
1082to update files in
1083.Sy INSTALLWORLDDIR Ns Pa /etc ,
1084and
1085.Xr postinstall 8
1086to check for or fix inconsistencies.
1087.It Sy sets
1088Create distribution sets from
1089.Sy DESTDIR
1090into
1091.Sy RELEASEDIR/RELEASEMACHINEDIR Ns Pa /binary/sets .
1092Should be run after
1093.Dq make distribution ,
1094as
1095.Dq make build
1096alone does not install all of the required files.
1097.
1098.It Sy sourcesets
1099Create source sets of the source tree into
1100.Sy RELEASEDIR Ns Pa /source/sets .
1101.
1102.It Sy syspkgs
1103Create syspkgs from
1104.Sy DESTDIR
1105into
1106.Sy RELEASEDIR/RELEASEMACHINEDIR Ns Pa /binary/syspkgs .
1107Should be run after
1108.Dq make distribution ,
1109as
1110.Dq make build
1111alone does not install all of the required files.
1112.
1113.It Sy release
1114Do a
1115.Dq make distribution ,
1116build kernels, distribution media, and install sets
1117(this as per
1118.Dq make sets ) ,
1119and
1120then package the system into a standard release layout as described by
1121.Xr release 7 .
1122This requires that
1123.Sy RELEASEDIR
1124be set (see above).
1125.
1126.It Sy iso-image
1127Create a
1128.Nx
1129installation CD-ROM image in the
1130.Sy RELEASEDIR Ns Pa /iso
1131directory.
1132The CD-ROM file system will have a layout as described in
1133.Xr release 7 .
1134.Pp
1135For most machine types, the CD-ROM will be bootable, and will automatically
1136run the
1137.Xr sysinst 8
1138menu-based installation program, which can be used to install or upgrade a
1139.Nx
1140system.
1141Bootable CD-ROMs also contain tools that may be useful in
1142repairing a damaged
1143.Nx
1144installation.
1145.Pp
1146Before
1147.Dq make iso-image
1148is attempted, RELEASEDIR must be populated by
1149.Dq make release
1150or equivalent.
1151.Pp
1152Note that other, smaller, CD-ROM images may be created in the
1153.Sy RELEASEDIR/RELEASEMACHINEDIR Ns Pa /installation/cdrom
1154directory by
1155.Dq "make release" .
1156These smaller images usually contain the same tools as the larger images in
1157.Sy RELEASEDIR Ns Pa /iso ,
1158but do not contain additional content such as the distribution sets.
1159.Pp
1160Note that the mac68k port still uses an older method of creating
1161CD-ROM images.
1162This requires the
1163.Xr mkisofs 1
1164utility, which is not part of
1165.Nx ,
1166but which can be installed from
1167.Pa pkgsrc/sysutils/cdrtools .
1168.
1169.It Sy iso-image-source
1170Create a
1171.Nx
1172installation CD-ROM image in the
1173.Sy RELEASEDIR Ns Pa /iso
1174directory.
1175The CD-ROM file system will have a layout as described in
1176.Xr release 7 .
1177It will have top level directories for the machine type and source.
1178.Pp
1179For most machine types, the CD-ROM will be bootable, and will automatically
1180run the
1181.Xr sysinst 8
1182menu-based installation program, which can be used to install or upgrade a
1183.Nx
1184system.
1185Bootable CD-ROMs also contain tools that may be useful in
1186repairing a damaged
1187.Nx
1188installation.
1189.Pp
1190Before
1191.Dq make iso-image-source
1192is attempted, RELEASEDIR must be populated by
1193.Dq make sourcesets release
1194or equivalent.
1195.Pp
1196Note that other, smaller, CD-ROM images may be created in the
1197.Sy RELEASEDIR/RELEASEMACHINEDIR Ns Pa /installation/cdrom
1198directory by
1199.Dq make release .
1200These smaller images usually contain the same tools as the larger images in
1201.Sy RELEASEDIR Ns Pa /iso ,
1202but do not contain additional content such as the distribution sets.
1203.Pp
1204Note that the mac68k port still uses an older method of creating
1205CD-ROM images.
1206This requires the
1207.Xr mkisofs 1
1208utility, which is not part of
1209.Nx ,
1210but which can be installed from
1211.Pa pkgsrc/sysutils/cdrtools .
1212.
1213.It Sy install-image
1214Create a bootable
1215.Nx
1216installation disk image in the
1217.Sy RELEASEDIR/RELEASEMACHINEDIR Ns Pa /installation/installimage
1218directory.
1219The installation disk image is suitable for copying to
1220bootable USB flash memory sticks, etc., for machines which
1221are able to boot from such devices.
1222The file system in the bootable disk image will have a layout
1223as described in
1224.Xr release 7 .
1225.Pp
1226The installation image is bootable, and will automatically
1227run the
1228.Xr sysinst 8
1229menu-based installation program, which can be used to install or upgrade a
1230.Nx
1231system.
1232The image also contains tools that may be
1233useful in repairing a damaged
1234.Nx
1235installation.
1236.Pp
1237Before
1238.Dq make install-image
1239is attempted,
1240.Sy RELEASEDIR
1241must be populated by
1242.Dq make release
1243or equivalent.
1244The build must have been performed with
1245.Sy MKUNPRIVED=yes
1246because
1247.Dq make install-image
1248relies on information in
1249.Sy DESTDIR Ns Pa /METALOG .
1250.
1251.It live-image
1252Create
1253.Nx
1254live images in the
1255.Sy RELEASEDIR/RELEASEMACHINEDIR Ns Pa /installation/liveimage
1256directory.
1257The live image contains all necessary files
1258to boot
1259.Nx
1260up to multi-user mode, including all files
1261which should be extracted during installation,
1262.Nx
1263disklabel, bootloaders, etc.
1264.Pp
1265The live image is suitable for use as a disk image in
1266virtual machine environments such as QEMU,
1267and also useful to boot
1268.Nx
1269from a USB flash memory stick
1270on a real machine, without the need for installation.
1271.Pp
1272Before
1273.Dq make live-image
1274is attempted, RELEASEDIR must be populated by
1275.Dq make release
1276or equivalent.
1277The build must have been performed with
1278.Sy MKUNPRIVED=yes
1279because
1280.Dq make install-image
1281relies on information in
1282.Sy DESTDIR Ns Pa /METALOG .
1283.
1284.It Sy regression-tests
1285Can only be run after building the regression tests in the directory
1286.Dq regress .
1287Runs those compiled regression tests on the local host.
1288Note that most tests are now managed instead using
1289.Xr atf 7 ;
1290this target should probably run those as well but currently does not.
1291.
1292.El
1293.
1294.Ss The \*qbuild.sh\*q script
1295.
1296This script file is a shell script designed to build the
1297entire
1298.Nx
1299system on any host with a suitable modern shell and some common
1300utilities.
1301The required shell features are described under the
1302.Sy HOST_SH
1303variable.
1304.Pp
1305If a host system's default shell does support the required
1306features, then we suggest that you explicitly specify
1307a suitable shell using a command like
1308.Bd -unfilled -offset indent
1309.Li /path/to/suitable/shell build.sh Op Ar options
1310.Ed
1311.Pp
1312The above command will usually enable
1313.Nm build.sh
1314to automatically set
1315.Sy HOST_SH Ns Cm = Ns Pa /path/to/suitable/shell ,
1316but if that fails, then the following set of commands may be used instead:
1317.Bd -unfilled -offset indent
1318.Li HOST_SH= Ns Va /path/to/suitable/shell
1319.Li export HOST_SH
1320.Li ${HOST_SH} build.sh Op Ar options
1321.Ed
1322.Pp
1323If
1324.Sy build.sh
1325detects that it is being executed under an unsuitable shell, it attempts
1326to exec a suitable shell instead, or prints an error message.
1327If
1328.Sy HOST_SH
1329is not set explicitly, then
1330.Nm build.sh
1331sets a default using heuristics dependent on the host platform,
1332or from the shell under which
1333.Nm build.sh
1334is executed (if that can be determined),
1335or using the first copy of
1336.Pa sh
1337found in
1338.Sy PATH .
1339.Pp
1340All cross-compile builds, and most native builds, of the entire system
1341should make use of
1342.Sy build.sh
1343rather than just running
1344.Dq make .
1345This way, the
1346.Xr make 1
1347program will be bootstrapped properly, in case the host system has an
1348older or incompatible
1349.Dq make
1350program.
1351.Pp
1352When compiling the entire system via
1353.Sy build.sh ,
1354many
1355.Xr make 1
1356variables are set for you in order to help encapsulate the build
1357process.
1358In the list of options below, variables that are automatically set by
1359.Sy build.sh
1360are noted where applicable.
1361.
1362.Pp
1363The following operations are supported by
1364.Sy build.sh :
1365.
1366.Bl -tag -width "distribution"
1367.
1368.It Sy build
1369Build the system as per
1370.Dq make build .
1371Before the main part of the build commences, this command runs the
1372.Sy obj
1373operation (unless the
1374.Fl o
1375option is given),
1376.Dq make cleandir
1377(unless the
1378.Fl u
1379option is given),
1380and the
1381.Sy tools
1382operation.
1383.
1384.It Sy distribution
1385Build a full distribution as per
1386.Dq make distribution .
1387This command first runs the
1388.Sy build
1389operation.
1390.
1391.It Sy release
1392Build a full release as per
1393.Dq make release .
1394This command first runs the
1395.Sy distribution
1396operation.
1397.
1398.It Sy makewrapper
1399Create the
1400.Sy \*[toolprefix]make-MACHINE
1401wrapper.
1402This operation is automatically performed for any of the other
1403operations.
1404.
1405.It Sy cleandir
1406Perform
1407.Dq make cleandir .
1408.
1409.It Sy obj
1410Perform
1411.Dq make obj .
1412.
1413.It Sy tools
1414Build and install the host tools from
1415.Pa src/tools .
1416This command will first run
1417.Dq make obj
1418and
1419.Dq make cleandir
1420in the
1421.Pa tools
1422subdirectory unless the
1423.Fl o
1424or
1425.Fl u
1426options (respectively) are given.
1427.
1428.It Sy install Ns = Ns Ar idir
1429Install the contents of
1430.Sy DESTDIR
1431to
1432.Ar idir ,
1433using
1434.Dq make installworld .
1435Note that files that are part of the
1436.Dq etc
1437or
1438.Dq xetc
1439sets will not be installed, unless overridden by
1440the INSTALLSETS environment variable.
1441.
1442.It Sy kernel Ns = Ns Ar kconf
1443Build a new kernel.
1444The
1445.Ar kconf
1446argument is the name of a configuration file suitable
1447for use by
1448.Xr config 1 .
1449If
1450.Ar kconf
1451does not contain any
1452.Sq /
1453characters, the configuration file is expected to be found in the
1454.Sy KERNCONFDIR
1455directory, which is typically
1456.Pa sys/arch/MACHINE/conf .
1457The new kernel will be built in a subdirectory of
1458.Sy KERNOBJDIR ,
1459which is typically
1460.Pa sys/arch/MACHINE/compile
1461or an associated object directory.
1462.Pp
1463This command does
1464.Em not
1465imply the
1466.Sy tools
1467command; run the
1468.Sy tools
1469command first unless it is
1470.Em certain
1471that the tools already exist and are up to date.
1472.Pp
1473This command will run
1474.Dq make cleandir
1475on the kernel in question first unless the
1476.Fl u
1477option is given.
1478.
1479.It Sy kernel.gdb Ns = Ns Ar kconf
1480Build a new kernel with debug information.
1481Similar to the above
1482.Sy kernel Ns = Ns Ar kconf
1483operation, but creates a
1484.Pa netbsd.gdb
1485file alongside of the kernel
1486.Pa netbsd ,
1487which contains a full symbol table and can be used for debugging
1488(for example with a cross-gdb built by
1489.Sy MKCROSSGDB ) .
1490.It Sy modules
1491This command will build kernel modules and install them into
1492.Sy DESTDIR .
1493.
1494.It Sy releasekernel Ns = Ns Ar kconf
1495Install a
1496.Xr gzip 1 Ns ed
1497copy of the kernel previously built by
1498.Sy kernel Ns = Ns Ar kconf
1499into
1500.Sy RELEASEDIR/RELEASEMACHINEDIR Ns Pa /binary/kernel ,
1501usually as
1502.Pa netbsd- Ns Ar kconf Ns Pa .gz ,
1503although the
1504.Dq Pa netbsd
1505prefix is determined from the
1506.Dq Sy config
1507directives in
1508.Ar kconf .
1509.
1510.It Sy sets
1511Perform
1512.Dq make sets .
1513.
1514.It Sy sourcesets
1515Perform
1516.Dq make sourcesets .
1517.
1518.It Sy syspkgs
1519Perform
1520.Dq make syspkgs .
1521.
1522.It Sy iso-image
1523Perform
1524.Dq make iso-image .
1525.
1526.It Sy iso-image-source
1527Perform
1528.Dq make iso-image-source .
1529.
1530.It Sy install-image
1531Perform
1532.Dq make install-image .
1533.
1534.It Sy live-image
1535Perform
1536.Dq make live-image .
1537.
1538.El
1539.
1540.Pp
1541The following command line options alter the behaviour of the
1542.Sy build.sh
1543operations described above:
1544.
1545.Bl -tag -width "-T tools"
1546.
1547.It Fl a Ar arch
1548Set the value of
1549.Sy MACHINE_ARCH
1550to
1551.Ar arch .
1552.
1553.It Fl B Ar buildid
1554Set the value of
1555.Sy BUILDID
1556to
1557.Ar buildid .
1558This will also append the build identifier to the name of the
1559.Dq make
1560wrapper script so that the resulting name is of the form
1561.Dq Sy \*[toolprefix]make-MACHINE-BUILDID .
1562.
1563.It Fl C Ar cdextras
1564Append
1565.Ar cdextras
1566to the
1567.Sy CDEXTRA
1568variable,
1569which is a space-separated list of files or directories that will be
1570added to the CD-ROM image that may be create by the
1571.Dq iso-image
1572or
1573.Dq iso-image-source
1574operations.
1575Files will be added to the root of the CD-ROM image, whereas directories
1576will be copied recursively.
1577If relative paths are specified, they will be converted to
1578absolute paths before being used.
1579Multiple paths may be specified via multiple
1580.Fl C
1581options, or via a single option whose argument contains multiple
1582space-separated paths.
1583.
1584.It Fl D Ar dest
1585Set the value of
1586.Sy DESTDIR
1587to
1588.Ar dest .
1589If a relative path is specified, it will be converted to an
1590absolute path before being used.
1591.
1592.It Fl E
1593Set
1594.Sq expert
1595mode.
1596This overrides various sanity checks, and allows:
1597.Sy DESTDIR
1598does not have to be set to a non-root path for builds,
1599and
1600.Sy MKUNPRIVED=yes
1601does not have to be set when building as a non-root user.
1602.Pp
1603.Em Note :
1604It is highly recommended that you know what you are doing when
1605you use this option.
1606.
1607.It Fl h
1608Print a help message.
1609.
1610.It Fl j Ar njob
1611Run up to
1612.Ar njob
1613.Xr make 1
1614subjobs in parallel;
1615passed through to
1616.Xr make 1 .
1617If you see failures for reasons other than running out of memory
1618while using
1619.Sy build.sh
1620with
1621.Fl j ,
1622please save complete build logs
1623so the failures can be analyzed.
1624.Pp
1625To achieve the fastest builds,
1626.Fl j
1627values between (1 + the number of CPUs) and (2 * the number of CPUs)
1628are recommended.
1629Use lower values on machines with limited memory or I/O bandwidth.
1630.
1631.It Fl M Ar obj
1632Set
1633.Sy MAKEOBJDIRPREFIX
1634to
1635.Ar obj .
1636Unsets
1637.Sy MAKEOBJDIR .
1638See
1639.Dq Fl O Ar obj
1640for more information.
1641.Pp
1642For instance, if the source directory is
1643.Pa /usr/src ,
1644a setting of
1645.Dq Fl M Pa /usr/obj
1646will place build-time files under
1647.Pa /usr/obj/usr/src/bin ,
1648.Pa /usr/obj/usr/src/lib ,
1649.Pa /usr/obj/usr/src/usr.bin ,
1650and so forth.
1651.Pp
1652If a relative path is specified, it will be converted to an
1653absolute path before being used.
1654.Sy build.sh
1655imposes the restriction that the argument to the
1656.Fl M
1657option must not begin with a
1658.Dq \&$
1659(dollar sign)
1660character; otherwise it would be too difficult
1661to determine whether the value is an absolute or a relative path.
1662If the directory does not already exist,
1663.Sy build.sh
1664will create it.
1665.
1666.It Fl m Ar mach
1667Set the value of
1668.Sy MACHINE
1669to
1670.Ar mach ,
1671except in some special cases listed below.
1672This will also override any value of
1673.Sy MACHINE_ARCH
1674in the process environment with a value deduced from
1675.Ar mach ,
1676unless
1677.Fl a
1678is specified.
1679All cross builds require
1680.Fl m ,
1681but if unset on a NetBSD host, the host's value of MACHINE will be
1682detected and used automatically.
1683.Pp
1684Some machines support multiple values for
1685.Sy MACHINE_ARCH .
1686The following special cases for the
1687.Ar mach
1688argument are defined to set the listed values of
1689.Sy MACHINE
1690and
1691.Sy MACHINE_ARCH :
1692.Bl -column "evbmips-el" "MACHINE" "MACHINE_ARCH" -offset indent
1693.It Sy mach Ta Sy "MACHINE" Ta Sy "MACHINE_ARCH"
1694.It evbarm Ta evbarm Ta (not set)
1695.It evbarm-eb Ta evbarm Ta armeb
1696.It evbarm-el Ta evbarm Ta arm
1697.It evbmips Ta evbmips Ta (not set)
1698.It evbmips-eb Ta evbmips Ta mipseb
1699.It evbmips-el Ta evbmips Ta mipsel
1700.It evbsh3 Ta evbsh3 Ta (not set)
1701.It evbsh3-eb Ta evbsh3 Ta sh3eb
1702.It evbsh3-el Ta evbsh3 Ta sh3el
1703.It sbmips Ta sbmips Ta (not set)
1704.It sbmips-eb Ta sbmips Ta mipseb
1705.It sbmips-el Ta sbmips Ta mipsel
1706.El
1707.
1708.It Fl N Ar noiselevel
1709Set the
1710.Dq noisyness
1711level of the build, by setting
1712.Sy MAKEVERBOSE
1713to
1714.Ar noiselevel .
1715.
1716.It Fl n
1717Show the commands that would be executed by
1718.Sy build.sh ,
1719but do not make any changes.
1720This is similar in concept to
1721.Dq make -n .
1722.
1723.It Fl O Ar obj
1724Create an appropriate transform macro for
1725.Sy MAKEOBJDIR
1726that will place the built object files under
1727.Ar obj .
1728Unsets
1729.Sy MAKEOBJDIRPREFIX .
1730.Pp
1731For instance, a setting of
1732.Dq Fl O Pa /usr/obj
1733will place build-time files under
1734.Pa /usr/obj/bin ,
1735.Pa /usr/obj/lib ,
1736.Pa /usr/obj/usr.bin ,
1737and so forth.
1738.Pp
1739If a relative path is specified, it will be converted to an
1740absolute path before being used.
1741.Sy build.sh
1742imposes the restriction that the argument to the
1743.Fl O
1744option must not contain a
1745.Dq \&$
1746(dollar sign)
1747character.
1748If the directory does not already exist,
1749.Sy build.sh
1750will create it.
1751.Pp
1752In normal use, exactly one of the
1753.Fl M
1754or
1755.Fl O
1756options should be specified.
1757If neither
1758.Fl M
1759nor
1760.Fl O
1761is specified, then a default object directory will be chosen
1762according to rules in
1763.Aq bsd.obj.mk .
1764Relying on this default is not recommended because
1765it is determined by complex rules that are influenced
1766by the values of several variables and
1767by the location of the source directory.
1768.It Fl o
1769Set the value of
1770.Sy MKOBJDIRS
1771to
1772.Dq no .
1773Otherwise, it will be automatically set to
1774.Dq yes .
1775This default is opposite to the behaviour when not using
1776.Sy build.sh .
1777.
1778.It Fl R Ar rel
1779Set the value of
1780.Sy RELEASEDIR
1781to
1782.Ar rel .
1783If a relative path is specified, it will be converted to an
1784absolute path before being used.
1785.
1786.It Fl r
1787Remove the contents of
1788.Sy DESTDIR
1789and
1790.Sy TOOLDIR
1791before building (provides a clean starting point).
1792This will skip deleting
1793.Sy DESTDIR
1794if building on a native system to the root directory.
1795.
1796.It Fl S Ar seed
1797Change the value of
1798.Sy BUILDSEED
1799to
1800.Ar seed .
1801This should rarely be necessary.
1802.
1803.It Fl T Ar tools
1804Set the value of
1805.Sy TOOLDIR
1806to
1807.Ar tools .
1808If a relative path is specified, it will be converted to an
1809absolute path before being used.
1810If set, the bootstrap
1811.Dq make
1812will only be rebuilt if the source files for
1813.Xr make 1
1814have changed.
1815.
1816.It Fl U
1817Set
1818.Sy MKUNPRIVED=yes .
1819.
1820.It Fl u
1821Set
1822.Sy MKUPDATE=yes .
1823.
1824.It Xo
1825.Fl V
1826.Sm off
1827.Ar var
1828.Li =
1829.Op Ar value
1830.Sm on
1831.Xc
1832Set the environment variable
1833.Ar var
1834to an optional
1835.Ar value .
1836This is propagated to the
1837.Sy \*[toolprefix]make
1838wrapper.
1839.
1840.It Fl w Ar wrapper
1841Create the
1842.Sy \*[toolprefix]make
1843wrapper script (see below) in a custom location,
1844specified by
1845.Ar wrapper .
1846This allows, for instance, to place the wrapper in
1847.Sy PATH
1848automatically.
1849Note that
1850.Ar wrapper
1851is the full name of the file, not just a directory name.
1852If a relative path is specified, it will be converted to an
1853absolute path before being used.
1854.
1855.It Fl X Ar x11src
1856Set the value of
1857.Sy X11SRCDIR
1858to
1859.Ar x11src .
1860If a relative path is specified, it will be converted to an
1861absolute path before being used.
1862.
1863.It Fl x
1864Set
1865.Sy MKX11=yes .
1866.
1867.It Fl Z Ar var
1868Unset ("zap") the environment variable
1869.Ar var .
1870This is propagated to the
1871.Sy \*[toolprefix]make
1872wrapper.
1873.
1874.El
1875.
1876.Ss The \*q\*[toolprefix]make-MACHINE\*q wrapper script
1877.
1878If using the
1879.Sy build.sh
1880script to build
1881.Nx ,
1882a
1883.Sy \*[toolprefix]make-MACHINE
1884script will be created in
1885.Sy TOOLDIR Ns Pa /bin
1886upon the first build to assist in building subtrees on a cross-compile
1887host.
1888.Pp
1889.Sy \*[toolprefix]make-MACHINE
1890can be invoked in lieu of
1891.Xr make 1 ,
1892and will instead call the up-to-date version of
1893.Dq \*[toolprefix]make
1894installed into
1895.Sy TOOLDIR Ns Pa /bin
1896with several key variables pre-set, including
1897.Sy MACHINE , MACHINE_ARCH ,
1898and
1899.Sy TOOLDIR .
1900.Sy \*[toolprefix]make-MACHINE
1901will also set variables specified with
1902.Fl V ,
1903and unset variables specified with
1904.Fl Z .
1905.Pp
1906This script can be symlinked into a directory listed in
1907.Sy PATH ,
1908or called with an absolute path.
1909.
1910.Sh EXAMPLES
1911.
1912.Bl -enum
1913.
1914.It
1915.Li "% ./build.sh [options] tools kernel=GENERIC"
1916.Pp
1917Build a new toolchain, and use the new toolchain to
1918configure and build a new GENERIC kernel.
1919.
1920.It
1921.Li "% ./build.sh [options] -U distribution"
1922.Pp
1923Using unprivileged mode,
1924build a complete distribution to a
1925.Sy DESTDIR
1926directory that
1927.Sy build.sh
1928selects (and will display).
1929.
1930.It
1931.Li "# ./build.sh [options] -U install=/"
1932.Pp
1933As root, install to
1934.Pa /
1935the distribution that was built
1936by example 2.
1937Even though this is run as root,
1938.Fl U
1939is required so that the permissions stored in
1940.Sy DESTDIR Ns Pa /METALOG
1941are correctly applied to the files as they're copied to
1942.Pa / .
1943.
1944.It
1945.Li "% ./build.sh [options] -U -u release"
1946.Pp
1947Using unprivileged mode,
1948build a complete release to
1949.Sy DESTDIR
1950and
1951.Sy RELEASEDIR
1952directories that
1953.Sy build.sh
1954selects (and will display).
1955.Sy MKUPDATE=yes
1956.Pq Fl u
1957is set to prevent the
1958.Dq make cleandir ,
1959so that if this is run after example 2, it doesn't need to redo that
1960portion of the release build.
1961.El
1962.
1963.Sh OBSOLETE VARIABLES
1964.
1965.Bl -tag -width "NBUILDJOBS"
1966.
1967.It Sy NBUILDJOBS
1968Use the
1969.Xr make 1
1970option
1971.Fl j
1972instead.
1973.
1974.It Sy USE_NEW_TOOLCHAIN
1975The new toolchain is now the default.
1976To disable, use
1977.Sy TOOLCHAIN_MISSING=yes .
1978.El
1979.Sh SEE ALSO
1980.Xr make 1 ,
1981.Xr hier 7 ,
1982.Xr release 7 ,
1983.Xr etcupdate 8 ,
1984.Xr postinstall 8 ,
1985.Xr sysinst 8 ,
1986.Pa pkgsrc/sysutils/cdrtools
1987.
1988.Sh HISTORY
1989.
1990The
1991.Nm build.sh
1992based build scheme was introduced for
1993.Nx 1.6
1994as
1995.Sy USE_NEW_TOOLCHAIN ,
1996and re-worked to
1997.Sy TOOLCHAIN_MISSING
1998after that.
1999