xref: /freebsd/Makefile (revision 322b341d002945fae9151b8beba6f420db61037d)
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)
510# powerpcspe excluded from main list until clang fixed
511EXTRA_ARCHES_powerpc=	powerpcspe powerpc64le
512.endif
513TARGETS?=amd64 arm arm64 i386 powerpc riscv
514_UNIVERSE_TARGETS=	${TARGETS}
515TARGET_ARCHES_arm?=	armv6 armv7
516TARGET_ARCHES_arm64?=	aarch64
517TARGET_ARCHES_powerpc?=	powerpc powerpc64 ${EXTRA_ARCHES_powerpc}
518TARGET_ARCHES_riscv?=	riscv64 riscv64sf
519.for target in ${TARGETS}
520TARGET_ARCHES_${target}?= ${target}
521.endfor
522
523.if defined(USE_GCC_TOOLCHAINS)
524TOOLCHAINS_amd64=	amd64-gcc6
525TOOLCHAINS_arm64=	aarch64-gcc6
526TOOLCHAINS_i386=	i386-gcc6
527TOOLCHAINS_powerpc=	powerpc-gcc6 powerpc64-gcc6
528TOOLCHAIN_powerpc64=	powerpc64-gcc6
529.endif
530
531# If a target is using an external toolchain, set MAKE_PARAMS to enable use
532# of the toolchain.  If the external toolchain is missing, exclude the target
533# from universe.
534.for target in ${_UNIVERSE_TARGETS}
535.if !empty(TOOLCHAINS_${target})
536.for toolchain in ${TOOLCHAINS_${target}}
537.if !exists(/usr/local/share/toolchains/${toolchain}.mk)
538_UNIVERSE_TARGETS:= ${_UNIVERSE_TARGETS:N${target}}
539universe: universe_${toolchain}_skip .PHONY
540universe_epilogue: universe_${toolchain}_skip .PHONY
541universe_${toolchain}_skip: universe_prologue .PHONY
542	@echo ">> ${target} skipped - install ${toolchain} port or package to build"
543.endif
544.endfor
545.for arch in ${TARGET_ARCHES_${target}}
546TOOLCHAIN_${arch}?=	${TOOLCHAINS_${target}:[1]}
547MAKE_PARAMS_${arch}?=	CROSS_TOOLCHAIN=${TOOLCHAIN_${arch}}
548.endfor
549.endif
550.endfor
551
552UNIVERSE_TARGET?=	buildworld
553KERNSRCDIR?=		${.CURDIR}/sys
554
555targets:	.PHONY
556	@echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
557.for target in ${TARGETS}
558.for target_arch in ${TARGET_ARCHES_${target}}
559	@echo "    ${target}/${target_arch}"
560.endfor
561.endfor
562
563.if defined(DOING_TINDERBOX)
564FAILFILE=${.CURDIR}/_.tinderbox.failed
565MAKEFAIL=tee -a ${FAILFILE}
566.else
567MAKEFAIL=cat
568.endif
569
570universe_prologue:  upgrade_checks
571universe: universe_prologue
572universe_prologue: .PHONY
573	@echo "--------------------------------------------------------------"
574	@echo ">>> make universe started on ${STARTTIME}"
575	@echo "--------------------------------------------------------------"
576.if defined(DOING_TINDERBOX)
577	@rm -f ${FAILFILE}
578.endif
579
580universe-toolchain: .PHONY universe_prologue
581	@echo "--------------------------------------------------------------"
582	@echo "> Toolchain bootstrap started on `LC_ALL=C date`"
583	@echo "--------------------------------------------------------------"
584	${_+_}@cd ${.CURDIR}; \
585	    env PATH=${PATH} ${SUB_MAKE} ${JFLAG} kernel-toolchain \
586	    TARGET=${MACHINE} TARGET_ARCH=${MACHINE_ARCH} \
587	    OBJTOP="${HOST_OBJTOP}" \
588	    WITHOUT_SYSTEM_COMPILER=yes \
589	    WITHOUT_SYSTEM_LINKER=yes \
590	    TOOLS_PREFIX_UNDEF= \
591	    kernel-toolchain \
592	    MK_LLVM_TARGET_ALL=yes \
593	    > _.${.TARGET} 2>&1 || \
594	    (echo "${.TARGET} failed," \
595	    "check _.${.TARGET} for details" | \
596	    ${MAKEFAIL}; false)
597	@if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/cc" ]; then \
598	    echo "Missing host compiler at ${HOST_OBJTOP}/tmp/usr/bin/cc?" >&2; \
599	    false; \
600	fi
601	@if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/ld" ]; then \
602	    echo "Missing host linker at ${HOST_OBJTOP}/tmp/usr/bin/ld?" >&2; \
603	    false; \
604	fi
605	@echo "--------------------------------------------------------------"
606	@echo "> Toolchain bootstrap completed on `LC_ALL=C date`"
607	@echo "--------------------------------------------------------------"
608
609.for target in ${_UNIVERSE_TARGETS}
610universe: universe_${target}
611universe_epilogue: universe_${target}
612universe_${target}: universe_${target}_prologue .PHONY
613universe_${target}_prologue: universe_prologue .PHONY
614	@echo ">> ${target} started on `LC_ALL=C date`"
615universe_${target}_worlds: .PHONY
616
617.if !make(targets) && !make(universe-toolchain)
618.for target_arch in ${TARGET_ARCHES_${target}}
619.if !defined(_need_clang_${target}_${target_arch})
620_need_clang_${target}_${target_arch} != \
621	env TARGET=${target} TARGET_ARCH=${target_arch} \
622	${SUB_MAKE} -C ${.CURDIR} -f Makefile.inc1 test-system-compiler \
623	    ${MAKE_PARAMS_${target_arch}} -V MK_CLANG_BOOTSTRAP 2>/dev/null || \
624	    echo unknown
625.export _need_clang_${target}_${target_arch}
626.endif
627.if !defined(_need_lld_${target}_${target_arch})
628_need_lld_${target}_${target_arch} != \
629	env TARGET=${target} TARGET_ARCH=${target_arch} \
630	${SUB_MAKE} -C ${.CURDIR} -f Makefile.inc1 test-system-linker \
631	    ${MAKE_PARAMS_${target_arch}} -V MK_LLD_BOOTSTRAP 2>/dev/null || \
632	    echo unknown
633.export _need_lld_${target}_${target_arch}
634.endif
635# Setup env for each arch to use the one clang.
636.if defined(_need_clang_${target}_${target_arch}) && \
637    ${_need_clang_${target}_${target_arch}} == "yes"
638# No check on existing XCC or CROSS_BINUTILS_PREFIX, etc, is needed since
639# we use the test-system-compiler logic to determine if clang needs to be
640# built.  It will be no from that logic if already using an external
641# toolchain or /usr/bin/cc.
642# XXX: Passing HOST_OBJTOP into the PATH would allow skipping legacy,
643#      bootstrap-tools, and cross-tools.  Need to ensure each tool actually
644#      supports all TARGETS though.
645# For now we only pass UNIVERSE_TOOLCHAIN_PATH which will be added at the end
646# of STRICTTMPPATH to ensure that the target-specific binaries come first.
647MAKE_PARAMS_${target_arch}+= \
648	XCC="${HOST_OBJTOP}/tmp/usr/bin/cc" \
649	XCXX="${HOST_OBJTOP}/tmp/usr/bin/c++" \
650	XCPP="${HOST_OBJTOP}/tmp/usr/bin/cpp" \
651	UNIVERSE_TOOLCHAIN_PATH=${HOST_OBJTOP}/tmp/usr/bin
652.endif
653.if defined(_need_lld_${target}_${target_arch}) && \
654    ${_need_lld_${target}_${target_arch}} == "yes"
655MAKE_PARAMS_${target_arch}+= \
656	XLD="${HOST_OBJTOP}/tmp/usr/bin/ld"
657.endif
658.endfor
659.endif	# !make(targets)
660
661.if ${__DO_WORLDS} == "yes"
662universe_${target}_done: universe_${target}_worlds .PHONY
663.for target_arch in ${TARGET_ARCHES_${target}}
664universe_${target}_worlds: universe_${target}_${target_arch} .PHONY
665.if (defined(_need_clang_${target}_${target_arch}) && \
666    ${_need_clang_${target}_${target_arch}} == "yes") || \
667    (defined(_need_lld_${target}_${target_arch}) && \
668    ${_need_lld_${target}_${target_arch}} == "yes")
669universe_${target}_${target_arch}: universe-toolchain
670universe_${target}_prologue: universe-toolchain
671.endif
672universe_${target}_${target_arch}: universe_${target}_prologue .MAKE .PHONY
673	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
674	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
675	    ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
676	    TARGET=${target} \
677	    TARGET_ARCH=${target_arch} \
678	    ${MAKE_PARAMS_${target_arch}} \
679	    > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
680	    (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
681	    "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
682	    ${MAKEFAIL}))
683	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
684.endfor
685.endif # ${__DO_WORLDS} == "yes"
686
687.if ${__DO_KERNELS} == "yes"
688universe_${target}_done: universe_${target}_kernels .PHONY
689universe_${target}_kernels: universe_${target}_worlds .PHONY
690universe_${target}_kernels: universe_${target}_prologue .MAKE .PHONY
691	@cd ${.CURDIR}; ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
692	    universe_kernels
693.endif # ${__DO_KERNELS} == "yes"
694
695# Tell the user the worlds and kernels have completed
696universe_${target}: universe_${target}_done
697universe_${target}_done:
698	@echo ">> ${target} completed on `LC_ALL=C date`"
699.endfor
700.if make(universe_kernconfs) || make(universe_kernels)
701.if !defined(TARGET)
702TARGET!=	uname -m
703.endif
704universe_kernels_prologue: .PHONY
705	@echo ">> ${TARGET} kernels started on `LC_ALL=C date`"
706universe_kernels: universe_kernconfs .PHONY
707	@echo ">> ${TARGET} kernels completed on `LC_ALL=C date`"
708.if defined(MAKE_ALL_KERNELS)
709_THINNER=cat
710.elif defined(MAKE_LINT_KERNELS)
711_THINNER=grep 'LINT' || true
712.else
713_THINNER=xargs grep -L "^.NO_UNIVERSE" || true
714.endif
715KERNCONFS!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
716		find [[:upper:][:digit:]]*[[:upper:][:digit:]] \
717		-type f -maxdepth 0 \
718		! -name DEFAULTS ! -name NOTES | \
719		${_THINNER}
720universe_kernconfs: universe_kernels_prologue .PHONY
721.for kernel in ${KERNCONFS}
722TARGET_ARCH_${kernel}!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
723	env PATH=${HOST_OBJTOP}/tmp/legacy/bin:${PATH:Q} \
724	config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
725	grep -v WARNING: | cut -f 2
726.if empty(TARGET_ARCH_${kernel})
727.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
728.endif
729universe_kernconfs_${TARGET_ARCH_${kernel}}: universe_kernconf_${TARGET}_${kernel}
730universe_kernconf_${TARGET}_${kernel}: .MAKE
731	@echo ">> ${TARGET}.${TARGET_ARCH_${kernel}} ${kernel} kernel started on `LC_ALL=C date`"
732	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
733	    ${SUB_MAKE} ${JFLAG} buildkernel \
734	    TARGET=${TARGET} \
735	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
736	    ${MAKE_PARAMS_${TARGET_ARCH_${kernel}}} \
737	    KERNCONF=${kernel} \
738	    > _.${TARGET}.${kernel} 2>&1 || \
739	    (echo "${TARGET} ${kernel} kernel failed," \
740	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
741	@echo ">> ${TARGET}.${TARGET_ARCH_${kernel}} ${kernel} kernel completed on `LC_ALL=C date`"
742.endfor
743.for target_arch in ${TARGET_ARCHES_${TARGET}}
744universe_kernconfs: universe_kernconfs_${target_arch} .PHONY
745universe_kernconfs_${target_arch}:
746.endfor
747.endif	# make(universe_kernels)
748universe: universe_epilogue
749universe_epilogue: .PHONY
750	@echo "--------------------------------------------------------------"
751	@echo ">>> make universe completed on `LC_ALL=C date`"
752	@echo "                      (started ${STARTTIME})"
753	@echo "--------------------------------------------------------------"
754.if defined(DOING_TINDERBOX)
755	@if [ -e ${FAILFILE} ] ; then \
756		echo "Tinderbox failed:" ;\
757		cat ${FAILFILE} ;\
758		exit 1 ;\
759	fi
760.endif
761.endif
762
763.if defined(.PARSEDIR)
764# This makefile does not run in meta mode
765.MAKE.MODE= normal
766# Normally the things we run from here don't either.
767# Using -DWITH_META_MODE
768# we can buildworld with meta files created which are useful
769# for debugging, but without any of the rest of a meta mode build.
770MK_DIRDEPS_BUILD= no
771MK_STAGING= no
772# tell meta.autodep.mk to not even think about updating anything.
773UPDATE_DEPENDFILE= NO
774.if !make(showconfig)
775.export MK_DIRDEPS_BUILD MK_STAGING UPDATE_DEPENDFILE
776.endif
777
778.if make(universe)
779# we do not want a failure of one branch abort all.
780MAKE_JOB_ERROR_TOKEN= no
781.export MAKE_JOB_ERROR_TOKEN
782.endif
783.endif # bmake
784
785.endif				# DIRDEPS_BUILD
786