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