BUILDING revision 1.152
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 NBUILDJOBS Now obsolete. Use the make(1) option -j, instead. See 680 below. 681 682 Default: Unset. 683 684 NOCLEANDIR If set, avoids the "make cleandir" phase of a full build. 685 This has the effect of allowing only changed files in a 686 source tree to be recompiled. This can speed up builds 687 when updating only a few files in the tree. 688 689 Default: Unset. 690 691 See also MKUPDATE. 692 693 NODISTRIBDIRS If set, avoids the "make distrib-dirs" phase of a full 694 build. This skips running mtree(8) on DESTDIR, useful on 695 systems where building as an unprivileged user, or where 696 it is known that the system-wide mtree files have not 697 changed. 698 699 Default: Unset. 700 701 NOINCLUDES If set, avoids the "make includes" phase of a full build. 702 This has the effect of preventing make(1) from thinking 703 that some programs are out-of-date simply because the 704 system include files have changed. However, this option 705 should not be used when updating the entire NetBSD source 706 tree arbitrarily; it is suggested to use MKUPDATE=yes 707 instead in that case. 708 709 Default: Unset. 710 711 RELEASEDIR If set, specifies the directory to which a release(7) 712 layout will be written at the end of a "make release". 713 If specified, must be an absolute path. 714 715 Note: build.sh will provide a default of releasedir (in 716 the top-level .OBJDIR) unless run in `expert' mode. 717 718 Default: Unset. 719 720BUILDING 721 "make" command line options 722 This is not a summary of all the options available to make(1); only the 723 options used most frequently with NetBSD builds are listed here. 724 725 -j njob Run up to njob make(1) subjobs in parallel. Makefiles should 726 use .WAIT or have explicit dependencies as necessary to 727 enforce build ordering. 728 729 -m dir Specify the default directory for searching for system 730 Makefile segments, mainly the <bsd.*.mk> files. When building 731 any full NetBSD source tree, this should be set to the 732 "share/mk" directory in the source tree. This is set 733 automatically when building from the top level, or when using 734 build.sh. 735 736 -n Show the commands that would have been executed, but do not 737 actually execute them. This will still cause recursion to 738 take place. 739 740 -V var Show make(1)'s idea of the value of var. Does not build any 741 targets. 742 743 var=value Set the variable var to value, overriding any setting 744 specified by the process environment, the MAKECONF 745 configuration file, or the system Makefile segments. 746 747 "make" targets 748 These default targets may be built by running make(1) in any subtree of 749 the NetBSD source code. It is recommended that none of these be used 750 from the top level Makefile; as a specific exception, "make obj" and 751 "make cleandir" are useful in that context. 752 753 all Build programs, libraries, and preformatted documentation. 754 755 clean Remove program and library object code files. 756 757 cleandir Same as clean, but also remove preformatted documentation, 758 dependency files generated by "make depend", and any other 759 files known to be created at build time. 760 761 depend Create dependency files (.depend) containing more detailed 762 information about the dependencies of source code on header 763 files. Allows programs to be recompiled automatically when a 764 dependency changes. 765 766 dependall Does a "make depend" immediately followed by a "make all". 767 This improves cache locality of the build since both passes 768 read the source files in their entirety. 769 770 distclean Synonym for cleandir. 771 772 includes Build and install system header files. Typically needed 773 before any system libraries or programs can be built. 774 775 install Install programs, libraries, and documentation into DESTDIR. 776 Few files will be installed to DESTDIR/dev, DESTDIR/etc, 777 DESTDIR/root or DESTDIR/var in order to prevent user supplied 778 configuration data from being overwritten. 779 780 lint Run lint(1) against the C source code, where appropriate, and 781 generate system-installed lint libraries. 782 783 obj Create object directories to be used for built files, instead 784 of building directly in the source tree. 785 786 tags Create ctags(1) searchable function lists usable by the ex(1) 787 and vi(1) text editors. 788 789 "make" targets for the top level 790 Additional make(1) targets are usable specifically from the top source 791 level to facilitate building the entire NetBSD source tree. 792 793 build Build the entire NetBSD system (except the kernel). This 794 orders portions of the source tree such that prerequisites 795 will be built in the proper order. 796 797 distribution Do a "make build", and then install a full distribution 798 (which does not include a kernel) into DESTDIR, including 799 files in DESTDIR/dev, DESTDIR/etc, DESTDIR/root and 800 DESTDIR/var. 801 802 buildworld As per "make distribution", except that it ensures that 803 DESTDIR is not the root directory. 804 805 installworld Install the distribution from DESTDIR to INSTALLWORLDDIR, 806 which defaults to the root directory. Ensures that 807 INSTALLWORLDDIR is not the root directory if cross 808 compiling. 809 810 The INSTALLSETS environment variable may be set to a space- 811 separated list of distribution sets to be installed. By 812 default, all sets except "etc" and "xetc" are installed, so 813 most files in INSTALLWORLDDIR/etc will not be installed or 814 modified. 815 816 Note: Before performing this operation with 817 INSTALLWORLDDIR=/, it is highly recommended that you 818 upgrade your kernel and reboot. After performing this 819 operation, it is recommended that you use etcupdate(8) to 820 update files in INSTALLWORLDDIR/etc, and postinstall(8) to 821 check for or fix inconsistencies. 822 823 sets Create distribution sets from DESTDIR into 824 RELEASEDIR/RELEASEMACHINEDIR/binary/sets. Should be run 825 after "make distribution", as "make build" alone does not 826 install all of the required files. 827 828 sourcesets Create source sets of the source tree into 829 RELEASEDIR/source/sets. 830 831 syspkgs Create syspkgs from DESTDIR into 832 RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs. Should be run 833 after "make distribution", as "make build" alone does not 834 install all of the required files. 835 836 release Do a "make distribution", build kernels, distribution 837 media, and install sets (this as per "make sets"), and then 838 package the system into a standard release layout as 839 described by release(7). This requires that RELEASEDIR be 840 set (see above). 841 842 iso-image Create a NetBSD installation CD-ROM image in the 843 RELEASEDIR/images directory. The CD-ROM file system will 844 have a layout as described in release(7). 845 846 For most machine types, the CD-ROM will be bootable, and 847 will automatically run the sysinst(8) menu-based 848 installation program, which can be used to install or 849 upgrade a NetBSD system. Bootable CD-ROMs also contain 850 tools that may be useful in repairing a damaged NetBSD 851 installation. 852 853 Before "make iso-image" is attempted, RELEASEDIR must be 854 populated by "make release" or equivalent. 855 856 Note: Other, smaller, CD-ROM images may be created in the 857 RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom directory 858 by "make release". These smaller images usually contain 859 the same tools as the larger images in RELEASEDIR/images, 860 but do not contain additional content such as the 861 distribution sets. 862 863 Note: The mac68k port still uses an older method of 864 creating CD-ROM images. This requires the mkisofs(1) 865 utility, which is not part of NetBSD, but which can be 866 installed from pkgsrc/sysutils/cdrtools. 867 868 iso-image-source 869 Create a NetBSD installation CD-ROM image in the 870 RELEASEDIR/images directory. The CD-ROM file system will 871 have a layout as described in release(7). It will have top 872 level directories for the machine type and source. 873 874 For most machine types, the CD-ROM will be bootable, and 875 will automatically run the sysinst(8) menu-based 876 installation program, which can be used to install or 877 upgrade a NetBSD system. Bootable CD-ROMs also contain 878 tools that may be useful in repairing a damaged NetBSD 879 installation. 880 881 Before "make iso-image-source" is attempted, RELEASEDIR 882 must be populated by "make sourcesets release" or 883 equivalent. 884 885 Note: Other, smaller, CD-ROM images may be created in the 886 RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom directory 887 by "make release". These smaller images usually contain 888 the same tools as the larger images in RELEASEDIR/images, 889 but do not contain additional content such as the 890 distribution sets. 891 892 Note: The mac68k port still uses an older method of 893 creating CD-ROM images. This requires the mkisofs(1) 894 utility, which is not part of NetBSD, but which can be 895 installed from pkgsrc/sysutils/cdrtools. 896 897 install-image 898 Create a bootable NetBSD installation disk image in the 899 RELEASEDIR/images directory. The installation disk image 900 is suitable for copying to bootable USB flash memory 901 sticks, etc., for machines which are able to boot from such 902 devices. The file system in the bootable disk image will 903 have a layout as described in release(7). 904 905 The installation image is bootable, and will automatically 906 run the sysinst(8) menu-based installation program, which 907 can be used to install or upgrade a NetBSD system. The 908 image also contains tools that may be useful in repairing a 909 damaged NetBSD installation. 910 911 Before "make install-image" is attempted, RELEASEDIR must 912 be populated by "make release" or equivalent. The build 913 must have been performed with MKUNPRIVED=yes because "make 914 install-image" relies on information in DESTDIR/METALOG. 915 916 live-image Create NetBSD live images in the RELEASEDIR/images 917 directory. The live image contains all necessary files to 918 boot NetBSD up to multi-user mode, including all files 919 which should be extracted during installation, NetBSD 920 disklabel, bootloaders, etc. 921 922 The live image is suitable for use as a disk image in 923 virtual machine environments such as QEMU, and also useful 924 to boot NetBSD from a USB flash memory stick on a real 925 machine, without the need for installation. 926 927 Before "make live-image" is attempted, RELEASEDIR must be 928 populated by "make release" or equivalent. The build must 929 have been performed with MKUNPRIVED=yes because "make 930 install-image" relies on information in DESTDIR/METALOG. 931 932 regression-tests 933 Can only be run after building the regression tests in the 934 directory "regress". Runs those compiled regression tests 935 on the local host. 936 937 Note: Most tests are now managed instead using atf(7); this 938 target should probably run those as well but currently does 939 not. 940 941 The "build.sh" script 942 This script file is a shell script designed to build the entire NetBSD 943 system on any host with a suitable modern shell and some common 944 utilities. The required shell features are described under the HOST_SH 945 variable. 946 947 If a host system's default shell does support the required features, then 948 we suggest that you explicitly specify a suitable shell using a command 949 like 950 951 /path/to/suitable/shell build.sh [options] 952 953 The above command will usually enable build.sh to automatically set 954 HOST_SH=/path/to/suitable/shell, but if that fails, then the following 955 set of commands may be used instead: 956 957 HOST_SH=/path/to/suitable/shell 958 export HOST_SH 959 ${HOST_SH} build.sh [options] 960 961 If build.sh detects that it is being executed under an unsuitable shell, 962 it attempts to exec a suitable shell instead, or shows an error message. 963 If HOST_SH is not set explicitly, then build.sh sets a default using 964 heuristics dependent on the host platform, or from the shell under which 965 build.sh is executed (if that can be determined), or using the first copy 966 of sh found in PATH. 967 968 All cross-compile builds, and most native builds, of the entire system 969 should make use of build.sh rather than just running "make". This way, 970 the make(1) program will be bootstrapped properly, in case the host 971 system has an older or incompatible "make" program. 972 973 When compiling the entire system via build.sh, many make(1) variables are 974 set for you in order to help encapsulate the build process. In the list 975 of options below, variables that are automatically set by build.sh are 976 noted where applicable. 977 978 The following operations are supported by build.sh: 979 980 build Build the system as per "make build". Before the main part 981 of the build commences, this command runs the obj operation 982 (unless the -o option is given), "make cleandir" (unless 983 the -u option is given), and the tools operation. 984 985 distribution Build a full distribution as per "make distribution". This 986 command first runs the build operation. 987 988 release Build a full release as per "make release". This command 989 first runs the distribution operation. 990 991 help Show a help message, and exit. 992 993 makewrapper Create the nbmake-MACHINE wrapper. This operation is 994 automatically performed for any of the other operations. 995 996 cleandir Perform "make cleandir". 997 998 obj Perform "make obj". 999 1000 tools Build and install the host tools from src/tools. This 1001 command will first run "make obj" and "make cleandir" in 1002 the tools subdirectory unless the -o or -u options 1003 (respectively) are given. 1004 1005 install=idir Install the contents of DESTDIR to idir, using "make 1006 installworld". 1007 1008 Note: Files that are part of the "etc" or "xetc" sets will 1009 not be installed, unless overridden by the INSTALLSETS 1010 environment variable. 1011 1012 kernel=kconf Build a new kernel. The kconf argument is the name of a 1013 configuration file suitable for use by config(1). If kconf 1014 does not contain any `/' characters, the configuration file 1015 is expected to be found in the KERNCONFDIR directory, which 1016 is typically sys/arch/MACHINE/conf. The new kernel will be 1017 built in a subdirectory of KERNOBJDIR, which is typically 1018 sys/arch/MACHINE/compile or an associated object directory. 1019 1020 This command does not imply the tools command; run the 1021 tools command first unless it is certain that the tools 1022 already exist and are up to date. 1023 1024 This command will run "make cleandir" on the kernel in 1025 question first unless the -u option is given. 1026 1027 kernel.gdb=kconf 1028 Build a new kernel with debug information. Similar to the 1029 above kernel=kconf operation, but creates a netbsd.gdb file 1030 alongside of the kernel netbsd, which contains a full 1031 symbol table and can be used for debugging (for example 1032 with a cross-gdb built by MKCROSSGDB). 1033 1034 kernels This command will build all kernels defined in port 1035 specific release build procedure. 1036 1037 This command internally calls the kernel=kconf operation 1038 for each found kernel configuration file. 1039 1040 modules This command will build kernel modules and install them 1041 into DESTDIR. 1042 1043 releasekernel=kconf 1044 Install a gzip(1)ed copy of the kernel previously built by 1045 kernel=kconf into 1046 RELEASEDIR/RELEASEMACHINEDIR/binary/kernel, usually as 1047 netbsd-kconf.gz, although the "netbsd" prefix is determined 1048 from the "config" directives in kconf. 1049 1050 sets Perform "make sets". 1051 1052 sourcesets Perform "make sourcesets". 1053 1054 syspkgs Perform "make syspkgs". 1055 1056 iso-image Perform "make iso-image". 1057 1058 iso-image-source 1059 Perform "make iso-image-source". 1060 1061 install-image 1062 Perform "make install-image". 1063 1064 live-image Perform "make live-image". 1065 1066 list-arch Show a list of valid MACHINE and MACHINE_ARCH settings, the 1067 default MACHINE_ARCH for each MACHINE, and aliases for 1068 MACHINE/MACHINE_ARCH pairs, and then exits. The -m or -a 1069 options (or both) may be used to specify glob patterns that 1070 will be used to narrow the list of results; for example, 1071 "build.sh -m 'evb*' -a '*arm*' list-arch" will list all 1072 known MACHINE/MACHINE_ARCH values in which either MACHINE 1073 or ALIAS matches the pattern `evb*', and MACHINE_ARCH 1074 matches the pattern `*arm*'. 1075 1076 The following command line options alter the behaviour of the build.sh 1077 operations described above: 1078 1079 -a arch Set the value of MACHINE_ARCH to arch. See the -m option for 1080 more information. 1081 1082 -B buildid 1083 Set the value of BUILDID to buildid. This will also append the 1084 build identifier to the name of the "make" wrapper script so 1085 that the resulting name is of the form 1086 "nbmake-MACHINE-BUILDID". 1087 1088 -C cdextras 1089 Append cdextras to the CDEXTRA variable, which is a space- 1090 separated list of files or directories that will be added to 1091 the CD-ROM image that may be create by the "iso-image" or 1092 "iso-image-source" operations. Files will be added to the root 1093 of the CD-ROM image, whereas directories will be copied 1094 recursively. If relative paths are specified, they will be 1095 converted to absolute paths before being used. Multiple paths 1096 may be specified via multiple -C options, or via a single 1097 option whose argument contains multiple space-separated paths. 1098 1099 -c compiler 1100 Select the compiler for the toolchain to build NetBSD and for 1101 inclusion in the NetBSD distribution. Supported choices: 1102 1103 clang 1104 1105 gcc [default] 1106 1107 The compiler used to build the toolchain can be different; see 1108 HOST_CC and HOST_CXX. 1109 1110 -D dest Set the value of DESTDIR to dest. If a relative path is 1111 specified, it will be converted to an absolute path before 1112 being used. 1113 1114 -E Set `expert' mode. This overrides various sanity checks, and 1115 allows: DESTDIR does not have to be set to a non-root path for 1116 builds, and MKUNPRIVED=yes does not have to be set when 1117 building as a non-root user. 1118 1119 Note: It is highly recommended that you know what you are doing 1120 when you use this option. 1121 1122 -h Show a help message, and exit. 1123 1124 -j njob Run up to njob make(1) subjobs in parallel; passed through to 1125 make(1). If you see failures for reasons other than running 1126 out of memory while using build.sh with -j, please save 1127 complete build logs so the failures can be analyzed. 1128 1129 To achieve the fastest builds, -j values between (1 + the 1130 number of CPUs) and (2 * the number of CPUs) are recommended. 1131 Use lower values on machines with limited memory or I/O 1132 bandwidth. 1133 1134 -M obj Set MAKEOBJDIRPREFIX to obj. Unsets MAKEOBJDIR. See "-O obj" 1135 for more information. 1136 1137 For instance, if the source directory is /usr/src, a setting of 1138 "-M /usr/obj" will place build-time files under 1139 /usr/obj/usr/src/bin, /usr/obj/usr/src/lib, 1140 /usr/obj/usr/src/usr.bin, and so forth. 1141 1142 If a relative path is specified, it will be converted to an 1143 absolute path before being used. build.sh imposes the 1144 restriction that the argument to the -M option must not begin 1145 with a "$" (dollar sign) character; otherwise it would be too 1146 difficult to determine whether the value is an absolute or a 1147 relative path. If the directory does not already exist, 1148 build.sh will create it. 1149 1150 -m mach Set the value of MACHINE to mach, unless the mach argument is 1151 an alias that refers to a MACHINE/MACHINE_ARCH pair, in which 1152 case both MACHINE and MACHINE_ARCH are set from the alias. 1153 Such aliases are interpreted entirely by build.sh; they are not 1154 used by any other part of the build system. The MACHINE_ARCH 1155 setting implied by mach will override any value of MACHINE_ARCH 1156 in the process environment, but will not override a value set 1157 by the -a option. All cross builds require -m, but if unset on 1158 a NetBSD host, the host's value of MACHINE will be detected and 1159 used automatically. 1160 1161 See the list-arch operation for a way to get a list of valid 1162 MACHINE and MACHINE_ARCH settings. 1163 1164 -N noiselevel 1165 Set the "noisyness" level of the build, by setting MAKEVERBOSE 1166 to noiselevel. 1167 1168 -n Show the commands that would be executed by build.sh, but do 1169 not make any changes. This is similar in concept to "make -n". 1170 1171 -O obj Create an appropriate transform macro for MAKEOBJDIR that will 1172 place the built object files under obj. Unsets 1173 MAKEOBJDIRPREFIX. 1174 1175 For instance, a setting of "-O /usr/obj" will place build-time 1176 files under /usr/obj/bin, /usr/obj/lib, /usr/obj/usr.bin, and 1177 so forth. 1178 1179 If a relative path is specified, it will be converted to an 1180 absolute path before being used. build.sh imposes the 1181 restriction that the argument to the -O option must not contain 1182 a "$" (dollar sign) character. If the directory does not 1183 already exist, build.sh will create it. 1184 1185 In normal use, exactly one of the -M or -O options should be 1186 specified. If neither -M nor -O is specified, then a default 1187 object directory will be chosen according to rules in 1188 <bsd.obj.mk>. Relying on this default is not recommended 1189 because it is determined by complex rules that are influenced 1190 by the values of several variables and by the location of the 1191 source directory. 1192 1193 Note: Placing the obj directory location outside of the default 1194 source tree hierarchy makes it easier to manually clear out old 1195 files in the event the "make cleandir" operation is unable to 1196 do so. (See CAVEATS below.) 1197 1198 Note: The use of one of -M or -O is the only means of building 1199 multiple machine architecture userlands from the same source 1200 tree without cleaning between builds (in which case, one would 1201 specify distinct obj locations for each). 1202 1203 -o Set the value of MKOBJDIRS to "no". Otherwise, it will be 1204 automatically set to "yes". This default is opposite to the 1205 behaviour when not using build.sh. 1206 1207 -P Set the value of MKREPRO and MKREPRO_TIMESTAMP to the latest 1208 source CVS timestamp for reproducible builds. 1209 1210 -R rel Set the value of RELEASEDIR to rel. If a relative path is 1211 specified, it will be converted to an absolute path before 1212 being used. 1213 1214 -r Remove the contents of DESTDIR and TOOLDIR before building 1215 (provides a clean starting point). This will skip deleting 1216 DESTDIR if building on a native system to the root directory. 1217 1218 -S seed Change the value of BUILDSEED to seed. This should rarely be 1219 necessary. 1220 1221 -T tools Set the value of TOOLDIR to tools. If a relative path is 1222 specified, it will be converted to an absolute path before 1223 being used. If set, the bootstrap "make" will only be rebuilt 1224 if the source files for make(1) have changed. 1225 1226 -U Set MKUNPRIVED=yes. 1227 1228 -u Set MKUPDATE=yes. 1229 1230 -V var=[value] 1231 Set the environment variable var to an optional value. This is 1232 propagated to the nbmake wrapper. 1233 1234 -w wrapper 1235 Create the nbmake wrapper script (see below) in a custom 1236 location, specified by wrapper. This allows, for instance, to 1237 place the wrapper in PATH automatically. 1238 1239 Note: wrapper is the full name of the file, not just a 1240 directory name. If a relative path is specified, it will be 1241 converted to an absolute path before being used. 1242 1243 -X x11src 1244 Set the value of X11SRCDIR to x11src. If a relative path is 1245 specified, it will be converted to an absolute path before 1246 being used. 1247 1248 -x Set MKX11=yes. 1249 1250 -Z var Unset ("zap") the environment variable var. This is propagated 1251 to the nbmake wrapper. 1252 1253 -? Show a help message, and exit. 1254 1255 The "nbmake-MACHINE" wrapper script 1256 If using the build.sh script to build NetBSD, a nbmake-MACHINE script 1257 will be created in TOOLDIR/bin upon the first build to assist in building 1258 subtrees on a cross-compile host. 1259 1260 nbmake-MACHINE can be invoked in lieu of make(1), and will instead call 1261 the up-to-date version of "nbmake" installed into TOOLDIR/bin with 1262 several key variables pre-set, including MACHINE, MACHINE_ARCH, and 1263 TOOLDIR. nbmake-MACHINE will also set variables specified with -V, and 1264 unset variables specified with -Z. 1265 1266 This script can be symlinked into a directory listed in PATH, or called 1267 with an absolute path. 1268 1269EXAMPLES 1270 1. % ./build.sh [OPTIONS] tools kernel=GENERIC 1271 1272 Build a new toolchain, and use the new toolchain to configure and 1273 build a new GENERIC kernel. 1274 1275 2. % ./build.sh [OPTIONS] -U distribution 1276 1277 Using unprivileged mode, build a complete distribution to a DESTDIR 1278 directory that build.sh selects (and will show). 1279 1280 3. # ./build.sh [OPTIONS] -U install=/ 1281 1282 As root, install to / the distribution that was built by example 2. 1283 Even though this is run as root, -U is required so that the 1284 permissions stored in DESTDIR/METALOG are correctly applied to the 1285 files as they're copied to /. 1286 1287 4. % ./build.sh [OPTIONS] -U -u release 1288 1289 Using unprivileged mode, build a complete release to DESTDIR and 1290 RELEASEDIR directories that build.sh selects (and will show). 1291 MKUPDATE=yes (-u) is set to prevent the "make cleandir", so that if 1292 this is run after example 2, it doesn't need to redo that portion of 1293 the release build. 1294 1295OBSOLETE VARIABLES 1296 NBUILDJOBS Use the make(1) option -j instead. 1297 1298 USE_NEW_TOOLCHAIN 1299 The new toolchain is now the default. To disable, use 1300 TOOLCHAIN_MISSING=yes. 1301 1302SEE ALSO 1303 ar(1), config(1), ctags(1), cvs(1), cvslatest(1), ex(1), g++(1), gzip(1), 1304 ident(1), ld(1), lint(1), make(1), mkisofs(1), sh(1), uname(1), vi(1), 1305 options(4), mk.conf(5), atf(7), hier(7), release(7), sysctl(7), 1306 etcupdate(8), installboot(8), mount(8), mtree(8), postinstall(8), 1307 sysinst(8), pkgsrc/sysutils/cdrtools 1308 1309HISTORY 1310 The build.sh based build scheme was introduced for NetBSD 1.6 as 1311 USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that. 1312 1313CAVEATS 1314 After significant updates to third-party components in the source tree, 1315 the "make cleandir" operation may be insufficient to clean out old files 1316 in object directories. Instead, one may have to manually remove the 1317 files. Consult the UPDATING file for notices concerning this. 1318 1319NetBSD June 5, 2023 NetBSD 1320