BUILDING revision 1.153
1BUILDING(8) 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 host 13 system to create a build toolchain for the target architecture. The host 14 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 BUILDING This document (in plaintext). Generated from 22 doc/BUILDING.mdoc. 23 24 Makefile The main Makefile for NetBSD; should only be run for 25 native builds with an appropriately up-to-date version of 26 NetBSD make(1). Intended for expert use with knowledge of 27 its shortcomings, it has been superseded by the build.sh 28 shell script as the recommended means for building NetBSD. 29 30 UPDATING Special notes for updating from an earlier revision of 31 NetBSD. It is important to read this file before every 32 build of an updated source tree. 33 34 build.sh Bourne-compatible shell script used for building the host 35 build tools and the NetBSD system from scratch. Can be 36 used for both native and cross builds, and should be used 37 instead of make(1) as it performs additional checks to 38 prevent common issues going undetected, such as building 39 with an outdated version of make(1). 40 41 crypto/dist/, dist/, gnu/dist/ 42 Sources imported verbatim from third parties, without 43 mangling the existing build structure. Other source trees 44 in bin through usr.sbin use the NetBSD make(1) "reachover" 45 Makefile semantics when building these programs for a 46 native host. 47 48 distrib/, etc/ 49 Sources for items used when making a full release 50 snapshot, such as files installed in DESTDIR/etc on the 51 destination system, boot media, and release notes. 52 53 doc/BUILDING.mdoc 54 This document, in -mdoc troff format; the original copy. 55 Used to generate BUILDING. 56 57 external, sys/external 58 Sources and build infrastructure for components imported 59 (mostly) unchanged from upstream maintainers, sorted by 60 applicable license. This is (slowly) replacing the 61 crypto/dist, dist, and gnu/dist directories. 62 63 external/mit/xorg/ 64 "Reachover" build structure for modular Xorg; the source 65 is in X11SRCDIR. 66 67 regress/, tests/ 68 Regression test harness. Can be cross-compiled, but only 69 run natively. tests/ uses the atf(7) test framework; 70 regress/ contains older tests that have not yet been 71 migrated to atf(7). 72 73 sys/ NetBSD kernel sources. 74 75 tools/ "Reachover" build structure for the host build tools. 76 This has a special method of determining out-of-date 77 status. 78 79 tools/compat/README 80 Special notes for cross-hosting a NetBSD build on non- 81 NetBSD platforms. 82 83 Other directories including bin/ ... usr.sbin/ 84 Sources to the NetBSD userland (non-kernel) programs. If 85 any of these directories are missing, they will be skipped 86 during the build. 87 88 Build tree layout 89 The NetBSD build tree is described in hier(7), and the release layout is 90 described in release(7). 91 92CONFIGURATION 93 Environment variables 94 Several environment variables control the behaviour of NetBSD builds. 95 96 HOST_CC Path name to C compiler used to create the toolchain. 97 98 HOST_CFLAGS Flags passed to the host C compiler. 99 100 HOST_CXX Path name to C++ compiler used to create the toolchain. 101 102 HOST_CXXFLAGS Flags passed to the host C++ compiler. 103 104 HOST_SH Path name to a shell available on the host system and 105 suitable for use during the build. The NetBSD build 106 system requires a modern Bourne-like shell with POSIX- 107 compliant features, and also requires support for the 108 "local" keyword to declare local variables in shell 109 functions (which is a widely-implemented but non- 110 standardised feature). 111 112 Depending on the host system, a suitable shell may be 113 /bin/sh, /usr/xpg4/bin/sh, /bin/ksh (provided it is a 114 variant of ksh that supports the "local" keyword, such as 115 ksh88, but not ksh93), or /usr/local/bin/bash. 116 117 Most parts of the build require HOST_SH to be an absolute 118 path; however, build.sh allows it to be a simple command 119 name, which will be converted to an absolute path by 120 searching the PATH. 121 122 INSTALLBOOT_UBOOT_PATHS 123 A colon-separated list of search paths used by 124 installboot(8) to find U-Boot packages. 125 126 MACHINE Machine type, e.g., "macppc". 127 128 MACHINE_ARCH Machine architecture, e.g., "powerpc". 129 130 MAKE Path name to invoke make(1) as. 131 132 MAKECONF The name of the make(1) configuration file. See "make" 133 variables and mk.conf(5). 134 135 Note: Only settable in the process environment. 136 137 Default: "/etc/mk.conf" 138 139 MAKEFLAGS Flags to invoke make(1) with. 140 141 Note: build.sh ignores the value of MAKEFLAGS passed in 142 the environment, but allows MAKEFLAGS to be set via the 143 -V option. 144 145 MAKEOBJDIR Directory to use as the .OBJDIR for the current 146 directory. The value is subjected to variable expansion 147 by make(1). Typical usage is to set this variable to a 148 value involving the use of `${.CURDIR:S...}' or 149 `${.CURDIR:C...}', to derive the value of .OBJDIR from 150 the value of .CURDIR. Used only if MAKEOBJDIRPREFIX is 151 not defined. 152 153 Note: MAKEOBJDIR can be provided only in the environment 154 or via the -O flag of build.sh; it cannot usefully be set 155 inside a Makefile, including in mk.conf(5) or MAKECONF. 156 157 MAKEOBJDIRPREFIX 158 Top level directory of the object directory tree. The 159 value is subjected to variable expansion by make(1). 160 build.sh will create the ${MAKEOBJDIRPREFIX} directory if 161 necessary, but if make(1) is used without build.sh, then 162 rules in <bsd.obj.mk> will abort the build if the 163 ${MAKEOBJDIRPREFIX} directory does not exist. If the 164 value is defined and valid, then 165 ${MAKEOBJDIRPREFIX}/${.CURDIR} is used as the .OBJDIR for 166 the current directory. The current directory may be read 167 only. 168 169 Note: MAKEOBJDIRPREFIX can be provided only in the 170 environment or via the -M flag of build.sh; it cannot 171 usefully be set inside a Makefile, including in 172 mk.conf(5) or MAKECONF. 173 174 TMPDIR Top-level directory to store temporary directories used 175 by build.sh before paths to other directories such as 176 .OBJDIR can be determined. 177 178 Note: Must support execution of binaries. I.e., without 179 mount(8)'s -o noexec option. 180 181 Default: "/tmp". 182 183 "make" variables 184 Several variables control the behavior of NetBSD builds. Unless 185 otherwise specified, these variables may be set in either the process 186 environment or the make(1) configuration file mk.conf(5) specified by 187 MAKECONF. 188 189 This list is not comprehensive; all supported variables and their 190 defaults are documented in mk.conf(5). 191 192 BSDOBJDIR The real path to the object directory tree for the NetBSD 193 source tree. 194 195 Default: "/usr/obj" 196 197 BSDSRCDIR The real path to the NetBSD source tree, if NETBSDSRCDIR 198 isn't defined. 199 200 Default: "/usr/src" 201 202 BUILDID Identifier for the build. If set, this should be a short 203 string that is suitable for use as part of a file or 204 directory name. The identifier will be appended to 205 object directory names, and can be consulted in the 206 make(1) configuration file in order to set additional 207 build parameters, such as compiler flags. It will also 208 be used as part of the kernel version string, which can 209 be shown by "uname -v". 210 211 Default: Unset. 212 213 BUILDINFO Optional multi-line string containing information about 214 the build. This will appear in DESTDIR/etc/release, and 215 it will be stored in the buildinfo variable in any 216 kernels that are built. When such kernels are booted, 217 the sysctl(7) kern.buildinfo variable will report this 218 value. The string may contain backslash escape 219 sequences, such as "\\" (representing a backslash 220 character) and "\n" (representing a newline). 221 222 Default: Unset. 223 224 BUILDSEED g++(1) uses random numbers when compiling C++ code. This 225 variable seeds the g++(1) random number generator using 226 -frandom-seed with this value. By default, it is set to 227 "NetBSD-(majorversion)". Using a fixed value causes C++ 228 binaries to be the same when built from the same sources, 229 resulting in identical (reproducible) builds. Additional 230 information is available in the g++(1) documentation of 231 -frandom-seed. 232 233 Default: Unset. 234 235 CPUFLAGS Additional flags to the compiler/assembler to select CPU 236 instruction set options, CPU tuning options, etc. 237 238 Default: Unset. 239 240 DESTDIR Directory to contain the built NetBSD system. If set, 241 special options are passed to the compilation tools to 242 prevent their default use of the host system's 243 /usr/include, /usr/lib, and so forth. This pathname must 244 be an absolute path, and should not end with a slash (/) 245 character. (For installation into the system's root 246 directory, set DESTDIR to an empty string, not to "/"). 247 The directory must reside on a file system which supports 248 long file names and hard links. 249 250 Note: build.sh will provide a default of destdir.MACHINE 251 (in the top-level .OBJDIR) unless run in `expert' mode. 252 253 Default: Empty string if USETOOLS is "yes"; unset 254 otherwise. 255 256 EXTERNAL_TOOLCHAIN 257 If defined, this variable indicates the root directory of 258 an external toolchain which will be used to build the 259 tree. For example, if a platform is a TOOLCHAIN_MISSING 260 platform, EXTERNAL_TOOLCHAIN can be used to re-enable the 261 cross-compile framework. 262 263 If EXTERNAL_TOOLCHAIN is defined, act as MKGCC=no, since 264 the external version of the compiler may not be able to 265 build the library components of the in-tree compiler. 266 267 This variable should be used in conjunction with an 268 appropriate HAVE_GCC or HAVE_LLVM setting to control the 269 compiler flags. 270 271 Note: This variable is not yet used in as many places as 272 it should be. Expect the exact semantics of this 273 variable to change in the short term as parts of the 274 cross-compile framework continue to be cleaned up. 275 276 Default: Unset. 277 278 MAKEVERBOSE Level of verbosity of status messages. Supported values: 279 280 0 No descriptive messages or commands executed by 281 make(1) are shown. 282 283 1 Brief messages are shown describing what is being 284 done, but the actual commands executed by make(1) are 285 not shown. 286 287 2 Descriptive messages are shown as above (prefixed 288 with a `#'), and ordinary commands performed by 289 make(1) are shown. 290 291 3 In addition to the above, all commands performed by 292 make(1) are shown, even if they would ordinarily have 293 been hidden through use of the "@" prefix in the 294 relevant makefile. 295 296 4 In addition to the above, commands executed by 297 make(1) are traced through use of the sh(1) "-x" 298 flag. 299 300 Default: 2 301 302 MKCATPAGES Can be set to "yes" or "no". Indicates whether 303 preformatted plaintext manual pages will be created and 304 installed. 305 306 Forced to "no" if MKMAN=no or MKSHARE=no. 307 308 Default: "no" 309 310 MKCROSSGDB Can be set to "yes" or "no". Create a cross-gdb as a 311 host tool. 312 313 Default: "no" 314 315 MKDEBUG Can be set to "yes" or "no". Indicates whether debug 316 information should be generated for all userland 317 binaries. The result is collected as an additional 318 debug.tgz and xdebug.tgz set and installed in 319 DESTDIR/usr/libdata/debug. 320 321 Forced to "no" if NODEBUG is defined, usually in the 322 Makefile before any make(1) .include directives. 323 324 Default: "no" 325 326 MKDEBUGKERNEL Can be set to "yes" or "no". Indicates whether debugging 327 symbols will be built for kernels by default; pretend as 328 if makeoptions DEBUG="-g" is specified in kernel 329 configuration files. This will also put the debug kernel 330 netbsd.gdb in the kernel sets. See options(4) for 331 details. This is useful if a cross-gdb is built as well 332 (see MKCROSSGDB). 333 334 Default: "no" 335 336 MKDEBUGLIB Can be set to "yes" or "no". Indicates whether debug 337 libraries (lib*_g.a) will be built and installed. Debug 338 libraries are compiled with "-g -DDEBUG". 339 340 Forced to "no" if NODEBUGLIB is defined, usually in the 341 Makefile before any make(1) .include directives. 342 343 Default: "no" 344 345 MKDEBUGTOOLS Can be set to "yes" or "no". Indicates whether debug 346 information (lib*_g.a) will be included in the build 347 toolchain. 348 349 Default: "no" 350 351 MKDOC Can be set to "yes" or "no". Indicates whether system 352 documentation destined for DESTDIR/usr/share/doc will be 353 installed. 354 355 Forced to "no" if NODOC is defined, usually in the 356 Makefile before any make(1) .include directives. 357 358 Forced to "no" if MKSHARE=no. 359 360 Default: "yes" 361 362 MKHOSTOBJ Can be set to "yes" or "no". If set to "yes", then for 363 programs intended to be run on the compile host, the 364 name, release, and architecture of the host operating 365 system will be suffixed to the name of the object 366 directory created by "make obj". (This allows multiple 367 host systems to compile NetBSD for a single target.) If 368 set to "no", then programs built to be run on the compile 369 host will use the same object directory names as programs 370 built to be run on the target. 371 372 Default: "no" 373 374 MKHTML Can be set to "yes" or "no". Indicates whether the HTML 375 manual pages are created and installed. and installed 376 377 Forced to "no" if NOHTML is defined, usually in the 378 Makefile before any make(1) .include directives. 379 380 Forced to "no" if MKMAN=no or MKSHARE=no. 381 382 Default: "yes" 383 384 MKINFO Can be set to "yes" or "no". Indicates whether GNU Info 385 files, used for the documentation for most of the 386 compilation tools, will be built and installed. 387 388 Forced to "no" if NOINFO is defined, usually in the 389 Makefile before any make(1) .include directives. 390 391 Forced to "no" if MKSHARE=no. 392 393 Default: "yes" 394 395 MKKDEBUG Deprecated, use MKDEBUGKERNEL. 396 397 MKKMOD Can be set to "yes" or "no". Indicates whether kernel 398 modules are built and installed. 399 400 Default: "no" on or1k; "yes" on other platforms. 401 402 MKLINKLIB Can be set to "yes" or "no". Indicates whether all of 403 the shared library infrastructure will be built and 404 installed. If "no", prevents: installation of the *.a 405 libraries, installation of the *_pic.a libraries on PIC 406 systems, building of *.a libraries on PIC systems, or 407 installation of .so symlinks on ELF systems. 408 409 Forced to "no" if NOLINKLIB is defined, usually in the 410 Makefile before any make(1) .include directives. 411 412 If "no", acts as MKLINT=no MKPICINSTALL=no MKPROFILE=no. 413 414 Default: "yes" 415 416 MKLINT Can be set to "yes" or "no". Indicates whether lint(1) 417 will be run against portions of the NetBSD source code 418 during the build, and whether lint libraries will be 419 installed into DESTDIR/usr/libdata/lint. 420 421 Forced to "no" if NOLINT is defined, usually in the 422 Makefile before any make(1) .include directives. 423 424 Forced to "no" if MKLINKLIB=no. 425 426 Default: "no" 427 428 MKMAN Can be set to "yes" or "no". Indicates whether manual 429 pages will be installed. 430 431 Forced to "no" if NOMAN is defined, usually in the 432 Makefile before any make(1) .include directives. 433 434 Forced to "no" if MKSHARE=no. 435 436 If "no", acts as MKCATPAGES=no MKHTML=no. 437 438 Default: "yes" 439 440 MKNLS Can be set to "yes" or "no". Indicates whether Native 441 Language System (NLS) locale zone files will be built and 442 installed. 443 444 Forced to "no" if NONLS is defined, usually in the 445 Makefile before any make(1) .include directives. 446 447 Forced to "no" if MKSHARE=no. 448 449 Default: "yes" 450 451 MKOBJ Can be set to "yes" or "no". Indicates whether object 452 directories will be created when running "make obj". If 453 set to "no", then all built files will be located inside 454 the regular source tree. 455 456 Forced to "no" if NOOBJ is defined, usually in the 457 Makefile before any make(1) .include directives. 458 459 If "no", acts as MKOBJDIRS=no. 460 461 Note: Setting MKOBJ to "no" is not recommended and may 462 cause problems when updating the tree with cvs(1). 463 464 Default: "yes" 465 466 MKOBJDIRS Can be set to "yes" or "no". Indicates whether object 467 directories will be created automatically (via a "make 468 obj" pass) at the start of a build. 469 470 Forced to "no" if MKOBJ=no. 471 472 Default: "no" 473 474 MKPIC Can be set to "yes" or "no". Indicates whether shared 475 objects and libraries will be created and installed. If 476 "no", the entire built system will be statically linked. 477 478 Forced to "no" if NOPIC is defined, usually in the 479 Makefile before any make(1) .include directives. 480 481 If "no", acts as MKPICLIB=no. 482 483 Default: "no" on m68000; "yes" on other platforms. 484 485 MKPICINSTALL Can be set to "yes" or "no". Indicates whether the ar(1) 486 format libraries (lib*_pic.a), used to generate shared 487 libraries, are installed. 488 489 Forced to "no" if NOPICINSTALL is defined, usually in the 490 Makefile before any make(1) .include directives. 491 492 Forced to "no" if MKLINKLIB=no. 493 494 Default: "no" 495 496 MKPROFILE Can be set to "yes" or "no". Indicates whether profiled 497 libraries (lib*_p.a) will be built and installed. 498 499 Forced to "no" if NOPROFILE is defined, usually in the 500 Makefile before any make(1) .include directives. 501 502 Forced to "no" if MKLINKLIB=no. 503 504 Default: "no" on or1k, riscv32, and riscv64 (due to 505 toolchain problems with profiled code); "yes" on other 506 platforms. 507 508 MKREPRO Can be set to "yes" or "no". Indicates whether builds 509 are to be reproducible. If "yes", two builds from the 510 same source tree will produce the same build results. 511 512 Used as the default for MKARZERO. 513 514 This may be set to "yes" by giving build.sh the -P 515 option. 516 517 Default: "no" Can be set to "yes" or "no". 518 519 MKREPRO_TIMESTAMP 520 Unix timestamp. When MKREPRO is set, the timestamp of 521 all files in the sets will be set to this value. 522 523 This may be set automatically to the latest source tree 524 timestamp using cvslatest(1) by giving build.sh the -P 525 option. 526 527 Default: Unset. 528 529 MKSHARE Can be set to "yes" or "no". Indicates whether files 530 destined to reside in DESTDIR/usr/share will be built and 531 installed. 532 533 Forced to "no" if NOSHARE is defined, usually in the 534 Makefile before any make(1) .include directives. 535 536 If "no", acts as MKCATPAGES=no MKDOC=no MKINFO=no 537 MKHTML=no MKMAN=no MKNLS=no. 538 539 Default: "yes" 540 541 MKSTRIPIDENT Can be set to "yes" or "no". Indicates whether RCS IDs, 542 for use with ident(1), should be stripped from program 543 binaries and shared libraries. 544 545 Default: "no" 546 547 MKSTRIPSYM Can be set to "yes" or "no". Indicates whether all local 548 symbols should be stripped from shared libraries. If 549 "yes", strip all local symbols from shared libraries; the 550 affect is equivalent to the -x option of ld(1). If "no", 551 strip only temporary local symbols; the affect is 552 equivalent to the -X option of ld(1). Keeping non- 553 temporary local symbols such as static function names is 554 useful on using DTrace for userland libraries and getting 555 a backtrace from a rump kernel loading shared libraries. 556 557 Default: "yes" 558 559 MKUNPRIVED Can be set to "yes" or "no". Indicates whether an 560 unprivileged install will occur. The user, group, 561 permissions, and file flags, will not be set on the 562 installed items; instead the information will be appended 563 to a file called METALOG in DESTDIR. The contents of 564 METALOG are used during the generation of the 565 distribution tar files to ensure that the appropriate 566 file ownership is stored. 567 568 Default: "no" 569 570 MKUPDATE Can be set to "yes" or "no". Indicates whether all 571 install operations intended to write to DESTDIR will 572 compare file timestamps before installing, and skip the 573 install phase if the destination files are up-to-date. 574 575 Note: This also has implications on full builds (see next 576 subsection). 577 578 Default: "no" 579 580 MKX11 Can be set to "yes" or "no". Indicates whether X11 is 581 built and installed from X11SRCDIR, and whether the X 582 sets will be created. 583 584 Note: If "yes", requires MKINET6=yes. 585 586 Default: "no" 587 588 NETBSDSRCDIR The path to the top level of the NetBSD sources. 589 590 Default: Top level of the NetBSD source tree (as 591 determined by the presence of build.sh and tools/) if 592 make(1) is run from within that tree; otherwise BSDSRCDIR 593 will be used. 594 595 TOOLCHAIN_MISSING 596 Can be set to "yes" or "no". If not "no", this indicates 597 that the platform "MACHINE_ARCH" being built does not 598 have a working in-tree toolchain. 599 600 If not "no", acts as MKBINUTILS=no MKGCC=no MKGDB=no. 601 602 Default: "no" 603 604 TOOLDIR Directory to hold the host tools, once built. If 605 specified, must be an absolute path. This directory 606 should be unique to a given host system and NetBSD source 607 tree. (However, multiple targets may share the same 608 TOOLDIR; the target-dependent files have unique names.) 609 If unset, a default based on the uname(1) information of 610 the host platform will be created in the .OBJDIR of src. 611 612 Default: Unset. 613 614 USETOOLS Can be set to "yes" or "no". Indicates whether the tools 615 specified by TOOLDIR should be used as part of a build in 616 progress. Must be set to "yes" if cross-compiling. 617 618 yes Use the tools from TOOLDIR. 619 620 no Do not use the tools from TOOLDIR, but refuse to 621 build native compilation tool components that are 622 version-specific for that tool. 623 624 never Do not use the tools from TOOLDIR, even when 625 building native tool components. This is similar 626 to the traditional NetBSD build method, but does 627 not verify that the compilation tools in use are 628 up-to-date enough in order to build the tree 629 successfully. This may cause build or runtime 630 problems when building the whole NetBSD source 631 tree. 632 633 Default: "no" when using <bsd.*.mk> outside the NetBSD 634 source tree (detected automatically) or if 635 TOOLCHAIN_MISSING=yes; "yes" otherwise. 636 637 X11SRCDIR Directory containing the modular Xorg source. If 638 specified, must be an absolute path. The main modular 639 Xorg source is found in X11SRCDIR/external/mit. 640 641 Default: NETBSDSRCDIR/../xsrc, if that exists; otherwise 642 /usr/xsrc. 643 644 "make" variables for full builds 645 These variables only affect the top level "Makefile" and do not affect 646 manually building subtrees of the NetBSD source code. 647 648 INSTALLBOOT_BOARDS 649 A list of boards to create bootable images for. If 650 corresponding U-Boot packages are installed, bootable 651 images are created as part of a release. See the 652 -o board=name option of installboot(8). 653 654 INSTALLWORLDDIR 655 Location for the "make installworld" target to install 656 to. If specified, must be an absolute path. 657 658 Default: "/" 659 660 MKOBJDIRS Can be set to "yes" or "no". Indicates whether object 661 directories will be created automatically (via a "make 662 obj" pass) at the start of a build. 663 664 Default: "no" 665 666 If using build.sh, the default is "yes". This may be set 667 back to "no" by giving build.sh the -o option. 668 669 MKUPDATE Can be set to "yes" or "no". If set, then in addition to 670 the effects described for MKUPDATE=yes above, this 671 implies the effects of NOCLEANDIR (i.e., "make cleandir" 672 is avoided). 673 674 Default: "no" 675 676 If using build.sh, this may be set by giving the -u 677 option. 678 679 NOCLEANDIR If set, avoids the "make cleandir" phase of a full build. 680 This has the effect of allowing only changed files in a 681 source tree to be recompiled. This can speed up builds 682 when updating only a few files in the tree. 683 684 Default: Unset. 685 686 See also MKUPDATE. 687 688 NODISTRIBDIRS If set, avoids the "make distrib-dirs" phase of a full 689 build. This skips running mtree(8) on DESTDIR, useful on 690 systems where building as an unprivileged user, or where 691 it is known that the system-wide mtree files have not 692 changed. 693 694 Default: Unset. 695 696 NOINCLUDES If set, avoids the "make includes" phase of a full build. 697 This has the effect of preventing make(1) from thinking 698 that some programs are out-of-date simply because the 699 system include files have changed. However, this option 700 should not be used when updating the entire NetBSD source 701 tree arbitrarily; it is suggested to use MKUPDATE=yes 702 instead in that case. 703 704 Default: Unset. 705 706 RELEASEDIR If set, specifies the directory to which a release(7) 707 layout will be written at the end of a "make release". 708 If specified, must be an absolute path. 709 710 Note: build.sh will provide a default of releasedir (in 711 the top-level .OBJDIR) unless run in `expert' mode. 712 713 Default: Unset. 714 715BUILDING 716 "make" command line options 717 This is not a summary of all the options available to make(1); only the 718 options used most frequently with NetBSD builds are listed here. 719 720 -j njob Run up to njob make(1) subjobs in parallel. Makefiles should 721 use .WAIT or have explicit dependencies as necessary to 722 enforce build ordering. 723 724 -m dir Specify the default directory for searching for system 725 Makefile segments, mainly the <bsd.*.mk> files. When building 726 any full NetBSD source tree, this should be set to the 727 "share/mk" directory in the source tree. This is set 728 automatically when building from the top level, or when using 729 build.sh. 730 731 -n Show the commands that would have been executed, but do not 732 actually execute them. This will still cause recursion to 733 take place. 734 735 -V var Show make(1)'s idea of the value of var. Does not build any 736 targets. 737 738 var=value Set the variable var to value, overriding any setting 739 specified by the process environment, the MAKECONF 740 configuration file, or the system Makefile segments. 741 742 "make" targets 743 These default targets may be built by running make(1) in any subtree of 744 the NetBSD source code. It is recommended that none of these be used 745 from the top level Makefile; as a specific exception, "make obj" and 746 "make cleandir" are useful in that context. 747 748 all Build programs, libraries, and preformatted documentation. 749 750 clean Remove program and library object code files. 751 752 cleandir Same as clean, but also remove preformatted documentation, 753 dependency files generated by "make depend", and any other 754 files known to be created at build time. 755 756 depend Create dependency files (.depend) containing more detailed 757 information about the dependencies of source code on header 758 files. Allows programs to be recompiled automatically when a 759 dependency changes. 760 761 dependall Does a "make depend" immediately followed by a "make all". 762 This improves cache locality of the build since both passes 763 read the source files in their entirety. 764 765 distclean Synonym for cleandir. 766 767 includes Build and install system header files. Typically needed 768 before any system libraries or programs can be built. 769 770 install Install programs, libraries, and documentation into DESTDIR. 771 Few files will be installed to DESTDIR/dev, DESTDIR/etc, 772 DESTDIR/root or DESTDIR/var in order to prevent user supplied 773 configuration data from being overwritten. 774 775 lint Run lint(1) against the C source code, where appropriate, and 776 generate system-installed lint libraries. 777 778 obj Create object directories to be used for built files, instead 779 of building directly in the source tree. 780 781 tags Create ctags(1) searchable function lists usable by the ex(1) 782 and vi(1) text editors. 783 784 "make" targets for the top level 785 Additional make(1) targets are usable specifically from the top source 786 level to facilitate building the entire NetBSD source tree. 787 788 build Build the entire NetBSD system (except the kernel). This 789 orders portions of the source tree such that prerequisites 790 will be built in the proper order. 791 792 distribution Do a "make build", and then install a full distribution 793 (which does not include a kernel) into DESTDIR, including 794 files in DESTDIR/dev, DESTDIR/etc, DESTDIR/root and 795 DESTDIR/var. 796 797 buildworld As per "make distribution", except that it ensures that 798 DESTDIR is not the root directory. 799 800 installworld Install the distribution from DESTDIR to INSTALLWORLDDIR, 801 which defaults to the root directory. Ensures that 802 INSTALLWORLDDIR is not the root directory if cross 803 compiling. 804 805 The INSTALLSETS environment variable may be set to a space- 806 separated list of distribution sets to be installed. By 807 default, all sets except "etc" and "xetc" are installed, so 808 most files in INSTALLWORLDDIR/etc will not be installed or 809 modified. 810 811 Note: Before performing this operation with 812 INSTALLWORLDDIR=/, it is highly recommended that you 813 upgrade your kernel and reboot. After performing this 814 operation, it is recommended that you use etcupdate(8) to 815 update files in INSTALLWORLDDIR/etc, and postinstall(8) to 816 check for or fix inconsistencies. 817 818 sets Create distribution sets from DESTDIR into 819 RELEASEDIR/RELEASEMACHINEDIR/binary/sets. Should be run 820 after "make distribution", as "make build" alone does not 821 install all of the required files. 822 823 sourcesets Create source sets of the source tree into 824 RELEASEDIR/source/sets. 825 826 syspkgs Create syspkgs from DESTDIR into 827 RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs. Should be run 828 after "make distribution", as "make build" alone does not 829 install all of the required files. 830 831 release Do a "make distribution", build kernels, distribution 832 media, and install sets (this as per "make sets"), and then 833 package the system into a standard release layout as 834 described by release(7). This requires that RELEASEDIR be 835 set (see above). 836 837 iso-image Create a NetBSD installation CD-ROM image in the 838 RELEASEDIR/images directory. The CD-ROM file system will 839 have a layout as described in release(7). 840 841 For most machine types, the CD-ROM will be bootable, and 842 will automatically run the sysinst(8) menu-based 843 installation program, which can be used to install or 844 upgrade a NetBSD system. Bootable CD-ROMs also contain 845 tools that may be useful in repairing a damaged NetBSD 846 installation. 847 848 Before "make iso-image" is attempted, RELEASEDIR must be 849 populated by "make release" or equivalent. 850 851 Note: Other, smaller, CD-ROM images may be created in the 852 RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom directory 853 by "make release". These smaller images usually contain 854 the same tools as the larger images in RELEASEDIR/images, 855 but do not contain additional content such as the 856 distribution sets. 857 858 Note: The mac68k port still uses an older method of 859 creating CD-ROM images. This requires the mkisofs(1) 860 utility, which is not part of NetBSD, but which can be 861 installed from pkgsrc/sysutils/cdrtools. 862 863 iso-image-source 864 Create a NetBSD installation CD-ROM image in the 865 RELEASEDIR/images directory. The CD-ROM file system will 866 have a layout as described in release(7). It will have top 867 level directories for the machine type and source. 868 869 For most machine types, the CD-ROM will be bootable, and 870 will automatically run the sysinst(8) menu-based 871 installation program, which can be used to install or 872 upgrade a NetBSD system. Bootable CD-ROMs also contain 873 tools that may be useful in repairing a damaged NetBSD 874 installation. 875 876 Before "make iso-image-source" is attempted, RELEASEDIR 877 must be populated by "make sourcesets release" or 878 equivalent. 879 880 Note: Other, smaller, CD-ROM images may be created in the 881 RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom directory 882 by "make release". These smaller images usually contain 883 the same tools as the larger images in RELEASEDIR/images, 884 but do not contain additional content such as the 885 distribution sets. 886 887 Note: The mac68k port still uses an older method of 888 creating CD-ROM images. This requires the mkisofs(1) 889 utility, which is not part of NetBSD, but which can be 890 installed from pkgsrc/sysutils/cdrtools. 891 892 install-image 893 Create a bootable NetBSD installation disk image in the 894 RELEASEDIR/images directory. The installation disk image 895 is suitable for copying to bootable USB flash memory 896 sticks, etc., for machines which are able to boot from such 897 devices. The file system in the bootable disk image will 898 have a layout as described in release(7). 899 900 The installation image is bootable, and will automatically 901 run the sysinst(8) menu-based installation program, which 902 can be used to install or upgrade a NetBSD system. The 903 image also contains tools that may be useful in repairing a 904 damaged NetBSD installation. 905 906 Before "make install-image" is attempted, RELEASEDIR must 907 be populated by "make release" or equivalent. The build 908 must have been performed with MKUNPRIVED=yes because "make 909 install-image" relies on information in DESTDIR/METALOG. 910 911 live-image Create NetBSD live images in the RELEASEDIR/images 912 directory. The live image contains all necessary files to 913 boot NetBSD up to multi-user mode, including all files 914 which should be extracted during installation, NetBSD 915 disklabel, bootloaders, etc. 916 917 The live image is suitable for use as a disk image in 918 virtual machine environments such as QEMU, and also useful 919 to boot NetBSD from a USB flash memory stick on a real 920 machine, without the need for installation. 921 922 Before "make live-image" is attempted, RELEASEDIR must be 923 populated by "make release" or equivalent. The build must 924 have been performed with MKUNPRIVED=yes because "make 925 install-image" relies on information in DESTDIR/METALOG. 926 927 regression-tests 928 Can only be run after building the regression tests in the 929 directory "regress". Runs those compiled regression tests 930 on the local host. 931 932 Note: Most tests are now managed instead using atf(7); this 933 target should probably run those as well but currently does 934 not. 935 936 The "build.sh" script 937 This script file is a shell script designed to build the entire NetBSD 938 system on any host with a suitable modern shell and some common 939 utilities. The required shell features are described under the HOST_SH 940 variable. 941 942 If a host system's default shell does support the required features, then 943 we suggest that you explicitly specify a suitable shell using a command 944 like 945 946 /path/to/suitable/shell build.sh [options] 947 948 The above command will usually enable build.sh to automatically set 949 HOST_SH=/path/to/suitable/shell, but if that fails, then the following 950 set of commands may be used instead: 951 952 HOST_SH=/path/to/suitable/shell 953 export HOST_SH 954 ${HOST_SH} build.sh [options] 955 956 If build.sh detects that it is being executed under an unsuitable shell, 957 it attempts to exec a suitable shell instead, or shows an error message. 958 If HOST_SH is not set explicitly, then build.sh sets a default using 959 heuristics dependent on the host platform, or from the shell under which 960 build.sh is executed (if that can be determined), or using the first copy 961 of sh found in PATH. 962 963 All cross-compile builds, and most native builds, of the entire system 964 should make use of build.sh rather than just running "make". This way, 965 the make(1) program will be bootstrapped properly, in case the host 966 system has an older or incompatible "make" program. 967 968 When compiling the entire system via build.sh, many make(1) variables are 969 set for you in order to help encapsulate the build process. In the list 970 of options below, variables that are automatically set by build.sh are 971 noted where applicable. 972 973 The following operations are supported by build.sh: 974 975 build Build the system as per "make build". Before the main part 976 of the build commences, this command runs the obj operation 977 (unless the -o option is given), "make cleandir" (unless 978 the -u option is given), and the tools operation. 979 980 distribution Build a full distribution as per "make distribution". This 981 command first runs the build operation. 982 983 release Build a full release as per "make release". This command 984 first runs the distribution operation. 985 986 help Show a help message, and exit. 987 988 makewrapper Create the nbmake-MACHINE wrapper. This operation is 989 automatically performed for any of the other operations. 990 991 cleandir Perform "make cleandir". 992 993 obj Perform "make obj". 994 995 tools Build and install the host tools from src/tools. This 996 command will first run "make obj" and "make cleandir" in 997 the tools subdirectory unless the -o or -u options 998 (respectively) are given. 999 1000 install=idir Install the contents of DESTDIR to idir, using "make 1001 installworld". 1002 1003 Note: Files that are part of the "etc" or "xetc" sets will 1004 not be installed, unless overridden by the INSTALLSETS 1005 environment variable. 1006 1007 kernel=kconf Build a new kernel. The kconf argument is the name of a 1008 configuration file suitable for use by config(1). If kconf 1009 does not contain any `/' characters, the configuration file 1010 is expected to be found in the KERNCONFDIR directory, which 1011 is typically sys/arch/MACHINE/conf. The new kernel will be 1012 built in a subdirectory of KERNOBJDIR, which is typically 1013 sys/arch/MACHINE/compile or an associated object directory. 1014 1015 This command does not imply the tools command; run the 1016 tools command first unless it is certain that the tools 1017 already exist and are up to date. 1018 1019 This command will run "make cleandir" on the kernel in 1020 question first unless the -u option is given. 1021 1022 kernel.gdb=kconf 1023 Build a new kernel with debug information. Similar to the 1024 above kernel=kconf operation, but creates a netbsd.gdb file 1025 alongside of the kernel netbsd, which contains a full 1026 symbol table and can be used for debugging (for example 1027 with a cross-gdb built by MKCROSSGDB). 1028 1029 kernels This command will build all kernels defined in port 1030 specific release build procedure. 1031 1032 This command internally calls the kernel=kconf operation 1033 for each found kernel configuration file. 1034 1035 modules This command will build kernel modules and install them 1036 into DESTDIR. 1037 1038 releasekernel=kconf 1039 Install a gzip(1)ed copy of the kernel previously built by 1040 kernel=kconf into 1041 RELEASEDIR/RELEASEMACHINEDIR/binary/kernel, usually as 1042 netbsd-kconf.gz, although the "netbsd" prefix is determined 1043 from the "config" directives in kconf. 1044 1045 sets Perform "make sets". 1046 1047 sourcesets Perform "make sourcesets". 1048 1049 syspkgs Perform "make syspkgs". 1050 1051 iso-image Perform "make iso-image". 1052 1053 iso-image-source 1054 Perform "make iso-image-source". 1055 1056 install-image 1057 Perform "make install-image". 1058 1059 live-image Perform "make live-image". 1060 1061 list-arch Show a list of valid MACHINE and MACHINE_ARCH settings, the 1062 default MACHINE_ARCH for each MACHINE, and aliases for 1063 MACHINE/MACHINE_ARCH pairs, and then exits. The -m or -a 1064 options (or both) may be used to specify glob patterns that 1065 will be used to narrow the list of results; for example, 1066 "build.sh -m 'evb*' -a '*arm*' list-arch" will list all 1067 known MACHINE/MACHINE_ARCH values in which either MACHINE 1068 or ALIAS matches the pattern `evb*', and MACHINE_ARCH 1069 matches the pattern `*arm*'. 1070 1071 The following command line options alter the behaviour of the build.sh 1072 operations described above: 1073 1074 -a arch Set the value of MACHINE_ARCH to arch. See the -m option for 1075 more information. 1076 1077 -B buildid 1078 Set the value of BUILDID to buildid. This will also append the 1079 build identifier to the name of the "make" wrapper script so 1080 that the resulting name is of the form 1081 "nbmake-MACHINE-BUILDID". 1082 1083 -C cdextras 1084 Append cdextras to the CDEXTRA variable, which is a space- 1085 separated list of files or directories that will be added to 1086 the CD-ROM image that may be create by the "iso-image" or 1087 "iso-image-source" operations. Files will be added to the root 1088 of the CD-ROM image, whereas directories will be copied 1089 recursively. If relative paths are specified, they will be 1090 converted to absolute paths before being used. Multiple paths 1091 may be specified via multiple -C options, or via a single 1092 option whose argument contains multiple space-separated paths. 1093 1094 -c compiler 1095 Select the compiler for the toolchain to build NetBSD and for 1096 inclusion in the NetBSD distribution. Supported choices: 1097 1098 clang 1099 1100 gcc [default] 1101 1102 The compiler used to build the toolchain can be different; see 1103 HOST_CC and HOST_CXX. 1104 1105 -D dest Set the value of DESTDIR to dest. If a relative path is 1106 specified, it will be converted to an absolute path before 1107 being used. 1108 1109 -E Set `expert' mode. This overrides various sanity checks, and 1110 allows: DESTDIR does not have to be set to a non-root path for 1111 builds, and MKUNPRIVED=yes does not have to be set when 1112 building as a non-root user. 1113 1114 Note: It is highly recommended that you know what you are doing 1115 when you use this option. 1116 1117 -h Show a help message, and exit. 1118 1119 -j njob Run up to njob make(1) subjobs in parallel; passed through to 1120 make(1). If you see failures for reasons other than running 1121 out of memory while using build.sh with -j, please save 1122 complete build logs so the failures can be analyzed. 1123 1124 To achieve the fastest builds, -j values between (1 + the 1125 number of CPUs) and (2 * the number of CPUs) are recommended. 1126 Use lower values on machines with limited memory or I/O 1127 bandwidth. 1128 1129 -M obj Set MAKEOBJDIRPREFIX to obj. Unsets MAKEOBJDIR. See "-O obj" 1130 for more information. 1131 1132 For instance, if the source directory is /usr/src, a setting of 1133 "-M /usr/obj" will place build-time files under 1134 /usr/obj/usr/src/bin, /usr/obj/usr/src/lib, 1135 /usr/obj/usr/src/usr.bin, and so forth. 1136 1137 If a relative path is specified, it will be converted to an 1138 absolute path before being used. build.sh imposes the 1139 restriction that the argument to the -M option must not begin 1140 with a "$" (dollar sign) character; otherwise it would be too 1141 difficult to determine whether the value is an absolute or a 1142 relative path. If the directory does not already exist, 1143 build.sh will create it. 1144 1145 -m mach Set the value of MACHINE to mach, unless the mach argument is 1146 an alias that refers to a MACHINE/MACHINE_ARCH pair, in which 1147 case both MACHINE and MACHINE_ARCH are set from the alias. 1148 Such aliases are interpreted entirely by build.sh; they are not 1149 used by any other part of the build system. The MACHINE_ARCH 1150 setting implied by mach will override any value of MACHINE_ARCH 1151 in the process environment, but will not override a value set 1152 by the -a option. All cross builds require -m, but if unset on 1153 a NetBSD host, the host's value of MACHINE will be detected and 1154 used automatically. 1155 1156 See the list-arch operation for a way to get a list of valid 1157 MACHINE and MACHINE_ARCH settings. 1158 1159 -N noiselevel 1160 Set the "noisyness" level of the build, by setting MAKEVERBOSE 1161 to noiselevel. 1162 1163 -n Show the commands that would be executed by build.sh, but do 1164 not make any changes. This is similar in concept to "make -n". 1165 1166 -O obj Create an appropriate transform macro for MAKEOBJDIR that will 1167 place the built object files under obj. Unsets 1168 MAKEOBJDIRPREFIX. 1169 1170 For instance, a setting of "-O /usr/obj" will place build-time 1171 files under /usr/obj/bin, /usr/obj/lib, /usr/obj/usr.bin, and 1172 so forth. 1173 1174 If a relative path is specified, it will be converted to an 1175 absolute path before being used. build.sh imposes the 1176 restriction that the argument to the -O option must not contain 1177 a "$" (dollar sign) character. If the directory does not 1178 already exist, build.sh will create it. 1179 1180 In normal use, exactly one of the -M or -O options should be 1181 specified. If neither -M nor -O is specified, then a default 1182 object directory will be chosen according to rules in 1183 <bsd.obj.mk>. Relying on this default is not recommended 1184 because it is determined by complex rules that are influenced 1185 by the values of several variables and by the location of the 1186 source directory. 1187 1188 Note: Placing the obj directory location outside of the default 1189 source tree hierarchy makes it easier to manually clear out old 1190 files in the event the "make cleandir" operation is unable to 1191 do so. (See CAVEATS below.) 1192 1193 Note: The use of one of -M or -O is the only means of building 1194 multiple machine architecture userlands from the same source 1195 tree without cleaning between builds (in which case, one would 1196 specify distinct obj locations for each). 1197 1198 -o Set the value of MKOBJDIRS to "no". Otherwise, it will be 1199 automatically set to "yes". This default is opposite to the 1200 behaviour when not using build.sh. 1201 1202 -P Set the value of MKREPRO and MKREPRO_TIMESTAMP to the latest 1203 source CVS timestamp for reproducible builds. 1204 1205 -R rel Set the value of RELEASEDIR to rel. If a relative path is 1206 specified, it will be converted to an absolute path before 1207 being used. 1208 1209 -r Remove the contents of DESTDIR and TOOLDIR before building 1210 (provides a clean starting point). This will skip deleting 1211 DESTDIR if building on a native system to the root directory. 1212 1213 -S seed Change the value of BUILDSEED to seed. This should rarely be 1214 necessary. 1215 1216 -T tools Set the value of TOOLDIR to tools. If a relative path is 1217 specified, it will be converted to an absolute path before 1218 being used. If set, the bootstrap "make" will only be rebuilt 1219 if the source files for make(1) have changed. 1220 1221 -U Set MKUNPRIVED=yes. 1222 1223 -u Set MKUPDATE=yes. 1224 1225 -V var=[value] 1226 Set the environment variable var to an optional value. This is 1227 propagated to the nbmake wrapper. 1228 1229 -w wrapper 1230 Create the nbmake wrapper script (see below) in a custom 1231 location, specified by wrapper. This allows, for instance, to 1232 place the wrapper in PATH automatically. 1233 1234 Note: wrapper is the full name of the file, not just a 1235 directory name. If a relative path is specified, it will be 1236 converted to an absolute path before being used. 1237 1238 -X x11src 1239 Set the value of X11SRCDIR to x11src. If a relative path is 1240 specified, it will be converted to an absolute path before 1241 being used. 1242 1243 -x Set MKX11=yes. 1244 1245 -Z var Unset ("zap") the environment variable var. This is propagated 1246 to the nbmake wrapper. 1247 1248 -? Show a help message, and exit. 1249 1250 The "nbmake-MACHINE" wrapper script 1251 If using the build.sh script to build NetBSD, a nbmake-MACHINE script 1252 will be created in TOOLDIR/bin upon the first build to assist in building 1253 subtrees on a cross-compile host. 1254 1255 nbmake-MACHINE can be invoked in lieu of make(1), and will instead call 1256 the up-to-date version of "nbmake" installed into TOOLDIR/bin with 1257 several key variables pre-set, including MACHINE, MACHINE_ARCH, and 1258 TOOLDIR. nbmake-MACHINE will also set variables specified with -V, and 1259 unset variables specified with -Z. 1260 1261 This script can be symlinked into a directory listed in PATH, or called 1262 with an absolute path. 1263 1264EXAMPLES 1265 1. % ./build.sh [OPTIONS] tools kernel=GENERIC 1266 1267 Build a new toolchain, and use the new toolchain to configure and 1268 build a new GENERIC kernel. 1269 1270 2. % ./build.sh [OPTIONS] -U distribution 1271 1272 Using unprivileged mode, build a complete distribution to a DESTDIR 1273 directory that build.sh selects (and will show). 1274 1275 3. # ./build.sh [OPTIONS] -U install=/ 1276 1277 As root, install to / the distribution that was built by example 2. 1278 Even though this is run as root, -U is required so that the 1279 permissions stored in DESTDIR/METALOG are correctly applied to the 1280 files as they're copied to /. 1281 1282 4. % ./build.sh [OPTIONS] -U -u release 1283 1284 Using unprivileged mode, build a complete release to DESTDIR and 1285 RELEASEDIR directories that build.sh selects (and will show). 1286 MKUPDATE=yes (-u) is set to prevent the "make cleandir", so that if 1287 this is run after example 2, it doesn't need to redo that portion of 1288 the release build. 1289 1290OBSOLETE VARIABLES 1291 NBUILDJOBS Use the build.sh and make(1) option -j instead. 1292 1293 USE_NEW_TOOLCHAIN 1294 The new toolchain is now the default. To disable, use 1295 TOOLCHAIN_MISSING=yes. 1296 1297SEE ALSO 1298 ar(1), config(1), ctags(1), cvs(1), cvslatest(1), ex(1), g++(1), gzip(1), 1299 ident(1), ld(1), lint(1), make(1), mkisofs(1), sh(1), uname(1), vi(1), 1300 options(4), mk.conf(5), atf(7), hier(7), release(7), sysctl(7), 1301 etcupdate(8), installboot(8), mount(8), mtree(8), postinstall(8), 1302 sysinst(8), pkgsrc/sysutils/cdrtools 1303 1304HISTORY 1305 The build.sh based build scheme was introduced for NetBSD 1.6 as 1306 USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that. 1307 1308CAVEATS 1309 After significant updates to third-party components in the source tree, 1310 the "make cleandir" operation may be insufficient to clean out old files 1311 in object directories. Instead, one may have to manually remove the 1312 files. Consult the UPDATING file for notices concerning this. 1313 1314NetBSD June 10, 2023 NetBSD 1315