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