xref: /freebsd/share/man/man7/build.7 (revision ea825d02749f382c3f7e17f28247f20a48733eab)
1.\" Copyright (c) 2000
2.\"	Mike W. Meyer
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.Dd May 11, 2017
28.Dt BUILD 7
29.Os
30.Sh NAME
31.Nm build
32.Nd information on how to build the system
33.Sh DESCRIPTION
34The sources for the
35.Fx
36system and its applications are contained in three different directories,
37normally
38.Pa /usr/src ,
39.Pa /usr/doc ,
40and
41.Pa /usr/ports .
42These directories may be initially empty or non-existent until updated with
43.Xr svn 1
44or
45.Xr portsnap 8 .
46Directory
47.Pa /usr/src
48contains the
49.Dq "base system"
50sources, which is loosely defined as the things required to rebuild
51the system to a useful state.
52Directory
53.Pa /usr/doc
54contains the source for the system documentation, excluding the manual
55pages.
56Directory
57.Pa /usr/ports
58contains a tree that provides a consistent interface for building and
59installing third party applications.
60For more information about the ports build process, see
61.Xr ports 7 .
62.Pp
63The
64.Xr make 1
65command is used in each of these directories to build and install the
66things in that directory.
67Issuing the
68.Xr make 1
69command in any directory or
70subdirectory of those directories has the same effect as issuing the
71same command in all subdirectories of that directory.
72With no target specified, the things in that directory are just built.
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.
85For a given source directory, its canonical object directory
86would be
87.Pa ${MAKEOBJDIRPREFIX}${.CURDIR}
88if
89.Xr make 1
90variable
91.Va MAKEOBJDIRPREFIX
92is set, or
93.Pa /usr/obj${.CURDIR}
94if this variable is not set.
95Cross-builds set the object directory as described in the
96documentation for the
97.Cm buildworld
98target below.
99.Pp
100The build may be controlled by defining
101.Xr make 1
102variables described in the
103.Sx ENVIRONMENT
104section below, and by the variables documented in
105.Xr make.conf 5 .
106.Pp
107The following list provides the names and actions for the targets
108supported by the build system:
109.Bl -tag -width ".Cm cleandepend"
110.It Cm analyze
111Run Clang static analyzer against all objects and present output on stdout.
112.It Cm check
113Run tests for a given subdirectory.
114The default directory used is
115.Pa ${.OBJDIR} ,
116but the check directory can be changed with
117.Pa ${CHECKDIR} .
118.It Cm checkworld
119Run the
120.Fx
121test suite on installed world.
122.It Cm clean
123Remove any files created during the build process.
124.It Cm cleandepend
125Remove the
126.Pa ${.OBJDIR}/${DEPENDFILE}*
127files generated by prior
128.Dq Li "make"
129and
130.Dq Li "make depend"
131steps.
132.It Cm cleandir
133Remove the canonical object directory if it exists, or perform
134actions equivalent to
135.Dq Li "make clean cleandepend"
136if it does not.
137This target will also remove an
138.Pa obj
139link in
140.Pa ${.CURDIR}
141if that exists.
142.Pp
143It is advisable to run
144.Dq Li "make cleandir"
145twice: the first invocation will remove the canonical object directory
146and the second one will clean up
147.Pa ${.CURDIR} .
148.It Cm depend
149Generate a list of build dependencies in file
150.Pa ${.OBJDIR}/${DEPENDFILE} .
151Per-object dependencies are generated at build time and stored in
152.Pa ${.OBJDIR}/${DEPENDFILE}.${OBJ} .
153.It Cm install
154Install the results of the build to the appropriate location in the
155installation directory hierarchy specified in variable
156.Va DESTDIR .
157.It Cm obj
158Create the canonical object directory associated with the current
159directory.
160.It Cm objlink
161Create a symbolic link to the canonical object directory in
162.Pa ${.CURDIR} .
163.It Cm tags
164Generate a tags file using the program specified in the
165.Xr make 1
166variable
167.Va CTAGS .
168The build system supports
169.Xr ctags 1
170and
171.Nm "GNU Global" .
172.El
173.Pp
174The other supported targets under directory
175.Pa /usr/src
176are:
177.Bl -tag -width ".Cm distributeworld"
178.It Cm buildenv
179Spawn an interactive shell with environment variables set up for
180cross-building the system.
181The target architecture needs to be specified with
182.Xr make 1
183variables
184.Va TARGET_ARCH
185and
186.Va TARGET .
187.Pp
188This target is only useful after a complete cross-toolchain including
189the compiler, linker, assembler, headers and libraries has been
190built; see the
191.Cm toolchain
192target below.
193.It Cm buildworld
194Build everything but the kernel, configure files in
195.Pa etc ,
196and
197.Pa release .
198The object directory can be changed from the default
199.Pa /usr/obj
200by setting the
201.Pa MAKEOBJDIRPREFIX
202.Xr make 1
203variable.
204The actual build location prefix used is
205.Pa ${MAKEOBJDIRPREFIX}${.CURDIR}
206for native builds, and
207.Pa ${MAKEOBJDIRPREFIX}/${TARGET}${.CURDIR}
208for cross builds and native builds with variable
209.Va CROSS_BUILD_TESTING
210set.
211.It Cm cleanworld
212Attempt to clean up targets built by a preceding
213.Cm buildworld
214step.
215.It Cm distributeworld
216Distribute everything compiled by a preceding
217.Cm buildworld
218step.
219Files are placed in the directory hierarchy specified by
220.Xr make 1
221variable
222.Va DISTDIR .
223This target is used while building a release; see
224.Xr release 7 .
225.It Cm native-xtools
226This target builds a cross-toolchain for the given
227.Sy TARGET
228and
229.Sy TARGET_ARCH ,
230as well as a select list of static userland tools for the host system.
231This is intended to be used in a jail where QEMU is used to improve
232performance by avoiding emulating binaries that do not need to be emulated.
233.Sy TARGET
234and
235.Sy TARGET_ARCH
236should be defined.
237.It Cm native-xtools-install
238Installs the results to
239.Pa ${DESTDIR}/${NXTP}
240where
241.Va NXTP
242defaults to
243.Pa nxb-bin .
244.Sy TARGET
245and
246.Sy TARGET_ARCH
247must be defined.
248.It Cm packageworld
249Archive the results of
250.Cm distributeworld ,
251placing the results in
252.Va DISTDIR .
253This target is used while building a release; see
254.Xr release 7 .
255.It Cm installworld
256Install everything built by a preceding
257.Cm buildworld
258step into the directory hierarchy pointed to by
259.Xr make 1
260variable
261.Va DESTDIR .
262.Pp
263If installing onto an NFS file system and running
264.Xr make 1
265with the
266.Fl j
267option, make sure that
268.Xr rpc.lockd 8
269is running on both client and server.
270See
271.Xr rc.conf 5
272on how to make it start at boot time.
273.It Cm toolchain
274Create the build toolchain needed to build the rest of the system.
275For cross-architecture builds, this step creates a cross-toolchain.
276.It Cm universe
277For each architecture,
278execute a
279.Cm buildworld
280followed by a
281.Cm buildkernel
282for all kernels for that architecture,
283including
284.Pa LINT .
285This command takes a long time.
286.It Cm update
287Get updated sources as configured in
288.Xr make.conf 5 .
289.It Cm targets
290Print a list of supported
291.Va TARGET
292/
293.Va TARGET_ARCH
294pairs for world and kernel targets.
295.It Cm tinderbox
296Execute the same targets as
297.Cm universe .
298In addition print a summary of all failed targets at the end and
299exit with an error if there were any.
300.It Cm toolchains
301Create a build toolchain for each architecture supported by the build system.
302.It Cm xdev
303Builds and installs a cross-toolchain and sysroot for the given
304.Sy TARGET
305and
306.Sy TARGET_ARCH .
307The sysroot contains target library and headers.
308The target is an alias for
309.Cm xdev-build
310and
311.Cm xdev-install .
312The location of the files installed can be controlled with
313.Va DESTDIR .
314The target location in
315.Va DESTDIR
316is
317.Pa ${DESTDIR}/${XDTP}
318where
319.Va XDTP
320defaults to
321.Pa /usr/${XDDIR}
322and
323.Va XDDIR
324defaults to
325.Pa ${TARGET_ARCH}-freebsd .
326.It Cm xdev-build
327Builds for the
328.Cm xdev
329target.
330.It Cm xdev-install
331Installs the files for the
332.Cm xdev
333target.
334.It Cm xdev-links
335Installs autoconf-style symlinks to
336.Pa ${DESTDIR}/usr/bin
337pointing into the xdev toolchain in
338.Pa ${DESTDIR}/${XDTP} .
339.El
340.Pp
341Kernel specific build targets in
342.Pa /usr/src
343are:
344.Bl -tag -width ".Cm distributekernel"
345.It Cm buildkernel
346Rebuild the kernel and the kernel modules.
347The object directory can be changed from the default
348.Pa /usr/obj
349by setting the
350.Pa MAKEOBJDIRPREFIX
351.Xr make 1
352variable.
353.It Cm installkernel
354Install the kernel and the kernel modules to directory
355.Pa ${DESTDIR}/boot/kernel ,
356renaming any pre-existing directory with this name to
357.Pa kernel.old
358if it contained the currently running kernel.
359The target directory under
360.Pa ${DESTDIR}
361may be modified using the
362.Va INSTKERNNAME
363and
364.Va KODIR
365.Xr make 1
366variables.
367.It Cm distributekernel
368Install the kernel to the directory
369.Pa ${DISTDIR}/kernel/boot/kernel .
370This target is used while building a release; see
371.Xr release 7 .
372.It Cm packagekernel
373Archive the results of
374.Cm distributekernel ,
375placing the results in
376.Va DISTDIR .
377This target is used while building a release; see
378.Xr release 7 .
379.It Cm kernel
380Equivalent to
381.Cm buildkernel
382followed by
383.Cm installkernel
384.It Cm kernel-toolchain
385Rebuild the tools needed for kernel compilation.
386Use this if you did not do a
387.Cm buildworld
388first.
389.It Cm reinstallkernel
390Reinstall the kernel and the kernel modules, overwriting the contents
391of the target directory.
392As with the
393.Cm installkernel
394target, the target directory can be specified using the
395.Xr make 1
396variable
397.Va INSTKERNNAME .
398.El
399.Pp
400Convenience targets for cleaning up the install destination directory
401denoted by variable
402.Va DESTDIR
403include:
404.Bl -tag -width ".Cm delete-old-libs"
405.It Cm check-old
406Print a list of old files and directories in the system.
407.It Cm delete-old
408Delete obsolete base system files and directories interactively.
409When
410.Li -DBATCH_DELETE_OLD_FILES
411is specified at the command line, the delete operation will be
412non-interactive.
413The variables
414.Va DESTDIR ,
415.Va TARGET_ARCH
416and
417.Va TARGET
418should be set as with
419.Dq Li "make installworld" .
420.It Cm delete-old-libs
421Delete obsolete base system libraries interactively.
422This target should only be used if no third party software uses these
423libraries.
424When
425.Li -DBATCH_DELETE_OLD_FILES
426is specified at the command line, the delete operation will be
427non-interactive.
428The variables
429.Va DESTDIR ,
430.Va TARGET_ARCH
431and
432.Va TARGET
433should be set as with
434.Dq Li "make installworld" .
435.El
436.Sh ENVIRONMENT
437Variables that influence all builds include:
438.Bl -tag -width ".Va MAKEOBJDIRPREFIX"
439.It Va DEBUG_FLAGS
440Defines a set of debugging flags that will be used to build all userland
441binaries under
442.Pa /usr/src .
443When
444.Va DEBUG_FLAGS
445is defined, the
446.Cm install
447and
448.Cm installworld
449targets install binaries from the current
450.Va MAKEOBJDIRPREFIX
451without stripping,
452so that debugging information is retained in the installed binaries.
453.It Va DESTDIR
454The directory hierarchy prefix where built objects will be installed.
455If not set,
456.Va DESTDIR
457defaults to the empty string.
458.It Va MAKEOBJDIRPREFIX
459Defines the prefix for directory names in the tree of built objects.
460Defaults to
461.Pa /usr/obj
462if not defined.
463This variable should only be set in the environment and not via
464.Pa /etc/make.conf
465or the command line.
466.It Va NO_WERROR
467If defined, compiler warnings will not cause the build to halt,
468even if the makefile says otherwise.
469.It Va WITH_CTF
470If defined, the build process will run the DTrace CTF conversion
471tools on built objects.
472.El
473.Pp
474Additionally, builds in
475.Pa /usr/src
476are influenced by the following
477.Xr make 1
478variables:
479.Bl -tag -width ".Va SUBDIR_OVERRIDE"
480.It Va KERNCONF
481Overrides which kernel to build and install for the various kernel
482make targets.
483It defaults to
484.Cm GENERIC .
485.It Va KERNFAST
486If set, the build target
487.Cm buildkernel
488defaults to setting
489.Va NO_KERNELCLEAN ,
490.Va NO_KERNELCONFIG ,
491and
492.Va NO_KERNELOBJ .
493When set to a value other than
494.Cm 1
495then
496.Va KERNCONF
497is set to the value of
498.Va KERNFAST .
499.It Va LOCAL_DIRS
500If set, this variable supplies a list of additional directories relative to
501the root of the source tree to build as part of the
502.Cm everything
503target.
504.It Va LOCAL_ITOOLS
505If set, this variable supplies a list of additional tools that are used by the
506.Cm installworld
507and
508.Cm distributeworld
509targets.
510.It Va LOCAL_LIB_DIRS
511If set, this variable supplies a list of additional directories relative to
512the root of the source tree to build as part of the
513.Cm libraries
514target.
515.It Va LOCAL_MTREE
516If set, this variable supplies a list of additional mtrees relative to the
517root of the source tree to use as part of the
518.Cm hierarchy
519target.
520.It Va LOCAL_TOOL_DIRS
521If set, this variable supplies a list of additional directories relative to
522the root of the source tree to build as part of the
523.Cm build-tools
524target.
525.It Va LOCAL_XTOOL_DIRS
526If set, this variable supplies a list of additional directories relative to
527the root of the source tree to build as part of the
528.Cm cross-tools
529target.
530.It Va PORTS_MODULES
531A list of ports with kernel modules that should be built and installed
532as part of the
533.Cm buildkernel
534and
535.Cm installkernel
536process.
537.Bd -literal -offset indent
538make PORTS_MODULES=emulators/kqemu-kmod kernel
539.Ed
540.It Va STRIPBIN
541Command to use at install time when stripping binaries.
542Be sure to add any additional tools required to run
543.Va STRIPBIN
544to the
545.Va LOCAL_ITOOLS
546.Xr make 1
547variable before running the
548.Cm distributeworld
549or
550.Cm installworld
551targets.
552See
553.Xr install 1
554for more details.
555.It Va SUBDIR_OVERRIDE
556Override the default list of sub-directories and only build the
557sub-directory named in this variable.
558If combined with
559.Cm buildworld
560then all libraries and includes, and some of the build tools will still build
561as well.
562Specifying
563.Cm -DNO_LIBS ,
564and
565.Cm -DWORLDFAST
566will only build the specified directory as was done historically.
567When combined with
568.Cm buildworld
569it is necesarry to override
570.Va LOCAL_LIB_DIRS
571with any custom directories containing libraries.
572This allows building a subset of the system in the same way as
573.Cm buildworld
574does using its sysroot handling.
575This variable can also be useful when debugging failed builds.
576.Bd -literal -offset indent
577make some-target SUBDIR_OVERRIDE=foo/bar
578.Ed
579.It Va TARGET
580The target hardware platform.
581This is analogous to the
582.Dq Nm uname Fl m
583output.
584This is necessary to cross-build some target architectures.
585For example, cross-building for ARM64 machines requires
586.Va TARGET_ARCH Ns = Ns Li aarch64
587and
588.Va TARGET Ns = Ns Li arm64 .
589If not set,
590.Va TARGET
591defaults to the current hardware platform, unless
592.Va TARGET_ARCH
593is also set, in which case it defaults to the appropriate
594value for that architecture.
595.It Va TARGET_ARCH
596The target machine processor architecture.
597This is analogous to the
598.Dq Nm uname Fl p
599output.
600Set this to cross-build for a different architecture.
601If not set,
602.Va TARGET_ARCH
603defaults to the current machine architecture, unless
604.Va TARGET
605is also set, in which case it defaults to the appropriate
606value for that platform.
607Typically, one only needs to set
608.Va TARGET .
609.El
610.Pp
611Builds under directory
612.Pa /usr/src
613are also influenced by defining one or more of the following symbols,
614using the
615.Fl D
616option of
617.Xr make 1 :
618.Bl -tag -width ".Va -DNO_KERNELCONFIG"
619.It Va NO_CLEANDIR
620If set, the build targets that clean parts of the object tree use the
621equivalent of
622.Dq make clean
623instead of
624.Dq make cleandir .
625.It Va NO_CLEAN
626If set, no object tree files are cleaned at all.
627This is the default when
628.Va WITH_META_MODE
629is used with
630.Xr filemon 4
631loaded.
632See
633.Xr src.conf 5
634for more details.
635Setting
636.Va NO_CLEAN
637implies
638.Va NO_KERNELCLEAN ,
639so when
640.Va NO_CLEAN
641is set no kernel objects are cleaned either.
642.It Va NO_CTF
643If set, the build process does not run the DTrace CTF conversion tools
644on built objects.
645.It Va NO_SHARE
646If set, the build does not descend into the
647.Pa /usr/src/share
648subdirectory (i.e., manual pages, locale data files, timezone data files and
649other
650.Pa /usr/src/share
651files will not be rebuild from their sources).
652.It Va NO_KERNELCLEAN
653If set, the build process does not run
654.Dq make clean
655as part of the
656.Cm buildkernel
657target.
658.It Va NO_KERNELCONFIG
659If set, the build process does not run
660.Xr config 8
661as part of the
662.Cm buildkernel
663target.
664.It Va NO_KERNELOBJ
665If set, the build process does not run
666.Dq make obj
667as part of the
668.Cm buildkernel
669target.
670.It Va NO_DOCUPDATE
671If set, the update process does not update the source of the
672.Fx
673documentation as part of the
674.Dq make update
675target.
676.It Va NO_LIBS
677If set, the libraries phase will be skipped.
678.It Va NO_OBJ
679If set, no object directories will be created.
680This should only be used if object directories were created in a
681previous build and no new directories are connected.
682.It Va NO_PORTSUPDATE
683If set, the update process does not update the Ports tree as part of the
684.Dq make update
685target.
686.It Va NO_WWWUPDATE
687If set, the update process does not update the www tree as part of the
688.Dq make update
689target.
690.It Va WORLDFAST
691If set, the build target
692.Cm buildworld
693defaults to setting
694.Va NO_CLEAN ,
695.Va NO_OBJ ,
696and will skip most bootstrap phases.
697It will only bootstrap libraries and build all of userland.
698This option should be used only when it is known that none of the bootstrap
699needs changed and that no new directories have been connected to the build.
700.El
701.Pp
702Builds under directory
703.Pa /usr/doc
704are influenced by the following
705.Xr make 1
706variables:
707.Bl -tag -width ".Va DOC_LANG"
708.It Va DOC_LANG
709If set, restricts the documentation build to the language subdirectories
710specified as its content.
711The default action is to build documentation for all languages.
712.El
713.Pp
714Builds using the
715.Cm universe
716target are influenced by the following
717.Xr make 1
718variables:
719.Bl -tag -width ".Va MAKE_JUST_KERNELS"
720.It Va JFLAG
721Pass the value of this variable to each
722.Xr make 1
723invocation used to build worlds and kernels.
724This can be used to enable multiple jobs within a single architecture's build
725while still building each architecture serially.
726.It Va MAKE_JUST_KERNELS
727Only build kernels for each supported architecture.
728.It Va MAKE_JUST_WORLDS
729Only build worlds for each supported architecture.
730.It Va UNIVERSE_TARGET
731Execute the specified
732.Xr make 1
733target for each supported architecture instead of the default action of
734building a world and one or more kernels.
735.El
736.Sh FILES
737.Bl -tag -width ".Pa /usr/share/examples/etc/make.conf" -compact
738.It Pa /usr/doc/Makefile
739.It Pa /usr/doc/share/mk/doc.project.mk
740.It Pa /usr/ports/Mk/bsd.port.mk
741.It Pa /usr/ports/Mk/bsd.sites.mk
742.It Pa /usr/share/examples/etc/make.conf
743.It Pa /usr/src/Makefile
744.It Pa /usr/src/Makefile.inc1
745.El
746.Sh EXAMPLES
747For an
748.Dq approved
749method of updating your system from the latest sources, please see the
750.Sx COMMON ITEMS
751section in
752.Pa src/UPDATING .
753.Pp
754The following sequence of commands can be used to cross-build the
755system for the armv6 architecture on an amd64 host:
756.Bd -literal -offset indent
757cd /usr/src
758make TARGET_ARCH=armv6 buildworld buildkernel
759make TARGET_ARCH=armv6 DESTDIR=/clients/arm64 installworld installkernel
760.Ed
761.Sh SEE ALSO
762.Xr cc 1 ,
763.Xr install 1 ,
764.Xr make 1 ,
765.Xr svn 1 ,
766.Xr make.conf 5 ,
767.Xr src.conf 5 ,
768.Xr arch 7 ,
769.Xr ports 7 ,
770.Xr release 7 ,
771.Xr tests 7 ,
772.Xr config 8 ,
773.Xr mergemaster 8 ,
774.Xr portsnap 8 ,
775.Xr reboot 8 ,
776.Xr shutdown 8
777.Sh AUTHORS
778.An Mike W. Meyer Aq Mt mwm@mired.org
779