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