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