xref: /freebsd/share/man/man7/build.7 (revision 046c625e9382e17da953767b881aaa782fa73af8)
1.\"
2.\" SPDX-License-Identifier: BSD-2-Clause
3.\"
4.\" Copyright (c) 2000
5.\"	Mike W. Meyer
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd September 25, 2025
29.Dt BUILD 7
30.Os
31.Sh NAME
32.Nm build
33.Nd general instructions on how to build the
34.Fx
35system
36.Sh DESCRIPTION
37The sources for the
38.Fx
39system and its applications are contained in three directories,
40normally:
41.Bl -tag -width "/usr/ports"
42.It Pa /usr/src
43.Dq base system ,
44loosely defined as everything required to build the system
45to a useful state
46.It Pa /usr/doc
47system documentation, excluding manual pages
48.It Pa /usr/ports
49third-party software, with a consistent interface for building and
50installing them; see
51.Xr ports 7
52.El
53.Pp
54These directories may be initially empty or non-existent until updated
55with Git
56.Po Pa devel/git
57from the
58.Fx
59Ports Collection
60.Pc .
61.Pp
62The
63.Xr make 1
64command is used in each of these directories to build and install the
65things in that directory.
66Issuing the
67.Xr make 1
68command in any directory issues the
69.Xr make 1
70command recursively in all subdirectories.
71With no target specified, the items in the directories are built
72and no further action is taken.
73.Pp
74A source tree is allowed to be read-only.
75As described in
76.Xr make 1 ,
77objects are usually built in a separate object directory hierarchy
78specified by the environment variable
79.Va MAKEOBJDIRPREFIX ,
80or under
81.Pa /usr/obj
82if variable
83.Va MAKEOBJDIRPREFIX
84is not set.
85The canonical object directory is described in the documentation for the
86.Cm buildworld
87target below.
88.Pp
89The
90.Nm
91may be controlled by defining
92.Xr make 1
93variables described in the
94.Sx ENVIRONMENT
95section below, and by the variables documented in
96.Xr make.conf 5 .
97.Pp
98The default components included in the build are specified in the file
99.Pa /etc/src.conf
100in the source tree.
101To override the default file, include the SRCCONF option in the make steps,
102pointing to a custom src.conf file.
103For more information see
104.Xr src.conf 5 .
105.Pp
106The following list provides the names and actions for the targets
107supported by the build system:
108.Bl -tag -width ".Cm cleandepend"
109.It Cm analyze
110Run Clang static analyzer against all objects and present output on stdout.
111.It Cm check
112Run tests for a given subdirectory.
113The default directory used is
114.Pa ${.OBJDIR} ,
115but the check directory can be changed with
116.Pa ${CHECKDIR} .
117.It Cm checkworld
118Run the
119.Fx
120test suite on installed world.
121.It Cm clean
122Remove any files created during the build process.
123.It Cm cleandepend
124Remove the
125.Pa ${.OBJDIR}/${DEPENDFILE}*
126files generated by prior
127.Dq Li "make"
128and
129.Dq Li "make depend"
130steps.
131.It Cm cleandir
132Remove the canonical object directory if it exists, or perform
133actions equivalent to
134.Dq Li "make clean cleandepend"
135if it does not.
136This target will also remove an
137.Pa obj
138link in
139.Pa ${.CURDIR}
140if that exists.
141.Pp
142It is advisable to run
143.Dq Li "make cleandir"
144twice: the first invocation will remove the canonical object directory
145and the second one will clean up
146.Pa ${.CURDIR} .
147.It Cm depend
148Generate a list of build dependencies in file
149.Pa ${.OBJDIR}/${DEPENDFILE} .
150Per-object dependencies are generated at build time and stored in
151.Pa ${.OBJDIR}/${DEPENDFILE}.${OBJ} .
152.It Cm install
153Install the results of the build to the appropriate location in the
154installation directory hierarchy specified in variable
155.Va DESTDIR .
156.It Cm obj
157Create the canonical object directory associated with the current
158directory.
159.It Cm objlink
160Create a symbolic link to the canonical object directory in
161.Pa ${.CURDIR} .
162.It Cm tags
163Generate a tags file using the program specified in the
164.Xr make 1
165variable
166.Va CTAGS .
167The build system supports
168.Xr ctags 1
169and
170.Nm "GNU Global" .
171.El
172.Pp
173The other supported targets under directory
174.Pa /usr/src
175are:
176.Bl -tag -width ".Cm distributeworld"
177.It Cm buildenv
178Spawn an interactive shell with environment variables set up for
179building the system or individual components.
180For cross-building the target architecture needs to be specified with
181.Xr make 1
182variables
183.Va TARGET_ARCH
184and
185.Va TARGET .
186.Pp
187This target is only useful after a complete toolchain (including
188the compiler, linker, assembler, headers and libraries) has been
189built; see the
190.Cm toolchain
191target below.
192.Pp
193.Va BUILDENV_SHELL ,
194which defaults to
195.Pa /bin/sh ,
196is executed.
197This can be set to a command that does something in this build environment,
198like cross build an application.
199If that application has dependencies, though, the
200.Pa devel/poudriere
201package or port provides a more generic solution.
202.It Cm buildenvvars
203Print the shell variables that are set for a
204.Cm buildenv
205envirnoment and exit.
206.It Cm buildworld
207Build everything but the kernel, configure files in
208.Pa etc ,
209and
210.Pa release .
211The object directory can be changed from the default
212.Pa /usr/obj
213by setting the
214.Pa MAKEOBJDIRPREFIX
215.Xr make 1
216variable.
217The actual build location prefix used
218depends on the
219.Va WITH_UNIFIED_OBJDIR
220option from
221.Xr src.conf 5 .
222If enabled it is
223.Pa ${MAKEOBJDIRPREFIX}${.CURDIR}/${TARGET}.${TARGET_ARCH}
224for all builds.
225If disabled it is
226.Pa ${MAKEOBJDIRPREFIX}${.CURDIR}
227for native builds, and
228.Pa ${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}${.CURDIR}
229for cross builds and native builds with variable
230.Va CROSS_BUILD_TESTING
231set.
232.It Cm cleankernel
233Attempts to clean up targets built by a preceding
234.Cm buildkernel ,
235or similar step, built from the same source directory and
236.Va KERNCONF .
237.It Cm cleanworld
238Attempt to clean up targets built by a preceding
239.Cm buildworld ,
240or similar step, built from this source directory.
241.It Cm cleanuniverse
242When
243.Va WITH_UNIFIED_OBJDIR
244is enabled, attempt to clean up targets built by a preceding
245.Cm buildworld ,
246.Cm universe ,
247or similar step, for any architecture built from this source directory.
248.It Cm distributeworld
249Distribute everything compiled by a preceding
250.Cm buildworld
251step.
252Files are placed in the directory hierarchy specified by
253.Xr make 1
254variable
255.Va DISTDIR .
256This target is used while building a release; see
257.Xr release 7 .
258.It Cm native-xtools
259This target builds a cross-toolchain for the given
260.Sy TARGET
261and
262.Sy TARGET_ARCH ,
263as well as a select list of static userland tools for the host system.
264This is intended to be used in a jail where QEMU is used to improve
265performance by avoiding emulating binaries that do not need to be emulated.
266.Sy TARGET
267and
268.Sy TARGET_ARCH
269should be defined.
270.It Cm native-xtools-install
271Installs the results to
272.Pa ${DESTDIR}/${NXTP}
273where
274.Va NXTP
275defaults to
276.Pa nxb-bin .
277.Sy TARGET
278and
279.Sy TARGET_ARCH
280must be defined.
281.It Cm packages
282Create a
283.Xr freebsd-base 7
284package repository containing packages that can be
285used to install or upgrade the base system.
286The repository is created in the object directory, under
287.Pa ${REPODIR}/${PKG_ABI}
288where
289.Ev REPODIR
290is the base directory where the repository will be created, and
291.Va PKG_ABI
292is the
293.Xr pkg 7
294ABI for the build target, for example,
295.Pa /usr/obj/${SRCDIR}/repo/FreeBSD:15:amd64 .
296.It Cm packageworld
297Archive the results of
298.Cm distributeworld ,
299placing the results in
300.Va DISTDIR .
301This target is used while building a
302.Xr release 7
303and is unrelated to building
304.Xr freebsd-base 7
305packages.
306.It Cm installworld
307Install everything built by a preceding
308.Cm buildworld
309step into the directory hierarchy pointed to by
310.Xr make 1
311variable
312.Va DESTDIR .
313.Pp
314If installing onto an NFS file system and running
315.Xr make 1
316with the
317.Fl j
318option, make sure that
319.Xr rpc.lockd 8
320is running on both client and server.
321See
322.Xr rc.conf 5
323on how to make it start at boot time.
324.It Cm toolchain
325Create the build toolchain needed to build the rest of the system.
326For cross-architecture builds, this step creates a cross-toolchain.
327.It Cm universe
328For each architecture,
329execute a
330.Cm buildworld
331followed by a
332.Cm buildkernel
333for all kernels for that architecture,
334including
335.Pa LINT .
336This command takes a long time.
337.It Cm kernels
338Like
339.Cm universe
340with
341.Va WITHOUT_WORLDS
342defined so only the kernels for each architecture are built.
343.It Cm worlds
344Like
345.Cm universe
346with
347.Va WITHOUT_KERNELS
348defined so only the worlds for each architecture are built.
349.It Cm targets
350Print a list of supported
351.Va TARGET
352/
353.Va TARGET_ARCH
354pairs for world and kernel targets.
355.It Cm tinderbox
356Execute the same targets as
357.Cm universe .
358In addition print a summary of all failed targets at the end and
359exit with an error if there were any.
360.It Cm toolchains
361Create a build toolchain for each architecture supported by the build system.
362.It Cm xdev
363Builds and installs a cross-toolchain and sysroot for the given
364.Sy TARGET
365and
366.Sy TARGET_ARCH .
367The sysroot contains target library and headers.
368The target is an alias for
369.Cm xdev-build
370and
371.Cm xdev-install .
372The location of the files installed can be controlled with
373.Va DESTDIR .
374The target location in
375.Va DESTDIR
376is
377.Pa ${DESTDIR}/${XDTP}
378where
379.Va XDTP
380defaults to
381.Pa /usr/${XDDIR}
382and
383.Va XDDIR
384defaults to
385.Pa ${TARGET_ARCH}-freebsd .
386.It Cm update-packages
387Create or update the
388.Xr freebsd-base 7
389package repository for the base system.
390If an old repository is being updated,
391then packages whose contents have not changed since the previous version
392will be copied into the new repository to avoid needless updating of the
393version number.
394.It Cm xdev-build
395Builds for the
396.Cm xdev
397target.
398.It Cm xdev-install
399Installs the files for the
400.Cm xdev
401target.
402.It Cm xdev-links
403Installs autoconf-style symlinks to
404.Pa ${DESTDIR}/usr/bin
405pointing into the xdev toolchain in
406.Pa ${DESTDIR}/${XDTP} .
407.El
408.Pp
409Kernel specific build targets in
410.Pa /usr/src
411are:
412.Bl -tag -width ".Cm distributekernel"
413.It Cm buildkernel
414Rebuild the kernel and the kernel modules.
415The object directory can be changed from the default
416.Pa /usr/obj
417by setting the
418.Pa MAKEOBJDIRPREFIX
419.Xr make 1
420variable.
421.It Cm installkernel
422Install the kernel and the kernel modules to directory
423.Pa ${DESTDIR}/boot/kernel ,
424renaming any pre-existing directory with this name to
425.Pa kernel.old
426if it contained the currently running kernel.
427The target directory under
428.Pa ${DESTDIR}
429may be modified using the
430.Va INSTKERNNAME
431or
432.Va KODIR
433.Xr make 1
434variables.
435.It Cm distributekernel
436Install the kernel to the directory
437.Pa ${DISTDIR}/kernel/boot/kernel .
438This target is used while building a release; see
439.Xr release 7 .
440.It Cm packagekernel
441Archive the results of
442.Cm distributekernel ,
443placing the results in
444.Va DISTDIR .
445This target is used while building a
446.Xr release 7
447and is unrelated to building
448.Xr freebsd-base 7
449packages.
450.It Cm kernel
451Equivalent to
452.Cm buildkernel
453followed by
454.Cm installkernel
455.It Cm kernel-toolchain
456Rebuild the tools needed for kernel compilation.
457Use this if you did not do a
458.Cm buildworld
459first.
460.It Cm reinstallkernel
461Reinstall the kernel and the kernel modules, overwriting the contents
462of the target directory.
463As with the
464.Cm installkernel
465target, the target directory can be specified using the
466.Xr make 1
467variable
468.Va INSTKERNNAME .
469.El
470.Pp
471Convenience targets for cleaning up the install destination directory
472denoted by variable
473.Va DESTDIR
474include:
475.Bl -tag -width ".Cm delete-old-libs"
476.It Cm check-old
477Print a list of old files and directories in the system.
478.It Cm check-old-libs
479Print a list of obsolete base system libraries.
480.It Cm delete-old
481Delete obsolete base system files and directories interactively.
482When
483.Li -DBATCH_DELETE_OLD_FILES
484is specified at the command line, the delete operation will be
485non-interactive.
486The variables
487.Va DESTDIR ,
488.Va TARGET_ARCH
489and
490.Va TARGET
491should be set as with
492.Dq Li "make installworld" .
493.It Cm delete-old-libs
494Delete obsolete base system libraries interactively.
495This target should only be used if no third party software uses these
496libraries.
497When
498.Li -DBATCH_DELETE_OLD_FILES
499is specified at the command line, the delete operation will be
500non-interactive.
501The variables
502.Va DESTDIR ,
503.Va TARGET_ARCH
504and
505.Va TARGET
506should be set as with
507.Dq Li "make installworld" .
508.El
509.Sh ENVIRONMENT
510Variables that influence all builds include:
511.Bl -tag -width ".Va MAKEOBJDIRPREFIX"
512.It Va DEBUG_FLAGS
513Defines a set of debugging flags that will be used to build all userland
514binaries under
515.Pa /usr/src .
516When
517.Va DEBUG_FLAGS
518is defined, the
519.Cm install
520and
521.Cm installworld
522targets install binaries from the current
523.Va MAKEOBJDIRPREFIX
524without stripping,
525so that debugging information is retained in the installed binaries.
526.It Va DESTDIR
527The directory hierarchy prefix where built objects will be installed.
528If not set,
529.Va DESTDIR
530defaults to the empty string.
531If set,
532.Va DESTDIR
533must specify an absolute path.
534.It Va MAKEOBJDIRPREFIX
535Defines the prefix for directory names in the tree of built objects.
536Defaults to
537.Pa /usr/obj
538if not defined.
539This variable should only be set in the environment or
540.Pa /etc/src-env.conf
541and not via
542.Pa /etc/make.conf
543or
544.Pa /etc/src.conf
545or the command line.
546.Va MAKEOBJDIRPREFIX
547must specify an absolute path.
548.It Va WITHOUT_WERROR
549If defined, compiler warnings will not cause the build to halt,
550even if the makefile says otherwise.
551.It Va WITH_CTF
552If defined, the build process will run the DTrace CTF conversion
553tools on built objects.
554.El
555.Pp
556Additionally, builds in
557.Pa /usr/src
558are influenced by the following
559.Xr make 1
560variables:
561.Bl -tag -width ".Va LOCAL_MODULES_DIR"
562.It Va CROSS_TOOLCHAIN
563Requests use of an external toolchain to build either the world or kernel.
564This value of this variable can either be the full path to a file,
565or the base name of a file in
566.Pa ${LOCALBASE}/share/toolchains .
567The file should be a make file which sets variables to request an external
568toolchain such as
569.Va XCC .
570.Pp
571External toolchains are available in ports for both LLVM and GCC/binutils.
572For external toolchains available in ports,
573.Va CROSS_TOOLCHAIN
574should be set to the name of the package.
575LLVM toolchain packages use the name llvm<major version>.
576GCC toolchains provide separate packages for each architecture and use the
577name ${MACHINE_ARCH}-gcc<major version>.
578.It Va INSTKERNNAME
579If set, specify an alternative name to build and install for the various
580kernel make targets.
581.It Va KERNCONF
582Overrides which kernel to build and install for the various kernel
583make targets.
584It defaults to
585.Cm GENERIC .
586.It Va KERNBUILDDIR
587Overrides the default directory to get all the opt_*.h files for
588building a kernel module.
589Useful for stand-alone modules that depend on
590.Xr config 8
591options.
592Automatically set for modules built with a kernel.
593.It Va KERNCONFDIR
594Overrides the directory in which
595.Va KERNCONF
596and any files included by
597.Va KERNCONF
598should be found.
599Defaults to
600.Pa sys/${ARCH}/conf .
601.It Va KERNFAST
602If set, the build target
603.Cm buildkernel
604defaults to setting
605.Va NO_KERNELCLEAN ,
606.Va NO_KERNELCONFIG ,
607and
608.Va NO_KERNELOBJ .
609When set to a value other than
610.Cm 1
611then
612.Va KERNCONF
613is set to the value of
614.Va KERNFAST .
615.It Va KODIR
616If set,
617this variable specifies an alternative directory to install the kernel.
618.It Va LOCAL_DIRS
619If set, this variable supplies a list of additional directories relative to
620the root of the source tree to build as part of the
621.Cm everything
622target.
623The directories are built in parallel with each other,
624and with the base system directories.
625Insert a
626.Va .WAIT
627directive at the beginning of the
628.Va LOCAL_DIRS
629list to ensure all base system directories are built first.
630.Va .WAIT
631may also be used as needed elsewhere within the list.
632.It Va LOCAL_ITOOLS
633If set, this variable supplies a list of additional tools that are used by the
634.Cm installworld
635and
636.Cm distributeworld
637targets.
638.It Va LOCAL_LIB_DIRS
639If set, this variable supplies a list of additional directories relative to
640the root of the source tree to build as part of the
641.Cm libraries
642target.
643The directories are built in parallel with each other,
644and with the base system libraries.
645Insert a
646.Va .WAIT
647directive at the beginning of the
648.Va LOCAL_DIRS
649list to ensure all base system libraries are built first.
650.Va .WAIT
651may also be used as needed elsewhere within the list.
652.It Va LOCAL_MTREE
653If set, this variable supplies a list of additional mtrees relative to the
654root of the source tree to use as part of the
655.Cm hierarchy
656target.
657.It Va LOCAL_LEGACY_DIRS
658If set, this variable supplies a list of additional directories relative to
659the root of the source tree to build as part of the
660.Cm legacy
661target.
662.It Va LOCAL_BSTOOL_DIRS
663If set, this variable supplies a list of additional directories relative to
664the root of the source tree to build as part of the
665.Cm bootstrap-tools
666target.
667.It Va LOCAL_TOOL_DIRS
668If set, this variable supplies a list of additional directories relative to
669the root of the source tree to build as part of the
670.Cm build-tools
671target.
672.It Va LOCAL_XTOOL_DIRS
673If set, this variable supplies a list of additional directories relative to
674the root of the source tree to build as part of the
675.Cm cross-tools
676target.
677.It Va OBJROOT
678The object directory root is defined as
679.Pa ${OBJDIR}/${SRCDIR}/ .
680See
681.Pa share/mk/src.sys.obj.mk .
682.It Va PKG_FORMAT
683Specify a package compression format when building
684.Xr freebsd-base 7
685packages.
686Default:
687.Ql tzst .
688Consider using
689.Ql tar
690to disable compression.
691Accepted options are documented in the
692.Fl f
693description of
694.Xr pkg-create 8 .
695.It Va PORTS_MODULES
696A list of ports with kernel modules that should be built and installed
697as part of the
698.Cm buildkernel
699and
700.Cm installkernel
701process.
702This is currently incompatible with building
703.Xr freebsd-base 7
704packages.
705Each port must be specified as
706.Ar category Ns Li / Ns Ar port Ns Op Li @ Ns Ar flavor ,
707e.g.
708.Bd -literal
709PORTS_MODULES=graphics/gpu-firmware-intel-kmod@kabylake
710PORTS_MODULES+=graphics/drm-66-kmod
711.Ed
712.It Va LOCAL_MODULES
713A list of external kernel modules that should be built and installed
714as part of the
715.Cm buildkernel
716and
717.Cm installkernel
718process.
719Defaults to the list of sub-directories of
720.Va LOCAL_MODULES_DIR .
721.It Va LOCAL_MODULES_DIR
722The directory in which to search for the kernel modules specified by
723.Va LOCAL_MODULES .
724Each kernel module should consist of a directory containing a makefile.
725Defaults to
726.Pa ${LOCALBASE}/sys/modules .
727.It Va SRCCONF
728Specify a file to override the default
729.Pa /etc/src.conf .
730The src.conf file controls the components to build.
731See
732.Xr src.conf 5
733.It Va REPODIR
734The root directory used to create the package repository for building
735.Xr packges 7 .
736Defaults to
737.Pa ${OBJROOT}/repo/ .
738This can also be set in
739.Xr src-env.conf 5 .
740.It Va STRIPBIN
741Command to use at install time when stripping binaries.
742Be sure to add any additional tools required to run
743.Va STRIPBIN
744to the
745.Va LOCAL_ITOOLS
746.Xr make 1
747variable before running the
748.Cm distributeworld
749or
750.Cm installworld
751targets.
752See
753.Xr install 1
754for more details.
755.It Va SUBDIR_OVERRIDE
756Override the default list of sub-directories and only build the
757sub-directory named in this variable.
758If combined with
759.Cm buildworld
760then all libraries and includes, and some of the build tools will still build
761as well.
762Specifying
763.Cm -DNO_LIBS ,
764and
765.Cm -DWORLDFAST
766will only build the specified directory as was done historically.
767When combined with
768.Cm buildworld
769it is necessary to override
770.Va LOCAL_LIB_DIRS
771with any custom directories containing libraries.
772This allows building a subset of the system in the same way as
773.Cm buildworld
774does using its sysroot handling.
775This variable can also be useful when debugging failed builds.
776.Bd -literal -offset indent
777make some-target SUBDIR_OVERRIDE=foo/bar
778.Ed
779.It Va SYSDIR
780Specify the location of the kernel source to override the default
781.Pa /usr/src/sys .
782The kernel source is located in the
783.Pa sys
784subdirectory of the source tree checked out from the
785.Pa src.git
786repository.
787.It Va TARGET
788The target hardware platform.
789This is analogous to the
790.Dq Nm uname Fl m
791output.
792This is necessary to cross-build some target architectures.
793For example, cross-building for ARM64 machines requires
794.Va TARGET_ARCH Ns = Ns Li aarch64
795and
796.Va TARGET Ns = Ns Li arm64 .
797If not set,
798.Va TARGET
799defaults to the current hardware platform, unless
800.Va TARGET_ARCH
801is also set, in which case it defaults to the appropriate
802value for that architecture.
803.It Va TARGET_ARCH
804The target machine processor architecture.
805This is analogous to the
806.Dq Nm uname Fl p
807output.
808Set this to cross-build for a different architecture.
809If not set,
810.Va TARGET_ARCH
811defaults to the current machine architecture, unless
812.Va TARGET
813is also set, in which case it defaults to the appropriate
814value for that platform.
815Typically, one only needs to set
816.Va TARGET .
817.El
818.Pp
819Builds under directory
820.Pa /usr/src
821are also influenced by defining one or more of the following symbols,
822using the
823.Fl D
824option of
825.Xr make 1 :
826.Bl -tag -width ".Va LOADER_DEFAULT_INTERP"
827.It Va LOADER_DEFAULT_INTERP
828Defines what interpreter the default loader program will have.
829Valid values include
830.Dq 4th ,
831.Dq lua ,
832and
833.Dq simp .
834This creates the default link for
835.Pa /boot/loader
836to the loader with that interpreter.
837It also determines what interpreter is compiled into
838.Pa userboot .
839.It Va NO_CLEANDIR
840If set, the build targets that clean parts of the object tree use the
841equivalent of
842.Dq make clean
843instead of
844.Dq make cleandir .
845.It Va NO_CLEAN
846If set, no object tree files are cleaned at all.
847This is the default when
848.Va WITH_META_MODE
849is used with
850.Xr filemon 4
851loaded.
852See
853.Xr src.conf 5
854for more details.
855Setting
856.Va NO_CLEAN
857implies
858.Va NO_KERNELCLEAN ,
859so when
860.Va NO_CLEAN
861is set no kernel objects are cleaned either.
862.It Va NO_CTF
863If set, the build process does not run the DTrace CTF conversion tools
864on built objects.
865.It Va NO_SHARE
866If set, the build does not descend into the
867.Pa /usr/src/share
868subdirectory (i.e., manual pages, locale data files, timezone data files and
869other
870.Pa /usr/src/share
871files will not be rebuild from their sources).
872.It Va NO_KERNELCLEAN
873If set, the build process does not run
874.Dq make clean
875as part of the
876.Cm buildkernel
877target.
878.It Va NO_KERNELCONFIG
879If set, the build process does not run
880.Xr config 8
881as part of the
882.Cm buildkernel
883target.
884.It Va NO_KERNELOBJ
885If set, the build process does not run
886.Dq make obj
887as part of the
888.Cm buildkernel
889target.
890.It Va NO_LIBS
891If set, the libraries phase will be skipped.
892.It Va NO_OBJWALK
893If set, no object directories will be created.
894This should only be used if object directories were created in a
895previous build and no new directories are connected.
896.It Va UNIVERSE_TOOLCHAIN
897Requests use of the toolchain built as part of the
898.Cm universe
899target as an external toolchain.
900.It Va WORLDFAST
901If set, the build target
902.Cm buildworld
903defaults to setting
904.Va NO_CLEAN ,
905.Va NO_OBJWALK ,
906and will skip most bootstrap phases.
907It will only bootstrap libraries and build all of userland.
908This option should be used only when it is known that none of the bootstrap
909needs changed and that no new directories have been connected to the build.
910.El
911.Pp
912Builds under directory
913.Pa /usr/doc
914are influenced by the following
915.Xr make 1
916variables:
917.Bl -tag -width ".Va DOC_LANG"
918.It Va DOC_LANG
919If set, restricts the documentation build to the language subdirectories
920specified as its content.
921The default action is to build documentation for all languages.
922.El
923.Pp
924Builds using the
925.Cm universe
926and related targets are influenced by the following
927.Xr make 1
928variables:
929.Bl -tag -width ".Va USE_GCC_TOOLCHAINS"
930.It Va JFLAG
931Pass the value of this variable to each
932.Xr make 1
933invocation used to build worlds and kernels.
934This can be used to enable multiple jobs within a single architecture's build
935while still building each architecture serially.
936.It Va MAKE_JUST_KERNELS
937Only build kernels for each supported architecture.
938.It Va MAKE_JUST_WORLDS
939Only build worlds for each supported architecture.
940.It Va WITHOUT_WORLDS
941Only build kernels for each supported architecture.
942.It Va WITHOUT_KERNELS
943Only build worlds for each supported architecture.
944.It Va UNIVERSE_TARGET
945Execute the specified
946.Xr make 1
947target for each supported architecture instead of the default action of
948building a world and one or more kernels.
949This variable implies
950.Va WITHOUT_KERNELS .
951.It Va USE_GCC_TOOLCHAINS
952Use external GCC toolchains to build the requested targets.
953If the required toolchain package for a supported architecture is not installed,
954the build for that architecture is skipped.
955.Pp
956A specific version of GCC can be used by setting the value of this variable
957to the desired version
958.Pq for example, Dq gcc14 ;
959otherwise a default version of GCC is used.
960.It Va TARGETS
961Only build the listed targets instead of each supported architecture.
962.It Va EXTRA_TARGETS
963In addition to the supported architectures, build the semi-supported
964architectures.
965A semi-supported architecture has build support in the
966.Fx
967tree, but receives significantly less testing and is generally for
968fringe uses that do not have a wide appeal.
969.El
970.Sh FILES
971.Bl -tag -width ".Pa /usr/share/examples/etc/make.conf" -compact
972.It Pa /usr/doc/Makefile
973.It Pa /usr/doc/share/mk/doc.project.mk
974.It Pa /usr/ports/Mk/bsd.port.mk
975.It Pa /usr/ports/Mk/bsd.sites.mk
976.It Pa /usr/src/Makefile
977.It Pa /usr/src/Makefile.inc1
978.Xr make 1
979infrastructure for each tree
980.It Pa /usr/ports/UPDATING
981.It Pa /usr/src/UPDATING
982notable changes in each tree
983.It Pa /usr/share/examples/etc/make.conf
984example
985.Xr make.conf 5
986.It Pa /etc/src.conf
987src build configuration, see
988.Xr src.conf 5
989.El
990.Sh EXAMPLES
991This section describes best practices for common situations.
992When manual intervention is necessary, it will be mentioned in
993.Pa UPDATING .
994Make sure you have full backups before proceeding!
995.Ss Example 1: Build and upgrade system in place
996If using installed drivers such as graphics or virtual machine guest
997drivers, check out the
998.Xr ports 7
999tree, and specify the drivers in
1000.Xr src.conf 5
1001so they are built and installed automatically after the kernel:
1002.Bd -literal -offset indent
1003git clone https://git.FreeBSD.org/ports.git /usr/ports
1004cat << EOF >> /etc/src.conf
1005PORTS_MODULES+=graphics/drm-kmod emulators/virtualbox-ose-kmod
1006EOF
1007.Ed
1008.Pp
1009Check out the CURRENT branch, build it, and install,
1010overwriting the current system:
1011.Bd -literal -offset indent
1012git clone https://git.FreeBSD.org/src.git /usr/src
1013cd /usr/src
1014make buildworld buildkernel
1015make installkernel
1016shutdown -r now
1017.Ed
1018.Pp
1019For major version upgrades, boot into single-user mode.
1020After restarting, install userspace, and merge configurations.
1021After verifying that you do not need them, delete old files
1022and libraries:
1023.Bd -literal -offset indent
1024cd /usr/src
1025etcupdate -p
1026make installworld
1027etcupdate -B
1028make delete-old delete-old-libs
1029shutdown -r now
1030.Ed
1031.Ss Example 2: Build and upgrade a custom kernel in place
1032Create a custom kernel configuration,
1033.Va MYKERNEL ,
1034by including an existing configuration and using
1035.Cm device Ns / Ns Cm nodevice
1036and
1037.Cm options Ns / Ns Cm nooption
1038to select and configure components:
1039.Bd -literal -offset indent
1040cd /usr/src
1041cat << EOF > sys/amd64/conf/MYKERNEL
1042include GENERIC
1043ident MYKERNEL
1044nodevice sound
1045EOF
1046.Ed
1047.Pp
1048After creating the new kernel configuration, build a fresh toolchain,
1049build the kernel, and install it, moving the old kernel to
1050.Pa /boot/kernel.old/ :
1051.Bd -literal -offset indent
1052make kernel-toolchain
1053make -DALWAYS_CHECK_MAKE buildkernel KERNCONF=MYKERNEL
1054make -DALWAYS_CHECK_MAKE installkernel KERNCONF=MYKERNEL
1055shutdown -r now
1056.Ed
1057.Pp
1058To build the kernel to an alternate location, use the
1059.Va INSTKERNNAME
1060variable and boot it once to test via
1061.Xr nextboot 8 :
1062.Bd -literal -offset indent
1063make installkernel KERNCONF=MYKERNEL INSTKERNNAME=testkernel
1064nextboot -k testkernel
1065shutdown -r now
1066.Ed
1067.Ss Example 3: Build and upgrade a single piece of userspace
1068Rebuild and reinstall a single piece of userspace, in this case
1069.Xr ls 1 :
1070.Bd -literal -offset indent
1071cd /usr/src/bin/ls
1072make clean all
1073make install
1074.Ed
1075.Ss Example 4: Build and upgrade a loadable kernel module
1076Rebuild and reinstall a single loadable kernel module, in this case
1077.Xr sound 4 :
1078.Bd -literal -offset indent
1079cd /usr/src/sys/modules/sound
1080make all install clean cleandepend KMODDIR=/boot/kernel
1081.Ed
1082.Ss Example 5: Quickly rebuild a kernel in place
1083Quickly rebuild and reinstall the kernel, only recompiling the files
1084changed since last build; note that this will only work if the full
1085kernel build has been completed in the past, not on a fresh source tree:
1086.Bd -literal -offset indent
1087cd /usr/src
1088make kernel KERNFAST=1
1089.Ed
1090.Ss Example 6: Cross-compiling for different architectures
1091To rebuild parts of
1092.Fx
1093for another CPU architecture,
1094first prepare your source tree by building the cross-toolchain:
1095.Bd -literal -offset indent
1096cd src
1097make toolchain TARGET_ARCH=aarch64
1098.Ed
1099.Pp
1100The following sequence of commands can be used to cross-build the system
1101for the arm64 (aarch64) architecture on a different host architecture,
1102such as amd64:
1103.Bd -literal -offset indent
1104cd /usr/src
1105make TARGET_ARCH=aarch64 buildworld buildkernel
1106make TARGET_ARCH=aarch64 DESTDIR=/armclient installworld installkernel
1107.Ed
1108.Pp
1109Afterwards, to build and install a single piece of userspace, use:
1110.Bd -literal -offset indent
1111cd src/bin/ls
1112make buildenv TARGET_ARCH=aarch64
1113make clean all install DESTDIR=/armclient
1114.Ed
1115.Pp
1116Likewise, to quickly rebuild and reinstall the kernel, use:
1117.Bd -literal -offset indent
1118cd src
1119make buildenv TARGET_ARCH=aarch64
1120make kernel KERNFAST=1 DESTDIR=/armclient
1121.Ed
1122.Sh DIAGNOSTICS
1123.Bl -diag
1124.It Bad system call (core dumped)
1125.It rescue/sh check failed, installation aborted
1126.Pp
1127The kernel was not updated due to incorrect build procedure.
1128Study the examples above.
1129.Sh SEE ALSO
1130.Xr cc 1 ,
1131.Xr install 1 ,
1132.Xr make 1 ,
1133.Xr make.conf 5 ,
1134.Xr src.conf 5 ,
1135.Xr arch 7 ,
1136.Xr development 7 ,
1137.Xr freebsd-base 7 ,
1138.Xr pkg 7 ,
1139.Xr ports 7 ,
1140.Xr release 7 ,
1141.Xr tests 7 ,
1142.Xr config 8 ,
1143.Xr etcupdate 8 ,
1144.Xr nextboot 8 ,
1145.Xr shutdown 8
1146.Sh HISTORY
1147The
1148.Nm
1149manpage first appeared in
1150.Fx 4.3 .
1151.Sh AUTHORS
1152.An Mike W. Meyer Aq Mt mwm@mired.org
1153.Sh CAVEATS
1154Old objects can cause obscure build problems; try
1155.Ql make cleandir cleandir .
1156.Pp
1157Environment poisioning can cause obscure build problems; try prefixing
1158.Xr make 1
1159commands with
1160.Ql env -i
1161.Pp
1162When doing a major release upgrade,
1163booting into single user mode for
1164.Cm installworld
1165is required.
1166.Pp
1167Updating the boot
1168.Xr loader 8
1169is architecture specific.
1170Consult
1171.Xr boot 8
1172for your architecture for more details.
1173