BUILDING revision 1.161
11.104SwizBUILDING(8) System Manager's Manual BUILDING(8) 21.1Stv 31.105SwizNAME 41.150Slukem BUILDING - Procedure for building NetBSD from source code 51.1Stv 61.105SwizREQUIREMENTS 71.1Stv NetBSD is designed to be buildable on most POSIX-compliant host systems. 81.105Swiz The basic build procedure is the same whether compiling natively (on the 91.105Swiz same NetBSD architecture) or cross compiling (on another architecture or 101.1Stv OS). 111.1Stv 121.157Slukem This source tree contains the build.sh shell script which supports both 131.157Slukem native and cross builds of NetBSD. 141.157Slukem 151.126Swiz This source tree contains a special subtree, "tools", which uses the host 161.126Swiz system to create a build toolchain for the target architecture. The host 171.126Swiz system must have at least C and C++ compilers in order to create the 181.157Slukem toolchain (make(1) is not required); all other tools (including make(1) 191.157Slukem as nbmake) are created as part of the NetBSD build process. (See the 201.157Slukem Environment variables section below if you need to override or manually 211.157Slukem select your compilers.) 221.1Stv 231.155Slukem Note: Within this document, cross-references to manual pages are to the 241.155Slukem NetBSD manual pages, not the host system manual pages. The mdoc(7) 251.155Slukem source to the NetBSD manual pages can be found within the source tree, 261.155Slukem and these and can be formatted with mandoc(1) or nroff(1) if those are 271.155Slukem available on the host system. The NetBSD manual pages are also available 281.155Slukem at https://man.netbsd.org 291.155Slukem 301.105SwizFILES 311.105Swiz Source tree layout 321.151Slukem BUILDING This document (in plaintext). Generated from 331.151Slukem doc/BUILDING.mdoc. 341.48Sjmc 351.105Swiz Makefile The main Makefile for NetBSD; should only be run for 361.44Slukem native builds with an appropriately up-to-date version of 371.142Sandvar NetBSD make(1). Intended for expert use with knowledge of 381.129Ssevan its shortcomings, it has been superseded by the build.sh 391.129Ssevan shell script as the recommended means for building NetBSD. 401.1Stv 411.105Swiz UPDATING Special notes for updating from an earlier revision of 421.1Stv NetBSD. It is important to read this file before every 431.1Stv build of an updated source tree. 441.1Stv 451.105Swiz build.sh Bourne-compatible shell script used for building the host 461.1Stv build tools and the NetBSD system from scratch. Can be 471.1Stv used for both native and cross builds, and should be used 481.129Ssevan instead of make(1) as it performs additional checks to 491.129Ssevan prevent common issues going undetected, such as building 501.129Ssevan with an outdated version of make(1). 511.1Stv 521.105Swiz crypto/dist/, dist/, gnu/dist/ 531.104Swiz Sources imported verbatim from third parties, without 541.104Swiz mangling the existing build structure. Other source trees 551.126Swiz in bin through usr.sbin use the NetBSD make(1) "reachover" 561.126Swiz Makefile semantics when building these programs for a 571.126Swiz native host. 581.104Swiz 591.151Slukem distrib/, etc/ 601.151Slukem Sources for items used when making a full release 611.151Slukem snapshot, such as files installed in DESTDIR/etc on the 621.151Slukem destination system, boot media, and release notes. 631.151Slukem 641.151Slukem doc/BUILDING.mdoc 651.155Slukem The source to this document, in mdoc(7) format. Used to 661.155Slukem generate BUILDING. 671.151Slukem 681.158Slukem external/, sys/external/ 691.106Swiz Sources and build infrastructure for components imported 701.106Swiz (mostly) unchanged from upstream maintainers, sorted by 711.106Swiz applicable license. This is (slowly) replacing the 721.106Swiz crypto/dist, dist, and gnu/dist directories. 731.106Swiz 741.151Slukem external/mit/xorg/ 751.151Slukem "Reachover" build structure for modular Xorg; the source 761.151Slukem is in X11SRCDIR. 771.1Stv 781.157Slukem mk.conf Optional source tree specific mk.conf(5), used (if 791.157Slukem present) instead of /etc/mk.conf unless MAKECONF is 801.157Slukem defined. 811.157Slukem 821.157Slukem Note: Not part of the NetBSD source repository. 831.157Slukem 841.151Slukem regress/, tests/ 851.70Sdholland Regression test harness. Can be cross-compiled, but only 861.105Swiz run natively. tests/ uses the atf(7) test framework; 871.105Swiz regress/ contains older tests that have not yet been 881.70Sdholland migrated to atf(7). 891.1Stv 901.105Swiz sys/ NetBSD kernel sources. 911.1Stv 921.126Swiz tools/ "Reachover" build structure for the host build tools. 931.104Swiz This has a special method of determining out-of-date 941.104Swiz status. 951.1Stv 961.151Slukem tools/compat/README 971.151Slukem Special notes for cross-hosting a NetBSD build on non- 981.151Slukem NetBSD platforms. 991.151Slukem 1001.151Slukem Other directories including bin/ ... usr.sbin/ 1011.1Stv Sources to the NetBSD userland (non-kernel) programs. If 1021.1Stv any of these directories are missing, they will be skipped 1031.1Stv during the build. 1041.1Stv 1051.105Swiz Build tree layout 1061.156Slukem The NetBSD build tree is described in hier(7) (whose mdoc(7) source is in 1071.155Slukem share/man/man7/hier.7), and the release layout is described in release(7) 1081.156Slukem (whose mdoc(7) source is in share/man/man7/release.7). 1091.1Stv 1101.105SwizCONFIGURATION 1111.105Swiz Environment variables 1121.8Slukem Several environment variables control the behaviour of NetBSD builds. 1131.8Slukem 1141.152Slukem HOST_CC Path name to C compiler used to create the toolchain. 1151.58Sapb 1161.155Slukem Default: "cc". 1171.155Slukem 1181.152Slukem HOST_CFLAGS Flags passed to the host C compiler. 1191.53Sreed 1201.155Slukem Default: "-O". 1211.155Slukem 1221.155Slukem HOST_CPPFLAGS Flags passed to the host C/C++ pre-processor. 1231.155Slukem 1241.155Slukem Default: Unset. 1251.155Slukem 1261.152Slukem HOST_CXX Path name to C++ compiler used to create the toolchain. 1271.137Suwe 1281.155Slukem Default: Unset, but defaults to "c++" where required. 1291.155Slukem 1301.152Slukem HOST_CXXFLAGS Flags passed to the host C++ compiler. 1311.53Sreed 1321.155Slukem Default: Unset. 1331.155Slukem 1341.152Slukem HOST_SH Path name to a shell available on the host system and 1351.152Slukem suitable for use during the build. The NetBSD build 1361.152Slukem system requires a modern Bourne-like shell with POSIX- 1371.152Slukem compliant features, and also requires support for the 1381.152Slukem "local" keyword to declare local variables in shell 1391.152Slukem functions (which is a widely-implemented but non- 1401.152Slukem standardised feature). 1411.152Slukem 1421.152Slukem Depending on the host system, a suitable shell may be 1431.152Slukem /bin/sh, /usr/xpg4/bin/sh, /bin/ksh (provided it is a 1441.152Slukem variant of ksh that supports the "local" keyword, such as 1451.152Slukem ksh88, but not ksh93), or /usr/local/bin/bash. 1461.152Slukem 1471.152Slukem Most parts of the build require HOST_SH to be an absolute 1481.152Slukem path; however, build.sh allows it to be a simple command 1491.152Slukem name, which will be converted to an absolute path by 1501.152Slukem searching the PATH. 1511.137Suwe 1521.155Slukem Default: "sh". 1531.155Slukem 1541.147Slukem INSTALLBOOT_UBOOT_PATHS 1551.152Slukem A colon-separated list of search paths used by 1561.152Slukem installboot(8) to find U-Boot packages. 1571.147Slukem 1581.155Slukem Default: Unset. 1591.155Slukem 1601.152Slukem MACHINE Machine type, e.g., "macppc". 1611.8Slukem 1621.155Slukem Default: Unset. 1631.155Slukem 1641.152Slukem MACHINE_ARCH Machine architecture, e.g., "powerpc". 1651.8Slukem 1661.155Slukem Default: Unset. 1671.155Slukem 1681.152Slukem MAKE Path name to invoke make(1) as. 1691.8Slukem 1701.155Slukem Default: "make". 1711.155Slukem 1721.160Slukem MAKECONF The name of the make(1) configuration file. See make 1731.152Slukem variables and mk.conf(5). 1741.151Slukem 1751.152Slukem Note: Only settable in the process environment. 1761.151Slukem 1771.157Slukem Default: "/etc/mk.conf", although build.sh will set the 1781.157Slukem default to the full path to mk.conf if the latter is 1791.157Slukem present in the same directory as build.sh. 1801.151Slukem 1811.152Slukem MAKEFLAGS Flags to invoke make(1) with. 1821.151Slukem 1831.152Slukem Note: build.sh ignores the value of MAKEFLAGS passed in 1841.152Slukem the environment, but allows MAKEFLAGS to be set via the 1851.152Slukem -V option. 1861.151Slukem 1871.155Slukem Default: "-X" on systems with a small ARG_MAX (Cygwin, 1881.155Slukem Darwin, FreeBSD); otherwise unset. 1891.155Slukem 1901.152Slukem MAKEOBJDIR Directory to use as the .OBJDIR for the current 1911.152Slukem directory. The value is subjected to variable expansion 1921.152Slukem by make(1). Typical usage is to set this variable to a 1931.152Slukem value involving the use of `${.CURDIR:S...}' or 1941.152Slukem `${.CURDIR:C...}', to derive the value of .OBJDIR from 1951.152Slukem the value of .CURDIR. Used only if MAKEOBJDIRPREFIX is 1961.152Slukem not defined. 1971.151Slukem 1981.152Slukem Note: MAKEOBJDIR can be provided only in the environment 1991.152Slukem or via the -O flag of build.sh; it cannot usefully be set 2001.152Slukem inside a Makefile, including in mk.conf(5) or MAKECONF. 2011.151Slukem 2021.155Slukem Default: Unset. 2031.155Slukem 2041.151Slukem MAKEOBJDIRPREFIX 2051.152Slukem Top level directory of the object directory tree. The 2061.152Slukem value is subjected to variable expansion by make(1). 2071.152Slukem build.sh will create the ${MAKEOBJDIRPREFIX} directory if 2081.152Slukem necessary, but if make(1) is used without build.sh, then 2091.152Slukem rules in <bsd.obj.mk> will abort the build if the 2101.152Slukem ${MAKEOBJDIRPREFIX} directory does not exist. If the 2111.152Slukem value is defined and valid, then 2121.152Slukem ${MAKEOBJDIRPREFIX}/${.CURDIR} is used as the .OBJDIR for 2131.152Slukem the current directory. The current directory may be read 2141.152Slukem only. 2151.152Slukem 2161.152Slukem Note: MAKEOBJDIRPREFIX can be provided only in the 2171.152Slukem environment or via the -M flag of build.sh; it cannot 2181.152Slukem usefully be set inside a Makefile, including in 2191.152Slukem mk.conf(5) or MAKECONF. 2201.152Slukem 2211.155Slukem Default: Unset. 2221.155Slukem 2231.152Slukem TMPDIR Top-level directory to store temporary directories used 2241.152Slukem by build.sh before paths to other directories such as 2251.152Slukem .OBJDIR can be determined. 2261.149Slukem 2271.152Slukem Note: Must support execution of binaries. I.e., without 2281.152Slukem mount(8)'s -o noexec option. 2291.149Slukem 2301.152Slukem Default: "/tmp". 2311.149Slukem 2321.160Slukem make variables 2331.156Slukem Variables that control the behavior of NetBSD builds are documented in 2341.156Slukem mk.conf(5) (whose mdoc(7) source is in share/man/man5/mk.conf.5). 2351.45Slukem 2361.155Slukem Unless otherwise specified, these variables may be set in either the 2371.155Slukem process environment or the make(1) configuration file mk.conf(5) 2381.155Slukem specified by MAKECONF. 2391.49Slukem 2401.159Slukem Note: Variables set in the environment, either directly or via build.sh 2411.159Slukem options to set specific values in the nbmake-MACHINE wrapper script do 2421.159Slukem not override variables set in the mk.conf(5) file. To allow variables in 2431.159Slukem mk.conf(5) to be overridden by the environment or build.sh options, 2441.159Slukem define the variables using the "?=" make(1) variable assignment operator. 2451.159Slukem For example, 2461.159Slukem 2471.159Slukem MAKEVERBOSE?=1 2481.159Slukem 2491.160Slukem The supported mk.conf(5) make variables are: 2501.160Slukem 2511.160Slukem BSDOBJDIR, BSDSRCDIR, BUILD, BUILDID, BUILDINFO, BUILDSEED, 2521.160Slukem CDEXTRA, CONFIGOPTS, COPTS, CPUFLAGS, DESTDIR, EXTERNAL_TOOLCHAIN, 2531.160Slukem INSTALLBOOT_BOARDS, INSTALLWORLDDIR, KERNARCHDIR, KERNCONFDIR, 2541.160Slukem KERNEL_DIR, KERNOBJDIR, KERNSRCDIR, LOCALTIME, MAKEVERBOSE, 2551.160Slukem MKAMDGPUFIRMWARE, MKARGON2, MKARZERO, MKATF, MKBINUTILS, MKBSDGREP, 2561.160Slukem MKBSDTAR, MKCATPAGES, MKCLEANSRC, MKCLEANVERIFY, MKCOMPAT, 2571.160Slukem MKCOMPATMODULES, MKCOMPATTESTS, MKCOMPATX11, MKCOMPLEX, MKCROSSGDB, 2581.160Slukem MKCTF, MKCVS, MKCXX, MKDEBUG, MKDEBUGKERNEL, MKDEBUGLIB, 2591.160Slukem MKDEBUGTOOLS, MKDEPINCLUDES, MKDOC, MKDTB, MKDTC, MKDTRACE, 2601.160Slukem MKDYNAMICROOT, MKFIRMWARE, MKGCC, MKGCCCMDS, MKGDB, MKGROFF, 2611.160Slukem MKGROFFHTMLDOC, MKHESIOD, MKHOSTOBJ, MKHTML, MKIEEEFP, MKINET6, 2621.160Slukem MKINFO, MKIPFILTER, MKISCSI, MKKERBEROS, MKKMOD, MKKYUA, MKLDAP, 2631.160Slukem MKLIBCSANITIZER, MKLIBCXX, MKLIBSTDCXX, MKLINKLIB, MKLINT, MKLLVM, 2641.160Slukem MKLLVMRT, MKLVM, MKMAKEMANDB, MKMAN, MKMANDOC, MKMANZ, MKMDNS, 2651.160Slukem MKNLS, MKNOUVEAUFIRMWARE, MKNPF, MKNSD, MKOBJ, MKOBJDIRS, MKPAM, 2661.160Slukem MKPCC, MKPF, MKPIC, MKPICINSTALL, MKPICLIB, MKPIE, MKPIGZGZIP, 2671.160Slukem MKPOSTFIX, MKPROFILE, MKRADEONFIRMWARE, MKRELRO, MKREPRO, 2681.160Slukem MKREPRO_TIMESTAMP, MKRUMP, MKSANITIZER, MKSHARE, MKSKEY, MKSLJIT, 2691.160Slukem MKSOFTFLOAT, MKSTATICLIB, MKSTATICPIE, MKSTRIPIDENT, MKSTRIPSYM, 2701.160Slukem MKTEGRAFIRMWARE, MKTPM, MKUNBOUND, MKUNPRIVED, MKUPDATE, MKX11, 2711.160Slukem MKX11FONTS, MKX11MOTIF, MKXORG_SERVER, MKYP, MKZFS, NETBSDSRCDIR, 2721.160Slukem NETBSD_OFFICIAL_RELEASE, NOCLEANDIR, NODISTRIBDIRS, NOINCLUDES, 2731.160Slukem OBJMACHINE, RELEASEDIR, RUMPUSER_THREADS, RUMP_CURLWP, RUMP_DEBUG, 2741.160Slukem RUMP_DIAGNOSTIC, RUMP_KTRACE, RUMP_LOCKDEBUG, RUMP_LOCKS_UP, 2751.160Slukem RUMP_NBCOMPAT, RUMP_VIRTIF, RUMP_VNODE_LOCKDEBUG, 2761.160Slukem TOOLCHAIN_MISSING, TOOLDIR, USETOOLS, USE_FORT, USE_HESIOD, 2771.160Slukem USE_INET6, USE_JEMALLOC, USE_KERBEROS, USE_LDAP, USE_LIBCSANITIZER, 2781.160Slukem USE_PAM, USE_PIGZGZIP, USE_SANITIZER, USE_SKEY, USE_SSP, 2791.160Slukem USE_XZ_SETS, USE_YP, X11MOTIFPATH, X11SRCDIR. 2801.160Slukem 2811.160Slukem The obsolete mk.conf(5) make variables are: 2821.160Slukem 2831.160Slukem EXTSRCSRCDIR, MKBFD, MKCRYPTO, MKEXTSRC, MKKDEBUG, MKKERBEROS4, 2841.160Slukem MKLLD, MKLLDB, MKMCLINKER, MKPERFUSE, MKTOOLSDEBUG, NBUILDJOBS, 2851.160Slukem SHAREDSTRINGS, USE_COMBINE, USE_NEW_TOOLCHAIN. 2861.160Slukem 2871.105SwizBUILDING 2881.160Slukem make command line options 2891.52Sjmc This is not a summary of all the options available to make(1); only the 2901.52Sjmc options used most frequently with NetBSD builds are listed here. 2911.1Stv 2921.105Swiz -j njob Run up to njob make(1) subjobs in parallel. Makefiles should 2931.52Sjmc use .WAIT or have explicit dependencies as necessary to 2941.74Sapb enforce build ordering. 2951.10Ssommerfe 2961.105Swiz -m dir Specify the default directory for searching for system 2971.104Swiz Makefile segments, mainly the <bsd.*.mk> files. When building 2981.104Swiz any full NetBSD source tree, this should be set to the 2991.126Swiz "share/mk" directory in the source tree. This is set 3001.104Swiz automatically when building from the top level, or when using 3011.105Swiz build.sh. 3021.1Stv 3031.148Slukem -n Show the commands that would have been executed, but do not 3041.1Stv actually execute them. This will still cause recursion to 3051.1Stv take place. 3061.1Stv 3071.148Slukem -V var Show make(1)'s idea of the value of var. Does not build any 3081.1Stv targets. 3091.1Stv 3101.105Swiz var=value Set the variable var to value, overriding any setting 3111.105Swiz specified by the process environment, the MAKECONF 3121.104Swiz configuration file, or the system Makefile segments. 3131.1Stv 3141.160Slukem make targets 3151.1Stv These default targets may be built by running make(1) in any subtree of 3161.1Stv the NetBSD source code. It is recommended that none of these be used 3171.126Swiz from the top level Makefile; as a specific exception, "make obj" and 3181.126Swiz "make cleandir" are useful in that context. 3191.1Stv 3201.105Swiz all Build programs, libraries, and preformatted documentation. 3211.1Stv 3221.105Swiz clean Remove program and library object code files. 3231.1Stv 3241.105Swiz cleandir Same as clean, but also remove preformatted documentation, 3251.126Swiz dependency files generated by "make depend", and any other 3261.49Slukem files known to be created at build time. 3271.1Stv 3281.105Swiz depend Create dependency files (.depend) containing more detailed 3291.44Slukem information about the dependencies of source code on header 3301.1Stv files. Allows programs to be recompiled automatically when a 3311.1Stv dependency changes. 3321.1Stv 3331.126Swiz dependall Does a "make depend" immediately followed by a "make all". 3341.10Ssommerfe This improves cache locality of the build since both passes 3351.10Ssommerfe read the source files in their entirety. 3361.1Stv 3371.105Swiz distclean Synonym for cleandir. 3381.49Slukem 3391.105Swiz includes Build and install system header files. Typically needed 3401.44Slukem before any system libraries or programs can be built. 3411.1Stv 3421.105Swiz install Install programs, libraries, and documentation into DESTDIR. 3431.105Swiz Few files will be installed to DESTDIR/dev, DESTDIR/etc, 3441.105Swiz DESTDIR/root or DESTDIR/var in order to prevent user supplied 3451.27Slukem configuration data from being overwritten. 3461.1Stv 3471.105Swiz lint Run lint(1) against the C source code, where appropriate, and 3481.1Stv generate system-installed lint libraries. 3491.1Stv 3501.105Swiz obj Create object directories to be used for built files, instead 3511.1Stv of building directly in the source tree. 3521.1Stv 3531.105Swiz tags Create ctags(1) searchable function lists usable by the ex(1) 3541.1Stv and vi(1) text editors. 3551.1Stv 3561.160Slukem make targets for the top level 3571.1Stv Additional make(1) targets are usable specifically from the top source 3581.1Stv level to facilitate building the entire NetBSD source tree. 3591.1Stv 3601.105Swiz build Build the entire NetBSD system (except the kernel). This 3611.68Sreed orders portions of the source tree such that prerequisites 3621.68Sreed will be built in the proper order. 3631.20Slukem 3641.126Swiz distribution Do a "make build", and then install a full distribution 3651.105Swiz (which does not include a kernel) into DESTDIR, including 3661.105Swiz files in DESTDIR/dev, DESTDIR/etc, DESTDIR/root and 3671.105Swiz DESTDIR/var. 3681.20Slukem 3691.126Swiz buildworld As per "make distribution", except that it ensures that 3701.105Swiz DESTDIR is not the root directory. 3711.20Slukem 3721.105Swiz installworld Install the distribution from DESTDIR to INSTALLWORLDDIR, 3731.70Sdholland which defaults to the root directory. Ensures that 3741.105Swiz INSTALLWORLDDIR is not the root directory if cross 3751.104Swiz compiling. 3761.20Slukem 3771.105Swiz The INSTALLSETS environment variable may be set to a space- 3781.95Sapb separated list of distribution sets to be installed. By 3791.126Swiz default, all sets except "etc" and "xetc" are installed, so 3801.126Swiz most files in INSTALLWORLDDIR/etc will not be installed or 3811.126Swiz modified. 3821.61Sapb 3831.105Swiz Note: Before performing this operation with 3841.105Swiz INSTALLWORLDDIR=/, it is highly recommended that you 3851.61Sapb upgrade your kernel and reboot. After performing this 3861.61Sapb operation, it is recommended that you use etcupdate(8) to 3871.105Swiz update files in INSTALLWORLDDIR/etc, and postinstall(8) to 3881.102Sabs check for or fix inconsistencies. 3891.20Slukem 3901.105Swiz sets Create distribution sets from DESTDIR into 3911.105Swiz RELEASEDIR/RELEASEMACHINEDIR/binary/sets. Should be run 3921.126Swiz after "make distribution", as "make build" alone does not 3931.126Swiz install all of the required files. 3941.25Slukem 3951.105Swiz sourcesets Create source sets of the source tree into 3961.105Swiz RELEASEDIR/source/sets. 3971.31Slukem 3981.105Swiz syspkgs Create syspkgs from DESTDIR into 3991.105Swiz RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs. Should be run 4001.126Swiz after "make distribution", as "make build" alone does not 4011.126Swiz install all of the required files. 4021.54Sapb 4031.126Swiz release Do a "make distribution", build kernels, distribution 4041.126Swiz media, and install sets (this as per "make sets"), and then 4051.126Swiz package the system into a standard release layout as 4061.105Swiz described by release(7). This requires that RELEASEDIR be 4071.25Slukem set (see above). 4081.1Stv 4091.105Swiz iso-image Create a NetBSD installation CD-ROM image in the 4101.114Ssnj RELEASEDIR/images directory. The CD-ROM file system will 4111.114Ssnj have a layout as described in release(7). 4121.62Sapb 4131.62Sapb For most machine types, the CD-ROM will be bootable, and 4141.104Swiz will automatically run the sysinst(8) menu-based 4151.104Swiz installation program, which can be used to install or 4161.104Swiz upgrade a NetBSD system. Bootable CD-ROMs also contain 4171.104Swiz tools that may be useful in repairing a damaged NetBSD 4181.104Swiz installation. 4191.62Sapb 4201.126Swiz Before "make iso-image" is attempted, RELEASEDIR must be 4211.126Swiz populated by "make release" or equivalent. 4221.62Sapb 4231.151Slukem Note: Other, smaller, CD-ROM images may be created in the 4241.151Slukem RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom directory 4251.151Slukem by "make release". These smaller images usually contain 4261.151Slukem the same tools as the larger images in RELEASEDIR/images, 4271.151Slukem but do not contain additional content such as the 4281.151Slukem distribution sets. 4291.62Sapb 4301.151Slukem Note: The mac68k port still uses an older method of 4311.104Swiz creating CD-ROM images. This requires the mkisofs(1) 4321.104Swiz utility, which is not part of NetBSD, but which can be 4331.105Swiz installed from pkgsrc/sysutils/cdrtools. 4341.56Sapb 4351.105Swiz iso-image-source 4361.64Sjnemeth Create a NetBSD installation CD-ROM image in the 4371.114Ssnj RELEASEDIR/images directory. The CD-ROM file system will 4381.114Ssnj have a layout as described in release(7). It will have top 4391.64Sjnemeth level directories for the machine type and source. 4401.64Sjnemeth 4411.64Sjnemeth For most machine types, the CD-ROM will be bootable, and 4421.104Swiz will automatically run the sysinst(8) menu-based 4431.104Swiz installation program, which can be used to install or 4441.104Swiz upgrade a NetBSD system. Bootable CD-ROMs also contain 4451.104Swiz tools that may be useful in repairing a damaged NetBSD 4461.104Swiz installation. 4471.64Sjnemeth 4481.126Swiz Before "make iso-image-source" is attempted, RELEASEDIR 4491.126Swiz must be populated by "make sourcesets release" or 4501.104Swiz equivalent. 4511.64Sjnemeth 4521.151Slukem Note: Other, smaller, CD-ROM images may be created in the 4531.151Slukem RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom directory 4541.151Slukem by "make release". These smaller images usually contain 4551.151Slukem the same tools as the larger images in RELEASEDIR/images, 4561.151Slukem but do not contain additional content such as the 4571.151Slukem distribution sets. 4581.64Sjnemeth 4591.151Slukem Note: The mac68k port still uses an older method of 4601.104Swiz creating CD-ROM images. This requires the mkisofs(1) 4611.104Swiz utility, which is not part of NetBSD, but which can be 4621.105Swiz installed from pkgsrc/sysutils/cdrtools. 4631.64Sjnemeth 4641.105Swiz install-image 4651.98Sapb Create a bootable NetBSD installation disk image in the 4661.127Splunky RELEASEDIR/images directory. The installation disk image 4671.127Splunky is suitable for copying to bootable USB flash memory 4681.127Splunky sticks, etc., for machines which are able to boot from such 4691.127Splunky devices. The file system in the bootable disk image will 4701.127Splunky have a layout as described in release(7). 4711.97Stsutsui 4721.97Stsutsui The installation image is bootable, and will automatically 4731.97Stsutsui run the sysinst(8) menu-based installation program, which 4741.98Sapb can be used to install or upgrade a NetBSD system. The 4751.98Sapb image also contains tools that may be useful in repairing a 4761.98Sapb damaged NetBSD installation. 4771.97Stsutsui 4781.126Swiz Before "make install-image" is attempted, RELEASEDIR must 4791.126Swiz be populated by "make release" or equivalent. The build 4801.126Swiz must have been performed with MKUNPRIVED=yes because "make 4811.126Swiz install-image" relies on information in DESTDIR/METALOG. 4821.97Stsutsui 4831.120Spgoyette live-image Create NetBSD live images in the RELEASEDIR/images 4841.104Swiz directory. The live image contains all necessary files to 4851.104Swiz boot NetBSD up to multi-user mode, including all files 4861.104Swiz which should be extracted during installation, NetBSD 4871.104Swiz disklabel, bootloaders, etc. 4881.104Swiz 4891.104Swiz The live image is suitable for use as a disk image in 4901.104Swiz virtual machine environments such as QEMU, and also useful 4911.104Swiz to boot NetBSD from a USB flash memory stick on a real 4921.98Sapb machine, without the need for installation. 4931.97Stsutsui 4941.126Swiz Before "make live-image" is attempted, RELEASEDIR must be 4951.126Swiz populated by "make release" or equivalent. The build must 4961.126Swiz have been performed with MKUNPRIVED=yes because "make 4971.126Swiz install-image" relies on information in DESTDIR/METALOG. 4981.97Stsutsui 4991.105Swiz regression-tests 5001.20Slukem Can only be run after building the regression tests in the 5011.126Swiz directory "regress". Runs those compiled regression tests 5021.151Slukem on the local host. 5031.151Slukem 5041.151Slukem Note: Most tests are now managed instead using atf(7); this 5051.151Slukem target should probably run those as well but currently does 5061.151Slukem not. 5071.1Stv 5081.160Slukem The build.sh script 5091.96Sapb This script file is a shell script designed to build the entire NetBSD 5101.104Swiz system on any host with a suitable modern shell and some common 5111.105Swiz utilities. The required shell features are described under the HOST_SH 5121.104Swiz variable. 5131.96Sapb 5141.96Sapb If a host system's default shell does support the required features, then 5151.96Sapb we suggest that you explicitly specify a suitable shell using a command 5161.96Sapb like 5171.96Sapb 5181.105Swiz /path/to/suitable/shell build.sh [options] 5191.96Sapb 5201.105Swiz The above command will usually enable build.sh to automatically set 5211.105Swiz HOST_SH=/path/to/suitable/shell, but if that fails, then the following 5221.96Sapb set of commands may be used instead: 5231.96Sapb 5241.105Swiz HOST_SH=/path/to/suitable/shell 5251.96Sapb export HOST_SH 5261.105Swiz ${HOST_SH} build.sh [options] 5271.96Sapb 5281.105Swiz If build.sh detects that it is being executed under an unsuitable shell, 5291.148Slukem it attempts to exec a suitable shell instead, or shows an error message. 5301.105Swiz If HOST_SH is not set explicitly, then build.sh sets a default using 5311.96Sapb heuristics dependent on the host platform, or from the shell under which 5321.105Swiz build.sh is executed (if that can be determined), or using the first copy 5331.105Swiz of sh found in PATH. 5341.1Stv 5351.1Stv All cross-compile builds, and most native builds, of the entire system 5361.126Swiz should make use of build.sh rather than just running "make". This way, 5371.104Swiz the make(1) program will be bootstrapped properly, in case the host 5381.126Swiz system has an older or incompatible "make" program. 5391.1Stv 5401.105Swiz When compiling the entire system via build.sh, many make(1) variables are 5411.1Stv set for you in order to help encapsulate the build process. In the list 5421.105Swiz of options below, variables that are automatically set by build.sh are 5431.1Stv noted where applicable. 5441.1Stv 5451.105Swiz The following operations are supported by build.sh: 5461.22Slukem 5471.126Swiz build Build the system as per "make build". Before the main part 5481.126Swiz of the build commences, this command runs the obj operation 5491.126Swiz (unless the -o option is given), "make cleandir" (unless 5501.126Swiz the -u option is given), and the tools operation. 5511.22Slukem 5521.126Swiz distribution Build a full distribution as per "make distribution". This 5531.126Swiz command first runs the build operation. 5541.22Slukem 5551.126Swiz release Build a full release as per "make release". This command 5561.105Swiz first runs the distribution operation. 5571.22Slukem 5581.148Slukem help Show a help message, and exit. 5591.148Slukem 5601.159Slukem makewrapper Create the nbmake-MACHINE wrapper script. This operation 5611.159Slukem is automatically performed for any of the other operations. 5621.23Slukem 5631.126Swiz cleandir Perform "make cleandir". 5641.75Slukem 5651.126Swiz obj Perform "make obj". 5661.22Slukem 5671.105Swiz tools Build and install the host tools from src/tools. This 5681.126Swiz command will first run "make obj" and "make cleandir" in 5691.126Swiz the tools subdirectory unless the -o or -u options 5701.104Swiz (respectively) are given. 5711.22Slukem 5721.126Swiz install=idir Install the contents of DESTDIR to idir, using "make 5731.151Slukem installworld". 5741.151Slukem 5751.151Slukem Note: Files that are part of the "etc" or "xetc" sets will 5761.151Slukem not be installed, unless overridden by the INSTALLSETS 5771.151Slukem environment variable. 5781.35Slukem 5791.105Swiz kernel=kconf Build a new kernel. The kconf argument is the name of a 5801.105Swiz configuration file suitable for use by config(1). If kconf 5811.22Slukem does not contain any `/' characters, the configuration file 5821.105Swiz is expected to be found in the KERNCONFDIR directory, which 5831.105Swiz is typically sys/arch/MACHINE/conf. The new kernel will be 5841.105Swiz built in a subdirectory of KERNOBJDIR, which is typically 5851.105Swiz sys/arch/MACHINE/compile or an associated object directory. 5861.70Sdholland 5871.105Swiz This command does not imply the tools command; run the 5881.105Swiz tools command first unless it is certain that the tools 5891.70Sdholland already exist and are up to date. 5901.70Sdholland 5911.126Swiz This command will run "make cleandir" on the kernel in 5921.105Swiz question first unless the -u option is given. 5931.22Slukem 5941.106Swiz kernel.gdb=kconf 5951.106Swiz Build a new kernel with debug information. Similar to the 5961.106Swiz above kernel=kconf operation, but creates a netbsd.gdb file 5971.106Swiz alongside of the kernel netbsd, which contains a full 5981.106Swiz symbol table and can be used for debugging (for example 5991.106Swiz with a cross-gdb built by MKCROSSGDB). 6001.106Swiz 6011.113Suebayasi kernels This command will build all kernels defined in port 6021.113Suebayasi specific release build procedure. 6031.111Suebayasi 6041.112Suebayasi This command internally calls the kernel=kconf operation 6051.112Suebayasi for each found kernel configuration file. 6061.111Suebayasi 6071.105Swiz modules This command will build kernel modules and install them 6081.105Swiz into DESTDIR. 6091.86Sjnemeth 6101.105Swiz releasekernel=kconf 6111.70Sdholland Install a gzip(1)ed copy of the kernel previously built by 6121.105Swiz kernel=kconf into 6131.105Swiz RELEASEDIR/RELEASEMACHINEDIR/binary/kernel, usually as 6141.126Swiz netbsd-kconf.gz, although the "netbsd" prefix is determined 6151.126Swiz from the "config" directives in kconf. 6161.24Slukem 6171.126Swiz sets Perform "make sets". 6181.31Slukem 6191.126Swiz sourcesets Perform "make sourcesets". 6201.22Slukem 6211.126Swiz syspkgs Perform "make syspkgs". 6221.54Sapb 6231.126Swiz iso-image Perform "make iso-image". 6241.56Sapb 6251.105Swiz iso-image-source 6261.126Swiz Perform "make iso-image-source". 6271.65Sjnemeth 6281.105Swiz install-image 6291.126Swiz Perform "make install-image". 6301.97Stsutsui 6311.126Swiz live-image Perform "make live-image". 6321.97Stsutsui 6331.148Slukem list-arch Show a list of valid MACHINE and MACHINE_ARCH settings, the 6341.148Slukem default MACHINE_ARCH for each MACHINE, and aliases for 6351.109Sapb MACHINE/MACHINE_ARCH pairs, and then exits. The -m or -a 6361.109Sapb options (or both) may be used to specify glob patterns that 6371.109Sapb will be used to narrow the list of results; for example, 6381.131Sleot "build.sh -m 'evb*' -a '*arm*' list-arch" will list all 6391.109Sapb known MACHINE/MACHINE_ARCH values in which either MACHINE 6401.109Sapb or ALIAS matches the pattern `evb*', and MACHINE_ARCH 6411.109Sapb matches the pattern `*arm*'. 6421.109Sapb 6431.105Swiz The following command line options alter the behaviour of the build.sh 6441.51Swiz operations described above: 6451.1Stv 6461.109Sapb -a arch Set the value of MACHINE_ARCH to arch. See the -m option for 6471.109Sapb more information. 6481.9Sthorpej 6491.105Swiz -B buildid 6501.105Swiz Set the value of BUILDID to buildid. This will also append the 6511.159Slukem build identifier to the name of the nbmake-MACHINE wrapper 6521.159Slukem script so that the resulting name is of the form 6531.126Swiz "nbmake-MACHINE-BUILDID". 6541.1Stv 6551.105Swiz -C cdextras 6561.105Swiz Append cdextras to the CDEXTRA variable, which is a space- 6571.104Swiz separated list of files or directories that will be added to 6581.126Swiz the CD-ROM image that may be create by the "iso-image" or 6591.126Swiz "iso-image-source" operations. Files will be added to the root 6601.126Swiz of the CD-ROM image, whereas directories will be copied 6611.87Sapb recursively. If relative paths are specified, they will be 6621.87Sapb converted to absolute paths before being used. Multiple paths 6631.105Swiz may be specified via multiple -C options, or via a single 6641.87Sapb option whose argument contains multiple space-separated paths. 6651.66Sjnemeth 6661.136Suwe -c compiler 6671.136Suwe Select the compiler for the toolchain to build NetBSD and for 6681.136Suwe inclusion in the NetBSD distribution. Supported choices: 6691.136Suwe 6701.136Suwe clang 6711.136Suwe 6721.136Suwe gcc [default] 6731.136Suwe 6741.136Suwe The compiler used to build the toolchain can be different; see 6751.136Suwe HOST_CC and HOST_CXX. 6761.136Suwe 6771.105Swiz -D dest Set the value of DESTDIR to dest. If a relative path is 6781.104Swiz specified, it will be converted to an absolute path before 6791.104Swiz being used. 6801.104Swiz 6811.105Swiz -E Set `expert' mode. This overrides various sanity checks, and 6821.105Swiz allows: DESTDIR does not have to be set to a non-root path for 6831.105Swiz builds, and MKUNPRIVED=yes does not have to be set when 6841.104Swiz building as a non-root user. 6851.23Slukem 6861.105Swiz Note: It is highly recommended that you know what you are doing 6871.23Slukem when you use this option. 6881.19Slukem 6891.148Slukem -h Show a help message, and exit. 6901.51Swiz 6911.105Swiz -j njob Run up to njob make(1) subjobs in parallel; passed through to 6921.74Sapb make(1). If you see failures for reasons other than running 6931.105Swiz out of memory while using build.sh with -j, please save 6941.104Swiz complete build logs so the failures can be analyzed. 6951.74Sapb 6961.105Swiz To achieve the fastest builds, -j values between (1 + the 6971.104Swiz number of CPUs) and (2 * the number of CPUs) are recommended. 6981.104Swiz Use lower values on machines with limited memory or I/O 6991.104Swiz bandwidth. 7001.104Swiz 7011.126Swiz -M obj Set MAKEOBJDIRPREFIX to obj. Unsets MAKEOBJDIR. See "-O obj" 7021.126Swiz for more information. 7031.104Swiz 7041.105Swiz For instance, if the source directory is /usr/src, a setting of 7051.126Swiz "-M /usr/obj" will place build-time files under 7061.105Swiz /usr/obj/usr/src/bin, /usr/obj/usr/src/lib, 7071.105Swiz /usr/obj/usr/src/usr.bin, and so forth. 7081.88Sapb 7091.73Sapb If a relative path is specified, it will be converted to an 7101.105Swiz absolute path before being used. build.sh imposes the 7111.105Swiz restriction that the argument to the -M option must not begin 7121.126Swiz with a "$" (dollar sign) character; otherwise it would be too 7131.104Swiz difficult to determine whether the value is an absolute or a 7141.104Swiz relative path. If the directory does not already exist, 7151.105Swiz build.sh will create it. 7161.18Slukem 7171.109Sapb -m mach Set the value of MACHINE to mach, unless the mach argument is 7181.109Sapb an alias that refers to a MACHINE/MACHINE_ARCH pair, in which 7191.109Sapb case both MACHINE and MACHINE_ARCH are set from the alias. 7201.109Sapb Such aliases are interpreted entirely by build.sh; they are not 7211.109Sapb used by any other part of the build system. The MACHINE_ARCH 7221.109Sapb setting implied by mach will override any value of MACHINE_ARCH 7231.109Sapb in the process environment, but will not override a value set 7241.109Sapb by the -a option. All cross builds require -m, but if unset on 7251.109Sapb a NetBSD host, the host's value of MACHINE will be detected and 7261.109Sapb used automatically. 7271.109Sapb 7281.109Sapb See the list-arch operation for a way to get a list of valid 7291.109Sapb MACHINE and MACHINE_ARCH settings. 7301.1Stv 7311.105Swiz -N noiselevel 7321.161Srillig Set the "noisiness" level of the build, by setting MAKEVERBOSE 7331.126Swiz to noiselevel. 7341.45Slukem 7351.105Swiz -n Show the commands that would be executed by build.sh, but do 7361.126Swiz not make any changes. This is similar in concept to "make -n". 7371.1Stv 7381.105Swiz -O obj Create an appropriate transform macro for MAKEOBJDIR that will 7391.105Swiz place the built object files under obj. Unsets 7401.105Swiz MAKEOBJDIRPREFIX. 7411.88Sapb 7421.126Swiz For instance, a setting of "-O /usr/obj" will place build-time 7431.126Swiz files under /usr/obj/bin, /usr/obj/lib, /usr/obj/usr.bin, and 7441.126Swiz so forth. 7451.88Sapb 7461.88Sapb If a relative path is specified, it will be converted to an 7471.105Swiz absolute path before being used. build.sh imposes the 7481.105Swiz restriction that the argument to the -O option must not contain 7491.126Swiz a "$" (dollar sign) character. If the directory does not 7501.105Swiz already exist, build.sh will create it. 7511.73Sapb 7521.105Swiz In normal use, exactly one of the -M or -O options should be 7531.105Swiz specified. If neither -M nor -O is specified, then a default 7541.78Sapb object directory will be chosen according to rules in 7551.78Sapb <bsd.obj.mk>. Relying on this default is not recommended 7561.78Sapb because it is determined by complex rules that are influenced 7571.78Sapb by the values of several variables and by the location of the 7581.78Sapb source directory. 7591.18Slukem 7601.151Slukem Note: Placing the obj directory location outside of the default 7611.151Slukem source tree hierarchy makes it easier to manually clear out old 7621.151Slukem files in the event the "make cleandir" operation is unable to 7631.151Slukem do so. (See CAVEATS below.) 7641.151Slukem 7651.151Slukem Note: The use of one of -M or -O is the only means of building 7661.151Slukem multiple machine architecture userlands from the same source 7671.151Slukem tree without cleaning between builds (in which case, one would 7681.151Slukem specify distinct obj locations for each). 7691.109Sapb 7701.126Swiz -o Set the value of MKOBJDIRS to "no". Otherwise, it will be 7711.126Swiz automatically set to "yes". This default is opposite to the 7721.105Swiz behaviour when not using build.sh. 7731.1Stv 7741.148Slukem -P Set the value of MKREPRO and MKREPRO_TIMESTAMP to the latest 7751.148Slukem source CVS timestamp for reproducible builds. 7761.148Slukem 7771.105Swiz -R rel Set the value of RELEASEDIR to rel. If a relative path is 7781.59Sapb specified, it will be converted to an absolute path before 7791.59Sapb being used. 7801.18Slukem 7811.105Swiz -r Remove the contents of DESTDIR and TOOLDIR before building 7821.1Stv (provides a clean starting point). This will skip deleting 7831.105Swiz DESTDIR if building on a native system to the root directory. 7841.1Stv 7851.105Swiz -S seed Change the value of BUILDSEED to seed. This should rarely be 7861.72Sperry necessary. 7871.72Sperry 7881.105Swiz -T tools Set the value of TOOLDIR to tools. If a relative path is 7891.104Swiz specified, it will be converted to an absolute path before 7901.126Swiz being used. If set, the bootstrap "make" will only be rebuilt 7911.126Swiz if the source files for make(1) have changed. 7921.104Swiz 7931.105Swiz -U Set MKUNPRIVED=yes. 7941.104Swiz 7951.105Swiz -u Set MKUPDATE=yes. 7961.104Swiz 7971.105Swiz -V var=[value] 7981.105Swiz Set the environment variable var to an optional value. This is 7991.159Slukem propagated to the nbmake-MACHINE wrapper script. 8001.105Swiz 8011.105Swiz -w wrapper 8021.159Slukem Create the nbmake-MACHINE wrapper script (see below) in a 8031.159Slukem custom location, specified by wrapper. This allows, for 8041.159Slukem instance, to place the wrapper script in PATH automatically. 8051.151Slukem 8061.151Slukem Note: wrapper is the full name of the file, not just a 8071.151Slukem directory name. If a relative path is specified, it will be 8081.151Slukem converted to an absolute path before being used. 8091.1Stv 8101.105Swiz -X x11src 8111.105Swiz Set the value of X11SRCDIR to x11src. If a relative path is 8121.59Sapb specified, it will be converted to an absolute path before 8131.59Sapb being used. 8141.49Slukem 8151.105Swiz -x Set MKX11=yes. 8161.49Slukem 8171.105Swiz -Z var Unset ("zap") the environment variable var. This is propagated 8181.159Slukem to the nbmake-MACHINE wrapper script. 8191.40Slukem 8201.148Slukem -? Show a help message, and exit. 8211.148Slukem 8221.160Slukem The nbmake-MACHINE wrapper script 8231.159Slukem If using the build.sh script to build NetBSD, a nbmake-MACHINE wrapper 8241.159Slukem script will be created in TOOLDIR/bin upon the first build to assist in 8251.159Slukem building subtrees on a cross-compile host. 8261.159Slukem 8271.159Slukem The nbmake-MACHINE wrapper script can be invoked in lieu of make(1), and 8281.159Slukem will instead call the up-to-date version of "nbmake" installed into 8291.159Slukem TOOLDIR/bin with several key variables pre-set, including MACHINE, 8301.159Slukem MACHINE_ARCH, and TOOLDIR. nbmake-MACHINE will also set variables 8311.159Slukem specified with -V, and unset variables specified with -Z. Note that by 8321.160Slukem default these variables will not override mk.conf(5); see make variables 8331.160Slukem for more details. 8341.40Slukem 8351.159Slukem This wrapper script can be symlinked into a directory listed in PATH, or 8361.159Slukem called with an absolute path. 8371.1Stv 8381.105SwizEXAMPLES 8391.151Slukem 1. % ./build.sh [OPTIONS] tools kernel=GENERIC 8401.28Slukem 8411.28Slukem Build a new toolchain, and use the new toolchain to configure and 8421.28Slukem build a new GENERIC kernel. 8431.28Slukem 8441.151Slukem 2. % ./build.sh [OPTIONS] -U distribution 8451.28Slukem 8461.105Swiz Using unprivileged mode, build a complete distribution to a DESTDIR 8471.148Slukem directory that build.sh selects (and will show). 8481.28Slukem 8491.151Slukem 3. # ./build.sh [OPTIONS] -U install=/ 8501.28Slukem 8511.105Swiz As root, install to / the distribution that was built by example 2. 8521.105Swiz Even though this is run as root, -U is required so that the 8531.105Swiz permissions stored in DESTDIR/METALOG are correctly applied to the 8541.105Swiz files as they're copied to /. 8551.28Slukem 8561.151Slukem 4. % ./build.sh [OPTIONS] -U -u release 8571.28Slukem 8581.105Swiz Using unprivileged mode, build a complete release to DESTDIR and 8591.148Slukem RELEASEDIR directories that build.sh selects (and will show). 8601.126Swiz MKUPDATE=yes (-u) is set to prevent the "make cleandir", so that if 8611.126Swiz this is run after example 2, it doesn't need to redo that portion of 8621.126Swiz the release build. 8631.16Slukem 8641.105SwizSEE ALSO 8651.155Slukem config(1), ctags(1), ex(1), gzip(1), lint(1), make(1), mandoc(1), 8661.155Slukem mkisofs(1), nroff(1), vi(1), mk.conf(5), atf(7), hier(7), mdoc(7), 8671.155Slukem release(7), etcupdate(8), installboot(8), mount(8), postinstall(8), 8681.151Slukem sysinst(8), pkgsrc/sysutils/cdrtools 8691.1Stv 8701.155Slukem Note: The NetBSD manual pages are also available at 8711.155Slukem https://man.netbsd.org 8721.155Slukem 8731.105SwizHISTORY 8741.105Swiz The build.sh based build scheme was introduced for NetBSD 1.6 as 8751.105Swiz USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that. 8761.1Stv 8771.109SapbCAVEATS 8781.109Sapb After significant updates to third-party components in the source tree, 8791.126Swiz the "make cleandir" operation may be insufficient to clean out old files 8801.126Swiz in object directories. Instead, one may have to manually remove the 8811.126Swiz files. Consult the UPDATING file for notices concerning this. 8821.109Sapb 8831.159SlukemNetBSD July 21, 2023 NetBSD 884