BUILDING revision 1.62
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.59Sapb                       tory.  The value is subjected to variable expansion by
1231.59Sapb                       make(1).  Used only if MAKEOBJDIRPREFIX is not defined.
1241.36Slukem                       MAKEOBJDIR can only be provided in the environment or
1251.41Slukem                       via the -O flag of build.sh.
1261.8Slukem
1271.8Slukem     MAKEOBJDIRPREFIX  Top level directory of the object directory tree.  If
1281.59Sapb                       specified, must be an absolute path.  If this is
1291.59Sapb                       defined, ${MAKEOBJDIRPREFIX}/${.CURDIR} is used as the
1301.59Sapb                       .OBJDIR for the current directory.  The current direc-
1311.59Sapb                       tory may be read only.  MAKEOBJDIRPREFIX can only be
1321.59Sapb                       provided in the environment or via the -M flag of
1331.36Slukem                       build.sh.
1341.8Slukem
1351.1Stv   "make" variables
1361.1Stv     Several variables control the behavior of NetBSD builds.  Unless other-
1371.1Stv     wise specified, these variables may be set in either the process environ-
1381.1Stv     ment or the make(1) configuration file specified by MAKECONF.
1391.1Stv
1401.9Sthorpej     BUILDID     Identifier for the build.  The identifier will be appended to
1411.9Sthorpej                 object directory names, and can be consulted in the make(1)
1421.9Sthorpej                 configuration file in order to set additional build parame-
1431.9Sthorpej                 ters, such as compiler flags.
1441.9Sthorpej
1451.1Stv     DESTDIR     Directory to contain the built NetBSD system.  If set, spe-
1461.1Stv                 cial options are passed to the compilation tools to prevent
1471.1Stv                 their default use of the host system's /usr/include,
1481.59Sapb                 /usr/lib, and so forth.  This pathname must be an absolute
1491.59Sapb                 path, and should not end with a slash (/) character.  (For
1501.59Sapb                 installation into the system's root directory, set DESTDIR to
1511.59Sapb                 an empty string, not to ``/'').  The directory must reside on
1521.59Sapb                 a file system which supports long file names and hard links.
1531.1Stv
1541.1Stv                 Default: Empty string if USETOOLS is ``yes''; unset other-
1551.1Stv                 wise.
1561.1Stv
1571.30Slukem                 Note: build.sh will provide a default of destdir.MACHINE (in
1581.30Slukem                 the top-level .OBJDIR) unless run in `expert' mode
1591.30Slukem
1601.1Stv     MAKECONF    The name of the make(1) configuration file.  Only settable in
1611.1Stv                 the process environment.
1621.1Stv
1631.1Stv                 Default: ``/etc/mk.conf''
1641.1Stv
1651.45Slukem     MAKEVERBOSE
1661.45Slukem                 Level of verbosity of status messages.  Supported values:
1671.45Slukem
1681.45Slukem                 0    No descriptive messages are shown.
1691.45Slukem
1701.45Slukem                 1    Descriptive messages are shown.
1711.45Slukem
1721.45Slukem                 2    Descriptive messages (prefixed with a `#') and command
1731.45Slukem                      output is not suppressed.
1741.45Slukem
1751.45Slukem                 Default: 2
1761.45Slukem
1771.1Stv     MKCATPAGES  Can be set to ``yes'' or ``no''.  Indicates whether prefor-
1781.1Stv                 matted plaintext manual pages will be created during a build.
1791.1Stv
1801.1Stv                 Default: ``yes''
1811.1Stv
1821.1Stv     MKCRYPTO    Can be set to ``yes'' or ``no''.  Indicates whether crypto-
1831.1Stv                 graphic code will be included in a build; provided for the
1841.1Stv                 benefit of countries that do not allow strong cryptography.
1851.44Slukem                 Will not affect use of the standard low-security password
1861.44Slukem                 encryption system, crypt(3).
1871.1Stv
1881.1Stv                 Default: ``yes''
1891.1Stv
1901.1Stv     MKDOC       Can be set to ``yes'' or ``no''.  Indicates whether system
1911.44Slukem                 documentation destined for DESTDIR/usr/share/doc will be
1921.44Slukem                 installed during a build.
1931.1Stv
1941.1Stv                 Default: ``yes''
1951.1Stv
1961.4Stv     MKHOSTOBJ   Can be set to ``yes'' or ``no''.  If set to ``yes'', then for
1971.4Stv                 programs intended to be run on the compile host, the name,
1981.4Stv                 release, and architecture of the host operating system will
1991.4Stv                 be suffixed to the name of the object directory created by
2001.4Stv                 ``make obj''.  (This allows multiple host systems to compile
2011.4Stv                 NetBSD for a single target.)  If set to ``no'', then programs
2021.4Stv                 built to be run on the compile host will use the same object
2031.4Stv                 directory names as programs built to be run on the target.
2041.4Stv
2051.4Stv                 Default: ``no''
2061.4Stv
2071.1Stv     MKINFO      Can be set to ``yes'' or ``no''.  Indicates whether GNU Info
2081.1Stv                 files, used for the documentation for most of the compilation
2091.1Stv                 tools, will be created and installed during a build.
2101.1Stv
2111.1Stv                 Default: ``yes''
2121.1Stv
2131.1Stv     MKLINT      Can be set to ``yes'' or ``no''.  Indicates whether lint(1)
2141.1Stv                 will be run against portions of the NetBSD source code during
2151.1Stv                 the build, and whether lint libraries will be installed into
2161.27Slukem                 DESTDIR/usr/libdata/lint.
2171.1Stv
2181.1Stv                 Default: ``yes''
2191.1Stv
2201.1Stv     MKMAN       Can be set to ``yes'' or ``no''.  Indicates whether manual
2211.1Stv                 pages will be installed during a build.
2221.1Stv
2231.1Stv                 Default: ``yes''
2241.1Stv
2251.1Stv     MKNLS       Can be set to ``yes'' or ``no''.  Indicates whether Native
2261.44Slukem                 Language System locale zone files will be compiled and
2271.44Slukem                 installed during a build.
2281.1Stv
2291.1Stv                 Default: ``yes''
2301.1Stv
2311.1Stv     MKOBJ       Can be set to ``yes'' or ``no''.  Indicates whether object
2321.1Stv                 directories will be created when running ``make obj''.  If
2331.1Stv                 set to ``no'', then all built files will be located inside
2341.1Stv                 the regular source tree.
2351.1Stv
2361.1Stv                 Default: ``yes''
2371.1Stv
2381.1Stv     MKPIC       Can be set to ``yes'' or ``no''.  Indicates whether shared
2391.1Stv                 objects and libraries will be created and installed during a
2401.1Stv                 build.  If set to ``no'', the entire built system will be
2411.1Stv                 statically linked.
2421.1Stv
2431.1Stv                 Default: Platform dependent.  As of this writing, all plat-
2441.1Stv                 forms except sh3 default to ``yes''.
2451.1Stv
2461.1Stv     MKPICINSTALL
2471.1Stv                 Can be set to ``yes'' or ``no''.  Indicates whether the ar(1)
2481.44Slukem                 format libraries (lib*_pic.a), used to generate shared
2491.44Slukem                 libraries, are installed during a build.
2501.1Stv
2511.1Stv                 Default: ``yes''
2521.1Stv
2531.1Stv     MKPROFILE   Can be set to ``yes'' or ``no''.  Indicates whether profiled
2541.1Stv                 libraries (lib*_p.a) will be built and installed during a
2551.1Stv                 build.
2561.1Stv
2571.1Stv                 Default: ``yes''; however, some platforms turn off MKPROFILE
2581.1Stv                 by default at times due to toolchain problems with profiled
2591.1Stv                 code.
2601.1Stv
2611.1Stv     MKSHARE     Can be set to ``yes'' or ``no''.  Indicates whether files
2621.44Slukem                 destined to reside in DESTDIR/usr/share will be built and
2631.44Slukem                 installed during a build.  If set to ``no'', then all of
2641.27Slukem                 MKCATPAGES, MKDOC, MKINFO, MKMAN, and MKNLS will be set to
2651.27Slukem                 ``no'' unconditionally.
2661.1Stv
2671.1Stv                 Default: ``yes''
2681.1Stv
2691.50Swiz     MKTTINTERP  Can be set to ``yes'' or ``no''.  For X builds, decides if
2701.50Swiz                 the TrueType bytecode interpreter is turned on.  See
2711.50Swiz                 http://www.freetype.org/patents.html for details.
2721.50Swiz
2731.50Swiz                 Default: ``no''
2741.50Swiz
2751.44Slukem     MKUNPRIVED  Can be set to ``yes'' or ``no''.  Indicates whether an
2761.44Slukem                 unprivileged install will occur.  The user, group, permis-
2771.52Sjmc                 sions, and file flags, will not be set on the installed
2781.52Sjmc                 items; instead the information will be appended to a file
2791.52Sjmc                 called METALOG in DESTDIR.  The contents of METALOG are used
2801.52Sjmc                 during the generation of the distribution tar files to ensure
2811.52Sjmc                 that the appropriate file ownership is stored.
2821.38Slukem
2831.38Slukem                 Default: ``no''
2841.38Slukem
2851.44Slukem     MKUPDATE    Can be set to ``yes'' or ``no''.  Indicates whether all
2861.44Slukem                 install operations intended to write to DESTDIR will compare
2871.38Slukem                 file timestamps before installing, and skip the install phase
2881.44Slukem                 if the destination files are up-to-date.  This also has
2891.44Slukem                 implications on full builds (see next subsection).
2901.38Slukem
2911.38Slukem                 Default: ``no''
2921.38Slukem
2931.49Slukem     MKX11       Can be set to ``yes'' or ``no''.  Indicates whether X11R6 is
2941.49Slukem                 built from X11SRCDIR.
2951.49Slukem
2961.49Slukem                 Default: ``no''
2971.49Slukem
2981.59Sapb     TOOLDIR     Directory to hold the host tools, once built.  If specified,
2991.59Sapb                 must be an absolute path.  This directory should be unique to
3001.59Sapb                 a given host system and NetBSD source tree.  (However, multi-
3011.59Sapb                 ple targets may share the same TOOLDIR; the target-dependent
3021.59Sapb                 files have unique names.)  If unset, a default based on the
3031.59Sapb                 uname(1) information of the host platform will be created in
3041.59Sapb                 the .OBJDIR of src.
3051.1Stv
3061.1Stv                 Default: Unset.
3071.1Stv
3081.1Stv     USETOOLS    Indicates whether the tools specified by TOOLDIR should be
3091.1Stv                 used as part of a build in progress.  Must be set to ``yes''
3101.1Stv                 if cross-compiling.
3111.1Stv
3121.1Stv                 yes    Use the tools from TOOLDIR.
3131.1Stv
3141.1Stv                 no     Do not use the tools from TOOLDIR, but refuse to build
3151.1Stv                        native compilation tool components that are version-
3161.1Stv                        specific for that tool.
3171.1Stv
3181.1Stv                 never  Do not use the tools from TOOLDIR, even when building
3191.1Stv                        native tool components.  This is similar to the tradi-
3201.1Stv                        tional NetBSD build method, but does not verify that
3211.1Stv                        the compilation tools in use are up-to-date enough in
3221.1Stv                        order to build the tree successfully.  This may cause
3231.1Stv                        build or runtime problems when building the whole
3241.1Stv                        NetBSD source tree.
3251.1Stv
3261.1Stv                 Default: ``yes'' if building all or part of a whole NetBSD
3271.1Stv                 source tree (detected automatically); ``no'' otherwise (to
3281.44Slukem                 preserve traditional semantics of the <bsd.*.mk> make(1)
3291.44Slukem                 include files).
3301.1Stv
3311.59Sapb     X11SRCDIR   Directory containing the X11R6 source.  If specified, must be
3321.59Sapb                 an absolute path.  The main X11R6 source is found in
3331.59Sapb                 X11SRCDIR/xfree/xc.
3341.49Slukem
3351.49Slukem                 Default: ``/usr/xsrc''
3361.49Slukem
3371.1Stv   "make" variables for full builds
3381.7Slukem     These variables only affect the top level ``Makefile'' and do not affect
3391.7Slukem     manually building subtrees of the NetBSD source code.
3401.1Stv
3411.20Slukem     INSTALLWORLDDIR  Location for the ``make installworld'' target to install
3421.59Sapb                      to.  If specified, must be an absolute path.
3431.1Stv
3441.20Slukem                      Default: ``/''
3451.1Stv
3461.44Slukem     MKOBJDIRS        Can be set to ``yes'' or ``no''.  Indicates whether
3471.44Slukem                      object directories will be created automatically (via a
3481.20Slukem                      ``make obj'' pass) at the start of a build.
3491.1Stv
3501.34Slukem                      Default: ``no''
3511.1Stv
3521.38Slukem     MKUPDATE         Can be set to ``yes'' or ``no''.  If set, then in addi-
3531.38Slukem                      tion to the effects described for MKUPDATE=yes above,
3541.38Slukem                      this implies the effects of NOCLEANDIR (i.e., ``make
3551.38Slukem                      cleandir'' is avoided).
3561.38Slukem
3571.38Slukem                      Default: ``no''
3581.38Slukem
3591.20Slukem     NBUILDJOBS       Now obsolete.  Use the make(1) option -j, instead (see
3601.20Slukem                      below)
3611.1Stv
3621.20Slukem                      Default: Unset.
3631.1Stv
3641.20Slukem     NOCLEANDIR       If set, avoids the ``make cleandir'' phase of a full
3651.20Slukem                      build.  This has the effect of allowing only changed
3661.20Slukem                      files in a source tree to be recompiled.  This can speed
3671.20Slukem                      up builds when updating only a few files in the tree.
3681.1Stv
3691.20Slukem                      Default: Unset.
3701.1Stv
3711.20Slukem     NODISTRIBDIRS    If set, avoids the ``make distrib-dirs'' phase of a full
3721.20Slukem                      build.  This skips running mtree(8) on DESTDIR, useful
3731.20Slukem                      on systems where building as an unprivileged user, or
3741.20Slukem                      where it is known that the system-wide mtree files have
3751.20Slukem                      not changed.
3761.1Stv
3771.20Slukem                      Default: Unset.
3781.1Stv
3791.20Slukem     NOINCLUDES       If set, avoids the ``make includes'' phase of a full
3801.20Slukem                      build.  This has the effect of preventing make(1) from
3811.44Slukem                      thinking that some programs are out-of-date simply
3821.44Slukem                      because the system include files have changed.  However,
3831.20Slukem                      this option should not be used when updating the entire
3841.20Slukem                      NetBSD source tree arbitrarily; it is suggested to use
3851.38Slukem                      MKUPDATE=yes in that case.
3861.1Stv
3871.20Slukem                      Default: Unset.
3881.1Stv
3891.20Slukem     RELEASEDIR       If set, specifies the directory to which a release(7)
3901.20Slukem                      layout will be written at the end of a ``make release''.
3911.59Sapb                      If specified, must be an absolute path.
3921.20Slukem
3931.20Slukem                      Default: Unset.
3941.20Slukem
3951.30Slukem                      Note: build.sh will provide a default of releasedir (in
3961.30Slukem                      the top-level .OBJDIR) unless run in `expert' mode
3971.30Slukem
3981.1StvBUILDING
3991.1Stv   "make" command line options
4001.52Sjmc     This is not a summary of all the options available to make(1); only the
4011.52Sjmc     options used most frequently with NetBSD builds are listed here.
4021.1Stv
4031.10Ssommerfe     -j njob    Run up to njob make(1) subjobs in parallel.  Makefiles should
4041.52Sjmc                use .WAIT or have explicit dependencies as necessary to
4051.44Slukem                enforce build ordering.  If you see build failures with -j,
4061.10Ssommerfe                please save complete build logs so the failures can be ana-
4071.10Ssommerfe                lyzed.
4081.10Ssommerfe
4091.1Stv     -m dir     Specify the default directory for searching for system Make-
4101.1Stv                file segments, mainly the <bsd.*.mk> files.  When building any
4111.1Stv                full NetBSD source tree, this should be set to the
4121.1Stv                ``share/mk'' directory in the source tree.  (This is set auto-
4131.1Stv                matically when building from the top level.)
4141.1Stv
4151.1Stv     -n         Display the commands that would have been executed, but do not
4161.1Stv                actually execute them.  This will still cause recursion to
4171.1Stv                take place.
4181.1Stv
4191.47Szuntum     -V var     Print make(1)'s idea of the value of var.  Does not build any
4201.1Stv                targets.
4211.1Stv
4221.1Stv     var=value  Set the variable var to value, overriding any setting speci-
4231.1Stv                fied by the process environment, the MAKECONF configuration
4241.1Stv                file, or the system Makefile segments.
4251.1Stv
4261.1Stv   "make" targets
4271.1Stv     These default targets may be built by running make(1) in any subtree of
4281.1Stv     the NetBSD source code.  It is recommended that none of these be used
4291.1Stv     from the top level Makefile; as a specific exception, ``make obj'' and
4301.1Stv     ``make cleandir'' are useful in that context.
4311.1Stv
4321.1Stv     all        Build programs, libraries, and preformatted documentation.
4331.1Stv
4341.1Stv     clean      Remove program and library object code files.
4351.1Stv
4361.44Slukem     cleandir   Same as clean, but also remove preformatted documentation,
4371.44Slukem                dependency files generated by ``make depend'', and any other
4381.49Slukem                files known to be created at build time.
4391.1Stv
4401.44Slukem     depend     Create dependency files (.depend) containing more detailed
4411.44Slukem                information about the dependencies of source code on header
4421.1Stv                files.  Allows programs to be recompiled automatically when a
4431.1Stv                dependency changes.
4441.1Stv
4451.1Stv     dependall  Does a ``make depend'' immediately followed by a ``make all''.
4461.10Ssommerfe                This improves cache locality of the build since both passes
4471.10Ssommerfe                read the source files in their entirety.
4481.1Stv
4491.49Slukem     distclean  Synonym for cleandir.
4501.49Slukem
4511.44Slukem     includes   Build and install system header files.  Typically needed
4521.44Slukem                before any system libraries or programs can be built.
4531.1Stv
4541.1Stv     install    Install programs, libraries, and documentation into DESTDIR.
4551.27Slukem                Few files will be installed to DESTDIR/dev, DESTDIR/etc,
4561.27Slukem                DESTDIR/root or DESTDIR/var in order to prevent user supplied
4571.27Slukem                configuration data from being overwritten.
4581.1Stv
4591.1Stv     lint       Run lint(1) against the C source code, where appropriate, and
4601.1Stv                generate system-installed lint libraries.
4611.1Stv
4621.1Stv     obj        Create object directories to be used for built files, instead
4631.1Stv                of building directly in the source tree.
4641.1Stv
4651.1Stv     tags       Create ctags(1) searchable function lists usable by the ex(1)
4661.1Stv                and vi(1) text editors.
4671.1Stv
4681.1Stv   "make" targets for the top level
4691.1Stv     Additional make(1) targets are usable specifically from the top source
4701.1Stv     level to facilitate building the entire NetBSD source tree.
4711.1Stv
4721.20Slukem     build         Build the entire NetBSD system.  This orders portions of
4731.20Slukem                   the source tree such that prerequisites will be built in
4741.20Slukem                   the proper order.
4751.20Slukem
4761.20Slukem     distribution  Do a ``make build'', and then install a full distribution
4771.27Slukem                   into DESTDIR, including files in DESTDIR/dev, DESTDIR/etc,
4781.27Slukem                   DESTDIR/root and DESTDIR/var.
4791.20Slukem
4801.20Slukem     buildworld    As per ``make distribution'', except that it ensures that
4811.20Slukem                   DESTDIR is not the root directory.
4821.20Slukem
4831.20Slukem     installworld  Install the distribution from DESTDIR to INSTALLWORLDDIR
4841.20Slukem                   (which defaults to the root directory).  Ensures that
4851.52Sjmc                   INSTALLWORLDDIR is not the root directory if cross compil-
4861.20Slukem                   ing.
4871.20Slukem
4881.61Sapb                   The INSTALLSETS environment variable may be set to a list
4891.61Sapb                   of distribution sets to be installed.  By default, all sets
4901.61Sapb                   except ``etc'' and ``xetc'' are installed (so most files in
4911.61Sapb                   INSTALLWORLDDIR/etc will not be installed or modified).
4921.61Sapb
4931.61Sapb                   Note: Before performing this operation with
4941.61Sapb                   INSTALLWORLDDIR=/, it is highly recommended that you
4951.61Sapb                   upgrade your kernel and reboot.  After performing this
4961.61Sapb                   operation, it is recommended that you use etcupdate(8) to
4971.61Sapb                   update files in INSTALLWORLDDIR/etc and that you use
4981.61Sapb                   postinstall(8) to check for inconsistencies (and possibly
4991.61Sapb                   to fix them).
5001.20Slukem
5011.25Slukem     sets          Create distribution sets from DESTDIR into
5021.25Slukem                   RELEASEDIR/MACHINE/binary/sets.  Should be run after ``make
5031.25Slukem                   distribution'' (as ``make build'' does not install all of
5041.25Slukem                   the required files).
5051.25Slukem
5061.31Slukem     sourcesets    Create source sets of the source tree into
5071.31Slukem                   RELEASEDIR/source/sets.
5081.31Slukem
5091.54Sapb     syspkgs       Create syspkgs from DESTDIR into
5101.54Sapb                   RELEASEDIR/MACHINE/binary/syspkgs.  Should be run after
5111.54Sapb                   ``make distribution'' (as ``make build'' does not install
5121.54Sapb                   all of the required files).
5131.54Sapb
5141.44Slukem     release       Do a ``make distribution'', build kernels, distribution
5151.44Slukem                   media, and install sets (this as per ``make sets''), and
5161.44Slukem                   then package the system into a standard release layout as
5171.44Slukem                   described by release(7).  This requires that RELEASEDIR be
5181.25Slukem                   set (see above).
5191.1Stv
5201.62Sapb     iso-image     Create a NetBSD installation CD-ROM image in the
5211.62Sapb                   RELEASEDIR/iso directory.  The CD-ROM file system will have
5221.62Sapb                   a layout as described in release(7).
5231.62Sapb
5241.62Sapb                   For most machine types, the CD-ROM will be bootable, and
5251.62Sapb                   will automatically run the sysinst(8) menu-based installa-
5261.62Sapb                   tion program, which can be used to install or upgrade a
5271.62Sapb                   NetBSD system.  Bootable CD-ROMs also contain tools that
5281.62Sapb                   may be useful in repairing a damaged NetBSD installation.
5291.62Sapb
5301.62Sapb                   Before ``make iso-image'' is attempted, RELEASEDIR must be
5311.62Sapb                   populated by ``make release'' or equivalent.
5321.62Sapb
5331.62Sapb                   Note that other, smaller, CD-ROM images may be created in
5341.62Sapb                   the RELEASEDIR/MACHINE/installation/cdrom directory by
5351.62Sapb                   ``make release''.  These smaller images usually contain the
5361.62Sapb                   same tools as the larger images in RELEASEDIR/iso, but do
5371.62Sapb                   not contain additional content such as the distribution
5381.62Sapb                   sets.
5391.62Sapb
5401.62Sapb                   Note that the mac68k port still uses an older method of
5411.62Sapb                   creating CD-ROM images.  This requires the mkisofs(1) util-
5421.62Sapb                   ity, which is not part of NetBSD, but which can be
5431.62Sapb                   installed from pkgsrc/sysutils/cdrtools.
5441.56Sapb
5451.1Stv     regression-tests
5461.20Slukem                   Can only be run after building the regression tests in the
5471.20Slukem                   directory ``regress''.  Runs the compiled regression tests
5481.20Slukem                   on the local host.
5491.1Stv
5501.1Stv   The "build.sh" script
5511.1Stv     This script file is a Bourne shell script designed to build the entire
5521.1Stv     NetBSD system on any host with a Bourne shell in /bin/sh, including many
5531.1Stv     that are not POSIX compliant.  Note that if a host system's /bin/sh is
5541.1Stv     unusually old and broken, the Korn Shell (/bin/ksh), if available, may be
5551.1Stv     a usable alternative.
5561.1Stv
5571.1Stv     All cross-compile builds, and most native builds, of the entire system
5581.1Stv     should make use of build.sh rather than just running ``make''.  This way,
5591.1Stv     the make(1) program will be bootstrapped properly, in case the host sys-
5601.1Stv     tem has an older or incompatible ``make'' program.
5611.1Stv
5621.1Stv     When compiling the entire system via build.sh, many make(1) variables are
5631.1Stv     set for you in order to help encapsulate the build process.  In the list
5641.1Stv     of options below, variables that are automatically set by build.sh are
5651.1Stv     noted where applicable.
5661.1Stv
5671.22Slukem     The following operations are supported by build.sh:
5681.22Slukem
5691.44Slukem     build         Build the system as per ``make build''.  This option
5701.44Slukem                   implies the obj and tools operations.
5711.22Slukem
5721.22Slukem     distribution  Build a full distribution as per ``make distribution''.
5731.22Slukem                   This option implies the build operation.
5741.22Slukem
5751.22Slukem     release       Build a full release as per ``make release''.  This option
5761.22Slukem                   implies the distribution operation.
5771.22Slukem
5781.23Slukem     makewrapper   Create the nbmake-MACHINE wrapper.  This operation is auto-
5791.23Slukem                   matically performed for any of the other operations.
5801.23Slukem
5811.22Slukem     obj           Perform ``make obj''.
5821.22Slukem
5831.22Slukem     tools         Build and install the host tools from src/tools.
5841.22Slukem
5851.35Slukem     install=idir  Install the contents of DESTDIR to idir, using ``make
5861.61Sapb                   installworld''.  Note that files that are part of the
5871.61Sapb                   ``etc'' or ``xetc'' sets will not be installed.
5881.35Slukem
5891.22Slukem     kernel=kconf  Build a new kernel.  The kconf argument is the name of a
5901.54Sapb                   configuration file suitable for use by config(1).  If kconf
5911.22Slukem                   does not contain any `/' characters, the configuration file
5921.22Slukem                   is expected to be found in the KERNCONFDIR directory, which
5931.22Slukem                   is typically sys/arch/MACHINE/conf.  The new kernel will be
5941.22Slukem                   built in a subdirectory of KERNOBJDIR, which is typically
5951.22Slukem                   sys/arch/MACHINE/compile or an associated object directory.
5961.22Slukem                   In order to ensure that the kernel is built using up-to-
5971.22Slukem                   date tools, it is strongly recommended that the tools be
5981.22Slukem                   rebuilt (using the tools operation).
5991.22Slukem
6001.35Slukem     releasekernel=kconf
6011.35Slukem                   Install a gzip(1)ed copy of the kernel built by
6021.35Slukem                   kernel=kconf into RELEASEDIR/MACHINE/binary/kernel, usually
6031.44Slukem                   as netbsd-kconf.gz, although the ``netbsd'' prefix is
6041.44Slukem                   determined from the ``config'' directives in kconf.
6051.24Slukem
6061.24Slukem     sets          Perform ``make sets''.
6071.31Slukem
6081.31Slukem     sourcesets    Perform ``make sourcesets''.
6091.22Slukem
6101.54Sapb     syspkgs       Perform ``make syspkgs''.
6111.54Sapb
6121.56Sapb     iso-image     Perform ``make iso-image''.
6131.56Sapb
6141.51Swiz     The following command line options alter the behaviour of the build.sh
6151.51Swiz     operations described above:
6161.1Stv
6171.1Stv     -a arch   Set the value of MACHINE_ARCH to arch.
6181.9Sthorpej
6191.9Sthorpej     -B buildid
6201.9Sthorpej               Set the value of BUILDID to buildid.  This will also append the
6211.9Sthorpej               build idenfitier to the name of the ``make'' wrapper script so
6221.37Slukem               that the resulting name is of the form
6231.37Slukem               ``nbmake-MACHINE-BUILDID''.
6241.1Stv
6251.59Sapb     -D dest   Set the value of DESTDIR to dest.  If a relative path is speci-
6261.59Sapb               fied, it will be converted to an absolute path before being
6271.59Sapb               used.
6281.18Slukem
6291.23Slukem     -E        Set `expert' mode.  This overrides various sanity checks, and
6301.23Slukem               allows: DESTDIR does not have to be set to a non-root path for
6311.38Slukem               builds, and MKUNPRIVED=yes does not have to be set when build-
6321.38Slukem               ing as a non-root user.
6331.23Slukem
6341.23Slukem               Note: It is highly recommended that you know what you are doing
6351.23Slukem               when you use this option.
6361.19Slukem
6371.51Swiz     -h        Print a help message.
6381.51Swiz
6391.10Ssommerfe     -j njob   Passed through to make(1).  Makefiles should use .WAIT or have
6401.10Ssommerfe               explicit dependancies as necessary to enforce build ordering.
6411.10Ssommerfe               If you see build failures with -j, please save complete build
6421.10Ssommerfe               logs so the failures can be analyzed.
6431.1Stv
6441.59Sapb     -M obj    Set MAKEOBJDIRPREFIX to obj.  If a relative path is specified,
6451.59Sapb               it will be converted to an absolute path before being used.
6461.59Sapb               Unsets MAKEOBJDIR.
6471.18Slukem
6481.60Sapb     -m mach   Set the value of MACHINE to mach, except in some special cases
6491.60Sapb               listed below.  This will also override any value of
6501.60Sapb               MACHINE_ARCH in the process environment with a value deduced
6511.60Sapb               from mach, unless -a is specified.  All cross builds require
6521.60Sapb               -m, but if unset on a NetBSD host, the host's value of MACHINE
6531.60Sapb               will be detected and used automatically.
6541.60Sapb
6551.60Sapb               Some machines support multiple values for MACHINE_ARCH.  The
6561.60Sapb               following special cases for the mach argument are defined to
6571.60Sapb               set the listed values of MACHINE and MACHINE_ARCH:
6581.33Slukem
6591.33Slukem                     mach          MACHINE    MACHINE_ARCH
6601.60Sapb                     evbarm        evbarm     (not set)
6611.60Sapb                     evbarm-eb     evbarm     armeb
6621.60Sapb                     evbarm-el     evbarm     arm
6631.33Slukem                     evbmips       evbmips    (not set)
6641.33Slukem                     evbmips-eb    evbmips    mipseb
6651.33Slukem                     evbmips-el    evbmips    mipsel
6661.33Slukem                     evbsh3        evbsh3     (not set)
6671.33Slukem                     evbsh3-eb     evbsh3     sh3eb
6681.33Slukem                     evbsh3-el     evbsh3     sh3el
6691.33Slukem                     sbmips        sbmips     (not set)
6701.33Slukem                     sbmips-eb     sbmips     mipseb
6711.33Slukem                     sbmips-el     sbmips     mipsel
6721.1Stv
6731.45Slukem     -N noiselevel
6741.46Slukem               Set the ``noisyness'' level of the build, by setting
6751.46Slukem               MAKEVERBOSE to noiselevel.
6761.45Slukem
6771.1Stv     -n        Show the commands that would be executed by build.sh, but do
6781.1Stv               not make any changes.  This is similar in concept to ``make
6791.1Stv               -n''.
6801.1Stv
6811.18Slukem     -O obj    Create an appropriate transform macro for MAKEOBJDIR that will
6821.59Sapb               place the built object files under obj.  If a relative path is
6831.59Sapb               specified, it will be converted to an absolute path before
6841.59Sapb               being used.  For instance, a setting of /usr/obj will place
6851.59Sapb               build-time files under /usr/obj/bin, /usr/obj/lib,
6861.59Sapb               /usr/obj/usr.bin, and so forth.  Unsets MAKEOBJDIRPREFIX.
6871.18Slukem
6881.34Slukem     -o        Set the value of MKOBJDIRS to ``no''.  Otherwise, it will be
6891.34Slukem               automatically set to ``yes'' (which is opposite to the default
6901.34Slukem               behaviour).
6911.1Stv
6921.59Sapb     -R rel    Set the value of RELEASEDIR to rel.  If a relative path is
6931.59Sapb               specified, it will be converted to an absolute path before
6941.59Sapb               being used.
6951.18Slukem
6961.1Stv     -r        Remove the contents of DESTDIR and TOOLDIR before building
6971.1Stv               (provides a clean starting point).  This will skip deleting
6981.1Stv               DESTDIR if building on a native system to the root directory.
6991.1Stv
7001.59Sapb     -T tools  Set the value of TOOLDIR to tools.  If a relative path is spec-
7011.59Sapb               ified, it will be converted to an absolute path before being
7021.59Sapb               used.  If set, the bootstrap ``make'' will only be rebuilt as
7031.59Sapb               needed (when the source files for make(1) change).
7041.18Slukem
7051.38Slukem     -U        Set MKUNPRIVED=yes.
7061.18Slukem
7071.38Slukem     -u        Set MKUPDATE=yes.
7081.1Stv
7091.21Slukem     -V var=[value]
7101.40Slukem               Set the environment variable var to an optional value.  This is
7111.40Slukem               propagated to the nbmake wrapper.
7121.21Slukem
7131.1Stv     -w wrapper
7141.1Stv               Create the nbmake wrapper script (see below) in a custom loca-
7151.1Stv               tion, specified by wrapper.  This allows, for instance, to
7161.1Stv               place the wrapper in PATH automatically.  Note that wrapper is
7171.59Sapb               the full name of the file, not just a directory name.  If a
7181.59Sapb               relative path is specified, it will be converted to an absolute
7191.59Sapb               path before being used.
7201.1Stv
7211.49Slukem     -X x11src
7221.59Sapb               Set the value of X11SRCDIR to x11src.  If a relative path is
7231.59Sapb               specified, it will be converted to an absolute path before
7241.59Sapb               being used.
7251.49Slukem
7261.49Slukem     -x        Set MKX11=yes.
7271.49Slukem
7281.40Slukem     -Z var    Unset ("zap") the environment variable var.  This is propagated
7291.40Slukem               to the nbmake wrapper.
7301.40Slukem
7311.1Stv   The "nbmake-MACHINE" wrapper script
7321.1Stv     If using the build.sh script to build NetBSD, a nbmake-MACHINE script
7331.1Stv     will be created in TOOLDIR/bin upon the first build to assist in building
7341.1Stv     subtrees on a cross-compile host.
7351.1Stv
7361.1Stv     nbmake-MACHINE can be invoked in lieu of make(1), and will instead call
7371.1Stv     the up-to-date version of ``nbmake'' installed into TOOLDIR/bin with sev-
7381.1Stv     eral key variables pre-set, including MACHINE, MACHINE_ARCH, and TOOLDIR.
7391.40Slukem     build.sh will also set variables specified with -V, and unset variables
7401.40Slukem     specified with -Z.
7411.40Slukem
7421.1Stv     This script can be symlinked into a directory listed in PATH, or called
7431.1Stv     with an absolute path.
7441.1Stv
7451.16SlukemEXAMPLES
7461.44Slukem     1.   % ./build.sh tools kernel=GENERIC
7471.28Slukem
7481.28Slukem          Build a new toolchain, and use the new toolchain to configure and
7491.28Slukem          build a new GENERIC kernel.
7501.28Slukem
7511.44Slukem     2.   % ./build.sh -U distribution
7521.28Slukem
7531.30Slukem          Using unprivileged mode, build a complete distribution to a DESTDIR
7541.30Slukem          directory that build.sh selects (and will display).
7551.28Slukem
7561.43Smartti     3.   # ./build.sh -U install=/
7571.28Slukem
7581.29Slukem          As root, install to / the distribution that was built by example 2.
7591.29Slukem          Even though this is run as root, -U is required so that the permis-
7601.30Slukem          sions stored in DESTDIR/METALOG are correctly applied to the files
7611.30Slukem          as they're copied to /.
7621.28Slukem
7631.44Slukem     4.   % ./build.sh -U -u release
7641.28Slukem
7651.30Slukem          Using unprivileged mode, build a complete release to DESTDIR and
7661.30Slukem          RELEASEDIR directories that build.sh selects (and will display).
7671.38Slukem          MKUPDATE=yes (-u) is set to prevent the ``make cleandir'', so that
7681.38Slukem          if this is run after example 2, it doesn't need to redo that portion
7691.38Slukem          of the release build.
7701.16Slukem
7711.10SsommerfeOBSOLETE VARIABLES
7721.15Slukem     NBUILDJOBS  Use the make(1) option -j, instead.
7731.15Slukem
7741.15Slukem     USE_NEW_TOOLCHAIN
7751.15Slukem                 The new toolchain is now the default.  To disable, use
7761.15Slukem                 TOOLCHAIN_MISSING=yes.
7771.10Ssommerfe
7781.1StvSEE ALSO
7791.62Sapb     make(1), hier(7), release(7), etcupdate(8), postinstall(8), sysinst(8),
7801.61Sapb     pkgsrc/sysutils/cdrtools
7811.1Stv
7821.1StvHISTORY
7831.15Slukem     The build.sh based build scheme was introduced for NetBSD 1.6 as
7841.15Slukem     USE_NEW_TOOLCHAIN, and re-worked to TOOLCHAIN_MISSING after that.
7851.1Stv
7861.1StvBUGS
7871.15Slukem     A few platforms are not yet using this build system.
7881.1Stv
7891.62SapbNetBSD                          April 13, 2007                          NetBSD
790