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