BUILDING revision 1.8 1 BUILDING(8) NetBSD System Manager's Manual BUILDING(8)
2
3 NAME
4 BUILDING - Procedure for building NetBSD from source code.
5
6 STATUS
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 default setting of USE_NEW_TOOLCHAIN in <bsd.own.mk>.
17 Platforms which have not yet been switched to the new toolchain should
18 continue building traditionally, using the notes specified in the file
19 UPDATING.
20
21 REQUIREMENTS
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
38 FILES
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
90 CONFIGURATION
91 Environment variables
92 Several environment variables control the behaviour of NetBSD builds.
93
94 MACHINE Machine type.
95
96 MACHINE_ARCH Machine architecture.
97
98 MAKE Path name to invoke make(1) as.
99
100 MAKEFLAGS Flags to invoke make(1) with.
101
102 MAKEOBJDIR Directory to use as the .OBJDIR for the current direc-
103 tory. Used only if MAKEOBJDIRPREFIX is not defined.
104 MAKEOBJDIR can only be provided in the environment.
105
106 MAKEOBJDIRPREFIX Top level directory of the object directory tree. If
107 this is defined, ${MAKEOBJDIRPREFIX}/${.CURDIR} is used
108 as the .OBJDIR for the current directory. The current
109 directory may be read only. MAKEOBJDIRPREFIX can only
110 be provided in the environment.
111
112 "make" variables
113 Several variables control the behavior of NetBSD builds. Unless other-
114 wise specified, these variables may be set in either the process environ-
115 ment or the make(1) configuration file specified by MAKECONF.
116
117 DESTDIR Directory to contain the built NetBSD system. If set, spe-
118 cial options are passed to the compilation tools to prevent
119 their default use of the host system's /usr/include,
120 /usr/lib, and so forth. This pathname should not end with a
121 slash (/) character (for installation into the system's root
122 directory, set DESTDIR to an empty string). The directory
123 must reside on a file system which supports long file names
124 and hard links.
125
126 Default: Empty string if USETOOLS is ``yes''; unset other-
127 wise.
128
129 MAKECONF The name of the make(1) configuration file. Only settable in
130 the process environment.
131
132 Default: ``/etc/mk.conf''
133
134 MKCATPAGES Can be set to ``yes'' or ``no''. Indicates whether prefor-
135 matted plaintext manual pages will be created during a build.
136
137 Default: ``yes''
138
139 MKCRYPTO Can be set to ``yes'' or ``no''. Indicates whether crypto-
140 graphic code will be included in a build; provided for the
141 benefit of countries that do not allow strong cryptography.
142 Will not affect use of the standard low-security password en-
143 cryption system, crypt(3).
144
145 Default: ``yes''
146
147 MKDOC Can be set to ``yes'' or ``no''. Indicates whether system
148 documentation destined for /usr/share/doc will be installed
149 during a build.
150
151 Default: ``yes''
152
153 MKHOSTOBJ Can be set to ``yes'' or ``no''. If set to ``yes'', then for
154 programs intended to be run on the compile host, the name,
155 release, and architecture of the host operating system will
156 be suffixed to the name of the object directory created by
157 ``make obj''. (This allows multiple host systems to compile
158 NetBSD for a single target.) If set to ``no'', then programs
159 built to be run on the compile host will use the same object
160 directory names as programs built to be run on the target.
161
162 Default: ``no''
163
164 MKINFO Can be set to ``yes'' or ``no''. Indicates whether GNU Info
165 files, used for the documentation for most of the compilation
166 tools, will be created and installed during a build.
167
168 Default: ``yes''
169
170 MKLINT Can be set to ``yes'' or ``no''. Indicates whether lint(1)
171 will be run against portions of the NetBSD source code during
172 the build, and whether lint libraries will be installed into
173 /usr/libdata/lint.
174
175 Default: ``yes''
176
177 MKMAN Can be set to ``yes'' or ``no''. Indicates whether manual
178 pages will be installed during a build.
179
180 Default: ``yes''
181
182 MKNLS Can be set to ``yes'' or ``no''. Indicates whether Native
183 Language System locale zone files will be compiled and in-
184 stalled during a build.
185
186 Default: ``yes''
187
188 MKOBJ Can be set to ``yes'' or ``no''. Indicates whether object
189 directories will be created when running ``make obj''. If
190 set to ``no'', then all built files will be located inside
191 the regular source tree.
192
193 Default: ``yes''
194
195 MKPIC Can be set to ``yes'' or ``no''. Indicates whether shared
196 objects and libraries will be created and installed during a
197 build. If set to ``no'', the entire built system will be
198 statically linked.
199
200 Default: Platform dependent. As of this writing, all plat-
201 forms except sh3 default to ``yes''.
202
203 MKPICINSTALL
204 Can be set to ``yes'' or ``no''. Indicates whether the ar(1)
205 format libraries (lib*_pic.a), used to generate shared li-
206 braries, are installed during a build.
207
208 Default: ``yes''
209
210 MKPROFILE Can be set to ``yes'' or ``no''. Indicates whether profiled
211 libraries (lib*_p.a) will be built and installed during a
212 build.
213
214 Default: ``yes''; however, some platforms turn off MKPROFILE
215 by default at times due to toolchain problems with profiled
216 code.
217
218 MKSHARE Can be set to ``yes'' or ``no''. Indicates whether files
219 destined to reside in /usr/share will be built and installed
220 during a build. If set to ``no'', then all of MKCATPAGES,
221 MKDOC, MKINFO, MKMAN, and MKNLS will be set to ``no'' uncon-
222 ditionally.
223
224 Default: ``yes''
225
226 TOOLDIR Directory to hold the host tools, once built. This directory
227 should be unique to a given host system and NetBSD source
228 tree. (However, multiple targets may share the same TOOLDIR;
229 the target-dependent files have unique names.) If unset, a
230 default based on the uname(1) information of the host plat-
231 form will be created in the .OBJDIR of src/tools.
232
233 Default: Unset.
234
235 UNPRIVED If set, then an unprivileged install will occur. The user,
236 group, permissions, and file flags, will not be set on the
237 installed item; instead the information will be appended to a
238 file called METALOG in the .OBJDIR of src. The contents of
239 METALOG is used during the generation of the distribution tar
240 files to ensure that the appropriate file ownership is
241 stored.
242
243 Default: Unset.
244
245 UPDATE If set, then all install operations intended to write to
246 DESTDIR will compare file timestamps before installing, and
247 skip the install phase if the destination files are up-to-
248 date. This also has implications on full builds (see next
249 subsection).
250
251 Default: Unset.
252
253 USETOOLS Indicates whether the tools specified by TOOLDIR should be
254 used as part of a build in progress. Must be set to ``yes''
255 if cross-compiling.
256
257 yes Use the tools from TOOLDIR.
258
259 no Do not use the tools from TOOLDIR, but refuse to build
260 native compilation tool components that are version-
261 specific for that tool.
262
263 never Do not use the tools from TOOLDIR, even when building
264 native tool components. This is similar to the tradi-
265 tional NetBSD build method, but does not verify that
266 the compilation tools in use are up-to-date enough in
267 order to build the tree successfully. This may cause
268 build or runtime problems when building the whole
269 NetBSD source tree.
270
271 Default: ``yes'' if building all or part of a whole NetBSD
272 source tree (detected automatically); ``no'' otherwise (to
273 preserve traditional semantics of the <bsd.*.mk> make(1) in-
274 clude files).
275
276 "make" variables for full builds
277 These variables only affect the top level ``Makefile'' and do not affect
278 manually building subtrees of the NetBSD source code.
279
280 MKOBJDIRS Can be set to ``yes'' or ``no''. Indicates whether object
281 directories will be created automatically (via a ``make
282 obj'' pass) at the start of a build.
283
284 Default: ``yes''
285
286 NBUILDJOBS If set, specifies the number of parallel make(1) processes
287 that should be run simultaneously. This can speed up
288 builds on SMP machines, or machines with much more CPU
289 power than I/O availability. This should be used instead
290 of the make(1) option -j, in order to ensure proper order-
291 ing of build components.
292
293 Default: Unset.
294
295 NOCLEANDIR If set, avoids the ``make cleandir'' phase of a full
296 build. This has the effect of allowing only changed files
297 in a source tree to be recompiled. This can speed up
298 builds when updating only a few files in the tree.
299
300 Default: Unset.
301
302 NODISTRIBDIRS If set, avoids the ``make distrib-dirs'' phase of a full
303 build. This skips running mtree(8) on DESTDIR, useful on
304 systems where building as an unprivileged user, or where
305 it is known that the system-wide mtree files have not
306 changed.
307
308 Default: Unset.
309
310 NOINCLUDES If set, avoids the ``make includes'' phase of a full
311 build. This has the effect of preventing make(1) from
312 thinking that some programs are out-of-date simply because
313 the system include files have changed. However, this op-
314 tion should not be used when updating the entire NetBSD
315 source tree arbitrarily; it is suggested to use UPDATE in
316 that case.
317
318 Default: Unset.
319
320 RELEASEDIR If set, specifies the directory to which a release(7) lay-
321 out will be written at the end of a ``make release''.
322
323 Default: Unset.
324
325 UPDATE If set, then in addition to the effects described for UP-
326 DATE above, this implies the effects of NOCLEANDIR.
327
328 BUILDING
329 "make" command line options
330 This is only a summary of options available to make(1); only the options
331 used most frequently with NetBSD builds are listed here.
332
333 -m dir Specify the default directory for searching for system Make-
334 file segments, mainly the <bsd.*.mk> files. When building any
335 full NetBSD source tree, this should be set to the
336 ``share/mk'' directory in the source tree. (This is set auto-
337 matically when building from the top level.)
338
339 -n Display the commands that would have been executed, but do not
340 actually execute them. This will still cause recursion to
341 take place.
342
343 -v var Print make(1)'s idea of the value of var. Does not build any
344 targets.
345
346 var=value Set the variable var to value, overriding any setting speci-
347 fied by the process environment, the MAKECONF configuration
348 file, or the system Makefile segments.
349
350 "make" targets
351 These default targets may be built by running make(1) in any subtree of
352 the NetBSD source code. It is recommended that none of these be used
353 from the top level Makefile; as a specific exception, ``make obj'' and
354 ``make cleandir'' are useful in that context.
355
356 all Build programs, libraries, and preformatted documentation.
357
358 clean Remove program and library object code files.
359
360 cleandir Same as clean, but also remove preformatted documentation, de-
361 pendency files generated by ``make depend'', and any other
362 files known to be created at build time. ``make distclean''
363 may be used as a synonym, for familiarity with a similar well-
364 known convention.
365
366 depend Create dependency files (.depend) containing more detailed in-
367 formation about the dependencies of source code on header
368 files. Allows programs to be recompiled automatically when a
369 dependency changes.
370
371 dependall Does a ``make depend'' immediately followed by a ``make all''.
372 This combined target recurses as an atomic unit, so that the
373 ``make depend'' phase can participate in make -j parallelism.
374
375 includes Build and install system header files. Typically needed be-
376 fore any system libraries or programs can be built.
377
378 install Install programs, libraries, and documentation into DESTDIR.
379
380 lint Run lint(1) against the C source code, where appropriate, and
381 generate system-installed lint libraries.
382
383 obj Create object directories to be used for built files, instead
384 of building directly in the source tree.
385
386 tags Create ctags(1) searchable function lists usable by the ex(1)
387 and vi(1) text editors.
388
389 "make" targets for the top level
390 Additional make(1) targets are usable specifically from the top source
391 level to facilitate building the entire NetBSD source tree.
392
393 build Build the entire NetBSD system. This orders portions of the
394 source tree such that prerequisites will be built in the prop-
395 er order.
396
397 release Do a ``make build'', then package the system into a standard
398 release layout as described by release(7). This requires that
399 RELEASEDIR be set (see above).
400
401 regression-tests
402 Can only be run after building the regression tests in the di-
403 rectory ``regress''. Runs the compiled regression tests on
404 the local host.
405
406 The "build.sh" script
407 This script file is a Bourne shell script designed to build the entire
408 NetBSD system on any host with a Bourne shell in /bin/sh, including many
409 that are not POSIX compliant. Note that if a host system's /bin/sh is
410 unusually old and broken, the Korn Shell (/bin/ksh), if available, may be
411 a usable alternative.
412
413 All cross-compile builds, and most native builds, of the entire system
414 should make use of build.sh rather than just running ``make''. This way,
415 the make(1) program will be bootstrapped properly, in case the host sys-
416 tem has an older or incompatible ``make'' program.
417
418 When compiling the entire system via build.sh, many make(1) variables are
419 set for you in order to help encapsulate the build process. In the list
420 of options below, variables that are automatically set by build.sh are
421 noted where applicable.
422
423 The following are available command line options that may be supplied to
424 build.sh:
425
426 -a arch Set the value of MACHINE_ARCH to arch.
427
428 -b Bootstrap ``make'' and create a nbmake-MACHINE script (see be-
429 low).
430
431 -d Build a full distribution. This differs from a normal build in
432 that etc files will also be installed. Note this does not
433 build a ``release''; no release sets are placed in ${RE-
434 LEASEDIR}.
435
436 -j njob Set the value of NBUILDJOBS to njob. This provides similar
437 functionality to the familiar ``make -j'', but preserves the
438 ordering of the top level ``make build''.
439
440 -m mach Set the value of MACHINE to mach. This will also override any
441 value of MACHINE_ARCH in the process environment with a value
442 deduced from mach, unless -a is specified. All cross builds
443 require -m, but if unset on a NetBSD host, the host's value of
444 MACHINE will be detected and used automatically.
445
446 -n Show the commands that would be executed by build.sh, but do
447 not make any changes. This is similar in concept to ``make
448 -n''.
449
450 -o Set the value of MKOBJDIRS to ``no''.
451
452 -r Remove the contents of DESTDIR and TOOLDIR before building
453 (provides a clean starting point). This will skip deleting
454 DESTDIR if building on a native system to the root directory.
455
456 -t Build and install the host tools from src/tools only. This op-
457 tion implies -b.
458
459 -u Set the UPDATE variable.
460
461 -w wrapper
462 Create the nbmake wrapper script (see below) in a custom loca-
463 tion, specified by wrapper. This allows, for instance, to
464 place the wrapper in PATH automatically. Note that wrapper is
465 the full name of the file, not just a directory name.
466
467 -D dest Set the value of DESTDIR to dest.
468
469 -O obj Create an appropriate transform macro for MAKEOBJDIR that will
470 place the built object files under obj. For instance, a set-
471 ting of /usr/obj will place build-time files files under
472 /usr/obj/bin, /usr/obj/lib, and so forth.
473
474 -R rel Set the value of RELEASEDIR to rel. Setting this option will
475 cause build.sh to run ``make release'' instead of ``make
476 build''.
477
478 -T tools Set the value of TOOLDIR to tools. If set, the bootstrap
479 ``make'' will only be rebuilt as needed (when the source files
480 for make(1) change).
481
482 -U Set the UNPRIVED variable.
483
484 The "nbmake-MACHINE" wrapper script
485 If using the build.sh script to build NetBSD, a nbmake-MACHINE script
486 will be created in TOOLDIR/bin upon the first build to assist in building
487 subtrees on a cross-compile host.
488
489 nbmake-MACHINE can be invoked in lieu of make(1), and will instead call
490 the up-to-date version of ``nbmake'' installed into TOOLDIR/bin with sev-
491 eral key variables pre-set, including MACHINE, MACHINE_ARCH, and TOOLDIR.
492 This script can be symlinked into a directory listed in PATH, or called
493 with an absolute path.
494
495 SEE ALSO
496 make(1), hier(7), release(7)
497
498 HISTORY
499 The USE_NEW_TOOLCHAIN based build scheme was introduced in the ``NetBSD-
500 current'' development sources between NetBSD 1.5 and NetBSD 1.6.
501
502 BUGS
503 Many platforms are not yet using the USE_NEW_TOOLCHAIN system.
504
505 NetBSD March 5, 2002 8
506