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