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