xref: /netbsd-src/Makefile (revision 5278b8e44df34702d8041b06cf76319dea99b5ed)
1*5278b8e4Sriastradh#	$NetBSD: Makefile,v 1.338 2023/09/08 12:01:56 riastradh Exp $
2f1de59e0Spgoyette
3f1de59e0Spgoyette#
4f1de59e0Spgoyette# This is the top-level makefile for building NetBSD. For an outline of
5f1de59e0Spgoyette# how to build a snapshot or release, as well as other release engineering
6f1de59e0Spgoyette# information, see http://www.NetBSD.org/developers/releng/index.html
7f1de59e0Spgoyette#
8f1de59e0Spgoyette# Not everything you can set or do is documented in this makefile. In
9f1de59e0Spgoyette# particular, you should review the files in /usr/share/mk (especially
10f1de59e0Spgoyette# bsd.README) for general information on building programs and writing
11f1de59e0Spgoyette# Makefiles within this structure, and see the comments in src/etc/Makefile
12f1de59e0Spgoyette# for further information on installation and release set options.
13f1de59e0Spgoyette#
14f1de59e0Spgoyette# Variables listed below can be set on the make command line (highest
15f1de59e0Spgoyette# priority), in /etc/mk.conf (middle priority), or in the environment
16f1de59e0Spgoyette# (lowest priority).
17f1de59e0Spgoyette#
18f1de59e0Spgoyette# Variables:
19f1de59e0Spgoyette#   DESTDIR is the target directory for installation of the compiled
20f1de59e0Spgoyette#	software. It defaults to /. Note that programs are built against
21f1de59e0Spgoyette#	libraries installed in DESTDIR.
22f1de59e0Spgoyette#   MKMAN, if `no', will prevent building of manual pages.
23f1de59e0Spgoyette#   MKOBJDIRS, if not `no', will build object directories at
24f1de59e0Spgoyette#	an appropriate point in a build.
25f1de59e0Spgoyette#   MKSHARE, if `no', will prevent building and installing
26f1de59e0Spgoyette#	anything in /usr/share.
27f1de59e0Spgoyette#   MKUPDATE, if not `no', will avoid a `make cleandir' at the start of
28f1de59e0Spgoyette#	`make build', as well as having the effects listed in
29f1de59e0Spgoyette#	/usr/share/mk/bsd.README.
30f1de59e0Spgoyette#   NOCLEANDIR, if defined, will avoid a `make cleandir' at the start
31f1de59e0Spgoyette#	of the `make build'.
32f1de59e0Spgoyette#   NOINCLUDES will avoid the `make includes' usually done by `make build'.
33f1de59e0Spgoyette#   NOBINARIES will not build binaries, only includes and libraries
34f1de59e0Spgoyette#
35f1de59e0Spgoyette#   See mk.conf(5) for more details.
36f1de59e0Spgoyette#
37f1de59e0Spgoyette#
38f1de59e0Spgoyette# Targets:
39f1de59e0Spgoyette#   build:
40f1de59e0Spgoyette#	Builds a full release of NetBSD in DESTDIR, except for the
41f1de59e0Spgoyette#	/etc configuration files.
42f1de59e0Spgoyette#	If BUILD_DONE is set, this is an empty target.
43f1de59e0Spgoyette#   distribution:
44f1de59e0Spgoyette#	Builds a full release of NetBSD in DESTDIR, including the /etc
45f1de59e0Spgoyette#	configuration files.
46f1de59e0Spgoyette#   buildworld:
47f1de59e0Spgoyette#	As per `make distribution', except that it ensures that DESTDIR
48f1de59e0Spgoyette#	is not the root directory.
49f1de59e0Spgoyette#   installworld:
50f1de59e0Spgoyette#	Install the distribution from DESTDIR to INSTALLWORLDDIR (which
51f1de59e0Spgoyette#	defaults to the root directory).  Ensures that INSTALLWORLDDIR
52f1de59e0Spgoyette#	is not the root directory if cross compiling.
53f1de59e0Spgoyette#   release:
54f1de59e0Spgoyette#	Does a `make distribution', and then tars up the DESTDIR files
55f1de59e0Spgoyette#	into ${RELEASEDIR}/${RELEASEMACHINEDIR}, in release(7) format.
56f1de59e0Spgoyette#	(See etc/Makefile for more information on this.)
57f1de59e0Spgoyette#   regression-tests:
58f1de59e0Spgoyette#	Runs the regression tests in "regress" on this host.
59f1de59e0Spgoyette#   sets:
60f1de59e0Spgoyette#	Populate ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
61f1de59e0Spgoyette#	from ${DESTDIR}
62f1de59e0Spgoyette#   sourcesets:
63f1de59e0Spgoyette#	Populate ${RELEASEDIR}/source/sets from ${NETBSDSRCDIR}
64f1de59e0Spgoyette#   syspkgs:
65f1de59e0Spgoyette#	Populate ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/syspkgs
66f1de59e0Spgoyette#	from ${DESTDIR}
67f1de59e0Spgoyette#   iso-image:
68f1de59e0Spgoyette#	Create CD-ROM image in RELEASEDIR/images.
69f1de59e0Spgoyette#	RELEASEDIR must already have been populated by `make release'
70f1de59e0Spgoyette#	or equivalent.
71f1de59e0Spgoyette#   iso-image-source:
72f1de59e0Spgoyette#	Create CD-ROM image with source in RELEASEDIR/images.
73f1de59e0Spgoyette#	RELEASEDIR must already have been populated by
74f1de59e0Spgoyette#	`make release sourcesets' or equivalent.
75f1de59e0Spgoyette#   live-image:
76f1de59e0Spgoyette#	Create bootable live image for emulators or USB stick etc.
77f1de59e0Spgoyette#	in RELEASEDIR/liveimage.
78f1de59e0Spgoyette#	RELEASEDIR must already have been populated by `make release'
79f1de59e0Spgoyette#	or equivalent.
80f1de59e0Spgoyette#   install-image:
81f1de59e0Spgoyette#	Create bootable installation image for USB stick etc.
82f1de59e0Spgoyette#	in RELEASEDIR/installimage.
83f1de59e0Spgoyette#	RELEASEDIR must already have been populated by `make release'
84f1de59e0Spgoyette#	or equivalent.
85f1de59e0Spgoyette#
86f1de59e0Spgoyette# Targets invoked by `make build,' in order:
87f1de59e0Spgoyette#   cleandir:        cleans the tree.
88f1de59e0Spgoyette#   do-top-obj:      creates the top level object directory.
89f1de59e0Spgoyette#   do-tools-obj:    creates object directories for the host toolchain.
90f1de59e0Spgoyette#   do-tools:        builds host toolchain.
91439f74efSlukem#   params:          create params file with various make(1) parameters.
92439f74efSlukem#   show-params:     show various make(1) parameters.
93f1de59e0Spgoyette#   obj:             creates object directories.
94f1de59e0Spgoyette#   do-distrib-dirs: creates the distribution directories.
95f1de59e0Spgoyette#   includes:        installs include files.
96cbca735bSmartin#   do-lib:          builds and installs prerequisites from lib.
97f1de59e0Spgoyette#   do-compat-lib:   builds and installs prerequisites from compat/lib
98f1de59e0Spgoyette#                    if ${MKCOMPAT} != "no".
99f1de59e0Spgoyette#   do-x11:          builds and installs X11 tools and libraries
100f1de59e0Spgoyette#                    from src/external/mit/xorg if ${MKX11} != "no".
101f1de59e0Spgoyette#   do-build:        builds and installs the entire system.
102f1de59e0Spgoyette#   do-obsolete:     installs the obsolete sets (for the postinstall-* targets).
103f1de59e0Spgoyette#
104f1de59e0Spgoyette
105f1de59e0Spgoyette.if ${.MAKEFLAGS:M${.CURDIR}/share/mk} == ""
106f1de59e0Spgoyette.MAKEFLAGS: -m ${.CURDIR}/share/mk
107f1de59e0Spgoyette.endif
108f1de59e0Spgoyette
109f1de59e0Spgoyette#
110f1de59e0Spgoyette# If _SRC_TOP_OBJ_ gets set here, we will end up with a directory that may
111f1de59e0Spgoyette# not be the top level objdir, because "make obj" can happen in the *middle*
112f1de59e0Spgoyette# of "make build" (long after <bsd.own.mk> is calculated it).  So, pre-set
113f1de59e0Spgoyette# _SRC_TOP_OBJ_ here so it will not be added to ${.MAKEOVERRIDES}.
114f1de59e0Spgoyette#
115f1de59e0Spgoyette_SRC_TOP_OBJ_=
116f1de59e0Spgoyette
117f1de59e0Spgoyette.include <bsd.own.mk>
118f1de59e0Spgoyette
119f1de59e0Spgoyette#
120f1de59e0Spgoyette# Sanity check: make sure that "make build" is not invoked simultaneously
121f1de59e0Spgoyette# with a standard recursive target.
122f1de59e0Spgoyette#
123f1de59e0Spgoyette
124f1de59e0Spgoyette.if make(build) || make(release) || make(snapshot)
125f1de59e0Spgoyette.for targ in ${TARGETS:Nobj:Ncleandir}
126f1de59e0Spgoyette.if make(${targ}) && !target(.BEGIN)
127f1de59e0Spgoyette.BEGIN:
128f1de59e0Spgoyette	@echo 'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
129f1de59e0Spgoyette	@false
130f1de59e0Spgoyette.endif
131f1de59e0Spgoyette.endfor
132f1de59e0Spgoyette.endif
133f1de59e0Spgoyette
134f1de59e0Spgoyette#
135f1de59e0Spgoyette# _SUBDIR is used to set SUBDIR, after removing directories that have
136f1de59e0Spgoyette# BUILD_${dir}=no, or that have no ${dir}/Makefile.
137f1de59e0Spgoyette#
138ae9c7cb9Skamil_SUBDIR=	tools .WAIT lib
139ae9c7cb9Skamil.if ${MKLLVM} != "no"
140ae9c7cb9Skamil_SUBDIR+=	external/bsd/compiler_rt
141ae9c7cb9Skamil.endif
142ae9c7cb9Skamil_SUBDIR+=	include external crypto/external bin
14387431fddSmaya_SUBDIR+=	games libexec sbin usr.bin
144f1de59e0Spgoyette_SUBDIR+=	usr.sbin share sys etc tests compat
145f1de59e0Spgoyette_SUBDIR+=	.WAIT rescue .WAIT distrib regress
146f1de59e0Spgoyette
147f1de59e0Spgoyette.for dir in ${_SUBDIR}
148f1de59e0Spgoyette.if "${dir}" == ".WAIT" \
149f1de59e0Spgoyette	|| (${BUILD_${dir}:Uyes} != "no" && exists(${dir}/Makefile))
150f1de59e0SpgoyetteSUBDIR+=	${dir}
151f1de59e0Spgoyette.endif
152f1de59e0Spgoyette.endfor
153f1de59e0Spgoyette
154f1de59e0Spgoyette.if exists(regress)
155f1de59e0Spgoyetteregression-tests: .PHONY .MAKE
156f1de59e0Spgoyette	@echo Running regression tests...
157f1de59e0Spgoyette	${MAKEDIRTARGET} regress regress
158f1de59e0Spgoyette.endif
159f1de59e0Spgoyette
160f1de59e0Spgoyette.if ${MKUNPRIVED} != "no"
161f1de59e0SpgoyetteNOPOSTINSTALL=	# defined
162f1de59e0Spgoyette.endif
163f1de59e0Spgoyette
164f1de59e0Spgoyetteafterinstall: .PHONY .MAKE
165f1de59e0Spgoyette.if ${MKMAN} != "no"
166f1de59e0Spgoyette	${MAKEDIRTARGET} share/man makedb
167f1de59e0Spgoyette.endif
168f1de59e0Spgoyette.if (${MKUNPRIVED} != "no" && ${MKINFO} != "no")
169f1de59e0Spgoyette	${MAKEDIRTARGET} external/gpl2/texinfo/bin/install-info infodir-meta
170f1de59e0Spgoyette.endif
171f1de59e0Spgoyette.if !defined(NOPOSTINSTALL)
172f1de59e0Spgoyette	${MAKEDIRTARGET} . postinstall-check
173f1de59e0Spgoyette.endif
174f1de59e0Spgoyette
175bebf19faSmartin_POSTINSTALL=	${:!cd ${.CURDIR}/usr.sbin/postinstall && \
176c5b32978Srillig			${MAKE} -v .OBJDIR!}/postinstall  \
177f1de59e0Spgoyette		-m ${MACHINE} -a ${MACHINE_ARCH}
178f1de59e0Spgoyette_POSTINSTALL_ENV= \
179f1de59e0Spgoyette	AWK=${TOOL_AWK:Q}		\
180f1de59e0Spgoyette	DB=${TOOL_DB:Q}			\
181f1de59e0Spgoyette	HOST_SH=${HOST_SH:Q}		\
182f1de59e0Spgoyette	MAKE=${MAKE:Q}			\
183f1de59e0Spgoyette	PWD_MKDB=${TOOL_PWD_MKDB:Q}	\
184f1de59e0Spgoyette	SED=${TOOL_SED:Q}		\
185f1de59e0Spgoyette	STAT=${TOOL_STAT:Q}
186f1de59e0Spgoyette
187f1de59e0Spgoyette.if ${MKX11} != "no"
188f1de59e0Spgoyette_POSTINSTALL_X11=-x ${X11SRCDIR:Q}
189f1de59e0Spgoyette.endif
190f1de59e0Spgoyette
191f1de59e0Spgoyettepostinstall-check: .PHONY
192f1de59e0Spgoyette	@echo "   === Post installation checks ==="
193*5278b8e4Sriastradh	${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR:C/^\/$//}/ check; if [ $$? -gt 1 ]; then exit 1; fi
194f1de59e0Spgoyette	@echo "   ================================"
195f1de59e0Spgoyette
196f1de59e0Spgoyettepostinstall-fix: .NOTMAIN .PHONY
197f1de59e0Spgoyette	@echo "   === Post installation fixes ==="
198*5278b8e4Sriastradh	${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR:C/^\/$//}/ fix
199f1de59e0Spgoyette	@echo "   ==============================="
200f1de59e0Spgoyette
201f1de59e0Spgoyettepostinstall-fix-obsolete: .NOTMAIN .PHONY
202f1de59e0Spgoyette	@echo "   === Removing obsolete files ==="
203*5278b8e4Sriastradh	${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR:C/^\/$//}/ fix obsolete
204f1de59e0Spgoyette	@echo "   ==============================="
205f1de59e0Spgoyette
206f1de59e0Spgoyettepostinstall-fix-obsolete_stand: .NOTMAIN .PHONY
207f1de59e0Spgoyette	@echo "   === Removing obsolete files ==="
208*5278b8e4Sriastradh	${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR:C/^\/$//}/ fix obsolete_stand
209*5278b8e4Sriastradh	${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR:C/^\/$//}/ fix obsolete_stand_debug
210f1de59e0Spgoyette	@echo "   ==============================="
211f1de59e0Spgoyette
212f1de59e0Spgoyette
213f1de59e0Spgoyette#
214f1de59e0Spgoyette# Targets (in order!) called by "make build".
215f1de59e0Spgoyette#
216f1de59e0SpgoyetteBUILDTARGETS+=	check-tools
217f1de59e0Spgoyette.if ${MKUPDATE} == "no" && !defined(NOCLEANDIR)
218f1de59e0SpgoyetteBUILDTARGETS+=	cleandir
219f1de59e0Spgoyette.endif
220f1de59e0Spgoyette.if ${MKOBJDIRS} != "no"
221f1de59e0SpgoyetteBUILDTARGETS+=	do-top-obj
222f1de59e0Spgoyette.endif
223f1de59e0Spgoyette.if ${USETOOLS} == "yes"	# {
224f1de59e0Spgoyette.if ${MKOBJDIRS} != "no"
225f1de59e0SpgoyetteBUILDTARGETS+=	do-tools-obj
226f1de59e0Spgoyette.endif
227f1de59e0SpgoyetteBUILDTARGETS+=	do-tools
228f1de59e0Spgoyette.endif # USETOOLS		# }
229f1de59e0SpgoyetteBUILDTARGETS+=	params
230f1de59e0Spgoyette.if ${MKOBJDIRS} != "no"
231f1de59e0SpgoyetteBUILDTARGETS+=	obj
232f1de59e0Spgoyette.endif
233f1de59e0SpgoyetteBUILDTARGETS+=	clean_METALOG
234f1de59e0Spgoyette.if !defined(NODISTRIBDIRS)
235f1de59e0SpgoyetteBUILDTARGETS+=	do-distrib-dirs
236f1de59e0Spgoyette.endif
237f1de59e0Spgoyette.if !defined(NOINCLUDES)
238f1de59e0SpgoyetteBUILDTARGETS+=	includes
239f1de59e0Spgoyette.endif
240f1de59e0SpgoyetteBUILDTARGETS+=	do-lib
241f1de59e0SpgoyetteBUILDTARGETS+=	do-compat-lib
2424ed00d96Skamil.if ${MKLLVM} != "no"
243ae9c7cb9SkamilBUILDTARGETS+=	do-sanitizer
2444ed00d96Skamil.if ${MKSANITIZER:Uno} == "yes"
2454ed00d96SkamilBUILDTARGETS+=	do-sanitizer-tools
2464ed00d96Skamil.endif
2474ed00d96Skamil.endif
248f1de59e0Spgoyette.if ${MKX11} != "no"
249f1de59e0SpgoyetteBUILDTARGETS+=	do-x11
250f1de59e0Spgoyette.endif
251f1de59e0Spgoyette.if !defined(NOBINARIES)
252f1de59e0SpgoyetteBUILDTARGETS+=	do-build
253f1de59e0SpgoyetteBUILDTARGETS+=	do-obsolete
254f1de59e0Spgoyette.endif
255f1de59e0Spgoyette
256f1de59e0Spgoyette#
257f1de59e0Spgoyette# Enforce proper ordering of some rules.
258f1de59e0Spgoyette#
259f1de59e0Spgoyette
260f1de59e0Spgoyette.ORDER:		${BUILDTARGETS}
261f1de59e0Spgoyetteincludes-lib:	.PHONY includes-include includes-sys
262f1de59e0Spgoyette
263f1de59e0Spgoyette#
264f1de59e0Spgoyette# Record the values of variables that might affect the build.
265f1de59e0Spgoyette# If no values have changed, avoid updating the timestamp
266f1de59e0Spgoyette# of the params file.
267f1de59e0Spgoyette#
268f1de59e0Spgoyette# This is referenced by _NETBSD_VERSION_DEPENDS in <bsd.own.mk>.
269f1de59e0Spgoyette#
270f1de59e0Spgoyette.include "${NETBSDSRCDIR}/etc/Makefile.params"
271f1de59e0SpgoyetteCLEANDIRFILES+= params
272f1de59e0Spgoyetteparams: .EXEC
273f1de59e0Spgoyette	${_MKMSG_CREATE} params
274f1de59e0Spgoyette	@${PRINT_PARAMS} >${.TARGET}.new
275f1de59e0Spgoyette	@if cmp -s ${.TARGET}.new ${.TARGET} > /dev/null 2>&1; then \
276f1de59e0Spgoyette		: "params is unchanged" ; \
277f1de59e0Spgoyette		rm ${.TARGET}.new ; \
278f1de59e0Spgoyette	else \
279f1de59e0Spgoyette		: "params has changed or is new" ; \
280f1de59e0Spgoyette		mv ${.TARGET}.new ${.TARGET} ; \
281f1de59e0Spgoyette	fi
282f1de59e0Spgoyette
283f1de59e0Spgoyette#
284f1de59e0Spgoyette# Display current make(1) parameters
285f1de59e0Spgoyette#
286f1de59e0Spgoyetteshow-params: .PHONY .MAKE
287f1de59e0Spgoyette	@${PRINT_PARAMS}
288f1de59e0Spgoyette
289f1de59e0Spgoyette#
290f1de59e0Spgoyette# Build the system and install into DESTDIR.
291f1de59e0Spgoyette#
292f1de59e0Spgoyette
293f1de59e0SpgoyetteSTART_TIME!=	date
294f1de59e0Spgoyette
295f1de59e0Spgoyettebuild: .PHONY .MAKE
296f1de59e0Spgoyette.if defined(BUILD_DONE)
297f1de59e0Spgoyette	@echo "Build already installed into ${DESTDIR}"
298f1de59e0Spgoyette.else
299f1de59e0Spgoyette	@echo "Build started at: ${START_TIME}"
300f1de59e0Spgoyette.for tgt in ${BUILDTARGETS}
301f1de59e0Spgoyette	${MAKEDIRTARGET} . ${tgt}
302f1de59e0Spgoyette.endfor
303f1de59e0Spgoyette	${MAKEDIRTARGET} etc install-etc-release
304f1de59e0Spgoyette	@echo   "Build started at:  ${START_TIME}"
305f1de59e0Spgoyette	@printf "Build finished at: " && date
306f1de59e0Spgoyette.endif
307f1de59e0Spgoyette
308f1de59e0Spgoyette#
309f1de59e0Spgoyette# Build a full distribution, but not a release (i.e. no sets into
310f1de59e0Spgoyette# ${RELEASEDIR}).  "buildworld" enforces a build to ${DESTDIR} != /
311f1de59e0Spgoyette#
312f1de59e0Spgoyette
313f1de59e0Spgoyettedistribution buildworld: .PHONY .MAKE
314f1de59e0Spgoyette.if make(buildworld) && \
315f1de59e0Spgoyette    (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
316f1de59e0Spgoyette	@echo "Won't make ${.TARGET} with DESTDIR=/"
317f1de59e0Spgoyette	@false
318f1de59e0Spgoyette.endif
319f1de59e0Spgoyette	${MAKEDIRTARGET} . build NOPOSTINSTALL=1
320f1de59e0Spgoyette	${MAKEDIRTARGET} etc distribution INSTALL_DONE=1
321f1de59e0Spgoyette.if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/"
322f1de59e0Spgoyette	${MAKEDIRTARGET} . postinstall-fix-obsolete
323f1de59e0Spgoyette	${MAKEDIRTARGET} . postinstall-fix-obsolete_stand
324f1de59e0Spgoyette	${MAKEDIRTARGET} distrib/sets checkflist
325f1de59e0Spgoyette.endif
326f1de59e0Spgoyette	@echo   "make ${.TARGET} started at:  ${START_TIME}"
327f1de59e0Spgoyette	@printf "make ${.TARGET} finished at: " && date
328f1de59e0Spgoyette
329f1de59e0Spgoyette#
330f1de59e0Spgoyette# Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
331f1de59e0Spgoyette# If installing to /, ensures that the host's operating system is NetBSD and
332f1de59e0Spgoyette# the host's `uname -m` == ${MACHINE}.
333f1de59e0Spgoyette#
334f1de59e0Spgoyette
335f1de59e0SpgoyetteHOST_UNAME_S!=	uname -s
336f1de59e0SpgoyetteHOST_UNAME_M!=	uname -m
337f1de59e0Spgoyette
338f1de59e0Spgoyetteinstallworld: .PHONY .MAKE
339f1de59e0Spgoyette.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
340f1de59e0Spgoyette	@echo "Can't make ${.TARGET} to DESTDIR=/"
341f1de59e0Spgoyette	@false
342f1de59e0Spgoyette.endif
343f1de59e0Spgoyette.if !defined(INSTALLWORLDDIR) || \
344f1de59e0Spgoyette    ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/"
345f1de59e0Spgoyette.if (${HOST_UNAME_S} != "NetBSD")
346f1de59e0Spgoyette	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLWORLDDIR=/"
347f1de59e0Spgoyette	@false
348f1de59e0Spgoyette.endif
349f1de59e0Spgoyette.if (${HOST_UNAME_M} != ${MACHINE})
350f1de59e0Spgoyette	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
351f1de59e0Spgoyette	@false
352f1de59e0Spgoyette.endif
353f1de59e0Spgoyette.endif
354f1de59e0Spgoyette	${MAKEDIRTARGET} distrib/sets installsets \
355f1de59e0Spgoyette		INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS=${INSTALLSETS:Q}
356f1de59e0Spgoyette	${MAKEDIRTARGET} . postinstall-check DESTDIR=${INSTALLWORLDDIR}
357f1de59e0Spgoyette	@echo   "make ${.TARGET} started at:  ${START_TIME}"
358f1de59e0Spgoyette	@printf "make ${.TARGET} finished at: " && date
359f1de59e0Spgoyette
360f1de59e0Spgoyette#
361f1de59e0Spgoyette# Install modules from $DESTDIR to $INSTALLMODULESDIR
362f1de59e0Spgoyette#
363f1de59e0Spgoyetteinstallmodules: .PHONY .MAKE
364f1de59e0Spgoyette.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
365f1de59e0Spgoyette	@echo "Can't make ${.TARGET} to DESTDIR=/"
366f1de59e0Spgoyette	@false
367f1de59e0Spgoyette.endif
368f1de59e0Spgoyette.if !defined(INSTALLMODULESDIR) || \
369f1de59e0Spgoyette    ${INSTALLMODULESDIR} == "" || ${INSTALLMODULESDIR} == "/"
370f1de59e0Spgoyette.if (${HOST_UNAME_S} != "NetBSD")
371f1de59e0Spgoyette	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLMODULESDIR=/"
372f1de59e0Spgoyette	@false
373f1de59e0Spgoyette.endif
374f1de59e0Spgoyette.if (${HOST_UNAME_M} != ${MACHINE})
375f1de59e0Spgoyette	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLMODULESDIR=/"
376f1de59e0Spgoyette	@false
377f1de59e0Spgoyette.endif
378f1de59e0Spgoyette.endif
379f1de59e0Spgoyette	${MAKEDIRTARGET} sys/modules install DESTDIR=${INSTALLMODULESDIR:U/}
380f1de59e0Spgoyette	@echo   "make ${.TARGET} started at:  ${START_TIME}"
381f1de59e0Spgoyette	@printf "make ${.TARGET} finished at: " && date
382f1de59e0Spgoyette
383f1de59e0Spgoyette#
384f1de59e0Spgoyette# Create sets from $DESTDIR or $NETBSDSRCDIR into $RELEASEDIR
385f1de59e0Spgoyette#
386f1de59e0Spgoyette
387f1de59e0Spgoyette.for tgt in sets sourcesets syspkgs
388f1de59e0Spgoyette${tgt}: .PHONY .MAKE
389f1de59e0Spgoyette	${MAKEDIRTARGET} distrib/sets ${tgt}
390f1de59e0Spgoyette.endfor
391f1de59e0Spgoyette
392f1de59e0Spgoyette#
393f1de59e0Spgoyette# Build a release or snapshot (implies "make distribution").  Note that
394f1de59e0Spgoyette# in this case, the set lists will be checked before the tar files
395f1de59e0Spgoyette# are made.
396f1de59e0Spgoyette#
397f1de59e0Spgoyette
398f1de59e0Spgoyetterelease snapshot: .PHONY .MAKE
399f1de59e0Spgoyette	${MAKEDIRTARGET} . distribution
400f1de59e0Spgoyette	${MAKEDIRTARGET} etc release DISTRIBUTION_DONE=1
401f1de59e0Spgoyette	@echo   "make ${.TARGET} started at:  ${START_TIME}"
402f1de59e0Spgoyette	@printf "make ${.TARGET} finished at: " && date
403f1de59e0Spgoyette
404f1de59e0Spgoyette#
405f1de59e0Spgoyette# Create a CD-ROM image.
406f1de59e0Spgoyette#
407f1de59e0Spgoyette
408f1de59e0Spgoyetteiso-image: .PHONY
409f1de59e0Spgoyette	${MAKEDIRTARGET} distrib iso_image
410f1de59e0Spgoyette	${MAKEDIRTARGET} etc iso-image
411f1de59e0Spgoyette	@echo   "make ${.TARGET} started at:  ${START_TIME}"
412f1de59e0Spgoyette	@printf "make ${.TARGET} finished at: " && date
413f1de59e0Spgoyette
414f1de59e0Spgoyetteiso-image-source: .PHONY
415f1de59e0Spgoyette	${MAKEDIRTARGET} distrib iso_image CDSOURCE=true
416f1de59e0Spgoyette	${MAKEDIRTARGET} etc iso-image
417f1de59e0Spgoyette	@echo   "make ${.TARGET} started at:  ${START_TIME}"
418f1de59e0Spgoyette	@printf "make ${.TARGET} finished at: " && date
419f1de59e0Spgoyette
420f1de59e0Spgoyette#
421f1de59e0Spgoyette# Create bootable live images.
422f1de59e0Spgoyette#
423f1de59e0Spgoyette
424f1de59e0Spgoyettelive-image: .PHONY
425f1de59e0Spgoyette	${MAKEDIRTARGET} etc live-image
426f1de59e0Spgoyette	@echo   "make ${.TARGET} started at:  ${START_TIME}"
427f1de59e0Spgoyette	@printf "make ${.TARGET} finished at: " && date
428f1de59e0Spgoyette
429f1de59e0Spgoyette#
430f1de59e0Spgoyette# Create bootable installation images.
431f1de59e0Spgoyette#
432f1de59e0Spgoyette
433f1de59e0Spgoyetteinstall-image: .PHONY
434f1de59e0Spgoyette	${MAKEDIRTARGET} etc install-image
435f1de59e0Spgoyette	@echo   "make ${.TARGET} started at:  ${START_TIME}"
436f1de59e0Spgoyette	@printf "make ${.TARGET} finished at: " && date
437f1de59e0Spgoyette
438f1de59e0Spgoyette#
439f1de59e0Spgoyette# Special components of the "make build" process.
440f1de59e0Spgoyette#
441f1de59e0Spgoyette
442f1de59e0Spgoyettecheck-tools: .PHONY
443f1de59e0Spgoyette.if ${TOOLCHAIN_MISSING} != "no" && !defined(EXTERNAL_TOOLCHAIN)
444f1de59e0Spgoyette	@echo '*** WARNING:  Building on MACHINE=${MACHINE} with missing toolchain.'
445f1de59e0Spgoyette	@echo '*** May result in a failed build or corrupt binaries!'
446f1de59e0Spgoyette.elif defined(EXTERNAL_TOOLCHAIN)
447f1de59e0Spgoyette	@echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
448f1de59e0Spgoyette.endif
449f1de59e0Spgoyette
450f1de59e0Spgoyette# Delete or sanitise a leftover METALOG from a previous build.
451f1de59e0Spgoyetteclean_METALOG: .PHONY .MAKE
452f1de59e0Spgoyette.if ${MKUPDATE} != "no"
453f1de59e0Spgoyette	${MAKEDIRTARGET} distrib/sets clean_METALOG
454f1de59e0Spgoyette.endif
455f1de59e0Spgoyette
456f1de59e0Spgoyettedo-distrib-dirs: .PHONY .MAKE
457f1de59e0Spgoyette.if !defined(DESTDIR) || ${DESTDIR} == ""
458f1de59e0Spgoyette	${MAKEDIRTARGET} etc distrib-dirs DESTDIR=/
459f1de59e0Spgoyette.else
460f1de59e0Spgoyette	${MAKEDIRTARGET} etc distrib-dirs DESTDIR=${DESTDIR}
461f1de59e0Spgoyette.endif
462f1de59e0Spgoyette
463f1de59e0Spgoyette.for targ in cleandir obj includes
464f1de59e0Spgoyettedo-${targ}: .PHONY ${targ}
465f1de59e0Spgoyette	@true
466f1de59e0Spgoyette.endfor
467f1de59e0Spgoyette
468f1de59e0Spgoyettedo-tools: .PHONY .MAKE
469f1de59e0Spgoyette	${MAKEDIRTARGET} tools build_install
470f1de59e0Spgoyette
471f1de59e0Spgoyettedo-lib: .PHONY .MAKE
472f1de59e0Spgoyette	${MAKEDIRTARGET} lib build_install
473f1de59e0Spgoyette
474f1de59e0Spgoyettedo-compat-lib: .PHONY .MAKE
475f1de59e0Spgoyette	${MAKEDIRTARGET} compat build_install BOOTSTRAP_SUBDIRS="../../../lib"
476f1de59e0Spgoyette
477ae9c7cb9Skamildo-sanitizer: .PHONY .MAKE
4781a5f018bSkamil	${MAKEDIRTARGET} external/bsd/compiler_rt build_install
4794ed00d96Skamil
4804ed00d96Skamildo-sanitizer-tools: .PHONY .MAKE
481ae9c7cb9Skamil.if !exists(${TOOLDIR}/lib/clang) && ${HAVE_LLVM:Uno} == "yes"
4824ed00d96Skamil	mkdir -p ${TOOLDIR}/lib/clang
4834ed00d96Skamil	cd ${DESTDIR}/usr/lib/clang && \
4844ed00d96Skamil		${TOOL_PAX} -rw . ${TOOLDIR}/lib/clang
4854ed00d96Skamil.endif
4864ed00d96Skamil
487f1de59e0Spgoyettedo-top-obj: .PHONY .MAKE
488f1de59e0Spgoyette	${MAKEDIRTARGET} . obj NOSUBDIR=
489f1de59e0Spgoyette
490f1de59e0Spgoyettedo-tools-obj: .PHONY .MAKE
491f1de59e0Spgoyette	${MAKEDIRTARGET} tools obj
492f1de59e0Spgoyette
493f1de59e0Spgoyettedo-build: .PHONY .MAKE
494f1de59e0Spgoyette.for targ in dependall install
495f1de59e0Spgoyette	${MAKEDIRTARGET} . ${targ} BUILD_tools=no BUILD_lib=no
496f1de59e0Spgoyette.endfor
497f1de59e0Spgoyette
498f1de59e0Spgoyettedo-x11: .PHONY .MAKE
499f1de59e0Spgoyette.if ${MKX11} != "no"
500f1de59e0Spgoyette	${MAKEDIRTARGET} external/mit/xorg/tools all
501f1de59e0Spgoyette	${MAKEDIRTARGET} external/mit/xorg/lib build_install
502f1de59e0Spgoyette.if ${MKCOMPATX11} != "no"
503f1de59e0Spgoyette	${MAKEDIRTARGET} compat build_install BOOTSTRAP_SUBDIRS="../../../external/mit/xorg/lib"
504f1de59e0Spgoyette.endif
505f1de59e0Spgoyette.else
506f1de59e0Spgoyette	@echo "MKX11 is not enabled"
507f1de59e0Spgoyette	@false
508f1de59e0Spgoyette.endif
509f1de59e0Spgoyette
510f1de59e0Spgoyettedo-obsolete: .PHONY .MAKE
511f1de59e0Spgoyette	${MAKEDIRTARGET} etc install-obsolete-lists
512f1de59e0Spgoyette
513f1de59e0Spgoyette#
514f1de59e0Spgoyette# Speedup stubs for some subtrees that don't need to run these rules.
515f1de59e0Spgoyette# (Tells <bsd.subdir.mk> not to recurse for them.)
516f1de59e0Spgoyette#
517f1de59e0Spgoyette
518f1de59e0Spgoyette.for dir in bin etc distrib games libexec regress sbin usr.bin usr.sbin tools
519f1de59e0Spgoyetteincludes-${dir}: .PHONY
520f1de59e0Spgoyette	@true
521f1de59e0Spgoyette.endfor
522f1de59e0Spgoyette.for dir in etc distrib regress
523f1de59e0Spgoyetteinstall-${dir}: .PHONY
524f1de59e0Spgoyette	@true
525f1de59e0Spgoyette.endfor
526f1de59e0Spgoyette
527f1de59e0Spgoyette#
528f1de59e0Spgoyette# XXX this needs to change when distrib Makefiles are recursion compliant
529f1de59e0Spgoyette# XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
530f1de59e0Spgoyette#
531f1de59e0Spgoyettedependall-distrib depend-distrib all-distrib: .PHONY
532f1de59e0Spgoyette	@true
533f1de59e0Spgoyette
534f1de59e0Spgoyette.include <bsd.obj.mk>
535f1de59e0Spgoyette.include <bsd.kernobj.mk>
536f1de59e0Spgoyette.include <bsd.subdir.mk>
537f1de59e0Spgoyette.include <bsd.clean.mk>
538