Makefile revision 1.289
1#	$NetBSD: Makefile,v 1.289 2011/09/09 14:23:37 apb 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# Install modules from $DESTDIR to $INSTALLMODULESDIR
346#
347installmodules: .PHONY .MAKE
348.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
349	@echo "Can't make ${.TARGET} to DESTDIR=/"
350	@false
351.endif
352.if !defined(INSTALLMODULESDIR) || \
353    ${INSTALLMODULESDIR} == "" || ${INSTALLMODULESDIR} == "/"
354.if (${HOST_UNAME_S} != "NetBSD")
355	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLMODULESDIR=/"
356	@false
357.endif
358.if (${HOST_UNAME_M} != ${MACHINE})
359	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLMODULESDIR=/"
360	@false
361.endif
362.endif
363	${MAKEDIRTARGET} sys/modules install DESTDIR=${INSTALLMODULESDIR:U/}
364	@echo   "make ${.TARGET} started at:  ${START_TIME}"
365	@printf "make ${.TARGET} finished at: " && date
366
367#
368# Create sets from $DESTDIR or $NETBSDSRCDIR into $RELEASEDIR
369#
370
371.for tgt in sets sourcesets syspkgs
372${tgt}: .PHONY .MAKE
373	${MAKEDIRTARGET} distrib/sets ${tgt}
374.endfor
375
376#
377# Build a release or snapshot (implies "make distribution").  Note that
378# in this case, the set lists will be checked before the tar files
379# are made.
380#
381
382release snapshot: .PHONY .MAKE
383	${MAKEDIRTARGET} . distribution
384	${MAKEDIRTARGET} etc release DISTRIBUTION_DONE=1
385	@echo   "make ${.TARGET} started at:  ${START_TIME}"
386	@printf "make ${.TARGET} finished at: " && date
387
388#
389# Create a CD-ROM image.
390#
391
392iso-image: .PHONY
393	${MAKEDIRTARGET} distrib iso_image
394	${MAKEDIRTARGET} etc iso-image
395	@echo   "make ${.TARGET} started at:  ${START_TIME}"
396	@printf "make ${.TARGET} finished at: " && date
397
398iso-image-source: .PHONY
399	${MAKEDIRTARGET} distrib iso_image CDSOURCE=true
400	${MAKEDIRTARGET} etc iso-image
401	@echo   "make ${.TARGET} started at:  ${START_TIME}"
402	@printf "make ${.TARGET} finished at: " && date
403
404#
405# Special components of the "make build" process.
406#
407
408check-tools: .PHONY
409.if ${TOOLCHAIN_MISSING} != "no" && !defined(EXTERNAL_TOOLCHAIN)
410	@echo '*** WARNING:  Building on MACHINE=${MACHINE} with missing toolchain.'
411	@echo '*** May result in a failed build or corrupt binaries!'
412.elif defined(EXTERNAL_TOOLCHAIN)
413	@echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
414.endif
415.if defined(NBUILDJOBS)
416	@echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
417.endif
418
419# Delete or sanitise a leftover METALOG from a previous build.
420clean_METALOG: .PHONY .MAKE
421.if ${MKUPDATE} != "no"
422	${MAKEDIRTARGET} distrib/sets clean_METALOG
423.endif
424
425do-distrib-dirs: .PHONY .MAKE
426.if !defined(DESTDIR) || ${DESTDIR} == ""
427	${MAKEDIRTARGET} etc distrib-dirs DESTDIR=/
428.else
429	${MAKEDIRTARGET} etc distrib-dirs DESTDIR=${DESTDIR}
430.endif
431
432.for targ in cleandir obj includes
433do-${targ}: .PHONY ${targ}
434	@true
435.endfor
436
437.if defined(HAVE_GCC)
438.if ${USE_COMPILERCRTSTUFF} == "yes"
439BUILD_CC_LIB= ${BUILD_CC_LIB_BASEDIR}/crtstuff${LIBGCC_EXT}
440.endif
441BUILD_CC_LIB+= ${BUILD_CC_LIB_BASEDIR}/libgcc${LIBGCC_EXT}
442.elif defined(HAVE_PCC)
443BUILD_CC_LIB+= external/bsd/pcc/crtstuff
444BUILD_CC_LIB+= external/bsd/pcc/libpcc
445.endif
446
447.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
448do-${dir:S/\//-/g}: .PHONY .MAKE
449.for targ in dependall install
450	${MAKEDIRTARGET} ${dir} ${targ}
451.endfor
452.endfor
453
454.if ${MKCOMPAT} != "no"
455COMPAT_SUBDIR_LIST=lib/csu ${BUILD_CC_LIB} lib/libc
456.for dir in ${COMPAT_SUBDIR_LIST}
457do-compat-${dir:S/\//-/g}: .PHONY .MAKE
458.for targ in dependall install
459	${MAKEDIRTARGET} compat ${targ} BOOTSTRAP_SUBDIRS="../../../${dir}"
460.endfor
461.endfor
462.endif
463
464do-top-obj: .PHONY .MAKE
465	${MAKEDIRTARGET} . obj NOSUBDIR=
466
467do-tools-obj: .PHONY .MAKE
468	${MAKEDIRTARGET} tools obj
469
470do-libgcc: .PHONY .MAKE
471.if defined(HAVE_GCC)
472.if ${MKGCC} != "no"
473.if ${USE_COMPILERCRTSTUFF} == "yes"
474	${MAKEDIRTARGET} . do-${BUILD_CC_LIB_BASETARGET}-crtstuff${LIBGCC_EXT}
475.endif
476	${MAKEDIRTARGET} . do-${BUILD_CC_LIB_BASETARGET}-libgcc${LIBGCC_EXT}
477.endif
478.endif
479
480do-compat-libgcc: .PHONY .MAKE
481.if defined(HAVE_GCC)
482.if ${MKGCC} != "no"
483.if ${USE_COMPILERCRTSTUFF} == "yes"
484	${MAKEDIRTARGET} . do-compat-${BUILD_CC_LIB_BASETARGET}-crtstuff${LIBGCC_EXT}
485.endif
486	${MAKEDIRTARGET} . do-compat-${BUILD_CC_LIB_BASETARGET}-libgcc${LIBGCC_EXT}
487.endif
488.endif
489
490do-libpcc: .PHONY .MAKE
491.if defined(HAVE_PCC)
492.if ${MKPCC} != "no"
493.if ${USE_COMPILERCRTSTUFF} == "yes"
494	${MAKEDIRTARGET} . do-pcc-lib-crtstuff
495.endif
496	${MAKEDIRTARGET} . do-pcc-lib-libpcc
497.endif
498.endif
499
500do-ld.so: .PHONY .MAKE
501.for targ in dependall install
502	${MAKEDIRTARGET} libexec/ld.elf_so ${targ}
503.endfor
504
505do-build: .PHONY .MAKE
506.for targ in dependall install
507	${MAKEDIRTARGET} . ${targ} BUILD_tools=no BUILD_lib=no
508.endfor
509
510do-x11: .PHONY .MAKE
511.if ${MKX11} != "no"
512.if ${X11FLAVOUR} == "Xorg"
513	${MAKEDIRTARGET} external/mit/xorg build
514.else
515	${MAKEDIRTARGET} x11 build
516.endif
517.else
518	@echo "MKX11 is not enabled"
519	@false
520.endif
521
522do-extsrc: .PHONY .MAKE
523.if ${MKEXTSRC} != "no"
524	${MAKEDIRTARGET} extsrc build
525.else
526	@echo "MKEXTSRC is not enabled"
527	@false
528.endif
529
530do-obsolete: .PHONY .MAKE
531	${MAKEDIRTARGET} etc install-obsolete-lists
532
533#
534# Speedup stubs for some subtrees that don't need to run these rules.
535# (Tells <bsd.subdir.mk> not to recurse for them.)
536#
537
538.for dir in bin etc distrib games libexec regress sbin usr.sbin tools
539includes-${dir}: .PHONY
540	@true
541.endfor
542.for dir in etc distrib regress
543install-${dir}: .PHONY
544	@true
545.endfor
546
547#
548# XXX this needs to change when distrib Makefiles are recursion compliant
549# XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
550#
551dependall-distrib depend-distrib all-distrib: .PHONY
552	@true
553
554.include <bsd.sys.mk>
555.include <bsd.obj.mk>
556.include <bsd.kernobj.mk>
557.include <bsd.subdir.mk>
558
559#
560# Display current make(1) parameters
561#
562params: .PHONY .MAKE
563	${MAKEDIRTARGET} etc params
564