BUILDING revision 1.50
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.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.1Stv     the NetBSD build process.
321.1Stv
331.1StvFILES
341.1Stv   Source tree layout
351.17Swiz     doc/BUILDING.mdoc
361.17Swiz                    This document (in -mdoc troff format; the original copy).
371.1Stv
381.2Swiz     BUILDING       This document (in plaintext).
391.1Stv
401.48Sjmc     tools/compat/README
411.48Sjmc                    Special notes for cross-hosting a NetBSD build on non-
421.48Sjmc                    NetBSD platforms.
431.48Sjmc
441.44Slukem     Makefile       The main Makefile for NetBSD; should only be run for
451.44Slukem                    native builds with an appropriately up-to-date version of
461.1Stv                    NetBSD make(1).  (For building from out-of-date systems or
471.1Stv                    on a non-native host, see the build.sh shell script.)
481.1Stv
491.1Stv     UPDATING       Special notes for updating from an earlier revision of
501.1Stv                    NetBSD.  It is important to read this file before every
511.1Stv                    build of an updated source tree.
521.1Stv
531.1Stv     build.sh       Bourne-compatible shell script used for building the host
541.1Stv                    build tools and the NetBSD system from scratch.  Can be
551.1Stv                    used for both native and cross builds, and should be used
561.1Stv                    instead of make(1) for any source tree that is updated and
571.1Stv                    recompiled regularly.
581.1Stv
591.1Stv     crypto/dist/, dist/, gnu/dist/
601.1Stv                    Sources imported verbatim from third parties, without man-
611.1Stv                    gling the existing build structure.  Other source trees in
621.1Stv                    bin through usr.sbin use the NetBSD make(1) ``reachover''
631.44Slukem                    Makefile semantics when building these programs for a
641.44Slukem                    native host.
651.1Stv
661.1Stv     distrib/, etc/
671.1Stv                    Sources for items used when making a full release snap-
681.27Slukem                    shot, such as files installed in DESTDIR/etc on the desti-
691.27Slukem                    nation system, boot media, and release notes.
701.1Stv
711.1Stv     regress/       Regression test harness.  Can be cross-compiled, but only
721.1Stv                    run natively.
731.1Stv
741.1Stv     sys/           NetBSD kernel sources.
751.1Stv
761.1Stv     tools/         ``Reachover'' build structure for the host build tools.
771.1Stv                    This has a special method of determining out-of-date sta-
781.1Stv                    tus.
791.1Stv
801.1Stv     bin/ ... usr.sbin/
811.1Stv                    Sources to the NetBSD userland (non-kernel) programs.  If
821.1Stv                    any of these directories are missing, they will be skipped
831.1Stv                    during the build.
841.1Stv
851.49Slukem     x11/           ``Reachover'' build structure for X11R6; the source is in
861.49Slukem                    X11SRCDIR.
871.49Slukem
881.1Stv   Build tree layout
891.1Stv     The NetBSD build tree is described in hier(7), and the release layout is
901.1Stv     described in release(7).
911.1Stv
921.1StvCONFIGURATION
931.8Slukem   Environment variables
941.8Slukem     Several environment variables control the behaviour of NetBSD builds.
951.8Slukem
961.8Slukem     MACHINE           Machine type.
971.8Slukem
981.8Slukem     MACHINE_ARCH      Machine architecture.
991.8Slukem
1001.8Slukem     MAKE              Path name to invoke make(1) as.
1011.8Slukem
1021.8Slukem     MAKEFLAGS         Flags to invoke make(1) with.
1031.8Slukem
1041.8Slukem     MAKEOBJDIR        Directory to use as the .OBJDIR for the current direc-
1051.8Slukem                       tory.  Used only if MAKEOBJDIRPREFIX is not defined.
1061.36Slukem                       MAKEOBJDIR can only be provided in the environment or
1071.41Slukem                       via the -O flag of build.sh.
1081.8Slukem
1091.8Slukem     MAKEOBJDIRPREFIX  Top level directory of the object directory tree.  If
1101.8Slukem                       this is defined, ${MAKEOBJDIRPREFIX}/${.CURDIR} is used
1111.8Slukem                       as the .OBJDIR for the current directory.  The current
1121.8Slukem                       directory may be read only.  MAKEOBJDIRPREFIX can only
1131.36Slukem                       be provided in the environment or via the -M flag of
1141.36Slukem                       build.sh.
1151.8Slukem
1161.1Stv   "make" variables
1171.1Stv     Several variables control the behavior of NetBSD builds.  Unless other-
1181.1Stv     wise specified, these variables may be set in either the process environ-
1191.1Stv     ment or the make(1) configuration file specified by MAKECONF.
1201.1Stv
1211.9Sthorpej     BUILDID     Identifier for the build.  The identifier will be appended to
1221.9Sthorpej                 object directory names, and can be consulted in the make(1)
1231.9Sthorpej                 configuration file in order to set additional build parame-
1241.9Sthorpej                 ters, such as compiler flags.
1251.9Sthorpej
1261.1Stv     DESTDIR     Directory to contain the built NetBSD system.  If set, spe-
1271.1Stv                 cial options are passed to the compilation tools to prevent
1281.1Stv                 their default use of the host system's /usr/include,
1291.1Stv                 /usr/lib, and so forth.  This pathname should not end with a
1301.1Stv                 slash (/) character (for installation into the system's root
1311.7Slukem                 directory, set DESTDIR to an empty string).  The directory
1321.7Slukem                 must reside on a file system which supports long file names
1331.7Slukem                 and hard links.
1341.1Stv
1351.1Stv                 Default: Empty string if USETOOLS is ``yes''; unset other-
1361.1Stv                 wise.
1371.1Stv
1381.30Slukem                 Note: build.sh will provide a default of destdir.MACHINE (in
1391.30Slukem                 the top-level .OBJDIR) unless run in `expert' mode
1401.30Slukem
1411.1Stv     MAKECONF    The name of the make(1) configuration file.  Only settable in
1421.1Stv                 the process environment.
1431.1Stv
1441.1Stv                 Default: ``/etc/mk.conf''
1451.1Stv
1461.45Slukem     MAKEVERBOSE
1471.45Slukem                 Level of verbosity of status messages.  Supported values:
1481.45Slukem
1491.45Slukem                 0    No descriptive messages are shown.
1501.45Slukem
1511.45Slukem                 1    Descriptive messages are shown.
1521.45Slukem
1531.45Slukem                 2    Descriptive messages (prefixed with a `#') and command
1541.45Slukem                      output is not suppressed.
1551.45Slukem
1561.45Slukem                 Default: 2
1571.45Slukem
1581.1Stv     MKCATPAGES  Can be set to ``yes'' or ``no''.  Indicates whether prefor-
1591.1Stv                 matted plaintext manual pages will be created during a build.
1601.1Stv
1611.1Stv                 Default: ``yes''
1621.1Stv
1631.1Stv     MKCRYPTO    Can be set to ``yes'' or ``no''.  Indicates whether crypto-
1641.1Stv                 graphic code will be included in a build; provided for the
1651.1Stv                 benefit of countries that do not allow strong cryptography.
1661.44Slukem                 Will not affect use of the standard low-security password
1671.44Slukem                 encryption system, crypt(3).
1681.1Stv
1691.1Stv                 Default: ``yes''
1701.1Stv
1711.1Stv     MKDOC       Can be set to ``yes'' or ``no''.  Indicates whether system
1721.44Slukem                 documentation destined for DESTDIR/usr/share/doc will be
1731.44Slukem                 installed during a build.
1741.1Stv
1751.1Stv                 Default: ``yes''
1761.1Stv
1771.4Stv     MKHOSTOBJ   Can be set to ``yes'' or ``no''.  If set to ``yes'', then for
1781.4Stv                 programs intended to be run on the compile host, the name,
1791.4Stv                 release, and architecture of the host operating system will
1801.4Stv                 be suffixed to the name of the object directory created by
1811.4Stv                 ``make obj''.  (This allows multiple host systems to compile
1821.4Stv                 NetBSD for a single target.)  If set to ``no'', then programs
1831.4Stv                 built to be run on the compile host will use the same object
1841.4Stv                 directory names as programs built to be run on the target.
1851.4Stv
1861.4Stv                 Default: ``no''
1871.4Stv
1881.1Stv     MKINFO      Can be set to ``yes'' or ``no''.  Indicates whether GNU Info
1891.1Stv                 files, used for the documentation for most of the compilation
1901.1Stv                 tools, will be created and installed during a build.
1911.1Stv
1921.1Stv                 Default: ``yes''
1931.1Stv
1941.1Stv     MKLINT      Can be set to ``yes'' or ``no''.  Indicates whether lint(1)
1951.1Stv                 will be run against portions of the NetBSD source code during
1961.1Stv                 the build, and whether lint libraries will be installed into
1971.27Slukem                 DESTDIR/usr/libdata/lint.
1981.1Stv
1991.1Stv                 Default: ``yes''
2001.1Stv
2011.1Stv     MKMAN       Can be set to ``yes'' or ``no''.  Indicates whether manual
2021.1Stv                 pages will be installed during a build.
2031.1Stv
2041.1Stv                 Default: ``yes''
2051.1Stv
2061.1Stv     MKNLS       Can be set to ``yes'' or ``no''.  Indicates whether Native
2071.44Slukem                 Language System locale zone files will be compiled and
2081.44Slukem                 installed during a build.
2091.1Stv
2101.1Stv                 Default: ``yes''
2111.1Stv
2121.1Stv     MKOBJ       Can be set to ``yes'' or ``no''.  Indicates whether object
2131.1Stv                 directories will be created when running ``make obj''.  If
2141.1Stv                 set to ``no'', then all built files will be located inside
2151.1Stv                 the regular source tree.
2161.1Stv
2171.1Stv                 Default: ``yes''
2181.1Stv
2191.1Stv     MKPIC       Can be set to ``yes'' or ``no''.  Indicates whether shared
2201.1Stv                 objects and libraries will be created and installed during a
2211.1Stv                 build.  If set to ``no'', the entire built system will be
2221.1Stv                 statically linked.
2231.1Stv
2241.1Stv                 Default: Platform dependent.  As of this writing, all plat-
2251.1Stv                 forms except sh3 default to ``yes''.
2261.1Stv
2271.1Stv     MKPICINSTALL
2281.1Stv                 Can be set to ``yes'' or ``no''.  Indicates whether the ar(1)
2291.44Slukem                 format libraries (lib*_pic.a), used to generate shared
2301.44Slukem                 libraries, are installed during a build.
2311.1Stv
2321.1Stv                 Default: ``yes''
2331.1Stv
2341.1Stv     MKPROFILE   Can be set to ``yes'' or ``no''.  Indicates whether profiled
2351.1Stv                 libraries (lib*_p.a) will be built and installed during a
2361.1Stv                 build.
2371.1Stv
2381.1Stv                 Default: ``yes''; however, some platforms turn off MKPROFILE
2391.1Stv                 by default at times due to toolchain problems with profiled
2401.1Stv                 code.
2411.1Stv
2421.1Stv     MKSHARE     Can be set to ``yes'' or ``no''.  Indicates whether files
2431.44Slukem                 destined to reside in DESTDIR/usr/share will be built and
2441.44Slukem                 installed during a build.  If set to ``no'', then all of
2451.27Slukem                 MKCATPAGES, MKDOC, MKINFO, MKMAN, and MKNLS will be set to
2461.27Slukem                 ``no'' unconditionally.
2471.1Stv
2481.1Stv                 Default: ``yes''
2491.1Stv
2501.50Swiz     MKTTINTERP  Can be set to ``yes'' or ``no''.  For X builds, decides if
2511.50Swiz                 the TrueType bytecode interpreter is turned on.  See
2521.50Swiz                 http://www.freetype.org/patents.html for details.
2531.50Swiz
2541.50Swiz                 Default: ``no''
2551.50Swiz
2561.44Slukem     MKUNPRIVED  Can be set to ``yes'' or ``no''.  Indicates whether an
2571.44Slukem                 unprivileged install will occur.  The user, group, permis-
2581.44Slukem                 sions, and file flags, will not be set on the installed item;
2591.44Slukem                 instead the information will be appended to a file called
2601.38Slukem                 METALOG in DESTDIR.  The contents of METALOG is used during
2611.38Slukem                 the generation of the distribution tar files to ensure that
2621.38Slukem                 the appropriate file ownership is stored.
2631.38Slukem
2641.38Slukem                 Default: ``no''
2651.38Slukem
2661.44Slukem     MKUPDATE    Can be set to ``yes'' or ``no''.  Indicates whether all
2671.44Slukem                 install operations intended to write to DESTDIR will compare
2681.38Slukem                 file timestamps before installing, and skip the install phase
2691.44Slukem                 if the destination files are up-to-date.  This also has
2701.44Slukem                 implications on full builds (see next subsection).
2711.38Slukem
2721.38Slukem                 Default: ``no''
2731.38Slukem
2741.49Slukem     MKX11       Can be set to ``yes'' or ``no''.  Indicates whether X11R6 is
2751.49Slukem                 built from X11SRCDIR.
2761.49Slukem
2771.49Slukem                 Default: ``no''
2781.49Slukem
2791.1Stv     TOOLDIR     Directory to hold the host tools, once built.  This directory
2801.1Stv                 should be unique to a given host system and NetBSD source
2811.1Stv                 tree.  (However, multiple targets may share the same TOOLDIR;
2821.1Stv                 the target-dependent files have unique names.)  If unset, a
2831.1Stv                 default based on the uname(1) information of the host plat-
2841.39Slukem                 form will be created in the .OBJDIR of src.
2851.1Stv
2861.1Stv                 Default: Unset.
2871.1Stv
2881.1Stv     USETOOLS    Indicates whether the tools specified by TOOLDIR should be
2891.1Stv                 used as part of a build in progress.  Must be set to ``yes''
2901.1Stv                 if cross-compiling.
2911.1Stv
2921.1Stv                 yes    Use the tools from TOOLDIR.
2931.1Stv
2941.1Stv                 no     Do not use the tools from TOOLDIR, but refuse to build
2951.1Stv                        native compilation tool components that are version-
2961.1Stv                        specific for that tool.
2971.1Stv
2981.1Stv                 never  Do not use the tools from TOOLDIR, even when building
2991.1Stv                        native tool components.  This is similar to the tradi-
3001.1Stv                        tional NetBSD build method, but does not verify that
3011.1Stv                        the compilation tools in use are up-to-date enough in
3021.1Stv                        order to build the tree successfully.  This may cause
3031.1Stv                        build or runtime problems when building the whole
3041.1Stv                        NetBSD source tree.
3051.1Stv
3061.1Stv                 Default: ``yes'' if building all or part of a whole NetBSD
3071.1Stv                 source tree (detected automatically); ``no'' otherwise (to
3081.44Slukem                 preserve traditional semantics of the <bsd.*.mk> make(1)
3091.44Slukem                 include files).
3101.1Stv
3111.49Slukem     X11SRCDIR   Directory containing the X11R6 source.  The main X11R6 source
3121.49Slukem                 is found in X11SRCDIR/xfree/xc.
3131.49Slukem
3141.49Slukem                 Default: ``/usr/xsrc''
3151.49Slukem
3161.1Stv   "make" variables for full builds
3171.7Slukem     These variables only affect the top level ``Makefile'' and do not affect
3181.7Slukem     manually building subtrees of the NetBSD source code.
3191.1Stv
3201.20Slukem     INSTALLWORLDDIR  Location for the ``make installworld'' target to install
3211.20Slukem                      to.
3221.1Stv
3231.20Slukem                      Default: ``/''
3241.1Stv
3251.44Slukem     MKOBJDIRS        Can be set to ``yes'' or ``no''.  Indicates whether
3261.44Slukem                      object directories will be created automatically (via a
3271.20Slukem                      ``make obj'' pass) at the start of a build.
3281.1Stv
3291.34Slukem                      Default: ``no''
3301.1Stv
3311.38Slukem     MKUPDATE         Can be set to ``yes'' or ``no''.  If set, then in addi-
3321.38Slukem                      tion to the effects described for MKUPDATE=yes above,
3331.38Slukem                      this implies the effects of NOCLEANDIR (i.e., ``make
3341.38Slukem                      cleandir'' is avoided).
3351.38Slukem
3361.38Slukem                      Default: ``no''
3371.38Slukem
3381.20Slukem     NBUILDJOBS       Now obsolete.  Use the make(1) option -j, instead (see
3391.20Slukem                      below)
3401.1Stv
3411.20Slukem                      Default: Unset.
3421.1Stv
3431.20Slukem     NOCLEANDIR       If set, avoids the ``make cleandir'' phase of a full
3441.20Slukem                      build.  This has the effect of allowing only changed
3451.20Slukem                      files in a source tree to be recompiled.  This can speed
3461.20Slukem                      up builds when updating only a few files in the tree.
3471.1Stv
3481.20Slukem                      Default: Unset.
3491.1Stv
3501.20Slukem     NODISTRIBDIRS    If set, avoids the ``make distrib-dirs'' phase of a full
3511.20Slukem                      build.  This skips running mtree(8) on DESTDIR, useful
3521.20Slukem                      on systems where building as an unprivileged user, or
3531.20Slukem                      where it is known that the system-wide mtree files have
3541.20Slukem                      not changed.
3551.1Stv
3561.20Slukem                      Default: Unset.
3571.1Stv
3581.20Slukem     NOINCLUDES       If set, avoids the ``make includes'' phase of a full
3591.20Slukem                      build.  This has the effect of preventing make(1) from
3601.44Slukem                      thinking that some programs are out-of-date simply
3611.44Slukem                      because the system include files have changed.  However,
3621.20Slukem                      this option should not be used when updating the entire
3631.20Slukem                      NetBSD source tree arbitrarily; it is suggested to use
3641.38Slukem                      MKUPDATE=yes in that case.
3651.1Stv
3661.20Slukem                      Default: Unset.
3671.1Stv
3681.20Slukem     RELEASEDIR       If set, specifies the directory to which a release(7)
3691.20Slukem                      layout will be written at the end of a ``make release''.
3701.20Slukem
3711.20Slukem                      Default: Unset.
3721.20Slukem
3731.30Slukem                      Note: build.sh will provide a default of releasedir (in
3741.30Slukem                      the top-level .OBJDIR) unless run in `expert' mode
3751.30Slukem
3761.1StvBUILDING
3771.1Stv   "make" command line options
3781.1Stv     This is only a summary of options available to make(1); only the options
3791.1Stv     used most frequently with NetBSD builds are listed here.
3801.1Stv
3811.10Ssommerfe     -j njob    Run up to njob make(1) subjobs in parallel.  Makefiles should
3821.44Slukem                use .WAIT or have explicit dependancies as necessary to
3831.44Slukem                enforce build ordering.  If you see build failures with -j,
3841.10Ssommerfe                please save complete build logs so the failures can be ana-
3851.10Ssommerfe                lyzed.
3861.10Ssommerfe
3871.1Stv     -m dir     Specify the default directory for searching for system Make-
3881.1Stv                file segments, mainly the <bsd.*.mk> files.  When building any
3891.1Stv                full NetBSD source tree, this should be set to the
3901.1Stv                ``share/mk'' directory in the source tree.  (This is set auto-
3911.1Stv                matically when building from the top level.)
3921.1Stv
3931.1Stv     -n         Display the commands that would have been executed, but do not
3941.1Stv                actually execute them.  This will still cause recursion to
3951.1Stv                take place.
3961.1Stv
3971.47Szuntum     -V var     Print make(1)'s idea of the value of var.  Does not build any
3981.1Stv                targets.
3991.1Stv
4001.1Stv     var=value  Set the variable var to value, overriding any setting speci-
4011.1Stv                fied by the process environment, the MAKECONF configuration
4021.1Stv                file, or the system Makefile segments.
4031.1Stv
4041.1Stv   "make" targets
4051.1Stv     These default targets may be built by running make(1) in any subtree of
4061.1Stv     the NetBSD source code.  It is recommended that none of these be used
4071.1Stv     from the top level Makefile; as a specific exception, ``make obj'' and
4081.1Stv     ``make cleandir'' are useful in that context.
4091.1Stv
4101.1Stv     all        Build programs, libraries, and preformatted documentation.
4111.1Stv
4121.1Stv     clean      Remove program and library object code files.
4131.1Stv
4141.44Slukem     cleandir   Same as clean, but also remove preformatted documentation,
4151.44Slukem                dependency files generated by ``make depend'', and any other
4161.49Slukem                files known to be created at build time.
4171.1Stv
4181.44Slukem     depend     Create dependency files (.depend) containing more detailed
4191.44Slukem                information about the dependencies of source code on header
4201.1Stv                files.  Allows programs to be recompiled automatically when a
4211.1Stv                dependency changes.
4221.1Stv
4231.1Stv     dependall  Does a ``make depend'' immediately followed by a ``make all''.
4241.10Ssommerfe                This improves cache locality of the build since both passes
4251.10Ssommerfe                read the source files in their entirety.
4261.1Stv
4271.49Slukem     distclean  Synonym for cleandir.
4281.49Slukem
4291.44Slukem     includes   Build and install system header files.  Typically needed
4301.44Slukem                before any system libraries or programs can be built.
4311.1Stv
4321.1Stv     install    Install programs, libraries, and documentation into DESTDIR.
4331.27Slukem                Few files will be installed to DESTDIR/dev, DESTDIR/etc,
4341.27Slukem                DESTDIR/root or DESTDIR/var in order to prevent user supplied
4351.27Slukem                configuration data from being overwritten.
4361.1Stv
4371.1Stv     lint       Run lint(1) against the C source code, where appropriate, and
4381.1Stv                generate system-installed lint libraries.
4391.1Stv
4401.1Stv     obj        Create object directories to be used for built files, instead
4411.1Stv                of building directly in the source tree.
4421.1Stv
4431.1Stv     tags       Create ctags(1) searchable function lists usable by the ex(1)
4441.1Stv                and vi(1) text editors.
4451.1Stv
4461.1Stv   "make" targets for the top level
4471.1Stv     Additional make(1) targets are usable specifically from the top source
4481.1Stv     level to facilitate building the entire NetBSD source tree.
4491.1Stv
4501.20Slukem     build         Build the entire NetBSD system.  This orders portions of
4511.20Slukem                   the source tree such that prerequisites will be built in
4521.20Slukem                   the proper order.
4531.20Slukem
4541.20Slukem     distribution  Do a ``make build'', and then install a full distribution
4551.27Slukem                   into DESTDIR, including files in DESTDIR/dev, DESTDIR/etc,
4561.27Slukem                   DESTDIR/root and DESTDIR/var.
4571.20Slukem
4581.20Slukem     buildworld    As per ``make distribution'', except that it ensures that
4591.20Slukem                   DESTDIR is not the root directory.
4601.20Slukem
4611.20Slukem     installworld  Install the distribution from DESTDIR to INSTALLWORLDDIR
4621.20Slukem                   (which defaults to the root directory).  Ensures that
4631.20Slukem                   INSTALLWORLDDIR is the not root directory if cross compil-
4641.20Slukem                   ing.
4651.20Slukem
4661.20Slukem                   Note: It is highly recommended that you upgrade your kernel
4671.20Slukem                   and reboot before performing this operation.
4681.20Slukem
4691.25Slukem     sets          Create distribution sets from DESTDIR into
4701.25Slukem                   RELEASEDIR/MACHINE/binary/sets.  Should be run after ``make
4711.25Slukem                   distribution'' (as ``make build'' does not install all of
4721.25Slukem                   the required files).
4731.25Slukem
4741.31Slukem     sourcesets    Create source sets of the source tree into
4751.31Slukem                   RELEASEDIR/source/sets.
4761.31Slukem
4771.44Slukem     release       Do a ``make distribution'', build kernels, distribution
4781.44Slukem                   media, and install sets (this as per ``make sets''), and
4791.44Slukem                   then package the system into a standard release layout as
4801.44Slukem                   described by release(7).  This requires that RELEASEDIR be
4811.25Slukem                   set (see above).
4821.1Stv
4831.1Stv     regression-tests
4841.20Slukem                   Can only be run after building the regression tests in the
4851.20Slukem                   directory ``regress''.  Runs the compiled regression tests
4861.20Slukem                   on the local host.
4871.1Stv
4881.1Stv   The "build.sh" script
4891.1Stv     This script file is a Bourne shell script designed to build the entire
4901.1Stv     NetBSD system on any host with a Bourne shell in /bin/sh, including many
4911.1Stv     that are not POSIX compliant.  Note that if a host system's /bin/sh is
4921.1Stv     unusually old and broken, the Korn Shell (/bin/ksh), if available, may be
4931.1Stv     a usable alternative.
4941.1Stv
4951.1Stv     All cross-compile builds, and most native builds, of the entire system
4961.1Stv     should make use of build.sh rather than just running ``make''.  This way,
4971.1Stv     the make(1) program will be bootstrapped properly, in case the host sys-
4981.1Stv     tem has an older or incompatible ``make'' program.
4991.1Stv
5001.1Stv     When compiling the entire system via build.sh, many make(1) variables are
5011.1Stv     set for you in order to help encapsulate the build process.  In the list
5021.1Stv     of options below, variables that are automatically set by build.sh are
5031.1Stv     noted where applicable.
5041.1Stv
5051.22Slukem     The following operations are supported by build.sh:
5061.22Slukem
5071.44Slukem     build         Build the system as per ``make build''.  This option
5081.44Slukem                   implies the obj and tools operations.
5091.22Slukem
5101.22Slukem     distribution  Build a full distribution as per ``make distribution''.
5111.22Slukem                   This option implies the build operation.
5121.22Slukem
5131.22Slukem     release       Build a full release as per ``make release''.  This option
5141.22Slukem                   implies the distribution operation.
5151.22Slukem
5161.23Slukem     makewrapper   Create the nbmake-MACHINE wrapper.  This operation is auto-
5171.23Slukem                   matically performed for any of the other operations.
5181.23Slukem
5191.22Slukem     obj           Perform ``make obj''.
5201.22Slukem
5211.22Slukem     tools         Build and install the host tools from src/tools.
5221.22Slukem
5231.35Slukem     install=idir  Install the contents of DESTDIR to idir, using ``make
5241.35Slukem                   installworld''.
5251.35Slukem
5261.22Slukem     kernel=kconf  Build a new kernel.  The kconf argument is the name of a
5271.22Slukem                   configuration file suitable for use by config(8).  If kconf
5281.22Slukem                   does not contain any `/' characters, the configuration file
5291.22Slukem                   is expected to be found in the KERNCONFDIR directory, which
5301.22Slukem                   is typically sys/arch/MACHINE/conf.  The new kernel will be
5311.22Slukem                   built in a subdirectory of KERNOBJDIR, which is typically
5321.22Slukem                   sys/arch/MACHINE/compile or an associated object directory.
5331.22Slukem                   In order to ensure that the kernel is built using up-to-
5341.22Slukem                   date tools, it is strongly recommended that the tools be
5351.22Slukem                   rebuilt (using the tools operation).
5361.22Slukem
5371.35Slukem     releasekernel=kconf
5381.35Slukem                   Install a gzip(1)ed copy of the kernel built by
5391.35Slukem                   kernel=kconf into RELEASEDIR/MACHINE/binary/kernel, usually
5401.44Slukem                   as netbsd-kconf.gz, although the ``netbsd'' prefix is
5411.44Slukem                   determined from the ``config'' directives in kconf.
5421.24Slukem
5431.24Slukem     sets          Perform ``make sets''.
5441.31Slukem
5451.31Slukem     sourcesets    Perform ``make sourcesets''.
5461.22Slukem
5471.22Slukem     The following command line options alter the behaviour of the above oper-
5481.22Slukem     ations: The following command line options alter the behaviour of the
5491.22Slukem     build.sh operations described above:
5501.1Stv
5511.1Stv     -a arch   Set the value of MACHINE_ARCH to arch.
5521.9Sthorpej
5531.9Sthorpej     -B buildid
5541.9Sthorpej               Set the value of BUILDID to buildid.  This will also append the
5551.9Sthorpej               build idenfitier to the name of the ``make'' wrapper script so
5561.37Slukem               that the resulting name is of the form
5571.37Slukem               ``nbmake-MACHINE-BUILDID''.
5581.1Stv
5591.18Slukem     -D dest   Set the value of DESTDIR to dest.
5601.18Slukem
5611.23Slukem     -E        Set `expert' mode.  This overrides various sanity checks, and
5621.23Slukem               allows: DESTDIR does not have to be set to a non-root path for
5631.38Slukem               builds, and MKUNPRIVED=yes does not have to be set when build-
5641.38Slukem               ing as a non-root user.
5651.23Slukem
5661.23Slukem               Note: It is highly recommended that you know what you are doing
5671.23Slukem               when you use this option.
5681.19Slukem
5691.10Ssommerfe     -j njob   Passed through to make(1).  Makefiles should use .WAIT or have
5701.10Ssommerfe               explicit dependancies as necessary to enforce build ordering.
5711.10Ssommerfe               If you see build failures with -j, please save complete build
5721.10Ssommerfe               logs so the failures can be analyzed.
5731.1Stv
5741.40Slukem     -M obj    Set MAKEOBJDIRPREFIX to obj.  Unsets MAKEOBJDIR.
5751.18Slukem
5761.1Stv     -m mach   Set the value of MACHINE to mach.  This will also override any
5771.1Stv               value of MACHINE_ARCH in the process environment with a value
5781.33Slukem               deduced from mach, unless -a is specified, or mach is a special
5791.33Slukem               case listed below.  All cross builds require -m, but if unset
5801.33Slukem               on a NetBSD host, the host's value of MACHINE will be detected
5811.33Slukem               and used automatically.
5821.33Slukem
5831.33Slukem               Some machines support multiple values for MACHINE_ARCH.  For a
5841.33Slukem               given value of mach, the following MACHINE and MACHINE_ARCH
5851.33Slukem               values will result:
5861.33Slukem
5871.33Slukem                     mach          MACHINE    MACHINE_ARCH
5881.33Slukem                     evbmips       evbmips    (not set)
5891.33Slukem                     evbmips-eb    evbmips    mipseb
5901.33Slukem                     evbmips-el    evbmips    mipsel
5911.33Slukem                     evbsh3        evbsh3     (not set)
5921.33Slukem                     evbsh3-eb     evbsh3     sh3eb
5931.33Slukem                     evbsh3-el     evbsh3     sh3el
5941.33Slukem                     sbmips        sbmips     (not set)
5951.33Slukem                     sbmips-eb     sbmips     mipseb
5961.33Slukem                     sbmips-el     sbmips     mipsel
5971.1Stv
5981.45Slukem     -N noiselevel
5991.46Slukem               Set the ``noisyness'' level of the build, by setting
6001.46Slukem               MAKEVERBOSE to noiselevel.
6011.45Slukem
6021.1Stv     -n        Show the commands that would be executed by build.sh, but do
6031.1Stv               not make any changes.  This is similar in concept to ``make
6041.1Stv               -n''.
6051.1Stv
6061.18Slukem     -O obj    Create an appropriate transform macro for MAKEOBJDIR that will
6071.18Slukem               place the built object files under obj.  For instance, a set-
6081.18Slukem               ting of /usr/obj will place build-time files under
6091.40Slukem               /usr/obj/bin, /usr/obj/lib, /usr/obj/usr.bin, and so forth.
6101.40Slukem               Unsets MAKEOBJDIRPREFIX.
6111.18Slukem
6121.34Slukem     -o        Set the value of MKOBJDIRS to ``no''.  Otherwise, it will be
6131.34Slukem               automatically set to ``yes'' (which is opposite to the default
6141.34Slukem               behaviour).
6151.1Stv
6161.22Slukem     -R rel    Set the value of RELEASEDIR to rel.
6171.18Slukem
6181.1Stv     -r        Remove the contents of DESTDIR and TOOLDIR before building
6191.1Stv               (provides a clean starting point).  This will skip deleting
6201.1Stv               DESTDIR if building on a native system to the root directory.
6211.1Stv
6221.18Slukem     -T tools  Set the value of TOOLDIR to tools.  If set, the bootstrap
6231.18Slukem               ``make'' will only be rebuilt as needed (when the source files
6241.18Slukem               for make(1) change).
6251.18Slukem
6261.38Slukem     -U        Set MKUNPRIVED=yes.
6271.18Slukem
6281.38Slukem     -u        Set MKUPDATE=yes.
6291.1Stv
6301.21Slukem     -V var=[value]
6311.40Slukem               Set the environment variable var to an optional value.  This is
6321.40Slukem               propagated to the nbmake wrapper.
6331.21Slukem
6341.1Stv     -w wrapper
6351.1Stv               Create the nbmake wrapper script (see below) in a custom loca-
6361.1Stv               tion, specified by wrapper.  This allows, for instance, to
6371.1Stv               place the wrapper in PATH automatically.  Note that wrapper is
6381.1Stv               the full name of the file, not just a directory name.
6391.1Stv
6401.49Slukem     -X x11src
6411.49Slukem               Set the value of X11SRCDIR to x11src.
6421.49Slukem
6431.49Slukem     -x        Set MKX11=yes.
6441.49Slukem
6451.40Slukem     -Z var    Unset ("zap") the environment variable var.  This is propagated
6461.40Slukem               to the nbmake wrapper.
6471.40Slukem
6481.1Stv   The "nbmake-MACHINE" wrapper script
6491.1Stv     If using the build.sh script to build NetBSD, a nbmake-MACHINE script
6501.1Stv     will be created in TOOLDIR/bin upon the first build to assist in building
6511.1Stv     subtrees on a cross-compile host.
6521.1Stv
6531.1Stv     nbmake-MACHINE can be invoked in lieu of make(1), and will instead call
6541.1Stv     the up-to-date version of ``nbmake'' installed into TOOLDIR/bin with sev-
6551.1Stv     eral key variables pre-set, including MACHINE, MACHINE_ARCH, and TOOLDIR.
6561.40Slukem     build.sh will also set variables specified with -V, and unset variables
6571.40Slukem     specified with -Z.
6581.40Slukem
6591.1Stv     This script can be symlinked into a directory listed in PATH, or called
6601.1Stv     with an absolute path.
6611.1Stv
6621.16SlukemEXAMPLES
6631.44Slukem     1.   % ./build.sh tools kernel=GENERIC
6641.28Slukem
6651.28Slukem          Build a new toolchain, and use the new toolchain to configure and
6661.28Slukem          build a new GENERIC kernel.
6671.28Slukem
6681.44Slukem     2.   % ./build.sh -U distribution
6691.28Slukem
6701.30Slukem          Using unprivileged mode, build a complete distribution to a DESTDIR
6711.30Slukem          directory that build.sh selects (and will display).
6721.28Slukem
6731.43Smartti     3.   # ./build.sh -U install=/
6741.28Slukem
6751.29Slukem          As root, install to / the distribution that was built by example 2.
6761.29Slukem          Even though this is run as root, -U is required so that the permis-
6771.30Slukem          sions stored in DESTDIR/METALOG are correctly applied to the files
6781.30Slukem          as they're copied to /.
6791.28Slukem
6801.44Slukem     4.   % ./build.sh -U -u release
6811.28Slukem
6821.30Slukem          Using unprivileged mode, build a complete release to DESTDIR and
6831.30Slukem          RELEASEDIR directories that build.sh selects (and will display).
6841.38Slukem          MKUPDATE=yes (-u) is set to prevent the ``make cleandir'', so that
6851.38Slukem          if this is run after example 2, it doesn't need to redo that portion
6861.38Slukem          of the release build.
6871.16Slukem
6881.10SsommerfeOBSOLETE VARIABLES
6891.15Slukem     NBUILDJOBS  Use the make(1) option -j, instead.
6901.15Slukem
6911.15Slukem     USE_NEW_TOOLCHAIN
6921.15Slukem                 The new toolchain is now the default.  To disable, use
6931.15Slukem                 TOOLCHAIN_MISSING=yes.
6941.10Ssommerfe
6951.1StvSEE ALSO
6961.1Stv     make(1), hier(7), release(7)
6971.1Stv
6981.1StvHISTORY
6991.15Slukem     The build.sh based build scheme was introduced for NetBSD 1.6 as
7001.15Slukem     USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that.
7011.1Stv
7021.1StvBUGS
7031.15Slukem     A few platforms are not yet using this build system.
7041.1Stv
7051.49SlukemNetBSD                         February 6, 2003                         NetBSD
706