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