BUILDING revision 1.36
1BUILDING(8) NetBSD System Manager's Manual BUILDING(8) 2 3NAME 4 BUILDING - Procedure for building NetBSD from source code. 5 6STATUS 7 This document is a work-in-progress. As such, the information described 8 here may not match the reality of the build system as of this writing. 9 Once this document is completely in sync with reality, this paragraph 10 will be removed. 11 12 Discrepancies between this documentation and the current reality of im- 13 plementation are noted specially, as with the note below: 14 15 Note: This document applies only to platforms which use the new toolchain 16 as indicated by the default setting of TOOLCHAIN_MISSING in <bsd.own.mk>. 17 Platforms which have not yet been switched to the new toolchain should 18 continue building traditionally, using the notes specified in the file 19 UPDATING. 20 21REQUIREMENTS 22 NetBSD is designed to be buildable on most POSIX-compliant host systems. 23 The basic build procedure is the same whether compiling natively (on the 24 same NetBSD architecture) or cross compiling (on another architecture or 25 OS). 26 27 This source tree contains a special subtree, ``tools'', which uses the 28 host system to create a build toolchain for the target architecture. The 29 host system must have at least C and C++ compilers in order to create the 30 toolchain (make is not required); all other tools are created as part of 31 the NetBSD build process. 32 33 Note: A couple of host toolchain components are not yet available 34 in the tools directory. Also, some tools use non-POSIX, non-ANSI C 35 extensions and need to be standardized. As a result, cross-compil- 36 ing from systems other than NetBSD is not currently supported. 37 38FILES 39 Source tree layout 40 41 doc/BUILDING.mdoc 42 This document (in -mdoc troff format; the original copy). 43 44 BUILDING This document (in plaintext). 45 46 Makefile The main Makefile for NetBSD; should only be run for na- 47 tive builds with an appropriately up-to-date version of 48 NetBSD make(1). (For building from out-of-date systems or 49 on a non-native host, see the build.sh shell script.) 50 51 UPDATING Special notes for updating from an earlier revision of 52 NetBSD. It is important to read this file before every 53 build of an updated source tree. 54 55 build.sh Bourne-compatible shell script used for building the host 56 build tools and the NetBSD system from scratch. Can be 57 used for both native and cross builds, and should be used 58 instead of make(1) for any source tree that is updated and 59 recompiled regularly. 60 61 crypto/dist/, dist/, gnu/dist/ 62 Sources imported verbatim from third parties, without man- 63 gling the existing build structure. Other source trees in 64 bin through usr.sbin use the NetBSD make(1) ``reachover'' 65 Makefile semantics when building these programs for a na- 66 tive host. 67 68 distrib/, etc/ 69 Sources for items used when making a full release snap- 70 shot, such as files installed in DESTDIR/etc on the desti- 71 nation system, boot media, and release notes. 72 73 regress/ Regression test harness. Can be cross-compiled, but only 74 run natively. 75 76 sys/ NetBSD kernel sources. 77 78 tools/ ``Reachover'' build structure for the host build tools. 79 This has a special method of determining out-of-date sta- 80 tus. 81 82 bin/ ... usr.sbin/ 83 Sources to the NetBSD userland (non-kernel) programs. If 84 any of these directories are missing, they will be skipped 85 during the build. 86 87 Build tree layout 88 The NetBSD build tree is described in hier(7), and the release layout is 89 described in release(7). 90 91CONFIGURATION 92 Environment variables 93 Several environment variables control the behaviour of NetBSD builds. 94 95 MACHINE Machine type. 96 97 MACHINE_ARCH Machine architecture. 98 99 MAKE Path name to invoke make(1) as. 100 101 MAKEFLAGS Flags to invoke make(1) with. 102 103 MAKEOBJDIR Directory to use as the .OBJDIR for the current direc- 104 tory. Used only if MAKEOBJDIRPREFIX is not defined. 105 MAKEOBJDIR can only be provided in the environment or 106 via the -M flag of build.sh. 107 108 MAKEOBJDIRPREFIX Top level directory of the object directory tree. If 109 this is defined, ${MAKEOBJDIRPREFIX}/${.CURDIR} is used 110 as the .OBJDIR for the current directory. The current 111 directory may be read only. MAKEOBJDIRPREFIX can only 112 be provided in the environment or via the -M flag of 113 build.sh. 114 115 "make" variables 116 Several variables control the behavior of NetBSD builds. Unless other- 117 wise specified, these variables may be set in either the process environ- 118 ment or the make(1) configuration file specified by MAKECONF. 119 120 BUILDID Identifier for the build. The identifier will be appended to 121 object directory names, and can be consulted in the make(1) 122 configuration file in order to set additional build parame- 123 ters, such as compiler flags. 124 125 DESTDIR Directory to contain the built NetBSD system. If set, spe- 126 cial options are passed to the compilation tools to prevent 127 their default use of the host system's /usr/include, 128 /usr/lib, and so forth. This pathname should not end with a 129 slash (/) character (for installation into the system's root 130 directory, set DESTDIR to an empty string). The directory 131 must reside on a file system which supports long file names 132 and hard links. 133 134 Default: Empty string if USETOOLS is ``yes''; unset other- 135 wise. 136 137 Note: build.sh will provide a default of destdir.MACHINE (in 138 the top-level .OBJDIR) unless run in `expert' mode 139 140 MAKECONF The name of the make(1) configuration file. Only settable in 141 the process environment. 142 143 Default: ``/etc/mk.conf'' 144 145 MKCATPAGES Can be set to ``yes'' or ``no''. Indicates whether prefor- 146 matted plaintext manual pages will be created during a build. 147 148 Default: ``yes'' 149 150 MKCRYPTO Can be set to ``yes'' or ``no''. Indicates whether crypto- 151 graphic code will be included in a build; provided for the 152 benefit of countries that do not allow strong cryptography. 153 Will not affect use of the standard low-security password en- 154 cryption system, crypt(3). 155 156 Default: ``yes'' 157 158 MKDOC Can be set to ``yes'' or ``no''. Indicates whether system 159 documentation destined for DESTDIR/usr/share/doc will be in- 160 stalled during a build. 161 162 Default: ``yes'' 163 164 MKHOSTOBJ Can be set to ``yes'' or ``no''. If set to ``yes'', then for 165 programs intended to be run on the compile host, the name, 166 release, and architecture of the host operating system will 167 be suffixed to the name of the object directory created by 168 ``make obj''. (This allows multiple host systems to compile 169 NetBSD for a single target.) If set to ``no'', then programs 170 built to be run on the compile host will use the same object 171 directory names as programs built to be run on the target. 172 173 Default: ``no'' 174 175 MKINFO Can be set to ``yes'' or ``no''. Indicates whether GNU Info 176 files, used for the documentation for most of the compilation 177 tools, will be created and installed during a build. 178 179 Default: ``yes'' 180 181 MKLINT Can be set to ``yes'' or ``no''. Indicates whether lint(1) 182 will be run against portions of the NetBSD source code during 183 the build, and whether lint libraries will be installed into 184 DESTDIR/usr/libdata/lint. 185 186 Default: ``yes'' 187 188 MKMAN Can be set to ``yes'' or ``no''. Indicates whether manual 189 pages will be installed during a build. 190 191 Default: ``yes'' 192 193 MKNLS Can be set to ``yes'' or ``no''. Indicates whether Native 194 Language System locale zone files will be compiled and in- 195 stalled during a build. 196 197 Default: ``yes'' 198 199 MKOBJ Can be set to ``yes'' or ``no''. Indicates whether object 200 directories will be created when running ``make obj''. If 201 set to ``no'', then all built files will be located inside 202 the regular source tree. 203 204 Default: ``yes'' 205 206 MKPIC Can be set to ``yes'' or ``no''. Indicates whether shared 207 objects and libraries will be created and installed during a 208 build. If set to ``no'', the entire built system will be 209 statically linked. 210 211 Default: Platform dependent. As of this writing, all plat- 212 forms except sh3 default to ``yes''. 213 214 MKPICINSTALL 215 Can be set to ``yes'' or ``no''. Indicates whether the ar(1) 216 format libraries (lib*_pic.a), used to generate shared li- 217 braries, are installed during a build. 218 219 Default: ``yes'' 220 221 MKPROFILE Can be set to ``yes'' or ``no''. Indicates whether profiled 222 libraries (lib*_p.a) will be built and installed during a 223 build. 224 225 Default: ``yes''; however, some platforms turn off MKPROFILE 226 by default at times due to toolchain problems with profiled 227 code. 228 229 MKSHARE Can be set to ``yes'' or ``no''. Indicates whether files 230 destined to reside in DESTDIR/usr/share will be built and in- 231 stalled during a build. If set to ``no'', then all of 232 MKCATPAGES, MKDOC, MKINFO, MKMAN, and MKNLS will be set to 233 ``no'' unconditionally. 234 235 Default: ``yes'' 236 237 TOOLDIR Directory to hold the host tools, once built. This directory 238 should be unique to a given host system and NetBSD source 239 tree. (However, multiple targets may share the same TOOLDIR; 240 the target-dependent files have unique names.) If unset, a 241 default based on the uname(1) information of the host plat- 242 form will be created in the .OBJDIR of src/tools. 243 244 Default: Unset. 245 246 UNPRIVED If set, then an unprivileged install will occur. The user, 247 group, permissions, and file flags, will not be set on the 248 installed item; instead the information will be appended to a 249 file called METALOG in DESTDIR. The contents of METALOG is 250 used during the generation of the distribution tar files to 251 ensure that the appropriate file ownership is stored. 252 253 Default: Unset. 254 255 UPDATE If set, then all install operations intended to write to 256 DESTDIR will compare file timestamps before installing, and 257 skip the install phase if the destination files are up-to- 258 date. This also has implications on full builds (see next 259 subsection). 260 261 Default: Unset. 262 263 USETOOLS Indicates whether the tools specified by TOOLDIR should be 264 used as part of a build in progress. Must be set to ``yes'' 265 if cross-compiling. 266 267 yes Use the tools from TOOLDIR. 268 269 no Do not use the tools from TOOLDIR, but refuse to build 270 native compilation tool components that are version- 271 specific for that tool. 272 273 never Do not use the tools from TOOLDIR, even when building 274 native tool components. This is similar to the tradi- 275 tional NetBSD build method, but does not verify that 276 the compilation tools in use are up-to-date enough in 277 order to build the tree successfully. This may cause 278 build or runtime problems when building the whole 279 NetBSD source tree. 280 281 Default: ``yes'' if building all or part of a whole NetBSD 282 source tree (detected automatically); ``no'' otherwise (to 283 preserve traditional semantics of the <bsd.*.mk> make(1) in- 284 clude files). 285 286 "make" variables for full builds 287 These variables only affect the top level ``Makefile'' and do not affect 288 manually building subtrees of the NetBSD source code. 289 290 INSTALLWORLDDIR Location for the ``make installworld'' target to install 291 to. 292 293 Default: ``/'' 294 295 MKOBJDIRS Can be set to ``yes'' or ``no''. Indicates whether ob- 296 ject directories will be created automatically (via a 297 ``make obj'' pass) at the start of a build. 298 299 Default: ``no'' 300 301 NBUILDJOBS Now obsolete. Use the make(1) option -j, instead (see 302 below) 303 304 Default: Unset. 305 306 NOCLEANDIR If set, avoids the ``make cleandir'' phase of a full 307 build. This has the effect of allowing only changed 308 files in a source tree to be recompiled. This can speed 309 up builds when updating only a few files in the tree. 310 311 Default: Unset. 312 313 NODISTRIBDIRS If set, avoids the ``make distrib-dirs'' phase of a full 314 build. This skips running mtree(8) on DESTDIR, useful 315 on systems where building as an unprivileged user, or 316 where it is known that the system-wide mtree files have 317 not changed. 318 319 Default: Unset. 320 321 NOINCLUDES If set, avoids the ``make includes'' phase of a full 322 build. This has the effect of preventing make(1) from 323 thinking that some programs are out-of-date simply be- 324 cause the system include files have changed. However, 325 this option should not be used when updating the entire 326 NetBSD source tree arbitrarily; it is suggested to use 327 UPDATE in that case. 328 329 Default: Unset. 330 331 RELEASEDIR If set, specifies the directory to which a release(7) 332 layout will be written at the end of a ``make release''. 333 334 Default: Unset. 335 336 Note: build.sh will provide a default of releasedir (in 337 the top-level .OBJDIR) unless run in `expert' mode 338 339 UPDATE If set, then in addition to the effects described for 340 UPDATE above, this implies the effects of NOCLEANDIR 341 (i.e., ``make cleandir'' is avoided). 342 343BUILDING 344 "make" command line options 345 This is only a summary of options available to make(1); only the options 346 used most frequently with NetBSD builds are listed here. 347 348 -j njob Run up to njob make(1) subjobs in parallel. Makefiles should 349 use .WAIT or have explicit dependancies as necessary to en- 350 force build ordering. If you see build failures with -j, 351 please save complete build logs so the failures can be ana- 352 lyzed. 353 354 -m dir Specify the default directory for searching for system Make- 355 file segments, mainly the <bsd.*.mk> files. When building any 356 full NetBSD source tree, this should be set to the 357 ``share/mk'' directory in the source tree. (This is set auto- 358 matically when building from the top level.) 359 360 -n Display the commands that would have been executed, but do not 361 actually execute them. This will still cause recursion to 362 take place. 363 364 -v var Print make(1)'s idea of the value of var. Does not build any 365 targets. 366 367 var=value Set the variable var to value, overriding any setting speci- 368 fied by the process environment, the MAKECONF configuration 369 file, or the system Makefile segments. 370 371 "make" targets 372 These default targets may be built by running make(1) in any subtree of 373 the NetBSD source code. It is recommended that none of these be used 374 from the top level Makefile; as a specific exception, ``make obj'' and 375 ``make cleandir'' are useful in that context. 376 377 all Build programs, libraries, and preformatted documentation. 378 379 clean Remove program and library object code files. 380 381 cleandir Same as clean, but also remove preformatted documentation, de- 382 pendency files generated by ``make depend'', and any other 383 files known to be created at build time. ``make distclean'' 384 may be used as a synonym, for familiarity with a similar well- 385 known convention. 386 387 depend Create dependency files (.depend) containing more detailed in- 388 formation about the dependencies of source code on header 389 files. Allows programs to be recompiled automatically when a 390 dependency changes. 391 392 dependall Does a ``make depend'' immediately followed by a ``make all''. 393 This improves cache locality of the build since both passes 394 read the source files in their entirety. 395 396 includes Build and install system header files. Typically needed be- 397 fore any system libraries or programs can be built. 398 399 install Install programs, libraries, and documentation into DESTDIR. 400 Few files will be installed to DESTDIR/dev, DESTDIR/etc, 401 DESTDIR/root or DESTDIR/var in order to prevent user supplied 402 configuration data from being overwritten. 403 404 lint Run lint(1) against the C source code, where appropriate, and 405 generate system-installed lint libraries. 406 407 obj Create object directories to be used for built files, instead 408 of building directly in the source tree. 409 410 tags Create ctags(1) searchable function lists usable by the ex(1) 411 and vi(1) text editors. 412 413 "make" targets for the top level 414 Additional make(1) targets are usable specifically from the top source 415 level to facilitate building the entire NetBSD source tree. 416 417 build Build the entire NetBSD system. This orders portions of 418 the source tree such that prerequisites will be built in 419 the proper order. 420 421 distribution Do a ``make build'', and then install a full distribution 422 into DESTDIR, including files in DESTDIR/dev, DESTDIR/etc, 423 DESTDIR/root and DESTDIR/var. 424 425 buildworld As per ``make distribution'', except that it ensures that 426 DESTDIR is not the root directory. 427 428 installworld Install the distribution from DESTDIR to INSTALLWORLDDIR 429 (which defaults to the root directory). Ensures that 430 INSTALLWORLDDIR is the not root directory if cross compil- 431 ing. 432 433 Note: It is highly recommended that you upgrade your kernel 434 and reboot before performing this operation. 435 436 sets Create distribution sets from DESTDIR into 437 RELEASEDIR/MACHINE/binary/sets. Should be run after ``make 438 distribution'' (as ``make build'' does not install all of 439 the required files). 440 441 sourcesets Create source sets of the source tree into 442 RELEASEDIR/source/sets. 443 444 release Do a ``make distribution'', build kernels, distribution me- 445 dia, and install sets (this as per ``make sets''), and then 446 package the system into a standard release layout as de- 447 scribed by release(7). This requires that RELEASEDIR be 448 set (see above). 449 450 regression-tests 451 Can only be run after building the regression tests in the 452 directory ``regress''. Runs the compiled regression tests 453 on the local host. 454 455 The "build.sh" script 456 This script file is a Bourne shell script designed to build the entire 457 NetBSD system on any host with a Bourne shell in /bin/sh, including many 458 that are not POSIX compliant. Note that if a host system's /bin/sh is 459 unusually old and broken, the Korn Shell (/bin/ksh), if available, may be 460 a usable alternative. 461 462 All cross-compile builds, and most native builds, of the entire system 463 should make use of build.sh rather than just running ``make''. This way, 464 the make(1) program will be bootstrapped properly, in case the host sys- 465 tem has an older or incompatible ``make'' program. 466 467 When compiling the entire system via build.sh, many make(1) variables are 468 set for you in order to help encapsulate the build process. In the list 469 of options below, variables that are automatically set by build.sh are 470 noted where applicable. 471 472 The following operations are supported by build.sh: 473 474 build Build the system as per ``make build''. This option im- 475 plies the obj and tools operations. 476 477 distribution Build a full distribution as per ``make distribution''. 478 This option implies the build operation. 479 480 release Build a full release as per ``make release''. This option 481 implies the distribution operation. 482 483 makewrapper Create the nbmake-MACHINE wrapper. This operation is auto- 484 matically performed for any of the other operations. 485 486 obj Perform ``make obj''. 487 488 tools Build and install the host tools from src/tools. 489 490 install=idir Install the contents of DESTDIR to idir, using ``make 491 installworld''. 492 493 kernel=kconf Build a new kernel. The kconf argument is the name of a 494 configuration file suitable for use by config(8). If kconf 495 does not contain any `/' characters, the configuration file 496 is expected to be found in the KERNCONFDIR directory, which 497 is typically sys/arch/MACHINE/conf. The new kernel will be 498 built in a subdirectory of KERNOBJDIR, which is typically 499 sys/arch/MACHINE/compile or an associated object directory. 500 In order to ensure that the kernel is built using up-to- 501 date tools, it is strongly recommended that the tools be 502 rebuilt (using the tools operation). 503 504 releasekernel=kconf 505 Install a gzip(1)ed copy of the kernel built by 506 kernel=kconf into RELEASEDIR/MACHINE/binary/kernel, usually 507 as netbsd-kconf.gz, although the ``netbsd'' prefix is de- 508 termined from the ``config'' directives in kconf. 509 510 sets Perform ``make sets''. 511 512 sourcesets Perform ``make sourcesets''. 513 514 The following command line options alter the behaviour of the above oper- 515 ations: The following command line options alter the behaviour of the 516 build.sh operations described above: 517 518 -a arch Set the value of MACHINE_ARCH to arch. 519 520 -B buildid 521 Set the value of BUILDID to buildid. This will also append the 522 build idenfitier to the name of the ``make'' wrapper script so 523 that the resulting name is of the form ``nbmake-MACHINE- 524 BUILDID''. 525 526 -D dest Set the value of DESTDIR to dest. 527 528 -E Set `expert' mode. This overrides various sanity checks, and 529 allows: DESTDIR does not have to be set to a non-root path for 530 builds, and UNPRIVED does not have to be set when building as a 531 non-root user. 532 533 Note: It is highly recommended that you know what you are doing 534 when you use this option. 535 536 -j njob Passed through to make(1). Makefiles should use .WAIT or have 537 explicit dependancies as necessary to enforce build ordering. 538 If you see build failures with -j, please save complete build 539 logs so the failures can be analyzed. 540 541 -M obj Set MAKEOBJDIRPREFIX to obj. 542 543 -m mach Set the value of MACHINE to mach. This will also override any 544 value of MACHINE_ARCH in the process environment with a value 545 deduced from mach, unless -a is specified, or mach is a special 546 case listed below. All cross builds require -m, but if unset 547 on a NetBSD host, the host's value of MACHINE will be detected 548 and used automatically. 549 550 Some machines support multiple values for MACHINE_ARCH. For a 551 given value of mach, the following MACHINE and MACHINE_ARCH 552 values will result: 553 554 mach MACHINE MACHINE_ARCH 555 evbmips evbmips (not set) 556 evbmips-eb evbmips mipseb 557 evbmips-el evbmips mipsel 558 evbsh3 evbsh3 (not set) 559 evbsh3-eb evbsh3 sh3eb 560 evbsh3-el evbsh3 sh3el 561 sbmips sbmips (not set) 562 sbmips-eb sbmips mipseb 563 sbmips-el sbmips mipsel 564 565 -n Show the commands that would be executed by build.sh, but do 566 not make any changes. This is similar in concept to ``make 567 -n''. 568 569 -O obj Create an appropriate transform macro for MAKEOBJDIR that will 570 place the built object files under obj. For instance, a set- 571 ting of /usr/obj will place build-time files under 572 /usr/obj/bin, /usr/obj/lib, and so forth. 573 574 -o Set the value of MKOBJDIRS to ``no''. Otherwise, it will be 575 automatically set to ``yes'' (which is opposite to the default 576 behaviour). 577 578 -R rel Set the value of RELEASEDIR to rel. 579 580 -r Remove the contents of DESTDIR and TOOLDIR before building 581 (provides a clean starting point). This will skip deleting 582 DESTDIR if building on a native system to the root directory. 583 584 -T tools Set the value of TOOLDIR to tools. If set, the bootstrap 585 ``make'' will only be rebuilt as needed (when the source files 586 for make(1) change). 587 588 -U Set the UNPRIVED variable. 589 590 -u Set the UPDATE variable. 591 592 -V var=[value] 593 Set the variable var to value (which is optional). 594 595 -w wrapper 596 Create the nbmake wrapper script (see below) in a custom loca- 597 tion, specified by wrapper. This allows, for instance, to 598 place the wrapper in PATH automatically. Note that wrapper is 599 the full name of the file, not just a directory name. 600 601 The "nbmake-MACHINE" wrapper script 602 If using the build.sh script to build NetBSD, a nbmake-MACHINE script 603 will be created in TOOLDIR/bin upon the first build to assist in building 604 subtrees on a cross-compile host. 605 606 nbmake-MACHINE can be invoked in lieu of make(1), and will instead call 607 the up-to-date version of ``nbmake'' installed into TOOLDIR/bin with sev- 608 eral key variables pre-set, including MACHINE, MACHINE_ARCH, and TOOLDIR. 609 This script can be symlinked into a directory listed in PATH, or called 610 with an absolute path. 611 612EXAMPLES 613 1. ./build.sh tools kernel=GENERIC 614 615 Build a new toolchain, and use the new toolchain to configure and 616 build a new GENERIC kernel. 617 618 2. ./build.sh -U distribution 619 620 Using unprivileged mode, build a complete distribution to a DESTDIR 621 directory that build.sh selects (and will display). 622 623 3. # ./build.sh -U install=/ 624 625 As root, install to / the distribution that was built by example 2. 626 Even though this is run as root, -U is required so that the permis- 627 sions stored in DESTDIR/METALOG are correctly applied to the files 628 as they're copied to /. 629 630 4. ./build.sh -U -u release 631 632 Using unprivileged mode, build a complete release to DESTDIR and 633 RELEASEDIR directories that build.sh selects (and will display). 634 UPDATE (-u) is set to prevent the ``make cleandir'', so that if this 635 is run after example 2, it doesn't need to redo that portion of the 636 release build. 637 638OBSOLETE VARIABLES 639 NBUILDJOBS Use the make(1) option -j, instead. 640 641 USE_NEW_TOOLCHAIN 642 The new toolchain is now the default. To disable, use 643 TOOLCHAIN_MISSING=yes. 644 645SEE ALSO 646 make(1), hier(7), release(7) 647 648HISTORY 649 The build.sh based build scheme was introduced for NetBSD 1.6 as 650 USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that. 651 652BUGS 653 A few platforms are not yet using this build system. 654 655NetBSD July 3, 2003 10 656