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