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