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