BUILDING revision 1.58
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.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.44Slukem     Discrepancies between this documentation and the current reality of
131.44Slukem     implementation 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.15Slukem     as indicated by the default setting of TOOLCHAIN_MISSING 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.53Sreed     the NetBSD build process.  (See the environment variables section below
321.53Sreed     if you need to override or manually select your compilers.)
331.1Stv
341.1StvFILES
351.1Stv   Source tree layout
361.17Swiz     doc/BUILDING.mdoc
371.17Swiz                    This document (in -mdoc troff format; the original copy).
381.1Stv
391.2Swiz     BUILDING       This document (in plaintext).
401.1Stv
411.48Sjmc     tools/compat/README
421.48Sjmc                    Special notes for cross-hosting a NetBSD build on non-
431.48Sjmc                    NetBSD platforms.
441.48Sjmc
451.44Slukem     Makefile       The main Makefile for NetBSD; should only be run for
461.44Slukem                    native 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.44Slukem                    Makefile semantics when building these programs for a
651.44Slukem                    native host.
661.1Stv
671.1Stv     distrib/, etc/
681.1Stv                    Sources for items used when making a full release snap-
691.27Slukem                    shot, such as files installed in DESTDIR/etc on the desti-
701.27Slukem                    nation 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.49Slukem     x11/           ``Reachover'' build structure for X11R6; the source is in
871.49Slukem                    X11SRCDIR.
881.49Slukem
891.1Stv   Build tree layout
901.1Stv     The NetBSD build tree is described in hier(7), and the release layout is
911.1Stv     described in release(7).
921.1Stv
931.1StvCONFIGURATION
941.8Slukem   Environment variables
951.8Slukem     Several environment variables control the behaviour of NetBSD builds.
961.8Slukem
971.58Sapb     HOST_SH           Path name to a POSIX-compliant shell.  If this is not
981.58Sapb                       set explicitly, then the default is set using heuris-
991.58Sapb                       tics dependent on the host platform, or from the shell
1001.58Sapb                       under which build.sh is executed (if that can be deter-
1011.58Sapb                       mined), or using the first copy of sh found in PATH.
1021.58Sapb                       If the host system's /bin/sh is not POSIX-compliant, we
1031.58Sapb                       suggest that you build using commands like
1041.58Sapb
1051.58Sapb                             HOST_SH=/path/to/working/shell
1061.58Sapb                             export HOST_SH
1071.58Sapb                             ${HOST_SH} build.sh [options]
1081.58Sapb
1091.53Sreed     HOST_CC           Path name to C compiler used to create the toolchain.
1101.53Sreed
1111.53Sreed     HOST_CXX          Path name to C++ compiler used to create the toolchain.
1121.53Sreed
1131.8Slukem     MACHINE           Machine type.
1141.8Slukem
1151.8Slukem     MACHINE_ARCH      Machine architecture.
1161.8Slukem
1171.8Slukem     MAKE              Path name to invoke make(1) as.
1181.8Slukem
1191.8Slukem     MAKEFLAGS         Flags to invoke make(1) with.
1201.8Slukem
1211.8Slukem     MAKEOBJDIR        Directory to use as the .OBJDIR for the current direc-
1221.8Slukem                       tory.  Used only if MAKEOBJDIRPREFIX is not defined.
1231.36Slukem                       MAKEOBJDIR can only be provided in the environment or
1241.41Slukem                       via the -O flag of build.sh.
1251.8Slukem
1261.8Slukem     MAKEOBJDIRPREFIX  Top level directory of the object directory tree.  If
1271.8Slukem                       this is defined, ${MAKEOBJDIRPREFIX}/${.CURDIR} is used
1281.8Slukem                       as the .OBJDIR for the current directory.  The current
1291.8Slukem                       directory may be read only.  MAKEOBJDIRPREFIX can only
1301.36Slukem                       be provided in the environment or via the -M flag of
1311.36Slukem                       build.sh.
1321.8Slukem
1331.1Stv   "make" variables
1341.1Stv     Several variables control the behavior of NetBSD builds.  Unless other-
1351.1Stv     wise specified, these variables may be set in either the process environ-
1361.1Stv     ment or the make(1) configuration file specified by MAKECONF.
1371.1Stv
1381.9Sthorpej     BUILDID     Identifier for the build.  The identifier will be appended to
1391.9Sthorpej                 object directory names, and can be consulted in the make(1)
1401.9Sthorpej                 configuration file in order to set additional build parame-
1411.9Sthorpej                 ters, such as compiler flags.
1421.9Sthorpej
1431.1Stv     DESTDIR     Directory to contain the built NetBSD system.  If set, spe-
1441.1Stv                 cial options are passed to the compilation tools to prevent
1451.1Stv                 their default use of the host system's /usr/include,
1461.1Stv                 /usr/lib, and so forth.  This pathname should not end with a
1471.1Stv                 slash (/) character (for installation into the system's root
1481.7Slukem                 directory, set DESTDIR to an empty string).  The directory
1491.7Slukem                 must reside on a file system which supports long file names
1501.7Slukem                 and hard links.
1511.1Stv
1521.1Stv                 Default: Empty string if USETOOLS is ``yes''; unset other-
1531.1Stv                 wise.
1541.1Stv
1551.30Slukem                 Note: build.sh will provide a default of destdir.MACHINE (in
1561.30Slukem                 the top-level .OBJDIR) unless run in `expert' mode
1571.30Slukem
1581.1Stv     MAKECONF    The name of the make(1) configuration file.  Only settable in
1591.1Stv                 the process environment.
1601.1Stv
1611.1Stv                 Default: ``/etc/mk.conf''
1621.1Stv
1631.45Slukem     MAKEVERBOSE
1641.45Slukem                 Level of verbosity of status messages.  Supported values:
1651.45Slukem
1661.45Slukem                 0    No descriptive messages are shown.
1671.45Slukem
1681.45Slukem                 1    Descriptive messages are shown.
1691.45Slukem
1701.45Slukem                 2    Descriptive messages (prefixed with a `#') and command
1711.45Slukem                      output is not suppressed.
1721.45Slukem
1731.45Slukem                 Default: 2
1741.45Slukem
1751.1Stv     MKCATPAGES  Can be set to ``yes'' or ``no''.  Indicates whether prefor-
1761.1Stv                 matted plaintext manual pages will be created during a build.
1771.1Stv
1781.1Stv                 Default: ``yes''
1791.1Stv
1801.1Stv     MKCRYPTO    Can be set to ``yes'' or ``no''.  Indicates whether crypto-
1811.1Stv                 graphic code will be included in a build; provided for the
1821.1Stv                 benefit of countries that do not allow strong cryptography.
1831.44Slukem                 Will not affect use of the standard low-security password
1841.44Slukem                 encryption system, crypt(3).
1851.1Stv
1861.1Stv                 Default: ``yes''
1871.1Stv
1881.1Stv     MKDOC       Can be set to ``yes'' or ``no''.  Indicates whether system
1891.44Slukem                 documentation destined for DESTDIR/usr/share/doc will be
1901.44Slukem                 installed during a build.
1911.1Stv
1921.1Stv                 Default: ``yes''
1931.1Stv
1941.4Stv     MKHOSTOBJ   Can be set to ``yes'' or ``no''.  If set to ``yes'', then for
1951.4Stv                 programs intended to be run on the compile host, the name,
1961.4Stv                 release, and architecture of the host operating system will
1971.4Stv                 be suffixed to the name of the object directory created by
1981.4Stv                 ``make obj''.  (This allows multiple host systems to compile
1991.4Stv                 NetBSD for a single target.)  If set to ``no'', then programs
2001.4Stv                 built to be run on the compile host will use the same object
2011.4Stv                 directory names as programs built to be run on the target.
2021.4Stv
2031.4Stv                 Default: ``no''
2041.4Stv
2051.1Stv     MKINFO      Can be set to ``yes'' or ``no''.  Indicates whether GNU Info
2061.1Stv                 files, used for the documentation for most of the compilation
2071.1Stv                 tools, will be created and installed during a build.
2081.1Stv
2091.1Stv                 Default: ``yes''
2101.1Stv
2111.1Stv     MKLINT      Can be set to ``yes'' or ``no''.  Indicates whether lint(1)
2121.1Stv                 will be run against portions of the NetBSD source code during
2131.1Stv                 the build, and whether lint libraries will be installed into
2141.27Slukem                 DESTDIR/usr/libdata/lint.
2151.1Stv
2161.1Stv                 Default: ``yes''
2171.1Stv
2181.1Stv     MKMAN       Can be set to ``yes'' or ``no''.  Indicates whether manual
2191.1Stv                 pages will be installed during a build.
2201.1Stv
2211.1Stv                 Default: ``yes''
2221.1Stv
2231.1Stv     MKNLS       Can be set to ``yes'' or ``no''.  Indicates whether Native
2241.44Slukem                 Language System locale zone files will be compiled and
2251.44Slukem                 installed during a build.
2261.1Stv
2271.1Stv                 Default: ``yes''
2281.1Stv
2291.1Stv     MKOBJ       Can be set to ``yes'' or ``no''.  Indicates whether object
2301.1Stv                 directories will be created when running ``make obj''.  If
2311.1Stv                 set to ``no'', then all built files will be located inside
2321.1Stv                 the regular source tree.
2331.1Stv
2341.1Stv                 Default: ``yes''
2351.1Stv
2361.1Stv     MKPIC       Can be set to ``yes'' or ``no''.  Indicates whether shared
2371.1Stv                 objects and libraries will be created and installed during a
2381.1Stv                 build.  If set to ``no'', the entire built system will be
2391.1Stv                 statically linked.
2401.1Stv
2411.1Stv                 Default: Platform dependent.  As of this writing, all plat-
2421.1Stv                 forms except sh3 default to ``yes''.
2431.1Stv
2441.1Stv     MKPICINSTALL
2451.1Stv                 Can be set to ``yes'' or ``no''.  Indicates whether the ar(1)
2461.44Slukem                 format libraries (lib*_pic.a), used to generate shared
2471.44Slukem                 libraries, are installed during a build.
2481.1Stv
2491.1Stv                 Default: ``yes''
2501.1Stv
2511.1Stv     MKPROFILE   Can be set to ``yes'' or ``no''.  Indicates whether profiled
2521.1Stv                 libraries (lib*_p.a) will be built and installed during a
2531.1Stv                 build.
2541.1Stv
2551.1Stv                 Default: ``yes''; however, some platforms turn off MKPROFILE
2561.1Stv                 by default at times due to toolchain problems with profiled
2571.1Stv                 code.
2581.1Stv
2591.1Stv     MKSHARE     Can be set to ``yes'' or ``no''.  Indicates whether files
2601.44Slukem                 destined to reside in DESTDIR/usr/share will be built and
2611.44Slukem                 installed during a build.  If set to ``no'', then all of
2621.27Slukem                 MKCATPAGES, MKDOC, MKINFO, MKMAN, and MKNLS will be set to
2631.27Slukem                 ``no'' unconditionally.
2641.1Stv
2651.1Stv                 Default: ``yes''
2661.1Stv
2671.50Swiz     MKTTINTERP  Can be set to ``yes'' or ``no''.  For X builds, decides if
2681.50Swiz                 the TrueType bytecode interpreter is turned on.  See
2691.50Swiz                 http://www.freetype.org/patents.html for details.
2701.50Swiz
2711.50Swiz                 Default: ``no''
2721.50Swiz
2731.44Slukem     MKUNPRIVED  Can be set to ``yes'' or ``no''.  Indicates whether an
2741.44Slukem                 unprivileged install will occur.  The user, group, permis-
2751.52Sjmc                 sions, and file flags, will not be set on the installed
2761.52Sjmc                 items; instead the information will be appended to a file
2771.52Sjmc                 called METALOG in DESTDIR.  The contents of METALOG are used
2781.52Sjmc                 during the generation of the distribution tar files to ensure
2791.52Sjmc                 that the appropriate file ownership is stored.
2801.38Slukem
2811.38Slukem                 Default: ``no''
2821.38Slukem
2831.44Slukem     MKUPDATE    Can be set to ``yes'' or ``no''.  Indicates whether all
2841.44Slukem                 install operations intended to write to DESTDIR will compare
2851.38Slukem                 file timestamps before installing, and skip the install phase
2861.44Slukem                 if the destination files are up-to-date.  This also has
2871.44Slukem                 implications on full builds (see next subsection).
2881.38Slukem
2891.38Slukem                 Default: ``no''
2901.38Slukem
2911.49Slukem     MKX11       Can be set to ``yes'' or ``no''.  Indicates whether X11R6 is
2921.49Slukem                 built from X11SRCDIR.
2931.49Slukem
2941.49Slukem                 Default: ``no''
2951.49Slukem
2961.1Stv     TOOLDIR     Directory to hold the host tools, once built.  This directory
2971.1Stv                 should be unique to a given host system and NetBSD source
2981.1Stv                 tree.  (However, multiple targets may share the same TOOLDIR;
2991.1Stv                 the target-dependent files have unique names.)  If unset, a
3001.1Stv                 default based on the uname(1) information of the host plat-
3011.39Slukem                 form will be created in the .OBJDIR of src.
3021.1Stv
3031.1Stv                 Default: Unset.
3041.1Stv
3051.1Stv     USETOOLS    Indicates whether the tools specified by TOOLDIR should be
3061.1Stv                 used as part of a build in progress.  Must be set to ``yes''
3071.1Stv                 if cross-compiling.
3081.1Stv
3091.1Stv                 yes    Use the tools from TOOLDIR.
3101.1Stv
3111.1Stv                 no     Do not use the tools from TOOLDIR, but refuse to build
3121.1Stv                        native compilation tool components that are version-
3131.1Stv                        specific for that tool.
3141.1Stv
3151.1Stv                 never  Do not use the tools from TOOLDIR, even when building
3161.1Stv                        native tool components.  This is similar to the tradi-
3171.1Stv                        tional NetBSD build method, but does not verify that
3181.1Stv                        the compilation tools in use are up-to-date enough in
3191.1Stv                        order to build the tree successfully.  This may cause
3201.1Stv                        build or runtime problems when building the whole
3211.1Stv                        NetBSD source tree.
3221.1Stv
3231.1Stv                 Default: ``yes'' if building all or part of a whole NetBSD
3241.1Stv                 source tree (detected automatically); ``no'' otherwise (to
3251.44Slukem                 preserve traditional semantics of the <bsd.*.mk> make(1)
3261.44Slukem                 include files).
3271.1Stv
3281.49Slukem     X11SRCDIR   Directory containing the X11R6 source.  The main X11R6 source
3291.49Slukem                 is found in X11SRCDIR/xfree/xc.
3301.49Slukem
3311.49Slukem                 Default: ``/usr/xsrc''
3321.49Slukem
3331.1Stv   "make" variables for full builds
3341.7Slukem     These variables only affect the top level ``Makefile'' and do not affect
3351.7Slukem     manually building subtrees of the NetBSD source code.
3361.1Stv
3371.20Slukem     INSTALLWORLDDIR  Location for the ``make installworld'' target to install
3381.20Slukem                      to.
3391.1Stv
3401.20Slukem                      Default: ``/''
3411.1Stv
3421.44Slukem     MKOBJDIRS        Can be set to ``yes'' or ``no''.  Indicates whether
3431.44Slukem                      object directories will be created automatically (via a
3441.20Slukem                      ``make obj'' pass) at the start of a build.
3451.1Stv
3461.34Slukem                      Default: ``no''
3471.1Stv
3481.38Slukem     MKUPDATE         Can be set to ``yes'' or ``no''.  If set, then in addi-
3491.38Slukem                      tion to the effects described for MKUPDATE=yes above,
3501.38Slukem                      this implies the effects of NOCLEANDIR (i.e., ``make
3511.38Slukem                      cleandir'' is avoided).
3521.38Slukem
3531.38Slukem                      Default: ``no''
3541.38Slukem
3551.20Slukem     NBUILDJOBS       Now obsolete.  Use the make(1) option -j, instead (see
3561.20Slukem                      below)
3571.1Stv
3581.20Slukem                      Default: Unset.
3591.1Stv
3601.20Slukem     NOCLEANDIR       If set, avoids the ``make cleandir'' phase of a full
3611.20Slukem                      build.  This has the effect of allowing only changed
3621.20Slukem                      files in a source tree to be recompiled.  This can speed
3631.20Slukem                      up builds when updating only a few files in the tree.
3641.1Stv
3651.20Slukem                      Default: Unset.
3661.1Stv
3671.20Slukem     NODISTRIBDIRS    If set, avoids the ``make distrib-dirs'' phase of a full
3681.20Slukem                      build.  This skips running mtree(8) on DESTDIR, useful
3691.20Slukem                      on systems where building as an unprivileged user, or
3701.20Slukem                      where it is known that the system-wide mtree files have
3711.20Slukem                      not changed.
3721.1Stv
3731.20Slukem                      Default: Unset.
3741.1Stv
3751.20Slukem     NOINCLUDES       If set, avoids the ``make includes'' phase of a full
3761.20Slukem                      build.  This has the effect of preventing make(1) from
3771.44Slukem                      thinking that some programs are out-of-date simply
3781.44Slukem                      because the system include files have changed.  However,
3791.20Slukem                      this option should not be used when updating the entire
3801.20Slukem                      NetBSD source tree arbitrarily; it is suggested to use
3811.38Slukem                      MKUPDATE=yes in that case.
3821.1Stv
3831.20Slukem                      Default: Unset.
3841.1Stv
3851.20Slukem     RELEASEDIR       If set, specifies the directory to which a release(7)
3861.20Slukem                      layout will be written at the end of a ``make release''.
3871.20Slukem
3881.20Slukem                      Default: Unset.
3891.20Slukem
3901.30Slukem                      Note: build.sh will provide a default of releasedir (in
3911.30Slukem                      the top-level .OBJDIR) unless run in `expert' mode
3921.30Slukem
3931.1StvBUILDING
3941.1Stv   "make" command line options
3951.52Sjmc     This is not a summary of all the options available to make(1); only the
3961.52Sjmc     options used most frequently with NetBSD builds are listed here.
3971.1Stv
3981.10Ssommerfe     -j njob    Run up to njob make(1) subjobs in parallel.  Makefiles should
3991.52Sjmc                use .WAIT or have explicit dependencies as necessary to
4001.44Slukem                enforce build ordering.  If you see build failures with -j,
4011.10Ssommerfe                please save complete build logs so the failures can be ana-
4021.10Ssommerfe                lyzed.
4031.10Ssommerfe
4041.1Stv     -m dir     Specify the default directory for searching for system Make-
4051.1Stv                file segments, mainly the <bsd.*.mk> files.  When building any
4061.1Stv                full NetBSD source tree, this should be set to the
4071.1Stv                ``share/mk'' directory in the source tree.  (This is set auto-
4081.1Stv                matically when building from the top level.)
4091.1Stv
4101.1Stv     -n         Display the commands that would have been executed, but do not
4111.1Stv                actually execute them.  This will still cause recursion to
4121.1Stv                take place.
4131.1Stv
4141.47Szuntum     -V var     Print make(1)'s idea of the value of var.  Does not build any
4151.1Stv                targets.
4161.1Stv
4171.1Stv     var=value  Set the variable var to value, overriding any setting speci-
4181.1Stv                fied by the process environment, the MAKECONF configuration
4191.1Stv                file, or the system Makefile segments.
4201.1Stv
4211.1Stv   "make" targets
4221.1Stv     These default targets may be built by running make(1) in any subtree of
4231.1Stv     the NetBSD source code.  It is recommended that none of these be used
4241.1Stv     from the top level Makefile; as a specific exception, ``make obj'' and
4251.1Stv     ``make cleandir'' are useful in that context.
4261.1Stv
4271.1Stv     all        Build programs, libraries, and preformatted documentation.
4281.1Stv
4291.1Stv     clean      Remove program and library object code files.
4301.1Stv
4311.44Slukem     cleandir   Same as clean, but also remove preformatted documentation,
4321.44Slukem                dependency files generated by ``make depend'', and any other
4331.49Slukem                files known to be created at build time.
4341.1Stv
4351.44Slukem     depend     Create dependency files (.depend) containing more detailed
4361.44Slukem                information about the dependencies of source code on header
4371.1Stv                files.  Allows programs to be recompiled automatically when a
4381.1Stv                dependency changes.
4391.1Stv
4401.1Stv     dependall  Does a ``make depend'' immediately followed by a ``make all''.
4411.10Ssommerfe                This improves cache locality of the build since both passes
4421.10Ssommerfe                read the source files in their entirety.
4431.1Stv
4441.49Slukem     distclean  Synonym for cleandir.
4451.49Slukem
4461.44Slukem     includes   Build and install system header files.  Typically needed
4471.44Slukem                before any system libraries or programs can be built.
4481.1Stv
4491.1Stv     install    Install programs, libraries, and documentation into DESTDIR.
4501.27Slukem                Few files will be installed to DESTDIR/dev, DESTDIR/etc,
4511.27Slukem                DESTDIR/root or DESTDIR/var in order to prevent user supplied
4521.27Slukem                configuration data from being overwritten.
4531.1Stv
4541.1Stv     lint       Run lint(1) against the C source code, where appropriate, and
4551.1Stv                generate system-installed lint libraries.
4561.1Stv
4571.1Stv     obj        Create object directories to be used for built files, instead
4581.1Stv                of building directly in the source tree.
4591.1Stv
4601.1Stv     tags       Create ctags(1) searchable function lists usable by the ex(1)
4611.1Stv                and vi(1) text editors.
4621.1Stv
4631.1Stv   "make" targets for the top level
4641.1Stv     Additional make(1) targets are usable specifically from the top source
4651.1Stv     level to facilitate building the entire NetBSD source tree.
4661.1Stv
4671.20Slukem     build         Build the entire NetBSD system.  This orders portions of
4681.20Slukem                   the source tree such that prerequisites will be built in
4691.20Slukem                   the proper order.
4701.20Slukem
4711.20Slukem     distribution  Do a ``make build'', and then install a full distribution
4721.27Slukem                   into DESTDIR, including files in DESTDIR/dev, DESTDIR/etc,
4731.27Slukem                   DESTDIR/root and DESTDIR/var.
4741.20Slukem
4751.20Slukem     buildworld    As per ``make distribution'', except that it ensures that
4761.20Slukem                   DESTDIR is not the root directory.
4771.20Slukem
4781.20Slukem     installworld  Install the distribution from DESTDIR to INSTALLWORLDDIR
4791.20Slukem                   (which defaults to the root directory).  Ensures that
4801.52Sjmc                   INSTALLWORLDDIR is not the root directory if cross compil-
4811.20Slukem                   ing.
4821.20Slukem
4831.20Slukem                   Note: It is highly recommended that you upgrade your kernel
4841.20Slukem                   and reboot before performing this operation.
4851.20Slukem
4861.25Slukem     sets          Create distribution sets from DESTDIR into
4871.25Slukem                   RELEASEDIR/MACHINE/binary/sets.  Should be run after ``make
4881.25Slukem                   distribution'' (as ``make build'' does not install all of
4891.25Slukem                   the required files).
4901.25Slukem
4911.31Slukem     sourcesets    Create source sets of the source tree into
4921.31Slukem                   RELEASEDIR/source/sets.
4931.31Slukem
4941.54Sapb     syspkgs       Create syspkgs from DESTDIR into
4951.54Sapb                   RELEASEDIR/MACHINE/binary/syspkgs.  Should be run after
4961.54Sapb                   ``make distribution'' (as ``make build'' does not install
4971.54Sapb                   all of the required files).
4981.54Sapb
4991.44Slukem     release       Do a ``make distribution'', build kernels, distribution
5001.44Slukem                   media, and install sets (this as per ``make sets''), and
5011.44Slukem                   then package the system into a standard release layout as
5021.44Slukem                   described by release(7).  This requires that RELEASEDIR be
5031.25Slukem                   set (see above).
5041.1Stv
5051.56Sapb     iso-image     Create a CD-ROM image in
5061.56Sapb                   RELEASEDIR/MACHINE/installation/cdrom.  RELEASEDIR must
5071.56Sapb                   already have been populated by ``make release'' or equiva-
5081.56Sapb                   lent.  This requires the mkisofs(1) utility, which is not
5091.56Sapb                   part of NetBSD, but which can be installed from
5101.57Sapb                   pkgsrc/sysutils/cdrtools.
5111.56Sapb
5121.1Stv     regression-tests
5131.20Slukem                   Can only be run after building the regression tests in the
5141.20Slukem                   directory ``regress''.  Runs the compiled regression tests
5151.20Slukem                   on the local host.
5161.1Stv
5171.1Stv   The "build.sh" script
5181.1Stv     This script file is a Bourne shell script designed to build the entire
5191.1Stv     NetBSD system on any host with a Bourne shell in /bin/sh, including many
5201.1Stv     that are not POSIX compliant.  Note that if a host system's /bin/sh is
5211.1Stv     unusually old and broken, the Korn Shell (/bin/ksh), if available, may be
5221.1Stv     a usable alternative.
5231.1Stv
5241.1Stv     All cross-compile builds, and most native builds, of the entire system
5251.1Stv     should make use of build.sh rather than just running ``make''.  This way,
5261.1Stv     the make(1) program will be bootstrapped properly, in case the host sys-
5271.1Stv     tem has an older or incompatible ``make'' program.
5281.1Stv
5291.1Stv     When compiling the entire system via build.sh, many make(1) variables are
5301.1Stv     set for you in order to help encapsulate the build process.  In the list
5311.1Stv     of options below, variables that are automatically set by build.sh are
5321.1Stv     noted where applicable.
5331.1Stv
5341.22Slukem     The following operations are supported by build.sh:
5351.22Slukem
5361.44Slukem     build         Build the system as per ``make build''.  This option
5371.44Slukem                   implies the obj and tools operations.
5381.22Slukem
5391.22Slukem     distribution  Build a full distribution as per ``make distribution''.
5401.22Slukem                   This option implies the build operation.
5411.22Slukem
5421.22Slukem     release       Build a full release as per ``make release''.  This option
5431.22Slukem                   implies the distribution operation.
5441.22Slukem
5451.23Slukem     makewrapper   Create the nbmake-MACHINE wrapper.  This operation is auto-
5461.23Slukem                   matically performed for any of the other operations.
5471.23Slukem
5481.22Slukem     obj           Perform ``make obj''.
5491.22Slukem
5501.22Slukem     tools         Build and install the host tools from src/tools.
5511.22Slukem
5521.35Slukem     install=idir  Install the contents of DESTDIR to idir, using ``make
5531.35Slukem                   installworld''.
5541.35Slukem
5551.22Slukem     kernel=kconf  Build a new kernel.  The kconf argument is the name of a
5561.54Sapb                   configuration file suitable for use by config(1).  If kconf
5571.22Slukem                   does not contain any `/' characters, the configuration file
5581.22Slukem                   is expected to be found in the KERNCONFDIR directory, which
5591.22Slukem                   is typically sys/arch/MACHINE/conf.  The new kernel will be
5601.22Slukem                   built in a subdirectory of KERNOBJDIR, which is typically
5611.22Slukem                   sys/arch/MACHINE/compile or an associated object directory.
5621.22Slukem                   In order to ensure that the kernel is built using up-to-
5631.22Slukem                   date tools, it is strongly recommended that the tools be
5641.22Slukem                   rebuilt (using the tools operation).
5651.22Slukem
5661.35Slukem     releasekernel=kconf
5671.35Slukem                   Install a gzip(1)ed copy of the kernel built by
5681.35Slukem                   kernel=kconf into RELEASEDIR/MACHINE/binary/kernel, usually
5691.44Slukem                   as netbsd-kconf.gz, although the ``netbsd'' prefix is
5701.44Slukem                   determined from the ``config'' directives in kconf.
5711.24Slukem
5721.24Slukem     sets          Perform ``make sets''.
5731.31Slukem
5741.31Slukem     sourcesets    Perform ``make sourcesets''.
5751.22Slukem
5761.54Sapb     syspkgs       Perform ``make syspkgs''.
5771.54Sapb
5781.56Sapb     iso-image     Perform ``make iso-image''.
5791.56Sapb
5801.51Swiz     The following command line options alter the behaviour of the build.sh
5811.51Swiz     operations described above:
5821.1Stv
5831.1Stv     -a arch   Set the value of MACHINE_ARCH to arch.
5841.9Sthorpej
5851.9Sthorpej     -B buildid
5861.9Sthorpej               Set the value of BUILDID to buildid.  This will also append the
5871.9Sthorpej               build idenfitier to the name of the ``make'' wrapper script so
5881.37Slukem               that the resulting name is of the form
5891.37Slukem               ``nbmake-MACHINE-BUILDID''.
5901.1Stv
5911.18Slukem     -D dest   Set the value of DESTDIR to dest.
5921.18Slukem
5931.23Slukem     -E        Set `expert' mode.  This overrides various sanity checks, and
5941.23Slukem               allows: DESTDIR does not have to be set to a non-root path for
5951.38Slukem               builds, and MKUNPRIVED=yes does not have to be set when build-
5961.38Slukem               ing as a non-root user.
5971.23Slukem
5981.23Slukem               Note: It is highly recommended that you know what you are doing
5991.23Slukem               when you use this option.
6001.19Slukem
6011.51Swiz     -h        Print a help message.
6021.51Swiz
6031.10Ssommerfe     -j njob   Passed through to make(1).  Makefiles should use .WAIT or have
6041.10Ssommerfe               explicit dependancies as necessary to enforce build ordering.
6051.10Ssommerfe               If you see build failures with -j, please save complete build
6061.10Ssommerfe               logs so the failures can be analyzed.
6071.1Stv
6081.40Slukem     -M obj    Set MAKEOBJDIRPREFIX to obj.  Unsets MAKEOBJDIR.
6091.18Slukem
6101.1Stv     -m mach   Set the value of MACHINE to mach.  This will also override any
6111.1Stv               value of MACHINE_ARCH in the process environment with a value
6121.33Slukem               deduced from mach, unless -a is specified, or mach is a special
6131.33Slukem               case listed below.  All cross builds require -m, but if unset
6141.33Slukem               on a NetBSD host, the host's value of MACHINE will be detected
6151.33Slukem               and used automatically.
6161.33Slukem
6171.33Slukem               Some machines support multiple values for MACHINE_ARCH.  For a
6181.33Slukem               given value of mach, the following MACHINE and MACHINE_ARCH
6191.33Slukem               values will result:
6201.33Slukem
6211.33Slukem                     mach          MACHINE    MACHINE_ARCH
6221.33Slukem                     evbmips       evbmips    (not set)
6231.33Slukem                     evbmips-eb    evbmips    mipseb
6241.33Slukem                     evbmips-el    evbmips    mipsel
6251.33Slukem                     evbsh3        evbsh3     (not set)
6261.33Slukem                     evbsh3-eb     evbsh3     sh3eb
6271.33Slukem                     evbsh3-el     evbsh3     sh3el
6281.33Slukem                     sbmips        sbmips     (not set)
6291.33Slukem                     sbmips-eb     sbmips     mipseb
6301.33Slukem                     sbmips-el     sbmips     mipsel
6311.1Stv
6321.45Slukem     -N noiselevel
6331.46Slukem               Set the ``noisyness'' level of the build, by setting
6341.46Slukem               MAKEVERBOSE to noiselevel.
6351.45Slukem
6361.1Stv     -n        Show the commands that would be executed by build.sh, but do
6371.1Stv               not make any changes.  This is similar in concept to ``make
6381.1Stv               -n''.
6391.1Stv
6401.18Slukem     -O obj    Create an appropriate transform macro for MAKEOBJDIR that will
6411.18Slukem               place the built object files under obj.  For instance, a set-
6421.18Slukem               ting of /usr/obj will place build-time files under
6431.40Slukem               /usr/obj/bin, /usr/obj/lib, /usr/obj/usr.bin, and so forth.
6441.40Slukem               Unsets MAKEOBJDIRPREFIX.
6451.18Slukem
6461.34Slukem     -o        Set the value of MKOBJDIRS to ``no''.  Otherwise, it will be
6471.34Slukem               automatically set to ``yes'' (which is opposite to the default
6481.34Slukem               behaviour).
6491.1Stv
6501.22Slukem     -R rel    Set the value of RELEASEDIR to rel.
6511.18Slukem
6521.1Stv     -r        Remove the contents of DESTDIR and TOOLDIR before building
6531.1Stv               (provides a clean starting point).  This will skip deleting
6541.1Stv               DESTDIR if building on a native system to the root directory.
6551.1Stv
6561.18Slukem     -T tools  Set the value of TOOLDIR to tools.  If set, the bootstrap
6571.18Slukem               ``make'' will only be rebuilt as needed (when the source files
6581.18Slukem               for make(1) change).
6591.18Slukem
6601.38Slukem     -U        Set MKUNPRIVED=yes.
6611.18Slukem
6621.38Slukem     -u        Set MKUPDATE=yes.
6631.1Stv
6641.21Slukem     -V var=[value]
6651.40Slukem               Set the environment variable var to an optional value.  This is
6661.40Slukem               propagated to the nbmake wrapper.
6671.21Slukem
6681.1Stv     -w wrapper
6691.1Stv               Create the nbmake wrapper script (see below) in a custom loca-
6701.1Stv               tion, specified by wrapper.  This allows, for instance, to
6711.1Stv               place the wrapper in PATH automatically.  Note that wrapper is
6721.1Stv               the full name of the file, not just a directory name.
6731.1Stv
6741.49Slukem     -X x11src
6751.49Slukem               Set the value of X11SRCDIR to x11src.
6761.49Slukem
6771.49Slukem     -x        Set MKX11=yes.
6781.49Slukem
6791.40Slukem     -Z var    Unset ("zap") the environment variable var.  This is propagated
6801.40Slukem               to the nbmake wrapper.
6811.40Slukem
6821.1Stv   The "nbmake-MACHINE" wrapper script
6831.1Stv     If using the build.sh script to build NetBSD, a nbmake-MACHINE script
6841.1Stv     will be created in TOOLDIR/bin upon the first build to assist in building
6851.1Stv     subtrees on a cross-compile host.
6861.1Stv
6871.1Stv     nbmake-MACHINE can be invoked in lieu of make(1), and will instead call
6881.1Stv     the up-to-date version of ``nbmake'' installed into TOOLDIR/bin with sev-
6891.1Stv     eral key variables pre-set, including MACHINE, MACHINE_ARCH, and TOOLDIR.
6901.40Slukem     build.sh will also set variables specified with -V, and unset variables
6911.40Slukem     specified with -Z.
6921.40Slukem
6931.1Stv     This script can be symlinked into a directory listed in PATH, or called
6941.1Stv     with an absolute path.
6951.1Stv
6961.16SlukemEXAMPLES
6971.44Slukem     1.   % ./build.sh tools kernel=GENERIC
6981.28Slukem
6991.28Slukem          Build a new toolchain, and use the new toolchain to configure and
7001.28Slukem          build a new GENERIC kernel.
7011.28Slukem
7021.44Slukem     2.   % ./build.sh -U distribution
7031.28Slukem
7041.30Slukem          Using unprivileged mode, build a complete distribution to a DESTDIR
7051.30Slukem          directory that build.sh selects (and will display).
7061.28Slukem
7071.43Smartti     3.   # ./build.sh -U install=/
7081.28Slukem
7091.29Slukem          As root, install to / the distribution that was built by example 2.
7101.29Slukem          Even though this is run as root, -U is required so that the permis-
7111.30Slukem          sions stored in DESTDIR/METALOG are correctly applied to the files
7121.30Slukem          as they're copied to /.
7131.28Slukem
7141.44Slukem     4.   % ./build.sh -U -u release
7151.28Slukem
7161.30Slukem          Using unprivileged mode, build a complete release to DESTDIR and
7171.30Slukem          RELEASEDIR directories that build.sh selects (and will display).
7181.38Slukem          MKUPDATE=yes (-u) is set to prevent the ``make cleandir'', so that
7191.38Slukem          if this is run after example 2, it doesn't need to redo that portion
7201.38Slukem          of the release build.
7211.16Slukem
7221.10SsommerfeOBSOLETE VARIABLES
7231.15Slukem     NBUILDJOBS  Use the make(1) option -j, instead.
7241.15Slukem
7251.15Slukem     USE_NEW_TOOLCHAIN
7261.15Slukem                 The new toolchain is now the default.  To disable, use
7271.15Slukem                 TOOLCHAIN_MISSING=yes.
7281.10Ssommerfe
7291.1StvSEE ALSO
7301.57Sapb     make(1), hier(7), release(7), pkgsrc/sysutils/cdrtools
7311.1Stv
7321.1StvHISTORY
7331.15Slukem     The build.sh based build scheme was introduced for NetBSD 1.6 as
7341.15Slukem     USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that.
7351.1Stv
7361.1StvBUGS
7371.15Slukem     A few platforms are not yet using this build system.
7381.1Stv
7391.55SwizNetBSD                          January 4, 2006                         NetBSD
740