BUILDING revision 1.5
11.1StvBUILDING(8) NetBSD System Manager's Manual BUILDING(8) 21.1Stv 31.1StvNAME 41.1Stv BUILDING - Procedure for building NetBSD from source code. 51.1Stv 61.1StvSTATUS 71.1Stv This document is a work-in-progress. As such, the information described 81.1Stv here may not match the reality of the build system as of this writing. 91.1Stv Once this document is completely in sync with reality, this paragraph 101.1Stv will be removed. 111.1Stv 121.1Stv Discrepancies between this documentation and the current reality of im- 131.1Stv plementation are noted specially, as with the note below: 141.1Stv 151.1Stv Note: This document applies only to platforms which use the new toolchain 161.5Stv as indicated by the default setting of USE_NEW_TOOLCHAIN in <bsd.own.mk>. 171.5Stv Platforms which have not yet been switched to the new toolchain should 181.5Stv continue building traditionally, using the notes specified in the file 191.5Stv UPDATING. 201.1Stv 211.1StvREQUIREMENTS 221.1Stv NetBSD is designed to be buildable on most POSIX-compliant host systems. 231.1Stv The basic build procedure is the same whether compiling natively (on the 241.1Stv same NetBSD architecture) or cross compiling (on another architecture or 251.1Stv OS). 261.1Stv 271.1Stv This source tree contains a special subtree, ``tools'', which uses the 281.1Stv host system to create a build toolchain for the target architecture. The 291.1Stv host system must have at least C and C++ compilers in order to create the 301.1Stv toolchain (make is not required); all other tools are created as part of 311.1Stv the NetBSD build process. 321.1Stv 331.1Stv Note: A couple host toolchain components are not yet available in 341.1Stv the tools directory. Also, some tools use non-POSIX, non-ANSI C 351.1Stv extensions and need to be standardized. As a result, cross-compil- 361.1Stv ing from systems other than NetBSD is not currently supported. 371.1Stv 381.1StvFILES 391.1Stv Source tree layout 401.1Stv 411.1Stv BUILDING.mdoc This document (in -mdoc troff format; the original copy). 421.1Stv 431.2Swiz BUILDING This document (in plaintext). 441.1Stv 451.1Stv Makefile The main Makefile for NetBSD; should only be run for na- 461.1Stv tive builds with an appropriately up-to-date version of 471.1Stv NetBSD make(1). (For building from out-of-date systems or 481.1Stv on a non-native host, see the build.sh shell script.) 491.1Stv 501.1Stv UPDATING Special notes for updating from an earlier revision of 511.1Stv NetBSD. It is important to read this file before every 521.1Stv build of an updated source tree. 531.1Stv 541.1Stv build.sh Bourne-compatible shell script used for building the host 551.1Stv build tools and the NetBSD system from scratch. Can be 561.1Stv used for both native and cross builds, and should be used 571.1Stv instead of make(1) for any source tree that is updated and 581.1Stv recompiled regularly. 591.1Stv 601.1Stv crypto/dist/, dist/, gnu/dist/ 611.1Stv Sources imported verbatim from third parties, without man- 621.1Stv gling the existing build structure. Other source trees in 631.1Stv bin through usr.sbin use the NetBSD make(1) ``reachover'' 641.1Stv Makefile semantics when building these programs for a na- 651.1Stv tive host. 661.1Stv 671.1Stv distrib/, etc/ 681.1Stv Sources for items used when making a full release snap- 691.1Stv shot, such as files installed in /etc on the destination 701.1Stv system, boot media, and release notes. 711.1Stv 721.1Stv regress/ Regression test harness. Can be cross-compiled, but only 731.1Stv run natively. 741.1Stv 751.1Stv sys/ NetBSD kernel sources. 761.1Stv 771.1Stv tools/ ``Reachover'' build structure for the host build tools. 781.1Stv This has a special method of determining out-of-date sta- 791.1Stv tus. 801.1Stv 811.1Stv bin/ ... usr.sbin/ 821.1Stv Sources to the NetBSD userland (non-kernel) programs. If 831.1Stv any of these directories are missing, they will be skipped 841.1Stv during the build. 851.1Stv 861.1Stv Build tree layout 871.1Stv The NetBSD build tree is described in hier(7), and the release layout is 881.1Stv described in release(7). 891.1Stv 901.1StvCONFIGURATION 911.1Stv "make" variables 921.1Stv Several variables control the behavior of NetBSD builds. Unless other- 931.1Stv wise specified, these variables may be set in either the process environ- 941.1Stv ment or the make(1) configuration file specified by MAKECONF. 951.1Stv 961.1Stv DESTDIR Directory to contain the built NetBSD system. If set, spe- 971.1Stv cial options are passed to the compilation tools to prevent 981.1Stv their default use of the host system's /usr/include, 991.1Stv /usr/lib, and so forth. This pathname should not end with a 1001.1Stv slash (/) character (for installation into the system's root 1011.1Stv directory, set DESTDIR to an empty string). 1021.1Stv 1031.1Stv Default: Empty string if USETOOLS is ``yes''; unset other- 1041.1Stv wise. 1051.1Stv 1061.1Stv MAKECONF The name of the make(1) configuration file. Only settable in 1071.1Stv the process environment. 1081.1Stv 1091.1Stv Default: ``/etc/mk.conf'' 1101.1Stv 1111.1Stv MKCATPAGES Can be set to ``yes'' or ``no''. Indicates whether prefor- 1121.1Stv matted plaintext manual pages will be created during a build. 1131.1Stv 1141.1Stv Default: ``yes'' 1151.1Stv 1161.1Stv MKCRYPTO Can be set to ``yes'' or ``no''. Indicates whether crypto- 1171.1Stv graphic code will be included in a build; provided for the 1181.1Stv benefit of countries that do not allow strong cryptography. 1191.1Stv Will not affect use of the standard low-security password en- 1201.1Stv cryption system, crypt(3). 1211.1Stv 1221.1Stv Default: ``yes'' 1231.1Stv 1241.1Stv MKDOC Can be set to ``yes'' or ``no''. Indicates whether system 1251.1Stv documentation destined for /usr/share/doc will be installed 1261.1Stv during a build. 1271.1Stv 1281.1Stv Default: ``yes'' 1291.1Stv 1301.4Stv MKHOSTOBJ Can be set to ``yes'' or ``no''. If set to ``yes'', then for 1311.4Stv programs intended to be run on the compile host, the name, 1321.4Stv release, and architecture of the host operating system will 1331.4Stv be suffixed to the name of the object directory created by 1341.4Stv ``make obj''. (This allows multiple host systems to compile 1351.4Stv NetBSD for a single target.) If set to ``no'', then programs 1361.4Stv built to be run on the compile host will use the same object 1371.4Stv directory names as programs built to be run on the target. 1381.4Stv 1391.4Stv Default: ``no'' 1401.4Stv 1411.1Stv MKINFO Can be set to ``yes'' or ``no''. Indicates whether GNU Info 1421.1Stv files, used for the documentation for most of the compilation 1431.1Stv tools, will be created and installed during a build. 1441.1Stv 1451.1Stv Default: ``yes'' 1461.1Stv 1471.1Stv MKLINT Can be set to ``yes'' or ``no''. Indicates whether lint(1) 1481.1Stv will be run against portions of the NetBSD source code during 1491.1Stv the build, and whether lint libraries will be installed into 1501.1Stv /usr/libdata/lint. 1511.1Stv 1521.1Stv Default: ``yes'' 1531.1Stv 1541.1Stv MKMAN Can be set to ``yes'' or ``no''. Indicates whether manual 1551.1Stv pages will be installed during a build. 1561.1Stv 1571.1Stv Default: ``yes'' 1581.1Stv 1591.1Stv MKNLS Can be set to ``yes'' or ``no''. Indicates whether Native 1601.1Stv Language System locale zone files will be compiled and in- 1611.1Stv stalled during a build. 1621.1Stv 1631.1Stv Default: ``yes'' 1641.1Stv 1651.1Stv MKOBJ Can be set to ``yes'' or ``no''. Indicates whether object 1661.1Stv directories will be created when running ``make obj''. If 1671.1Stv set to ``no'', then all built files will be located inside 1681.1Stv the regular source tree. 1691.1Stv 1701.1Stv Default: ``yes'' 1711.1Stv 1721.1Stv MKPIC Can be set to ``yes'' or ``no''. Indicates whether shared 1731.1Stv objects and libraries will be created and installed during a 1741.1Stv build. If set to ``no'', the entire built system will be 1751.1Stv statically linked. 1761.1Stv 1771.1Stv Default: Platform dependent. As of this writing, all plat- 1781.1Stv forms except sh3 default to ``yes''. 1791.1Stv 1801.1Stv MKPICINSTALL 1811.1Stv Can be set to ``yes'' or ``no''. Indicates whether the ar(1) 1821.1Stv format libraries (lib*_pic.a), used to generate shared li- 1831.1Stv braries, are installed during a build. 1841.1Stv 1851.1Stv Default: ``yes'' 1861.1Stv 1871.1Stv MKPROFILE Can be set to ``yes'' or ``no''. Indicates whether profiled 1881.1Stv libraries (lib*_p.a) will be built and installed during a 1891.1Stv build. 1901.1Stv 1911.1Stv Default: ``yes''; however, some platforms turn off MKPROFILE 1921.1Stv by default at times due to toolchain problems with profiled 1931.1Stv code. 1941.1Stv 1951.1Stv MKSHARE Can be set to ``yes'' or ``no''. Indicates whether files 1961.1Stv destined to reside in /usr/share will be built and installed 1971.1Stv during a build. If set to ``no'', then all of MKCATPAGES, 1981.1Stv MKDOC, MKINFO, MKMAN, and MKNLS will be set to ``no'' uncon- 1991.1Stv ditionally. 2001.1Stv 2011.1Stv Default: ``yes'' 2021.1Stv 2031.1Stv TOOLDIR Directory to hold the host tools, once built. This directory 2041.1Stv should be unique to a given host system and NetBSD source 2051.1Stv tree. (However, multiple targets may share the same TOOLDIR; 2061.1Stv the target-dependent files have unique names.) If unset, a 2071.1Stv default based on the uname(1) information of the host plat- 2081.1Stv form will be created in the .OBJDIR of src/tools. 2091.1Stv 2101.1Stv Default: Unset. 2111.1Stv 2121.1Stv UPDATE If set, then all install operations intended to write to 2131.1Stv DESTDIR will compare file timestamps before installing, and 2141.1Stv skip the install phase if the destination files are up-to- 2151.1Stv date. This also has implications on full builds (see next 2161.1Stv subsection). 2171.1Stv 2181.1Stv Default: Unset. 2191.1Stv 2201.1Stv USETOOLS Indicates whether the tools specified by TOOLDIR should be 2211.1Stv used as part of a build in progress. Must be set to ``yes'' 2221.1Stv if cross-compiling. 2231.1Stv 2241.1Stv yes Use the tools from TOOLDIR. 2251.1Stv 2261.1Stv no Do not use the tools from TOOLDIR, but refuse to build 2271.1Stv native compilation tool components that are version- 2281.1Stv specific for that tool. 2291.1Stv 2301.1Stv never Do not use the tools from TOOLDIR, even when building 2311.1Stv native tool components. This is similar to the tradi- 2321.1Stv tional NetBSD build method, but does not verify that 2331.1Stv the compilation tools in use are up-to-date enough in 2341.1Stv order to build the tree successfully. This may cause 2351.1Stv build or runtime problems when building the whole 2361.1Stv NetBSD source tree. 2371.1Stv 2381.1Stv Default: ``yes'' if building all or part of a whole NetBSD 2391.1Stv source tree (detected automatically); ``no'' otherwise (to 2401.1Stv preserve traditional semantics of the <bsd.*.mk> make(1) in- 2411.1Stv clude files). 2421.1Stv 2431.1Stv "make" variables for full builds 2441.1Stv These variables only affect the top level ``Makefile'' and do not manual- 2451.1Stv ly building subtrees of the NetBSD source code. 2461.1Stv 2471.1Stv MKOBJDIRS Can be set to ``yes'' or ``no''. Indicates whether object 2481.1Stv directories will be created automatically (via a ``make 2491.1Stv obj'' pass) at the start of a build. 2501.1Stv 2511.1Stv Default: ``yes'' 2521.1Stv 2531.1Stv NBUILDJOBS If set, specifies the number of parallel make(1) processes 2541.1Stv that should be run simultaneously. This can speed up 2551.1Stv builds on SMP machines, or machines with much more CPU 2561.1Stv power than I/O availability. This should be used instead 2571.1Stv of the make(1) option -j, in order to ensure proper order- 2581.1Stv ing of build components. 2591.1Stv 2601.1Stv Default: Unset. 2611.1Stv 2621.1Stv NOCLEANDIR If set, avoids the ``make cleandir'' phase of a full 2631.1Stv build. This has the effect of allowing only changed files 2641.1Stv in a source tree to be recompiled. This can speed up 2651.1Stv builds when updating only a few files in the tree. 2661.1Stv 2671.1Stv Default: Unset. 2681.1Stv 2691.1Stv NODISTRIBDIRS If set, avoids the ``make distrib-dirs'' phase of a full 2701.1Stv build. This skips running mtree(8) on DESTDIR, useful on 2711.1Stv systems where building as an unprivileged user, or where 2721.1Stv it is known that the system-wide mtree files have not 2731.1Stv changed. 2741.1Stv 2751.1Stv Default: Unset. 2761.1Stv 2771.1Stv NOINCLUDES If set, avoids the ``make includes'' phase of a full 2781.1Stv build. This has the effect of preventing make(1) from 2791.1Stv thinking that some programs are out-of-date simply because 2801.1Stv the system include files have changed. However, this op- 2811.1Stv tion should not be used when updating the entire NetBSD 2821.1Stv source tree arbitrarily; it is suggested to use UPDATE in 2831.1Stv that case. 2841.1Stv 2851.1Stv Default: Unset. 2861.1Stv 2871.1Stv RELEASEDIR If set, specifies the directory to which a release(7) lay- 2881.1Stv out will be written at the end of a ``make release''. 2891.1Stv 2901.1Stv Default: Unset. 2911.1Stv 2921.1Stv UPDATE If set, then in addition to the effects described for UP- 2931.1Stv DATE above, this implies the effects of NOCLEANDIR. 2941.1Stv 2951.1StvBUILDING 2961.1Stv "make" command line options 2971.1Stv This is only a summary of options available to make(1); only the options 2981.1Stv used most frequently with NetBSD builds are listed here. 2991.1Stv 3001.1Stv -m dir Specify the default directory for searching for system Make- 3011.1Stv file segments, mainly the <bsd.*.mk> files. When building any 3021.1Stv full NetBSD source tree, this should be set to the 3031.1Stv ``share/mk'' directory in the source tree. (This is set auto- 3041.1Stv matically when building from the top level.) 3051.1Stv 3061.1Stv -n Display the commands that would have been executed, but do not 3071.1Stv actually execute them. This will still cause recursion to 3081.1Stv take place. 3091.1Stv 3101.1Stv -v var Print make(1)'s idea of the value of var. Does not build any 3111.1Stv targets. 3121.1Stv 3131.1Stv var=value Set the variable var to value, overriding any setting speci- 3141.1Stv fied by the process environment, the MAKECONF configuration 3151.1Stv file, or the system Makefile segments. 3161.1Stv 3171.1Stv "make" targets 3181.1Stv These default targets may be built by running make(1) in any subtree of 3191.1Stv the NetBSD source code. It is recommended that none of these be used 3201.1Stv from the top level Makefile; as a specific exception, ``make obj'' and 3211.1Stv ``make cleandir'' are useful in that context. 3221.1Stv 3231.1Stv all Build programs, libraries, and preformatted documentation. 3241.1Stv 3251.1Stv clean Remove program and library object code files. 3261.1Stv 3271.1Stv cleandir Same as clean, but also remove preformatted documentation, de- 3281.1Stv pendency files generated by ``make depend'', and any other 3291.1Stv files known to be created at build time. ``make distclean'' 3301.1Stv may be used as a synonym, for familiarity with a similar well- 3311.1Stv known convention. 3321.1Stv 3331.1Stv depend Create dependency files (.depend) containing more detailed in- 3341.1Stv formation about the dependencies of source code on header 3351.1Stv files. Allows programs to be recompiled automatically when a 3361.1Stv dependency changes. 3371.1Stv 3381.1Stv dependall Does a ``make depend'' immediately followed by a ``make all''. 3391.1Stv This combined target recurses as an atomic unit, so that the 3401.1Stv ``make depend'' phase can participate in make -j parallelism. 3411.1Stv 3421.1Stv includes Build and install system header files. Typically needed be- 3431.1Stv fore any system libraries or programs can be built. 3441.1Stv 3451.1Stv install Install programs, libraries, and documentation into DESTDIR. 3461.1Stv 3471.1Stv lint Run lint(1) against the C source code, where appropriate, and 3481.1Stv generate system-installed lint libraries. 3491.1Stv 3501.1Stv obj Create object directories to be used for built files, instead 3511.1Stv of building directly in the source tree. 3521.1Stv 3531.1Stv tags Create ctags(1) searchable function lists usable by the ex(1) 3541.1Stv and vi(1) text editors. 3551.1Stv 3561.1Stv "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.1Stv build Build the entire NetBSD system. This orders portions of the 3611.1Stv source tree such that prerequisites will be built in the prop- 3621.1Stv er order. 3631.1Stv 3641.1Stv release Do a ``make build'', then package the system into a standard 3651.1Stv release layout as described by release(7). This requires that 3661.1Stv RELEASEDIR be set (see above). 3671.1Stv 3681.1Stv regression-tests 3691.1Stv Can only be run after building the regression tests in the di- 3701.1Stv rectory ``regress''. Runs the compiled regression tests on 3711.1Stv the local host. 3721.1Stv 3731.1Stv The "build.sh" script 3741.1Stv This script file is a Bourne shell script designed to build the entire 3751.1Stv NetBSD system on any host with a Bourne shell in /bin/sh, including many 3761.1Stv that are not POSIX compliant. Note that if a host system's /bin/sh is 3771.1Stv unusually old and broken, the Korn Shell (/bin/ksh), if available, may be 3781.1Stv a usable alternative. 3791.1Stv 3801.1Stv All cross-compile builds, and most native builds, of the entire system 3811.1Stv should make use of build.sh rather than just running ``make''. This way, 3821.1Stv the make(1) program will be bootstrapped properly, in case the host sys- 3831.1Stv tem has an older or incompatible ``make'' program. 3841.1Stv 3851.1Stv When compiling the entire system via build.sh, many make(1) variables are 3861.1Stv set for you in order to help encapsulate the build process. In the list 3871.1Stv of options below, variables that are automatically set by build.sh are 3881.1Stv noted where applicable. 3891.1Stv 3901.1Stv The following are available command line options that may be supplied to 3911.1Stv build.sh: 3921.1Stv 3931.1Stv -a arch Set the value of MACHINE_ARCH to arch. 3941.1Stv 3951.1Stv -b Bootstrap ``make'' and create a nbmake-MACHINE script (see be- 3961.1Stv low). 3971.1Stv 3981.1Stv -j njob Set the value of NBUILDJOBS to njob. This provides similar 3991.1Stv functionality to the familiar ``make -j'', but preserves the 4001.1Stv ordering of the top level ``make build''. 4011.1Stv 4021.1Stv -m mach Set the value of MACHINE to mach. This will also override any 4031.1Stv value of MACHINE_ARCH in the process environment with a value 4041.1Stv deduced from mach, unless -a is specified. All cross builds 4051.1Stv require -m, but if unset on a NetBSD host, the host's value of 4061.1Stv MACHINE will be detected and used automatically. 4071.1Stv 4081.1Stv -n Show the commands that would be executed by build.sh, but do 4091.1Stv not make any changes. This is similar in concept to ``make 4101.1Stv -n''. 4111.1Stv 4121.1Stv -o Set the value of MKOBJDIRS to ``no''. 4131.1Stv 4141.1Stv -r Remove the contents of DESTDIR and TOOLDIR before building 4151.1Stv (provides a clean starting point). This will skip deleting 4161.1Stv DESTDIR if building on a native system to the root directory. 4171.1Stv 4181.1Stv -t Build and install the host tools from src/tools only. This op- 4191.1Stv tion implies -b. 4201.1Stv 4211.1Stv -u Set the UPDATE variable. 4221.1Stv 4231.1Stv -w wrapper 4241.1Stv Create the nbmake wrapper script (see below) in a custom loca- 4251.1Stv tion, specified by wrapper. This allows, for instance, to 4261.1Stv place the wrapper in PATH automatically. Note that wrapper is 4271.1Stv the full name of the file, not just a directory name. 4281.1Stv 4291.1Stv -D dest Set the value of DESTDIR to dest. 4301.1Stv 4311.1Stv -O obj Create an appropriate transform macro for MAKEOBJDIR that will 4321.1Stv place the built object files under obj. For instance, a set- 4331.1Stv ting of /usr/obj will place build-time files files under 4341.1Stv /usr/obj/bin, /usr/obj/lib, and so forth. 4351.1Stv 4361.1Stv -R rel Set the value of RELEASEDIR to rel. Setting this option will 4371.1Stv cause build.sh to run ``make release'' instead of ``make 4381.1Stv build''. 4391.1Stv 4401.1Stv -T tools Set the value of TOOLDIR to tools. If set, the bootstrap 4411.1Stv ``make'' will only be rebuilt as needed (when the source files 4421.1Stv for make(1) change). 4431.1Stv 4441.1Stv The "nbmake-MACHINE" wrapper script 4451.1Stv If using the build.sh script to build NetBSD, a nbmake-MACHINE script 4461.1Stv will be created in TOOLDIR/bin upon the first build to assist in building 4471.1Stv subtrees on a cross-compile host. 4481.1Stv 4491.1Stv nbmake-MACHINE can be invoked in lieu of make(1), and will instead call 4501.1Stv the up-to-date version of ``nbmake'' installed into TOOLDIR/bin with sev- 4511.1Stv eral key variables pre-set, including MACHINE, MACHINE_ARCH, and TOOLDIR. 4521.1Stv This script can be symlinked into a directory listed in PATH, or called 4531.1Stv with an absolute path. 4541.1Stv 4551.1StvSEE ALSO 4561.1Stv make(1), hier(7), release(7) 4571.1Stv 4581.1StvHISTORY 4591.1Stv The USE_NEW_TOOLCHAIN based build scheme was introduced in the ``NetBSD- 4601.1Stv current'' development sources between NetBSD 1.5 and NetBSD 1.6. 4611.1Stv 4621.1StvBUGS 4631.1Stv Many platforms are not yet using the USE_NEW_TOOLCHAIN system. 4641.1Stv 4651.4StvNetBSD November 12, 2001 8 466