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