Makefile revision 1.280 1 # $NetBSD: Makefile,v 1.280 2010/11/28 18:40:54 skrll Exp $
2
3 #
4 # This is the top-level makefile for building NetBSD. For an outline of
5 # how to build a snapshot or release, as well as other release engineering
6 # information, see http://www.NetBSD.org/developers/releng/index.html
7 #
8 # Not everything you can set or do is documented in this makefile. In
9 # particular, you should review the files in /usr/share/mk (especially
10 # bsd.README) for general information on building programs and writing
11 # Makefiles within this structure, and see the comments in src/etc/Makefile
12 # for further information on installation and release set options.
13 #
14 # Variables listed below can be set on the make command line (highest
15 # priority), in /etc/mk.conf (middle priority), or in the environment
16 # (lowest priority).
17 #
18 # Variables:
19 # DESTDIR is the target directory for installation of the compiled
20 # software. It defaults to /. Note that programs are built against
21 # libraries installed in DESTDIR.
22 # MKMAN, if `no', will prevent building of manual pages.
23 # MKOBJDIRS, if not `no', will build object directories at
24 # an appropriate point in a build.
25 # MKSHARE, if `no', will prevent building and installing
26 # anything in /usr/share.
27 # MKUPDATE, if not `no', will avoid a `make cleandir' at the start of
28 # `make build', as well as having the effects listed in
29 # /usr/share/mk/bsd.README.
30 # NOCLEANDIR, if defined, will avoid a `make cleandir' at the start
31 # of the `make build'.
32 # NOINCLUDES will avoid the `make includes' usually done by `make build'.
33 #
34 # See mk.conf(5) for more details.
35 #
36 #
37 # Targets:
38 # build:
39 # Builds a full release of NetBSD in DESTDIR, except for the
40 # /etc configuration files.
41 # If BUILD_DONE is set, this is an empty target.
42 # distribution:
43 # Builds a full release of NetBSD in DESTDIR, including the /etc
44 # configuration files.
45 # buildworld:
46 # As per `make distribution', except that it ensures that DESTDIR
47 # is not the root directory.
48 # installworld:
49 # Install the distribution from DESTDIR to INSTALLWORLDDIR (which
50 # defaults to the root directory). Ensures that INSTALLWORLDDIR
51 # is the not root directory if cross compiling.
52 # release:
53 # Does a `make distribution', and then tars up the DESTDIR files
54 # into ${RELEASEDIR}/${RELEASEMACHINEDIR}, in release(7) format.
55 # (See etc/Makefile for more information on this.)
56 # regression-tests:
57 # Runs the regression tests in "regress" on this host.
58 # sets:
59 # Populate ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
60 # from ${DESTDIR}
61 # sourcesets:
62 # Populate ${RELEASEDIR}/source/sets from ${NETBSDSRCDIR}
63 # syspkgs:
64 # Populate ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/syspkgs
65 # from ${DESTDIR}
66 # iso-image:
67 # Create CD-ROM image in RELEASEDIR/iso.
68 # RELEASEDIR must already have been populated by `make release'
69 # or equivalent.
70 # iso-image-source:
71 # Create CD-ROM image with source in RELEASEDIR/iso.
72 # RELEASEDIR must already have been populated by
73 # `make release sourcesets' or equivalent.
74 #
75 # Targets invoked by `make build,' in order:
76 # cleandir: cleans the tree.
77 # do-top-obj: creates the top level object directory.
78 # do-tools-obj: creates object directories for the host toolchain.
79 # do-tools: builds host toolchain.
80 # obj: creates object directories.
81 # do-distrib-dirs: creates the distribution directories.
82 # includes: installs include files.
83 # do-tools-compat: builds the "libnbcompat" library; needed for some
84 # random host tool programs in the source tree.
85 # do-lib-csu: builds and installs prerequisites from lib/csu.
86 # do-libgcc: builds and installs prerequisites from
87 # gnu/lib/crtstuff${LIBGCC_EXT} (if necessary) and
88 # gnu/lib/libgcc${LIBGCC_EXT}.
89 # do-libpcc: builds and install prerequisites from
90 # external/bsd/pcc/crtstuff (if necessary) and
91 # external/bsd/pcc/libpcc.
92 # do-lib-libc: builds and installs prerequisites from lib/libc.
93 # do-lib: builds and installs prerequisites from lib.
94 # do-gnu-lib: builds and installs prerequisites from gnu/lib.
95 # do-external-lib: builds and installs prerequisites from external/lib.
96 # do-sys-rump-dev-lib: builds and installs prerequisites from sys/rump/dev/lib
97 # do-sys-rump-fs-lib: builds and installs prerequisites from sys/rump/fs/lib
98 # do-sys-rump-kern-lib: builds and installs prereq. from sys/rump/kern/lib
99 # do-sys-rump-net-lib: builds and installs prerequisites from sys/rump/net/lib
100 # do-sys-modules: builds and installs kernel modules (used by rump binaries)
101 # do-ld.so: builds and installs prerequisites from libexec/ld.*_so.
102 # do-compat-lib-csu: builds and installs prerequisites from compat/lib/csu
103 # if ${MKCOMPAT} != "no".
104 # do-compat-libgcc: builds and installs prerequisites from
105 # compat/gnu/lib/crtstuff${LIBGCC_EXT} (if necessary) and
106 # compat/gnu/lib/libgcc${LIBGCC_EXT} if ${MKCOMPAT} != "no".
107 # do-compat-lib-libc: builds and installs prerequisites from compat/lib/libc
108 # if ${MKCOMPAT} != "no".
109 # do-build: builds and installs the entire system.
110 # do-x11: builds and installs X11 if ${MKX11} != "no"; either
111 # X11R7 from src/external/mit/xorg if ${X11FLAVOUR} == "Xorg"
112 # or X11R6 from src/x11
113 # do-extsrc: builds and installs extsrc if ${MKEXTSRC} != "no".
114 # do-obsolete: installs the obsolete sets (for the postinstall-* targets).
115 #
116
117 .if ${.MAKEFLAGS:M${.CURDIR}/share/mk} == ""
118 .MAKEFLAGS: -m ${.CURDIR}/share/mk
119 .endif
120
121 #
122 # If _SRC_TOP_OBJ_ gets set here, we will end up with a directory that may
123 # not be the top level objdir, because "make obj" can happen in the *middle*
124 # of "make build" (long after <bsd.own.mk> is calculated it). So, pre-set
125 # _SRC_TOP_OBJ_ here so it will not be added to ${.MAKEOVERRIDES}.
126 #
127 _SRC_TOP_OBJ_=
128
129 .include <bsd.own.mk>
130
131 #
132 # Sanity check: make sure that "make build" is not invoked simultaneously
133 # with a standard recursive target.
134 #
135
136 .if make(build) || make(release) || make(snapshot)
137 .for targ in ${TARGETS:Nobj:Ncleandir}
138 .if make(${targ}) && !target(.BEGIN)
139 .BEGIN:
140 @echo 'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
141 @false
142 .endif
143 .endfor
144 .endif
145
146 #
147 # _SUBDIR is used to set SUBDIR, after removing directories that have
148 # BUILD_${dir}=no, or that have no ${dir}/Makefile.
149 #
150 _SUBDIR= tools lib include gnu external crypto/external bin games
151 _SUBDIR+= libexec sbin usr.bin
152 _SUBDIR+= usr.sbin share rescue sys etc tests compat .WAIT distrib regress
153
154 .for dir in ${_SUBDIR}
155 .if "${dir}" == ".WAIT" \
156 || (${BUILD_${dir}:Uyes} != "no" && exists(${dir}/Makefile))
157 SUBDIR+= ${dir}
158 .endif
159 .endfor
160
161 .if exists(regress)
162 regression-tests: .PHONY .MAKE
163 @echo Running regression tests...
164 ${MAKEDIRTARGET} regress regress
165 .endif
166
167 .if ${MKUNPRIVED} != "no"
168 NOPOSTINSTALL= # defined
169 .endif
170
171 afterinstall: .PHONY .MAKE
172 .if ${MKMAN} != "no"
173 ${MAKEDIRTARGET} share/man makedb
174 .endif
175 .if (${MKUNPRIVED} != "no" && ${MKINFO} != "no")
176 ${MAKEDIRTARGET} gnu/usr.bin/texinfo/install-info infodir-meta
177 .endif
178 .if !defined(NOPOSTINSTALL)
179 ${MAKEDIRTARGET} . postinstall-check
180 .endif
181
182 _POSTINSTALL= ${.CURDIR}/usr.sbin/postinstall/postinstall
183
184 postinstall-check: .PHONY
185 @echo " === Post installation checks ==="
186 AWK=${TOOL_AWK:Q} MAKE=${MAKE:Q} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} -d ${DESTDIR}/ check; if [ $$? -gt 1 ]; then exit 1; fi
187 @echo " ================================"
188
189 postinstall-fix: .NOTMAIN .PHONY
190 @echo " === Post installation fixes ==="
191 AWK=${TOOL_AWK:Q} MAKE=${MAKE:Q} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} -d ${DESTDIR}/ fix
192 @echo " ==============================="
193
194 postinstall-fix-obsolete: .NOTMAIN .PHONY
195 @echo " === Removing obsolete files ==="
196 AWK=${TOOL_AWK:Q} MAKE=${MAKE:Q} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} -d ${DESTDIR}/ fix obsolete
197 @echo " ==============================="
198
199
200 #
201 # Targets (in order!) called by "make build".
202 #
203 .if defined(HAVE_GCC)
204 .if ${HAVE_GCC} == "3"
205 LIBGCC_EXT=3
206 .else
207 LIBGCC_EXT=4
208 .endif
209 .endif
210
211 BUILDTARGETS+= check-tools
212 .if ${MKUPDATE} == "no" && !defined(NOCLEANDIR)
213 BUILDTARGETS+= cleandir
214 .endif
215 .if ${MKOBJDIRS} != "no"
216 BUILDTARGETS+= do-top-obj
217 .endif
218 .if ${USETOOLS} == "yes" # {
219 .if ${MKOBJDIRS} != "no"
220 BUILDTARGETS+= do-tools-obj
221 .endif
222 BUILDTARGETS+= do-tools
223 .endif # USETOOLS # }
224 .if ${MKOBJDIRS} != "no"
225 BUILDTARGETS+= obj
226 .endif
227 BUILDTARGETS+= clean_METALOG
228 .if !defined(NODISTRIBDIRS)
229 BUILDTARGETS+= do-distrib-dirs
230 .endif
231 .if !defined(NOINCLUDES)
232 BUILDTARGETS+= includes
233 .endif
234 BUILDTARGETS+= do-tools-compat
235 BUILDTARGETS+= do-lib-csu
236 .if ${MKGCC} != "no"
237 BUILDTARGETS+= do-libgcc
238 .endif
239 .if ${MKPCC} != "no"
240 BUILDTARGET+= do-libpcc
241 .endif
242 BUILDTARGETS+= do-lib-libc
243 BUILDTARGETS+= do-lib do-gnu-lib do-external-lib
244 .if (${MACHINE} != "evbppc") && ${MKKMOD} != "no"
245 BUILDTARGETS+= do-sys-modules
246 .endif
247 BUILDTARGETS+= do-sys-rump-dev-lib do-sys-rump-fs-lib
248 BUILDTARGETS+= do-sys-rump-kern-lib do-sys-rump-net-lib
249 .if ${MKCOMPAT} != "no"
250 BUILDTARGETS+= do-compat-lib-csu
251 BUILDTARGETS+= do-compat-libgcc
252 BUILDTARGETS+= do-compat-lib-libc
253 .endif
254 BUILDTARGETS+= do-ld.so
255 BUILDTARGETS+= do-build
256 .if ${MKX11} != "no"
257 BUILDTARGETS+= do-x11
258 .endif
259 .if ${MKEXTSRC} != "no"
260 BUILDTARGETS+= do-extsrc
261 .endif
262 BUILDTARGETS+= do-obsolete
263
264 #
265 # Enforce proper ordering of some rules.
266 #
267
268 .ORDER: ${BUILDTARGETS}
269 includes-lib: .PHONY includes-include includes-sys
270 includes-gnu: .PHONY includes-lib
271
272 #
273 # Build the system and install into DESTDIR.
274 #
275
276 START_TIME!= date
277
278 build: .PHONY .MAKE
279 .if defined(BUILD_DONE)
280 @echo "Build already installed into ${DESTDIR}"
281 .else
282 @echo "Build started at: ${START_TIME}"
283 .for tgt in ${BUILDTARGETS}
284 ${MAKEDIRTARGET} . ${tgt}
285 .endfor
286 ${MAKEDIRTARGET} etc install-etc-release
287 @echo "Build started at: ${START_TIME}"
288 @printf "Build finished at: " && date
289 .endif
290
291 #
292 # Build a full distribution, but not a release (i.e. no sets into
293 # ${RELEASEDIR}). "buildworld" enforces a build to ${DESTDIR} != /
294 #
295
296 distribution buildworld: .PHONY .MAKE
297 .if make(buildworld) && \
298 (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
299 @echo "Won't make ${.TARGET} with DESTDIR=/"
300 @false
301 .endif
302 ${MAKEDIRTARGET} . build NOPOSTINSTALL=1
303 ${MAKEDIRTARGET} etc distribution INSTALL_DONE=1
304 .if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/"
305 ${MAKEDIRTARGET} . postinstall-fix-obsolete
306 ${MAKEDIRTARGET} distrib/sets checkflist
307 .endif
308 @echo "make ${.TARGET} started at: ${START_TIME}"
309 @printf "make ${.TARGET} finished at: " && date
310
311 #
312 # Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
313 # If installing to /, ensures that the host's operating system is NetBSD and
314 # the host's `uname -m` == ${MACHINE}.
315 #
316
317 HOST_UNAME_S!= uname -s
318 HOST_UNAME_M!= uname -m
319
320 installworld: .PHONY .MAKE
321 .if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
322 @echo "Can't make ${.TARGET} to DESTDIR=/"
323 @false
324 .endif
325 .if !defined(INSTALLWORLDDIR) || \
326 ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/"
327 .if (${HOST_UNAME_S} != "NetBSD")
328 @echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLWORLDDIR=/"
329 @false
330 .endif
331 .if (${HOST_UNAME_M} != ${MACHINE})
332 @echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
333 @false
334 .endif
335 .endif
336 ${MAKEDIRTARGET} distrib/sets installsets \
337 INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS=
338 ${MAKEDIRTARGET} . postinstall-check DESTDIR=${INSTALLWORLDDIR}
339 @echo "make ${.TARGET} started at: ${START_TIME}"
340 @printf "make ${.TARGET} finished at: " && date
341
342 #
343 # Create sets from $DESTDIR or $NETBSDSRCDIR into $RELEASEDIR
344 #
345
346 .for tgt in sets sourcesets syspkgs
347 ${tgt}: .PHONY .MAKE
348 ${MAKEDIRTARGET} distrib/sets ${tgt}
349 .endfor
350
351 #
352 # Build a release or snapshot (implies "make distribution"). Note that
353 # in this case, the set lists will be checked before the tar files
354 # are made.
355 #
356
357 release snapshot: .PHONY .MAKE
358 ${MAKEDIRTARGET} . distribution
359 ${MAKEDIRTARGET} etc release DISTRIBUTION_DONE=1
360 @echo "make ${.TARGET} started at: ${START_TIME}"
361 @printf "make ${.TARGET} finished at: " && date
362
363 #
364 # Create a CD-ROM image.
365 #
366
367 iso-image: .PHONY
368 ${MAKEDIRTARGET} distrib iso_image
369 ${MAKEDIRTARGET} etc iso-image
370 @echo "make ${.TARGET} started at: ${START_TIME}"
371 @printf "make ${.TARGET} finished at: " && date
372
373 iso-image-source: .PHONY
374 ${MAKEDIRTARGET} distrib iso_image CDSOURCE=true
375 ${MAKEDIRTARGET} etc iso-image
376 @echo "make ${.TARGET} started at: ${START_TIME}"
377 @printf "make ${.TARGET} finished at: " && date
378
379 #
380 # Special components of the "make build" process.
381 #
382
383 check-tools: .PHONY
384 .if ${TOOLCHAIN_MISSING} != "no" && !defined(EXTERNAL_TOOLCHAIN)
385 @echo '*** WARNING: Building on MACHINE=${MACHINE} with missing toolchain.'
386 @echo '*** May result in a failed build or corrupt binaries!'
387 .elif defined(EXTERNAL_TOOLCHAIN)
388 @echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
389 .endif
390 .if defined(NBUILDJOBS)
391 @echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
392 .endif
393
394 # Delete or sanitise a leftover METALOG from a previous build.
395 clean_METALOG: .PHONY .MAKE
396 .if ${MKUPDATE} != "no"
397 ${MAKEDIRTARGET} distrib/sets clean_METALOG
398 .endif
399
400 do-distrib-dirs: .PHONY .MAKE
401 .if !defined(DESTDIR) || ${DESTDIR} == ""
402 ${MAKEDIRTARGET} etc distrib-dirs DESTDIR=/
403 .else
404 ${MAKEDIRTARGET} etc distrib-dirs DESTDIR=${DESTDIR}
405 .endif
406
407 .for targ in cleandir obj includes
408 do-${targ}: .PHONY ${targ}
409 @true
410 .endfor
411
412 .if defined(HAVE_GCC)
413 .if ${USE_COMPILERCRTSTUFF} == "yes"
414 BUILD_CC_LIB= gnu/lib/crtstuff${LIBGCC_EXT}
415 .endif
416 BUILD_CC_LIB+= gnu/lib/libgcc${LIBGCC_EXT}
417 .elif defined(HAVE_PCC)
418 BUILD_CC_LIB+= external/bsd/pcc/crtstuff
419 BUILD_CC_LIB+= external/bsd/pcc/libpcc
420 .endif
421
422 .for dir in tools tools/compat lib/csu ${BUILD_CC_LIB} lib/libc lib gnu/lib external/lib crypto/external/lib sys/rump/dev/lib sys/rump/fs/lib sys/rump/kern/lib sys/rump/net/lib sys/modules
423 do-${dir:S/\//-/g}: .PHONY .MAKE
424 .for targ in dependall install
425 ${MAKEDIRTARGET} ${dir} ${targ}
426 .endfor
427 .endfor
428
429 .if ${MKCOMPAT} != "no"
430 COMPAT_SUBDIR_LIST=lib/csu ${BUILD_CC_LIB} lib/libc
431 .for dir in ${COMPAT_SUBDIR_LIST}
432 do-compat-${dir:S/\//-/g}: .PHONY .MAKE
433 .for targ in obj dependall install
434 ${MAKEDIRTARGET} compat ${targ} BOOTSTRAP_SUBDIRS="../../../${dir}"
435 .endfor
436 .endfor
437 .endif
438
439 do-top-obj: .PHONY .MAKE
440 ${MAKEDIRTARGET} . obj NOSUBDIR=
441
442 do-tools-obj: .PHONY .MAKE
443 ${MAKEDIRTARGET} tools obj
444
445 do-libgcc: .PHONY .MAKE
446 .if defined(HAVE_GCC)
447 .if ${MKGCC} != "no"
448 .if ${USE_COMPILERCRTSTUFF} == "yes"
449 .if (${HAVE_GCC} == "3" || ${HAVE_GCC} == "4")
450 ${MAKEDIRTARGET} . do-gnu-lib-crtstuff${LIBGCC_EXT}
451 .endif
452 .endif
453 ${MAKEDIRTARGET} . do-gnu-lib-libgcc${LIBGCC_EXT}
454 .endif
455 .endif
456
457 do-compat-libgcc: .PHONY .MAKE
458 .if defined(HAVE_GCC)
459 .if ${MKGCC} != "no"
460 .if ${USE_COMPILERCRTSTUFF} == "yes"
461 ${MAKEDIRTARGET} . do-compat-gnu-lib-crtstuff${LIBGCC_EXT}
462 .endif
463 ${MAKEDIRTARGET} . do-compat-gnu-lib-libgcc${LIBGCC_EXT}
464 .endif
465 .endif
466
467 do-libpcc: .PHONY .MAKE
468 .if defined(HAVE_PCC)
469 .if ${MKPCC} != "no"
470 .if ${USE_COMPILERCRTSTUFF} == "yes"
471 ${MAKEDIRTARGET} . do-pcc-lib-crtstuff
472 .endif
473 ${MAKEDIRTARGET} . do-pcc-lib-libpcc
474 .endif
475 .endif
476
477 do-ld.so: .PHONY .MAKE
478 .for targ in dependall install
479 ${MAKEDIRTARGET} libexec/ld.elf_so ${targ}
480 .endfor
481
482 do-build: .PHONY .MAKE
483 .for targ in dependall install
484 ${MAKEDIRTARGET} . ${targ} BUILD_tools=no BUILD_lib=no
485 .endfor
486
487 do-x11: .PHONY .MAKE
488 .if ${MKX11} != "no"
489 .if ${X11FLAVOUR} == "Xorg"
490 ${MAKEDIRTARGET} external/mit/xorg build
491 .else
492 ${MAKEDIRTARGET} x11 build
493 .endif
494 .else
495 @echo "MKX11 is not enabled"
496 @false
497 .endif
498
499 do-extsrc: .PHONY .MAKE
500 .if ${MKEXTSRC} != "no"
501 ${MAKEDIRTARGET} extsrc build
502 .else
503 @echo "MKEXTSRC is not enabled"
504 @false
505 .endif
506
507 do-obsolete: .PHONY .MAKE
508 ${MAKEDIRTARGET} etc install-obsolete-lists
509
510 #
511 # Speedup stubs for some subtrees that don't need to run these rules.
512 # (Tells <bsd.subdir.mk> not to recurse for them.)
513 #
514
515 .for dir in bin etc distrib games libexec regress sbin usr.sbin tools
516 includes-${dir}: .PHONY
517 @true
518 .endfor
519 .for dir in etc distrib regress
520 install-${dir}: .PHONY
521 @true
522 .endfor
523
524 #
525 # XXX this needs to change when distrib Makefiles are recursion compliant
526 # XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
527 #
528 dependall-distrib depend-distrib all-distrib: .PHONY
529 @true
530
531 .include <bsd.sys.mk>
532 .include <bsd.obj.mk>
533 .include <bsd.kernobj.mk>
534 .include <bsd.subdir.mk>
535
536 build-docs: .PHONY ${.CURDIR}/BUILDING
537 ${.CURDIR}/BUILDING: doc/BUILDING.mdoc
538 ${_MKMSG_CREATE} ${.TARGET}
539 ${TOOL_GROFF} -mdoc -Tascii -P-bou $> >$@
540
541
542 #
543 # Display current make(1) parameters
544 #
545 params: .PHONY .MAKE
546 ${MAKEDIRTARGET} etc params
547