BUILDING revision 1.2
1BUILDING(8)             NetBSD System Manager's Manual             BUILDING(8)
2
3NAME
4     BUILDING - Procedure for building NetBSD from source code.
5
6STATUS
7     This document is a work-in-progress.  As such, the information described
8     here may not match the reality of the build system as of this writing.
9     Once this document is completely in sync with reality, this paragraph
10     will be removed.
11
12     Discrepancies between this documentation and the current reality of im-
13     plementation are noted specially, as with the note below:
14
15     Note: This document applies only to platforms which use the new toolchain
16     as indicated by the setting of USE_NEW_TOOLCHAIN in /etc/mk.conf or
17     <bsd.own.mk>.  Platforms which have not yet been switched to the new
18     toolchain should continue building traditionally, using the notes speci-
19     fied in the file UPDATING.
20
21REQUIREMENTS
22     NetBSD is designed to be buildable on most POSIX-compliant host systems.
23     The basic build procedure is the same whether compiling natively (on the
24     same NetBSD architecture) or cross compiling (on another architecture or
25     OS).
26
27     This source tree contains a special subtree, ``tools'', which uses the
28     host system to create a build toolchain for the target architecture.  The
29     host system must have at least C and C++ compilers in order to create the
30     toolchain (make is not required); all other tools are created as part of
31     the NetBSD build process.
32
33           Note: A couple host toolchain components are not yet available in
34           the tools directory.  Also, some tools use non-POSIX, non-ANSI C
35           extensions and need to be standardized.  As a result, cross-compil-
36           ing from systems other than NetBSD is not currently supported.
37
38FILES
39   Source tree layout
40
41     BUILDING.mdoc  This document (in -mdoc troff format; the original copy).
42
43     BUILDING       This document (in plaintext).
44
45     Makefile       The main Makefile for NetBSD; should only be run for na-
46                    tive builds with an appropriately up-to-date version of
47                    NetBSD make(1).  (For building from out-of-date systems or
48                    on a non-native host, see the build.sh shell script.)
49
50     UPDATING       Special notes for updating from an earlier revision of
51                    NetBSD.  It is important to read this file before every
52                    build of an updated source tree.
53
54     build.sh       Bourne-compatible shell script used for building the host
55                    build tools and the NetBSD system from scratch.  Can be
56                    used for both native and cross builds, and should be used
57                    instead of make(1) for any source tree that is updated and
58                    recompiled regularly.
59
60     crypto/dist/, dist/, gnu/dist/
61                    Sources imported verbatim from third parties, without man-
62                    gling the existing build structure.  Other source trees in
63                    bin through usr.sbin use the NetBSD make(1) ``reachover''
64                    Makefile semantics when building these programs for a na-
65                    tive host.
66
67     distrib/, etc/
68                    Sources for items used when making a full release snap-
69                    shot, such as files installed in /etc on the destination
70                    system, boot media, and release notes.
71
72     regress/       Regression test harness.  Can be cross-compiled, but only
73                    run natively.
74
75     sys/           NetBSD kernel sources.
76
77     tools/         ``Reachover'' build structure for the host build tools.
78                    This has a special method of determining out-of-date sta-
79                    tus.
80
81     bin/ ... usr.sbin/
82                    Sources to the NetBSD userland (non-kernel) programs.  If
83                    any of these directories are missing, they will be skipped
84                    during the build.
85
86   Build tree layout
87     The NetBSD build tree is described in hier(7), and the release layout is
88     described in release(7).
89
90CONFIGURATION
91   "make" variables
92     Several variables control the behavior of NetBSD builds.  Unless other-
93     wise specified, these variables may be set in either the process environ-
94     ment or the make(1) configuration file specified by MAKECONF.
95
96     DESTDIR     Directory to contain the built NetBSD system.  If set, spe-
97                 cial options are passed to the compilation tools to prevent
98                 their default use of the host system's /usr/include,
99                 /usr/lib, and so forth.  This pathname should not end with a
100                 slash (/) character (for installation into the system's root
101                 directory, set DESTDIR to an empty string).
102
103                 Default: Empty string if USETOOLS is ``yes''; unset other-
104                 wise.
105
106     MAKECONF    The name of the make(1) configuration file.  Only settable in
107                 the process environment.
108
109                 Default: ``/etc/mk.conf''
110
111     MKCATPAGES  Can be set to ``yes'' or ``no''.  Indicates whether prefor-
112                 matted plaintext manual pages will be created during a build.
113
114                 Default: ``yes''
115
116     MKCRYPTO    Can be set to ``yes'' or ``no''.  Indicates whether crypto-
117                 graphic code will be included in a build; provided for the
118                 benefit of countries that do not allow strong cryptography.
119                 Will not affect use of the standard low-security password en-
120                 cryption system, crypt(3).
121
122                 Default: ``yes''
123
124     MKDOC       Can be set to ``yes'' or ``no''.  Indicates whether system
125                 documentation destined for /usr/share/doc will be installed
126                 during a build.
127
128                 Default: ``yes''
129
130     MKINFO      Can be set to ``yes'' or ``no''.  Indicates whether GNU Info
131                 files, used for the documentation for most of the compilation
132                 tools, will be created and installed during a build.
133
134                 Default: ``yes''
135
136     MKLINT      Can be set to ``yes'' or ``no''.  Indicates whether lint(1)
137                 will be run against portions of the NetBSD source code during
138                 the build, and whether lint libraries will be installed into
139                 /usr/libdata/lint.
140
141                 Default: ``yes''
142
143     MKMAN       Can be set to ``yes'' or ``no''.  Indicates whether manual
144                 pages will be installed during a build.
145
146                 Default: ``yes''
147
148     MKNLS       Can be set to ``yes'' or ``no''.  Indicates whether Native
149                 Language System locale zone files will be compiled and in-
150                 stalled during a build.
151
152                 Default: ``yes''
153
154     MKOBJ       Can be set to ``yes'' or ``no''.  Indicates whether object
155                 directories will be created when running ``make obj''.  If
156                 set to ``no'', then all built files will be located inside
157                 the regular source tree.
158
159                 Default: ``yes''
160
161     MKPIC       Can be set to ``yes'' or ``no''.  Indicates whether shared
162                 objects and libraries will be created and installed during a
163                 build.  If set to ``no'', the entire built system will be
164                 statically linked.
165
166                 Default: Platform dependent.  As of this writing, all plat-
167                 forms except sh3 default to ``yes''.
168
169     MKPICINSTALL
170                 Can be set to ``yes'' or ``no''.  Indicates whether the ar(1)
171                 format libraries (lib*_pic.a), used to generate shared li-
172                 braries, are installed during a build.
173
174                 Default: ``yes''
175
176     MKPROFILE   Can be set to ``yes'' or ``no''.  Indicates whether profiled
177                 libraries (lib*_p.a) will be built and installed during a
178                 build.
179
180                 Default: ``yes''; however, some platforms turn off MKPROFILE
181                 by default at times due to toolchain problems with profiled
182                 code.
183
184     MKSHARE     Can be set to ``yes'' or ``no''.  Indicates whether files
185                 destined to reside in /usr/share will be built and installed
186                 during a build.  If set to ``no'', then all of MKCATPAGES,
187                 MKDOC, MKINFO, MKMAN, and MKNLS will be set to ``no'' uncon-
188                 ditionally.
189
190                 Default: ``yes''
191
192     TOOLDIR     Directory to hold the host tools, once built.  This directory
193                 should be unique to a given host system and NetBSD source
194                 tree.  (However, multiple targets may share the same TOOLDIR;
195                 the target-dependent files have unique names.)  If unset, a
196                 default based on the uname(1) information of the host plat-
197                 form will be created in the .OBJDIR of src/tools.
198
199                 Default: Unset.
200
201     UPDATE      If set, then all install operations intended to write to
202                 DESTDIR will compare file timestamps before installing, and
203                 skip the install phase if the destination files are up-to-
204                 date.  This also has implications on full builds (see next
205                 subsection).
206
207                 Default: Unset.
208
209     USETOOLS    Indicates whether the tools specified by TOOLDIR should be
210                 used as part of a build in progress.  Must be set to ``yes''
211                 if cross-compiling.
212
213                 yes    Use the tools from TOOLDIR.
214
215                 no     Do not use the tools from TOOLDIR, but refuse to build
216                        native compilation tool components that are version-
217                        specific for that tool.
218
219                 never  Do not use the tools from TOOLDIR, even when building
220                        native tool components.  This is similar to the tradi-
221                        tional NetBSD build method, but does not verify that
222                        the compilation tools in use are up-to-date enough in
223                        order to build the tree successfully.  This may cause
224                        build or runtime problems when building the whole
225                        NetBSD source tree.
226
227                 Default: ``yes'' if building all or part of a whole NetBSD
228                 source tree (detected automatically); ``no'' otherwise (to
229                 preserve traditional semantics of the <bsd.*.mk> make(1) in-
230                 clude files).
231
232   "make" variables for full builds
233     These variables only affect the top level ``Makefile'' and do not manual-
234     ly building subtrees of the NetBSD source code.
235
236     MKOBJDIRS      Can be set to ``yes'' or ``no''.  Indicates whether object
237                    directories will be created automatically (via a ``make
238                    obj'' pass) at the start of a build.
239
240                    Default: ``yes''
241
242     MKTOOLS        Indicates whether the host tools will be built and in-
243                    stalled automatically if they are out-of-date.
244
245                    yes    Build tools as needed into TOOLDIR, but only if the
246                           tools in question are out-of-date.
247
248                    no     Do not update the tools in TOOLDIR; halt the build
249                           as a safety precaution if tools are out-of-date.
250
251                    always
252                           Always rebuild the tools in TOOLDIR from scratch
253                           during a build.  This is similar to the standard
254                           NetBSD source tree build method, but is not typi-
255                           cally required for host tools.
256
257                    Default: ``yes''
258
259     NBUILDJOBS     If set, specifies the number of parallel make(1) processes
260                    that should be run simultaneously.  This can speed up
261                    builds on SMP machines, or machines with much more CPU
262                    power than I/O availability.  This should be used instead
263                    of the make(1) option -j, in order to ensure proper order-
264                    ing of build components.
265
266                    Default: Unset.
267
268     NOCLEANDIR     If set, avoids the ``make cleandir'' phase of a full
269                    build.  This has the effect of allowing only changed files
270                    in a source tree to be recompiled.  This can speed up
271                    builds when updating only a few files in the tree.
272
273                    Default: Unset.
274
275     NODISTRIBDIRS  If set, avoids the ``make distrib-dirs'' phase of a full
276                    build.  This skips running mtree(8) on DESTDIR, useful on
277                    systems where building as an unprivileged user, or where
278                    it is known that the system-wide mtree files have not
279                    changed.
280
281                    Default: Unset.
282
283     NOINCLUDES     If set, avoids the ``make includes'' phase of a full
284                    build.  This has the effect of preventing make(1) from
285                    thinking that some programs are out-of-date simply because
286                    the system include files have changed.  However, this op-
287                    tion should not be used when updating the entire NetBSD
288                    source tree arbitrarily; it is suggested to use UPDATE in
289                    that case.
290
291                    Default: Unset.
292
293     RELEASEDIR     If set, specifies the directory to which a release(7) lay-
294                    out will be written at the end of a ``make release''.
295
296                    Default: Unset.
297
298     UPDATE         If set, then in addition to the effects described for UP-
299                    DATE above, this implies the effects of NOCLEANDIR.
300
301BUILDING
302   "make" command line options
303     This is only a summary of options available to make(1); only the options
304     used most frequently with NetBSD builds are listed here.
305
306     -m dir     Specify the default directory for searching for system Make-
307                file segments, mainly the <bsd.*.mk> files.  When building any
308                full NetBSD source tree, this should be set to the
309                ``share/mk'' directory in the source tree.  (This is set auto-
310                matically when building from the top level.)
311
312     -n         Display the commands that would have been executed, but do not
313                actually execute them.  This will still cause recursion to
314                take place.
315
316     -v var     Print make(1)'s idea of the value of var.  Does not build any
317                targets.
318
319     var=value  Set the variable var to value, overriding any setting speci-
320                fied by the process environment, the MAKECONF configuration
321                file, or the system Makefile segments.
322
323   "make" targets
324     These default targets may be built by running make(1) in any subtree of
325     the NetBSD source code.  It is recommended that none of these be used
326     from the top level Makefile; as a specific exception, ``make obj'' and
327     ``make cleandir'' are useful in that context.
328
329     all        Build programs, libraries, and preformatted documentation.
330
331     clean      Remove program and library object code files.
332
333     cleandir   Same as clean, but also remove preformatted documentation, de-
334                pendency files generated by ``make depend'', and any other
335                files known to be created at build time.  ``make distclean''
336                may be used as a synonym, for familiarity with a similar well-
337                known convention.
338
339     depend     Create dependency files (.depend) containing more detailed in-
340                formation about the dependencies of source code on header
341                files.  Allows programs to be recompiled automatically when a
342                dependency changes.
343
344     dependall  Does a ``make depend'' immediately followed by a ``make all''.
345                This combined target recurses as an atomic unit, so that the
346                ``make depend'' phase can participate in make -j parallelism.
347
348     includes   Build and install system header files.  Typically needed be-
349                fore any system libraries or programs can be built.
350
351     install    Install programs, libraries, and documentation into DESTDIR.
352
353     lint       Run lint(1) against the C source code, where appropriate, and
354                generate system-installed lint libraries.
355
356     obj        Create object directories to be used for built files, instead
357                of building directly in the source tree.
358
359     tags       Create ctags(1) searchable function lists usable by the ex(1)
360                and vi(1) text editors.
361
362   "make" targets for the top level
363     Additional make(1) targets are usable specifically from the top source
364     level to facilitate building the entire NetBSD source tree.
365
366     build      Build the entire NetBSD system.  This orders portions of the
367                source tree such that prerequisites will be built in the prop-
368                er order.
369
370     release    Do a ``make build'', then package the system into a standard
371                release layout as described by release(7).  This requires that
372                RELEASEDIR be set (see above).
373
374     regression-tests
375                Can only be run after building the regression tests in the di-
376                rectory ``regress''.  Runs the compiled regression tests on
377                the local host.
378
379   The "build.sh" script
380     This script file is a Bourne shell script designed to build the entire
381     NetBSD system on any host with a Bourne shell in /bin/sh, including many
382     that are not POSIX compliant.  Note that if a host system's /bin/sh is
383     unusually old and broken, the Korn Shell (/bin/ksh), if available, may be
384     a usable alternative.
385
386     All cross-compile builds, and most native builds, of the entire system
387     should make use of build.sh rather than just running ``make''.  This way,
388     the make(1) program will be bootstrapped properly, in case the host sys-
389     tem has an older or incompatible ``make'' program.
390
391     When compiling the entire system via build.sh, many make(1) variables are
392     set for you in order to help encapsulate the build process.  In the list
393     of options below, variables that are automatically set by build.sh are
394     noted where applicable.
395
396     The following are available command line options that may be supplied to
397     build.sh:
398
399     -a arch   Set the value of MACHINE_ARCH to arch.
400
401     -b        Bootstrap ``make'' and create a nbmake-MACHINE script (see be-
402               low).
403
404     -j njob   Set the value of NBUILDJOBS to njob.  This provides similar
405               functionality to the familiar ``make -j'', but preserves the
406               ordering of the top level ``make build''.
407
408     -m mach   Set the value of MACHINE to mach.  This will also override any
409               value of MACHINE_ARCH in the process environment with a value
410               deduced from mach, unless -a is specified.  All cross builds
411               require -m, but if unset on a NetBSD host, the host's value of
412               MACHINE will be detected and used automatically.
413
414     -n        Show the commands that would be executed by build.sh, but do
415               not make any changes.  This is similar in concept to ``make
416               -n''.
417
418     -o        Set the value of MKOBJDIRS to ``no''.
419
420     -r        Remove the contents of DESTDIR and TOOLDIR before building
421               (provides a clean starting point).  This will skip deleting
422               DESTDIR if building on a native system to the root directory.
423
424     -t        Build and install the host tools from src/tools only.  This op-
425               tion implies -b.
426
427     -u        Set the UPDATE variable.
428
429     -w wrapper
430               Create the nbmake wrapper script (see below) in a custom loca-
431               tion, specified by wrapper.  This allows, for instance, to
432               place the wrapper in PATH automatically.  Note that wrapper is
433               the full name of the file, not just a directory name.
434
435     -D dest   Set the value of DESTDIR to dest.
436
437     -O obj    Create an appropriate transform macro for MAKEOBJDIR that will
438               place the built object files under obj.  For instance, a set-
439               ting of /usr/obj will place build-time files files under
440               /usr/obj/bin, /usr/obj/lib, and so forth.
441
442     -R rel    Set the value of RELEASEDIR to rel.  Setting this option will
443               cause build.sh to run ``make release'' instead of ``make
444               build''.
445
446     -T tools  Set the value of TOOLDIR to tools.  If set, the bootstrap
447               ``make'' will only be rebuilt as needed (when the source files
448               for make(1) change).
449
450   The "nbmake-MACHINE" wrapper script
451     If using the build.sh script to build NetBSD, a nbmake-MACHINE script
452     will be created in TOOLDIR/bin upon the first build to assist in building
453     subtrees on a cross-compile host.
454
455     nbmake-MACHINE can be invoked in lieu of make(1), and will instead call
456     the up-to-date version of ``nbmake'' installed into TOOLDIR/bin with sev-
457     eral key variables pre-set, including MACHINE, MACHINE_ARCH, and TOOLDIR.
458     This script can be symlinked into a directory listed in PATH, or called
459     with an absolute path.
460
461SEE ALSO
462     make(1), hier(7), release(7)
463
464HISTORY
465     The USE_NEW_TOOLCHAIN based build scheme was introduced in the ``NetBSD-
466     current'' development sources between NetBSD 1.5 and NetBSD 1.6.
467
468BUGS
469     Many platforms are not yet using the USE_NEW_TOOLCHAIN system.
470
471NetBSD                         October 29, 2001                              8
472