BUILDING revision 1.41
11.1StvBUILDING(8)             NetBSD System Manager's Manual             BUILDING(8)
21.1Stv
31.1StvNAME
41.1Stv     BUILDING - Procedure for building NetBSD from source code.
51.1Stv
61.1StvSTATUS
71.1Stv     This document is a work-in-progress.  As such, the information described
81.1Stv     here may not match the reality of the build system as of this writing.
91.1Stv     Once this document is completely in sync with reality, this paragraph
101.1Stv     will be removed.
111.1Stv
121.1Stv     Discrepancies between this documentation and the current reality of im-
131.1Stv     plementation are noted specially, as with the note below:
141.1Stv
151.1Stv     Note: This document applies only to platforms which use the new toolchain
161.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.22Slukem           Note: A couple of host toolchain components are not yet available
341.22Slukem           in the tools directory.  Also, some tools use non-POSIX, non-ANSI C
351.1Stv           extensions and need to be standardized.  As a result, cross-compil-
361.1Stv           ing from systems other than NetBSD is not currently supported.
371.1Stv
381.1StvFILES
391.1Stv   Source tree layout
401.17Swiz     doc/BUILDING.mdoc
411.17Swiz                    This document (in -mdoc troff format; the original copy).
421.1Stv
431.2Swiz     BUILDING       This document (in plaintext).
441.1Stv
451.1Stv     Makefile       The main Makefile for NetBSD; should only be run for na-
461.1Stv                    tive builds with an appropriately up-to-date version of
471.1Stv                    NetBSD make(1).  (For building from out-of-date systems or
481.1Stv                    on a non-native host, see the build.sh shell script.)
491.1Stv
501.1Stv     UPDATING       Special notes for updating from an earlier revision of
511.1Stv                    NetBSD.  It is important to read this file before every
521.1Stv                    build of an updated source tree.
531.1Stv
541.1Stv     build.sh       Bourne-compatible shell script used for building the host
551.1Stv                    build tools and the NetBSD system from scratch.  Can be
561.1Stv                    used for both native and cross builds, and should be used
571.1Stv                    instead of make(1) for any source tree that is updated and
581.1Stv                    recompiled regularly.
591.1Stv
601.1Stv     crypto/dist/, dist/, gnu/dist/
611.1Stv                    Sources imported verbatim from third parties, without man-
621.1Stv                    gling the existing build structure.  Other source trees in
631.1Stv                    bin through usr.sbin use the NetBSD make(1) ``reachover''
641.1Stv                    Makefile semantics when building these programs for a na-
651.1Stv                    tive host.
661.1Stv
671.1Stv     distrib/, etc/
681.1Stv                    Sources for items used when making a full release snap-
691.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.1Stv   Build tree layout
871.1Stv     The NetBSD build tree is described in hier(7), and the release layout is
881.1Stv     described in release(7).
891.1Stv
901.1StvCONFIGURATION
911.8Slukem   Environment variables
921.8Slukem     Several environment variables control the behaviour of NetBSD builds.
931.8Slukem
941.8Slukem     MACHINE           Machine type.
951.8Slukem
961.8Slukem     MACHINE_ARCH      Machine architecture.
971.8Slukem
981.8Slukem     MAKE              Path name to invoke make(1) as.
991.8Slukem
1001.8Slukem     MAKEFLAGS         Flags to invoke make(1) with.
1011.8Slukem
1021.8Slukem     MAKEOBJDIR        Directory to use as the .OBJDIR for the current direc-
1031.8Slukem                       tory.  Used only if MAKEOBJDIRPREFIX is not defined.
1041.36Slukem                       MAKEOBJDIR can only be provided in the environment or
1051.41Slukem                       via the -O flag of build.sh.
1061.8Slukem
1071.8Slukem     MAKEOBJDIRPREFIX  Top level directory of the object directory tree.  If
1081.8Slukem                       this is defined, ${MAKEOBJDIRPREFIX}/${.CURDIR} is used
1091.8Slukem                       as the .OBJDIR for the current directory.  The current
1101.8Slukem                       directory may be read only.  MAKEOBJDIRPREFIX can only
1111.36Slukem                       be provided in the environment or via the -M flag of
1121.36Slukem                       build.sh.
1131.8Slukem
1141.1Stv   "make" variables
1151.1Stv     Several variables control the behavior of NetBSD builds.  Unless other-
1161.1Stv     wise specified, these variables may be set in either the process environ-
1171.1Stv     ment or the make(1) configuration file specified by MAKECONF.
1181.1Stv
1191.9Sthorpej     BUILDID     Identifier for the build.  The identifier will be appended to
1201.9Sthorpej                 object directory names, and can be consulted in the make(1)
1211.9Sthorpej                 configuration file in order to set additional build parame-
1221.9Sthorpej                 ters, such as compiler flags.
1231.9Sthorpej
1241.1Stv     DESTDIR     Directory to contain the built NetBSD system.  If set, spe-
1251.1Stv                 cial options are passed to the compilation tools to prevent
1261.1Stv                 their default use of the host system's /usr/include,
1271.1Stv                 /usr/lib, and so forth.  This pathname should not end with a
1281.1Stv                 slash (/) character (for installation into the system's root
1291.7Slukem                 directory, set DESTDIR to an empty string).  The directory
1301.7Slukem                 must reside on a file system which supports long file names
1311.7Slukem                 and hard links.
1321.1Stv
1331.1Stv                 Default: Empty string if USETOOLS is ``yes''; unset other-
1341.1Stv                 wise.
1351.1Stv
1361.30Slukem                 Note: build.sh will provide a default of destdir.MACHINE (in
1371.30Slukem                 the top-level .OBJDIR) unless run in `expert' mode
1381.30Slukem
1391.1Stv     MAKECONF    The name of the make(1) configuration file.  Only settable in
1401.1Stv                 the process environment.
1411.1Stv
1421.1Stv                 Default: ``/etc/mk.conf''
1431.1Stv
1441.1Stv     MKCATPAGES  Can be set to ``yes'' or ``no''.  Indicates whether prefor-
1451.1Stv                 matted plaintext manual pages will be created during a build.
1461.1Stv
1471.1Stv                 Default: ``yes''
1481.1Stv
1491.1Stv     MKCRYPTO    Can be set to ``yes'' or ``no''.  Indicates whether crypto-
1501.1Stv                 graphic code will be included in a build; provided for the
1511.1Stv                 benefit of countries that do not allow strong cryptography.
1521.1Stv                 Will not affect use of the standard low-security password en-
1531.1Stv                 cryption system, crypt(3).
1541.1Stv
1551.1Stv                 Default: ``yes''
1561.1Stv
1571.1Stv     MKDOC       Can be set to ``yes'' or ``no''.  Indicates whether system
1581.27Slukem                 documentation destined for DESTDIR/usr/share/doc will be in-
1591.27Slukem                 stalled during a build.
1601.1Stv
1611.1Stv                 Default: ``yes''
1621.1Stv
1631.4Stv     MKHOSTOBJ   Can be set to ``yes'' or ``no''.  If set to ``yes'', then for
1641.4Stv                 programs intended to be run on the compile host, the name,
1651.4Stv                 release, and architecture of the host operating system will
1661.4Stv                 be suffixed to the name of the object directory created by
1671.4Stv                 ``make obj''.  (This allows multiple host systems to compile
1681.4Stv                 NetBSD for a single target.)  If set to ``no'', then programs
1691.4Stv                 built to be run on the compile host will use the same object
1701.4Stv                 directory names as programs built to be run on the target.
1711.4Stv
1721.4Stv                 Default: ``no''
1731.4Stv
1741.1Stv     MKINFO      Can be set to ``yes'' or ``no''.  Indicates whether GNU Info
1751.1Stv                 files, used for the documentation for most of the compilation
1761.1Stv                 tools, will be created and installed during a build.
1771.1Stv
1781.1Stv                 Default: ``yes''
1791.1Stv
1801.1Stv     MKLINT      Can be set to ``yes'' or ``no''.  Indicates whether lint(1)
1811.1Stv                 will be run against portions of the NetBSD source code during
1821.1Stv                 the build, and whether lint libraries will be installed into
1831.27Slukem                 DESTDIR/usr/libdata/lint.
1841.1Stv
1851.1Stv                 Default: ``yes''
1861.1Stv
1871.1Stv     MKMAN       Can be set to ``yes'' or ``no''.  Indicates whether manual
1881.1Stv                 pages will be installed during a build.
1891.1Stv
1901.1Stv                 Default: ``yes''
1911.1Stv
1921.1Stv     MKNLS       Can be set to ``yes'' or ``no''.  Indicates whether Native
1931.1Stv                 Language System locale zone files will be compiled and in-
1941.1Stv                 stalled during a build.
1951.1Stv
1961.1Stv                 Default: ``yes''
1971.1Stv
1981.1Stv     MKOBJ       Can be set to ``yes'' or ``no''.  Indicates whether object
1991.1Stv                 directories will be created when running ``make obj''.  If
2001.1Stv                 set to ``no'', then all built files will be located inside
2011.1Stv                 the regular source tree.
2021.1Stv
2031.1Stv                 Default: ``yes''
2041.1Stv
2051.1Stv     MKPIC       Can be set to ``yes'' or ``no''.  Indicates whether shared
2061.1Stv                 objects and libraries will be created and installed during a
2071.1Stv                 build.  If set to ``no'', the entire built system will be
2081.1Stv                 statically linked.
2091.1Stv
2101.1Stv                 Default: Platform dependent.  As of this writing, all plat-
2111.1Stv                 forms except sh3 default to ``yes''.
2121.1Stv
2131.1Stv     MKPICINSTALL
2141.1Stv                 Can be set to ``yes'' or ``no''.  Indicates whether the ar(1)
2151.1Stv                 format libraries (lib*_pic.a), used to generate shared li-
2161.1Stv                 braries, are installed during a build.
2171.1Stv
2181.1Stv                 Default: ``yes''
2191.1Stv
2201.1Stv     MKPROFILE   Can be set to ``yes'' or ``no''.  Indicates whether profiled
2211.1Stv                 libraries (lib*_p.a) will be built and installed during a
2221.1Stv                 build.
2231.1Stv
2241.1Stv                 Default: ``yes''; however, some platforms turn off MKPROFILE
2251.1Stv                 by default at times due to toolchain problems with profiled
2261.1Stv                 code.
2271.1Stv
2281.1Stv     MKSHARE     Can be set to ``yes'' or ``no''.  Indicates whether files
2291.27Slukem                 destined to reside in DESTDIR/usr/share will be built and in-
2301.27Slukem                 stalled during a build.  If set to ``no'', then all of
2311.27Slukem                 MKCATPAGES, MKDOC, MKINFO, MKMAN, and MKNLS will be set to
2321.27Slukem                 ``no'' unconditionally.
2331.1Stv
2341.1Stv                 Default: ``yes''
2351.1Stv
2361.38Slukem     MKUNPRIVED  Can be set to ``yes'' or ``no''.  Indicates whether an un-
2371.38Slukem                 privileged install will occur.  The user, group, permissions,
2381.38Slukem                 and file flags, will not be set on the installed item; in-
2391.38Slukem                 stead the information will be appended to a file called
2401.38Slukem                 METALOG in DESTDIR.  The contents of METALOG is used during
2411.38Slukem                 the generation of the distribution tar files to ensure that
2421.38Slukem                 the appropriate file ownership is stored.
2431.38Slukem
2441.38Slukem                 Default: ``no''
2451.38Slukem
2461.38Slukem     MKUPDATE    Can be set to ``yes'' or ``no''.  Indicates whether all in-
2471.38Slukem                 stall operations intended to write to DESTDIR will compare
2481.38Slukem                 file timestamps before installing, and skip the install phase
2491.38Slukem                 if the destination files are up-to-date.  This also has im-
2501.38Slukem                 plications on full builds (see next subsection).
2511.38Slukem
2521.38Slukem                 Default: ``no''
2531.38Slukem
2541.1Stv     TOOLDIR     Directory to hold the host tools, once built.  This directory
2551.1Stv                 should be unique to a given host system and NetBSD source
2561.1Stv                 tree.  (However, multiple targets may share the same TOOLDIR;
2571.1Stv                 the target-dependent files have unique names.)  If unset, a
2581.1Stv                 default based on the uname(1) information of the host plat-
2591.39Slukem                 form will be created in the .OBJDIR of src.
2601.1Stv
2611.1Stv                 Default: Unset.
2621.1Stv
2631.1Stv     USETOOLS    Indicates whether the tools specified by TOOLDIR should be
2641.1Stv                 used as part of a build in progress.  Must be set to ``yes''
2651.1Stv                 if cross-compiling.
2661.1Stv
2671.1Stv                 yes    Use the tools from TOOLDIR.
2681.1Stv
2691.1Stv                 no     Do not use the tools from TOOLDIR, but refuse to build
2701.1Stv                        native compilation tool components that are version-
2711.1Stv                        specific for that tool.
2721.1Stv
2731.1Stv                 never  Do not use the tools from TOOLDIR, even when building
2741.1Stv                        native tool components.  This is similar to the tradi-
2751.1Stv                        tional NetBSD build method, but does not verify that
2761.1Stv                        the compilation tools in use are up-to-date enough in
2771.1Stv                        order to build the tree successfully.  This may cause
2781.1Stv                        build or runtime problems when building the whole
2791.1Stv                        NetBSD source tree.
2801.1Stv
2811.1Stv                 Default: ``yes'' if building all or part of a whole NetBSD
2821.1Stv                 source tree (detected automatically); ``no'' otherwise (to
2831.1Stv                 preserve traditional semantics of the <bsd.*.mk> make(1) in-
2841.1Stv                 clude files).
2851.1Stv
2861.1Stv   "make" variables for full builds
2871.7Slukem     These variables only affect the top level ``Makefile'' and do not affect
2881.7Slukem     manually building subtrees of the NetBSD source code.
2891.1Stv
2901.20Slukem     INSTALLWORLDDIR  Location for the ``make installworld'' target to install
2911.20Slukem                      to.
2921.1Stv
2931.20Slukem                      Default: ``/''
2941.1Stv
2951.20Slukem     MKOBJDIRS        Can be set to ``yes'' or ``no''.  Indicates whether ob-
2961.20Slukem                      ject directories will be created automatically (via a
2971.20Slukem                      ``make obj'' pass) at the start of a build.
2981.1Stv
2991.34Slukem                      Default: ``no''
3001.1Stv
3011.38Slukem     MKUPDATE         Can be set to ``yes'' or ``no''.  If set, then in addi-
3021.38Slukem                      tion to the effects described for MKUPDATE=yes above,
3031.38Slukem                      this implies the effects of NOCLEANDIR (i.e., ``make
3041.38Slukem                      cleandir'' is avoided).
3051.38Slukem
3061.38Slukem                      Default: ``no''
3071.38Slukem
3081.20Slukem     NBUILDJOBS       Now obsolete.  Use the make(1) option -j, instead (see
3091.20Slukem                      below)
3101.1Stv
3111.20Slukem                      Default: Unset.
3121.1Stv
3131.20Slukem     NOCLEANDIR       If set, avoids the ``make cleandir'' phase of a full
3141.20Slukem                      build.  This has the effect of allowing only changed
3151.20Slukem                      files in a source tree to be recompiled.  This can speed
3161.20Slukem                      up builds when updating only a few files in the tree.
3171.1Stv
3181.20Slukem                      Default: Unset.
3191.1Stv
3201.20Slukem     NODISTRIBDIRS    If set, avoids the ``make distrib-dirs'' phase of a full
3211.20Slukem                      build.  This skips running mtree(8) on DESTDIR, useful
3221.20Slukem                      on systems where building as an unprivileged user, or
3231.20Slukem                      where it is known that the system-wide mtree files have
3241.20Slukem                      not changed.
3251.1Stv
3261.20Slukem                      Default: Unset.
3271.1Stv
3281.20Slukem     NOINCLUDES       If set, avoids the ``make includes'' phase of a full
3291.20Slukem                      build.  This has the effect of preventing make(1) from
3301.20Slukem                      thinking that some programs are out-of-date simply be-
3311.20Slukem                      cause the system include files have changed.  However,
3321.20Slukem                      this option should not be used when updating the entire
3331.20Slukem                      NetBSD source tree arbitrarily; it is suggested to use
3341.38Slukem                      MKUPDATE=yes in that case.
3351.1Stv
3361.20Slukem                      Default: Unset.
3371.1Stv
3381.20Slukem     RELEASEDIR       If set, specifies the directory to which a release(7)
3391.20Slukem                      layout will be written at the end of a ``make release''.
3401.20Slukem
3411.20Slukem                      Default: Unset.
3421.20Slukem
3431.30Slukem                      Note: build.sh will provide a default of releasedir (in
3441.30Slukem                      the top-level .OBJDIR) unless run in `expert' mode
3451.30Slukem
3461.1StvBUILDING
3471.1Stv   "make" command line options
3481.1Stv     This is only a summary of options available to make(1); only the options
3491.1Stv     used most frequently with NetBSD builds are listed here.
3501.1Stv
3511.10Ssommerfe     -j njob    Run up to njob make(1) subjobs in parallel.  Makefiles should
3521.10Ssommerfe                use .WAIT or have explicit dependancies as necessary to en-
3531.10Ssommerfe                force build ordering.  If you see build failures with -j,
3541.10Ssommerfe                please save complete build logs so the failures can be ana-
3551.10Ssommerfe                lyzed.
3561.10Ssommerfe
3571.1Stv     -m dir     Specify the default directory for searching for system Make-
3581.1Stv                file segments, mainly the <bsd.*.mk> files.  When building any
3591.1Stv                full NetBSD source tree, this should be set to the
3601.1Stv                ``share/mk'' directory in the source tree.  (This is set auto-
3611.1Stv                matically when building from the top level.)
3621.1Stv
3631.1Stv     -n         Display the commands that would have been executed, but do not
3641.1Stv                actually execute them.  This will still cause recursion to
3651.1Stv                take place.
3661.1Stv
3671.1Stv     -v var     Print make(1)'s idea of the value of var.  Does not build any
3681.1Stv                targets.
3691.1Stv
3701.1Stv     var=value  Set the variable var to value, overriding any setting speci-
3711.1Stv                fied by the process environment, the MAKECONF configuration
3721.1Stv                file, or the system Makefile segments.
3731.1Stv
3741.1Stv   "make" targets
3751.1Stv     These default targets may be built by running make(1) in any subtree of
3761.1Stv     the NetBSD source code.  It is recommended that none of these be used
3771.1Stv     from the top level Makefile; as a specific exception, ``make obj'' and
3781.1Stv     ``make cleandir'' are useful in that context.
3791.1Stv
3801.1Stv     all        Build programs, libraries, and preformatted documentation.
3811.1Stv
3821.1Stv     clean      Remove program and library object code files.
3831.1Stv
3841.1Stv     cleandir   Same as clean, but also remove preformatted documentation, de-
3851.1Stv                pendency files generated by ``make depend'', and any other
3861.1Stv                files known to be created at build time.  ``make distclean''
3871.1Stv                may be used as a synonym, for familiarity with a similar well-
3881.1Stv                known convention.
3891.1Stv
3901.1Stv     depend     Create dependency files (.depend) containing more detailed in-
3911.1Stv                formation about the dependencies of source code on header
3921.1Stv                files.  Allows programs to be recompiled automatically when a
3931.1Stv                dependency changes.
3941.1Stv
3951.1Stv     dependall  Does a ``make depend'' immediately followed by a ``make all''.
3961.10Ssommerfe                This improves cache locality of the build since both passes
3971.10Ssommerfe                read the source files in their entirety.
3981.1Stv
3991.1Stv     includes   Build and install system header files.  Typically needed be-
4001.1Stv                fore any system libraries or programs can be built.
4011.1Stv
4021.1Stv     install    Install programs, libraries, and documentation into DESTDIR.
4031.27Slukem                Few files will be installed to DESTDIR/dev, DESTDIR/etc,
4041.27Slukem                DESTDIR/root or DESTDIR/var in order to prevent user supplied
4051.27Slukem                configuration data from being overwritten.
4061.1Stv
4071.1Stv     lint       Run lint(1) against the C source code, where appropriate, and
4081.1Stv                generate system-installed lint libraries.
4091.1Stv
4101.1Stv     obj        Create object directories to be used for built files, instead
4111.1Stv                of building directly in the source tree.
4121.1Stv
4131.1Stv     tags       Create ctags(1) searchable function lists usable by the ex(1)
4141.1Stv                and vi(1) text editors.
4151.1Stv
4161.1Stv   "make" targets for the top level
4171.1Stv     Additional make(1) targets are usable specifically from the top source
4181.1Stv     level to facilitate building the entire NetBSD source tree.
4191.1Stv
4201.20Slukem     build         Build the entire NetBSD system.  This orders portions of
4211.20Slukem                   the source tree such that prerequisites will be built in
4221.20Slukem                   the proper order.
4231.20Slukem
4241.20Slukem     distribution  Do a ``make build'', and then install a full distribution
4251.27Slukem                   into DESTDIR, including files in DESTDIR/dev, DESTDIR/etc,
4261.27Slukem                   DESTDIR/root and DESTDIR/var.
4271.20Slukem
4281.20Slukem     buildworld    As per ``make distribution'', except that it ensures that
4291.20Slukem                   DESTDIR is not the root directory.
4301.20Slukem
4311.20Slukem     installworld  Install the distribution from DESTDIR to INSTALLWORLDDIR
4321.20Slukem                   (which defaults to the root directory).  Ensures that
4331.20Slukem                   INSTALLWORLDDIR is the not root directory if cross compil-
4341.20Slukem                   ing.
4351.20Slukem
4361.20Slukem                   Note: It is highly recommended that you upgrade your kernel
4371.20Slukem                   and reboot before performing this operation.
4381.20Slukem
4391.25Slukem     sets          Create distribution sets from DESTDIR into
4401.25Slukem                   RELEASEDIR/MACHINE/binary/sets.  Should be run after ``make
4411.25Slukem                   distribution'' (as ``make build'' does not install all of
4421.25Slukem                   the required files).
4431.25Slukem
4441.31Slukem     sourcesets    Create source sets of the source tree into
4451.31Slukem                   RELEASEDIR/source/sets.
4461.31Slukem
4471.22Slukem     release       Do a ``make distribution'', build kernels, distribution me-
4481.25Slukem                   dia, and install sets (this as per ``make sets''), and then
4491.25Slukem                   package the system into a standard release layout as de-
4501.25Slukem                   scribed by release(7).  This requires that RELEASEDIR be
4511.25Slukem                   set (see above).
4521.1Stv
4531.1Stv     regression-tests
4541.20Slukem                   Can only be run after building the regression tests in the
4551.20Slukem                   directory ``regress''.  Runs the compiled regression tests
4561.20Slukem                   on the local host.
4571.1Stv
4581.1Stv   The "build.sh" script
4591.1Stv     This script file is a Bourne shell script designed to build the entire
4601.1Stv     NetBSD system on any host with a Bourne shell in /bin/sh, including many
4611.1Stv     that are not POSIX compliant.  Note that if a host system's /bin/sh is
4621.1Stv     unusually old and broken, the Korn Shell (/bin/ksh), if available, may be
4631.1Stv     a usable alternative.
4641.1Stv
4651.1Stv     All cross-compile builds, and most native builds, of the entire system
4661.1Stv     should make use of build.sh rather than just running ``make''.  This way,
4671.1Stv     the make(1) program will be bootstrapped properly, in case the host sys-
4681.1Stv     tem has an older or incompatible ``make'' program.
4691.1Stv
4701.1Stv     When compiling the entire system via build.sh, many make(1) variables are
4711.1Stv     set for you in order to help encapsulate the build process.  In the list
4721.1Stv     of options below, variables that are automatically set by build.sh are
4731.1Stv     noted where applicable.
4741.1Stv
4751.22Slukem     The following operations are supported by build.sh:
4761.22Slukem
4771.22Slukem     build         Build the system as per ``make build''.  This option im-
4781.22Slukem                   plies the obj and tools operations.
4791.22Slukem
4801.22Slukem     distribution  Build a full distribution as per ``make distribution''.
4811.22Slukem                   This option implies the build operation.
4821.22Slukem
4831.22Slukem     release       Build a full release as per ``make release''.  This option
4841.22Slukem                   implies the distribution operation.
4851.22Slukem
4861.23Slukem     makewrapper   Create the nbmake-MACHINE wrapper.  This operation is auto-
4871.23Slukem                   matically performed for any of the other operations.
4881.23Slukem
4891.22Slukem     obj           Perform ``make obj''.
4901.22Slukem
4911.22Slukem     tools         Build and install the host tools from src/tools.
4921.22Slukem
4931.35Slukem     install=idir  Install the contents of DESTDIR to idir, using ``make
4941.35Slukem                   installworld''.
4951.35Slukem
4961.22Slukem     kernel=kconf  Build a new kernel.  The kconf argument is the name of a
4971.22Slukem                   configuration file suitable for use by config(8).  If kconf
4981.22Slukem                   does not contain any `/' characters, the configuration file
4991.22Slukem                   is expected to be found in the KERNCONFDIR directory, which
5001.22Slukem                   is typically sys/arch/MACHINE/conf.  The new kernel will be
5011.22Slukem                   built in a subdirectory of KERNOBJDIR, which is typically
5021.22Slukem                   sys/arch/MACHINE/compile or an associated object directory.
5031.22Slukem                   In order to ensure that the kernel is built using up-to-
5041.22Slukem                   date tools, it is strongly recommended that the tools be
5051.22Slukem                   rebuilt (using the tools operation).
5061.22Slukem
5071.35Slukem     releasekernel=kconf
5081.35Slukem                   Install a gzip(1)ed copy of the kernel built by
5091.35Slukem                   kernel=kconf into RELEASEDIR/MACHINE/binary/kernel, usually
5101.35Slukem                   as netbsd-kconf.gz, although the ``netbsd'' prefix is de-
5111.35Slukem                   termined from the ``config'' directives in kconf.
5121.24Slukem
5131.24Slukem     sets          Perform ``make sets''.
5141.31Slukem
5151.31Slukem     sourcesets    Perform ``make sourcesets''.
5161.22Slukem
5171.22Slukem     The following command line options alter the behaviour of the above oper-
5181.22Slukem     ations: The following command line options alter the behaviour of the
5191.22Slukem     build.sh operations described above:
5201.1Stv
5211.1Stv     -a arch   Set the value of MACHINE_ARCH to arch.
5221.9Sthorpej
5231.9Sthorpej     -B buildid
5241.9Sthorpej               Set the value of BUILDID to buildid.  This will also append the
5251.9Sthorpej               build idenfitier to the name of the ``make'' wrapper script so
5261.37Slukem               that the resulting name is of the form
5271.37Slukem               ``nbmake-MACHINE-BUILDID''.
5281.1Stv
5291.18Slukem     -D dest   Set the value of DESTDIR to dest.
5301.18Slukem
5311.23Slukem     -E        Set `expert' mode.  This overrides various sanity checks, and
5321.23Slukem               allows: DESTDIR does not have to be set to a non-root path for
5331.38Slukem               builds, and MKUNPRIVED=yes does not have to be set when build-
5341.38Slukem               ing as a non-root user.
5351.23Slukem
5361.23Slukem               Note: It is highly recommended that you know what you are doing
5371.23Slukem               when you use this option.
5381.19Slukem
5391.10Ssommerfe     -j njob   Passed through to make(1).  Makefiles should use .WAIT or have
5401.10Ssommerfe               explicit dependancies as necessary to enforce build ordering.
5411.10Ssommerfe               If you see build failures with -j, please save complete build
5421.10Ssommerfe               logs so the failures can be analyzed.
5431.1Stv
5441.40Slukem     -M obj    Set MAKEOBJDIRPREFIX to obj.  Unsets MAKEOBJDIR.
5451.18Slukem
5461.1Stv     -m mach   Set the value of MACHINE to mach.  This will also override any
5471.1Stv               value of MACHINE_ARCH in the process environment with a value
5481.33Slukem               deduced from mach, unless -a is specified, or mach is a special
5491.33Slukem               case listed below.  All cross builds require -m, but if unset
5501.33Slukem               on a NetBSD host, the host's value of MACHINE will be detected
5511.33Slukem               and used automatically.
5521.33Slukem
5531.33Slukem               Some machines support multiple values for MACHINE_ARCH.  For a
5541.33Slukem               given value of mach, the following MACHINE and MACHINE_ARCH
5551.33Slukem               values will result:
5561.33Slukem
5571.33Slukem                     mach          MACHINE    MACHINE_ARCH
5581.33Slukem                     evbmips       evbmips    (not set)
5591.33Slukem                     evbmips-eb    evbmips    mipseb
5601.33Slukem                     evbmips-el    evbmips    mipsel
5611.33Slukem                     evbsh3        evbsh3     (not set)
5621.33Slukem                     evbsh3-eb     evbsh3     sh3eb
5631.33Slukem                     evbsh3-el     evbsh3     sh3el
5641.33Slukem                     sbmips        sbmips     (not set)
5651.33Slukem                     sbmips-eb     sbmips     mipseb
5661.33Slukem                     sbmips-el     sbmips     mipsel
5671.1Stv
5681.1Stv     -n        Show the commands that would be executed by build.sh, but do
5691.1Stv               not make any changes.  This is similar in concept to ``make
5701.1Stv               -n''.
5711.1Stv
5721.18Slukem     -O obj    Create an appropriate transform macro for MAKEOBJDIR that will
5731.18Slukem               place the built object files under obj.  For instance, a set-
5741.18Slukem               ting of /usr/obj will place build-time files under
5751.40Slukem               /usr/obj/bin, /usr/obj/lib, /usr/obj/usr.bin, and so forth.
5761.40Slukem               Unsets MAKEOBJDIRPREFIX.
5771.18Slukem
5781.34Slukem     -o        Set the value of MKOBJDIRS to ``no''.  Otherwise, it will be
5791.34Slukem               automatically set to ``yes'' (which is opposite to the default
5801.34Slukem               behaviour).
5811.1Stv
5821.22Slukem     -R rel    Set the value of RELEASEDIR to rel.
5831.18Slukem
5841.1Stv     -r        Remove the contents of DESTDIR and TOOLDIR before building
5851.1Stv               (provides a clean starting point).  This will skip deleting
5861.1Stv               DESTDIR if building on a native system to the root directory.
5871.1Stv
5881.18Slukem     -T tools  Set the value of TOOLDIR to tools.  If set, the bootstrap
5891.18Slukem               ``make'' will only be rebuilt as needed (when the source files
5901.18Slukem               for make(1) change).
5911.18Slukem
5921.38Slukem     -U        Set MKUNPRIVED=yes.
5931.18Slukem
5941.38Slukem     -u        Set MKUPDATE=yes.
5951.1Stv
5961.21Slukem     -V var=[value]
5971.40Slukem               Set the environment variable var to an optional value.  This is
5981.40Slukem               propagated to the nbmake wrapper.
5991.21Slukem
6001.1Stv     -w wrapper
6011.1Stv               Create the nbmake wrapper script (see below) in a custom loca-
6021.1Stv               tion, specified by wrapper.  This allows, for instance, to
6031.1Stv               place the wrapper in PATH automatically.  Note that wrapper is
6041.1Stv               the full name of the file, not just a directory name.
6051.1Stv
6061.40Slukem     -Z var    Unset ("zap") the environment variable var.  This is propagated
6071.40Slukem               to the nbmake wrapper.
6081.40Slukem
6091.1Stv   The "nbmake-MACHINE" wrapper script
6101.1Stv     If using the build.sh script to build NetBSD, a nbmake-MACHINE script
6111.1Stv     will be created in TOOLDIR/bin upon the first build to assist in building
6121.1Stv     subtrees on a cross-compile host.
6131.1Stv
6141.1Stv     nbmake-MACHINE can be invoked in lieu of make(1), and will instead call
6151.1Stv     the up-to-date version of ``nbmake'' installed into TOOLDIR/bin with sev-
6161.1Stv     eral key variables pre-set, including MACHINE, MACHINE_ARCH, and TOOLDIR.
6171.40Slukem     build.sh will also set variables specified with -V, and unset variables
6181.40Slukem     specified with -Z.
6191.40Slukem
6201.1Stv     This script can be symlinked into a directory listed in PATH, or called
6211.1Stv     with an absolute path.
6221.1Stv
6231.16SlukemEXAMPLES
6241.28Slukem     1.   ./build.sh tools kernel=GENERIC
6251.28Slukem
6261.28Slukem          Build a new toolchain, and use the new toolchain to configure and
6271.28Slukem          build a new GENERIC kernel.
6281.28Slukem
6291.30Slukem     2.   ./build.sh -U distribution
6301.28Slukem
6311.30Slukem          Using unprivileged mode, build a complete distribution to a DESTDIR
6321.30Slukem          directory that build.sh selects (and will display).
6331.28Slukem
6341.30Slukem     3.   # ./build.sh -U install=/
6351.28Slukem
6361.29Slukem          As root, install to / the distribution that was built by example 2.
6371.29Slukem          Even though this is run as root, -U is required so that the permis-
6381.30Slukem          sions stored in DESTDIR/METALOG are correctly applied to the files
6391.30Slukem          as they're copied to /.
6401.28Slukem
6411.30Slukem     4.   ./build.sh -U -u release
6421.28Slukem
6431.30Slukem          Using unprivileged mode, build a complete release to DESTDIR and
6441.30Slukem          RELEASEDIR directories that build.sh selects (and will display).
6451.38Slukem          MKUPDATE=yes (-u) is set to prevent the ``make cleandir'', so that
6461.38Slukem          if this is run after example 2, it doesn't need to redo that portion
6471.38Slukem          of the release build.
6481.16Slukem
6491.10SsommerfeOBSOLETE VARIABLES
6501.15Slukem     NBUILDJOBS  Use the make(1) option -j, instead.
6511.15Slukem
6521.15Slukem     USE_NEW_TOOLCHAIN
6531.15Slukem                 The new toolchain is now the default.  To disable, use
6541.15Slukem                 TOOLCHAIN_MISSING=yes.
6551.10Ssommerfe
6561.1StvSEE ALSO
6571.1Stv     make(1), hier(7), release(7)
6581.1Stv
6591.1StvHISTORY
6601.15Slukem     The build.sh based build scheme was introduced for NetBSD 1.6 as
6611.15Slukem     USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that.
6621.1Stv
6631.1StvBUGS
6641.15Slukem     A few platforms are not yet using this build system.
6651.1Stv
6661.41SlukemNetBSD                          August 7, 2003                          NetBSD
667