xref: /freebsd/Makefile (revision 4d63aec3c3805e2b8d91d2622752c525be755c17)
152bff0d7SRui Paulo#
252bff0d7SRui Paulo#
352bff0d7SRui Paulo# The common user-driven targets are (for a complete list, see build(7)):
452bff0d7SRui Paulo#
552bff0d7SRui Paulo# universe            - *Really* build *everything* (buildworld and
652bff0d7SRui Paulo#                       all kernels on all architectures).  Define
70ea45b9cSKyle Evans#                       MAKE_JUST_KERNELS or WITHOUT_WORLDS to only build kernels,
852bff0d7SRui Paulo#                       MAKE_JUST_WORLDS or WITHOUT_KERNELS to only build userland.
952bff0d7SRui Paulo# tinderbox           - Same as universe, but presents a list of failed build
1052bff0d7SRui Paulo#                       targets and exits with an error if there were any.
1152bff0d7SRui Paulo# worlds	      - Same as universe, except just makes the worlds.
1252bff0d7SRui Paulo# kernels	      - Same as universe, except just makes the kernels.
1352bff0d7SRui Paulo# buildworld          - Rebuild *everything*, including glue to help do
1452bff0d7SRui Paulo#                       upgrades.
1552bff0d7SRui Paulo# installworld        - Install everything built by "buildworld".
1652bff0d7SRui Paulo# world               - buildworld + installworld, no kernel.
1752bff0d7SRui Paulo# buildkernel         - Rebuild the kernel and the kernel-modules.
1852bff0d7SRui Paulo# installkernel       - Install the kernel and the kernel-modules.
1952bff0d7SRui Paulo# installkernel.debug
2052bff0d7SRui Paulo# reinstallkernel     - Reinstall the kernel and the kernel-modules.
2152bff0d7SRui Paulo# reinstallkernel.debug
2252bff0d7SRui Paulo# kernel              - buildkernel + installkernel.
2352bff0d7SRui Paulo# kernel-toolchain    - Builds the subset of world necessary to build a kernel
2452bff0d7SRui Paulo# kernel-toolchains   - Build kernel-toolchain for all universe targets.
2552bff0d7SRui Paulo# doxygen             - Build API documentation of the kernel, needs doxygen.
2652bff0d7SRui Paulo# checkworld          - Run test suite on installed world.
2752bff0d7SRui Paulo# check-old           - List obsolete directories/files/libraries.
2852bff0d7SRui Paulo# check-old-dirs      - List obsolete directories.
2952bff0d7SRui Paulo# check-old-files     - List obsolete files.
3052bff0d7SRui Paulo# check-old-libs      - List obsolete libraries.
3152bff0d7SRui Paulo# delete-old          - Delete obsolete directories/files.
3252bff0d7SRui Paulo# delete-old-dirs     - Delete obsolete directories.
3352bff0d7SRui Paulo# delete-old-files    - Delete obsolete files.
3452bff0d7SRui Paulo# delete-old-libs     - Delete obsolete libraries.
3552bff0d7SRui Paulo# list-old-dirs       - Raw list of possibly obsolete directories.
3652bff0d7SRui Paulo# list-old-files      - Raw list of possibly obsolete files.
3752bff0d7SRui Paulo# list-old-libs       - Raw list of possibly obsolete libraries.
3852bff0d7SRui Paulo# targets             - Print a list of supported TARGET/TARGET_ARCH pairs
3971944acbSWarner Losh#                       for world and kernel targets.
4052bff0d7SRui Paulo# toolchains          - Build a toolchain for all world and kernel targets.
4152bff0d7SRui Paulo# makeman             - Regenerate src.conf(5)
4252bff0d7SRui Paulo# sysent              - (Re)build syscall entries from syscalls.master.
4352bff0d7SRui Paulo# xdev                - xdev-build + xdev-install for the architecture
4452bff0d7SRui Paulo#                       specified with TARGET and TARGET_ARCH.
4552bff0d7SRui Paulo# xdev-build          - Build cross-development tools.
4652bff0d7SRui Paulo# xdev-install        - Install cross-development tools.
4752bff0d7SRui Paulo# xdev-links          - Create traditional links in /usr/bin for cc, etc
480ea45b9cSKyle Evans# native-xtools       - Create host binaries that produce target objects
49*4d63aec3SWarner Losh#                       for use in qemu user-mode jails.  TARGET and
5052bff0d7SRui Paulo#                       TARGET_ARCH should be defined.
5152bff0d7SRui Paulo# native-xtools-install
5252bff0d7SRui Paulo#                     - Install the files to the given DESTDIR/NXTP where
5352bff0d7SRui Paulo#                       NXTP defaults to /nxb-bin.
540ea45b9cSKyle Evans#
550ea45b9cSKyle Evans# This makefile is simple by design. The FreeBSD make automatically reads
5652bff0d7SRui Paulo# the /usr/share/mk/sys.mk unless the -m argument is specified on the
5752bff0d7SRui Paulo# command line. By keeping this makefile simple, it doesn't matter too
5852bff0d7SRui Paulo# much how different the installed mk files are from those in the source
5952bff0d7SRui Paulo# tree. This makefile executes a child make process, forcing it to use
6052bff0d7SRui Paulo# the mk files from the source tree which are supposed to DTRT.
6152bff0d7SRui Paulo#
6252bff0d7SRui Paulo# Most of the user-driven targets (as listed above) are implemented in
6352bff0d7SRui Paulo# Makefile.inc1.  The exceptions are universe, tinderbox and targets.
6452bff0d7SRui Paulo#
6552bff0d7SRui Paulo# If you want to build your system from source, be sure that /usr/obj has
6652bff0d7SRui Paulo# at least 6 GB of disk space available.  A complete 'universe' build of
6752bff0d7SRui Paulo# r340283 (2018-11) required 167 GB of space.  ZFS lz4 compression
6852bff0d7SRui Paulo# achieved a 2.18x ratio, reducing actual space to 81 GB.
6952bff0d7SRui Paulo#
7052bff0d7SRui Paulo# For individuals wanting to build from the sources currently on their
7152bff0d7SRui Paulo# system, the simple instructions are:
7252bff0d7SRui Paulo#
730ea45b9cSKyle Evans# 1.  `cd /usr/src'  (or to the directory containing your source tree).
7452bff0d7SRui Paulo# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
7552bff0d7SRui Paulo# 3.  `make world'
760ea45b9cSKyle Evans#
7752bff0d7SRui Paulo# For individuals wanting to upgrade their sources (even if only a
7852bff0d7SRui Paulo# delta of a few days):
7952bff0d7SRui Paulo#
8052bff0d7SRui Paulo#  1.  `cd /usr/src'       (or to the directory containing your source tree).
8152bff0d7SRui Paulo#  2.  `make buildworld'
8252bff0d7SRui Paulo#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
8352bff0d7SRui Paulo#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
8452bff0d7SRui Paulo#       [steps 3. & 4. can be combined by using the "kernel" target]
8552bff0d7SRui Paulo#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
8652bff0d7SRui Paulo#  6.  `etcupdate -p'
8752bff0d7SRui Paulo#  7.  `make installworld'
8852bff0d7SRui Paulo#  8.  `etcupdate -B'
8952bff0d7SRui Paulo#  9.  `make delete-old'
9052bff0d7SRui Paulo# 10.  `reboot'
9152bff0d7SRui Paulo# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
9252bff0d7SRui Paulo#
9352bff0d7SRui Paulo# For individuals wanting to build from source with GCC from ports, first
9452bff0d7SRui Paulo# install the appropriate GCC cross toolchain package:
9552bff0d7SRui Paulo#   `pkg install ${TARGET_ARCH}-gccN`
960ea45b9cSKyle Evans#
9752bff0d7SRui Paulo# Once you have installed the necessary cross toolchain, simply pass
9852bff0d7SRui Paulo# CROSS_TOOLCHAIN=${TARGET_ARCH}-gccN while building with the above steps,
9952bff0d7SRui Paulo# e.g., `make buildworld CROSS_TOOLCHAIN=amd64-gcc13`.
10052bff0d7SRui Paulo#
10152bff0d7SRui Paulo# The ${TARGET_ARCH}-gccN packages are provided as flavors of the
10252bff0d7SRui Paulo# devel/freebsd-gccN ports.
1030ea45b9cSKyle Evans#
1040ea45b9cSKyle Evans# See src/UPDATING `COMMON ITEMS' for more complete information.
10552bff0d7SRui Paulo#
10652bff0d7SRui Paulo# If TARGET=machine (e.g. powerpc64, arm64, ...) is specified you can
107# cross build world for other machine types using the buildworld target,
108# and once the world is built you can cross build a kernel using the
109# buildkernel target.
110#
111# Define the user-driven targets. These are listed here in alphabetical
112# order, but that's not important.
113#
114# Targets that begin with underscore are internal targets intended for
115# developer convenience only.  They are intentionally not documented and
116# completely subject to change without notice.
117#
118# For more information, see the build(7) manual page.
119#
120
121# Include jobs.mk early if we need it.
122# It will turn:
123# 	make buildworld-jobs
124# into
125# 	make -j${JOB_MAX} buildworld > ../buildworld.log 2>&1
126#
127.if make(*-jobs)
128.include <jobs.mk>
129.endif
130
131.if defined(UNIVERSE_TARGET) || defined(MAKE_JUST_WORLDS) || defined(WITHOUT_KERNELS)
132__DO_KERNELS=no
133.endif
134.if defined(MAKE_JUST_KERNELS) || defined(WITHOUT_WORLDS)
135__DO_WORLDS=no
136.endif
137__DO_WORLDS?=yes
138__DO_KERNELS?=yes
139
140# This is included so CC is set to ccache for -V, and COMPILER_TYPE/VERSION can
141# be cached for sub-makes. The need for CC is done with new make later in the
142# build, and caching COMPILER_TYPE/VERSION is only an optimization. Also
143# sinclude it to be friendlier to foreign OS hosted builds.
144.sinclude <bsd.compiler.mk>
145
146# Note: we use this awkward construct to be compatible with FreeBSD's
147# old make used in 10.0 and 9.2 and earlier.
148.if defined(MK_DIRDEPS_BUILD) && ${MK_DIRDEPS_BUILD} == "yes" && \
149    !make(showconfig) && !make(print-dir)
150# targets/Makefile plays the role of top-level
151.include "targets/Makefile"
152.else
153
154.include "${.CURDIR}/share/mk/bsd.compat.pre.mk"
155
156TGTS=	all all-man buildenv buildenvvars buildetc buildkernel buildworld \
157	check check-old check-old-dirs check-old-files check-old-libs \
158	checkdpadd checkworld clean cleandepend cleandir cleankernel \
159	cleanworld cleanuniverse \
160	delete-old delete-old-dirs delete-old-files delete-old-libs \
161	depend distribute distributekernel distributekernel.debug \
162	distributeworld distrib-dirs distribution doxygen \
163	everything hier hierarchy install installcheck installetc installkernel \
164	installkernel.debug packagekernel packageworld \
165	reinstallkernel reinstallkernel.debug \
166	installworld kernel-toolchain libraries maninstall \
167	list-old-dirs list-old-files list-old-libs \
168	obj objlink showconfig tags toolchain \
169	makeman sysent \
170	_cleanworldtmp _worldtmp _legacy _bootstrap-tools _cleanobj _obj \
171	_build-tools _build-metadata _cross-tools _includes _libraries \
172	builddtb xdev xdev-build xdev-install \
173	xdev-links native-xtools native-xtools-install stageworld stagekernel \
174	stage-packages stage-packages-kernel stage-packages-world stage-packages-source \
175	create-packages-world create-packages-kernel \
176	create-packages-kernel-repo create-packages-world-repo \
177	create-packages-source create-packages \
178	update-packages packages installconfig real-packages real-update-packages \
179	sign-packages package-pkg print-dir test-system-compiler test-system-linker \
180	test-includes
181
182.for libcompat in ${_ALL_libcompats}
183TGTS+=	build${libcompat} distribute${libcompat} install${libcompat}
184.endfor
185
186# These targets require a TARGET and TARGET_ARCH be defined.
187XTGTS=	native-xtools native-xtools-install xdev xdev-build xdev-install \
188	xdev-links
189
190# XXX: r156740: This can't work since bsd.subdir.mk is not included ever.
191# It will only work for SUBDIR_TARGETS in make.conf.
192TGTS+=	${SUBDIR_TARGETS}
193
194BITGTS=	files includes
195BITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
196TGTS+=	${BITGTS}
197
198# Only some targets are allowed to use meta mode.  Others get it
199# disabled.  In some cases, such as 'install', meta mode can be dangerous
200# as a cookie may be used to prevent redundant installations (such as
201# for WORLDTMP staging).  For DESTDIR=/ we always want to install though.
202# For other cases, such as delete-old-libs, meta mode may break
203# the interactive tty prompt.  The safest route is to just whitelist
204# the ones that benefit from it.
205META_TGT_WHITELIST+= \
206	_* buildfiles buildincludes buildkernel \
207	buildworld everything kernel-toolchain kernel-toolchains kernel \
208	kernels libraries native-xtools showconfig test-includes \
209	test-system-compiler test-system-linker tinderbox toolchain \
210	toolchains universe universe-toolchain world worlds xdev xdev-build
211
212.for libcompat in ${_ALL_libcompats}
213META_TGT_WHITELIST+=	build${libcompat}
214.endfor
215
216.ORDER: buildworld installworld
217.ORDER: buildworld distrib-dirs
218.ORDER: buildworld distribution
219.ORDER: buildworld distribute
220.ORDER: buildworld distributeworld
221.ORDER: buildworld buildkernel
222.ORDER: 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.ORDER: kernel-toolchain buildkernel
236
237# Only sanitize PATH on FreeBSD.
238# PATH may include tools that are required to cross-build
239# on non-FreeBSD systems.
240.if ${.MAKE.OS} == "FreeBSD"
241PATH=	/sbin:/bin:/usr/sbin:/usr/bin
242.endif
243MAKEOBJDIRPREFIX?=	/usr/obj
244_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH:Q} ${MAKE} MK_AUTO_OBJ=no \
245    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
246    SRCCONF=${SRCCONF} SRC_ENV_CONF= \
247    -f /dev/null -V MAKEOBJDIRPREFIX dummy
248.if !empty(_MAKEOBJDIRPREFIX) || !empty(.MAKEOVERRIDES:MMAKEOBJDIRPREFIX)
249.error MAKEOBJDIRPREFIX can only be set in environment or src-env.conf(5),\
250    not as a global (in make.conf(5) or src.conf(5)) or command-line variable.
251.endif
252
253# We often need to use the tree's version of make to build it.
254.if !empty(.MAKE.MODE:Mmeta)
255# 20160604 - support missing-meta,missing-filemon and performance improvements
256WANT_MAKE_VERSION= 20160604
257.else
258# 20160220 - support .dinclude for FAST_DEPEND.
259WANT_MAKE_VERSION= 20160220
260.endif
261.if defined(MYMAKE)
262.error MYMAKE cannot be overridden, use as command name instead
263.endif
264MYMAKE=		${OBJROOT}make.${MACHINE}/bmake
265.if defined(ALWAYS_BOOTSTRAP_MAKE) || \
266    (defined(WANT_MAKE_VERSION) && ${MAKE_VERSION} < ${WANT_MAKE_VERSION})
267NEED_MAKE_UPGRADE= t
268.endif
269.if defined(NEED_MAKE_UPGRADE)
270. if exists(${MYMAKE})
271SUB_MAKE:= ${MYMAKE} -m ${.CURDIR}/share/mk
272. else
273# It may not exist yet but we may cause it to.
274SUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \
275	-m ${.CURDIR}/share/mk
276. endif
277.else
278SUB_MAKE= ${MAKE} -m ${.CURDIR}/share/mk
279.endif
280
281_MAKE=	PATH=${PATH:Q} MAKE_CMD="${MAKE}" ${SUB_MAKE} -f Makefile.inc1 \
282	TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH} ${_MAKEARGS}
283
284.if defined(MK_META_MODE) && ${MK_META_MODE} == "yes"
285# Only allow meta mode for the whitelisted targets.  See META_TGT_WHITELIST
286# above.  If overridden as a make argument then don't bother trying to
287# disable it.
288.if empty(.MAKEOVERRIDES:MMK_META_MODE)
289.for _tgt in ${META_TGT_WHITELIST}
290.if make(${_tgt})
291_CAN_USE_META_MODE?= yes
292.endif
293.endfor
294.if !defined(_CAN_USE_META_MODE)
295_MAKE+=	MK_META_MODE=no
296MK_META_MODE= no
297.unexport META_MODE
298.endif	# !defined(_CAN_USE_META_MODE)
299.endif	# empty(.MAKEOVERRIDES:MMK_META_MODE)
300
301.if ${MK_META_MODE} == "yes"
302.if !exists(/dev/filemon) && !defined(NO_FILEMON) && !make(showconfig)
303# Require filemon be loaded to provide a working incremental build
304.error ${.newline}ERROR: The filemon module (/dev/filemon) is not loaded. \
305    ${.newline}ERROR: WITH_META_MODE is enabled but requires filemon for an incremental build. \
306    ${.newline}ERROR: 'kldload filemon' or pass -DNO_FILEMON to suppress this error.
307.endif	# !exists(/dev/filemon) && !defined(NO_FILEMON)
308.endif	# ${MK_META_MODE} == yes
309.endif	# defined(MK_META_MODE) && ${MK_META_MODE} == yes
310
311# Guess target architecture from target type, and vice versa, based on
312# historic FreeBSD practice of tending to have TARGET == TARGET_ARCH
313# expanding to TARGET == TARGET_CPUARCH in recent times, with known
314# exceptions.
315.if !defined(TARGET_ARCH) && defined(TARGET)
316# T->TA mapping is usually TARGET with arm64 the odd man out
317_TARGET_ARCH=	${TARGET:S/arm64/aarch64/:S/riscv/riscv64/:S/arm/armv7/}
318.elif !defined(TARGET) && defined(TARGET_ARCH) && \
319    ${TARGET_ARCH} != ${MACHINE_ARCH}
320# TA->T mapping is accidentally CPUARCH with aarch64 the odd man out
321_TARGET=	${TARGET_ARCH:${__TO_CPUARCH}:C/aarch64/arm64/}
322.endif
323.if defined(TARGET) && !defined(_TARGET)
324_TARGET=${TARGET}
325.endif
326.if defined(TARGET_ARCH) && !defined(_TARGET_ARCH)
327_TARGET_ARCH=${TARGET_ARCH}
328.endif
329# for historical compatibility for xdev targets
330.if defined(XDEV)
331_TARGET=	${XDEV}
332.endif
333.if defined(XDEV_ARCH)
334_TARGET_ARCH=	${XDEV_ARCH}
335.endif
336# Some targets require a set TARGET/TARGET_ARCH, check before the default
337# MACHINE and after the compatibility handling.
338.if !defined(_TARGET) || !defined(_TARGET_ARCH)
339${XTGTS}: _assert_target
340.endif
341# Otherwise, default to current machine type and architecture.
342_TARGET?=	${MACHINE}
343_TARGET_ARCH?=	${MACHINE_ARCH}
344
345.if make(native-xtools*)
346NXB_TARGET:=		${_TARGET}
347NXB_TARGET_ARCH:=	${_TARGET_ARCH}
348_TARGET=		${MACHINE}
349_TARGET_ARCH=		${MACHINE_ARCH}
350_MAKE+=			NXB_TARGET=${NXB_TARGET} \
351			NXB_TARGET_ARCH=${NXB_TARGET_ARCH}
352.endif
353
354.if make(print-dir)
355.SILENT:
356.endif
357
358_assert_target: .PHONY .MAKE
359.for _tgt in ${XTGTS}
360.if make(${_tgt})
361	@echo "*** Error: Both TARGET and TARGET_ARCH must be defined for \"${_tgt}\" target"
362	@false
363.endif
364.endfor
365
366#
367# Make sure we have an up-to-date make(1). Only world, buildworld and
368# kernel-toolchain should do this as those are the initial targets used
369# for upgrades. The user can define ALWAYS_CHECK_MAKE to have this check
370# performed for all targets.
371#
372.if defined(ALWAYS_CHECK_MAKE)
373${TGTS}: upgrade_checks
374.else
375buildworld: upgrade_checks
376kernel-toolchain: 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} bmake)
466.elif exists(${MYMAKE:H})
467	@echo "Removing stale bmake(1)"
468	rm -r ${MYMAKE:H}
469.endif
470
471#
472# Upgrade make(1) to the current version using the installed
473# headers, libraries and tools.  Also, allow the location of
474# the system bsdmake-like utility to be overridden.
475#
476MMAKEENV=	\
477		DESTDIR= \
478		INSTALL="sh ${.CURDIR}/tools/install.sh"
479MMAKE=		${MMAKEENV} ${MAKE} \
480		OBJTOP=${MYMAKE:H}/obj \
481		OBJROOT='$${OBJTOP}/' \
482		MAKEOBJDIRPREFIX= \
483		MK_MAN=no -DNO_SHARED \
484		-DNO_CPU_CFLAGS MK_WERROR=no \
485		-DNO_SUBDIR \
486		DESTDIR= PROGNAME=${MYMAKE:T}
487
488bmake: .PHONY
489	@echo
490	@echo "--------------------------------------------------------------"
491	@echo ">>> Building an up-to-date ${.TARGET}(1)"
492	@echo "--------------------------------------------------------------"
493	${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \
494		${MMAKE} obj; \
495		${MMAKE} depend; \
496		${MMAKE} all; \
497		${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR=
498
499regress: .PHONY
500	@echo "'make regress' has been renamed 'make check'" | /usr/bin/fmt
501	@false
502
503tinderbox toolchains kernel-toolchains kernels worlds: upgrade_checks
504
505tinderbox: .PHONY
506	@cd ${.CURDIR}; ${SUB_MAKE} DOING_TINDERBOX=YES universe
507
508toolchains: .PHONY
509	@cd ${.CURDIR}; ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe
510
511kernel-toolchains: .PHONY
512	@cd ${.CURDIR}; ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe
513
514kernels: .PHONY
515	@cd ${.CURDIR}; ${SUB_MAKE} universe -DWITHOUT_WORLDS
516
517worlds: .PHONY
518	@cd ${.CURDIR}; ${SUB_MAKE} UNIVERSE_TARGET=buildworld universe
519
520#
521# universe
522#
523# Attempt to rebuild *everything* for all supported architectures,
524# with a reasonable chance of success, regardless of how old your
525# existing system is.
526#
527.if make(universe) || make(universe_kernels) || make(tinderbox) || \
528    make(targets) || make(universe-toolchain)
529#
530# Don't build rarely used, semi-supported architectures unless requested.
531#
532.if defined(EXTRA_TARGETS)
533EXTRA_ARCHES_powerpc=	powerpc powerpcspe
534.endif
535TARGETS?= ${TARGET_MACHINE_LIST}
536_UNIVERSE_TARGETS=	${TARGETS}
537.for target in ${TARGETS}
538TARGET_ARCHES_${target}= ${MACHINE_ARCH_LIST_${target}}
539.endfor
540
541.if defined(USE_GCC_TOOLCHAINS)
542_DEFAULT_GCC_VERSION=	gcc14
543_GCC_VERSION=		${"${USE_GCC_TOOLCHAINS:Mgcc*}" != "":?${USE_GCC_TOOLCHAINS}:${_DEFAULT_GCC_VERSION}}
544TOOLCHAINS_amd64=	amd64-${_GCC_VERSION}
545TOOLCHAINS_arm=		armv7-${_GCC_VERSION}
546TOOLCHAINS_arm64=	aarch64-${_GCC_VERSION}
547TOOLCHAINS_i386=	i386-${_GCC_VERSION}
548TOOLCHAINS_powerpc=	powerpc64-${_GCC_VERSION}
549TOOLCHAINS_riscv=	riscv64-${_GCC_VERSION}
550.endif
551
552# If a target is using an external toolchain, set MAKE_PARAMS to enable use
553# of the toolchain.  If the external toolchain is missing, exclude the target
554# from universe.
555.for target in ${_UNIVERSE_TARGETS}
556.if !empty(TOOLCHAINS_${target})
557.for toolchain in ${TOOLCHAINS_${target}}
558.if !exists(/usr/local/share/toolchains/${toolchain}.mk)
559_UNIVERSE_TARGETS:= ${_UNIVERSE_TARGETS:N${target}}
560universe: universe_${toolchain}_skip .PHONY
561universe_epilogue: universe_${toolchain}_skip .PHONY
562universe_${toolchain}_skip: universe_prologue .PHONY
563	@echo ">> ${target} skipped - install ${toolchain} port or package to build"
564.endif
565.endfor
566.for arch in ${TARGET_ARCHES_${target}}
567TOOLCHAIN_${arch}?=	${TOOLCHAINS_${target}:[1]}
568MAKE_PARAMS_${arch}?=	CROSS_TOOLCHAIN=${TOOLCHAIN_${arch}}
569.endfor
570.endif
571.endfor
572
573UNIVERSE_TARGET?=	buildworld
574KERNSRCDIR?=		${.CURDIR}/sys
575
576.if ${.MAKE.OS} == "FreeBSD"
577UNIVERSE_TOOLCHAIN_TARGET?=		${MACHINE}
578UNIVERSE_TOOLCHAIN_TARGET_ARCH?=	${MACHINE_ARCH}
579.else
580# MACHINE/MACHINE_ARCH may not follow the same naming as us (e.g. x86_64 vs
581# amd64) on non-FreeBSD. Rather than attempt to sanitise it, arbitrarily use
582# amd64 as the default universe toolchain target.
583UNIVERSE_TOOLCHAIN_TARGET?=		amd64
584UNIVERSE_TOOLCHAIN_TARGET_ARCH?=	amd64
585.endif
586
587targets:	.PHONY
588	@echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
589.for target in ${TARGETS}
590.for target_arch in ${TARGET_ARCHES_${target}}
591	@echo "    ${target}/${target_arch}"
592.endfor
593.endfor
594
595.if defined(DOING_TINDERBOX)
596FAILFILE=${.CURDIR}/_.tinderbox.failed
597MAKEFAIL=tee -a ${FAILFILE}
598.else
599MAKEFAIL=cat
600.endif
601
602universe_prologue:  upgrade_checks
603universe: universe_prologue
604universe_prologue: .PHONY
605	@echo "--------------------------------------------------------------"
606	@echo ">>> make universe started on ${STARTTIME}"
607	@echo "--------------------------------------------------------------"
608.if defined(DOING_TINDERBOX)
609	@rm -f ${FAILFILE}
610.endif
611
612universe-toolchain: .PHONY universe_prologue
613	@echo "--------------------------------------------------------------"
614	@echo "> Toolchain bootstrap started on `LC_ALL=C date`"
615	@echo "--------------------------------------------------------------"
616	${_+_}@cd ${.CURDIR}; \
617	    env PATH=${PATH:Q} ${SUB_MAKE} ${JFLAG} kernel-toolchain \
618	    TARGET=${UNIVERSE_TOOLCHAIN_TARGET} \
619	    TARGET_ARCH=${UNIVERSE_TOOLCHAIN_TARGET_ARCH} \
620	    OBJTOP="${HOST_OBJTOP}" \
621	    WITHOUT_SYSTEM_COMPILER=yes \
622	    WITHOUT_SYSTEM_LINKER=yes \
623	    TOOLS_PREFIX_UNDEF= \
624	    kernel-toolchain \
625	    MK_LLVM_TARGET_ALL=yes \
626	    > _.${.TARGET} 2>&1 || \
627	    (echo "${.TARGET} failed," \
628	    "check _.${.TARGET} for details" | \
629	    ${MAKEFAIL}; false)
630	@if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/cc" ]; then \
631	    echo "Missing host compiler at ${HOST_OBJTOP}/tmp/usr/bin/cc?" >&2; \
632	    false; \
633	fi
634	@if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/ld" ]; then \
635	    echo "Missing host linker at ${HOST_OBJTOP}/tmp/usr/bin/ld?" >&2; \
636	    false; \
637	fi
638	@echo "--------------------------------------------------------------"
639	@echo "> Toolchain bootstrap completed on `LC_ALL=C date`"
640	@echo "--------------------------------------------------------------"
641
642.for target in ${_UNIVERSE_TARGETS}
643universe: universe_${target}
644universe_epilogue: universe_${target}
645universe_${target}: universe_${target}_prologue .PHONY
646universe_${target}_prologue: universe_prologue .PHONY
647	@echo ">> ${target} started on `LC_ALL=C date`"
648universe_${target}_worlds: .PHONY
649
650.if !make(targets) && !make(universe-toolchain)
651.for target_arch in ${TARGET_ARCHES_${target}}
652.if !defined(_need_clang_${target}_${target_arch})
653_need_clang_${target}_${target_arch} != \
654	env TARGET=${target} TARGET_ARCH=${target_arch} \
655	${SUB_MAKE} -C ${.CURDIR} -f Makefile.inc1 test-system-compiler \
656	    ${MAKE_PARAMS_${target_arch}} -V MK_CLANG_BOOTSTRAP 2>/dev/null || \
657	    echo unknown
658.export _need_clang_${target}_${target_arch}
659.endif
660.if !defined(_need_lld_${target}_${target_arch})
661_need_lld_${target}_${target_arch} != \
662	env TARGET=${target} TARGET_ARCH=${target_arch} \
663	${SUB_MAKE} -C ${.CURDIR} -f Makefile.inc1 test-system-linker \
664	    ${MAKE_PARAMS_${target_arch}} -V MK_LLD_BOOTSTRAP 2>/dev/null || \
665	    echo unknown
666.export _need_lld_${target}_${target_arch}
667.endif
668# Setup env for each arch to use the one clang.
669.if defined(_need_clang_${target}_${target_arch}) && \
670    ${_need_clang_${target}_${target_arch}} == "yes"
671# No check on existing XCC or CROSS_BINUTILS_PREFIX, etc, is needed since
672# we use the test-system-compiler logic to determine if clang needs to be
673# built.  It will be no from that logic if already using an external
674# toolchain or /usr/bin/cc.
675# XXX: Passing HOST_OBJTOP into the PATH would allow skipping legacy,
676#      bootstrap-tools, and cross-tools.  Need to ensure each tool actually
677#      supports all TARGETS though.
678# For now we only pass UNIVERSE_TOOLCHAIN_PATH which will be added at the end
679# of STRICTTMPPATH to ensure that the target-specific binaries come first.
680MAKE_PARAMS_${target_arch}+= \
681	XCC="${HOST_OBJTOP}/tmp/usr/bin/cc" \
682	XCXX="${HOST_OBJTOP}/tmp/usr/bin/c++" \
683	XCPP="${HOST_OBJTOP}/tmp/usr/bin/cpp" \
684	UNIVERSE_TOOLCHAIN_PATH=${HOST_OBJTOP}/tmp/usr/bin
685.endif
686.if defined(_need_lld_${target}_${target_arch}) && \
687    ${_need_lld_${target}_${target_arch}} == "yes"
688MAKE_PARAMS_${target_arch}+= \
689	XLD="${HOST_OBJTOP}/tmp/usr/bin/ld"
690.endif
691.endfor
692.endif	# !make(targets)
693
694.if ${__DO_WORLDS} == "yes"
695universe_${target}_done: universe_${target}_worlds .PHONY
696.for target_arch in ${TARGET_ARCHES_${target}}
697universe_${target}_worlds: universe_${target}_${target_arch} .PHONY
698.if (defined(_need_clang_${target}_${target_arch}) && \
699    ${_need_clang_${target}_${target_arch}} == "yes") || \
700    (defined(_need_lld_${target}_${target_arch}) && \
701    ${_need_lld_${target}_${target_arch}} == "yes")
702universe_${target}_${target_arch}: universe-toolchain
703universe_${target}_prologue: universe-toolchain
704.endif
705universe_${target}_${target_arch}: universe_${target}_prologue .MAKE .PHONY
706	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
707	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
708	    ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
709	    TARGET=${target} \
710	    TARGET_ARCH=${target_arch} \
711	    ${MAKE_PARAMS_${target_arch}} \
712	    > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
713	    (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
714	    "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
715	    ${MAKEFAIL}))
716	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
717.endfor
718.endif # ${__DO_WORLDS} == "yes"
719
720.if ${__DO_KERNELS} == "yes"
721universe_${target}_done: universe_${target}_kernels .PHONY
722universe_${target}_kernels: universe_${target}_worlds .PHONY
723universe_${target}_kernels: universe_${target}_prologue .MAKE .PHONY
724	@cd ${.CURDIR}; ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
725	    universe_kernels
726.endif # ${__DO_KERNELS} == "yes"
727
728# Tell the user the worlds and kernels have completed
729universe_${target}: universe_${target}_done
730universe_${target}_done:
731	@echo ">> ${target} completed on `LC_ALL=C date`"
732.endfor
733.if make(universe_kernconfs) || make(universe_kernels)
734.if !defined(TARGET)
735TARGET!=	uname -m
736.endif
737universe_kernels_prologue: .PHONY
738	@echo ">> ${TARGET} kernels started on `LC_ALL=C date`"
739universe_kernels: universe_kernconfs .PHONY
740	@echo ">> ${TARGET} kernels completed on `LC_ALL=C date`"
741.if defined(MAKE_ALL_KERNELS)
742_THINNER=cat
743.elif defined(MAKE_LINT_KERNELS)
744_THINNER=grep 'LINT' || true
745.else
746_THINNER=xargs grep -L "^.NO_UNIVERSE" || true
747.endif
748KERNCONFS!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
749		find [[:upper:][:digit:]]*[[:upper:][:digit:]] \
750		-type f -maxdepth 0 \
751		! -name DEFAULTS ! -name NOTES | \
752		${_THINNER}
753universe_kernconfs: universe_kernels_prologue .PHONY
754.for kernel in ${KERNCONFS}
755TARGET_ARCH_${kernel}!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
756	env PATH=${HOST_OBJTOP}/tmp/legacy/bin:${PATH:Q} \
757	config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
758	grep -v WARNING: | cut -f 2
759.if empty(TARGET_ARCH_${kernel})
760.error Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old.
761.endif
762universe_kernconfs_${TARGET_ARCH_${kernel}}: universe_kernconf_${TARGET}_${kernel}
763universe_kernconf_${TARGET}_${kernel}: .MAKE
764	@echo ">> ${TARGET}.${TARGET_ARCH_${kernel}} ${kernel} kernel started on `LC_ALL=C date`"
765	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
766	    ${SUB_MAKE} ${JFLAG} buildkernel \
767	    TARGET=${TARGET} \
768	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
769	    ${MAKE_PARAMS_${TARGET_ARCH_${kernel}}} \
770	    KERNCONF=${kernel} \
771	    > _.${TARGET}.${kernel} 2>&1 || \
772	    (echo "${TARGET} ${kernel} kernel failed," \
773	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
774	@echo ">> ${TARGET}.${TARGET_ARCH_${kernel}} ${kernel} kernel completed on `LC_ALL=C date`"
775.endfor
776.for target_arch in ${TARGET_ARCHES_${TARGET}}
777universe_kernconfs: universe_kernconfs_${target_arch} .PHONY
778universe_kernconfs_${target_arch}:
779.endfor
780.endif	# make(universe_kernels)
781universe: universe_epilogue
782universe_epilogue: .PHONY
783	@echo "--------------------------------------------------------------"
784	@echo ">>> make universe completed on `LC_ALL=C date`"
785	@echo "                      (started ${STARTTIME})"
786	@echo "--------------------------------------------------------------"
787.if defined(DOING_TINDERBOX)
788	@if [ -e ${FAILFILE} ] ; then \
789		echo "Tinderbox failed:" ;\
790		cat ${FAILFILE} ;\
791		exit 1 ;\
792	fi
793.endif
794.endif
795
796# This makefile does not run in meta mode
797.MAKE.MODE= normal
798# Normally the things we run from here don't either.
799# Using -DWITH_META_MODE
800# we can buildworld with meta files created which are useful
801# for debugging, but without any of the rest of a meta mode build.
802MK_DIRDEPS_BUILD= no
803MK_STAGING= no
804# tell meta.autodep.mk to not even think about updating anything.
805UPDATE_DEPENDFILE= NO
806.if !make(showconfig)
807.export MK_DIRDEPS_BUILD MK_STAGING UPDATE_DEPENDFILE
808.endif
809
810.if make(universe)
811# we do not want a failure of one branch abort all.
812MAKE_JOB_ERROR_TOKEN= no
813.export MAKE_JOB_ERROR_TOKEN
814.endif
815
816.endif				# DIRDEPS_BUILD
817