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