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