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