Makefile revision 1.326
1#	$NetBSD: Makefile,v 1.326 2019/06/06 14:51:43 martin 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#   NOBINARIES will not build binaries, only includes and libraries
34#
35#   See mk.conf(5) for more details.
36#
37#
38# Targets:
39#   build:
40#	Builds a full release of NetBSD in DESTDIR, except for the
41#	/etc configuration files.
42#	If BUILD_DONE is set, this is an empty target.
43#   distribution:
44#	Builds a full release of NetBSD in DESTDIR, including the /etc
45#	configuration files.
46#   buildworld:
47#	As per `make distribution', except that it ensures that DESTDIR
48#	is not the root directory.
49#   installworld:
50#	Install the distribution from DESTDIR to INSTALLWORLDDIR (which
51#	defaults to the root directory).  Ensures that INSTALLWORLDDIR
52#	is not the root directory if cross compiling.
53#   release:
54#	Does a `make distribution', and then tars up the DESTDIR files
55#	into ${RELEASEDIR}/${RELEASEMACHINEDIR}, in release(7) format.
56#	(See etc/Makefile for more information on this.)
57#   regression-tests:
58#	Runs the regression tests in "regress" on this host.
59#   sets:
60#	Populate ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
61#	from ${DESTDIR}
62#   sourcesets:
63#	Populate ${RELEASEDIR}/source/sets from ${NETBSDSRCDIR}
64#   syspkgs:
65#	Populate ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/syspkgs
66#	from ${DESTDIR}
67#   iso-image:
68#	Create CD-ROM image in RELEASEDIR/images.
69#	RELEASEDIR must already have been populated by `make release'
70#	or equivalent.
71#   iso-image-source:
72#	Create CD-ROM image with source in RELEASEDIR/images.
73#	RELEASEDIR must already have been populated by
74#	`make release sourcesets' or equivalent.
75#   live-image:
76#	Create bootable live image for emulators or USB stick etc.
77#	in RELEASEDIR/liveimage.
78#	RELEASEDIR must already have been populated by `make release'
79#	or equivalent.
80#   install-image:
81#	Create bootable installation image for USB stick etc.
82#	in RELEASEDIR/installimage.
83#	RELEASEDIR must already have been populated by `make release'
84#	or equivalent.
85#
86# Targets invoked by `make build,' in order:
87#   cleandir:        cleans the tree.
88#   do-top-obj:      creates the top level object directory.
89#   do-tools-obj:    creates object directories for the host toolchain.
90#   do-tools:        builds host toolchain.
91#   params:          record the values of variables that might affect the
92#                    build.
93#   obj:             creates object directories.
94#   do-distrib-dirs: creates the distribution directories.
95#   includes:        installs include files.
96#   do-lib:          builds and installs prerequisites from lib.
97#   do-compat-lib:   builds and installs prerequisites from compat/lib
98#                    if ${MKCOMPAT} != "no".
99#   do-x11:          builds and installs X11 tools and libraries
100#                    from src/external/mit/xorg if ${MKX11} != "no".
101#   do-build:        builds and installs the entire system.
102#   do-extsrc:       builds and installs extsrc if ${MKEXTSRC} != "no".
103#   do-obsolete:     installs the obsolete sets (for the postinstall-* targets).
104#
105
106.if ${.MAKEFLAGS:M${.CURDIR}/share/mk} == ""
107.MAKEFLAGS: -m ${.CURDIR}/share/mk
108.endif
109
110#
111# If _SRC_TOP_OBJ_ gets set here, we will end up with a directory that may
112# not be the top level objdir, because "make obj" can happen in the *middle*
113# of "make build" (long after <bsd.own.mk> is calculated it).  So, pre-set
114# _SRC_TOP_OBJ_ here so it will not be added to ${.MAKEOVERRIDES}.
115#
116_SRC_TOP_OBJ_=
117
118.include <bsd.own.mk>
119
120#
121# Sanity check: make sure that "make build" is not invoked simultaneously
122# with a standard recursive target.
123#
124
125.if make(build) || make(release) || make(snapshot)
126.for targ in ${TARGETS:Nobj:Ncleandir}
127.if make(${targ}) && !target(.BEGIN)
128.BEGIN:
129	@echo 'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
130	@false
131.endif
132.endfor
133.endif
134
135#
136# _SUBDIR is used to set SUBDIR, after removing directories that have
137# BUILD_${dir}=no, or that have no ${dir}/Makefile.
138#
139_SUBDIR=	tools .WAIT lib include external crypto/external bin
140_SUBDIR+=	games libexec sbin usr.bin
141_SUBDIR+=	usr.sbin share sys etc tests compat
142_SUBDIR+=	.WAIT rescue .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} external/gpl2/texinfo/bin/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		-m ${MACHINE} -a ${MACHINE_ARCH}
174_POSTINSTALL_ENV= \
175	AWK=${TOOL_AWK:Q}		\
176	DB=${TOOL_DB:Q}			\
177	HOST_SH=${HOST_SH:Q}		\
178	MAKE=${MAKE:Q}			\
179	PWD_MKDB=${TOOL_PWD_MKDB:Q}	\
180	SED=${TOOL_SED:Q}		\
181	STAT=${TOOL_STAT:Q}
182
183.if ${MKX11} != "no"
184_POSTINSTALL_X11=-x ${X11SRCDIR:Q}
185.endif
186
187postinstall-check: .PHONY
188	@echo "   === Post installation checks ==="
189	${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ check; if [ $$? -gt 1 ]; then exit 1; fi
190	@echo "   ================================"
191
192postinstall-fix: .NOTMAIN .PHONY
193	@echo "   === Post installation fixes ==="
194	${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ fix
195	@echo "   ==============================="
196
197postinstall-fix-obsolete: .NOTMAIN .PHONY
198	@echo "   === Removing obsolete files ==="
199	${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ fix obsolete
200	@echo "   ==============================="
201
202postinstall-fix-obsolete_stand: .NOTMAIN .PHONY
203	@echo "   === Removing obsolete files ==="
204	${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ fix obsolete_stand
205	@echo "   ==============================="
206
207
208#
209# Targets (in order!) called by "make build".
210#
211BUILDTARGETS+=	check-tools
212.if ${MKUPDATE} == "no" && !defined(NOCLEANDIR)
213BUILDTARGETS+=	cleandir
214.endif
215.if ${MKOBJDIRS} != "no"
216BUILDTARGETS+=	do-top-obj
217.endif
218.if ${USETOOLS} == "yes"	# {
219.if ${MKOBJDIRS} != "no"
220BUILDTARGETS+=	do-tools-obj
221.endif
222BUILDTARGETS+=	do-tools
223.endif # USETOOLS		# }
224BUILDTARGETS+=	params
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
237.if ${MKX11} != "no"
238BUILDTARGETS+=	do-x11
239.endif
240.if !defined(NOBINARIES)
241BUILDTARGETS+=	do-build
242.if ${MKEXTSRC} != "no"
243BUILDTARGETS+=	do-extsrc
244.endif
245BUILDTARGETS+=	do-obsolete
246.endif
247
248#
249# Enforce proper ordering of some rules.
250#
251
252.ORDER:		${BUILDTARGETS}
253includes-lib:	.PHONY includes-include includes-sys
254
255#
256# Record the values of variables that might affect the build.
257# If no values have changed, avoid updating the timestamp
258# of the params file.
259#
260# This is referenced by _NETBSD_VERSION_DEPENDS in <bsd.own.mk>.
261#
262.include "${NETBSDSRCDIR}/etc/Makefile.params"
263CLEANDIRFILES+= params
264params: .EXEC
265	${_MKMSG_CREATE} params
266	@${PRINT_PARAMS} >${.TARGET}.new
267	@if cmp -s ${.TARGET}.new ${.TARGET} > /dev/null 2>&1; then \
268		: "params is unchanged" ; \
269		rm ${.TARGET}.new ; \
270	else \
271		: "params has changed or is new" ; \
272		mv ${.TARGET}.new ${.TARGET} ; \
273	fi
274
275#
276# Display current make(1) parameters
277#
278show-params: .PHONY .MAKE
279	@${PRINT_PARAMS}
280
281#
282# Build the system and install into DESTDIR.
283#
284
285START_TIME!=	date
286
287build: .PHONY .MAKE
288.if defined(BUILD_DONE)
289	@echo "Build already installed into ${DESTDIR}"
290.else
291	@echo "Build started at: ${START_TIME}"
292.for tgt in ${BUILDTARGETS}
293	${MAKEDIRTARGET} . ${tgt}
294.endfor
295	${MAKEDIRTARGET} etc install-etc-release
296	@echo   "Build started at:  ${START_TIME}"
297	@printf "Build finished at: " && date
298.endif
299
300#
301# Build a full distribution, but not a release (i.e. no sets into
302# ${RELEASEDIR}).  "buildworld" enforces a build to ${DESTDIR} != /
303#
304
305distribution buildworld: .PHONY .MAKE
306.if make(buildworld) && \
307    (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
308	@echo "Won't make ${.TARGET} with DESTDIR=/"
309	@false
310.endif
311	${MAKEDIRTARGET} . build NOPOSTINSTALL=1
312	${MAKEDIRTARGET} etc distribution INSTALL_DONE=1
313.if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/"
314	${MAKEDIRTARGET} . postinstall-fix-obsolete
315	${MAKEDIRTARGET} . postinstall-fix-obsolete_stand
316	${MAKEDIRTARGET} distrib/sets checkflist
317.endif
318	@echo   "make ${.TARGET} started at:  ${START_TIME}"
319	@printf "make ${.TARGET} finished at: " && date
320
321#
322# Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
323# If installing to /, ensures that the host's operating system is NetBSD and
324# the host's `uname -m` == ${MACHINE}.
325#
326
327HOST_UNAME_S!=	uname -s
328HOST_UNAME_M!=	uname -m
329
330installworld: .PHONY .MAKE
331.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
332	@echo "Can't make ${.TARGET} to DESTDIR=/"
333	@false
334.endif
335.if !defined(INSTALLWORLDDIR) || \
336    ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/"
337.if (${HOST_UNAME_S} != "NetBSD")
338	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLWORLDDIR=/"
339	@false
340.endif
341.if (${HOST_UNAME_M} != ${MACHINE})
342	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
343	@false
344.endif
345.endif
346	${MAKEDIRTARGET} distrib/sets installsets \
347		INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS=${INSTALLSETS:Q}
348	${MAKEDIRTARGET} . postinstall-check DESTDIR=${INSTALLWORLDDIR}
349	@echo   "make ${.TARGET} started at:  ${START_TIME}"
350	@printf "make ${.TARGET} finished at: " && date
351
352#
353# Install modules from $DESTDIR to $INSTALLMODULESDIR
354#
355installmodules: .PHONY .MAKE
356.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
357	@echo "Can't make ${.TARGET} to DESTDIR=/"
358	@false
359.endif
360.if !defined(INSTALLMODULESDIR) || \
361    ${INSTALLMODULESDIR} == "" || ${INSTALLMODULESDIR} == "/"
362.if (${HOST_UNAME_S} != "NetBSD")
363	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLMODULESDIR=/"
364	@false
365.endif
366.if (${HOST_UNAME_M} != ${MACHINE})
367	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLMODULESDIR=/"
368	@false
369.endif
370.endif
371	${MAKEDIRTARGET} sys/modules install DESTDIR=${INSTALLMODULESDIR:U/}
372	@echo   "make ${.TARGET} started at:  ${START_TIME}"
373	@printf "make ${.TARGET} finished at: " && date
374
375#
376# Create sets from $DESTDIR or $NETBSDSRCDIR into $RELEASEDIR
377#
378
379.for tgt in sets sourcesets syspkgs
380${tgt}: .PHONY .MAKE
381	${MAKEDIRTARGET} distrib/sets ${tgt}
382.endfor
383
384#
385# Build a release or snapshot (implies "make distribution").  Note that
386# in this case, the set lists will be checked before the tar files
387# are made.
388#
389
390release snapshot: .PHONY .MAKE
391	${MAKEDIRTARGET} . distribution
392	${MAKEDIRTARGET} etc release DISTRIBUTION_DONE=1
393	@echo   "make ${.TARGET} started at:  ${START_TIME}"
394	@printf "make ${.TARGET} finished at: " && date
395
396#
397# Create a CD-ROM image.
398#
399
400iso-image: .PHONY
401	${MAKEDIRTARGET} distrib iso_image
402	${MAKEDIRTARGET} etc iso-image
403	@echo   "make ${.TARGET} started at:  ${START_TIME}"
404	@printf "make ${.TARGET} finished at: " && date
405
406iso-image-source: .PHONY
407	${MAKEDIRTARGET} distrib iso_image CDSOURCE=true
408	${MAKEDIRTARGET} etc iso-image
409	@echo   "make ${.TARGET} started at:  ${START_TIME}"
410	@printf "make ${.TARGET} finished at: " && date
411
412#
413# Create bootable live images.
414#
415
416live-image: .PHONY
417	${MAKEDIRTARGET} etc live-image
418	@echo   "make ${.TARGET} started at:  ${START_TIME}"
419	@printf "make ${.TARGET} finished at: " && date
420
421#
422# Create bootable installation images.
423#
424
425install-image: .PHONY
426	${MAKEDIRTARGET} etc install-image
427	@echo   "make ${.TARGET} started at:  ${START_TIME}"
428	@printf "make ${.TARGET} finished at: " && date
429
430#
431# Special components of the "make build" process.
432#
433
434check-tools: .PHONY
435.if ${TOOLCHAIN_MISSING} != "no" && !defined(EXTERNAL_TOOLCHAIN)
436	@echo '*** WARNING:  Building on MACHINE=${MACHINE} with missing toolchain.'
437	@echo '*** May result in a failed build or corrupt binaries!'
438.elif defined(EXTERNAL_TOOLCHAIN)
439	@echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
440.endif
441.if defined(NBUILDJOBS)
442	@echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
443.endif
444
445# Delete or sanitise a leftover METALOG from a previous build.
446clean_METALOG: .PHONY .MAKE
447.if ${MKUPDATE} != "no"
448	${MAKEDIRTARGET} distrib/sets clean_METALOG
449.endif
450
451do-distrib-dirs: .PHONY .MAKE
452.if !defined(DESTDIR) || ${DESTDIR} == ""
453	${MAKEDIRTARGET} etc distrib-dirs DESTDIR=/
454.else
455	${MAKEDIRTARGET} etc distrib-dirs DESTDIR=${DESTDIR}
456.endif
457
458.for targ in cleandir obj includes
459do-${targ}: .PHONY ${targ}
460	@true
461.endfor
462
463do-tools: .PHONY .MAKE
464	${MAKEDIRTARGET} tools build_install
465
466do-lib: .PHONY .MAKE
467	${MAKEDIRTARGET} lib build_install
468
469do-compat-lib: .PHONY .MAKE
470	${MAKEDIRTARGET} compat build_install BOOTSTRAP_SUBDIRS="../../../lib"
471
472do-top-obj: .PHONY .MAKE
473	${MAKEDIRTARGET} . obj NOSUBDIR=
474
475do-tools-obj: .PHONY .MAKE
476	${MAKEDIRTARGET} tools obj
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	${MAKEDIRTARGET} external/mit/xorg/tools all
486	${MAKEDIRTARGET} external/mit/xorg/lib build_install
487.if ${MKCOMPATX11} != "no"
488	${MAKEDIRTARGET} compat build_install BOOTSTRAP_SUBDIRS="../../../external/mit/xorg/lib"
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.bin 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.obj.mk>
528.include <bsd.kernobj.mk>
529.include <bsd.subdir.mk>
530.include <bsd.clean.mk>
531