1BUILDING(8) NetBSD System Manager's Manual BUILDING(8) 2 3NAME 4 BUILDING -- Procedure for building NetBSD from source code. 5 6REQUIREMENTS 7 NetBSD is designed to be buildable on most POSIX-compliant host systems. 8 The basic build procedure is the same whether compiling natively (on the 9 same NetBSD architecture) or cross compiling (on another architecture or 10 OS). 11 12 This source tree contains a special subtree, ``tools'', which uses the 13 host system to create a build toolchain for the target architecture. The 14 host system must have at least C and C++ compilers in order to create the 15 toolchain (make is not required); all other tools are created as part of 16 the NetBSD build process. (See the environment variables section below 17 if you need to override or manually select your compilers.) 18 19FILES 20 Source tree layout 21 doc/BUILDING.mdoc 22 This document (in -mdoc troff format; the original copy). 23 24 BUILDING This document (in plaintext). 25 26 tools/compat/README 27 Special notes for cross-hosting a NetBSD build on non- 28 NetBSD platforms. 29 30 Makefile The main Makefile for NetBSD; should only be run for 31 native builds with an appropriately up-to-date version of 32 NetBSD make(1). (For building from out-of-date systems or 33 on a non-native host, see the build.sh shell script.) 34 35 UPDATING Special notes for updating from an earlier revision of 36 NetBSD. It is important to read this file before every 37 build of an updated source tree. 38 39 build.sh Bourne-compatible shell script used for building the host 40 build tools and the NetBSD system from scratch. Can be 41 used for both native and cross builds, and should be used 42 instead of make(1) for any source tree that is updated and 43 recompiled regularly. 44 45 crypto/dist/, dist/, gnu/dist/ 46 Sources imported verbatim from third parties, without man- 47 gling the existing build structure. Other source trees in 48 bin through usr.sbin use the NetBSD make(1) ``reachover'' 49 Makefile semantics when building these programs for a 50 native host. 51 52 distrib/, etc/ 53 Sources for items used when making a full release snap- 54 shot, such as files installed in DESTDIR/etc on the desti- 55 nation system, boot media, and release notes. 56 57 tests/, regress/ 58 Regression test harness. Can be cross-compiled, but only 59 run natively. tests/ uses the atf(7) test framework; 60 regress/ contains older tests that have not yet been 61 migrated to atf(7). 62 63 sys/ NetBSD kernel sources. 64 65 tools/ ``Reachover'' build structure for the host build tools. 66 This has a special method of determining out-of-date sta- 67 tus. 68 69 bin/ ... usr.sbin/ 70 Sources to the NetBSD userland (non-kernel) programs. If 71 any of these directories are missing, they will be skipped 72 during the build. 73 74 x11/ ``Reachover'' build structure for X11R6; the source is in 75 X11SRCDIR. 76 77 Build tree layout 78 The NetBSD build tree is described in hier(7), and the release layout is 79 described in release(7). 80 81CONFIGURATION 82 Environment variables 83 Several environment variables control the behaviour of NetBSD builds. 84 85 HOST_SH Path name to a shell available on the host system and 86 suitable for use during the build. The NetBSD build 87 system requires a modern Bourne-like shell with POSIX- 88 compliant features, and also requires support for the 89 ``local'' keyword to declare local variables in shell 90 functions (which is a widely-implemented but non-stan- 91 dardised feature). 92 93 Depending on the host system, a suitable shell may be 94 /bin/sh, /usr/xpg4/bin/sh, /bin/ksh (provided it is a 95 variant of ksh that supports the ``local'' keyword, 96 such as ksh88, but not ksh93), or /usr/local/bin/bash. 97 98 Most parts of the build require HOST_SH to be an abso- 99 lute path; however, build.sh allows it to be a simple 100 command name, which will be converted to an absolute 101 path by searching the PATH. 102 103 HOST_CC Path name to C compiler used to create the toolchain. 104 105 HOST_CXX Path name to C++ compiler used to create the toolchain. 106 107 MACHINE Machine type, e.g., ``macppc''. 108 109 MACHINE_ARCH Machine architecture, e.g., ``powerpc''. 110 111 MAKE Path name to invoke make(1) as. 112 113 MAKEFLAGS Flags to invoke make(1) with. Note that build.sh 114 ignores the value of MAKEFLAGS passed in the environ- 115 ment, but allows MAKEFLAGS to be set via the -V option. 116 117 MAKEOBJDIR Directory to use as the .OBJDIR for the current direc- 118 tory. The value is subjected to variable expansion by 119 make(1). Typical usage is to set this variable to a 120 value involving the use of `${.CURDIR:S...}' or 121 `${.CURDIR:C...}', to derive the value of .OBJDIR from 122 the value of .CURDIR. Used only if MAKEOBJDIRPREFIX is 123 not defined. MAKEOBJDIR can be provided only in the 124 environment or via the -O flag of build.sh; it cannot 125 usefully be set inside a Makefile, including mk.conf or 126 ${MAKECONF}. 127 128 MAKEOBJDIRPREFIX Top level directory of the object directory tree. The 129 value is subjected to variable expansion by make(1). 130 build.sh will create the ${MAKEOBJDIRPREFIX} directory 131 if necessary, but if make(1) is used without build.sh, 132 then rules in <bsd.obj.mk> will abort the build if the 133 ${MAKEOBJDIRPREFIX} directory does not exist. If the 134 value is defined and valid, then ${MAKEOBJDIRPRE- 135 FIX}/${.CURDIR} is used as the .OBJDIR for the current 136 directory. The current directory may be read only. 137 MAKEOBJDIRPREFIX can be provided only in the environ- 138 ment or via the -M flag of build.sh; it cannot usefully 139 be set inside a Makefile, including mk.conf or 140 ${MAKECONF}. 141 142 "make" variables 143 Several variables control the behavior of NetBSD builds. Unless other- 144 wise specified, these variables may be set in either the process environ- 145 ment or the make(1) configuration file specified by MAKECONF. 146 147 BUILDID Identifier for the build. The identifier will be appended to 148 object directory names, and can be consulted in the make(1) 149 configuration file in order to set additional build parame- 150 ters, such as compiler flags. 151 152 BUILDSEED GCC uses random numbers when compiling C++ code. This vari- 153 able seeds the gcc random number generator using the -fran- 154 dom-seed flag with this value. By default, it is set to 155 NetBSD-(majorversion). Using a fixed value causes C++ bina- 156 ries to be the same when built from the same sources, result- 157 ing in identical (reproducible) builds. Additional informa- 158 tion is available in the GCC documentation of -frandom-seed. 159 160 DESTDIR Directory to contain the built NetBSD system. If set, spe- 161 cial options are passed to the compilation tools to prevent 162 their default use of the host system's /usr/include, 163 /usr/lib, and so forth. This pathname must be an absolute 164 path, and should not end with a slash (/) character. (For 165 installation into the system's root directory, set DESTDIR to 166 an empty string, not to ``/''). The directory must reside on 167 a file system which supports long file names and hard links. 168 169 Default: Empty string if USETOOLS is ``yes''; unset other- 170 wise. 171 172 Note: build.sh will provide a default of destdir.MACHINE (in 173 the top-level .OBJDIR) unless run in `expert' mode. 174 175 MAKECONF The name of the make(1) configuration file. Only settable in 176 the process environment. 177 178 Default: ``/etc/mk.conf'' 179 180 MAKEVERBOSE 181 Level of verbosity of status messages. Supported values: 182 183 0 No descriptive messages or commands executed by make(1) 184 are shown. 185 186 1 Brief messages are shown describing what is being done, 187 but the actual commands executed by make(1) are not dis- 188 played. 189 190 2 Descriptive messages are shown as above (prefixed with a 191 `#'), and ordinary commands performed by make(1) are 192 displayed. 193 194 3 In addition to the above, all commands performed by 195 make(1) are displayed, even if they would ordinarily 196 have been hidden through use of the ``@'' prefix in the 197 relevant makefile. 198 199 4 In addition to the above, commands executed by make(1) 200 are traced through use of the sh(1) ``-x'' flag. 201 202 Default: 2 203 204 MKCATPAGES Can be set to ``yes'' or ``no''. Indicates whether prefor- 205 matted plaintext manual pages will be created during a build. 206 207 Default: ``yes'' 208 209 MKCRYPTO Can be set to ``yes'' or ``no''. Indicates whether crypto- 210 graphic code will be included in a build; provided for the 211 benefit of countries that do not allow strong cryptography. 212 Will not affect use of the standard low-security password 213 encryption system, crypt(3). 214 215 Default: ``yes'' 216 217 MKDOC Can be set to ``yes'' or ``no''. Indicates whether system 218 documentation destined for DESTDIR/usr/share/doc will be 219 installed during a build. 220 221 Default: ``yes'' 222 223 MKHTML Can be set to ``yes'' or ``no''. Indicates whether prefor- 224 matted HTML manual pages will be built and installed 225 226 Default: ``yes'' 227 228 MKHOSTOBJ Can be set to ``yes'' or ``no''. If set to ``yes'', then for 229 programs intended to be run on the compile host, the name, 230 release, and architecture of the host operating system will 231 be suffixed to the name of the object directory created by 232 ``make obj''. (This allows multiple host systems to compile 233 NetBSD for a single target.) If set to ``no'', then programs 234 built to be run on the compile host will use the same object 235 directory names as programs built to be run on the target. 236 237 Default: ``no'' 238 239 MKINFO Can be set to ``yes'' or ``no''. Indicates whether GNU Info 240 files, used for the documentation for most of the compilation 241 tools, will be created and installed during a build. 242 243 Default: ``yes'' 244 245 MKKMOD Can be set to ``yes'' or ``no''. Indicates whether kernel 246 modules are built and installed. 247 248 Default: ``yes'' 249 250 MKLINT Can be set to ``yes'' or ``no''. Indicates whether lint(1) 251 will be run against portions of the NetBSD source code during 252 the build, and whether lint libraries will be installed into 253 DESTDIR/usr/libdata/lint. 254 255 Default: ``yes'' 256 257 MKMAN Can be set to ``yes'' or ``no''. Indicates whether manual 258 pages will be installed during a build. 259 260 Default: ``yes'' 261 262 MKNLS Can be set to ``yes'' or ``no''. Indicates whether Native 263 Language System locale zone files will be compiled and 264 installed during a build. 265 266 Default: ``yes'' 267 268 MKOBJ Can be set to ``yes'' or ``no''. Indicates whether object 269 directories will be created when running ``make obj''. If 270 set to ``no'', then all built files will be located inside 271 the regular source tree. 272 273 Default: ``yes'' 274 275 Note that setting MKOBJ to ``no'' is not recommended and may 276 cause problems when updating the tree with cvs(1). 277 278 MKPIC Can be set to ``yes'' or ``no''. Indicates whether shared 279 objects and libraries will be created and installed during a 280 build. If set to ``no'', the entire built system will be 281 statically linked. 282 283 Default: Platform dependent. As of this writing, all plat- 284 forms except sh3 default to ``yes''. 285 286 MKPICINSTALL 287 Can be set to ``yes'' or ``no''. Indicates whether the ar(1) 288 format libraries (lib*_pic.a), used to generate shared 289 libraries, are installed during a build. 290 291 Default: ``yes'' 292 293 MKPROFILE Can be set to ``yes'' or ``no''. Indicates whether profiled 294 libraries (lib*_p.a) will be built and installed during a 295 build. 296 297 Default: ``yes''; however, some platforms turn off MKPROFILE 298 by default at times due to toolchain problems with profiled 299 code. 300 301 MKSHARE Can be set to ``yes'' or ``no''. Indicates whether files 302 destined to reside in DESTDIR/usr/share will be built and 303 installed during a build. If set to ``no'', then all of 304 MKCATPAGES, MKDOC, MKINFO, MKMAN, and MKNLS will be set to 305 ``no'' unconditionally. 306 307 Default: ``yes'' 308 309 MKSTRIPIDENT 310 Can be set to ``yes'' or ``no''. Indicates whether program 311 binaries and shared libraries should be built to include RCS 312 IDs for use with ident(1). 313 314 Default: ``no'' 315 316 MKUNPRIVED Can be set to ``yes'' or ``no''. Indicates whether an 317 unprivileged install will occur. The user, group, permis- 318 sions, and file flags, will not be set on the installed 319 items; instead the information will be appended to a file 320 called METALOG in DESTDIR. The contents of METALOG are used 321 during the generation of the distribution tar files to ensure 322 that the appropriate file ownership is stored. 323 324 Default: ``no'' 325 326 MKUPDATE Can be set to ``yes'' or ``no''. Indicates whether all 327 install operations intended to write to DESTDIR will compare 328 file timestamps before installing, and skip the install phase 329 if the destination files are up-to-date. This also has 330 implications on full builds (see next subsection). 331 332 Default: ``no'' 333 334 MKX11 Can be set to ``yes'' or ``no''. Indicates whether X11 is 335 built from X11SRCDIR. 336 337 Default: ``no'' 338 339 TOOLDIR Directory to hold the host tools, once built. If specified, 340 must be an absolute path. This directory should be unique to 341 a given host system and NetBSD source tree. (However, multi- 342 ple targets may share the same TOOLDIR; the target-dependent 343 files have unique names.) If unset, a default based on the 344 uname(1) information of the host platform will be created in 345 the .OBJDIR of src. 346 347 Default: Unset. 348 349 USETOOLS Indicates whether the tools specified by TOOLDIR should be 350 used as part of a build in progress. Must be set to ``yes'' 351 if cross-compiling. 352 353 yes Use the tools from TOOLDIR. 354 355 no Do not use the tools from TOOLDIR, but refuse to build 356 native compilation tool components that are version- 357 specific for that tool. 358 359 never Do not use the tools from TOOLDIR, even when building 360 native tool components. This is similar to the tradi- 361 tional NetBSD build method, but does not verify that 362 the compilation tools in use are up-to-date enough in 363 order to build the tree successfully. This may cause 364 build or runtime problems when building the whole 365 NetBSD source tree. 366 367 Default: ``yes'', unless TOOLCHAIN_MISSING is set to ``yes''. 368 369 USETOOLS is also set to ``no'' when using <bsd.*.mk> outside 370 the NetBSD source tree. 371 372 X11SRCDIR Directory containing the X11R6 source. If specified, must be 373 an absolute path. The main X11R6 source is found in 374 X11SRCDIR/xfree/xc. 375 376 Default: NETBSDRCDIR/../xsrc, if that exists; otherwise 377 /usr/xsrc. 378 379 X11FLAVOUR The style of X11 cross-built, set to either ``Xorg'' or 380 ``XFree86''. 381 382 Default: ``Xorg'' on amd64, i386, macppc, shark and sparc64 383 platforms, ``XFree86'' on everything else. 384 385 "make" variables for full builds 386 These variables only affect the top level ``Makefile'' and do not affect 387 manually building subtrees of the NetBSD source code. 388 389 INSTALLWORLDDIR Location for the ``make installworld'' target to install 390 to. If specified, must be an absolute path. 391 392 Default: ``/'' 393 394 MKOBJDIRS Can be set to ``yes'' or ``no''. Indicates whether 395 object directories will be created automatically (via a 396 ``make obj'' pass) at the start of a build. 397 398 Default: ``no'' 399 400 If using build.sh, the default is ``yes''. This may be 401 set back to ``no'' by giving build.sh the -o option. 402 403 MKUPDATE Can be set to ``yes'' or ``no''. If set, then in addi- 404 tion to the effects described for MKUPDATE=yes above, 405 this implies the effects of NOCLEANDIR (i.e., ``make 406 cleandir'' is avoided). 407 408 Default: ``no'' 409 410 If using build.sh, this may be set by giving the -u 411 option. 412 413 NBUILDJOBS Now obsolete. Use the make(1) option -j, instead. See 414 below. 415 416 Default: Unset. 417 418 NOCLEANDIR If set, avoids the ``make cleandir'' phase of a full 419 build. This has the effect of allowing only changed 420 files in a source tree to be recompiled. This can speed 421 up builds when updating only a few files in the tree. 422 423 Default: Unset. 424 425 See also MKUPDATE. 426 427 NODISTRIBDIRS If set, avoids the ``make distrib-dirs'' phase of a full 428 build. This skips running mtree(8) on DESTDIR, useful 429 on systems where building as an unprivileged user, or 430 where it is known that the system-wide mtree files have 431 not changed. 432 433 Default: Unset. 434 435 NOINCLUDES If set, avoids the ``make includes'' phase of a full 436 build. This has the effect of preventing make(1) from 437 thinking that some programs are out-of-date simply 438 because the system include files have changed. However, 439 this option should not be used when updating the entire 440 NetBSD source tree arbitrarily; it is suggested to use 441 MKUPDATE=yes instead in that case. 442 443 Default: Unset. 444 445 RELEASEDIR If set, specifies the directory to which a release(7) 446 layout will be written at the end of a ``make release''. 447 If specified, must be an absolute path. 448 449 Default: Unset. 450 451 Note: build.sh will provide a default of releasedir (in 452 the top-level .OBJDIR) unless run in `expert' mode. 453 454BUILDING 455 "make" command line options 456 This is not a summary of all the options available to make(1); only the 457 options used most frequently with NetBSD builds are listed here. 458 459 -j njob Run up to njob make(1) subjobs in parallel. Makefiles should 460 use .WAIT or have explicit dependencies as necessary to 461 enforce build ordering. 462 463 -m dir Specify the default directory for searching for system Make- 464 file segments, mainly the <bsd.*.mk> files. When building any 465 full NetBSD source tree, this should be set to the 466 ``share/mk'' directory in the source tree. This is set auto- 467 matically when building from the top level, or when using 468 build.sh. 469 470 -n Display the commands that would have been executed, but do not 471 actually execute them. This will still cause recursion to 472 take place. 473 474 -V var Print make(1)'s idea of the value of var. Does not build any 475 targets. 476 477 var=value Set the variable var to value, overriding any setting speci- 478 fied by the process environment, the MAKECONF configuration 479 file, or the system Makefile segments. 480 481 "make" targets 482 These default targets may be built by running make(1) in any subtree of 483 the NetBSD source code. It is recommended that none of these be used 484 from the top level Makefile; as a specific exception, ``make obj'' and 485 ``make cleandir'' are useful in that context. 486 487 all Build programs, libraries, and preformatted documentation. 488 489 clean Remove program and library object code files. 490 491 cleandir Same as clean, but also remove preformatted documentation, 492 dependency files generated by ``make depend'', and any other 493 files known to be created at build time. 494 495 depend Create dependency files (.depend) containing more detailed 496 information about the dependencies of source code on header 497 files. Allows programs to be recompiled automatically when a 498 dependency changes. 499 500 dependall Does a ``make depend'' immediately followed by a ``make all''. 501 This improves cache locality of the build since both passes 502 read the source files in their entirety. 503 504 distclean Synonym for cleandir. 505 506 includes Build and install system header files. Typically needed 507 before any system libraries or programs can be built. 508 509 install Install programs, libraries, and documentation into DESTDIR. 510 Few files will be installed to DESTDIR/dev, DESTDIR/etc, 511 DESTDIR/root or DESTDIR/var in order to prevent user supplied 512 configuration data from being overwritten. 513 514 lint Run lint(1) against the C source code, where appropriate, and 515 generate system-installed lint libraries. 516 517 obj Create object directories to be used for built files, instead 518 of building directly in the source tree. 519 520 tags Create ctags(1) searchable function lists usable by the ex(1) 521 and vi(1) text editors. 522 523 "make" targets for the top level 524 Additional make(1) targets are usable specifically from the top source 525 level to facilitate building the entire NetBSD source tree. 526 527 build Build the entire NetBSD system (except the kernel). This 528 orders portions of the source tree such that prerequisites 529 will be built in the proper order. 530 531 distribution Do a ``make build'', and then install a full distribution 532 (which does not include a kernel) into DESTDIR, including 533 files in DESTDIR/dev, DESTDIR/etc, DESTDIR/root and 534 DESTDIR/var. 535 536 buildworld As per ``make distribution'', except that it ensures that 537 DESTDIR is not the root directory. 538 539 installworld Install the distribution from DESTDIR to INSTALLWORLDDIR, 540 which defaults to the root directory. Ensures that 541 INSTALLWORLDDIR is not the root directory if cross compil- 542 ing. 543 544 The INSTALLSETS environment variable may be set to a space- 545 separated list of distribution sets to be installed. By 546 default, all sets except ``etc'' and ``xetc'' are 547 installed, so most files in INSTALLWORLDDIR/etc will not be 548 installed or modified. 549 550 Note: Before performing this operation with 551 INSTALLWORLDDIR=/, it is highly recommended that you 552 upgrade your kernel and reboot. After performing this 553 operation, it is recommended that you use etcupdate(8) to 554 update files in INSTALLWORLDDIR/etc and that you use 555 postinstall(8) to check for inconsistencies (and possibly 556 to fix them). 557 558 sets Create distribution sets from DESTDIR into 559 RELEASEDIR/RELEASEMACHINEDIR/binary/sets. Should be run 560 after ``make distribution'', as ``make build'' alone does 561 not install all of the required files. 562 563 sourcesets Create source sets of the source tree into 564 RELEASEDIR/source/sets. 565 566 syspkgs Create syspkgs from DESTDIR into 567 RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs. Should be run 568 after ``make distribution'', as ``make build'' alone does 569 not install all of the required files. 570 571 release Do a ``make distribution'', build kernels, distribution 572 media, and install sets (this as per ``make sets''), and 573 then package the system into a standard release layout as 574 described by release(7). This requires that RELEASEDIR be 575 set (see above). 576 577 iso-image Create a NetBSD installation CD-ROM image in the 578 RELEASEDIR/iso directory. The CD-ROM file system will have 579 a layout as described in release(7). 580 581 For most machine types, the CD-ROM will be bootable, and 582 will automatically run the sysinst(8) menu-based installa- 583 tion program, which can be used to install or upgrade a 584 NetBSD system. Bootable CD-ROMs also contain tools that 585 may be useful in repairing a damaged NetBSD installation. 586 587 Before ``make iso-image'' is attempted, RELEASEDIR must be 588 populated by ``make release'' or equivalent. 589 590 Note that other, smaller, CD-ROM images may be created in 591 the RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom direc- 592 tory by ``make release''. These smaller images usually 593 contain the same tools as the larger images in 594 RELEASEDIR/iso, but do not contain additional content such 595 as the distribution sets. 596 597 Note that the mac68k port still uses an older method of 598 creating CD-ROM images. This requires the mkisofs(1) util- 599 ity, which is not part of NetBSD, but which can be 600 installed from pkgsrc/sysutils/cdrtools. 601 602 iso-image-source 603 Create a NetBSD installation CD-ROM image in the 604 RELEASEDIR/iso directory. The CD-ROM file system will have 605 a layout as described in release(7). It will have top 606 level directories for the machine type and source. 607 608 For most machine types, the CD-ROM will be bootable, and 609 will automatically run the sysinst(8) menu-based installa- 610 tion program, which can be used to install or upgrade a 611 NetBSD system. Bootable CD-ROMs also contain tools that 612 may be useful in repairing a damaged NetBSD installation. 613 614 Before ``make iso-image-source'' is attempted, RELEASEDIR 615 must be populated by ``make sourcesets release'' or equiva- 616 lent. 617 618 Note that other, smaller, CD-ROM images may be created in 619 the RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom direc- 620 tory by ``make release''. These smaller images usually 621 contain the same tools as the larger images in 622 RELEASEDIR/iso, but do not contain additional content such 623 as the distribution sets. 624 625 Note that the mac68k port still uses an older method of 626 creating CD-ROM images. This requires the mkisofs(1) util- 627 ity, which is not part of NetBSD, but which can be 628 installed from pkgsrc/sysutils/cdrtools. 629 630 install-image 631 Create a bootable NetBSD installation disk image in the 632 RELEASEDIR/RELEASEMACHINEDIR/installation/installimage 633 directory. The installation disk image is suitable for 634 copying to bootable USB flash memory sticks, etc., for 635 machines which are able to boot from such devices. The 636 file system in the bootable disk image will have a layout 637 as described in release(7). 638 639 The installation image is bootable, and will automatically 640 run the sysinst(8) menu-based installation program, which 641 can be used to install or upgrade a NetBSD system. The 642 image also contains tools that may be useful in repairing a 643 damaged NetBSD installation. 644 645 Before ``make install-image'' is attempted, RELEASEDIR must 646 be populated by ``make release'' or equivalent. The build 647 must have been performed with MKUNPRIVED=yes because ``make 648 install-image'' relies on information in DESTDIR/METALOG. 649 650 live-image Create NetBSD live images in the 651 RELEASEDIR/RELEASEMACHINEDIR/installation/liveimage direc- 652 tory. The live image contains all necessary files to boot 653 NetBSD up to multi-user mode, including all files which 654 should be extracted during installation, NetBSD disklabel, 655 bootloaders, etc. 656 657 The live image is suitable for use as a disk image in vir- 658 tual machine environments such as QEMU, and also useful to 659 boot NetBSD from a USB flash memory stick on a real 660 machine, without the need for installation. 661 662 Before ``make live-image'' is attempted, RELEASEDIR must be 663 populated by ``make release'' or equivalent. The build 664 must have been performed with MKUNPRIVED=yes because ``make 665 install-image'' relies on information in DESTDIR/METALOG. 666 667 regression-tests 668 Can only be run after building the regression tests in the 669 directory ``regress''. Runs those compiled regression 670 tests on the local host. Note that most tests are now man- 671 aged instead using atf(7); this target should probably run 672 those as well but currently does not. 673 674 The "build.sh" script 675 This script file is a shell script designed to build the entire NetBSD 676 system on any host with a suitable modern shell and some common utili- 677 ties. The required shell features are described under the HOST_SH vari- 678 able. 679 680 If a host system's default shell does support the required features, then 681 we suggest that you explicitly specify a suitable shell using a command 682 like 683 684 /path/to/suitable/shell build.sh [options] 685 686 The above command will usually enable build.sh to automatically set 687 HOST_SH=/path/to/suitable/shell, but if that fails, then the following 688 set of commands may be used instead: 689 690 HOST_SH=/path/to/suitable/shell 691 export HOST_SH 692 ${HOST_SH} build.sh [options] 693 694 If build.sh detects that it is being executed under an unsuitable shell, 695 it attempts to exec a suitable shell instead, or prints an error message. 696 If HOST_SH is not set explicitly, then build.sh sets a default using 697 heuristics dependent on the host platform, or from the shell under which 698 build.sh is executed (if that can be determined), or using the first copy 699 of sh found in PATH. 700 701 All cross-compile builds, and most native builds, of the entire system 702 should make use of build.sh rather than just running ``make''. This way, 703 the make(1) program will be bootstrapped properly, in case the host sys- 704 tem has an older or incompatible ``make'' program. 705 706 When compiling the entire system via build.sh, many make(1) variables are 707 set for you in order to help encapsulate the build process. In the list 708 of options below, variables that are automatically set by build.sh are 709 noted where applicable. 710 711 The following operations are supported by build.sh: 712 713 build Build the system as per ``make build''. Before the main 714 part of the build commences, this command runs the obj 715 operation (unless the -o option is given), ``make 716 cleandir'' (unless the -u option is given), and the tools 717 operation. 718 719 distribution Build a full distribution as per ``make distribution''. 720 This command first runs the build operation. 721 722 release Build a full release as per ``make release''. This command 723 first runs the distribution operation. 724 725 makewrapper Create the nbmake-MACHINE wrapper. This operation is auto- 726 matically performed for any of the other operations. 727 728 cleandir Perform ``make cleandir''. 729 730 obj Perform ``make obj''. 731 732 tools Build and install the host tools from src/tools. This com- 733 mand will first run ``make obj'' and ``make cleandir'' in 734 the tools subdirectory unless the -o or -u options (respec- 735 tively) are given. 736 737 install=idir Install the contents of DESTDIR to idir, using ``make 738 installworld''. Note that files that are part of the 739 ``etc'' or ``xetc'' sets will not be installed, unless 740 overridden by the INSTALLSETS environment variable. 741 742 kernel=kconf Build a new kernel. The kconf argument is the name of a 743 configuration file suitable for use by config(1). If kconf 744 does not contain any `/' characters, the configuration file 745 is expected to be found in the KERNCONFDIR directory, which 746 is typically sys/arch/MACHINE/conf. The new kernel will be 747 built in a subdirectory of KERNOBJDIR, which is typically 748 sys/arch/MACHINE/compile or an associated object directory. 749 750 This command does not imply the tools command; run the 751 tools command first unless it is certain that the tools 752 already exist and are up to date. 753 754 This command will run ``make cleandir'' on the kernel in 755 question first unless the -u option is given. 756 757 modules This command will build kernel modules and install them 758 into DESTDIR. 759 760 releasekernel=kconf 761 Install a gzip(1)ed copy of the kernel previously built by 762 kernel=kconf into 763 RELEASEDIR/RELEASEMACHINEDIR/binary/kernel, usually as 764 netbsd-kconf.gz, although the ``netbsd'' prefix is deter- 765 mined from the ``config'' directives in kconf. 766 767 sets Perform ``make sets''. 768 769 sourcesets Perform ``make sourcesets''. 770 771 syspkgs Perform ``make syspkgs''. 772 773 iso-image Perform ``make iso-image''. 774 775 iso-image-source 776 Perform ``make iso-image-source''. 777 778 install-image 779 Perform ``make install-image''. 780 781 live-image Perform ``make live-image''. 782 783 The following command line options alter the behaviour of the build.sh 784 operations described above: 785 786 -a arch Set the value of MACHINE_ARCH to arch. 787 788 -B buildid 789 Set the value of BUILDID to buildid. This will also append the 790 build identifier to the name of the ``make'' wrapper script so 791 that the resulting name is of the form 792 ``nbmake-MACHINE-BUILDID''. 793 794 -C cdextras 795 Append cdextras to the CDEXTRA variable, which is a space-sepa- 796 rated list of files or directories that will be added to the 797 CD-ROM image that may be create by the ``iso-image'' or 798 ``iso-image-source'' operations. Files will be added to the 799 root of the CD-ROM image, whereas directories will be copied 800 recursively. If relative paths are specified, they will be 801 converted to absolute paths before being used. Multiple paths 802 may be specified via multiple -C options, or via a single 803 option whose argument contains multiple space-separated paths. 804 805 -D dest Set the value of DESTDIR to dest. If a relative path is speci- 806 fied, it will be converted to an absolute path before being 807 used. 808 809 -E Set `expert' mode. This overrides various sanity checks, and 810 allows: DESTDIR does not have to be set to a non-root path for 811 builds, and MKUNPRIVED=yes does not have to be set when build- 812 ing as a non-root user. 813 814 Note: It is highly recommended that you know what you are doing 815 when you use this option. 816 817 -h Print a help message. 818 819 -j njob Run up to njob make(1) subjobs in parallel; passed through to 820 make(1). If you see failures for reasons other than running 821 out of memory while using build.sh with -j, please save com- 822 plete build logs so the failures can be analyzed. 823 824 To achieve the fastest builds, -j values between (1 + the num- 825 ber of CPUs) and (2 * the number of CPUs) are recommended. Use 826 lower values on machines with limited memory or I/O bandwidth. 827 828 -M obj Set MAKEOBJDIRPREFIX to obj. Unsets MAKEOBJDIR. See ``-O 829 -obj'' for more information. 830 831 For instance, if the source directory is /usr/src, a setting of 832 ``-M /usr/obj'' will place build-time files under 833 /usr/obj/usr/src/bin, /usr/obj/usr/src/lib, 834 /usr/obj/usr/src/usr.bin, and so forth. 835 836 If a relative path is specified, it will be converted to an 837 absolute path before being used. build.sh imposes the restric- 838 tion that the argument to the -M option must not begin with a 839 ``$'' (dollar sign) character; otherwise it would be too diffi- 840 cult to determine whether the value is an absolute or a rela- 841 tive path. If the directory does not already exist, build.sh 842 will create it. 843 844 -m mach Set the value of MACHINE to mach, except in some special cases 845 listed below. This will also override any value of 846 MACHINE_ARCH in the process environment with a value deduced 847 from mach, unless -a is specified. All cross builds require 848 -m, but if unset on a NetBSD host, the host's value of MACHINE 849 will be detected and used automatically. 850 851 Some machines support multiple values for MACHINE_ARCH. The 852 following special cases for the mach argument are defined to 853 set the listed values of MACHINE and MACHINE_ARCH: 854 855 mach MACHINE MACHINE_ARCH 856 evbarm evbarm (not set) 857 evbarm-eb evbarm armeb 858 evbarm-el evbarm arm 859 evbmips evbmips (not set) 860 evbmips-eb evbmips mipseb 861 evbmips-el evbmips mipsel 862 evbsh3 evbsh3 (not set) 863 evbsh3-eb evbsh3 sh3eb 864 evbsh3-el evbsh3 sh3el 865 sbmips sbmips (not set) 866 sbmips-eb sbmips mipseb 867 sbmips-el sbmips mipsel 868 869 -N noiselevel 870 Set the ``noisyness'' level of the build, by setting 871 MAKEVERBOSE to noiselevel. 872 873 -n Show the commands that would be executed by build.sh, but do 874 not make any changes. This is similar in concept to ``make 875 -n''. 876 877 -O obj Create an appropriate transform macro for MAKEOBJDIR that will 878 place the built object files under obj. Unsets 879 MAKEOBJDIRPREFIX. 880 881 For instance, a setting of ``-O /usr/obj'' will place build- 882 time files under /usr/obj/bin, /usr/obj/lib, /usr/obj/usr.bin, 883 and so forth. 884 885 If a relative path is specified, it will be converted to an 886 absolute path before being used. build.sh imposes the restric- 887 tion that the argument to the -O option must not contain a 888 ``$'' (dollar sign) character. If the directory does not 889 already exist, build.sh will create it. 890 891 In normal use, exactly one of the -M or -O options should be 892 specified. If neither -M nor -O is specified, then a default 893 object directory will be chosen according to rules in 894 <bsd.obj.mk>. Relying on this default is not recommended 895 because it is determined by complex rules that are influenced 896 by the values of several variables and by the location of the 897 source directory. 898 899 -o Set the value of MKOBJDIRS to ``no''. Otherwise, it will be 900 automatically set to ``yes''. This default is opposite to the 901 behaviour when not using build.sh. 902 903 -R rel Set the value of RELEASEDIR to rel. If a relative path is 904 specified, it will be converted to an absolute path before 905 being used. 906 907 -r Remove the contents of DESTDIR and TOOLDIR before building 908 (provides a clean starting point). This will skip deleting 909 DESTDIR if building on a native system to the root directory. 910 911 -S seed Change the value of BUILDSEED to seed. This should rarely be 912 necessary. 913 914 -T tools Set the value of TOOLDIR to tools. If a relative path is spec- 915 ified, it will be converted to an absolute path before being 916 used. If set, the bootstrap ``make'' will only be rebuilt if 917 the source files for make(1) have changed. 918 919 -U Set MKUNPRIVED=yes. 920 921 -u Set MKUPDATE=yes. 922 923 -V var=[value] 924 Set the environment variable var to an optional value. This is 925 propagated to the nbmake wrapper. 926 927 -w wrapper 928 Create the nbmake wrapper script (see below) in a custom loca- 929 tion, specified by wrapper. This allows, for instance, to 930 place the wrapper in PATH automatically. Note that wrapper is 931 the full name of the file, not just a directory name. If a 932 relative path is specified, it will be converted to an absolute 933 path before being used. 934 935 -X x11src 936 Set the value of X11SRCDIR to x11src. If a relative path is 937 specified, it will be converted to an absolute path before 938 being used. 939 940 -x Set MKX11=yes. 941 942 -Z var Unset ("zap") the environment variable var. This is propagated 943 to the nbmake wrapper. 944 945 The "nbmake-MACHINE" wrapper script 946 If using the build.sh script to build NetBSD, a nbmake-MACHINE script 947 will be created in TOOLDIR/bin upon the first build to assist in building 948 subtrees on a cross-compile host. 949 950 nbmake-MACHINE can be invoked in lieu of make(1), and will instead call 951 the up-to-date version of ``nbmake'' installed into TOOLDIR/bin with sev- 952 eral key variables pre-set, including MACHINE, MACHINE_ARCH, and TOOLDIR. 953 nbmake-MACHINE will also set variables specified with -V, and unset vari- 954 ables specified with -Z. 955 956 This script can be symlinked into a directory listed in PATH, or called 957 with an absolute path. 958 959EXAMPLES 960 1. % ./build.sh [options] tools kernel=GENERIC 961 962 Build a new toolchain, and use the new toolchain to configure and 963 build a new GENERIC kernel. 964 965 2. % ./build.sh [options] -U distribution 966 967 Using unprivileged mode, build a complete distribution to a DESTDIR 968 directory that build.sh selects (and will display). 969 970 3. # ./build.sh [options] -U install=/ 971 972 As root, install to / the distribution that was built by example 2. 973 Even though this is run as root, -U is required so that the permis- 974 sions stored in DESTDIR/METALOG are correctly applied to the files 975 as they're copied to /. 976 977 4. % ./build.sh [options] -U -u release 978 979 Using unprivileged mode, build a complete release to DESTDIR and 980 RELEASEDIR directories that build.sh selects (and will display). 981 MKUPDATE=yes (-u) is set to prevent the ``make cleandir'', so that 982 if this is run after example 2, it doesn't need to redo that portion 983 of the release build. 984 985OBSOLETE VARIABLES 986 NBUILDJOBS Use the make(1) option -j instead. 987 988 USE_NEW_TOOLCHAIN 989 The new toolchain is now the default. To disable, use 990 TOOLCHAIN_MISSING=yes. 991 992SEE ALSO 993 make(1), hier(7), release(7), etcupdate(8), postinstall(8), sysinst(8), 994 pkgsrc/sysutils/cdrtools 995 996HISTORY 997 The build.sh based build scheme was introduced for NetBSD 1.6 as 998 USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that. 999 1000NetBSD September 9, 2011 NetBSD 1001