xref: /freebsd/Makefile (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
1#
2# $FreeBSD$
3#
4# The user-driven targets are:
5#
6# universe            - *Really* build *everything* (buildworld and
7#                       all kernels on all architectures).  Define
8#                       MAKE_JUST_KERNELS or WITHOUT_WORLDS to only build kernels,
9#                       MAKE_JUST_WORLDS or WITHOUT_KERNELS to only build userland.
10# tinderbox           - Same as universe, but presents a list of failed build
11#                       targets and exits with an error if there were any.
12# worlds	      - Same as universe, except just makes the worlds.
13# kernels	      - Same as universe, except just makes the kernels.
14# buildworld          - Rebuild *everything*, including glue to help do
15#                       upgrades.
16# installworld        - Install everything built by "buildworld".
17# world               - buildworld + installworld, no kernel.
18# buildkernel         - Rebuild the kernel and the kernel-modules.
19# installkernel       - Install the kernel and the kernel-modules.
20# installkernel.debug
21# reinstallkernel     - Reinstall the kernel and the kernel-modules.
22# reinstallkernel.debug
23# kernel              - buildkernel + installkernel.
24# kernel-toolchain    - Builds the subset of world necessary to build a kernel
25# kernel-toolchains   - Build kernel-toolchain for all universe targets.
26# doxygen             - Build API documentation of the kernel, needs doxygen.
27# update              - Convenient way to update your source tree(s).
28# checkworld          - Run test suite on installed world.
29# check-old           - List obsolete directories/files/libraries.
30# check-old-dirs      - List obsolete directories.
31# check-old-files     - List obsolete files.
32# check-old-libs      - List obsolete libraries.
33# delete-old          - Delete obsolete directories/files.
34# delete-old-dirs     - Delete obsolete directories.
35# delete-old-files    - Delete obsolete files.
36# delete-old-libs     - Delete obsolete libraries.
37# targets             - Print a list of supported TARGET/TARGET_ARCH pairs
38#                       for world and kernel targets.
39# toolchains          - Build a toolchain for all world and kernel targets.
40# makeman             - Regenerate src.conf(5)
41# sysent              - (Re)build syscall entries from syscalls.master.
42# xdev                - xdev-build + xdev-install for the architecture
43#                       specified with TARGET and TARGET_ARCH.
44# xdev-build          - Build cross-development tools.
45# xdev-install        - Install cross-development tools.
46# xdev-links          - Create traditional links in /usr/bin for cc, etc
47# native-xtools       - Create host binaries that produce target objects
48#                       for use in qemu user-mode jails.  TARGET and
49#                       TARGET_ARCH should be defined.
50# native-xtools-install
51#                     - Install the files to the given DESTDIR/NXTP where
52#                       NXTP defaults to /nxb-bin.
53#
54# This makefile is simple by design. The FreeBSD make automatically reads
55# the /usr/share/mk/sys.mk unless the -m argument is specified on the
56# command line. By keeping this makefile simple, it doesn't matter too
57# much how different the installed mk files are from those in the source
58# tree. This makefile executes a child make process, forcing it to use
59# the mk files from the source tree which are supposed to DTRT.
60#
61# Most of the user-driven targets (as listed above) are implemented in
62# Makefile.inc1.  The exceptions are universe, tinderbox and targets.
63#
64# If you want to build your system from source, be sure that /usr/obj has
65# at least 6 GB of disk space available.  A complete 'universe' build of
66# r340283 (2018-11) required 167 GB of space.  ZFS lz4 compression
67# achieved a 2.18x ratio, reducing actual space to 81 GB.
68#
69# For individuals wanting to build from the sources currently on their
70# system, the simple instructions are:
71#
72# 1.  `cd /usr/src'  (or to the directory containing your source tree).
73# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
74# 3.  `make world'
75#
76# For individuals wanting to upgrade their sources (even if only a
77# delta of a few days):
78#
79#  1.  `cd /usr/src'       (or to the directory containing your source tree).
80#  2.  `make buildworld'
81#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
82#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
83#       [steps 3. & 4. can be combined by using the "kernel" target]
84#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
85#  6.  `mergemaster -p'
86#  7.  `make installworld'
87#  8.  `mergemaster'            (you may wish to use -i, along with -U or -F).
88#  9.  `make delete-old'
89# 10.  `reboot'
90# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
91#
92# For individuals wanting to build from source with GCC from ports, first
93# install the appropriate GCC cross toolchain package:
94#   `pkg install ${TARGET_ARCH}-gccN`
95#
96# Once you have installed the necessary cross toolchain, simply pass
97# CROSS_TOOLCHAIN=${TARGET_ARCH}-gccN while building with the above steps,
98# e.g., `make buildworld CROSS_TOOLCHAIN=amd64-gcc6`.
99#
100# The ${TARGET_ARCH}-gccN packages are provided as flavors of the
101# devel/freebsd-gccN ports.
102#
103# See src/UPDATING `COMMON ITEMS' for more complete information.
104#
105# If TARGET=machine (e.g. powerpc, arm64, ...) is specified you can
106# cross build world for other machine types using the buildworld target,
107# and once the world is built you can cross build a kernel using the
108# buildkernel target.
109#
110# Define the user-driven targets. These are listed here in alphabetical
111# order, but that's not important.
112#
113# Targets that begin with underscore are internal targets intended for
114# developer convenience only.  They are intentionally not documented and
115# completely subject to change without notice.
116#
117# For more information, see the build(7) manual page.
118#
119
120.if defined(UNIVERSE_TARGET) || defined(MAKE_JUST_WORLDS) || defined(WITHOUT_KERNELS)
121__DO_KERNELS=no
122.endif
123.if defined(MAKE_JUST_KERNELS) || defined(WITHOUT_WORLDS)
124__DO_WORLDS=no
125.endif
126__DO_WORLDS?=yes
127__DO_KERNELS?=yes
128
129# This is included so CC is set to ccache for -V, and COMPILER_TYPE/VERSION
130# can be cached for sub-makes. We can't do this while still running on the
131# old fmake from FreeBSD 9.x or older, so avoid including it then to avoid
132# heartburn upgrading from older systems. The need for CC is done with new
133# make later in the build, and caching COMPILER_TYPE/VERSION is only an
134# optimization. Also sinclude it to be friendlier to foreign OS hosted builds.
135.if ${MAKE_VERSION} >= 20140620 && defined(.PARSEDIR)
136.sinclude <bsd.compiler.mk>
137.endif
138
139# Note: we use this awkward construct to be compatible with FreeBSD's
140# old make used in 10.0 and 9.2 and earlier.
141.if defined(MK_DIRDEPS_BUILD) && ${MK_DIRDEPS_BUILD} == "yes" && \
142    !make(showconfig) && !make(print-dir)
143# targets/Makefile plays the role of top-level
144.include "targets/Makefile"
145.else
146
147TGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
148	check check-old check-old-dirs check-old-files check-old-libs \
149	checkdpadd checkworld clean cleandepend cleandir cleanworld \
150	cleanuniverse \
151	delete-old delete-old-dirs delete-old-files delete-old-libs \
152	depend distribute distributekernel distributekernel.debug \
153	distributeworld distrib-dirs distribution doxygen \
154	everything hier hierarchy install installcheck installkernel \
155	installkernel.debug packagekernel packageworld \
156	reinstallkernel reinstallkernel.debug \
157	installworld kernel-toolchain libraries maninstall \
158	obj objlink showconfig tags toolchain update \
159	makeman sysent \
160	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
161	_build-tools _build-metadata _cross-tools _includes _libraries \
162	build32 distribute32 install32 buildsoft distributesoft installsoft \
163	builddtb xdev xdev-build xdev-install \
164	xdev-links native-xtools native-xtools-install stageworld stagekernel \
165	stage-packages stage-packages-kernel stage-packages-world \
166	create-packages-world create-packages-kernel create-packages \
167	update-packages packages installconfig real-packages real-update-packages \
168	sign-packages package-pkg print-dir test-system-compiler test-system-linker
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-system-compiler \
193	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)
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		MAN= -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)
511EXTRA_ARCHES_mips=	mipsel mipshf mipselhf mips64el mips64hf mips64elhf
512EXTRA_ARCHES_mips+=	mipsn32
513# powerpcspe excluded from main list until clang fixed
514EXTRA_ARCHES_powerpc=	powerpcspe powerpc64le
515.endif
516TARGETS?=amd64 arm arm64 i386 mips powerpc riscv
517_UNIVERSE_TARGETS=	${TARGETS}
518TARGET_ARCHES_arm?=	armv6 armv7
519TARGET_ARCHES_arm64?=	aarch64
520TARGET_ARCHES_mips?=	mips mips64 ${EXTRA_ARCHES_mips}
521TARGET_ARCHES_powerpc?=	powerpc powerpc64 ${EXTRA_ARCHES_powerpc}
522TARGET_ARCHES_riscv?=	riscv64 riscv64sf
523.for target in ${TARGETS}
524TARGET_ARCHES_${target}?= ${target}
525.endfor
526
527.if defined(USE_GCC_TOOLCHAINS)
528TOOLCHAINS_amd64=	amd64-gcc6
529TOOLCHAINS_arm64=	aarch64-gcc6
530TOOLCHAINS_i386=	i386-gcc6
531TOOLCHAINS_mips=	mips-gcc6
532TOOLCHAINS_powerpc=	powerpc-gcc6 powerpc64-gcc6
533TOOLCHAIN_powerpc64=	powerpc64-gcc6
534.endif
535
536# If a target is using an external toolchain, set MAKE_PARAMS to enable use
537# of the toolchain.  If the external toolchain is missing, exclude the target
538# from universe.
539.for target in ${_UNIVERSE_TARGETS}
540.if !empty(TOOLCHAINS_${target})
541.for toolchain in ${TOOLCHAINS_${target}}
542.if !exists(/usr/local/share/toolchains/${toolchain}.mk)
543_UNIVERSE_TARGETS:= ${_UNIVERSE_TARGETS:N${target}}
544universe: universe_${toolchain}_skip .PHONY
545universe_epilogue: universe_${toolchain}_skip .PHONY
546universe_${toolchain}_skip: universe_prologue .PHONY
547	@echo ">> ${target} skipped - install ${toolchain} port or package to build"
548.endif
549.endfor
550.for arch in ${TARGET_ARCHES_${target}}
551TOOLCHAIN_${arch}?=	${TOOLCHAINS_${target}:[1]}
552MAKE_PARAMS_${arch}?=	CROSS_TOOLCHAIN=${TOOLCHAIN_${arch}}
553.endfor
554.endif
555.endfor
556
557UNIVERSE_TARGET?=	buildworld
558KERNSRCDIR?=		${.CURDIR}/sys
559
560targets:	.PHONY
561	@echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
562.for target in ${TARGETS}
563.for target_arch in ${TARGET_ARCHES_${target}}
564	@echo "    ${target}/${target_arch}"
565.endfor
566.endfor
567
568.if defined(DOING_TINDERBOX)
569FAILFILE=${.CURDIR}/_.tinderbox.failed
570MAKEFAIL=tee -a ${FAILFILE}
571.else
572MAKEFAIL=cat
573.endif
574
575universe_prologue:  upgrade_checks
576universe: universe_prologue
577universe_prologue: .PHONY
578	@echo "--------------------------------------------------------------"
579	@echo ">>> make universe started on ${STARTTIME}"
580	@echo "--------------------------------------------------------------"
581.if defined(DOING_TINDERBOX)
582	@rm -f ${FAILFILE}
583.endif
584
585universe-toolchain: .PHONY universe_prologue
586	@echo "--------------------------------------------------------------"
587	@echo "> Toolchain bootstrap started on `LC_ALL=C date`"
588	@echo "--------------------------------------------------------------"
589	${_+_}@cd ${.CURDIR}; \
590	    env PATH=${PATH} ${SUB_MAKE} ${JFLAG} kernel-toolchain \
591	    TARGET=${MACHINE} TARGET_ARCH=${MACHINE_ARCH} \
592	    OBJTOP="${HOST_OBJTOP}" \
593	    WITHOUT_SYSTEM_COMPILER=yes \
594	    WITHOUT_SYSTEM_LINKER=yes \
595	    TOOLS_PREFIX_UNDEF= \
596	    kernel-toolchain \
597	    MK_LLVM_TARGET_ALL=yes \
598	    > _.${.TARGET} 2>&1 || \
599	    (echo "${.TARGET} failed," \
600	    "check _.${.TARGET} for details" | \
601	    ${MAKEFAIL}; false)
602	@if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/cc" ]; then \
603	    echo "Missing host compiler at ${HOST_OBJTOP}/tmp/usr/bin/cc?" >&2; \
604	    false; \
605	fi
606	@if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/ld" ]; then \
607	    echo "Missing host linker at ${HOST_OBJTOP}/tmp/usr/bin/ld?" >&2; \
608	    false; \
609	fi
610	@echo "--------------------------------------------------------------"
611	@echo "> Toolchain bootstrap completed on `LC_ALL=C date`"
612	@echo "--------------------------------------------------------------"
613
614.for target in ${_UNIVERSE_TARGETS}
615universe: universe_${target}
616universe_epilogue: universe_${target}
617universe_${target}: universe_${target}_prologue .PHONY
618universe_${target}_prologue: universe_prologue .PHONY
619	@echo ">> ${target} started on `LC_ALL=C date`"
620universe_${target}_worlds: .PHONY
621
622.if !make(targets) && !make(universe-toolchain)
623.for target_arch in ${TARGET_ARCHES_${target}}
624.if !defined(_need_clang_${target}_${target_arch})
625_need_clang_${target}_${target_arch} != \
626	env TARGET=${target} TARGET_ARCH=${target_arch} \
627	${SUB_MAKE} -C ${.CURDIR} -f Makefile.inc1 test-system-compiler \
628	    ${MAKE_PARAMS_${target_arch}} -V MK_CLANG_BOOTSTRAP 2>/dev/null || \
629	    echo unknown
630.export _need_clang_${target}_${target_arch}
631.endif
632.if !defined(_need_lld_${target}_${target_arch})
633_need_lld_${target}_${target_arch} != \
634	env TARGET=${target} TARGET_ARCH=${target_arch} \
635	${SUB_MAKE} -C ${.CURDIR} -f Makefile.inc1 test-system-linker \
636	    ${MAKE_PARAMS_${target_arch}} -V MK_LLD_BOOTSTRAP 2>/dev/null || \
637	    echo unknown
638.export _need_lld_${target}_${target_arch}
639.endif
640# Setup env for each arch to use the one clang.
641.if defined(_need_clang_${target}_${target_arch}) && \
642    ${_need_clang_${target}_${target_arch}} == "yes"
643# No check on existing XCC or CROSS_BINUTILS_PREFIX, etc, is needed since
644# we use the test-system-compiler logic to determine if clang needs to be
645# built.  It will be no from that logic if already using an external
646# toolchain or /usr/bin/cc.
647# XXX: Passing HOST_OBJTOP into the PATH would allow skipping legacy,
648#      bootstrap-tools, and cross-tools.  Need to ensure each tool actually
649#      supports all TARGETS though.
650# For now we only pass UNIVERSE_TOOLCHAIN_PATH which will be added at the end
651# of STRICTTMPPATH to ensure that the target-specific binaries come first.
652MAKE_PARAMS_${target_arch}+= \
653	XCC="${HOST_OBJTOP}/tmp/usr/bin/cc" \
654	XCXX="${HOST_OBJTOP}/tmp/usr/bin/c++" \
655	XCPP="${HOST_OBJTOP}/tmp/usr/bin/cpp" \
656	UNIVERSE_TOOLCHAIN_PATH=${HOST_OBJTOP}/tmp/usr/bin
657.endif
658.if defined(_need_lld_${target}_${target_arch}) && \
659    ${_need_lld_${target}_${target_arch}} == "yes"
660MAKE_PARAMS_${target_arch}+= \
661	XLD="${HOST_OBJTOP}/tmp/usr/bin/ld"
662.endif
663.endfor
664.endif	# !make(targets)
665
666.if ${__DO_WORLDS} == "yes"
667universe_${target}_done: universe_${target}_worlds .PHONY
668.for target_arch in ${TARGET_ARCHES_${target}}
669universe_${target}_worlds: universe_${target}_${target_arch} .PHONY
670.if (defined(_need_clang_${target}_${target_arch}) && \
671    ${_need_clang_${target}_${target_arch}} == "yes") || \
672    (defined(_need_lld_${target}_${target_arch}) && \
673    ${_need_lld_${target}_${target_arch}} == "yes")
674universe_${target}_${target_arch}: universe-toolchain
675universe_${target}_prologue: universe-toolchain
676.endif
677universe_${target}_${target_arch}: universe_${target}_prologue .MAKE .PHONY
678	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
679	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
680	    ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
681	    TARGET=${target} \
682	    TARGET_ARCH=${target_arch} \
683	    ${MAKE_PARAMS_${target_arch}} \
684	    > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
685	    (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
686	    "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
687	    ${MAKEFAIL}))
688	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
689.endfor
690.endif # ${__DO_WORLDS} == "yes"
691
692.if ${__DO_KERNELS} == "yes"
693universe_${target}_done: universe_${target}_kernels .PHONY
694universe_${target}_kernels: universe_${target}_worlds .PHONY
695universe_${target}_kernels: universe_${target}_prologue .MAKE .PHONY
696	@cd ${.CURDIR}; ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
697	    universe_kernels
698.endif # ${__DO_KERNELS} == "yes"
699
700# Tell the user the worlds and kernels have completed
701universe_${target}: universe_${target}_done
702universe_${target}_done:
703	@echo ">> ${target} completed on `LC_ALL=C date`"
704.endfor
705.if make(universe_kernconfs) || make(universe_kernels)
706.if !defined(TARGET)
707TARGET!=	uname -m
708.endif
709universe_kernels_prologue: .PHONY
710	@echo ">> ${TARGET} kernels started on `LC_ALL=C date`"
711universe_kernels: universe_kernconfs .PHONY
712	@echo ">> ${TARGET} kernels completed on `LC_ALL=C date`"
713.if defined(MAKE_ALL_KERNELS)
714_THINNER=cat
715.elif defined(MAKE_LINT_KERNELS)
716_THINNER=grep 'LINT' || true
717.else
718_THINNER=xargs grep -L "^.NO_UNIVERSE" || true
719.endif
720KERNCONFS!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
721		find [[:upper:][:digit:]]*[[:upper:][:digit:]] \
722		-type f -maxdepth 0 \
723		! -name DEFAULTS ! -name NOTES | \
724		${_THINNER}
725universe_kernconfs: universe_kernels_prologue .PHONY
726.for kernel in ${KERNCONFS}
727TARGET_ARCH_${kernel}!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
728	env PATH=${HOST_OBJTOP}/tmp/legacy/bin:${PATH:Q} \
729	config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
730	grep -v WARNING: | cut -f 2
731.if empty(TARGET_ARCH_${kernel})
732.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
733.endif
734universe_kernconfs_${TARGET_ARCH_${kernel}}: universe_kernconf_${TARGET}_${kernel}
735universe_kernconf_${TARGET}_${kernel}: .MAKE
736	@echo ">> ${TARGET}.${TARGET_ARCH_${kernel}} ${kernel} kernel started on `LC_ALL=C date`"
737	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
738	    ${SUB_MAKE} ${JFLAG} buildkernel \
739	    TARGET=${TARGET} \
740	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
741	    ${MAKE_PARAMS_${TARGET_ARCH_${kernel}}} \
742	    KERNCONF=${kernel} \
743	    > _.${TARGET}.${kernel} 2>&1 || \
744	    (echo "${TARGET} ${kernel} kernel failed," \
745	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
746	@echo ">> ${TARGET}.${TARGET_ARCH_${kernel}} ${kernel} kernel completed on `LC_ALL=C date`"
747.endfor
748.for target_arch in ${TARGET_ARCHES_${TARGET}}
749universe_kernconfs: universe_kernconfs_${target_arch} .PHONY
750universe_kernconfs_${target_arch}:
751.endfor
752.endif	# make(universe_kernels)
753universe: universe_epilogue
754universe_epilogue: .PHONY
755	@echo "--------------------------------------------------------------"
756	@echo ">>> make universe completed on `LC_ALL=C date`"
757	@echo "                      (started ${STARTTIME})"
758	@echo "--------------------------------------------------------------"
759.if defined(DOING_TINDERBOX)
760	@if [ -e ${FAILFILE} ] ; then \
761		echo "Tinderbox failed:" ;\
762		cat ${FAILFILE} ;\
763		exit 1 ;\
764	fi
765.endif
766.endif
767
768.if defined(.PARSEDIR)
769# This makefile does not run in meta mode
770.MAKE.MODE= normal
771# Normally the things we run from here don't either.
772# Using -DWITH_META_MODE
773# we can buildworld with meta files created which are useful
774# for debugging, but without any of the rest of a meta mode build.
775MK_DIRDEPS_BUILD= no
776MK_STAGING= no
777# tell meta.autodep.mk to not even think about updating anything.
778UPDATE_DEPENDFILE= NO
779.if !make(showconfig)
780.export MK_DIRDEPS_BUILD MK_STAGING UPDATE_DEPENDFILE
781.endif
782
783.if make(universe)
784# we do not want a failure of one branch abort all.
785MAKE_JOB_ERROR_TOKEN= no
786.export MAKE_JOB_ERROR_TOKEN
787.endif
788.endif # bmake
789
790.endif				# DIRDEPS_BUILD
791