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