xref: /freebsd-12.1/Makefile (revision 166da9ff)
1#
2# $FreeBSD$
3#
4# The user-driven targets are:
5#
6# universe            - *Really* build *everything* (buildworld and
7#                       all kernels on all architectures).
8# tinderbox           - Same as universe, but presents a list of failed build
9#                       targets and exits with an error if there were any.
10# buildworld          - Rebuild *everything*, including glue to help do
11#                       upgrades.
12# installworld        - Install everything built by "buildworld".
13# world               - buildworld + installworld, no kernel.
14# buildkernel         - Rebuild the kernel and the kernel-modules.
15# installkernel       - Install the kernel and the kernel-modules.
16# installkernel.debug
17# reinstallkernel     - Reinstall the kernel and the kernel-modules.
18# reinstallkernel.debug
19# kernel              - buildkernel + installkernel.
20# kernel-toolchain    - Builds the subset of world necessary to build a kernel
21# kernel-toolchains   - Build kernel-toolchain for all universe targets.
22# doxygen             - Build API documentation of the kernel, needs doxygen.
23# update              - Convenient way to update your source tree(s).
24# checkworld          - Run test suite on installed world.
25# check-old           - List obsolete directories/files/libraries.
26# check-old-dirs      - List obsolete directories.
27# check-old-files     - List obsolete files.
28# check-old-libs      - List obsolete libraries.
29# delete-old          - Delete obsolete directories/files.
30# delete-old-dirs     - Delete obsolete directories.
31# delete-old-files    - Delete obsolete files.
32# delete-old-libs     - Delete obsolete libraries.
33# targets             - Print a list of supported TARGET/TARGET_ARCH pairs
34#                       for world and kernel targets.
35# toolchains          - Build a toolchain for all world and kernel targets.
36# xdev                - xdev-build + xdev-install for the architecture
37#                       specified with TARGET and TARGET_ARCH.
38# xdev-build          - Build cross-development tools.
39# xdev-install        - Install cross-development tools.
40# xdev-links          - Create traditional links in /usr/bin for cc, etc
41# native-xtools       - Create host binaries that produce target objects
42#                       for use in qemu user-mode jails.  TARGET and
43#                       TARGET_ARCH should be defined.
44# native-xtools-install
45#                     - Install the files to the given DESTDIR/NXTP where
46#                       NXTP defaults to /nxb-bin.
47#
48# "quick" way to test all kernel builds:
49# 	_jflag=`sysctl -n hw.ncpu`
50# 	_jflag=$(($_jflag * 2))
51# 	[ $_jflag -gt 12 ] && _jflag=12
52# 	make universe -DMAKE_JUST_KERNELS JFLAG=-j${_jflag}
53#
54# This makefile is simple by design. The FreeBSD make automatically reads
55# the /usr/share/mk/sys.mk unless the -m argument is specified on the
56# command line. By keeping this makefile simple, it doesn't matter too
57# much how different the installed mk files are from those in the source
58# tree. This makefile executes a child make process, forcing it to use
59# the mk files from the source tree which are supposed to DTRT.
60#
61# Most of the user-driven targets (as listed above) are implemented in
62# Makefile.inc1.  The exceptions are universe, tinderbox and targets.
63#
64# If you want to build your system from source, be sure that /usr/obj has
65# at least 6 GB of disk space available.  A complete 'universe' build of
66# r340283 (2018-11) required 167 GB of space.  ZFS lz4 compression
67# achieved a 2.18x ratio, reducing actual space to 81 GB.
68#
69# For individuals wanting to build from the sources currently on their
70# system, the simple instructions are:
71#
72# 1.  `cd /usr/src'  (or to the directory containing your source tree).
73# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
74# 3.  `make world'
75#
76# For individuals wanting to upgrade their sources (even if only a
77# delta of a few days):
78#
79#  1.  `cd /usr/src'       (or to the directory containing your source tree).
80#  2.  `make buildworld'
81#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
82#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
83#       [steps 3. & 4. can be combined by using the "kernel" target]
84#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
85#  6.  `mergemaster -p'
86#  7.  `make installworld'
87#  8.  `mergemaster'		(you may wish to use -i, along with -U or -F).
88#  9.  `make delete-old'
89# 10.  `reboot'
90# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
91#
92# See src/UPDATING `COMMON ITEMS' for more complete information.
93#
94# If TARGET=machine (e.g. powerpc, sparc64, ...) is specified you can
95# cross build world for other machine types using the buildworld target,
96# and once the world is built you can cross build a kernel using the
97# buildkernel target.
98#
99# Define the user-driven targets. These are listed here in alphabetical
100# order, but that's not important.
101#
102# Targets that begin with underscore are internal targets intended for
103# developer convenience only.  They are intentionally not documented and
104# completely subject to change without notice.
105#
106# For more information, see the build(7) manual page.
107#
108
109# This is included so CC is set to ccache for -V, and COMPILER_TYPE/VERSION
110# can be cached for sub-makes. We can't do this while still running on the
111# old fmake from FreeBSD 9.x or older, so avoid including it then to avoid
112# heartburn upgrading from older systems. The need for CC is done with new
113# make later in the build, and caching COMPILER_TYPE/VERSION is only an
114# optimization. Also sinclude it to be friendlier to foreign OS hosted builds.
115.if ${MAKE_VERSION} >= 20140620 && defined(.PARSEDIR)
116.sinclude <bsd.compiler.mk>
117.endif
118
119# Note: we use this awkward construct to be compatible with FreeBSD's
120# old make used in 10.0 and 9.2 and earlier.
121.if defined(MK_DIRDEPS_BUILD) && ${MK_DIRDEPS_BUILD} == "yes" && \
122    !make(showconfig) && !make(print-dir)
123# targets/Makefile plays the role of top-level
124.include "targets/Makefile"
125.else
126
127TGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
128	check check-old check-old-dirs check-old-files check-old-libs \
129	checkdpadd checkworld clean cleandepend cleandir cleanworld \
130	cleanuniverse \
131	delete-old delete-old-dirs delete-old-files delete-old-libs \
132	depend distribute distributekernel distributekernel.debug \
133	distributeworld distrib-dirs distribution doxygen \
134	everything hier hierarchy install installcheck installkernel \
135	installkernel.debug packagekernel packageworld \
136	reinstallkernel reinstallkernel.debug \
137	installworld kernel-toolchain libraries maninstall \
138	obj objlink showconfig tags toolchain update \
139	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
140	_build-tools _build-metadata _cross-tools _includes _libraries \
141	build32 distribute32 install32 buildsoft distributesoft installsoft \
142	builddtb xdev xdev-build xdev-install \
143	xdev-links native-xtools native-xtools-install stageworld stagekernel \
144	stage-packages \
145	create-packages-world create-packages-kernel create-packages \
146	packages installconfig real-packages sign-packages package-pkg \
147	print-dir test-system-compiler test-system-linker
148
149# These targets require a TARGET and TARGET_ARCH be defined.
150XTGTS=	native-xtools native-xtools-install xdev xdev-build xdev-install \
151	xdev-links
152
153# XXX: r156740: This can't work since bsd.subdir.mk is not included ever.
154# It will only work for SUBDIR_TARGETS in make.conf.
155TGTS+=	${SUBDIR_TARGETS}
156
157BITGTS=	files includes
158BITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
159TGTS+=	${BITGTS}
160
161# Only some targets are allowed to use meta mode.  Others get it
162# disabled.  In some cases, such as 'install', meta mode can be dangerous
163# as a cookie may be used to prevent redundant installations (such as
164# for WORLDTMP staging).  For DESTDIR=/ we always want to install though.
165# For other cases, such as delete-old-libs, meta mode may break
166# the interactive tty prompt.  The safest route is to just whitelist
167# the ones that benefit from it.
168META_TGT_WHITELIST+= \
169	_* build32 buildfiles buildincludes buildkernel buildsoft \
170	buildworld everything kernel-toolchain kernel-toolchains kernel \
171	kernels libraries native-xtools showconfig test-system-compiler \
172	test-system-linker tinderbox toolchain \
173	toolchains universe universe-toolchain world worlds xdev xdev-build
174
175.ORDER: buildworld installworld
176.ORDER: buildworld distrib-dirs
177.ORDER: buildworld distribution
178.ORDER: buildworld distribute
179.ORDER: buildworld distributeworld
180.ORDER: buildworld buildkernel
181.ORDER: distrib-dirs distribute
182.ORDER: distrib-dirs distributeworld
183.ORDER: distrib-dirs installworld
184.ORDER: distribution distribute
185.ORDER: distributeworld distribute
186.ORDER: distributeworld distribution
187.ORDER: installworld distribute
188.ORDER: installworld distribution
189.ORDER: installworld installkernel
190.ORDER: buildkernel installkernel
191.ORDER: buildkernel installkernel.debug
192.ORDER: buildkernel reinstallkernel
193.ORDER: buildkernel reinstallkernel.debug
194
195PATH=	/sbin:/bin:/usr/sbin:/usr/bin
196MAKEOBJDIRPREFIX?=	/usr/obj
197_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} MK_AUTO_OBJ=no \
198    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
199    SRCCONF=${SRCCONF} SRC_ENV_CONF= \
200    -f /dev/null -V MAKEOBJDIRPREFIX dummy
201.if !empty(_MAKEOBJDIRPREFIX)
202.error MAKEOBJDIRPREFIX can only be set in environment or src-env.conf(5),\
203    not as a global (in make.conf(5) or src.conf(5)) or command-line variable.
204.endif
205
206# We often need to use the tree's version of make to build it.
207# Choices add to complexity though.
208# We cannot blindly use a make which may not be the one we want
209# so be explicit - until all choice is removed.
210WANT_MAKE=	bmake
211.if !empty(.MAKE.MODE:Mmeta)
212# 20160604 - support missing-meta,missing-filemon and performance improvements
213WANT_MAKE_VERSION= 20160604
214.else
215# 20160220 - support .dinclude for FAST_DEPEND.
216WANT_MAKE_VERSION= 20160220
217.endif
218MYMAKE=		${OBJROOT}make.${MACHINE}/${WANT_MAKE}
219.if defined(.PARSEDIR)
220HAVE_MAKE=	bmake
221.else
222HAVE_MAKE=	fmake
223.endif
224.if defined(ALWAYS_BOOTSTRAP_MAKE) || \
225    ${HAVE_MAKE} != ${WANT_MAKE} || \
226    (defined(WANT_MAKE_VERSION) && ${MAKE_VERSION} < ${WANT_MAKE_VERSION})
227NEED_MAKE_UPGRADE= t
228.endif
229.if exists(${MYMAKE})
230SUB_MAKE:= ${MYMAKE} -m ${.CURDIR}/share/mk
231.elif defined(NEED_MAKE_UPGRADE)
232# It may not exist yet but we may cause it to.
233# In the case of fmake, upgrade_checks may cause a newer version to be built.
234SUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \
235	-m ${.CURDIR}/share/mk
236.else
237SUB_MAKE= ${MAKE} -m ${.CURDIR}/share/mk
238.endif
239
240_MAKE=	PATH=${PATH} MAKE_CMD="${MAKE}" ${SUB_MAKE} -f Makefile.inc1 \
241	TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH} ${_MAKEARGS}
242
243.if defined(MK_META_MODE) && ${MK_META_MODE} == "yes"
244# Only allow meta mode for the whitelisted targets.  See META_TGT_WHITELIST
245# above.  If overridden as a make argument then don't bother trying to
246# disable it.
247.if empty(.MAKEOVERRIDES:MMK_META_MODE)
248.for _tgt in ${META_TGT_WHITELIST}
249.if make(${_tgt})
250_CAN_USE_META_MODE?= yes
251.endif
252.endfor
253.if !defined(_CAN_USE_META_MODE)
254_MAKE+=	MK_META_MODE=no
255MK_META_MODE= no
256.if defined(.PARSEDIR)
257.unexport META_MODE
258.endif
259.endif	# !defined(_CAN_USE_META_MODE)
260.endif	# empty(.MAKEOVERRIDES:MMK_META_MODE)
261
262.if ${MK_META_MODE} == "yes"
263.if !exists(/dev/filemon) && !defined(NO_FILEMON) && !make(showconfig)
264# Require filemon be loaded to provide a working incremental build
265.error ${.newline}ERROR: The filemon module (/dev/filemon) is not loaded. \
266    ${.newline}ERROR: WITH_META_MODE is enabled but requires filemon for an incremental build. \
267    ${.newline}ERROR: 'kldload filemon' or pass -DNO_FILEMON to suppress this error.
268.endif	# !exists(/dev/filemon) && !defined(NO_FILEMON)
269.endif	# ${MK_META_MODE} == yes
270.endif	# defined(MK_META_MODE) && ${MK_META_MODE} == yes
271
272# Guess target architecture from target type, and vice versa, based on
273# historic FreeBSD practice of tending to have TARGET == TARGET_ARCH
274# expanding to TARGET == TARGET_CPUARCH in recent times, with known
275# exceptions.
276.if !defined(TARGET_ARCH) && defined(TARGET)
277# T->TA mapping is usually TARGET with arm64 the odd man out
278_TARGET_ARCH=	${TARGET:S/arm64/aarch64/:S/riscv/riscv64/}
279.elif !defined(TARGET) && defined(TARGET_ARCH) && \
280    ${TARGET_ARCH} != ${MACHINE_ARCH}
281# TA->T mapping is accidentally CPUARCH with aarch64 the odd man out
282_TARGET=	${TARGET_ARCH:${__TO_CPUARCH}:C/aarch64/arm64/}
283.endif
284.if defined(TARGET) && !defined(_TARGET)
285_TARGET=${TARGET}
286.endif
287.if defined(TARGET_ARCH) && !defined(_TARGET_ARCH)
288_TARGET_ARCH=${TARGET_ARCH}
289.endif
290# for historical compatibility for xdev targets
291.if defined(XDEV)
292_TARGET=	${XDEV}
293.endif
294.if defined(XDEV_ARCH)
295_TARGET_ARCH=	${XDEV_ARCH}
296.endif
297# Some targets require a set TARGET/TARGET_ARCH, check before the default
298# MACHINE and after the compatibility handling.
299.if !defined(_TARGET) || !defined(_TARGET_ARCH)
300${XTGTS}: _assert_target
301.endif
302# Otherwise, default to current machine type and architecture.
303_TARGET?=	${MACHINE}
304_TARGET_ARCH?=	${MACHINE_ARCH}
305
306.if make(native-xtools*)
307NXB_TARGET:=		${_TARGET}
308NXB_TARGET_ARCH:=	${_TARGET_ARCH}
309_TARGET=		${MACHINE}
310_TARGET_ARCH=		${MACHINE_ARCH}
311_MAKE+=			NXB_TARGET=${NXB_TARGET} \
312			NXB_TARGET_ARCH=${NXB_TARGET_ARCH}
313.endif
314
315.if make(print-dir)
316.SILENT:
317.endif
318
319_assert_target: .PHONY .MAKE
320.for _tgt in ${XTGTS}
321.if make(${_tgt})
322	@echo "*** Error: Both TARGET and TARGET_ARCH must be defined for \"${_tgt}\" target"
323	@false
324.endif
325.endfor
326
327#
328# Make sure we have an up-to-date make(1). Only world and buildworld
329# should do this as those are the initial targets used for upgrades.
330# The user can define ALWAYS_CHECK_MAKE to have this check performed
331# for all targets.
332#
333.if defined(ALWAYS_CHECK_MAKE) || !defined(.PARSEDIR)
334${TGTS}: upgrade_checks
335.else
336buildworld: upgrade_checks
337.endif
338
339#
340# Handle the user-driven targets, using the source relative mk files.
341#
342
343tinderbox toolchains kernel-toolchains: .MAKE
344${TGTS}: .PHONY .MAKE
345	${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET}
346
347# The historic default "all" target creates files which may cause stale
348# or (in the cross build case) unlinkable results. Fail with an error
349# when no target is given. The users can explicitly specify "all"
350# if they want the historic behavior.
351.MAIN:	_guard
352
353_guard: .PHONY
354	@echo
355	@echo "Explicit target required.  Likely \"${SUBDIR_OVERRIDE:Dall:Ubuildworld}\" is wanted.  See build(7)."
356	@echo
357	@false
358
359STARTTIME!= LC_ALL=C date
360CHECK_TIME!= cmp=`mktemp`; find ${.CURDIR}/sys/sys/param.h -newer "$$cmp" && rm "$$cmp"; echo
361.if !empty(CHECK_TIME)
362.error check your date/time: ${STARTTIME}
363.endif
364
365.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
366#
367# world
368#
369# Attempt to rebuild and reinstall everything. This target is not to be
370# used for upgrading an existing FreeBSD system, because the kernel is
371# not included. One can argue that this target doesn't build everything
372# then.
373#
374world: upgrade_checks .PHONY
375	@echo "--------------------------------------------------------------"
376	@echo ">>> make world started on ${STARTTIME}"
377	@echo "--------------------------------------------------------------"
378.if target(pre-world)
379	@echo
380	@echo "--------------------------------------------------------------"
381	@echo ">>> Making 'pre-world' target"
382	@echo "--------------------------------------------------------------"
383	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
384.endif
385	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
386	${_+_}@cd ${.CURDIR}; ${_MAKE} installworld MK_META_MODE=no
387.if target(post-world)
388	@echo
389	@echo "--------------------------------------------------------------"
390	@echo ">>> Making 'post-world' target"
391	@echo "--------------------------------------------------------------"
392	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
393.endif
394	@echo
395	@echo "--------------------------------------------------------------"
396	@echo ">>> make world completed on `LC_ALL=C date`"
397	@echo "                   (started ${STARTTIME})"
398	@echo "--------------------------------------------------------------"
399.else
400world: .PHONY
401	@echo "WARNING: make world will overwrite your existing FreeBSD"
402	@echo "installation without also building and installing a new"
403	@echo "kernel.  This can be dangerous.  Please read the handbook,"
404	@echo "'Rebuilding world', for how to upgrade your system."
405	@echo "Define DESTDIR to where you want to install FreeBSD,"
406	@echo "including /, to override this warning and proceed as usual."
407	@echo ""
408	@echo "Bailing out now..."
409	@false
410.endif
411
412#
413# kernel
414#
415# Short hand for `make buildkernel installkernel'
416#
417kernel: buildkernel installkernel .PHONY
418
419#
420# Perform a few tests to determine if the installed tools are adequate
421# for building the world.
422#
423upgrade_checks: .PHONY
424.if defined(NEED_MAKE_UPGRADE)
425	@${_+_}(cd ${.CURDIR} && ${MAKE} ${WANT_MAKE:S,^f,,})
426.endif
427
428#
429# Upgrade make(1) to the current version using the installed
430# headers, libraries and tools.  Also, allow the location of
431# the system bsdmake-like utility to be overridden.
432#
433MMAKEENV=	\
434		DESTDIR= \
435		INSTALL="sh ${.CURDIR}/tools/install.sh"
436MMAKE=		${MMAKEENV} ${MAKE} \
437		OBJTOP=${MYMAKE:H}/obj \
438		OBJROOT='$${OBJTOP}/' \
439		MAKEOBJDIRPREFIX= \
440		MAN= -DNO_SHARED \
441		-DNO_CPU_CFLAGS -DNO_WERROR \
442		-DNO_SUBDIR \
443		DESTDIR= PROGNAME=${MYMAKE:T}
444
445bmake: .PHONY
446	@echo
447	@echo "--------------------------------------------------------------"
448	@echo ">>> Building an up-to-date ${.TARGET}(1)"
449	@echo "--------------------------------------------------------------"
450	${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \
451		${MMAKE} obj; \
452		${MMAKE} depend; \
453		${MMAKE} all; \
454		${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR=
455
456regress: .PHONY
457	@echo "'make regress' has been renamed 'make check'" | /usr/bin/fmt
458	@false
459
460tinderbox toolchains kernel-toolchains kernels worlds: upgrade_checks
461
462tinderbox: .PHONY
463	@cd ${.CURDIR}; ${SUB_MAKE} DOING_TINDERBOX=YES universe
464
465toolchains: .PHONY
466	@cd ${.CURDIR}; ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe
467
468kernel-toolchains: .PHONY
469	@cd ${.CURDIR}; ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe
470
471kernels: .PHONY
472	@cd ${.CURDIR}; ${SUB_MAKE} UNIVERSE_TARGET=buildkernel universe
473
474worlds: .PHONY
475	@cd ${.CURDIR}; ${SUB_MAKE} UNIVERSE_TARGET=buildworld universe
476
477#
478# universe
479#
480# Attempt to rebuild *everything* for all supported architectures,
481# with a reasonable chance of success, regardless of how old your
482# existing system is.
483#
484.if make(universe) || make(universe_kernels) || make(tinderbox) || \
485    make(targets) || make(universe-toolchain)
486TARGETS?=amd64 arm arm64 i386 mips powerpc riscv sparc64
487_UNIVERSE_TARGETS=	${TARGETS}
488TARGET_ARCHES_arm?=	arm armv6 armv7
489TARGET_ARCHES_arm64?=	aarch64
490TARGET_ARCHES_mips?=	mipsel mips mips64el mips64 mipsn32 mipselhf mipshf mips64elhf mips64hf
491TARGET_ARCHES_powerpc?=	powerpc powerpc64 powerpcspe
492# riscv64sf excluded due to PR 232085
493TARGET_ARCHES_riscv?=	riscv64
494.for target in ${TARGETS}
495TARGET_ARCHES_${target}?= ${target}
496.endfor
497
498MAKE_PARAMS_riscv?=	CROSS_TOOLCHAIN=riscv64-gcc
499
500# XXX Remove architectures only supported by external toolchain from universe
501# if required toolchain packages are missing.
502TOOLCHAINS_riscv=	riscv64
503.for target in riscv
504.if ${_UNIVERSE_TARGETS:M${target}}
505.for toolchain in ${TOOLCHAINS_${target}}
506.if !exists(/usr/local/share/toolchains/${toolchain}-gcc.mk)
507_UNIVERSE_TARGETS:= ${_UNIVERSE_TARGETS:N${target}}
508universe: universe_${toolchain}_skip .PHONY
509universe_epilogue: universe_${toolchain}_skip .PHONY
510universe_${toolchain}_skip: universe_prologue .PHONY
511	@echo ">> ${target} skipped - install ${toolchain}-xtoolchain-gcc port or package to build"
512.endif
513.endfor
514.endif
515.endfor
516
517.if defined(UNIVERSE_TARGET)
518MAKE_JUST_WORLDS=	YES
519.else
520UNIVERSE_TARGET?=	buildworld
521.endif
522KERNSRCDIR?=		${.CURDIR}/sys
523
524targets:	.PHONY
525	@echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
526.for target in ${TARGETS}
527.for target_arch in ${TARGET_ARCHES_${target}}
528	@echo "    ${target}/${target_arch}"
529.endfor
530.endfor
531
532.if defined(DOING_TINDERBOX)
533FAILFILE=${.CURDIR}/_.tinderbox.failed
534MAKEFAIL=tee -a ${FAILFILE}
535.else
536MAKEFAIL=cat
537.endif
538
539universe_prologue:  upgrade_checks
540universe: universe_prologue
541universe_prologue: .PHONY
542	@echo "--------------------------------------------------------------"
543	@echo ">>> make universe started on ${STARTTIME}"
544	@echo "--------------------------------------------------------------"
545.if defined(DOING_TINDERBOX)
546	@rm -f ${FAILFILE}
547.endif
548
549universe-toolchain: .PHONY universe_prologue
550	@echo "--------------------------------------------------------------"
551	@echo "> Toolchain bootstrap started on `LC_ALL=C date`"
552	@echo "--------------------------------------------------------------"
553	${_+_}@cd ${.CURDIR}; \
554	    env PATH=${PATH} ${SUB_MAKE} ${JFLAG} kernel-toolchain \
555	    TARGET=${MACHINE} TARGET_ARCH=${MACHINE_ARCH} \
556	    OBJTOP="${HOST_OBJTOP}" \
557	    WITHOUT_SYSTEM_COMPILER=yes \
558	    WITHOUT_SYSTEM_LINKER=yes \
559	    TOOLS_PREFIX_UNDEF= \
560	    kernel-toolchain \
561	    MK_LLVM_TARGET_ALL=yes \
562	    > _.${.TARGET} 2>&1 || \
563	    (echo "${.TARGET} failed," \
564	    "check _.${.TARGET} for details" | \
565	    ${MAKEFAIL}; false)
566	@if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/cc" ]; then \
567	    echo "Missing host compiler at ${HOST_OBJTOP}/tmp/usr/bin/cc?" >&2; \
568	    false; \
569	fi
570	@if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/ld" ]; then \
571	    echo "Missing host linker at ${HOST_OBJTOP}/tmp/usr/bin/cc?" >&2; \
572	    false; \
573	fi
574	@echo "--------------------------------------------------------------"
575	@echo "> Toolchain bootstrap completed on `LC_ALL=C date`"
576	@echo "--------------------------------------------------------------"
577
578.for target in ${_UNIVERSE_TARGETS}
579universe: universe_${target}
580universe_epilogue: universe_${target}
581universe_${target}: universe_${target}_prologue .PHONY
582universe_${target}_prologue: universe_prologue .PHONY
583	@echo ">> ${target} started on `LC_ALL=C date`"
584universe_${target}_worlds: .PHONY
585
586.if !make(targets) && !make(universe-toolchain)
587.for target_arch in ${TARGET_ARCHES_${target}}
588.if !defined(_need_clang_${target}_${target_arch})
589_need_clang_${target}_${target_arch} != \
590	env TARGET=${target} TARGET_ARCH=${target_arch} \
591	${SUB_MAKE} -C ${.CURDIR} -f Makefile.inc1 test-system-compiler \
592	    ${MAKE_PARAMS_${target}} -V MK_CLANG_BOOTSTRAP 2>/dev/null || \
593	    echo unknown
594.export _need_clang_${target}_${target_arch}
595.endif
596.if !defined(_need_lld_${target}_${target_arch})
597_need_lld_${target}_${target_arch} != \
598	env TARGET=${target} TARGET_ARCH=${target_arch} \
599	${SUB_MAKE} -C ${.CURDIR} -f Makefile.inc1 test-system-linker \
600	    ${MAKE_PARAMS_${target}} -V MK_LLD_BOOTSTRAP 2>/dev/null || \
601	    echo unknown
602.export _need_lld_${target}_${target_arch}
603.endif
604# Setup env for each arch to use the one clang.
605.if defined(_need_clang_${target}_${target_arch}) && \
606    ${_need_clang_${target}_${target_arch}} == "yes"
607# No check on existing XCC or CROSS_BINUTILS_PREFIX, etc, is needed since
608# we use the test-system-compiler logic to determine if clang needs to be
609# built.  It will be no from that logic if already using an external
610# toolchain or /usr/bin/cc.
611# XXX: Passing HOST_OBJTOP into the PATH would allow skipping legacy,
612#      bootstrap-tools, and cross-tools.  Need to ensure each tool actually
613#      supports all TARGETS though.
614MAKE_PARAMS_${target}+= \
615	XCC="${HOST_OBJTOP}/tmp/usr/bin/cc" \
616	XCXX="${HOST_OBJTOP}/tmp/usr/bin/c++" \
617	XCPP="${HOST_OBJTOP}/tmp/usr/bin/cpp"
618.endif
619.if defined(_need_lld_${target}_${target_arch}) && \
620    ${_need_lld_${target}_${target_arch}} == "yes"
621MAKE_PARAMS_${target}+= \
622	XLD="${HOST_OBJTOP}/tmp/usr/bin/ld"
623.endif
624.endfor
625.endif	# !make(targets)
626
627.if !defined(MAKE_JUST_KERNELS)
628universe_${target}_done: universe_${target}_worlds .PHONY
629.for target_arch in ${TARGET_ARCHES_${target}}
630universe_${target}_worlds: universe_${target}_${target_arch} .PHONY
631.if (defined(_need_clang_${target}_${target_arch}) && \
632    ${_need_clang_${target}_${target_arch}} == "yes") || \
633    (defined(_need_lld_${target}_${target_arch}) && \
634    ${_need_lld_${target}_${target_arch}} == "yes")
635universe_${target}_${target_arch}: universe-toolchain
636universe_${target}_prologue: universe-toolchain
637.endif
638universe_${target}_${target_arch}: universe_${target}_prologue .MAKE .PHONY
639	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
640	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
641	    ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
642	    TARGET=${target} \
643	    TARGET_ARCH=${target_arch} \
644	    ${MAKE_PARAMS_${target}} \
645	    > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
646	    (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
647	    "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
648	    ${MAKEFAIL}))
649	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
650.endfor
651.endif # !MAKE_JUST_KERNELS
652
653.if !defined(MAKE_JUST_WORLDS)
654universe_${target}_done: universe_${target}_kernels .PHONY
655universe_${target}_kernels: universe_${target}_worlds .PHONY
656universe_${target}_kernels: universe_${target}_prologue .MAKE .PHONY
657	@if [ -e "${KERNSRCDIR}/${target}/conf/NOTES" ]; then \
658	  (cd ${KERNSRCDIR}/${target}/conf && env __MAKE_CONF=/dev/null \
659	    ${SUB_MAKE} LINT \
660	    > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
661	    (echo "${target} 'make LINT' failed," \
662	    "check _.${target}.makeLINT for details"| ${MAKEFAIL})); \
663	fi
664	@cd ${.CURDIR}; ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
665	    universe_kernels
666.endif # !MAKE_JUST_WORLDS
667
668# Tell the user the worlds and kernels have completed
669universe_${target}: universe_${target}_done
670universe_${target}_done:
671	@echo ">> ${target} completed on `LC_ALL=C date`"
672.endfor
673.if make(universe_kernconfs) || make(universe_kernels)
674.if !defined(TARGET)
675TARGET!=	uname -m
676.endif
677universe_kernels_prologue: .PHONY
678	@echo ">> ${TARGET} kernels started on `LC_ALL=C date`"
679universe_kernels: universe_kernconfs .PHONY
680	@echo ">> ${TARGET} kernels completed on `LC_ALL=C date`"
681.if defined(MAKE_ALL_KERNELS)
682_THINNER=cat
683.elif defined(MAKE_LINT_KERNELS)
684_THINNER=grep 'LINT' || true
685.else
686_THINNER=xargs grep -L "^.NO_UNIVERSE" || true
687.endif
688KERNCONFS!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
689		find [[:upper:][:digit:]]*[[:upper:][:digit:]] \
690		-type f -maxdepth 0 \
691		! -name DEFAULTS ! -name NOTES | \
692		${_THINNER}
693universe_kernconfs: universe_kernels_prologue .PHONY
694.for kernel in ${KERNCONFS}
695TARGET_ARCH_${kernel}!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
696	config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
697	grep -v WARNING: | cut -f 2
698.if empty(TARGET_ARCH_${kernel})
699.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
700.endif
701universe_kernconfs: universe_kernconf_${TARGET}_${kernel}
702universe_kernconf_${TARGET}_${kernel}: .MAKE
703	@echo ">> ${TARGET}.${TARGET_ARCH_${kernel}} ${kernel} kernel started on `LC_ALL=C date`"
704	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
705	    ${SUB_MAKE} ${JFLAG} buildkernel \
706	    TARGET=${TARGET} \
707	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
708	    ${MAKE_PARAMS_${TARGET}} \
709	    KERNCONF=${kernel} \
710	    > _.${TARGET}.${kernel} 2>&1 || \
711	    (echo "${TARGET} ${kernel} kernel failed," \
712	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
713	@echo ">> ${TARGET}.${TARGET_ARCH_${kernel}} ${kernel} kernel completed on `LC_ALL=C date`"
714.endfor
715.endif	# make(universe_kernels)
716universe: universe_epilogue
717universe_epilogue: .PHONY
718	@echo "--------------------------------------------------------------"
719	@echo ">>> make universe completed on `LC_ALL=C date`"
720	@echo "                      (started ${STARTTIME})"
721	@echo "--------------------------------------------------------------"
722.if defined(DOING_TINDERBOX)
723	@if [ -e ${FAILFILE} ] ; then \
724		echo "Tinderbox failed:" ;\
725		cat ${FAILFILE} ;\
726		exit 1 ;\
727	fi
728.endif
729.endif
730
731buildLINT: .PHONY
732	${MAKE} -C ${.CURDIR}/sys/${_TARGET}/conf LINT
733
734.if defined(.PARSEDIR)
735# This makefile does not run in meta mode
736.MAKE.MODE= normal
737# Normally the things we run from here don't either.
738# Using -DWITH_META_MODE
739# we can buildworld with meta files created which are useful
740# for debugging, but without any of the rest of a meta mode build.
741MK_DIRDEPS_BUILD= no
742MK_STAGING= no
743# tell meta.autodep.mk to not even think about updating anything.
744UPDATE_DEPENDFILE= NO
745.if !make(showconfig)
746.export MK_DIRDEPS_BUILD MK_STAGING UPDATE_DEPENDFILE
747.endif
748
749.if make(universe)
750# we do not want a failure of one branch abort all.
751MAKE_JOB_ERROR_TOKEN= no
752.export MAKE_JOB_ERROR_TOKEN
753.endif
754.endif # bmake
755
756.endif				# DIRDEPS_BUILD
757