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