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 March 20, 2006 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 . 42Directory 43.Pa /usr/src 44contains the 45.Dq "base system" 46sources, which is loosely defined as the things required to rebuild 47the system to a useful state. 48Directory 49.Pa /usr/doc 50contains the source for the system documentation, excluding the manual 51pages. 52Directory 53.Pa /usr/ports 54contains a tree that provides a consistent interface for building and 55installing third party applications. 56For more information about the ports build process, see 57.Xr ports 7 . 58.Pp 59The 60.Xr make 1 61command is used in each of these directories to build and install the 62things in that directory. 63Issuing the 64.Xr make 1 65command in any directory or 66subdirectory of those directories has the same effect as issuing the 67same command in all subdirectories of that directory. 68With no target specified, the things in that directory are just built. 69.Pp 70A source tree is allowed to be read-only. 71As described in 72.Xr make 1 , 73objects are usually built in a separate object directory hierarchy 74specified by the environment variable 75.Va MAKEOBJDIRPREFIX , 76or under 77.Pa /usr/obj 78if variable 79.Va MAKEOBJDIRPREFIX 80is not set. 81For a given source directory, its canonical object directory 82would be 83.Pa ${MAKEOBJDIRPREFIX}${.CURDIR} 84if 85.Xr make 1 86variable 87.Va MAKEOBJDIRPREFIX 88is set, or 89.Pa /usr/obj${.CURDIR} 90if this variable is not set. 91Cross-builds set the object directory as described in the 92documentation for the 93.Cm buildworld 94target below. 95.Pp 96The build may be controlled by defining 97.Xr make 1 98variables described in the 99.Sx ENVIRONMENT 100section below, and by the variables documented in 101.Xr make.conf 5 . 102.Pp 103The following list provides the names and actions for the targets 104supported by the build system: 105.Bl -tag -width ".Cm cleandepend" 106.It Cm clean 107Remove any files created during the build process. 108.It Cm cleandepend 109Remove the file 110.Pa ${.OBJDIR}/${DEPENDFILE} 111generated by a prior 112.Dq Li "make depend" 113step. 114.It Cm cleandir 115Remove the canonical object directory if it exists, or perform 116actions equivalent to 117.Dq Li "make clean cleandepend" 118if it does not. 119This target will also remove an 120.Pa obj 121link in 122.Pa ${.CURDIR} 123if that exists. 124.Pp 125It is advisable to run 126.Dq Li "make cleandir" 127twice: the first invocation will remove the canonical object directory 128and the second one will clean up 129.Pa ${.CURDIR} . 130.It Cm depend 131Generate a list of build dependencies in file 132.Pa ${.OBJDIR}/${DEPENDFILE} . 133.It Cm install 134Install the results of the build to the appropriate location in the 135installation directory hierarchy specified in variable 136.Va DESTDIR . 137.It Cm obj 138Create the canonical object directory associated with the current 139directory. 140.It Cm objlink 141Create a symbolic link to the canonical object directory in 142.Pa ${.CURDIR} . 143.It Cm tags 144Generate a tags file using the program specified in the 145.Xr make 1 146variable 147.Va CTAGS . 148The build system supports 149.Xr ctags 1 150and 151.Nm "GNU Global" . 152.El 153.Pp 154The other supported targets under directory 155.Pa /usr/src 156are: 157.Bl -tag -width ".Cm distributeworld" 158.It Cm buildenv 159Spawn an interactive shell with environment variables set up for 160cross-building the system. 161The target architecture needs to be specified with 162.Xr make 1 163variables 164.Va TARGET_ARCH 165and 166.Va TARGET . 167.Pp 168This target is only useful after a complete cross-toolchain including 169the compiler, linker, assembler, headers and libraries has been 170built; see the 171.Cm toolchain 172target below. 173.It Cm buildworld 174Build everything but the kernel, configure files in 175.Pa etc , 176and 177.Pa release . 178The actual build location prefix used is 179.Pa ${MAKEOBJDIRPREFIX}${.CURDIR} 180for native builds, and 181.Pa ${MAKEOBJDIRPREFIX}/${TARGET}${.CURDIR} 182for cross builds and native builds with variable 183.Va CROSS_BUILD_TESTING 184set. 185.It Cm cleanworld 186Attempt to clean up targets built by a preceding 187.Cm buildworld 188step. 189.It Cm distributeworld 190Distribute everything compiled by a preceding 191.Cm buildworld 192step. 193Files are placed in the directory hierarchy specified by 194.Xr make 1 195variable 196.Va DISTDIR . 197This target is used while building a release; see 198.Xr release 7 . 199.It Cm installworld 200Install everything built by a preceding 201.Cm buildworld 202step into the directory hierarchy pointed to by 203.Xr make 1 204variable 205.Va DESTDIR . 206.Pp 207If installing onto an NFS file system, make sure that 208.Xr rpc.lockd 8 209is running on both client and server. 210See 211.Xr rc.conf 5 212on how to make it start at boot time. 213.It Cm toolchain 214Create the build toolchain needed to build the rest of the system. 215For cross-architecture builds, this step creates a cross-toolchain. 216.It Cm universe 217Execute a 218.Cm buildworld 219and 220.Cm buildkernel 221for all kernels including 222.Pa LINT , 223for each architecture supported by the build system. 224This command takes a long time. 225.It Cm update 226Get updated sources as configured in 227.Xr make.conf 5 . 228.El 229.Pp 230Kernel specific build targets in 231.Pa /usr/src 232are: 233.Bl -tag -width ".Cm reinstallkernel" 234.It Cm buildkernel 235Rebuild the kernel and the kernel modules. 236.It Cm installkernel 237Install the kernel and the kernel modules to directory 238.Pa ${DESTDIR}/boot/kernel , 239renaming any pre-existing directory with this name to 240.Pa kernel.old 241if it contained the currently running kernel. 242The target directory under 243.Pa ${DESTDIR} 244may be modified using the 245.Va INSTKERNNAME 246and 247.Va KODIR 248.Xr make 1 249variables. 250.It Cm kernel 251Equivalent to 252.Cm buildkernel 253followed by 254.Cm installkernel 255.It Cm kernel-toolchain 256Rebuild the tools needed for kernel compilation. 257Use this if you did not do a 258.Cm buildworld 259first. 260.It Cm reinstallkernel 261Reinstall the kernel and the kernel modules, overwriting the contents 262of the target directory. 263As with the 264.Cm installkernel 265target, the target directory can be specified using the 266.Xr make 1 267variable 268.Va INSTKERNNAME . 269.El 270.Pp 271Convenience targets for cleaning up the install destination directory 272denoted by variable 273.Va DESTDIR 274include: 275.Bl -tag -width ".Cm delete-old-libs" 276.It Cm check-old 277Print a list of old files and directores in the system. 278.It Cm delete-old 279Delete obsolete base system files and directories interactively. 280When 281.Li -DBATCH_DELETE_OLD_FILES 282is specified at the command line, the delete operation will be 283non-interactive. 284The variables 285.Va DESTDIR , 286.Va TARGET_ARCH 287and 288.Va TARGET 289should be set as with 290.Dq Li "make installworld" . 291.It Cm delete-old-libs 292Delete obsolete base system libraries interactively. 293This target should only be used if no 3rd party software uses these 294libraries. 295When 296.Li -DBATCH_DELETE_OLD_FILES 297is specified at the command line, the delete operation will be 298non-interactive. 299The variables 300.Va DESTDIR , 301.Va TARGET_ARCH 302and 303.Va TARGET 304should be set as with 305.Dq Li "make installworld" . 306.El 307.Sh ENVIRONMENT 308Variables that influence all builds include: 309.Bl -tag -width ".Va MAKEOBJDIRPREFIX" 310.It Va DESTDIR 311The directory hierarchy prefix where built objects will be installed. 312If not set, 313.Va DESTDIR 314defaults to the empty string. 315.It Va MAKEOBJDIRPREFIX 316Defines the prefix for directory names in the tree of built objects. 317Defaults to 318.Pa /usr/obj 319if not defined. 320This variable should only be set in the environment and not via 321.Pa /etc/make.conf 322or the command line. 323.It Va NO_WERROR 324If defined, compiler warnings will not cause the build to halt, 325even if the makefile says otherwise. 326.El 327.Pp 328Additionally, builds in 329.Pa /usr/src 330are influenced by the following 331.Xr make 1 332variables: 333.Bl -tag -width ".Va SUBDIR_OVERRIDE" 334.It Va LOCAL_DIRS 335If set, this variable supplies a list of additional directories to 336build, relative to the root of the source tree. 337.It Va SUBDIR_OVERRIDE 338Override the default list of sub-directories and only build the 339sub-directory named in this variable. 340This variable is useful when debugging failed builds. 341.Bd -literal -offset indent 342make some-target SUBDIR_OVERRIDE=foo/bar 343.Ed 344.It Va TARGET 345The target hardware platform. 346This is analogous to the 347.Dq Nm uname Fl m 348output. 349This is necessary to cross-build some target architectures. 350For example, cross-building for PC98 machines requires 351.Va TARGET_ARCH Ns = Ns Li i386 352and 353.Va TARGET Ns = Ns Li pc98 . 354If not set, 355.Va TARGET 356defaults to the current hardware platform. 357.It Va TARGET_ARCH 358The target machine processor architecture. 359This is analogous to the 360.Dq Nm uname Fl p 361output. 362Set this to cross-build for a different architecture. 363If not set, 364.Va TARGET_ARCH 365defaults to the current machine architecture. 366.El 367.Pp 368Builds under directory 369.Pa /usr/doc 370are influenced by the following 371.Xr make 1 372variables: 373.Bl -tag -width ".Va DOC_LANG" 374.It Va DOC_LANG 375If set, restricts the documentation build to the language subdirectories 376specified as its content. 377The default action is to build documentation for all languages. 378.El 379.Sh FILES 380.Bl -tag -width ".Pa /usr/share/examples/etc/make.conf" -compact 381.It Pa /usr/doc/Makefile 382.It Pa /usr/doc/share/mk/doc.project.mk 383.It Pa /usr/ports/Mk/bsd.port.mk 384.It Pa /usr/ports/Mk/bsd.sites.mk 385.It Pa /usr/share/examples/etc/make.conf 386.It Pa /usr/src/Makefile 387.It Pa /usr/src/Makefile.inc1 388.El 389.Sh EXAMPLES 390For an 391.Dq approved 392method of updating your system from the latest sources, please see the 393.Sx COMMON ITEMS 394section in 395.Pa src/UPDATING . 396.Pp 397The following sequence of commands can be used to cross-build the 398system for the sparc64 architecture on an i386 host: 399.Bd -literal -offset indent 400cd /usr/src 401make TARGET_ARCH=sparc64 buildworld 402make TARGET_ARCH=sparc64 DESTDIR=/clients/sparc64 installworld 403.Ed 404.Sh SEE ALSO 405.Xr cc 1 , 406.Xr install 1 , 407.Xr make 1 , 408.Xr make.conf 5 , 409.Xr src.conf 5 , 410.Xr ports 7 , 411.Xr release 7 , 412.Xr config 8 , 413.Xr mergemaster 8 , 414.Xr reboot 8 , 415.Xr shutdown 8 416.Sh AUTHORS 417.An Mike W. Meyer Aq mwm@mired.org . 418