xref: /freebsd/Makefile (revision 188bf8876fdc6e3edebeb76f80e764e419a65f1e)
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?=amd64 arm arm64 i386 powerpc riscv
534_UNIVERSE_TARGETS=	${TARGETS}
535TARGET_ARCHES_arm?=	armv6 armv7
536TARGET_ARCHES_arm64?=	aarch64
537TARGET_ARCHES_powerpc?=	powerpc powerpc64 powerpc64le ${EXTRA_ARCHES_powerpc}
538TARGET_ARCHES_riscv?=	riscv64
539.for target in ${TARGETS}
540TARGET_ARCHES_${target}?= ${target}
541.endfor
542
543.if defined(USE_GCC_TOOLCHAINS)
544TOOLCHAINS_amd64=	amd64-gcc12
545TOOLCHAINS_arm=		armv6-gcc12 armv7-gcc12
546TOOLCHAIN_armv7=	armv7-gcc12
547TOOLCHAINS_arm64=	aarch64-gcc12
548TOOLCHAINS_i386=	i386-gcc12
549TOOLCHAINS_powerpc=	powerpc-gcc12 powerpc64-gcc12
550TOOLCHAIN_powerpc64=	powerpc64-gcc12
551TOOLCHAINS_riscv=	riscv64-gcc12
552.endif
553
554# If a target is using an external toolchain, set MAKE_PARAMS to enable use
555# of the toolchain.  If the external toolchain is missing, exclude the target
556# from universe.
557.for target in ${_UNIVERSE_TARGETS}
558.if !empty(TOOLCHAINS_${target})
559.for toolchain in ${TOOLCHAINS_${target}}
560.if !exists(/usr/local/share/toolchains/${toolchain}.mk)
561_UNIVERSE_TARGETS:= ${_UNIVERSE_TARGETS:N${target}}
562universe: universe_${toolchain}_skip .PHONY
563universe_epilogue: universe_${toolchain}_skip .PHONY
564universe_${toolchain}_skip: universe_prologue .PHONY
565	@echo ">> ${target} skipped - install ${toolchain} port or package to build"
566.endif
567.endfor
568.for arch in ${TARGET_ARCHES_${target}}
569TOOLCHAIN_${arch}?=	${TOOLCHAINS_${target}:[1]}
570MAKE_PARAMS_${arch}?=	CROSS_TOOLCHAIN=${TOOLCHAIN_${arch}}
571.endfor
572.endif
573.endfor
574
575UNIVERSE_TARGET?=	buildworld
576KERNSRCDIR?=		${.CURDIR}/sys
577
578targets:	.PHONY
579	@echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
580.for target in ${TARGETS}
581.for target_arch in ${TARGET_ARCHES_${target}}
582	@echo "    ${target}/${target_arch}"
583.endfor
584.endfor
585
586.if defined(DOING_TINDERBOX)
587FAILFILE=${.CURDIR}/_.tinderbox.failed
588MAKEFAIL=tee -a ${FAILFILE}
589.else
590MAKEFAIL=cat
591.endif
592
593universe_prologue:  upgrade_checks
594universe: universe_prologue
595universe_prologue: .PHONY
596	@echo "--------------------------------------------------------------"
597	@echo ">>> make universe started on ${STARTTIME}"
598	@echo "--------------------------------------------------------------"
599.if defined(DOING_TINDERBOX)
600	@rm -f ${FAILFILE}
601.endif
602
603universe-toolchain: .PHONY universe_prologue
604	@echo "--------------------------------------------------------------"
605	@echo "> Toolchain bootstrap started on `LC_ALL=C date`"
606	@echo "--------------------------------------------------------------"
607	${_+_}@cd ${.CURDIR}; \
608	    env PATH=${PATH:Q} ${SUB_MAKE} ${JFLAG} kernel-toolchain \
609	    TARGET=${MACHINE} TARGET_ARCH=${MACHINE_ARCH} \
610	    OBJTOP="${HOST_OBJTOP}" \
611	    WITHOUT_SYSTEM_COMPILER=yes \
612	    WITHOUT_SYSTEM_LINKER=yes \
613	    TOOLS_PREFIX_UNDEF= \
614	    kernel-toolchain \
615	    MK_LLVM_TARGET_ALL=yes \
616	    > _.${.TARGET} 2>&1 || \
617	    (echo "${.TARGET} failed," \
618	    "check _.${.TARGET} for details" | \
619	    ${MAKEFAIL}; false)
620	@if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/cc" ]; then \
621	    echo "Missing host compiler at ${HOST_OBJTOP}/tmp/usr/bin/cc?" >&2; \
622	    false; \
623	fi
624	@if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/ld" ]; then \
625	    echo "Missing host linker at ${HOST_OBJTOP}/tmp/usr/bin/ld?" >&2; \
626	    false; \
627	fi
628	@echo "--------------------------------------------------------------"
629	@echo "> Toolchain bootstrap completed on `LC_ALL=C date`"
630	@echo "--------------------------------------------------------------"
631
632.for target in ${_UNIVERSE_TARGETS}
633universe: universe_${target}
634universe_epilogue: universe_${target}
635universe_${target}: universe_${target}_prologue .PHONY
636universe_${target}_prologue: universe_prologue .PHONY
637	@echo ">> ${target} started on `LC_ALL=C date`"
638universe_${target}_worlds: .PHONY
639
640.if !make(targets) && !make(universe-toolchain)
641.for target_arch in ${TARGET_ARCHES_${target}}
642.if !defined(_need_clang_${target}_${target_arch})
643_need_clang_${target}_${target_arch} != \
644	env TARGET=${target} TARGET_ARCH=${target_arch} \
645	${SUB_MAKE} -C ${.CURDIR} -f Makefile.inc1 test-system-compiler \
646	    ${MAKE_PARAMS_${target_arch}} -V MK_CLANG_BOOTSTRAP 2>/dev/null || \
647	    echo unknown
648.export _need_clang_${target}_${target_arch}
649.endif
650.if !defined(_need_lld_${target}_${target_arch})
651_need_lld_${target}_${target_arch} != \
652	env TARGET=${target} TARGET_ARCH=${target_arch} \
653	${SUB_MAKE} -C ${.CURDIR} -f Makefile.inc1 test-system-linker \
654	    ${MAKE_PARAMS_${target_arch}} -V MK_LLD_BOOTSTRAP 2>/dev/null || \
655	    echo unknown
656.export _need_lld_${target}_${target_arch}
657.endif
658# Setup env for each arch to use the one clang.
659.if defined(_need_clang_${target}_${target_arch}) && \
660    ${_need_clang_${target}_${target_arch}} == "yes"
661# No check on existing XCC or CROSS_BINUTILS_PREFIX, etc, is needed since
662# we use the test-system-compiler logic to determine if clang needs to be
663# built.  It will be no from that logic if already using an external
664# toolchain or /usr/bin/cc.
665# XXX: Passing HOST_OBJTOP into the PATH would allow skipping legacy,
666#      bootstrap-tools, and cross-tools.  Need to ensure each tool actually
667#      supports all TARGETS though.
668# For now we only pass UNIVERSE_TOOLCHAIN_PATH which will be added at the end
669# of STRICTTMPPATH to ensure that the target-specific binaries come first.
670MAKE_PARAMS_${target_arch}+= \
671	XCC="${HOST_OBJTOP}/tmp/usr/bin/cc" \
672	XCXX="${HOST_OBJTOP}/tmp/usr/bin/c++" \
673	XCPP="${HOST_OBJTOP}/tmp/usr/bin/cpp" \
674	UNIVERSE_TOOLCHAIN_PATH=${HOST_OBJTOP}/tmp/usr/bin
675.endif
676.if defined(_need_lld_${target}_${target_arch}) && \
677    ${_need_lld_${target}_${target_arch}} == "yes"
678MAKE_PARAMS_${target_arch}+= \
679	XLD="${HOST_OBJTOP}/tmp/usr/bin/ld"
680.endif
681.endfor
682.endif	# !make(targets)
683
684.if ${__DO_WORLDS} == "yes"
685universe_${target}_done: universe_${target}_worlds .PHONY
686.for target_arch in ${TARGET_ARCHES_${target}}
687universe_${target}_worlds: universe_${target}_${target_arch} .PHONY
688.if (defined(_need_clang_${target}_${target_arch}) && \
689    ${_need_clang_${target}_${target_arch}} == "yes") || \
690    (defined(_need_lld_${target}_${target_arch}) && \
691    ${_need_lld_${target}_${target_arch}} == "yes")
692universe_${target}_${target_arch}: universe-toolchain
693universe_${target}_prologue: universe-toolchain
694.endif
695universe_${target}_${target_arch}: universe_${target}_prologue .MAKE .PHONY
696	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
697	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
698	    ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
699	    TARGET=${target} \
700	    TARGET_ARCH=${target_arch} \
701	    ${MAKE_PARAMS_${target_arch}} \
702	    > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
703	    (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
704	    "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
705	    ${MAKEFAIL}))
706	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
707.endfor
708.endif # ${__DO_WORLDS} == "yes"
709
710.if ${__DO_KERNELS} == "yes"
711universe_${target}_done: universe_${target}_kernels .PHONY
712universe_${target}_kernels: universe_${target}_worlds .PHONY
713universe_${target}_kernels: universe_${target}_prologue .MAKE .PHONY
714	@cd ${.CURDIR}; ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
715	    universe_kernels
716.endif # ${__DO_KERNELS} == "yes"
717
718# Tell the user the worlds and kernels have completed
719universe_${target}: universe_${target}_done
720universe_${target}_done:
721	@echo ">> ${target} completed on `LC_ALL=C date`"
722.endfor
723.if make(universe_kernconfs) || make(universe_kernels)
724.if !defined(TARGET)
725TARGET!=	uname -m
726.endif
727universe_kernels_prologue: .PHONY
728	@echo ">> ${TARGET} kernels started on `LC_ALL=C date`"
729universe_kernels: universe_kernconfs .PHONY
730	@echo ">> ${TARGET} kernels completed on `LC_ALL=C date`"
731.if defined(MAKE_ALL_KERNELS)
732_THINNER=cat
733.elif defined(MAKE_LINT_KERNELS)
734_THINNER=grep 'LINT' || true
735.else
736_THINNER=xargs grep -L "^.NO_UNIVERSE" || true
737.endif
738KERNCONFS!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
739		find [[:upper:][:digit:]]*[[:upper:][:digit:]] \
740		-type f -maxdepth 0 \
741		! -name DEFAULTS ! -name NOTES | \
742		${_THINNER}
743universe_kernconfs: universe_kernels_prologue .PHONY
744.for kernel in ${KERNCONFS}
745TARGET_ARCH_${kernel}!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
746	env PATH=${HOST_OBJTOP}/tmp/legacy/bin:${PATH:Q} \
747	config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
748	grep -v WARNING: | cut -f 2
749.if empty(TARGET_ARCH_${kernel})
750.error Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old.
751.endif
752universe_kernconfs_${TARGET_ARCH_${kernel}}: universe_kernconf_${TARGET}_${kernel}
753universe_kernconf_${TARGET}_${kernel}: .MAKE
754	@echo ">> ${TARGET}.${TARGET_ARCH_${kernel}} ${kernel} kernel started on `LC_ALL=C date`"
755	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
756	    ${SUB_MAKE} ${JFLAG} buildkernel \
757	    TARGET=${TARGET} \
758	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
759	    ${MAKE_PARAMS_${TARGET_ARCH_${kernel}}} \
760	    KERNCONF=${kernel} \
761	    > _.${TARGET}.${kernel} 2>&1 || \
762	    (echo "${TARGET} ${kernel} kernel failed," \
763	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
764	@echo ">> ${TARGET}.${TARGET_ARCH_${kernel}} ${kernel} kernel completed on `LC_ALL=C date`"
765.endfor
766.for target_arch in ${TARGET_ARCHES_${TARGET}}
767universe_kernconfs: universe_kernconfs_${target_arch} .PHONY
768universe_kernconfs_${target_arch}:
769.endfor
770.endif	# make(universe_kernels)
771universe: universe_epilogue
772universe_epilogue: .PHONY
773	@echo "--------------------------------------------------------------"
774	@echo ">>> make universe completed on `LC_ALL=C date`"
775	@echo "                      (started ${STARTTIME})"
776	@echo "--------------------------------------------------------------"
777.if defined(DOING_TINDERBOX)
778	@if [ -e ${FAILFILE} ] ; then \
779		echo "Tinderbox failed:" ;\
780		cat ${FAILFILE} ;\
781		exit 1 ;\
782	fi
783.endif
784.endif
785
786.if defined(.PARSEDIR)
787# This makefile does not run in meta mode
788.MAKE.MODE= normal
789# Normally the things we run from here don't either.
790# Using -DWITH_META_MODE
791# we can buildworld with meta files created which are useful
792# for debugging, but without any of the rest of a meta mode build.
793MK_DIRDEPS_BUILD= no
794MK_STAGING= no
795# tell meta.autodep.mk to not even think about updating anything.
796UPDATE_DEPENDFILE= NO
797.if !make(showconfig)
798.export MK_DIRDEPS_BUILD MK_STAGING UPDATE_DEPENDFILE
799.endif
800
801.if make(universe)
802# we do not want a failure of one branch abort all.
803MAKE_JOB_ERROR_TOKEN= no
804.export MAKE_JOB_ERROR_TOKEN
805.endif
806.endif # bmake
807
808.endif				# DIRDEPS_BUILD
809