4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
30 .Nd General instructions on how to build the system
34 system and its applications are contained in three different directories,
40 These directories may be initially empty or non-existent until updated with
42 .Po installed from packages with
50 sources, which is loosely defined as the things required to rebuild
51 the system to a useful state.
54 contains the source for the system documentation, excluding the manual
58 contains a tree that provides a consistent interface for building and
59 installing third party applications.
60 For more information about the ports build process, see
65 command is used in each of these directories to build and install the
66 things in that directory.
69 command in any directory issues the
71 command recursively in all subdirectories.
72 With no target specified, the items in the directories are built
73 and no further action is taken.
75 A source tree is allowed to be read-only.
78 objects are usually built in a separate object directory hierarchy
79 specified by the environment variable
80 .Va MAKEOBJDIRPREFIX ,
86 The canonical object directory is described in the documentation for the
90 The build may be controlled by defining
92 variables described in the
94 section below, and by the variables documented in
97 The default components included in the build are specified in the file
100 To override the default file, include the SRCCONF option in the make steps,
101 pointing to a custom src.conf file.
102 For more information see
105 The following list provides the names and actions for the targets
106 supported by the build system:
107 .Bl -tag -width ".Cm cleandepend"
109 Run Clang static analyzer against all objects and present output on stdout.
111 Run tests for a given subdirectory.
112 The default directory used is
114 but the check directory can be changed with
119 test suite on installed world.
121 Remove any files created during the build process.
124 .Pa ${.OBJDIR}/${DEPENDFILE}*
125 files generated by prior
131 Remove the canonical object directory if it exists, or perform
132 actions equivalent to
133 .Dq Li "make clean cleandepend"
135 This target will also remove an
141 It is advisable to run
142 .Dq Li "make cleandir"
143 twice: the first invocation will remove the canonical object directory
144 and the second one will clean up
147 Generate a list of build dependencies in file
148 .Pa ${.OBJDIR}/${DEPENDFILE} .
149 Per-object dependencies are generated at build time and stored in
150 .Pa ${.OBJDIR}/${DEPENDFILE}.${OBJ} .
152 Install the results of the build to the appropriate location in the
153 installation directory hierarchy specified in variable
156 Create the canonical object directory associated with the current
159 Create a symbolic link to the canonical object directory in
162 Generate a tags file using the program specified in the
166 The build system supports
172 The other supported targets under directory
175 .Bl -tag -width ".Cm distributeworld"
177 Spawn an interactive shell with environment variables set up for
178 building the system or individual components.
179 For cross-building the target architecture needs to be specified with
186 This target is only useful after a complete toolchain (including
187 the compiler, linker, assembler, headers and libraries) has been
192 Build everything but the kernel, configure files in
196 The object directory can be changed from the default
202 The actual build location prefix used
204 .Va WITH_UNIFIED_OBJDIR
208 .Pa ${MAKEOBJDIRPREFIX}${.CURDIR}/${TARGET}.${TARGET_ARCH}
211 .Pa ${MAKEOBJDIRPREFIX}${.CURDIR}
212 for native builds, and
213 .Pa ${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}${.CURDIR}
214 for cross builds and native builds with variable
215 .Va CROSS_BUILD_TESTING
218 Attempts to clean up targets built by a preceding
220 or similar step, built from the same source directory and
223 Attempt to clean up targets built by a preceding
225 or similar step, built from this source directory.
228 .Va WITH_UNIFIED_OBJDIR
229 is enabled, attempt to clean up targets built by a preceding
232 or similar step, for any architecture built from this source directory.
233 .It Cm distributeworld
234 Distribute everything compiled by a preceding
237 Files are placed in the directory hierarchy specified by
241 This target is used while building a release; see
244 This target builds a cross-toolchain for the given
248 as well as a select list of static userland tools for the host system.
249 This is intended to be used in a jail where QEMU is used to improve
250 performance by avoiding emulating binaries that do not need to be emulated.
255 .It Cm native-xtools-install
256 Installs the results to
257 .Pa ${DESTDIR}/${NXTP}
267 Archive the results of
268 .Cm distributeworld ,
269 placing the results in
271 This target is used while building a release; see
274 Install everything built by a preceding
276 step into the directory hierarchy pointed to by
281 If installing onto an NFS file system and running
285 option, make sure that
287 is running on both client and server.
290 on how to make it start at boot time.
292 Create the build toolchain needed to build the rest of the system.
293 For cross-architecture builds, this step creates a cross-toolchain.
295 For each architecture,
300 for all kernels for that architecture,
303 This command takes a long time.
309 defined so only the kernels for each architecture are built.
315 defined so only the worlds for each architecture are built.
317 Print a list of supported
321 pairs for world and kernel targets.
323 Execute the same targets as
325 In addition print a summary of all failed targets at the end and
326 exit with an error if there were any.
328 Create a build toolchain for each architecture supported by the build system.
330 Builds and installs a cross-toolchain and sysroot for the given
334 The sysroot contains target library and headers.
335 The target is an alias for
339 The location of the files installed can be controlled with
341 The target location in
344 .Pa ${DESTDIR}/${XDTP}
352 .Pa ${TARGET_ARCH}-freebsd .
358 Installs the files for the
362 Installs autoconf-style symlinks to
363 .Pa ${DESTDIR}/usr/bin
364 pointing into the xdev toolchain in
365 .Pa ${DESTDIR}/${XDTP} .
368 Kernel specific build targets in
371 .Bl -tag -width ".Cm distributekernel"
373 Rebuild the kernel and the kernel modules.
374 The object directory can be changed from the default
381 Install the kernel and the kernel modules to directory
382 .Pa ${DESTDIR}/boot/kernel ,
383 renaming any pre-existing directory with this name to
385 if it contained the currently running kernel.
386 The target directory under
388 may be modified using the
394 .It Cm distributekernel
395 Install the kernel to the directory
396 .Pa ${DISTDIR}/kernel/boot/kernel .
397 This target is used while building a release; see
400 Archive the results of
401 .Cm distributekernel ,
402 placing the results in
404 This target is used while building a release; see
411 .It Cm kernel-toolchain
412 Rebuild the tools needed for kernel compilation.
413 Use this if you did not do a
416 .It Cm reinstallkernel
417 Reinstall the kernel and the kernel modules, overwriting the contents
418 of the target directory.
421 target, the target directory can be specified using the
427 Convenience targets for cleaning up the install destination directory
431 .Bl -tag -width ".Cm delete-old-libs"
433 Print a list of old files and directories in the system.
435 Delete obsolete base system files and directories interactively.
437 .Li -DBATCH_DELETE_OLD_FILES
438 is specified at the command line, the delete operation will be
445 should be set as with
446 .Dq Li "make installworld" .
447 .It Cm delete-old-libs
448 Delete obsolete base system libraries interactively.
449 This target should only be used if no third party software uses these
452 .Li -DBATCH_DELETE_OLD_FILES
453 is specified at the command line, the delete operation will be
460 should be set as with
461 .Dq Li "make installworld" .
464 Variables that influence all builds include:
465 .Bl -tag -width ".Va MAKEOBJDIRPREFIX"
467 Defines a set of debugging flags that will be used to build all userland
476 targets install binaries from the current
479 so that debugging information is retained in the installed binaries.
481 The directory hierarchy prefix where built objects will be installed.
484 defaults to the empty string.
485 .It Va MAKEOBJDIRPREFIX
486 Defines the prefix for directory names in the tree of built objects.
490 This variable should only be set in the environment or
491 .Pa /etc/src-env.conf
497 .It Va WITHOUT_WERROR
498 If defined, compiler warnings will not cause the build to halt,
499 even if the makefile says otherwise.
501 If defined, the build process will run the DTrace CTF conversion
502 tools on built objects.
505 Additionally, builds in
507 are influenced by the following
510 .Bl -tag -width ".Va LOCAL_MODULES_DIR"
511 .It Va CROSS_TOOLCHAIN
512 Requests use of an external toolchain to build either the world or kernel.
513 This value of this variable can either be the full path to a file,
514 or the base name of a file in
515 .Pa ${LOCALBASE}/share/toolchains .
516 The file should be a make file which sets variables to request an external
520 External toolchains are available in ports for both LLVM and GCC/binutils.
521 For external toolchains available in ports,
523 should be set to the name of the package.
524 LLVM toolchain packages use the name llvm<major version>.
525 GCC toolchains provide separate packages for each architecture and use the
526 name ${MACHINE_ARCH}-gcc<major version>.
528 Overrides which kernel to build and install for the various kernel
533 Overrides the directory in which
535 and any files included by
539 .Pa sys/${ARCH}/conf .
541 If set, the build target
545 .Va NO_KERNELCONFIG ,
548 When set to a value other than
552 is set to the value of
555 If set, this variable supplies a list of additional directories relative to
556 the root of the source tree to build as part of the
559 The directories are built in parallel with each other,
560 and with the base system directories.
563 directive at the beginning of the
565 list to ensure all base system directories are built first.
567 may also be used as needed elsewhere within the list.
569 If set, this variable supplies a list of additional tools that are used by the
574 .It Va LOCAL_LIB_DIRS
575 If set, this variable supplies a list of additional directories relative to
576 the root of the source tree to build as part of the
579 The directories are built in parallel with each other,
580 and with the base system libraries.
583 directive at the beginning of the
585 list to ensure all base system libraries are built first.
587 may also be used as needed elsewhere within the list.
589 If set, this variable supplies a list of additional mtrees relative to the
590 root of the source tree to use as part of the
593 .It Va LOCAL_LEGACY_DIRS
594 If set, this variable supplies a list of additional directories relative to
595 the root of the source tree to build as part of the
598 .It Va LOCAL_BSTOOL_DIRS
599 If set, this variable supplies a list of additional directories relative to
600 the root of the source tree to build as part of the
603 .It Va LOCAL_TOOL_DIRS
604 If set, this variable supplies a list of additional directories relative to
605 the root of the source tree to build as part of the
608 .It Va LOCAL_XTOOL_DIRS
609 If set, this variable supplies a list of additional directories relative to
610 the root of the source tree to build as part of the
614 A list of ports with kernel modules that should be built and installed
620 .Bd -literal -offset indent
621 make PORTS_MODULES=emulators/virtualbox-ose-kmod kernel
624 A list of external kernel modules that should be built and installed
630 Defaults to the list of sub-directories of
631 .Va LOCAL_MODULES_DIR .
632 .It Va LOCAL_MODULES_DIR
633 The directory in which to search for the kernel modules specified by
635 Each kernel module should consist of a directory containing a makefile.
637 .Pa ${LOCALBASE}/sys/modules .
639 Specify a file to override the default
641 The src.conf file controls the components to build.
645 Command to use at install time when stripping binaries.
646 Be sure to add any additional tools required to run
651 variable before running the
659 .It Va SUBDIR_OVERRIDE
660 Override the default list of sub-directories and only build the
661 sub-directory named in this variable.
664 then all libraries and includes, and some of the build tools will still build
670 will only build the specified directory as was done historically.
673 it is necesarry to override
675 with any custom directories containing libraries.
676 This allows building a subset of the system in the same way as
678 does using its sysroot handling.
679 This variable can also be useful when debugging failed builds.
680 .Bd -literal -offset indent
681 make some-target SUBDIR_OVERRIDE=foo/bar
684 Specify the location of the kernel source to override the default
686 The kernel source is located in the
688 subdirectory of the source tree checked out from the
692 The target hardware platform.
693 This is analogous to the
696 This is necessary to cross-build some target architectures.
697 For example, cross-building for ARM64 machines requires
698 .Va TARGET_ARCH Ns = Ns Li aarch64
700 .Va TARGET Ns = Ns Li arm64 .
703 defaults to the current hardware platform, unless
705 is also set, in which case it defaults to the appropriate
706 value for that architecture.
708 The target machine processor architecture.
709 This is analogous to the
712 Set this to cross-build for a different architecture.
715 defaults to the current machine architecture, unless
717 is also set, in which case it defaults to the appropriate
718 value for that platform.
719 Typically, one only needs to set
723 Builds under directory
725 are also influenced by defining one or more of the following symbols,
730 .Bl -tag -width ".Va LOADER_DEFAULT_INTERP"
731 .It Va LOADER_DEFAULT_INTERP
732 Defines what interpreter the default loader program will have.
738 This creates the default link for
740 to the loader with that interpreter.
741 It also determines what interpreter is compiled into
744 If set, the build targets that clean parts of the object tree use the
750 If set, no object tree files are cleaned at all.
751 This is the default when
765 is set no kernel objects are cleaned either.
767 If set, the build process does not run the DTrace CTF conversion tools
770 If set, the build does not descend into the
772 subdirectory (i.e., manual pages, locale data files, timezone data files and
775 files will not be rebuild from their sources).
776 .It Va NO_KERNELCLEAN
777 If set, the build process does not run
782 .It Va NO_KERNELCONFIG
783 If set, the build process does not run
789 If set, the build process does not run
795 If set, the libraries phase will be skipped.
797 If set, no object directories will be created.
798 This should only be used if object directories were created in a
799 previous build and no new directories are connected.
800 .It Va UNIVERSE_TOOLCHAIN
801 Requests use of the toolchain built as part of the
803 target as an external toolchain.
805 If set, the build target
810 and will skip most bootstrap phases.
811 It will only bootstrap libraries and build all of userland.
812 This option should be used only when it is known that none of the bootstrap
813 needs changed and that no new directories have been connected to the build.
816 Builds under directory
818 are influenced by the following
821 .Bl -tag -width ".Va DOC_LANG"
823 If set, restricts the documentation build to the language subdirectories
824 specified as its content.
825 The default action is to build documentation for all languages.
830 and related targets are influenced by the following
833 .Bl -tag -width ".Va USE_GCC_TOOLCHAINS"
835 Pass the value of this variable to each
837 invocation used to build worlds and kernels.
838 This can be used to enable multiple jobs within a single architecture's build
839 while still building each architecture serially.
840 .It Va MAKE_JUST_KERNELS
841 Only build kernels for each supported architecture.
842 .It Va MAKE_JUST_WORLDS
843 Only build worlds for each supported architecture.
844 .It Va WITHOUT_WORLDS
845 Only build kernels for each supported architecture.
846 .It Va WITHOUT_KERNELS
847 Only build worlds for each supported architecture.
848 .It Va UNIVERSE_TARGET
849 Execute the specified
851 target for each supported architecture instead of the default action of
852 building a world and one or more kernels.
853 This variable implies
854 .Va WITHOUT_KERNELS .
855 .It Va USE_GCC_TOOLCHAINS
856 Use external GCC toolchains to build the requested targets.
857 If the required toolchain package for a supported architecture is not installed,
858 the build for that architecture is skipped.
860 Only build the listed targets instead of each supported architecture.
862 In addition to the supported architectures, build the semi-supported
864 A semi-supported architecture has build support in the
866 tree, but receives significantly less testing and is generally for
867 fringe uses that do not have a wide appeal.
870 .Bl -tag -width ".Pa /usr/share/examples/etc/make.conf" -compact
871 .It Pa /usr/doc/Makefile
872 .It Pa /usr/doc/share/mk/doc.project.mk
873 .It Pa /usr/ports/Mk/bsd.port.mk
874 .It Pa /usr/ports/Mk/bsd.sites.mk
875 .It Pa /usr/share/examples/etc/make.conf
876 .It Pa /usr/src/Makefile
877 .It Pa /usr/src/Makefile.inc1
882 method of updating your system from the latest sources, please see the
887 The following sequence of commands can be used to cross-build the
888 system for the armv6 architecture on an amd64 host:
889 .Bd -literal -offset indent
891 make TARGET_ARCH=armv6 buildworld buildkernel
892 make TARGET_ARCH=armv6 DESTDIR=/clients/arm installworld installkernel
897 manpage first appeared in
915 .An Mike W. Meyer Aq Mt mwm@mired.org