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