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