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