Makefile revision 1.285
1#	$NetBSD: Makefile,v 1.285 2011/06/22 05:13:20 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
204BUILD_CC_LIB_BASEDIR= gnu/lib
205BUILD_CC_LIB_BASETARGET= gnu-lib
206.else
207LIBGCC_EXT=
208BUILD_CC_LIB_BASEDIR= external/gpl3/gcc/lib
209BUILD_CC_LIB_BASETARGET= external-gpl3-gcc-lib
210.endif
211.endif
212
213BUILDTARGETS+=	check-tools
214.if ${MKUPDATE} == "no" && !defined(NOCLEANDIR)
215BUILDTARGETS+=	cleandir
216.endif
217.if ${MKOBJDIRS} != "no"
218BUILDTARGETS+=	do-top-obj
219.endif
220.if ${USETOOLS} == "yes"	# {
221.if ${MKOBJDIRS} != "no"
222BUILDTARGETS+=	do-tools-obj
223.endif
224BUILDTARGETS+=	do-tools
225.endif # USETOOLS		# }
226.if ${MKOBJDIRS} != "no"
227BUILDTARGETS+=	obj
228.endif
229BUILDTARGETS+=	clean_METALOG
230.if !defined(NODISTRIBDIRS)
231BUILDTARGETS+=	do-distrib-dirs
232.endif
233.if !defined(NOINCLUDES)
234BUILDTARGETS+=	includes
235.endif
236BUILDTARGETS+=	do-tools-compat
237BUILDTARGETS+=	do-lib-csu
238.if ${MKGCC} != "no"
239BUILDTARGETS+=	do-libgcc
240.endif
241.if ${MKPCC} != "no"
242BUILDTARGET+=	do-libpcc
243.endif
244BUILDTARGETS+=	do-lib-libc
245BUILDTARGETS+=	do-lib
246.if ${MKKMOD} != "no"
247BUILDTARGETS+=	do-sys-modules
248.endif
249BUILDTARGETS+=	do-sys-rump-dev-lib do-sys-rump-fs-lib
250BUILDTARGETS+=	do-sys-rump-kern-lib do-sys-rump-net-lib
251.if ${MKCOMPAT} != "no"
252BUILDTARGETS+=	do-compat-lib-csu
253BUILDTARGETS+=	do-compat-libgcc
254BUILDTARGETS+=	do-compat-lib-libc
255.endif
256BUILDTARGETS+=	do-ld.so
257BUILDTARGETS+=	do-build
258.if ${MKX11} != "no"
259BUILDTARGETS+=	do-x11
260.endif
261.if ${MKEXTSRC} != "no"
262BUILDTARGETS+=	do-extsrc
263.endif
264BUILDTARGETS+=	do-obsolete
265
266#
267# Enforce proper ordering of some rules.
268#
269
270.ORDER:		${BUILDTARGETS}
271includes-lib:	.PHONY includes-include includes-sys
272includes-gnu:	.PHONY includes-lib
273
274#
275# Build the system and install into DESTDIR.
276#
277
278START_TIME!=	date
279
280build: .PHONY .MAKE
281.if defined(BUILD_DONE)
282	@echo "Build already installed into ${DESTDIR}"
283.else
284	@echo "Build started at: ${START_TIME}"
285.for tgt in ${BUILDTARGETS}
286	${MAKEDIRTARGET} . ${tgt}
287.endfor
288	${MAKEDIRTARGET} etc install-etc-release
289	@echo   "Build started at:  ${START_TIME}"
290	@printf "Build finished at: " && date
291.endif
292
293#
294# Build a full distribution, but not a release (i.e. no sets into
295# ${RELEASEDIR}).  "buildworld" enforces a build to ${DESTDIR} != /
296#
297
298distribution buildworld: .PHONY .MAKE
299.if make(buildworld) && \
300    (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
301	@echo "Won't make ${.TARGET} with DESTDIR=/"
302	@false
303.endif
304	${MAKEDIRTARGET} . build NOPOSTINSTALL=1
305	${MAKEDIRTARGET} etc distribution INSTALL_DONE=1
306.if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/"
307	${MAKEDIRTARGET} . postinstall-fix-obsolete
308	${MAKEDIRTARGET} distrib/sets checkflist
309.endif
310	@echo   "make ${.TARGET} started at:  ${START_TIME}"
311	@printf "make ${.TARGET} finished at: " && date
312
313#
314# Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
315# If installing to /, ensures that the host's operating system is NetBSD and
316# the host's `uname -m` == ${MACHINE}.
317#
318
319HOST_UNAME_S!=	uname -s
320HOST_UNAME_M!=	uname -m
321
322installworld: .PHONY .MAKE
323.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
324	@echo "Can't make ${.TARGET} to DESTDIR=/"
325	@false
326.endif
327.if !defined(INSTALLWORLDDIR) || \
328    ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/"
329.if (${HOST_UNAME_S} != "NetBSD")
330	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLWORLDDIR=/"
331	@false
332.endif
333.if (${HOST_UNAME_M} != ${MACHINE})
334	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
335	@false
336.endif
337.endif
338	${MAKEDIRTARGET} distrib/sets installsets \
339		INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS=${INSTALLSETS:Q}
340	${MAKEDIRTARGET} . postinstall-check DESTDIR=${INSTALLWORLDDIR}
341	@echo   "make ${.TARGET} started at:  ${START_TIME}"
342	@printf "make ${.TARGET} finished at: " && date
343
344#
345# Create sets from $DESTDIR or $NETBSDSRCDIR into $RELEASEDIR
346#
347
348.for tgt in sets sourcesets syspkgs
349${tgt}: .PHONY .MAKE
350	${MAKEDIRTARGET} distrib/sets ${tgt}
351.endfor
352
353#
354# Build a release or snapshot (implies "make distribution").  Note that
355# in this case, the set lists will be checked before the tar files
356# are made.
357#
358
359release snapshot: .PHONY .MAKE
360	${MAKEDIRTARGET} . distribution
361	${MAKEDIRTARGET} etc release DISTRIBUTION_DONE=1
362	@echo   "make ${.TARGET} started at:  ${START_TIME}"
363	@printf "make ${.TARGET} finished at: " && date
364
365#
366# Create a CD-ROM image.
367#
368
369iso-image: .PHONY
370	${MAKEDIRTARGET} distrib iso_image
371	${MAKEDIRTARGET} etc iso-image
372	@echo   "make ${.TARGET} started at:  ${START_TIME}"
373	@printf "make ${.TARGET} finished at: " && date
374
375iso-image-source: .PHONY
376	${MAKEDIRTARGET} distrib iso_image CDSOURCE=true
377	${MAKEDIRTARGET} etc iso-image
378	@echo   "make ${.TARGET} started at:  ${START_TIME}"
379	@printf "make ${.TARGET} finished at: " && date
380
381#
382# Special components of the "make build" process.
383#
384
385check-tools: .PHONY
386.if ${TOOLCHAIN_MISSING} != "no" && !defined(EXTERNAL_TOOLCHAIN)
387	@echo '*** WARNING:  Building on MACHINE=${MACHINE} with missing toolchain.'
388	@echo '*** May result in a failed build or corrupt binaries!'
389.elif defined(EXTERNAL_TOOLCHAIN)
390	@echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
391.endif
392.if defined(NBUILDJOBS)
393	@echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
394.endif
395
396# Delete or sanitise a leftover METALOG from a previous build.
397clean_METALOG: .PHONY .MAKE
398.if ${MKUPDATE} != "no"
399	${MAKEDIRTARGET} distrib/sets clean_METALOG
400.endif
401
402do-distrib-dirs: .PHONY .MAKE
403.if !defined(DESTDIR) || ${DESTDIR} == ""
404	${MAKEDIRTARGET} etc distrib-dirs DESTDIR=/
405.else
406	${MAKEDIRTARGET} etc distrib-dirs DESTDIR=${DESTDIR}
407.endif
408
409.for targ in cleandir obj includes
410do-${targ}: .PHONY ${targ}
411	@true
412.endfor
413
414.if defined(HAVE_GCC)
415.    if ${HAVE_GCC} != 45	# XXX for now
416.if ${USE_COMPILERCRTSTUFF} == "yes"
417BUILD_CC_LIB= ${BUILD_CC_LIB_BASEDIR}/crtstuff${LIBGCC_EXT}
418.endif
419BUILD_CC_LIB+= ${BUILD_CC_LIB_BASEDIR}/libgcc${LIBGCC_EXT}
420.    endif
421.elif defined(HAVE_PCC)
422BUILD_CC_LIB+= external/bsd/pcc/crtstuff
423BUILD_CC_LIB+= external/bsd/pcc/libpcc
424.endif
425
426.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
427do-${dir:S/\//-/g}: .PHONY .MAKE
428.for targ in dependall install
429	${MAKEDIRTARGET} ${dir} ${targ}
430.endfor
431.endfor
432
433.if ${MKCOMPAT} != "no"
434COMPAT_SUBDIR_LIST=lib/csu ${BUILD_CC_LIB} lib/libc
435.for dir in ${COMPAT_SUBDIR_LIST}
436do-compat-${dir:S/\//-/g}: .PHONY .MAKE
437.for targ in dependall install
438	${MAKEDIRTARGET} compat ${targ} BOOTSTRAP_SUBDIRS="../../../${dir}"
439.endfor
440.endfor
441.endif
442
443do-top-obj: .PHONY .MAKE
444	${MAKEDIRTARGET} . obj NOSUBDIR=
445
446do-tools-obj: .PHONY .MAKE
447	${MAKEDIRTARGET} tools obj
448
449do-libgcc: .PHONY .MAKE
450.if defined(HAVE_GCC)
451.    if ${HAVE_GCC} != 45	# XXX for now
452.if ${MKGCC} != "no"
453.if ${USE_COMPILERCRTSTUFF} == "yes"
454	${MAKEDIRTARGET} . do-${BUILD_CC_LIB_BASETARGET}-crtstuff${LIBGCC_EXT}
455.endif
456	${MAKEDIRTARGET} . do-${BUILD_CC_LIB_BASETARGET}-libgcc${LIBGCC_EXT}
457.endif
458.    endif
459.endif
460
461do-compat-libgcc: .PHONY .MAKE
462.if defined(HAVE_GCC)
463.    if ${HAVE_GCC} != 45	# XXX for now
464.if ${MKGCC} != "no"
465.if ${USE_COMPILERCRTSTUFF} == "yes"
466	${MAKEDIRTARGET} . do-compat-${BUILD_CC_LIB_BASETARGET}-crtstuff${LIBGCC_EXT}
467.endif
468	${MAKEDIRTARGET} . do-compat-${BUILD_CC_LIB_BASETARGET}-libgcc${LIBGCC_EXT}
469.endif
470.    endif
471.endif
472
473do-libpcc: .PHONY .MAKE
474.if defined(HAVE_PCC)
475.if ${MKPCC} != "no"
476.if ${USE_COMPILERCRTSTUFF} == "yes"
477	${MAKEDIRTARGET} . do-pcc-lib-crtstuff
478.endif
479	${MAKEDIRTARGET} . do-pcc-lib-libpcc
480.endif
481.endif
482
483do-ld.so: .PHONY .MAKE
484.for targ in dependall install
485	${MAKEDIRTARGET} libexec/ld.elf_so ${targ}
486.endfor
487
488do-build: .PHONY .MAKE
489.for targ in dependall install
490	${MAKEDIRTARGET} . ${targ} BUILD_tools=no BUILD_lib=no
491.endfor
492
493do-x11: .PHONY .MAKE
494.if ${MKX11} != "no"
495.if ${X11FLAVOUR} == "Xorg"
496	${MAKEDIRTARGET} external/mit/xorg build
497.else
498	${MAKEDIRTARGET} x11 build
499.endif
500.else
501	@echo "MKX11 is not enabled"
502	@false
503.endif
504
505do-extsrc: .PHONY .MAKE
506.if ${MKEXTSRC} != "no"
507	${MAKEDIRTARGET} extsrc build
508.else
509	@echo "MKEXTSRC is not enabled"
510	@false
511.endif
512
513do-obsolete: .PHONY .MAKE
514	${MAKEDIRTARGET} etc install-obsolete-lists
515
516#
517# Speedup stubs for some subtrees that don't need to run these rules.
518# (Tells <bsd.subdir.mk> not to recurse for them.)
519#
520
521.for dir in bin etc distrib games libexec regress sbin usr.sbin tools
522includes-${dir}: .PHONY
523	@true
524.endfor
525.for dir in etc distrib regress
526install-${dir}: .PHONY
527	@true
528.endfor
529
530#
531# XXX this needs to change when distrib Makefiles are recursion compliant
532# XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
533#
534dependall-distrib depend-distrib all-distrib: .PHONY
535	@true
536
537.include <bsd.sys.mk>
538.include <bsd.obj.mk>
539.include <bsd.kernobj.mk>
540.include <bsd.subdir.mk>
541
542build-docs: .PHONY ${.CURDIR}/BUILDING
543${.CURDIR}/BUILDING: doc/BUILDING.mdoc
544	${_MKMSG_CREATE} ${.TARGET}
545	${TOOL_GROFF} -mdoc -Tascii -P-bou $> >$@
546
547
548#
549# Display current make(1) parameters
550#
551params: .PHONY .MAKE
552	${MAKEDIRTARGET} etc params
553