BUILDING revision 1.71
11.1StvBUILDING(8)             NetBSD System Manager's Manual             BUILDING(8)
21.1Stv
31.1StvNAME
41.52Sjmc     BUILDING -- Procedure for building NetBSD from source code.
51.1Stv
61.1StvREQUIREMENTS
71.1Stv     NetBSD is designed to be buildable on most POSIX-compliant host systems.
81.1Stv     The basic build procedure is the same whether compiling natively (on the
91.1Stv     same NetBSD architecture) or cross compiling (on another architecture or
101.1Stv     OS).
111.1Stv
121.1Stv     This source tree contains a special subtree, ``tools'', which uses the
131.1Stv     host system to create a build toolchain for the target architecture.  The
141.1Stv     host system must have at least C and C++ compilers in order to create the
151.1Stv     toolchain (make is not required); all other tools are created as part of
161.53Sreed     the NetBSD build process.  (See the environment variables section below
171.53Sreed     if you need to override or manually select your compilers.)
181.1Stv
191.1StvFILES
201.1Stv   Source tree layout
211.17Swiz     doc/BUILDING.mdoc
221.17Swiz                    This document (in -mdoc troff format; the original copy).
231.1Stv
241.2Swiz     BUILDING       This document (in plaintext).
251.1Stv
261.48Sjmc     tools/compat/README
271.48Sjmc                    Special notes for cross-hosting a NetBSD build on non-
281.48Sjmc                    NetBSD platforms.
291.48Sjmc
301.44Slukem     Makefile       The main Makefile for NetBSD; should only be run for
311.44Slukem                    native builds with an appropriately up-to-date version of
321.1Stv                    NetBSD make(1).  (For building from out-of-date systems or
331.1Stv                    on a non-native host, see the build.sh shell script.)
341.1Stv
351.1Stv     UPDATING       Special notes for updating from an earlier revision of
361.1Stv                    NetBSD.  It is important to read this file before every
371.1Stv                    build of an updated source tree.
381.1Stv
391.1Stv     build.sh       Bourne-compatible shell script used for building the host
401.1Stv                    build tools and the NetBSD system from scratch.  Can be
411.1Stv                    used for both native and cross builds, and should be used
421.1Stv                    instead of make(1) for any source tree that is updated and
431.1Stv                    recompiled regularly.
441.1Stv
451.1Stv     crypto/dist/, dist/, gnu/dist/
461.1Stv                    Sources imported verbatim from third parties, without man-
471.1Stv                    gling the existing build structure.  Other source trees in
481.1Stv                    bin through usr.sbin use the NetBSD make(1) ``reachover''
491.44Slukem                    Makefile semantics when building these programs for a
501.44Slukem                    native host.
511.1Stv
521.1Stv     distrib/, etc/
531.1Stv                    Sources for items used when making a full release snap-
541.27Slukem                    shot, such as files installed in DESTDIR/etc on the desti-
551.27Slukem                    nation system, boot media, and release notes.
561.1Stv
571.70Sdholland     tests/, regress/
581.70Sdholland                    Regression test harness.  Can be cross-compiled, but only
591.70Sdholland                    run natively.  tests/ uses the atf(7) test framework;
601.70Sdholland                    regress/ contains older tests that have not yet been
611.70Sdholland                    migrated to atf(7).
621.1Stv
631.1Stv     sys/           NetBSD kernel sources.
641.1Stv
651.1Stv     tools/         ``Reachover'' build structure for the host build tools.
661.1Stv                    This has a special method of determining out-of-date sta-
671.1Stv                    tus.
681.1Stv
691.1Stv     bin/ ... usr.sbin/
701.1Stv                    Sources to the NetBSD userland (non-kernel) programs.  If
711.1Stv                    any of these directories are missing, they will be skipped
721.1Stv                    during the build.
731.1Stv
741.49Slukem     x11/           ``Reachover'' build structure for X11R6; the source is in
751.49Slukem                    X11SRCDIR.
761.49Slukem
771.1Stv   Build tree layout
781.1Stv     The NetBSD build tree is described in hier(7), and the release layout is
791.1Stv     described in release(7).
801.1Stv
811.1StvCONFIGURATION
821.8Slukem   Environment variables
831.8Slukem     Several environment variables control the behaviour of NetBSD builds.
841.8Slukem
851.58Sapb     HOST_SH           Path name to a POSIX-compliant shell.  If this is not
861.58Sapb                       set explicitly, then the default is set using heuris-
871.58Sapb                       tics dependent on the host platform, or from the shell
881.58Sapb                       under which build.sh is executed (if that can be deter-
891.58Sapb                       mined), or using the first copy of sh found in PATH.
901.58Sapb                       If the host system's /bin/sh is not POSIX-compliant, we
911.58Sapb                       suggest that you build using commands like
921.58Sapb
931.58Sapb                             HOST_SH=/path/to/working/shell
941.58Sapb                             export HOST_SH
951.58Sapb                             ${HOST_SH} build.sh [options]
961.58Sapb
971.53Sreed     HOST_CC           Path name to C compiler used to create the toolchain.
981.53Sreed
991.53Sreed     HOST_CXX          Path name to C++ compiler used to create the toolchain.
1001.53Sreed
1011.70Sdholland     MACHINE           Machine type, e.g., ``macppc''.
1021.8Slukem
1031.70Sdholland     MACHINE_ARCH      Machine architecture, e.g., ``powerpc''.
1041.8Slukem
1051.8Slukem     MAKE              Path name to invoke make(1) as.
1061.8Slukem
1071.8Slukem     MAKEFLAGS         Flags to invoke make(1) with.
1081.8Slukem
1091.8Slukem     MAKEOBJDIR        Directory to use as the .OBJDIR for the current direc-
1101.59Sapb                       tory.  The value is subjected to variable expansion by
1111.59Sapb                       make(1).  Used only if MAKEOBJDIRPREFIX is not defined.
1121.36Slukem                       MAKEOBJDIR can only be provided in the environment or
1131.41Slukem                       via the -O flag of build.sh.
1141.8Slukem
1151.8Slukem     MAKEOBJDIRPREFIX  Top level directory of the object directory tree.  If
1161.59Sapb                       specified, must be an absolute path.  If this is
1171.59Sapb                       defined, ${MAKEOBJDIRPREFIX}/${.CURDIR} is used as the
1181.59Sapb                       .OBJDIR for the current directory.  The current direc-
1191.59Sapb                       tory may be read only.  MAKEOBJDIRPREFIX can only be
1201.59Sapb                       provided in the environment or via the -M flag of
1211.36Slukem                       build.sh.
1221.8Slukem
1231.1Stv   "make" variables
1241.1Stv     Several variables control the behavior of NetBSD builds.  Unless other-
1251.1Stv     wise specified, these variables may be set in either the process environ-
1261.1Stv     ment or the make(1) configuration file specified by MAKECONF.
1271.1Stv
1281.9Sthorpej     BUILDID     Identifier for the build.  The identifier will be appended to
1291.9Sthorpej                 object directory names, and can be consulted in the make(1)
1301.9Sthorpej                 configuration file in order to set additional build parame-
1311.9Sthorpej                 ters, such as compiler flags.
1321.9Sthorpej
1331.1Stv     DESTDIR     Directory to contain the built NetBSD system.  If set, spe-
1341.1Stv                 cial options are passed to the compilation tools to prevent
1351.1Stv                 their default use of the host system's /usr/include,
1361.59Sapb                 /usr/lib, and so forth.  This pathname must be an absolute
1371.59Sapb                 path, and should not end with a slash (/) character.  (For
1381.59Sapb                 installation into the system's root directory, set DESTDIR to
1391.59Sapb                 an empty string, not to ``/'').  The directory must reside on
1401.59Sapb                 a file system which supports long file names and hard links.
1411.1Stv
1421.1Stv                 Default: Empty string if USETOOLS is ``yes''; unset other-
1431.1Stv                 wise.
1441.1Stv
1451.30Slukem                 Note: build.sh will provide a default of destdir.MACHINE (in
1461.70Sdholland                 the top-level .OBJDIR) unless run in `expert' mode.
1471.30Slukem
1481.1Stv     MAKECONF    The name of the make(1) configuration file.  Only settable in
1491.1Stv                 the process environment.
1501.1Stv
1511.1Stv                 Default: ``/etc/mk.conf''
1521.1Stv
1531.45Slukem     MAKEVERBOSE
1541.45Slukem                 Level of verbosity of status messages.  Supported values:
1551.45Slukem
1561.45Slukem                 0    No descriptive messages are shown.
1571.45Slukem
1581.45Slukem                 1    Descriptive messages are shown.
1591.45Slukem
1601.45Slukem                 2    Descriptive messages (prefixed with a `#') and command
1611.45Slukem                      output is not suppressed.
1621.45Slukem
1631.45Slukem                 Default: 2
1641.45Slukem
1651.1Stv     MKCATPAGES  Can be set to ``yes'' or ``no''.  Indicates whether prefor-
1661.1Stv                 matted plaintext manual pages will be created during a build.
1671.1Stv
1681.1Stv                 Default: ``yes''
1691.1Stv
1701.1Stv     MKCRYPTO    Can be set to ``yes'' or ``no''.  Indicates whether crypto-
1711.1Stv                 graphic code will be included in a build; provided for the
1721.1Stv                 benefit of countries that do not allow strong cryptography.
1731.44Slukem                 Will not affect use of the standard low-security password
1741.44Slukem                 encryption system, crypt(3).
1751.1Stv
1761.1Stv                 Default: ``yes''
1771.1Stv
1781.1Stv     MKDOC       Can be set to ``yes'' or ``no''.  Indicates whether system
1791.44Slukem                 documentation destined for DESTDIR/usr/share/doc will be
1801.44Slukem                 installed during a build.
1811.1Stv
1821.1Stv                 Default: ``yes''
1831.1Stv
1841.4Stv     MKHOSTOBJ   Can be set to ``yes'' or ``no''.  If set to ``yes'', then for
1851.4Stv                 programs intended to be run on the compile host, the name,
1861.4Stv                 release, and architecture of the host operating system will
1871.4Stv                 be suffixed to the name of the object directory created by
1881.4Stv                 ``make obj''.  (This allows multiple host systems to compile
1891.4Stv                 NetBSD for a single target.)  If set to ``no'', then programs
1901.4Stv                 built to be run on the compile host will use the same object
1911.4Stv                 directory names as programs built to be run on the target.
1921.4Stv
1931.4Stv                 Default: ``no''
1941.4Stv
1951.1Stv     MKINFO      Can be set to ``yes'' or ``no''.  Indicates whether GNU Info
1961.1Stv                 files, used for the documentation for most of the compilation
1971.1Stv                 tools, will be created and installed during a build.
1981.1Stv
1991.1Stv                 Default: ``yes''
2001.1Stv
2011.1Stv     MKLINT      Can be set to ``yes'' or ``no''.  Indicates whether lint(1)
2021.1Stv                 will be run against portions of the NetBSD source code during
2031.1Stv                 the build, and whether lint libraries will be installed into
2041.27Slukem                 DESTDIR/usr/libdata/lint.
2051.1Stv
2061.1Stv                 Default: ``yes''
2071.1Stv
2081.1Stv     MKMAN       Can be set to ``yes'' or ``no''.  Indicates whether manual
2091.1Stv                 pages will be installed during a build.
2101.1Stv
2111.1Stv                 Default: ``yes''
2121.1Stv
2131.1Stv     MKNLS       Can be set to ``yes'' or ``no''.  Indicates whether Native
2141.44Slukem                 Language System locale zone files will be compiled and
2151.44Slukem                 installed during a build.
2161.1Stv
2171.1Stv                 Default: ``yes''
2181.1Stv
2191.1Stv     MKOBJ       Can be set to ``yes'' or ``no''.  Indicates whether object
2201.1Stv                 directories will be created when running ``make obj''.  If
2211.1Stv                 set to ``no'', then all built files will be located inside
2221.1Stv                 the regular source tree.
2231.1Stv
2241.1Stv                 Default: ``yes''
2251.1Stv
2261.70Sdholland                 Note that setting MKOBJ to ``no'' is not recommended and may
2271.70Sdholland                 cause problems when updating the tree with cvs(1).
2281.70Sdholland
2291.1Stv     MKPIC       Can be set to ``yes'' or ``no''.  Indicates whether shared
2301.1Stv                 objects and libraries will be created and installed during a
2311.1Stv                 build.  If set to ``no'', the entire built system will be
2321.1Stv                 statically linked.
2331.1Stv
2341.1Stv                 Default: Platform dependent.  As of this writing, all plat-
2351.1Stv                 forms except sh3 default to ``yes''.
2361.1Stv
2371.1Stv     MKPICINSTALL
2381.1Stv                 Can be set to ``yes'' or ``no''.  Indicates whether the ar(1)
2391.44Slukem                 format libraries (lib*_pic.a), used to generate shared
2401.44Slukem                 libraries, are installed during a build.
2411.1Stv
2421.1Stv                 Default: ``yes''
2431.1Stv
2441.1Stv     MKPROFILE   Can be set to ``yes'' or ``no''.  Indicates whether profiled
2451.1Stv                 libraries (lib*_p.a) will be built and installed during a
2461.1Stv                 build.
2471.1Stv
2481.1Stv                 Default: ``yes''; however, some platforms turn off MKPROFILE
2491.1Stv                 by default at times due to toolchain problems with profiled
2501.1Stv                 code.
2511.1Stv
2521.1Stv     MKSHARE     Can be set to ``yes'' or ``no''.  Indicates whether files
2531.44Slukem                 destined to reside in DESTDIR/usr/share will be built and
2541.44Slukem                 installed during a build.  If set to ``no'', then all of
2551.27Slukem                 MKCATPAGES, MKDOC, MKINFO, MKMAN, and MKNLS will be set to
2561.27Slukem                 ``no'' unconditionally.
2571.1Stv
2581.1Stv                 Default: ``yes''
2591.1Stv
2601.50Swiz     MKTTINTERP  Can be set to ``yes'' or ``no''.  For X builds, decides if
2611.50Swiz                 the TrueType bytecode interpreter is turned on.  See
2621.50Swiz                 http://www.freetype.org/patents.html for details.
2631.50Swiz
2641.50Swiz                 Default: ``no''
2651.50Swiz
2661.44Slukem     MKUNPRIVED  Can be set to ``yes'' or ``no''.  Indicates whether an
2671.44Slukem                 unprivileged install will occur.  The user, group, permis-
2681.52Sjmc                 sions, and file flags, will not be set on the installed
2691.52Sjmc                 items; instead the information will be appended to a file
2701.52Sjmc                 called METALOG in DESTDIR.  The contents of METALOG are used
2711.52Sjmc                 during the generation of the distribution tar files to ensure
2721.52Sjmc                 that the appropriate file ownership is stored.
2731.38Slukem
2741.38Slukem                 Default: ``no''
2751.38Slukem
2761.44Slukem     MKUPDATE    Can be set to ``yes'' or ``no''.  Indicates whether all
2771.44Slukem                 install operations intended to write to DESTDIR will compare
2781.38Slukem                 file timestamps before installing, and skip the install phase
2791.44Slukem                 if the destination files are up-to-date.  This also has
2801.44Slukem                 implications on full builds (see next subsection).
2811.38Slukem
2821.38Slukem                 Default: ``no''
2831.38Slukem
2841.49Slukem     MKX11       Can be set to ``yes'' or ``no''.  Indicates whether X11R6 is
2851.49Slukem                 built from X11SRCDIR.
2861.49Slukem
2871.49Slukem                 Default: ``no''
2881.49Slukem
2891.59Sapb     TOOLDIR     Directory to hold the host tools, once built.  If specified,
2901.59Sapb                 must be an absolute path.  This directory should be unique to
2911.59Sapb                 a given host system and NetBSD source tree.  (However, multi-
2921.59Sapb                 ple targets may share the same TOOLDIR; the target-dependent
2931.59Sapb                 files have unique names.)  If unset, a default based on the
2941.59Sapb                 uname(1) information of the host platform will be created in
2951.59Sapb                 the .OBJDIR of src.
2961.1Stv
2971.1Stv                 Default: Unset.
2981.1Stv
2991.1Stv     USETOOLS    Indicates whether the tools specified by TOOLDIR should be
3001.1Stv                 used as part of a build in progress.  Must be set to ``yes''
3011.1Stv                 if cross-compiling.
3021.1Stv
3031.1Stv                 yes    Use the tools from TOOLDIR.
3041.1Stv
3051.1Stv                 no     Do not use the tools from TOOLDIR, but refuse to build
3061.1Stv                        native compilation tool components that are version-
3071.1Stv                        specific for that tool.
3081.1Stv
3091.1Stv                 never  Do not use the tools from TOOLDIR, even when building
3101.1Stv                        native tool components.  This is similar to the tradi-
3111.1Stv                        tional NetBSD build method, but does not verify that
3121.1Stv                        the compilation tools in use are up-to-date enough in
3131.1Stv                        order to build the tree successfully.  This may cause
3141.1Stv                        build or runtime problems when building the whole
3151.1Stv                        NetBSD source tree.
3161.1Stv
3171.71Sdholland                 Default: ``yes'', unless TOOLCHAIN_MISSING is set to ``yes''.
3181.71Sdholland
3191.71Sdholland                 USETOOLS is also set to ``no'' when using <bsd.*.mk> outside
3201.71Sdholland                 the NetBSD source tree.
3211.1Stv
3221.59Sapb     X11SRCDIR   Directory containing the X11R6 source.  If specified, must be
3231.59Sapb                 an absolute path.  The main X11R6 source is found in
3241.59Sapb                 X11SRCDIR/xfree/xc.
3251.49Slukem
3261.49Slukem                 Default: ``/usr/xsrc''
3271.49Slukem
3281.1Stv   "make" variables for full builds
3291.7Slukem     These variables only affect the top level ``Makefile'' and do not affect
3301.7Slukem     manually building subtrees of the NetBSD source code.
3311.1Stv
3321.20Slukem     INSTALLWORLDDIR  Location for the ``make installworld'' target to install
3331.59Sapb                      to.  If specified, must be an absolute path.
3341.1Stv
3351.20Slukem                      Default: ``/''
3361.1Stv
3371.44Slukem     MKOBJDIRS        Can be set to ``yes'' or ``no''.  Indicates whether
3381.44Slukem                      object directories will be created automatically (via a
3391.20Slukem                      ``make obj'' pass) at the start of a build.
3401.1Stv
3411.34Slukem                      Default: ``no''
3421.1Stv
3431.70Sdholland                      If using build.sh, the default is ``yes''.  This may be
3441.70Sdholland                      set back to ``no'' by giving build.sh the -o option.
3451.70Sdholland
3461.38Slukem     MKUPDATE         Can be set to ``yes'' or ``no''.  If set, then in addi-
3471.38Slukem                      tion to the effects described for MKUPDATE=yes above,
3481.38Slukem                      this implies the effects of NOCLEANDIR (i.e., ``make
3491.38Slukem                      cleandir'' is avoided).
3501.38Slukem
3511.38Slukem                      Default: ``no''
3521.38Slukem
3531.70Sdholland                      If using build.sh, this may be set by giving the -u
3541.70Sdholland                      option.
3551.70Sdholland
3561.70Sdholland     NBUILDJOBS       Now obsolete.  Use the make(1) option -j, instead.  See
3571.70Sdholland                      below.
3581.1Stv
3591.20Slukem                      Default: Unset.
3601.1Stv
3611.20Slukem     NOCLEANDIR       If set, avoids the ``make cleandir'' phase of a full
3621.20Slukem                      build.  This has the effect of allowing only changed
3631.20Slukem                      files in a source tree to be recompiled.  This can speed
3641.20Slukem                      up builds when updating only a few files in the tree.
3651.1Stv
3661.20Slukem                      Default: Unset.
3671.1Stv
3681.70Sdholland                      See also MKUPDATE.
3691.70Sdholland
3701.20Slukem     NODISTRIBDIRS    If set, avoids the ``make distrib-dirs'' phase of a full
3711.20Slukem                      build.  This skips running mtree(8) on DESTDIR, useful
3721.20Slukem                      on systems where building as an unprivileged user, or
3731.20Slukem                      where it is known that the system-wide mtree files have
3741.20Slukem                      not changed.
3751.1Stv
3761.20Slukem                      Default: Unset.
3771.1Stv
3781.20Slukem     NOINCLUDES       If set, avoids the ``make includes'' phase of a full
3791.20Slukem                      build.  This has the effect of preventing make(1) from
3801.44Slukem                      thinking that some programs are out-of-date simply
3811.44Slukem                      because the system include files have changed.  However,
3821.20Slukem                      this option should not be used when updating the entire
3831.20Slukem                      NetBSD source tree arbitrarily; it is suggested to use
3841.70Sdholland                      MKUPDATE=yes instead in that case.
3851.1Stv
3861.20Slukem                      Default: Unset.
3871.1Stv
3881.20Slukem     RELEASEDIR       If set, specifies the directory to which a release(7)
3891.20Slukem                      layout will be written at the end of a ``make release''.
3901.59Sapb                      If specified, must be an absolute path.
3911.20Slukem
3921.20Slukem                      Default: Unset.
3931.20Slukem
3941.30Slukem                      Note: build.sh will provide a default of releasedir (in
3951.70Sdholland                      the top-level .OBJDIR) unless run in `expert' mode.
3961.30Slukem
3971.1StvBUILDING
3981.1Stv   "make" command line options
3991.52Sjmc     This is not a summary of all the options available to make(1); only the
4001.52Sjmc     options used most frequently with NetBSD builds are listed here.
4011.1Stv
4021.10Ssommerfe     -j njob    Run up to njob make(1) subjobs in parallel.  Makefiles should
4031.52Sjmc                use .WAIT or have explicit dependencies as necessary to
4041.44Slukem                enforce build ordering.  If you see build failures with -j,
4051.10Ssommerfe                please save complete build logs so the failures can be ana-
4061.10Ssommerfe                lyzed.
4071.10Ssommerfe
4081.1Stv     -m dir     Specify the default directory for searching for system Make-
4091.1Stv                file segments, mainly the <bsd.*.mk> files.  When building any
4101.1Stv                full NetBSD source tree, this should be set to the
4111.70Sdholland                ``share/mk'' directory in the source tree.  This is set auto-
4121.70Sdholland                matically when building from the top level, or when using
4131.70Sdholland                build.sh.
4141.1Stv
4151.1Stv     -n         Display the commands that would have been executed, but do not
4161.1Stv                actually execute them.  This will still cause recursion to
4171.1Stv                take place.
4181.1Stv
4191.47Szuntum     -V var     Print make(1)'s idea of the value of var.  Does not build any
4201.1Stv                targets.
4211.1Stv
4221.1Stv     var=value  Set the variable var to value, overriding any setting speci-
4231.1Stv                fied by the process environment, the MAKECONF configuration
4241.1Stv                file, or the system Makefile segments.
4251.1Stv
4261.1Stv   "make" targets
4271.1Stv     These default targets may be built by running make(1) in any subtree of
4281.1Stv     the NetBSD source code.  It is recommended that none of these be used
4291.1Stv     from the top level Makefile; as a specific exception, ``make obj'' and
4301.1Stv     ``make cleandir'' are useful in that context.
4311.1Stv
4321.1Stv     all        Build programs, libraries, and preformatted documentation.
4331.1Stv
4341.1Stv     clean      Remove program and library object code files.
4351.1Stv
4361.44Slukem     cleandir   Same as clean, but also remove preformatted documentation,
4371.44Slukem                dependency files generated by ``make depend'', and any other
4381.49Slukem                files known to be created at build time.
4391.1Stv
4401.44Slukem     depend     Create dependency files (.depend) containing more detailed
4411.44Slukem                information about the dependencies of source code on header
4421.1Stv                files.  Allows programs to be recompiled automatically when a
4431.1Stv                dependency changes.
4441.1Stv
4451.1Stv     dependall  Does a ``make depend'' immediately followed by a ``make all''.
4461.10Ssommerfe                This improves cache locality of the build since both passes
4471.10Ssommerfe                read the source files in their entirety.
4481.1Stv
4491.49Slukem     distclean  Synonym for cleandir.
4501.49Slukem
4511.44Slukem     includes   Build and install system header files.  Typically needed
4521.44Slukem                before any system libraries or programs can be built.
4531.1Stv
4541.1Stv     install    Install programs, libraries, and documentation into DESTDIR.
4551.27Slukem                Few files will be installed to DESTDIR/dev, DESTDIR/etc,
4561.27Slukem                DESTDIR/root or DESTDIR/var in order to prevent user supplied
4571.27Slukem                configuration data from being overwritten.
4581.1Stv
4591.1Stv     lint       Run lint(1) against the C source code, where appropriate, and
4601.1Stv                generate system-installed lint libraries.
4611.1Stv
4621.1Stv     obj        Create object directories to be used for built files, instead
4631.1Stv                of building directly in the source tree.
4641.1Stv
4651.1Stv     tags       Create ctags(1) searchable function lists usable by the ex(1)
4661.1Stv                and vi(1) text editors.
4671.1Stv
4681.1Stv   "make" targets for the top level
4691.1Stv     Additional make(1) targets are usable specifically from the top source
4701.1Stv     level to facilitate building the entire NetBSD source tree.
4711.1Stv
4721.68Sreed     build         Build the entire NetBSD system (except the kernel).  This
4731.68Sreed                   orders portions of the source tree such that prerequisites
4741.68Sreed                   will be built in the proper order.
4751.20Slukem
4761.20Slukem     distribution  Do a ``make build'', and then install a full distribution
4771.68Sreed                   (which does not include a kernel) into DESTDIR, including
4781.68Sreed                   files in DESTDIR/dev, DESTDIR/etc, DESTDIR/root and
4791.68Sreed                   DESTDIR/var.
4801.20Slukem
4811.20Slukem     buildworld    As per ``make distribution'', except that it ensures that
4821.20Slukem                   DESTDIR is not the root directory.
4831.20Slukem
4841.70Sdholland     installworld  Install the distribution from DESTDIR to INSTALLWORLDDIR,
4851.70Sdholland                   which defaults to the root directory.  Ensures that
4861.52Sjmc                   INSTALLWORLDDIR is not the root directory if cross compil-
4871.20Slukem                   ing.
4881.20Slukem
4891.61Sapb                   The INSTALLSETS environment variable may be set to a list
4901.61Sapb                   of distribution sets to be installed.  By default, all sets
4911.70Sdholland                   except ``etc'' and ``xetc'' are installed, so most files in
4921.70Sdholland                   INSTALLWORLDDIR/etc will not be installed or modified.
4931.61Sapb
4941.61Sapb                   Note: Before performing this operation with
4951.61Sapb                   INSTALLWORLDDIR=/, it is highly recommended that you
4961.61Sapb                   upgrade your kernel and reboot.  After performing this
4971.61Sapb                   operation, it is recommended that you use etcupdate(8) to
4981.61Sapb                   update files in INSTALLWORLDDIR/etc and that you use
4991.61Sapb                   postinstall(8) to check for inconsistencies (and possibly
5001.61Sapb                   to fix them).
5011.20Slukem
5021.25Slukem     sets          Create distribution sets from DESTDIR into
5031.69Slukem                   RELEASEDIR/RELEASEMACHINEDIR/binary/sets.  Should be run
5041.70Sdholland                   after ``make distribution'', as ``make build'' alone does
5051.70Sdholland                   not install all of the required files.
5061.25Slukem
5071.31Slukem     sourcesets    Create source sets of the source tree into
5081.31Slukem                   RELEASEDIR/source/sets.
5091.31Slukem
5101.54Sapb     syspkgs       Create syspkgs from DESTDIR into
5111.69Slukem                   RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.  Should be run
5121.70Sdholland                   after ``make distribution'', as ``make build'' alone does
5131.70Sdholland                   not install all of the required files.
5141.54Sapb
5151.44Slukem     release       Do a ``make distribution'', build kernels, distribution
5161.44Slukem                   media, and install sets (this as per ``make sets''), and
5171.44Slukem                   then package the system into a standard release layout as
5181.44Slukem                   described by release(7).  This requires that RELEASEDIR be
5191.25Slukem                   set (see above).
5201.1Stv
5211.62Sapb     iso-image     Create a NetBSD installation CD-ROM image in the
5221.62Sapb                   RELEASEDIR/iso directory.  The CD-ROM file system will have
5231.62Sapb                   a layout as described in release(7).
5241.62Sapb
5251.62Sapb                   For most machine types, the CD-ROM will be bootable, and
5261.62Sapb                   will automatically run the sysinst(8) menu-based installa-
5271.62Sapb                   tion program, which can be used to install or upgrade a
5281.62Sapb                   NetBSD system.  Bootable CD-ROMs also contain tools that
5291.62Sapb                   may be useful in repairing a damaged NetBSD installation.
5301.62Sapb
5311.62Sapb                   Before ``make iso-image'' is attempted, RELEASEDIR must be
5321.62Sapb                   populated by ``make release'' or equivalent.
5331.62Sapb
5341.62Sapb                   Note that other, smaller, CD-ROM images may be created in
5351.69Slukem                   the RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom direc-
5361.69Slukem                   tory by ``make release''.  These smaller images usually
5371.69Slukem                   contain the same tools as the larger images in
5381.69Slukem                   RELEASEDIR/iso, but do not contain additional content such
5391.69Slukem                   as the distribution sets.
5401.62Sapb
5411.62Sapb                   Note that the mac68k port still uses an older method of
5421.62Sapb                   creating CD-ROM images.  This requires the mkisofs(1) util-
5431.62Sapb                   ity, which is not part of NetBSD, but which can be
5441.62Sapb                   installed from pkgsrc/sysutils/cdrtools.
5451.56Sapb
5461.64Sjnemeth     iso-image-source
5471.64Sjnemeth                   Create a NetBSD installation CD-ROM image in the
5481.64Sjnemeth                   RELEASEDIR/iso directory.  The CD-ROM file system will have
5491.64Sjnemeth                   a layout as described in release(7).  It will have top
5501.64Sjnemeth                   level directories for the machine type and source.
5511.64Sjnemeth
5521.64Sjnemeth                   For most machine types, the CD-ROM will be bootable, and
5531.64Sjnemeth                   will automatically run the sysinst(8) menu-based installa-
5541.64Sjnemeth                   tion program, which can be used to install or upgrade a
5551.64Sjnemeth                   NetBSD system.  Bootable CD-ROMs also contain tools that
5561.64Sjnemeth                   may be useful in repairing a damaged NetBSD installation.
5571.64Sjnemeth
5581.64Sjnemeth                   Before ``make iso-image-source'' is attempted, RELEASEDIR
5591.64Sjnemeth                   must be populated by ``make sourcesets release'' or equiva-
5601.64Sjnemeth                   lent.
5611.64Sjnemeth
5621.64Sjnemeth                   Note that other, smaller, CD-ROM images may be created in
5631.69Slukem                   the RELEASEDIR/RELEASEMACHINEDIR/installation/cdrom direc-
5641.69Slukem                   tory by ``make release''.  These smaller images usually
5651.69Slukem                   contain the same tools as the larger images in
5661.69Slukem                   RELEASEDIR/iso, but do not contain additional content such
5671.69Slukem                   as the distribution sets.
5681.64Sjnemeth
5691.64Sjnemeth                   Note that the mac68k port still uses an older method of
5701.64Sjnemeth                   creating CD-ROM images.  This requires the mkisofs(1) util-
5711.64Sjnemeth                   ity, which is not part of NetBSD, but which can be
5721.64Sjnemeth                   installed from pkgsrc/sysutils/cdrtools.
5731.64Sjnemeth
5741.1Stv     regression-tests
5751.20Slukem                   Can only be run after building the regression tests in the
5761.70Sdholland                   directory ``regress''.  Runs those compiled regression
5771.70Sdholland                   tests on the local host.  Note that most tests are now man-
5781.70Sdholland                   aged instead using atf(7); this target should probably run
5791.70Sdholland                   those as well but currently does not.
5801.1Stv
5811.1Stv   The "build.sh" script
5821.1Stv     This script file is a Bourne shell script designed to build the entire
5831.1Stv     NetBSD system on any host with a Bourne shell in /bin/sh, including many
5841.1Stv     that are not POSIX compliant.  Note that if a host system's /bin/sh is
5851.1Stv     unusually old and broken, the Korn Shell (/bin/ksh), if available, may be
5861.1Stv     a usable alternative.
5871.1Stv
5881.1Stv     All cross-compile builds, and most native builds, of the entire system
5891.1Stv     should make use of build.sh rather than just running ``make''.  This way,
5901.1Stv     the make(1) program will be bootstrapped properly, in case the host sys-
5911.1Stv     tem has an older or incompatible ``make'' program.
5921.1Stv
5931.1Stv     When compiling the entire system via build.sh, many make(1) variables are
5941.1Stv     set for you in order to help encapsulate the build process.  In the list
5951.1Stv     of options below, variables that are automatically set by build.sh are
5961.1Stv     noted where applicable.
5971.1Stv
5981.22Slukem     The following operations are supported by build.sh:
5991.22Slukem
6001.70Sdholland     build         Build the system as per ``make build''.  Before the main
6011.70Sdholland                   part of the build commences, this command runs the obj
6021.70Sdholland                   operation (unless the -o option is given), ``make
6031.70Sdholland                   cleandir'' (unless the -u option is given), and the tools
6041.70Sdholland                   operation.
6051.22Slukem
6061.22Slukem     distribution  Build a full distribution as per ``make distribution''.
6071.70Sdholland                   This command first runs the build operation.
6081.22Slukem
6091.70Sdholland     release       Build a full release as per ``make release''.  This command
6101.70Sdholland                   first runs the distribution operation.
6111.22Slukem
6121.23Slukem     makewrapper   Create the nbmake-MACHINE wrapper.  This operation is auto-
6131.23Slukem                   matically performed for any of the other operations.
6141.23Slukem
6151.22Slukem     obj           Perform ``make obj''.
6161.22Slukem
6171.70Sdholland     tools         Build and install the host tools from src/tools.  This com-
6181.70Sdholland                   mand will first run ``make obj'' and ``make cleandir'' in
6191.70Sdholland                   the tools subdirectory unless the -o or -u options (respec-
6201.70Sdholland                   tively) are given.
6211.22Slukem
6221.35Slukem     install=idir  Install the contents of DESTDIR to idir, using ``make
6231.61Sapb                   installworld''.  Note that files that are part of the
6241.61Sapb                   ``etc'' or ``xetc'' sets will not be installed.
6251.35Slukem
6261.22Slukem     kernel=kconf  Build a new kernel.  The kconf argument is the name of a
6271.54Sapb                   configuration file suitable for use by config(1).  If kconf
6281.22Slukem                   does not contain any `/' characters, the configuration file
6291.22Slukem                   is expected to be found in the KERNCONFDIR directory, which
6301.22Slukem                   is typically sys/arch/MACHINE/conf.  The new kernel will be
6311.22Slukem                   built in a subdirectory of KERNOBJDIR, which is typically
6321.22Slukem                   sys/arch/MACHINE/compile or an associated object directory.
6331.70Sdholland
6341.70Sdholland                   This command does not imply the tools command; run the
6351.70Sdholland                   tools command first unless it is certain that the tools
6361.70Sdholland                   already exist and are up to date.
6371.70Sdholland
6381.70Sdholland                   This command will run ``make cleandir'' on the kernel in
6391.70Sdholland                   question first unless the -u option is given.
6401.22Slukem
6411.35Slukem     releasekernel=kconf
6421.70Sdholland                   Install a gzip(1)ed copy of the kernel previously built by
6431.69Slukem                   kernel=kconf into
6441.69Slukem                   RELEASEDIR/RELEASEMACHINEDIR/binary/kernel, usually as
6451.69Slukem                   netbsd-kconf.gz, although the ``netbsd'' prefix is deter-
6461.69Slukem                   mined from the ``config'' directives in kconf.
6471.24Slukem
6481.24Slukem     sets          Perform ``make sets''.
6491.31Slukem
6501.31Slukem     sourcesets    Perform ``make sourcesets''.
6511.22Slukem
6521.54Sapb     syspkgs       Perform ``make syspkgs''.
6531.54Sapb
6541.56Sapb     iso-image     Perform ``make iso-image''.
6551.56Sapb
6561.65Sjnemeth     iso-image-source
6571.65Sjnemeth                   Perform ``make iso-image-source''.
6581.65Sjnemeth
6591.51Swiz     The following command line options alter the behaviour of the build.sh
6601.51Swiz     operations described above:
6611.1Stv
6621.1Stv     -a arch   Set the value of MACHINE_ARCH to arch.
6631.9Sthorpej
6641.9Sthorpej     -B buildid
6651.9Sthorpej               Set the value of BUILDID to buildid.  This will also append the
6661.67Ssborrill               build identifier to the name of the ``make'' wrapper script so
6671.37Slukem               that the resulting name is of the form
6681.37Slukem               ``nbmake-MACHINE-BUILDID''.
6691.1Stv
6701.67Ssborrill     -C cdextras
6711.67Ssborrill               Set the value of CDEXTRA to cdextras which is a space-separated
6721.67Ssborrill               list of files or directories which will be added in order to
6731.67Ssborrill               the CD-ROM image when used in conjunction with ``iso-image'' or
6741.67Ssborrill               ``iso-image-source''.  Files will be added to the root of the
6751.67Ssborrill               CD-ROM image, whereas directories will be copied recursively.
6761.67Ssborrill               If relative paths are specified, they will be converted to
6771.67Ssborrill               absolute paths before being used.
6781.66Sjnemeth
6791.59Sapb     -D dest   Set the value of DESTDIR to dest.  If a relative path is speci-
6801.59Sapb               fied, it will be converted to an absolute path before being
6811.59Sapb               used.
6821.18Slukem
6831.23Slukem     -E        Set `expert' mode.  This overrides various sanity checks, and
6841.23Slukem               allows: DESTDIR does not have to be set to a non-root path for
6851.38Slukem               builds, and MKUNPRIVED=yes does not have to be set when build-
6861.38Slukem               ing as a non-root user.
6871.23Slukem
6881.23Slukem               Note: It is highly recommended that you know what you are doing
6891.23Slukem               when you use this option.
6901.19Slukem
6911.51Swiz     -h        Print a help message.
6921.51Swiz
6931.70Sdholland     -j njob   Run up to njob make(1) subjobs in parallel; passed through to
6941.70Sdholland               make(1).  Makefiles should use .WAIT or have explicit dependan-
6951.70Sdholland               cies as necessary to enforce build ordering.  If you see build
6961.70Sdholland               failures with -j, please save complete build logs so the fail-
6971.70Sdholland               ures can be analyzed.
6981.1Stv
6991.59Sapb     -M obj    Set MAKEOBJDIRPREFIX to obj.  If a relative path is specified,
7001.59Sapb               it will be converted to an absolute path before being used.
7011.59Sapb               Unsets MAKEOBJDIR.
7021.18Slukem
7031.60Sapb     -m mach   Set the value of MACHINE to mach, except in some special cases
7041.60Sapb               listed below.  This will also override any value of
7051.60Sapb               MACHINE_ARCH in the process environment with a value deduced
7061.60Sapb               from mach, unless -a is specified.  All cross builds require
7071.60Sapb               -m, but if unset on a NetBSD host, the host's value of MACHINE
7081.60Sapb               will be detected and used automatically.
7091.60Sapb
7101.60Sapb               Some machines support multiple values for MACHINE_ARCH.  The
7111.60Sapb               following special cases for the mach argument are defined to
7121.60Sapb               set the listed values of MACHINE and MACHINE_ARCH:
7131.33Slukem
7141.33Slukem                     mach          MACHINE    MACHINE_ARCH
7151.60Sapb                     evbarm        evbarm     (not set)
7161.60Sapb                     evbarm-eb     evbarm     armeb
7171.60Sapb                     evbarm-el     evbarm     arm
7181.33Slukem                     evbmips       evbmips    (not set)
7191.33Slukem                     evbmips-eb    evbmips    mipseb
7201.33Slukem                     evbmips-el    evbmips    mipsel
7211.33Slukem                     evbsh3        evbsh3     (not set)
7221.33Slukem                     evbsh3-eb     evbsh3     sh3eb
7231.33Slukem                     evbsh3-el     evbsh3     sh3el
7241.33Slukem                     sbmips        sbmips     (not set)
7251.33Slukem                     sbmips-eb     sbmips     mipseb
7261.33Slukem                     sbmips-el     sbmips     mipsel
7271.1Stv
7281.45Slukem     -N noiselevel
7291.46Slukem               Set the ``noisyness'' level of the build, by setting
7301.46Slukem               MAKEVERBOSE to noiselevel.
7311.45Slukem
7321.1Stv     -n        Show the commands that would be executed by build.sh, but do
7331.1Stv               not make any changes.  This is similar in concept to ``make
7341.1Stv               -n''.
7351.1Stv
7361.18Slukem     -O obj    Create an appropriate transform macro for MAKEOBJDIR that will
7371.59Sapb               place the built object files under obj.  If a relative path is
7381.59Sapb               specified, it will be converted to an absolute path before
7391.59Sapb               being used.  For instance, a setting of /usr/obj will place
7401.59Sapb               build-time files under /usr/obj/bin, /usr/obj/lib,
7411.59Sapb               /usr/obj/usr.bin, and so forth.  Unsets MAKEOBJDIRPREFIX.
7421.18Slukem
7431.34Slukem     -o        Set the value of MKOBJDIRS to ``no''.  Otherwise, it will be
7441.70Sdholland               automatically set to ``yes''.  This default is opposite to the
7451.70Sdholland               behaviour when not using build.sh.
7461.1Stv
7471.59Sapb     -R rel    Set the value of RELEASEDIR to rel.  If a relative path is
7481.59Sapb               specified, it will be converted to an absolute path before
7491.59Sapb               being used.
7501.18Slukem
7511.1Stv     -r        Remove the contents of DESTDIR and TOOLDIR before building
7521.1Stv               (provides a clean starting point).  This will skip deleting
7531.1Stv               DESTDIR if building on a native system to the root directory.
7541.1Stv
7551.59Sapb     -T tools  Set the value of TOOLDIR to tools.  If a relative path is spec-
7561.59Sapb               ified, it will be converted to an absolute path before being
7571.70Sdholland               used.  If set, the bootstrap ``make'' will only be rebuilt if
7581.70Sdholland               the source files for make(1) have changed.
7591.18Slukem
7601.38Slukem     -U        Set MKUNPRIVED=yes.
7611.18Slukem
7621.38Slukem     -u        Set MKUPDATE=yes.
7631.1Stv
7641.21Slukem     -V var=[value]
7651.40Slukem               Set the environment variable var to an optional value.  This is
7661.40Slukem               propagated to the nbmake wrapper.
7671.21Slukem
7681.1Stv     -w wrapper
7691.1Stv               Create the nbmake wrapper script (see below) in a custom loca-
7701.1Stv               tion, specified by wrapper.  This allows, for instance, to
7711.1Stv               place the wrapper in PATH automatically.  Note that wrapper is
7721.59Sapb               the full name of the file, not just a directory name.  If a
7731.59Sapb               relative path is specified, it will be converted to an absolute
7741.59Sapb               path before being used.
7751.1Stv
7761.49Slukem     -X x11src
7771.59Sapb               Set the value of X11SRCDIR to x11src.  If a relative path is
7781.59Sapb               specified, it will be converted to an absolute path before
7791.59Sapb               being used.
7801.49Slukem
7811.49Slukem     -x        Set MKX11=yes.
7821.49Slukem
7831.40Slukem     -Z var    Unset ("zap") the environment variable var.  This is propagated
7841.40Slukem               to the nbmake wrapper.
7851.40Slukem
7861.1Stv   The "nbmake-MACHINE" wrapper script
7871.1Stv     If using the build.sh script to build NetBSD, a nbmake-MACHINE script
7881.1Stv     will be created in TOOLDIR/bin upon the first build to assist in building
7891.1Stv     subtrees on a cross-compile host.
7901.1Stv
7911.1Stv     nbmake-MACHINE can be invoked in lieu of make(1), and will instead call
7921.1Stv     the up-to-date version of ``nbmake'' installed into TOOLDIR/bin with sev-
7931.1Stv     eral key variables pre-set, including MACHINE, MACHINE_ARCH, and TOOLDIR.
7941.70Sdholland     nbmake-MACHINE will also set variables specified with -V, and unset vari-
7951.70Sdholland     ables specified with -Z.
7961.40Slukem
7971.1Stv     This script can be symlinked into a directory listed in PATH, or called
7981.1Stv     with an absolute path.
7991.1Stv
8001.16SlukemEXAMPLES
8011.44Slukem     1.   % ./build.sh tools kernel=GENERIC
8021.28Slukem
8031.28Slukem          Build a new toolchain, and use the new toolchain to configure and
8041.28Slukem          build a new GENERIC kernel.
8051.28Slukem
8061.44Slukem     2.   % ./build.sh -U distribution
8071.28Slukem
8081.30Slukem          Using unprivileged mode, build a complete distribution to a DESTDIR
8091.30Slukem          directory that build.sh selects (and will display).
8101.28Slukem
8111.43Smartti     3.   # ./build.sh -U install=/
8121.28Slukem
8131.29Slukem          As root, install to / the distribution that was built by example 2.
8141.29Slukem          Even though this is run as root, -U is required so that the permis-
8151.30Slukem          sions stored in DESTDIR/METALOG are correctly applied to the files
8161.30Slukem          as they're copied to /.
8171.28Slukem
8181.44Slukem     4.   % ./build.sh -U -u release
8191.28Slukem
8201.30Slukem          Using unprivileged mode, build a complete release to DESTDIR and
8211.30Slukem          RELEASEDIR directories that build.sh selects (and will display).
8221.38Slukem          MKUPDATE=yes (-u) is set to prevent the ``make cleandir'', so that
8231.38Slukem          if this is run after example 2, it doesn't need to redo that portion
8241.38Slukem          of the release build.
8251.16Slukem
8261.10SsommerfeOBSOLETE VARIABLES
8271.70Sdholland     NBUILDJOBS  Use the make(1) option -j instead.
8281.15Slukem
8291.15Slukem     USE_NEW_TOOLCHAIN
8301.15Slukem                 The new toolchain is now the default.  To disable, use
8311.15Slukem                 TOOLCHAIN_MISSING=yes.
8321.10Ssommerfe
8331.1StvSEE ALSO
8341.62Sapb     make(1), hier(7), release(7), etcupdate(8), postinstall(8), sysinst(8),
8351.61Sapb     pkgsrc/sysutils/cdrtools
8361.1Stv
8371.1StvHISTORY
8381.15Slukem     The build.sh based build scheme was introduced for NetBSD 1.6 as
8391.15Slukem     USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that.
8401.1Stv
8411.1StvBUGS
8421.15Slukem     A few platforms are not yet using this build system.
8431.1Stv
8441.69SlukemNetBSD                          March 18, 2008                          NetBSD
845