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