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