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