]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - Makefile.inc1
ZFS: MFV 2.0-rc1-gfd20a8
[FreeBSD/FreeBSD.git] / Makefile.inc1
1 #
2 # $FreeBSD$
3 #
4 # Make command line options:
5 #       -DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
6 #       -DNO_CLEAN do not clean at all
7 #       -DDB_FROM_SRC use the user/group databases in src/etc instead of
8 #           the system database when installing.
9 #       -DNO_SHARE do not go into share subdir
10 #       -DKERNFAST define NO_KERNEL{CONFIG,CLEAN,OBJ}
11 #       -DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
12 #       -DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
13 #       -DNO_KERNELOBJ do not run ${MAKE} obj in ${MAKE} buildkernel
14 #       -DNO_PORTSUPDATE do not update ports in ${MAKE} update
15 #       -DNO_ROOT install without using root privilege
16 #       -DNO_DOCUPDATE do not update doc in ${MAKE} update
17 #       -DWITHOUT_CTF do not run the DTrace CTF conversion tools on built objects
18 #       LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
19 #       LOCAL_ITOOLS="list of tools" to add additional tools to the ITOOLS list
20 #       LOCAL_LIB_DIRS="list of dirs" to add additional dirs to libraries target
21 #       LOCAL_MTREE="list of mtree files" to process to allow local directories
22 #           to be created before files are installed
23 #       LOCAL_TOOL_DIRS="list of dirs" to add additional dirs to the build-tools
24 #           list
25 #       LOCAL_XTOOL_DIRS="list of dirs" to add additional dirs to the
26 #           cross-tools target
27 #       METALOG="path to metadata log" to write permission and ownership
28 #           when NO_ROOT is set.  (default: ${DESTDIR}/METALOG)
29 #       TARGET="machine" to crossbuild world for a different machine type
30 #       TARGET_ARCH= may be required when a TARGET supports multiple endians
31 #       BUILDENV_SHELL= shell to launch for the buildenv target (def:${SHELL})
32 #       WORLD_FLAGS= additional flags to pass to make(1) during buildworld
33 #       KERNEL_FLAGS= additional flags to pass to make(1) during buildkernel
34 #       SUBDIR_OVERRIDE="list of dirs" to build rather than everything.
35 #           All libraries and includes, and some build tools will still build.
36
37 #
38 # The intended user-driven targets are:
39 # buildworld  - rebuild *everything*, including glue to help do upgrades
40 # installworld- install everything built by "buildworld"
41 # checkworld  - run test suite on installed world
42 # doxygen     - build API documentation of the kernel
43 # update      - convenient way to update your source tree (eg: svn/svnup)
44 #
45 # Standard targets (not defined here) are documented in the makefiles in
46 # /usr/share/mk.  These include:
47 #               obj depend all install clean cleandepend cleanobj
48
49 .if !defined(TARGET) || !defined(TARGET_ARCH)
50 .error "Both TARGET and TARGET_ARCH must be defined."
51 .endif
52
53 .if make(showconfig) || make(test-system-*)
54 _MKSHOWCONFIG=  t
55 .endif
56
57 SRCDIR?=        ${.CURDIR}
58 LOCALBASE?=     /usr/local
59
60 .include "share/mk/src.tools.mk"
61
62 # Cross toolchain changes must be in effect before bsd.compiler.mk
63 # so that gets the right CC, and pass CROSS_TOOLCHAIN to submakes.
64 .if defined(CROSS_TOOLCHAIN)
65 .if exists(${LOCALBASE}/share/toolchains/${CROSS_TOOLCHAIN}.mk)
66 .include "${LOCALBASE}/share/toolchains/${CROSS_TOOLCHAIN}.mk"
67 .elif exists(/usr/share/toolchains/${CROSS_TOOLCHAIN}.mk)
68 .include "/usr/share/toolchains/${CROSS_TOOLCHAIN}.mk"
69 .elif exists(${CROSS_TOOLCHAIN})
70 .include "${CROSS_TOOLCHAIN}"
71 .else
72 .error CROSS_TOOLCHAIN ${CROSS_TOOLCHAIN} not found
73 .endif
74 CROSSENV+=CROSS_TOOLCHAIN="${CROSS_TOOLCHAIN}"
75 .endif
76 .if defined(CROSS_TOOLCHAIN_PREFIX)
77 CROSS_COMPILER_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
78 .endif
79
80 XCOMPILERS=     CC CXX CPP
81 .for COMPILER in ${XCOMPILERS}
82 .if defined(CROSS_COMPILER_PREFIX)
83 X${COMPILER}?=  ${CROSS_COMPILER_PREFIX}${${COMPILER}}
84 .else
85 X${COMPILER}?=  ${${COMPILER}}
86 .endif
87 .endfor
88 # If a full path to an external cross compiler is given, don't build
89 # a cross compiler.
90 .if ${XCC:N${CCACHE_BIN}:M/*}
91 MK_CLANG_BOOTSTRAP=     no
92 .endif
93
94 # Pull in compiler metadata from buildworld/toolchain if possible to avoid
95 # running CC from bsd.compiler.mk.
96 .if make(installworld) || make(install) || make(distributeworld) || \
97     make(stageworld)
98 .-include "${OBJTOP}/toolchain-metadata.mk"
99 .if !defined(_LOADED_TOOLCHAIN_METADATA)
100 .error A build is required first.  You may have the wrong MAKEOBJDIRPREFIX set.
101 .endif
102 .endif
103
104 # Pull in COMPILER_TYPE and COMPILER_FREEBSD_VERSION early. Pull it from the
105 # tree to be friendlier to foreign OS builds. It's safe to do so unconditionally
106 # here since we will always have the right make, unlike in src/Makefile
107 # Don't include bsd.linker.mk yet until XBINUTILS is handled (after src.opts.mk)
108 _NO_INCLUDE_LINKERMK=   t
109 # We also want the X_COMPILER* variables if we are using an external toolchain.
110 _WANT_TOOLCHAIN_CROSS_VARS=     t
111 .include "share/mk/bsd.compiler.mk"
112 .undef _NO_INCLUDE_LINKERMK
113 .undef _WANT_TOOLCHAIN_CROSS_VARS
114 # src.opts.mk depends on COMPILER_FEATURES
115 .include "share/mk/src.opts.mk"
116
117 .if ${TARGET} == ${MACHINE}
118 TARGET_CPUTYPE?=${CPUTYPE}
119 .else
120 TARGET_CPUTYPE?=
121 .endif
122 .if !empty(TARGET_CPUTYPE)
123 _TARGET_CPUTYPE=${TARGET_CPUTYPE}
124 .else
125 _TARGET_CPUTYPE=dummy
126 .endif
127 .if ${TARGET} == "arm"
128 .if ${TARGET_ARCH:Marmv[67]*} != "" && ${TARGET_CPUTYPE:M*soft*} == ""
129 TARGET_ABI=     gnueabihf
130 .else
131 TARGET_ABI=     gnueabi
132 .endif
133 .endif
134 MACHINE_ABI?=   unknown
135 MACHINE_TRIPLE?=${MACHINE_ARCH:S/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${MACHINE_ABI}-freebsd13.0
136 TARGET_ABI?=    unknown
137 TARGET_TRIPLE?= ${TARGET_ARCH:S/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${TARGET_ABI}-freebsd13.0
138 KNOWN_ARCHES?=  aarch64/arm64 \
139                 amd64 \
140                 armv6/arm \
141                 armv7/arm \
142                 i386 \
143                 mips \
144                 mipsel/mips \
145                 mips64el/mips \
146                 mipsn32el/mips \
147                 mips64/mips \
148                 mipsn32/mips \
149                 mipshf/mips \
150                 mipselhf/mips \
151                 mips64elhf/mips \
152                 mips64hf/mips \
153                 powerpc \
154                 powerpc64/powerpc \
155                 powerpcspe/powerpc \
156                 riscv64/riscv \
157                 riscv64sf/riscv
158
159 .if ${TARGET} == ${TARGET_ARCH}
160 _t=             ${TARGET}
161 .else
162 _t=             ${TARGET_ARCH}/${TARGET}
163 .endif
164 .for _t in ${_t}
165 .if empty(KNOWN_ARCHES:M${_t})
166 .error Unknown target ${TARGET_ARCH}:${TARGET}.
167 .endif
168 .endfor
169
170 .if ${.MAKE.OS} != "FreeBSD"
171 CROSSBUILD_HOST=${.MAKE.OS}
172 .if ${.MAKE.OS} != "Linux" && ${.MAKE.OS} != "Darwin"
173 .warning "Unsupported crossbuild system: ${.MAKE.OS}. Build will probably fail!"
174 .endif
175 # We need to force NO_ROOT/DB_FROM_SRC builds when building on other operating
176 # systems since the BSD.foo.dist specs contain users and groups that do not
177 # exist by default on a Linux/MacOS system.
178 NO_ROOT:=       1
179 DB_FROM_SRC:=   1
180 .export NO_ROOT
181 .endif
182
183 # If all targets are disabled for system llvm then don't expect it to work
184 # for cross-builds.
185 .if !defined(TOOLS_PREFIX) && ${MK_LLVM_TARGET_ALL} == "no" && \
186     ${MACHINE} != ${TARGET} && ${MACHINE_ARCH} != ${TARGET_ARCH} && \
187     !make(showconfig)
188 MK_SYSTEM_COMPILER=     no
189 MK_SYSTEM_LINKER=       no
190 .endif
191
192 # Handle external binutils.
193 .if defined(CROSS_TOOLCHAIN_PREFIX)
194 CROSS_BINUTILS_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
195 .endif
196 XBINUTILS=      AS AR LD NM OBJCOPY RANLIB SIZE STRINGS STRIPBIN
197 .for BINUTIL in ${XBINUTILS}
198 .if defined(CROSS_BINUTILS_PREFIX) && \
199     exists(${CROSS_BINUTILS_PREFIX}/${${BINUTIL}})
200 X${BINUTIL}?=   ${CROSS_BINUTILS_PREFIX:C,/*$,,}/${${BINUTIL}}
201 .else
202 X${BINUTIL}?=   ${${BINUTIL}}
203 .endif
204 .endfor
205
206 # If a full path to an external linker is given, don't build lld.
207 .if ${XLD:M/*}
208 MK_LLD_BOOTSTRAP=       no
209 .endif
210
211 # We also want the X_LINKER* variables if we are using an external toolchain.
212 _WANT_TOOLCHAIN_CROSS_VARS=     t
213 .include "share/mk/bsd.linker.mk"
214 .undef _WANT_TOOLCHAIN_CROSS_VARS
215
216 # Begin WITH_SYSTEM_COMPILER / WITH_SYSTEM_LD
217
218 # WITH_SYSTEM_COMPILER - Pull in needed values and make a decision.
219
220 # Check if there is a local compiler that can satisfy as an external compiler.
221 # Which compiler is expected to be used?
222 .if ${MK_CLANG_BOOTSTRAP} == "yes"
223 WANT_COMPILER_TYPE=     clang
224 .else
225 WANT_COMPILER_TYPE=
226 .endif
227
228 .if !defined(WANT_COMPILER_FREEBSD_VERSION) && !make(showconfig) && \
229     !make(test-system-linker)
230 .if ${WANT_COMPILER_TYPE} == "clang"
231 WANT_COMPILER_FREEBSD_VERSION_FILE= lib/clang/freebsd_cc_version.h
232 WANT_COMPILER_FREEBSD_VERSION!= \
233         awk '$$2 == "FREEBSD_CC_VERSION" {printf("%d\n", $$3)}' \
234         ${SRCDIR}/${WANT_COMPILER_FREEBSD_VERSION_FILE} || echo unknown
235 WANT_COMPILER_VERSION_FILE= lib/clang/include/clang/Basic/Version.inc
236 WANT_COMPILER_VERSION!= \
237         awk '$$2 == "CLANG_VERSION" {split($$3, a, "."); print a[1] * 10000 + a[2] * 100 + a[3]}' \
238         ${SRCDIR}/${WANT_COMPILER_VERSION_FILE} || echo unknown
239 .endif
240 .export WANT_COMPILER_FREEBSD_VERSION WANT_COMPILER_VERSION
241 .endif  # !defined(WANT_COMPILER_FREEBSD_VERSION)
242
243 # It needs to be the same revision as we would build for the bootstrap.
244 # If the expected vs CC is different then we can't skip.
245 # GCC cannot be used for cross-arch yet.  For clang we pass -target later if
246 # TARGET_ARCH!=MACHINE_ARCH.
247 .if ${MK_SYSTEM_COMPILER} == "yes" && \
248     defined(WANT_COMPILER_FREEBSD_VERSION) && \
249     ${MK_CLANG_BOOTSTRAP} == "yes" && \
250     !make(xdev*) && \
251     ${X_COMPILER_TYPE} == ${WANT_COMPILER_TYPE} && \
252     (${X_COMPILER_TYPE} == "clang" || ${TARGET_ARCH} == ${MACHINE_ARCH}) && \
253     ${X_COMPILER_VERSION} == ${WANT_COMPILER_VERSION} && \
254     ${X_COMPILER_FREEBSD_VERSION} == ${WANT_COMPILER_FREEBSD_VERSION}
255 # Everything matches, disable the bootstrap compiler.
256 MK_CLANG_BOOTSTRAP=     no
257 USING_SYSTEM_COMPILER=  yes
258 .endif  # ${WANT_COMPILER_TYPE} == ${COMPILER_TYPE}
259
260 # WITH_SYSTEM_LD - Pull in needed values and make a decision.
261
262 # Check if there is a local linker that can satisfy as an external linker.
263 # Which linker is expected to be used?
264 .if ${MK_LLD_BOOTSTRAP} == "yes"
265 WANT_LINKER_TYPE=               lld
266 .else
267 WANT_LINKER_TYPE=
268 .endif
269
270 .if !defined(WANT_LINKER_FREEBSD_VERSION) && !make(showconfig) && \
271     !make(test-system-compiler)
272 .if ${WANT_LINKER_TYPE} == "lld"
273 WANT_LINKER_FREEBSD_VERSION_FILE= lib/clang/include/VCSVersion.inc
274 _WANT_LINKER_FREEBSD_VERSION!= \
275         awk '$$2 == "LLD_REVISION" {gsub(/"/, "", $$3); print $$3}' \
276         ${SRCDIR}/${WANT_LINKER_FREEBSD_VERSION_FILE} || echo unknown
277 WANT_LINKER_FREEBSD_VERSION=${_WANT_LINKER_FREEBSD_VERSION:C/.*-(.*)/\1/}
278 WANT_LINKER_VERSION_FILE= lib/clang/include/lld/Common/Version.inc
279 WANT_LINKER_VERSION!= \
280         awk '$$2 == "LLD_VERSION_STRING" { gsub("\"", "", $$3); split($$3, a, "."); print a[1] * 10000 + a[2] * 100 + a[3]}' \
281         ${SRCDIR}/${WANT_LINKER_VERSION_FILE} || echo unknown
282 .else
283 WANT_LINKER_FREEBSD_VERSION_FILE=
284 WANT_LINKER_FREEBSD_VERSION=
285 .endif
286 .export WANT_LINKER_FREEBSD_VERSION WANT_LINKER_VERSION
287 .endif  # !defined(WANT_LINKER_FREEBSD_VERSION)
288
289 .if ${MK_SYSTEM_LINKER} == "yes" && \
290     defined(WANT_LINKER_FREEBSD_VERSION) && \
291     (${MK_LLD_BOOTSTRAP} == "yes") && \
292     !make(xdev*) && \
293     ${X_LINKER_TYPE} == ${WANT_LINKER_TYPE} && \
294     ${X_LINKER_VERSION} == ${WANT_LINKER_VERSION} && \
295     ${X_LINKER_FREEBSD_VERSION} == ${WANT_LINKER_FREEBSD_VERSION}
296 # Everything matches, disable the bootstrap linker.
297 MK_LLD_BOOTSTRAP=       no
298 USING_SYSTEM_LINKER=    yes
299 .endif  # ${WANT_LINKER_TYPE} == ${LINKER_TYPE}
300
301 # WITH_SYSTEM_COMPILER / WITH_SYSTEM_LINKER - Handle defaults and debug.
302 USING_SYSTEM_COMPILER?= no
303 USING_SYSTEM_LINKER?=   no
304
305 TEST_SYSTEM_COMPILER_VARS= \
306         USING_SYSTEM_COMPILER MK_SYSTEM_COMPILER \
307         MK_CROSS_COMPILER MK_CLANG_BOOTSTRAP \
308         WANT_COMPILER_TYPE WANT_COMPILER_VERSION WANT_COMPILER_VERSION_FILE \
309         WANT_COMPILER_FREEBSD_VERSION WANT_COMPILER_FREEBSD_VERSION_FILE \
310         CC COMPILER_TYPE COMPILER_FEATURES COMPILER_VERSION \
311         COMPILER_FREEBSD_VERSION \
312         XCC X_COMPILER_TYPE X_COMPILER_FEATURES X_COMPILER_VERSION \
313         X_COMPILER_FREEBSD_VERSION
314 TEST_SYSTEM_LINKER_VARS= \
315         USING_SYSTEM_LINKER MK_SYSTEM_LINKER \
316         MK_LLD_BOOTSTRAP \
317         WANT_LINKER_TYPE WANT_LINKER_VERSION WANT_LINKER_VERSION_FILE \
318         WANT_LINKER_FREEBSD_VERSION WANT_LINKER_FREEBSD_VERSION_FILE \
319         LD LINKER_TYPE LINKER_FEATURES LINKER_VERSION \
320         LINKER_FREEBSD_VERSION \
321         XLD X_LINKER_TYPE X_LINKER_FEATURES X_LINKER_VERSION \
322         X_LINKER_FREEBSD_VERSION
323
324 .for _t in compiler linker
325 test-system-${_t}: .PHONY
326 .for v in ${TEST_SYSTEM_${_t:tu}_VARS}
327         ${_+_}@printf "%-35s= %s\n" "${v}" "${${v}}"
328 .endfor
329 .endfor
330 .if (make(buildworld) || make(buildkernel) || make(kernel-toolchain) || \
331     make(toolchain) || make(_cross-tools))
332 .if ${USING_SYSTEM_COMPILER} == "yes"
333 .info SYSTEM_COMPILER: Determined that CC=${CC} matches the source tree.  Not bootstrapping a cross-compiler.
334 .elif ${MK_CLANG_BOOTSTRAP} == "yes"
335 .info SYSTEM_COMPILER: libclang will be built for bootstrapping a cross-compiler.
336 .endif
337 .if ${USING_SYSTEM_LINKER} == "yes"
338 .info SYSTEM_LINKER: Determined that LD=${LD} matches the source tree.  Not bootstrapping a cross-linker.
339 .elif ${MK_LLD_BOOTSTRAP} == "yes"
340 .info SYSTEM_LINKER: libclang will be built for bootstrapping a cross-linker.
341 .endif
342 .endif
343
344 # End WITH_SYSTEM_COMPILER / WITH_SYSTEM_LD
345
346 # Store some compiler metadata for use in installworld where we don't
347 # want to invoke CC at all.
348 _TOOLCHAIN_METADATA_VARS=       COMPILER_VERSION \
349                                 COMPILER_TYPE \
350                                 COMPILER_FEATURES \
351                                 COMPILER_FREEBSD_VERSION \
352                                 COMPILER_RESOURCE_DIR \
353                                 LINKER_VERSION \
354                                 LINKER_FEATURES \
355                                 LINKER_TYPE \
356                                 LINKER_FREEBSD_VERSION
357 toolchain-metadata.mk: .PHONY .META
358         @: > ${.TARGET}
359         @echo ".info Using cached toolchain metadata from build at $$(hostname) on $$(date)" \
360             > ${.TARGET}
361         @echo "_LOADED_TOOLCHAIN_METADATA=t" >> ${.TARGET}
362 .for v in ${_TOOLCHAIN_METADATA_VARS}
363         @echo "${v}=${${v}}" >> ${.TARGET}
364         @echo "X_${v}=${X_${v}}" >> ${.TARGET}
365 .endfor
366         @echo ".export ${_TOOLCHAIN_METADATA_VARS}" >> ${.TARGET}
367         @echo ".export ${_TOOLCHAIN_METADATA_VARS:C,^,X_,}" >> ${.TARGET}
368
369
370 # We must do lib/ and libexec/ before bin/ in case of a mid-install error to
371 # keep the users system reasonably usable.  For static->dynamic root upgrades,
372 # we don't want to install a dynamic binary without rtld and the needed
373 # libraries.  More commonly, for dynamic root, we don't want to install a
374 # binary that requires a newer library version that hasn't been installed yet.
375 # This ordering is not a guarantee though.  The only guarantee of a working
376 # system here would require fine-grained ordering of all components based
377 # on their dependencies.
378 .if !empty(SUBDIR_OVERRIDE)
379 SUBDIR= ${SUBDIR_OVERRIDE}
380 .else
381 SUBDIR= lib libexec
382 # Add LOCAL_LIB_DIRS, but only if they will not be picked up as a SUBDIR
383 # of a LOCAL_DIRS directory.  This allows LOCAL_DIRS=foo and
384 # LOCAL_LIB_DIRS=foo/lib to behave as expected.
385 .for _DIR in ${LOCAL_DIRS:M*/} ${LOCAL_DIRS:N*/:S|$|/|}
386 _REDUNDANT_LIB_DIRS+=    ${LOCAL_LIB_DIRS:M${_DIR}*}
387 .endfor
388 .for _DIR in ${LOCAL_LIB_DIRS}
389 .if ${_DIR} == ".WAIT" || (empty(_REDUNDANT_LIB_DIRS:M${_DIR}) && exists(${.CURDIR}/${_DIR}/Makefile))
390 SUBDIR+=        ${_DIR}
391 .endif
392 .endfor
393 .if !defined(NO_ROOT) && (make(installworld) || make(install))
394 # Ensure libraries are installed before progressing.
395 SUBDIR+=.WAIT
396 .endif
397 SUBDIR+=bin
398 .if ${MK_CDDL} != "no"
399 SUBDIR+=cddl
400 .endif
401 SUBDIR+=gnu include
402 .if ${MK_KERBEROS} != "no"
403 SUBDIR+=kerberos5
404 .endif
405 .if ${MK_RESCUE} != "no"
406 SUBDIR+=rescue
407 .endif
408 SUBDIR+=sbin
409 .if ${MK_CRYPT} != "no"
410 SUBDIR+=secure
411 .endif
412 .if !defined(NO_SHARE)
413 SUBDIR+=share
414 .endif
415 .if ${MK_BOOT} != "no"
416 SUBDIR+=stand
417 .endif
418 SUBDIR+=sys usr.bin usr.sbin
419 .if ${MK_TESTS} != "no"
420 SUBDIR+=        tests
421 .endif
422
423 # Local directories are built in parallel with the base system directories.
424 # Users may insert a .WAIT directive at the beginning or elsewhere within
425 # the LOCAL_DIRS and LOCAL_LIB_DIRS lists as needed.
426 .for _DIR in ${LOCAL_DIRS}
427 .if ${_DIR} == ".WAIT" || exists(${.CURDIR}/${_DIR}/Makefile)
428 SUBDIR+=        ${_DIR}
429 .endif
430 .endfor
431
432 # We must do etc/ last as it hooks into building the man whatis file
433 # by calling 'makedb' in share/man.  This is only relevant for
434 # install/distribute so they build the whatis file after every manpage is
435 # installed.
436 .if make(installworld) || make(install)
437 SUBDIR+=.WAIT
438 .endif
439 SUBDIR+=etc
440
441 .endif  # !empty(SUBDIR_OVERRIDE)
442
443 .if defined(NOCLEAN)
444 .warning NOCLEAN option is deprecated. Use NO_CLEAN instead.
445 NO_CLEAN=       ${NOCLEAN}
446 .endif
447 .if defined(NO_CLEANDIR)
448 CLEANDIR=       clean cleandepend
449 .else
450 CLEANDIR=       cleandir
451 .endif
452
453 .if defined(WORLDFAST)
454 NO_CLEAN=       t
455 NO_OBJWALK=     t
456 .endif
457
458 .if ${MK_META_MODE} == "yes"
459 # If filemon is used then we can rely on the build being incremental-safe.
460 # The .meta files will also track the build command and rebuild should
461 # it change.
462 .if empty(.MAKE.MODE:Mnofilemon)
463 NO_CLEAN=       t
464 .endif
465 .endif
466 .if defined(NO_OBJWALK) || ${MK_AUTO_OBJ} == "yes"
467 NO_OBJWALK=     t
468 NO_KERNELOBJ=   t
469 .endif
470 .if !defined(NO_OBJWALK)
471 _obj=           obj
472 .endif
473
474 LOCAL_TOOL_DIRS?=
475 PACKAGEDIR?=    ${DESTDIR}/${DISTDIR}
476
477 .if empty(SHELL:M*csh*)
478 BUILDENV_SHELL?=${SHELL}
479 .else
480 BUILDENV_SHELL?=/bin/sh
481 .endif
482
483 .if !defined(_MKSHOWCONFIG)
484 .if !defined(SVN_CMD) || empty(SVN_CMD)
485 . for _P in /usr/bin /usr/local/bin
486 .  for _S in svn svnlite
487 .   if exists(${_P}/${_S})
488 SVN_CMD=   ${_P}/${_S}
489 .   endif
490 .  endfor
491 . endfor
492 .export SVN_CMD
493 .endif
494 SVNFLAGS?=      -r HEAD
495 .if !defined(VCS_REVISION) || empty(VCS_REVISION)
496 .if !defined(SVNVERSION_CMD) || empty(SVNVERSION_CMD)
497 . for _D in ${PATH:S,:, ,g}
498 .  if exists(${_D}/svnversion)
499 SVNVERSION_CMD?=${_D}/svnversion
500 .  endif
501 .  if exists(${_D}/svnliteversion)
502 SVNVERSION_CMD?=${_D}/svnliteversion
503 .  endif
504 . endfor
505 .endif
506 _VCS_REVISION?= $$(eval ${SVNVERSION_CMD} ${SRCDIR})
507 . if !empty(_VCS_REVISION)
508 VCS_REVISION=   $$(echo r${_VCS_REVISION})
509 . endif
510 .export VCS_REVISION
511 .endif
512
513 .if !defined(GIT_CMD) || empty(GIT_CMD)
514 . for _P in /usr/bin /usr/local/bin
515 .  if exists(${_P}/git)
516 GIT_CMD=   ${_P}/git
517 .  endif
518 . endfor
519 .export GIT_CMD
520 .endif
521
522 .if !defined(OSRELDATE)
523 .if exists(/usr/include/osreldate.h)
524 OSRELDATE!=     awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
525                 /usr/include/osreldate.h
526 .else
527 OSRELDATE=      0
528 .endif
529 .export OSRELDATE
530 .endif
531
532 # Set VERSION for CTFMERGE to use via the default CTFFLAGS=-L VERSION.
533 .if !defined(_REVISION)
534 _REVISION!=     ${MAKE} -C ${SRCDIR}/release MK_AUTO_OBJ=no -V REVISION
535 .export _REVISION
536 .endif
537 .if !defined(_BRANCH)
538 _BRANCH!=       ${MAKE} -C ${SRCDIR}/release MK_AUTO_OBJ=no -V BRANCH
539 .export _BRANCH
540 .endif
541 .if !defined(SRCRELDATE)
542 SRCRELDATE!=    awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
543                 ${SRCDIR}/sys/sys/param.h
544 .export SRCRELDATE
545 .endif
546 .if !defined(VERSION)
547 VERSION=        FreeBSD ${_REVISION}-${_BRANCH:C/-p[0-9]+$//} ${TARGET_ARCH} ${SRCRELDATE}
548 .export VERSION
549 .endif
550
551 .if !defined(PKG_VERSION)
552 .if ${_BRANCH:MSTABLE*} || ${_BRANCH:MCURRENT*}
553 TIMENOW=        %Y%m%d%H%M%S
554 EXTRA_REVISION= .s${TIMENOW:gmtime}
555 .elif ${_BRANCH:MALPHA*}
556 EXTRA_REVISION= _${_BRANCH:C/-ALPHA/.a/}
557 .elif ${_BRANCH:MBETA*}
558 EXTRA_REVISION= _${_BRANCH:C/-BETA/.b/}
559 .elif ${_BRANCH:MRC*}
560 EXTRA_REVISION= _${_BRANCH:C/-RC/.r/}
561 .elif ${_BRANCH:MPRERELEASE*}
562 EXTRA_REVISION= _${_BRANCH:C/-PRERELEASE/.p/}
563 .elif ${_BRANCH:M*-p*}
564 EXTRA_REVISION= _${_BRANCH:C/.*-p([0-9]+$)/\1/}
565 .endif
566 PKG_VERSION=    ${_REVISION}${EXTRA_REVISION}
567 .endif
568 .endif  # !defined(PKG_VERSION)
569
570 .if !defined(PKG_TIMESTAMP)
571 TIMEEPOCHNOW=   %s
572 SOURCE_DATE_EPOCH=      ${TIMEEPOCHNOW:gmtime}
573 .else
574 SOURCE_DATE_EPOCH=      ${PKG_TIMESTAMP}
575 .endif
576
577 PKG_NAME_PREFIX?=       FreeBSD
578 PKG_MAINTAINER?=        re@FreeBSD.org
579 PKG_WWW?=               https://www.FreeBSD.org
580 .export PKG_NAME_PREFIX
581 .export PKG_MAINTAINER
582 .export PKG_WWW
583
584 .if !defined(_MKSHOWCONFIG)
585 _CPUTYPE!=      MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} -f /dev/null \
586                 -m ${.CURDIR}/share/mk MK_AUTO_OBJ=no -V CPUTYPE
587 .if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
588 .error CPUTYPE global should be set with ?=.
589 .endif
590 .endif
591 .if make(buildworld)
592 BUILD_ARCH!=    uname -p
593 # On some Linux systems uname -p returns "unknown" so skip this check there.
594 # This check only exists to tell people to use TARGET_ARCH instead of
595 # MACHINE_ARCH so skipping it when crossbuilding on non-FreeBSD should be fine.
596 .if ${MACHINE_ARCH} != ${BUILD_ARCH} && ${.MAKE.OS} == "FreeBSD"
597 .error To cross-build, set TARGET_ARCH.
598 .endif
599 .endif
600 WORLDTMP?=      ${OBJTOP}/tmp
601 BPATH=          ${CCACHE_WRAPPER_PATH_PFX}${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/bin:${WORLDTMP}/legacy/usr/libexec
602 XPATH=          ${WORLDTMP}/bin:${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin
603
604 # When building we want to find the cross tools before the host tools in ${BPATH}.
605 # We also need to add UNIVERSE_TOOLCHAIN_PATH so that we can find the shared
606 # toolchain files (clang, lld, etc.) during make universe/tinderbox
607 STRICTTMPPATH=  ${XPATH}:${BPATH}:${UNIVERSE_TOOLCHAIN_PATH}
608 # We should not be using tools from /usr/bin accidentally since this could cause
609 # the build to break on other systems that don't have that tool. For now we
610 # still allow using the old behaviour (inheriting $PATH) if
611 # BUILD_WITH_STRICT_TMPPATH is set to 0 but this will eventually be removed.
612
613 # Currently strict $PATH can cause build failures and does not work yet with
614 # USING_SYSTEM_LINKER/USING_SYSTEM_COMPILER. Once these issues have been
615 # resolved it will be turned on by default.
616 BUILD_WITH_STRICT_TMPPATH?=0
617 .if defined(CROSSBUILD_HOST)
618 # When building on non-FreeBSD we can't rely on the tools in /usr/bin being compatible
619 # with what FreeBSD expects. Therefore we only use tools from STRICTTMPPATH
620 # during the world build stage. We build most tools during the bootstrap-tools
621 # phase but symlink host tools that are known to work instead of building them
622 BUILD_WITH_STRICT_TMPPATH:=1
623 .endif
624 .if ${BUILD_WITH_STRICT_TMPPATH} != 0
625 TMPPATH=        ${STRICTTMPPATH}
626 .else
627 TMPPATH=        ${STRICTTMPPATH}:${PATH}
628 .endif
629
630 #
631 # Avoid running mktemp(1) unless actually needed.
632 # It may not be functional, e.g., due to new ABI
633 # when in the middle of installing over this system.
634 #
635 .if make(distributeworld) || make(installworld) || make(stageworld)
636 .if ${BUILD_WITH_STRICT_TMPPATH} != 0
637 MKTEMP=${WORLDTMP}/legacy/usr/bin/mktemp
638 .if !exists(${MKTEMP})
639 .error "mktemp binary doesn't exist in expected location: ${MKTEMP}"
640 .endif
641 .else
642 MKTEMP=mktemp
643 .endif
644 INSTALLTMP!=    ${MKTEMP} -d -u -t install
645 .endif
646
647 .if make(stagekernel) || make(distributekernel)
648 TAGS+=          kernel
649 PACKAGE=        kernel
650 .endif
651
652 #
653 # Building a world goes through the following stages
654 #
655 # 1. legacy stage [BMAKE]
656 #       This stage is responsible for creating compatibility
657 #       shims that are needed by the bootstrap-tools,
658 #       build-tools and cross-tools stages. These are generally
659 #       APIs that tools from one of those three stages need to
660 #       build that aren't present on the host.
661 # 1. bootstrap-tools stage [BMAKE]
662 #       This stage is responsible for creating programs that
663 #       are needed for backward compatibility reasons. They
664 #       are not built as cross-tools.
665 # 2. build-tools stage [TMAKE]
666 #       This stage is responsible for creating the object
667 #       tree and building any tools that are needed during
668 #       the build process. Some programs are listed during
669 #       this phase because they build binaries to generate
670 #       files needed to build these programs. This stage also
671 #       builds the 'build-tools' target rather than 'all'.
672 # 3. cross-tools stage [XMAKE]
673 #       This stage is responsible for creating any tools that
674 #       are needed for building the system. A cross-compiler is one
675 #       of them. This differs from build tools in two ways:
676 #       1. the 'all' target is built rather than 'build-tools'
677 #       2. these tools are installed into TMPPATH for stage 4.
678 # 4. world stage [WMAKE]
679 #       This stage actually builds the world.
680 # 5. install stage (optional) [IMAKE]
681 #       This stage installs a previously built world.
682 #
683
684 BOOTSTRAPPING?= 0
685 # Keep these in sync
686 MINIMUM_SUPPORTED_OSREL?= 1002501
687 MINIMUM_SUPPORTED_REL?= 10.3
688
689 # Common environment for world related stages
690 CROSSENV+=      \
691                 MACHINE_ARCH=${TARGET_ARCH} \
692                 MACHINE=${TARGET} \
693                 CPUTYPE=${TARGET_CPUTYPE}
694 .if ${MK_META_MODE} != "no"
695 # Don't rebuild build-tools targets during normal build.
696 CROSSENV+=      BUILD_TOOLS_META=.NOMETA
697 .endif
698 .if defined(TARGET_CFLAGS)
699 CROSSENV+=      ${TARGET_CFLAGS}
700 .endif
701 .if (${TARGET} != ${MACHINE} && !defined(WITH_LOCAL_MODULES)) || \
702     defined(WITHOUT_LOCAL_MODULES)
703 CROSSENV+=      LOCAL_MODULES=
704 .endif
705
706 BOOTSTRAPPING_OSRELDATE?=${OSRELDATE}
707
708 # bootstrap-tools stage
709 BMAKEENV=       INSTALL="sh ${.CURDIR}/tools/install.sh" \
710                 TOOLS_PREFIX=${TOOLS_PREFIX_UNDEF:U${WORLDTMP}} \
711                 PATH=${BPATH}:${PATH} \
712                 WORLDTMP=${WORLDTMP} \
713                 MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
714 # need to keep this in sync with targets/pseudo/bootstrap-tools/Makefile
715 BSARGS=         DESTDIR= \
716                 OBJTOP='${WORLDTMP}/obj-tools' \
717                 OBJROOT='$${OBJTOP}/' \
718                 MAKEOBJDIRPREFIX= \
719                 BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
720                 BWPHASE=${.TARGET:C,^_,,} \
721                 SSP_CFLAGS= \
722                 MK_HTML=no NO_LINT=yes MK_MAN=no \
723                 -DNO_PIC MK_PROFILE=no -DNO_SHARED \
724                 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
725                 MK_CLANG_EXTRAS=no MK_CLANG_FORMAT=no MK_CLANG_FULL=no \
726                 MK_LLDB=no MK_RETPOLINE=no MK_TESTS=no \
727                 MK_INCLUDES=yes
728
729 BMAKE=          \
730                 ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
731                 ${BSARGS}
732 .if empty(.MAKEOVERRIDES:MMK_LLVM_TARGET_ALL)
733 BMAKE+=         MK_LLVM_TARGET_ALL=no
734 .endif
735
736 # build-tools stage
737 TMAKE=          \
738                 ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
739                 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
740                 DESTDIR= \
741                 BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
742                 BWPHASE=${.TARGET:C,^_,,} \
743                 SSP_CFLAGS= \
744                 -DNO_LINT \
745                 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
746                 MK_CLANG_EXTRAS=no MK_CLANG_FORMAT=no MK_CLANG_FULL=no \
747                 MK_LLDB=no MK_RETPOLINE=no MK_TESTS=no
748
749 # cross-tools stage
750 # TOOLS_PREFIX set in BMAKE
751 XMAKE=          ${BMAKE} \
752                 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
753                 MK_CLANG_IS_CC=${MK_CLANG_BOOTSTRAP} \
754                 MK_GDB=no MK_TESTS=no
755
756 # kernel-tools stage
757 KTMAKEENV=      INSTALL="sh ${.CURDIR}/tools/install.sh" \
758                 PATH=${BPATH}:${PATH} \
759                 WORLDTMP=${WORLDTMP} \
760                 MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
761
762 KTMAKE=         \
763                 TOOLS_PREFIX=${TOOLS_PREFIX_UNDEF:U${WORLDTMP}} \
764                 ${KTMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
765                 DESTDIR= \
766                 OBJTOP='${WORLDTMP}/obj-kernel-tools' \
767                 OBJROOT='$${OBJTOP}/' \
768                 MAKEOBJDIRPREFIX= \
769                 BOOTSTRAPPING=${BOOTSTRAPPING_OSRELDATE} \
770                 SSP_CFLAGS= \
771                 MK_HTML=no -DNO_LINT MK_MAN=no \
772                 -DNO_PIC MK_PROFILE=no -DNO_SHARED \
773                 -DNO_CPU_CFLAGS MK_RETPOLINE=no MK_WARNS=no MK_CTF=no
774
775 # world stage
776 WMAKEENV=       ${CROSSENV} \
777                 INSTALL="${INSTALL_CMD} -U" \
778                 PATH=${TMPPATH} \
779                 SYSROOT=${WORLDTMP}
780
781 # make hierarchy
782 HMAKE=          PATH=${TMPPATH} ${MAKE} LOCAL_MTREE=${LOCAL_MTREE:Q}
783 .if defined(NO_ROOT)
784 HMAKE+=         PATH=${TMPPATH} METALOG=${METALOG} -DNO_ROOT
785 .endif
786
787 CROSSENV+=      CC="${XCC} ${XCFLAGS}" CXX="${XCXX} ${XCXXFLAGS} ${XCFLAGS}" \
788                 CPP="${XCPP} ${XCFLAGS}" \
789                 AS="${XAS}" AR="${XAR}" LD="${XLD}" LLVM_LINK="${XLLVM_LINK}" \
790                 NM=${XNM} OBJCOPY="${XOBJCOPY}" \
791                 RANLIB=${XRANLIB} STRINGS=${XSTRINGS} \
792                 SIZE="${XSIZE}" STRIPBIN="${XSTRIPBIN}"
793
794 .if defined(CROSS_BINUTILS_PREFIX) && exists(${CROSS_BINUTILS_PREFIX})
795 # In the case of xdev-build tools, CROSS_BINUTILS_PREFIX won't be a
796 # directory, but the compiler will look in the right place for its
797 # tools so we don't need to tell it where to look.
798 BFLAGS+=        -B${CROSS_BINUTILS_PREFIX}
799 .endif
800
801
802 # The internal bootstrap compiler has a default sysroot set by TOOLS_PREFIX
803 # and target set by TARGET/TARGET_ARCH.  However, there are several needs to
804 # always pass an explicit --sysroot and -target.
805 # - External compiler needs sysroot and target flags.
806 # - External ld needs sysroot.
807 # - To be clear about the use of a sysroot when using the internal compiler.
808 # - Easier debugging.
809 # - Allowing WITH_SYSTEM_COMPILER+WITH_META_MODE to work together due to
810 #   the flip-flopping build command when sometimes using external and
811 #   sometimes using internal.
812 # - Allow using lld which has no support for default paths.
813 .if !defined(CROSS_BINUTILS_PREFIX) || !exists(${CROSS_BINUTILS_PREFIX})
814 BFLAGS+=        -B${WORLDTMP}/usr/bin
815 .endif
816 .if ${WANT_COMPILER_TYPE} == gcc || \
817     (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
818 .elif ${WANT_COMPILER_TYPE} == clang || \
819     (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == clang)
820 XCFLAGS+=       -target ${TARGET_TRIPLE}
821 .endif
822 XCFLAGS+=       --sysroot=${WORLDTMP}
823
824 .if !empty(BFLAGS)
825 XCFLAGS+=       ${BFLAGS}
826 .endif
827
828 .if ${MK_LIB32} == "yes"
829 _LIBCOMPAT= 32
830 .include "Makefile.libcompat"
831 .elif ${MK_LIBSOFT} == "yes"
832 _LIBCOMPAT= SOFT
833 .include "Makefile.libcompat"
834 .endif
835
836 # META_MODE normally ignores host file changes since every build updates
837 # timestamps (see NO_META_IGNORE_HOST in sys.mk).  There are known times
838 # when the ABI breaks though that we want to force rebuilding WORLDTMP
839 # to get updated host tools.
840 .if ${MK_META_MODE} == "yes" && defined(NO_CLEAN) && \
841     !defined(NO_META_IGNORE_HOST) && !defined(NO_META_IGNORE_HOST_HEADERS) && \
842     !defined(_MKSHOWCONFIG)
843 # r318736 - ino64 major ABI breakage
844 META_MODE_BAD_ABI_VERS+=        1200031
845
846 .if !defined(OBJDIR_HOST_OSRELDATE)
847 .if exists(${OBJTOP}/host-osreldate.h)
848 OBJDIR_HOST_OSRELDATE!= \
849     awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
850     ${OBJTOP}/host-osreldate.h
851 .elif exists(${WORLDTMP}/usr/include/osreldate.h)
852 OBJDIR_HOST_OSRELDATE=  0
853 .endif
854 .export OBJDIR_HOST_OSRELDATE
855 .endif
856
857 # Note that this logic is the opposite of normal BOOTSTRAP handling.  We want
858 # to compare the WORLDTMP's OSRELDATE to the host's OSRELDATE.  If the WORLDTMP
859 # is older than the ABI-breakage OSRELDATE of the HOST then we rebuild.
860 .if defined(OBJDIR_HOST_OSRELDATE)
861 .for _ver in ${META_MODE_BAD_ABI_VERS}
862 .if ${OSRELDATE} >= ${_ver} && ${OBJDIR_HOST_OSRELDATE} < ${_ver}
863 _meta_mode_need_rebuild=        ${_ver}
864 .endif
865 .endfor
866 .if defined(_meta_mode_need_rebuild)
867 .info META_MODE: Rebuilding host tools due to ABI breakage in __FreeBSD_version ${_meta_mode_need_rebuild}.
868 NO_META_IGNORE_HOST_HEADERS=    1
869 .export NO_META_IGNORE_HOST_HEADERS
870 .endif  # defined(_meta_mode_need_rebuild)
871 .endif  # defined(OBJDIR_HOST_OSRELDATE)
872 .endif  # ${MK_META_MODE} == "yes" && defined(NO_CLEAN) ...
873 # This is only used for META_MODE+filemon to track what the oldest
874 # __FreeBSD_version is in WORLDTMP.  This purposely does NOT have
875 # a make dependency on /usr/include/osreldate.h as the file should
876 # only be copied when it is missing or meta mode determines it has changed.
877 # Since host files are normally ignored without NO_META_IGNORE_HOST
878 # the file will never be updated unless that flag is specified.  This
879 # allows tracking the oldest osreldate to force rebuilds via
880 # META_MODE_BADABI_REVS above.
881 host-osreldate.h: # DO NOT ADD /usr/include/osreldate.h here
882 .if !defined(CROSSBUILD_HOST)
883         @cp -f /usr/include/osreldate.h ${.TARGET}
884 .else
885         @echo "#ifndef __FreeBSD_version" > ${.TARGET}
886         @echo "#define __FreeBSD_version ${OSRELDATE}" >> ${.TARGET}
887         @echo "#endif" >> ${.TARGET}
888 .endif
889
890 WMAKE=          ${WMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
891                 BWPHASE=${.TARGET:C,^_,,} \
892                 DESTDIR=${WORLDTMP}
893
894 IMAKEENV=       ${CROSSENV}
895 IMAKE=          ${IMAKEENV} ${MAKE} -f Makefile.inc1 \
896                 ${IMAKE_INSTALL} ${IMAKE_MTREE}
897 .if empty(.MAKEFLAGS:M-n)
898 IMAKEENV+=      PATH=${STRICTTMPPATH}:${INSTALLTMP} \
899                 LD_LIBRARY_PATH=${INSTALLTMP} \
900                 PATH_LOCALE=${INSTALLTMP}/locale
901 IMAKE+=         __MAKE_SHELL=${INSTALLTMP}/sh
902 .else
903 IMAKEENV+=      PATH=${TMPPATH}:${INSTALLTMP}
904 .endif
905
906 # When generating install media, do not allow user and group information from
907 # the build host to affect the contents of the distribution.
908 .if make(distributeworld) || make(distrib-dirs) || make(distribution) || \
909     make(stageworld)
910 DB_FROM_SRC=    yes
911 .endif
912
913 .if defined(DB_FROM_SRC)
914 INSTALLFLAGS+=  -N ${.CURDIR}/etc
915 MTREEFLAGS+=    -N ${.CURDIR}/etc
916 .endif
917 _INSTALL_DDIR=  ${DESTDIR}/${DISTDIR}
918 INSTALL_DDIR=   ${_INSTALL_DDIR:S://:/:g:C:/$::}
919 .if defined(NO_ROOT)
920 METALOG?=       ${DESTDIR}/${DISTDIR}/METALOG
921 METALOG:=       ${METALOG:C,//+,/,g}
922 IMAKE+=         -DNO_ROOT METALOG=${METALOG}
923 INSTALLFLAGS+=  -U -M ${METALOG} -D ${INSTALL_DDIR}
924 MTREEFLAGS+=    -W
925 .endif
926 .if defined(BUILD_PKGS)
927 INSTALLFLAGS+=  -h sha256
928 .endif
929 .if defined(DB_FROM_SRC) || defined(NO_ROOT)
930 IMAKE_INSTALL=  INSTALL="${INSTALL_CMD} ${INSTALLFLAGS}"
931 IMAKE_MTREE=    MTREE_CMD="${MTREE_CMD} ${MTREEFLAGS}"
932 .endif
933
934 DESTDIR_MTREEFLAGS=     -deU
935 # When creating worldtmp we don't need to set the directories as owned by root
936 # so we also pass -W
937 WORLDTMP_MTREEFLAGS=    -deUW
938 .if defined(NO_ROOT)
939 # When building with -DNO_ROOT we shouldn't be changing the directories
940 # that are created by mtree to be owned by root/wheel.
941 DESTDIR_MTREEFLAGS+=    -W
942 .endif
943 DISTR_MTREE=    ${MTREE_CMD}
944 .if ${BUILD_WITH_STRICT_TMPPATH} != 0
945 DISTR_MTREE=    ${WORLDTMP}/legacy/usr/sbin/mtree
946 .endif
947 WORLDTMP_MTREE= ${DISTR_MTREE} ${WORLDTMP_MTREEFLAGS}
948 DESTDIR_MTREE=  ${DISTR_MTREE} ${DESTDIR_MTREEFLAGS}
949
950 # kernel stage
951 KMAKEENV=       ${WMAKEENV:NSYSROOT=*}
952 KMAKE=          ${KMAKEENV} ${MAKE} ${.MAKEFLAGS} ${KERNEL_FLAGS} KERNEL=${INSTKERNNAME}
953
954 #
955 # buildworld
956 #
957 # Attempt to rebuild the entire system, with reasonable chance of
958 # success, regardless of how old your existing system is.
959 #
960 _sanity_check: .PHONY .MAKE
961 .if ${.CURDIR:C/[^,]//g} != ""
962 #       The m4 build of sendmail files doesn't like it if ',' is used
963 #       anywhere in the path of it's files.
964         @echo
965         @echo "*** Error: path to source tree contains a comma ','"
966         @echo
967         @false
968 .elif ${.CURDIR:M*\:*} != ""
969 #       Using ':' leaks into PATH and breaks finding cross-tools.
970         @echo
971         @echo "*** Error: path to source tree contains a colon ':'"
972         @echo
973         @false
974 .endif
975
976 # Our current approach to dependency tracking cannot cope with certain source
977 # tree changes, particularly with respect to removing source files and
978 # replacing generated files.  Handle these cases here in an ad-hoc fashion.
979 _cleanobj_fast_depend_hack: .PHONY
980         @echo ">>> Deleting stale dependencies...";
981         sh ${.CURDIR}/tools/build/depend-cleanup.sh ${OBJTOP}
982 # Date      SVN Rev  Syscalls/Changes
983 # Syscall stubs rewritten in C and obsolete MD assembly implementations
984 # 20191009  r353340  removal of opensolaris_atomic.S (also r353381)
985 .if ${MACHINE} != i386
986 .for f in opensolaris_atomic
987         @if [ -e "${OBJTOP}/cddl/lib/libzpool/.depend.${f}.o" ] && \
988             egrep -qw 'opensolaris_atomic\.S' ${OBJTOP}/cddl/lib/libzpool/.depend.${f}.o; then \
989                 echo "Removing stale dependencies for opensolaris_atomic"; \
990                 rm -f ${OBJTOP}/cddl/lib/libzpool/.depend.${f}.* \
991                    ${LIBCOMPAT:D${LIBCOMPAT_OBJTOP}/cddl/lib/libzpool/.depend.${f}.*}; \
992         fi
993 .endfor
994 .endif
995 # 20190925  r352689  removal of obsolete i386 memchr.S
996 .for f in memchr
997         @if [ -e "${OBJTOP}/lib/libc/.depend.${f}.o" ] && \
998             egrep -qw 'i386/string/memchr\.S' ${OBJTOP}/lib/libc/.depend.${f}.o; then \
999                 echo "Removing stale dependencies for memchr"; \
1000                 rm -f ${OBJTOP}/lib/libc/.depend.${f}.*; \
1001         fi
1002 .if defined(_LIBCOMPAT)
1003         @if [ -e "${LIBCOMPAT_OBJTOP}/lib/libc/.depend.${f}.o" ] && \
1004             egrep -qw 'i386/string/memchr\.S' ${LIBCOMPAT_OBJTOP}/lib/libc/.depend.${f}.o; then \
1005                 echo "Removing stale dependencies for memchr"; \
1006                 rm -f ${LIBCOMPAT_OBJTOP}/lib/libc/.depend.${f}.*; \
1007         fi
1008 .endif
1009 .endfor
1010
1011 _worldtmp: .PHONY
1012         @echo
1013         @echo "--------------------------------------------------------------"
1014         @echo ">>> Rebuilding the temporary build tree"
1015         @echo "--------------------------------------------------------------"
1016 .if !defined(NO_CLEAN)
1017         rm -rf ${WORLDTMP}
1018 .else
1019 # Note: for delete-old we need to set $PATH to also include the host $PATH
1020 # since otherwise a partial build with missing symlinks in ${WORLDTMP}/legacy/
1021 # will fail to run due to missing binaries. $WMAKE sets PATH to only ${TMPPATH}
1022 # so we remove that assingnment from $WMAKE and prepend the new $PATH
1023         ${_+_}@if [ -e "${WORLDTMP}" ]; then \
1024                 echo ">>> Deleting stale files in build tree..."; \
1025                 cd ${.CURDIR}; env PATH=${TMPPATH}:${PATH} ${WMAKE:NPATH=*} \
1026                     _NO_INCLUDE_COMPILERMK=t -DBATCH_DELETE_OLD_FILES delete-old \
1027                     delete-old-libs >/dev/null; \
1028         fi
1029         rm -rf ${WORLDTMP}/legacy/usr/include
1030 .if ${USING_SYSTEM_COMPILER} == "yes"
1031 .for cc in cc c++
1032         if [ -x ${WORLDTMP}/usr/bin/${cc} ]; then \
1033                 inum=$$(stat -f %i ${WORLDTMP}/usr/bin/${cc}); \
1034                 find ${WORLDTMP}/usr/bin -inum $${inum} -delete; \
1035         fi
1036 .endfor
1037 .endif  # ${USING_SYSTEM_COMPILER} == "yes"
1038 .if ${USING_SYSTEM_LINKER} == "yes"
1039         @rm -f ${WORLDTMP}/usr/bin/ld ${WORLDTMP}/usr/bin/ld.lld
1040 .endif  # ${USING_SYSTEM_LINKER} == "yes"
1041 .endif  # !defined(NO_CLEAN)
1042         @mkdir -p ${WORLDTMP}
1043         @touch ${WORLDTMP}/${.TARGET}
1044 # We can't use mtree to create the worldtmp directories since it may not be
1045 # available on the target system (this happens e.g. when building on non-FreeBSD)
1046         cd ${.CURDIR}/tools/build; \
1047             ${MAKE} DIRPRFX=tools/build/ DESTDIR=${WORLDTMP}/legacy installdirs
1048 # In order to build without inheriting $PATH we need to add symlinks to the host
1049 # tools in $WORLDTMP for the tools that we don't build during bootstrap-tools
1050         cd ${.CURDIR}/tools/build; \
1051             ${MAKE} DIRPRFX=tools/build/ DESTDIR=${WORLDTMP}/legacy host-symlinks
1052
1053 _legacy:
1054         @echo
1055         @echo "--------------------------------------------------------------"
1056         @echo ">>> stage 1.1: legacy release compatibility shims"
1057         @echo "--------------------------------------------------------------"
1058         ${_+_}cd ${.CURDIR}; ${BMAKE} legacy
1059 _bootstrap-tools:
1060         @echo
1061         @echo "--------------------------------------------------------------"
1062         @echo ">>> stage 1.2: bootstrap tools"
1063         @echo "--------------------------------------------------------------"
1064         ${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
1065         mkdir -p ${WORLDTMP}/usr ${WORLDTMP}/lib/casper ${WORLDTMP}/lib/geom \
1066             ${WORLDTMP}/bin
1067         ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1068             -p ${WORLDTMP}/usr >/dev/null
1069         ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1070             -p ${WORLDTMP}/usr/include >/dev/null
1071         ln -sf ${.CURDIR}/sys ${WORLDTMP}
1072 .if ${MK_DEBUG_FILES} != "no"
1073         ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
1074             -p ${WORLDTMP}/usr/lib >/dev/null
1075 .endif
1076 .for _mtree in ${LOCAL_MTREE}
1077         ${WORLDTMP_MTREE} -f ${.CURDIR}/${_mtree} -p ${WORLDTMP} > /dev/null
1078 .endfor
1079 _cleanobj:
1080 .if !defined(NO_CLEAN)
1081         @echo
1082         @echo "--------------------------------------------------------------"
1083         @echo ">>> stage 2.1: cleaning up the object tree"
1084         @echo "--------------------------------------------------------------"
1085         # Avoid including bsd.compiler.mk in clean and obj with _NO_INCLUDE_COMPILERMK
1086         # since the restricted $PATH might not contain a valid cc binary
1087         ${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t ${CLEANDIR}
1088 .if defined(_LIBCOMPAT)
1089         ${_+_}cd ${.CURDIR}; ${LIBCOMPATWMAKE} _NO_INCLUDE_COMPILERMK=t -f Makefile.inc1 ${CLEANDIR}
1090 .endif
1091 .else
1092         ${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t _cleanobj_fast_depend_hack
1093 .endif  # !defined(NO_CLEAN)
1094 _obj:
1095         @echo
1096         @echo "--------------------------------------------------------------"
1097         @echo ">>> stage 2.2: rebuilding the object tree"
1098         @echo "--------------------------------------------------------------"
1099         ${_+_}cd ${.CURDIR}; ${WMAKE} _NO_INCLUDE_COMPILERMK=t obj
1100 _build-tools:
1101         @echo
1102         @echo "--------------------------------------------------------------"
1103         @echo ">>> stage 2.3: build tools"
1104         @echo "--------------------------------------------------------------"
1105         ${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
1106 _cross-tools:
1107         @echo
1108         @echo "--------------------------------------------------------------"
1109         @echo ">>> stage 3: cross tools"
1110         @echo "--------------------------------------------------------------"
1111         @rm -f ${OBJTOP}/toolchain-metadata.mk
1112         ${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
1113         ${_+_}cd ${.CURDIR}; ${XMAKE} kernel-tools
1114 _build-metadata:
1115         @echo
1116         @echo "--------------------------------------------------------------"
1117         @echo ">>> stage 3.1: recording build metadata"
1118         @echo "--------------------------------------------------------------"
1119         ${_+_}cd ${.CURDIR}; ${WMAKE} toolchain-metadata.mk
1120         ${_+_}cd ${.CURDIR}; ${WMAKE} host-osreldate.h
1121 _includes:
1122         @echo
1123         @echo "--------------------------------------------------------------"
1124         @echo ">>> stage 4.1: building includes"
1125         @echo "--------------------------------------------------------------"
1126 # Special handling for SUBDIR_OVERRIDE in buildworld as they most likely need
1127 # headers from default SUBDIR.  Do SUBDIR_OVERRIDE includes last.
1128         ${_+_}cd ${.CURDIR}; ${WMAKE} SUBDIR_OVERRIDE= SHARED=symlinks \
1129             MK_INCLUDES=yes includes
1130 .if !empty(SUBDIR_OVERRIDE) && make(buildworld)
1131         ${_+_}cd ${.CURDIR}; ${WMAKE} MK_INCLUDES=yes SHARED=symlinks includes
1132 .endif
1133 _libraries:
1134         @echo
1135         @echo "--------------------------------------------------------------"
1136         @echo ">>> stage 4.2: building libraries"
1137         @echo "--------------------------------------------------------------"
1138         ${_+_}cd ${.CURDIR}; \
1139             ${WMAKE} -DNO_FSCHG MK_HTML=no -DNO_LINT MK_MAN=no \
1140             MK_PROFILE=no MK_TESTS=no MK_TESTS_SUPPORT=${MK_TESTS_SUPPORT} \
1141             libraries
1142 everything: .PHONY
1143         @echo
1144         @echo "--------------------------------------------------------------"
1145         @echo ">>> stage 4.4: building everything"
1146         @echo "--------------------------------------------------------------"
1147         ${_+_}cd ${.CURDIR}; _PARALLEL_SUBDIR_OK=1 ${WMAKE} all
1148
1149 WMAKE_TGTS=
1150 .if !defined(WORLDFAST)
1151 WMAKE_TGTS+=    _sanity_check _worldtmp _legacy
1152 .if empty(SUBDIR_OVERRIDE)
1153 WMAKE_TGTS+=    _bootstrap-tools
1154 .endif
1155 WMAKE_TGTS+=    _cleanobj
1156 .if !defined(NO_OBJWALK)
1157 WMAKE_TGTS+=    _obj
1158 .endif
1159 WMAKE_TGTS+=    _build-tools _cross-tools
1160 WMAKE_TGTS+=    _build-metadata
1161 WMAKE_TGTS+=    _includes
1162 .endif
1163 .if !defined(NO_LIBS)
1164 WMAKE_TGTS+=    _libraries
1165 .endif
1166 .if defined(_LIBCOMPAT) && empty(SUBDIR_OVERRIDE)
1167 WMAKE_TGTS+=    build${libcompat}
1168 .endif
1169 WMAKE_TGTS+=    everything
1170
1171 # record buildworld time in seconds
1172 .if make(buildworld)
1173 _BUILDWORLD_START!= date '+%s'
1174 .export _BUILDWORLD_START
1175 .endif
1176
1177 buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue .PHONY
1178 .ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
1179
1180 _ncpu_cmd=sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo unknown
1181
1182 buildworld_prologue: .PHONY
1183         @echo "--------------------------------------------------------------"
1184         @echo ">>> World build started on `LC_ALL=C date`"
1185         @echo "--------------------------------------------------------------"
1186
1187 buildworld_epilogue: .PHONY
1188         @echo
1189         @echo "--------------------------------------------------------------"
1190         @echo ">>> World build completed on `LC_ALL=C date`"
1191         @seconds=$$(($$(date '+%s') - ${_BUILDWORLD_START})); \
1192           echo -n ">>> World built in $$seconds seconds, "; \
1193           echo "ncpu: $$(${_ncpu_cmd})${.MAKE.JOBS:S/^/, make -j/}"
1194         @echo "--------------------------------------------------------------"
1195
1196 #
1197 # We need to have this as a target because the indirection between Makefile
1198 # and Makefile.inc1 causes the correct PATH to be used, rather than a
1199 # modification of the current environment's PATH.  In addition, we need
1200 # to quote multiword values.
1201 #
1202 buildenvvars: .PHONY
1203         @echo ${WMAKEENV:Q} ${.MAKE.EXPORTED:@v@$v=\"${$v}\"@}
1204
1205 .if ${.TARGETS:Mbuildenv}
1206 .if ${.MAKEFLAGS:M-j}
1207 .error The buildenv target is incompatible with -j
1208 .endif
1209 .endif
1210 BUILDENV_DIR?=  ${.CURDIR}
1211 #
1212 # Note: make will report any errors the shell reports. This can
1213 # be odd if the last command in an interactive shell generates an
1214 # error or is terminated by SIGINT. These reported errors look bad,
1215 # but are harmless. Allowing them also allows BUIDLENV_SHELL to
1216 # be a complex command whose status will be returned to the caller.
1217 # Some scripts in tools rely on this behavior to report build errors.
1218 #
1219 buildenv: .PHONY
1220         @echo Entering world for ${TARGET_ARCH}:${TARGET}
1221 .if ${BUILDENV_SHELL:M*zsh*}
1222         @echo For ZSH you must run: export CPUTYPE=${TARGET_CPUTYPE}
1223 .endif
1224         @cd ${BUILDENV_DIR} && env ${WMAKEENV} \
1225         INSTALL="${INSTALL_CMD} ${INSTALLFLAGS}" \
1226         MTREE_CMD="${MTREE_CMD} ${MTREEFLAGS}" BUILDENV=1 ${BUILDENV_SHELL}
1227
1228 TOOLCHAIN_TGTS= ${WMAKE_TGTS:Neverything:Nbuild${libcompat}}
1229 toolchain: ${TOOLCHAIN_TGTS} .PHONY
1230 KERNEL_TOOLCHAIN_TGTS=  ${TOOLCHAIN_TGTS:N_obj:N_cleanobj:N_includes:N_libraries}
1231 .if make(kernel-toolchain)
1232 .ORDER: ${KERNEL_TOOLCHAIN_TGTS}
1233 .endif
1234 kernel-toolchain: ${KERNEL_TOOLCHAIN_TGTS} .PHONY
1235
1236 #
1237 # installcheck
1238 #
1239 # Checks to be sure system is ready for installworld/installkernel.
1240 #
1241 installcheck: _installcheck_world _installcheck_kernel .PHONY
1242 _installcheck_world: .PHONY
1243         @echo "--------------------------------------------------------------"
1244         @echo ">>> Install check world"
1245         @echo "--------------------------------------------------------------"
1246 _installcheck_kernel: .PHONY
1247         @echo "--------------------------------------------------------------"
1248         @echo ">>> Install check kernel"
1249         @echo "--------------------------------------------------------------"
1250
1251 #
1252 # Require DESTDIR to be set if installing for a different architecture or
1253 # using the user/group database in the source tree.
1254 #
1255 .if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} || \
1256     defined(DB_FROM_SRC)
1257 .if !make(distributeworld)
1258 _installcheck_world: __installcheck_DESTDIR
1259 _installcheck_kernel: __installcheck_DESTDIR
1260 __installcheck_DESTDIR: .PHONY
1261 .if !defined(DESTDIR) || empty(DESTDIR)
1262         @echo "ERROR: Please set DESTDIR!"; \
1263         false
1264 .endif
1265 .endif
1266 .endif
1267
1268 .if !defined(DB_FROM_SRC)
1269 #
1270 # Check for missing UIDs/GIDs.
1271 #
1272 CHECK_UIDS=     auditdistd
1273 CHECK_GIDS=     audit
1274 CHECK_UIDS+=    ntpd
1275 CHECK_GIDS+=    ntpd
1276 CHECK_UIDS+=    proxy
1277 CHECK_GIDS+=    proxy authpf
1278 CHECK_UIDS+=    smmsp
1279 CHECK_GIDS+=    smmsp
1280 CHECK_UIDS+=    unbound
1281 CHECK_GIDS+=    unbound
1282 _installcheck_world: __installcheck_UGID
1283 __installcheck_UGID: .PHONY
1284 .for uid in ${CHECK_UIDS}
1285         @if ! `id -u ${uid} >/dev/null 2>&1`; then \
1286                 echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
1287                 false; \
1288         fi
1289 .endfor
1290 .for gid in ${CHECK_GIDS}
1291         @if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
1292                 echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
1293                 false; \
1294         fi
1295 .endfor
1296 .endif
1297 #
1298 # If installing over the running system (DESTDIR is / or unset) and the install
1299 # includes rescue, try running rescue from the objdir as a sanity check.  If
1300 # rescue is not functional (e.g., because it depends on a system call not
1301 # supported by the currently running kernel), abort the installation.
1302 #
1303 .if !make(distributeworld) && ${MK_RESCUE} != "no" && \
1304     (empty(DESTDIR) || ${DESTDIR} == "/") && empty(BYPASS_INSTALLCHECK_SH)
1305 _installcheck_world: __installcheck_sh_check
1306 __installcheck_sh_check: .PHONY
1307         @if [ "`${OBJTOP}/rescue/rescue/rescue sh -c 'echo OK'`" != \
1308             OK ]; then \
1309                 echo "rescue/sh check failed, installation aborted" >&2; \
1310                 false; \
1311         fi
1312 .endif
1313
1314 #
1315 # Required install tools to be saved in a scratch dir for safety.
1316 #
1317 .if ${MK_ZONEINFO} != "no"
1318 _zoneinfo=      zic tzsetup
1319 .endif
1320
1321 .if !defined(CROSSBUILD_HOST)
1322 _sysctl=sysctl
1323 .endif
1324
1325 ITOOLS= [ awk cap_mkdb cat chflags chmod chown cmp cp \
1326         date echo egrep find grep id install ${_install-info} \
1327         ln make mkdir mtree mv pwd_mkdb \
1328         rm sed services_mkdb sh sort strip ${_sysctl} test true uname wc \
1329         ${_zoneinfo} ${LOCAL_ITOOLS}
1330
1331 # Needed for share/man
1332 .if ${MK_MAN_UTILS} != "no"
1333 ITOOLS+=makewhatis
1334 .endif
1335
1336 #
1337 # distributeworld
1338 #
1339 # Distributes everything compiled by a `buildworld'.
1340 #
1341 # installworld
1342 #
1343 # Installs everything compiled by a 'buildworld'.
1344 #
1345
1346 # Non-base distributions produced by the base system
1347 EXTRA_DISTRIBUTIONS=
1348 .if defined(_LIBCOMPAT)
1349 EXTRA_DISTRIBUTIONS+=   lib${libcompat}
1350 .endif
1351 .if ${MK_TESTS} != "no"
1352 EXTRA_DISTRIBUTIONS+=   tests
1353 .endif
1354
1355 DEBUG_DISTRIBUTIONS=
1356 .if ${MK_DEBUG_FILES} != "no"
1357 DEBUG_DISTRIBUTIONS+=   base ${EXTRA_DISTRIBUTIONS:S,tests,,}
1358 .endif
1359
1360 MTREE_MAGIC?=   mtree 2.0
1361
1362 distributeworld installworld stageworld: _installcheck_world .PHONY
1363         mkdir -p ${INSTALLTMP}
1364         progs=$$(for prog in ${ITOOLS}; do \
1365                 if progpath=`env PATH=${TMPPATH} which $$prog`; then \
1366                         echo $$progpath; \
1367                 else \
1368                         echo "Required tool $$prog not found in PATH ($$PATH)." >&2; \
1369                         exit 1; \
1370                 fi; \
1371             done); \
1372         if [ -z "${CROSSBUILD_HOST}" ] ; then \
1373                 libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
1374                     while read line; do \
1375                         set -- $$line; \
1376                         if [ "$$2 $$3" != "not found" ]; then \
1377                                 echo $$2; \
1378                         else \
1379                                 echo "Required library $$1 not found." >&2; \
1380                                 exit 1; \
1381                         fi; \
1382                     done); \
1383         fi; \
1384         cp $$libs $$progs ${INSTALLTMP}
1385         cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
1386 .if defined(NO_ROOT)
1387         -mkdir -p ${METALOG:H}
1388         echo "#${MTREE_MAGIC}" > ${METALOG}
1389 .endif
1390 .if make(distributeworld)
1391 .for dist in ${EXTRA_DISTRIBUTIONS}
1392         -mkdir ${DESTDIR}/${DISTDIR}/${dist}
1393         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.root.dist \
1394             -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null
1395         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1396             -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
1397         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1398             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
1399 .if ${MK_DEBUG_FILES} != "no"
1400         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
1401             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib >/dev/null
1402 .endif
1403 .if defined(_LIBCOMPAT)
1404         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
1405             -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
1406 .if ${MK_DEBUG_FILES} != "no"
1407         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
1408             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/usr >/dev/null
1409 .endif
1410 .endif
1411 .if ${MK_TESTS} != "no" && ${dist} == "tests"
1412         -mkdir -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE}
1413         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
1414             -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE} >/dev/null
1415 .if ${MK_DEBUG_FILES} != "no"
1416         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
1417             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/${TESTSBASE} >/dev/null
1418 .endif
1419 .endif
1420 .if defined(NO_ROOT)
1421         ${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
1422             sed -e 's#^\./#./${dist}/#' >> ${METALOG}
1423         ${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
1424             sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
1425         ${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
1426             sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
1427 .if defined(_LIBCOMPAT)
1428         ${IMAKEENV} ${DISTR_MTREE} -C -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist | \
1429             sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
1430 .endif
1431 .endif
1432 .endfor
1433         -mkdir ${DESTDIR}/${DISTDIR}/base
1434         ${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
1435             METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
1436             DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
1437             LOCAL_MTREE=${LOCAL_MTREE:Q} distrib-dirs
1438         ${INSTALL_SYMLINK} ${INSTALLFLAGS} usr/src/sys ${INSTALL_DDIR}/base/sys
1439 .endif # make(distributeworld)
1440         ${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
1441             ${IMAKEENV} rm -rf ${INSTALLTMP}
1442 .if make(distributeworld)
1443 .for dist in ${EXTRA_DISTRIBUTIONS}
1444         find ${DESTDIR}/${DISTDIR}/${dist} -mindepth 1 -type d -empty -delete
1445 .endfor
1446 .if defined(NO_ROOT)
1447 .for dist in base ${EXTRA_DISTRIBUTIONS}
1448         @# For each file that exists in this dist, print the corresponding
1449         @# line from the METALOG.  This relies on the fact that
1450         @# a line containing only the filename will sort immediately before
1451         @# the relevant mtree line.
1452         cd ${DESTDIR}/${DISTDIR}; \
1453         find ./${dist} | sort -u ${METALOG} - | \
1454         awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
1455         ${DESTDIR}/${DISTDIR}/${dist}.meta
1456 .endfor
1457 .for dist in ${DEBUG_DISTRIBUTIONS}
1458         @# For each file that exists in this dist, print the corresponding
1459         @# line from the METALOG.  This relies on the fact that
1460         @# a line containing only the filename will sort immediately before
1461         @# the relevant mtree line.
1462         cd ${DESTDIR}/${DISTDIR}; \
1463         find ./${dist}/usr/lib/debug | sort -u ${METALOG} - | \
1464         awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
1465         ${DESTDIR}/${DISTDIR}/${dist}.debug.meta
1466 .endfor
1467 .endif
1468 .endif # make(distributeworld)
1469
1470 packageworld: .PHONY
1471 .for dist in base ${EXTRA_DISTRIBUTIONS}
1472 .if defined(NO_ROOT)
1473         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1474             tar cvf - --exclude usr/lib/debug \
1475             @${DESTDIR}/${DISTDIR}/${dist}.meta | \
1476             ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
1477 .else
1478         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1479             tar cvf - --exclude usr/lib/debug . | \
1480             ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
1481 .endif
1482 .endfor
1483
1484 .for dist in ${DEBUG_DISTRIBUTIONS}
1485 . if defined(NO_ROOT)
1486         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1487             tar cvf - @${DESTDIR}/${DISTDIR}/${dist}.debug.meta | \
1488             ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
1489 . else
1490         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
1491             tar cvLf - usr/lib/debug | \
1492             ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
1493 . endif
1494 .endfor
1495
1496 makeman: .PHONY
1497         ${_+_}cd ${.CURDIR}/tools/build/options; sh makeman > \
1498             ${.CURDIR}/share/man/man5/src.conf.5
1499
1500 # We can't assume here that ${TMPPATH} will include ${PATH} or /usr/libexec
1501 # because we may be building with a STRICTTMPPATH, so we explicitly include
1502 # /usr/libexec here for flua.  ${TMPPATH} still usefully includes anything else
1503 # we may need to function.
1504 _sysent_PATH=   ${TMPPATH}:/usr/libexec
1505 _sysent_dirs=   sys/kern
1506 _sysent_dirs+=  sys/compat/freebsd32
1507 _sysent_dirs+=  sys/compat/cloudabi32   \
1508                 sys/compat/cloudabi64
1509 _sysent_dirs+=  sys/amd64/linux         \
1510                 sys/amd64/linux32       \
1511                 sys/arm/linux           \
1512                 sys/arm64/linux         \
1513                 sys/i386/linux
1514 sysent: .PHONY
1515 .for _dir in ${_sysent_dirs}
1516         @echo "${MAKE} -C ${.CURDIR}/${_dir} sysent"
1517         ${_+_}@env PATH=${_sysent_PATH} ${MAKE} -C ${.CURDIR}/${_dir} sysent
1518 .endfor
1519
1520 #
1521 # reinstall
1522 #
1523 # If you have a build server, you can NFS mount the source and obj directories
1524 # and do a 'make reinstall' on the *client* to install new binaries from the
1525 # most recent server build.
1526 #
1527 restage reinstall: .MAKE .PHONY
1528         @echo "--------------------------------------------------------------"
1529         @echo ">>> Making hierarchy"
1530         @echo "--------------------------------------------------------------"
1531         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
1532             LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy
1533 .if make(restage)
1534         @echo "--------------------------------------------------------------"
1535         @echo ">>> Making distribution"
1536         @echo "--------------------------------------------------------------"
1537         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
1538             LOCAL_MTREE=${LOCAL_MTREE:Q} distribution
1539 .endif
1540         @echo
1541         @echo "--------------------------------------------------------------"
1542         @echo ">>> Installing everything started on `LC_ALL=C date`"
1543         @echo "--------------------------------------------------------------"
1544         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
1545 .if defined(_LIBCOMPAT)
1546         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install${libcompat}
1547 .endif
1548         @echo "--------------------------------------------------------------"
1549         @echo ">>> Installing everything completed on `LC_ALL=C date`"
1550         @echo "--------------------------------------------------------------"
1551
1552 redistribute: .MAKE .PHONY
1553         @echo "--------------------------------------------------------------"
1554         @echo ">>> Distributing everything"
1555         @echo "--------------------------------------------------------------"
1556         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
1557 .if defined(_LIBCOMPAT)
1558         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute${libcompat} \
1559             DISTRIBUTION=lib${libcompat}
1560 .endif
1561
1562 distrib-dirs distribution: .MAKE .PHONY
1563         ${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
1564             ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
1565 .if make(distribution)
1566         ${_+_}cd ${.CURDIR}; ${CROSSENV} PATH=${TMPPATH} \
1567                 ${MAKE} -f Makefile.inc1 ${IMAKE_INSTALL} \
1568                 METALOG=${METALOG} MK_TESTS=no \
1569                 MK_TESTS_SUPPORT=${MK_TESTS_SUPPORT} installconfig
1570 .endif
1571
1572 #
1573 # buildkernel and installkernel
1574 #
1575 # Which kernels to build and/or install is specified by setting
1576 # KERNCONF. If not defined a GENERIC kernel is built/installed.
1577 # Only the existing (depending TARGET) config files are used
1578 # for building kernels and only the first of these is designated
1579 # as the one being installed.
1580 #
1581 # Note that we have to use TARGET instead of TARGET_ARCH when
1582 # we're in kernel-land. Since only TARGET_ARCH is (expected) to
1583 # be set to cross-build, we have to make sure TARGET is set
1584 # properly.
1585
1586 .if defined(KERNFAST)
1587 NO_KERNELCLEAN= t
1588 NO_KERNELCONFIG=        t
1589 NO_KERNELOBJ=           t
1590 # Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
1591 .if !defined(KERNCONF) && ${KERNFAST} != "1"
1592 KERNCONF=${KERNFAST}
1593 .endif
1594 .endif
1595 .if ${TARGET_ARCH} == "powerpc64"
1596 KERNCONF?=      GENERIC64
1597 .else
1598 KERNCONF?=      GENERIC
1599 .endif
1600 INSTKERNNAME?=  kernel
1601
1602 KERNSRCDIR?=    ${.CURDIR}/sys
1603 KRNLCONFDIR=    ${KERNSRCDIR}/${TARGET}/conf
1604 KRNLOBJDIR=     ${OBJTOP}${KERNSRCDIR:C,^${.CURDIR},,}
1605 KERNCONFDIR?=   ${KRNLCONFDIR}
1606
1607 BUILDKERNELS=
1608 INSTALLKERNEL=
1609 .if defined(NO_INSTALLKERNEL)
1610 # All of the BUILDKERNELS loops start at index 1.
1611 BUILDKERNELS+= dummy
1612 .endif
1613 .for _kernel in ${KERNCONF}
1614 .if !defined(_MKSHOWCONFIG) && exists(${KERNCONFDIR}/${_kernel})
1615 BUILDKERNELS+=  ${_kernel}
1616 .if empty(INSTALLKERNEL) && !defined(NO_INSTALLKERNEL)
1617 INSTALLKERNEL= ${_kernel}
1618 .endif
1619 .else
1620 .if make(buildkernel)
1621 .error Missing KERNCONF ${KERNCONFDIR}/${_kernel}
1622 .endif
1623 .endif
1624 .endfor
1625
1626 _cleankernobj_fast_depend_hack: .PHONY
1627 # 20191009  r353340  removal of opensolaris_atomic.S (also r353381)
1628 .if ${MACHINE} != i386
1629 .for f in opensolaris_atomic
1630 .for m in opensolaris zfs
1631         @if [ -e "${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.o" ] && \
1632             grep -q ${f}.S "${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.o"; then \
1633                 echo "Removing stale dependencies for opensolaris_atomic"; \
1634                 rm -f ${KRNLOBJDIR}/${KERNCONF}/modules${SRCTOP}/sys/modules/${m}/.depend.${f}.*; \
1635         fi
1636 .endfor
1637 .endfor
1638 .endif
1639
1640 ${WMAKE_TGTS:N_worldtmp:Nbuild${libcompat}} ${.ALLTARGETS:M_*:N_worldtmp}: .MAKE .PHONY
1641
1642 # record kernel(s) build time in seconds
1643 .if make(buildkernel)
1644 _BUILDKERNEL_START!= date '+%s'
1645 .endif
1646
1647 #
1648 # buildkernel
1649 #
1650 # Builds all kernels defined by BUILDKERNELS.
1651 #
1652 buildkernel: .MAKE .PHONY
1653 .if empty(BUILDKERNELS:Ndummy)
1654         @echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
1655         false
1656 .endif
1657         @echo
1658 .for _kernel in ${BUILDKERNELS:Ndummy}
1659         @echo "--------------------------------------------------------------"
1660         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
1661         @echo "--------------------------------------------------------------"
1662         @echo "===> ${_kernel}"
1663         mkdir -p ${KRNLOBJDIR}
1664 .if !defined(NO_KERNELCONFIG)
1665         @echo
1666         @echo "--------------------------------------------------------------"
1667         @echo ">>> stage 1: configuring the kernel"
1668         @echo "--------------------------------------------------------------"
1669         cd ${KRNLCONFDIR}; \
1670                 PATH=${TMPPATH} \
1671                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
1672                         -I '${KERNCONFDIR}' -I '${KRNLCONFDIR}' \
1673                         '${KERNCONFDIR}/${_kernel}'
1674 .endif
1675 .if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
1676         @echo
1677         @echo "--------------------------------------------------------------"
1678         @echo ">>> stage 2.1: cleaning up the object tree"
1679         @echo "--------------------------------------------------------------"
1680         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
1681 .else
1682         ${_+_}cd ${.CURDIR}; ${WMAKE} _cleankernobj_fast_depend_hack
1683 .endif
1684 .if !defined(NO_KERNELOBJ)
1685         @echo
1686         @echo "--------------------------------------------------------------"
1687         @echo ">>> stage 2.2: rebuilding the object tree"
1688         @echo "--------------------------------------------------------------"
1689         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
1690 .endif
1691         @echo
1692         @echo "--------------------------------------------------------------"
1693         @echo ">>> stage 2.3: build tools"
1694         @echo "--------------------------------------------------------------"
1695         ${_+_}cd ${.CURDIR}; ${KTMAKE} kernel-tools
1696         @echo
1697         @echo "--------------------------------------------------------------"
1698         @echo ">>> stage 3.1: building everything"
1699         @echo "--------------------------------------------------------------"
1700         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
1701         @echo "--------------------------------------------------------------"
1702         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
1703         @echo "--------------------------------------------------------------"
1704
1705 .endfor
1706         @seconds=$$(($$(date '+%s') - ${_BUILDKERNEL_START})); \
1707           echo -n ">>> Kernel(s) ${BUILDKERNELS} built in $$seconds seconds, "; \
1708           echo "ncpu: $$(${_ncpu_cmd})${.MAKE.JOBS:S/^/, make -j/}"
1709         @echo "--------------------------------------------------------------"
1710
1711 NO_INSTALLEXTRAKERNELS?=        yes
1712
1713 #
1714 # installkernel, etc.
1715 #
1716 # Install the kernel defined by INSTALLKERNEL
1717 #
1718 installkernel installkernel.debug \
1719 reinstallkernel reinstallkernel.debug: _installcheck_kernel .PHONY
1720 .if !defined(NO_INSTALLKERNEL)
1721 .if empty(INSTALLKERNEL)
1722         @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1723         false
1724 .endif
1725         @echo "--------------------------------------------------------------"
1726         @echo ">>> Installing kernel ${INSTALLKERNEL} on $$(LC_ALL=C date)"
1727         @echo "--------------------------------------------------------------"
1728         ${_+_}cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1729             ${CROSSENV} PATH=${TMPPATH} \
1730             ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
1731         @echo "--------------------------------------------------------------"
1732         @echo ">>> Installing kernel ${INSTALLKERNEL} completed on $$(LC_ALL=C date)"
1733         @echo "--------------------------------------------------------------"
1734 .endif
1735 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1736 .for _kernel in ${BUILDKERNELS:[2..-1]}
1737         @echo "--------------------------------------------------------------"
1738         @echo ">>> Installing kernel ${_kernel} $$(LC_ALL=C date)"
1739         @echo "--------------------------------------------------------------"
1740         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; \
1741             ${CROSSENV} PATH=${TMPPATH} \
1742             ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME}.${_kernel} ${.TARGET:S/kernel//}
1743         @echo "--------------------------------------------------------------"
1744         @echo ">>> Installing kernel ${_kernel} completed on $$(LC_ALL=C date)"
1745         @echo "--------------------------------------------------------------"
1746 .endfor
1747 .endif
1748
1749 distributekernel distributekernel.debug: .PHONY
1750 .if !defined(NO_INSTALLKERNEL)
1751 .if empty(INSTALLKERNEL)
1752         @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1753         false
1754 .endif
1755         mkdir -p ${DESTDIR}/${DISTDIR}
1756 .if defined(NO_ROOT)
1757         @echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta
1758 .endif
1759         ${_+_}cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1760             ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.premeta/} \
1761             ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \
1762             DESTDIR=${INSTALL_DDIR}/kernel \
1763             ${.TARGET:S/distributekernel/install/}
1764 .if defined(NO_ROOT)
1765         @sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
1766             ${DESTDIR}/${DISTDIR}/kernel.meta
1767 .endif
1768 .endif
1769 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1770 .for _kernel in ${BUILDKERNELS:[2..-1]}
1771 .if defined(NO_ROOT)
1772         @echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
1773 .endif
1774         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; \
1775             ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.${_kernel}.premeta/} \
1776             ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} \
1777             KERNEL=${INSTKERNNAME}.${_kernel} \
1778             DESTDIR=${INSTALL_DDIR}/kernel.${_kernel} \
1779             ${.TARGET:S/distributekernel/install/}
1780 .if defined(NO_ROOT)
1781         @sed -e "s|^./kernel.${_kernel}|.|" \
1782             ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta > \
1783             ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
1784 .endif
1785 .endfor
1786 .endif
1787
1788 packagekernel: .PHONY
1789 .if defined(NO_ROOT)
1790 .if !defined(NO_INSTALLKERNEL)
1791         cd ${DESTDIR}/${DISTDIR}/kernel; \
1792             tar cvf - --exclude '*.debug' \
1793             @${DESTDIR}/${DISTDIR}/kernel.meta | \
1794             ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1795 .endif
1796 .if ${MK_DEBUG_FILES} != "no"
1797         cd ${DESTDIR}/${DISTDIR}/kernel; \
1798             tar cvf - --include '*/*/*.debug' \
1799             @${DESTDIR}/${DISTDIR}/kernel.meta | \
1800             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1801 .endif
1802 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1803 .for _kernel in ${BUILDKERNELS:[2..-1]}
1804         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1805             tar cvf - --exclude '*.debug' \
1806             @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1807             ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1808 .if ${MK_DEBUG_FILES} != "no"
1809         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1810             tar cvf - --include '*/*/*.debug' \
1811             @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1812             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1813 .endif
1814 .endfor
1815 .endif
1816 .else
1817 .if !defined(NO_INSTALLKERNEL)
1818         cd ${DESTDIR}/${DISTDIR}/kernel; \
1819             tar cvf - --exclude '*.debug' . | \
1820             ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1821 .endif
1822 .if ${MK_DEBUG_FILES} != "no"
1823         cd ${DESTDIR}/${DISTDIR}/kernel; \
1824             tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1825             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1826 .endif
1827 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1828 .for _kernel in ${BUILDKERNELS:[2..-1]}
1829         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1830             tar cvf - --exclude '*.debug' . | \
1831             ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1832 .if ${MK_DEBUG_FILES} != "no"
1833         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1834             tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1835             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1836 .endif
1837 .endfor
1838 .endif
1839 .endif
1840
1841 stagekernel: .PHONY
1842         ${_+_}${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} distributekernel
1843
1844 PORTSDIR?=      /usr/ports
1845 WSTAGEDIR?=     ${OBJTOP}/worldstage
1846 KSTAGEDIR?=     ${OBJTOP}/kernelstage
1847 REPODIR?=       ${OBJROOT}repo
1848 PKG_FORMAT?=    txz
1849 PKGSIGNKEY?=    # empty
1850 PKG_OUTPUT_DIR?=        ${PKG_VERSION}
1851
1852 .ORDER:         stage-packages create-packages
1853 .ORDER:         create-packages create-world-packages
1854 .ORDER:         create-packages create-kernel-packages
1855 .ORDER:         create-packages sign-packages
1856
1857 _pkgbootstrap: .PHONY
1858 .if make(*package*) && !exists(${LOCALBASE}/sbin/pkg)
1859         @env ASSUME_ALWAYS_YES=YES pkg bootstrap
1860 .endif
1861
1862 packages: .PHONY
1863         ${_+_}${MAKE} -C ${.CURDIR} PKG_VERSION=${PKG_VERSION} real-packages
1864
1865 package-pkg: .PHONY
1866         rm -rf /tmp/ports.${TARGET} || :
1867         env ${WMAKEENV:Q} SRCDIR=${.CURDIR} PORTSDIR=${PORTSDIR} REVISION=${_REVISION} \
1868                 PKG_CMD=${PKG_CMD} PKG_VERSION=${PKG_VERSION} REPODIR=${REPODIR} \
1869                 WSTAGEDIR=${WSTAGEDIR} \
1870                 sh ${.CURDIR}/release/scripts/make-pkg-package.sh
1871
1872 real-packages:  stage-packages create-packages sign-packages .PHONY
1873
1874 stage-packages-world: .PHONY
1875         @mkdir -p ${WSTAGEDIR}
1876         ${_+_}@cd ${.CURDIR}; \
1877                 ${MAKE} DESTDIR=${WSTAGEDIR} -DNO_ROOT stageworld
1878
1879 stage-packages-kernel: .PHONY
1880         @mkdir -p ${KSTAGEDIR}
1881         ${_+_}@cd ${.CURDIR}; \
1882                 ${MAKE} DESTDIR=${KSTAGEDIR} -DNO_ROOT stagekernel
1883
1884 stage-packages: .PHONY stage-packages-world stage-packages-kernel
1885
1886 _repodir: .PHONY
1887         @mkdir -p ${REPODIR}
1888
1889 create-packages-world:  _pkgbootstrap _repodir .PHONY
1890         ${_+_}@cd ${.CURDIR}; \
1891                 ${MAKE} -f Makefile.inc1 \
1892                         DESTDIR=${WSTAGEDIR} \
1893                         PKG_VERSION=${PKG_VERSION} create-world-packages
1894
1895 create-packages-kernel: _pkgbootstrap _repodir .PHONY
1896         ${_+_}@cd ${.CURDIR}; \
1897                 ${MAKE} -f Makefile.inc1 \
1898                         DESTDIR=${KSTAGEDIR} \
1899                         PKG_VERSION=${PKG_VERSION} DISTDIR=kernel \
1900                         SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
1901                         create-kernel-packages
1902
1903 create-packages: .PHONY create-packages-world create-packages-kernel
1904
1905 create-world-packages:  _pkgbootstrap .PHONY
1906         @rm -f ${WSTAGEDIR}/*.plist 2>/dev/null || :
1907         @cd ${WSTAGEDIR} ; \
1908                 env -i LC_COLLATE=C sort ${WSTAGEDIR}/${DISTDIR}/METALOG | \
1909                 awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk
1910         @for plist in ${WSTAGEDIR}/*.plist; do \
1911           plist=$${plist##*/} ; \
1912           pkgname=$${plist%.plist} ; \
1913           echo "_PKGS+= $${pkgname}" ; \
1914         done > ${WSTAGEDIR}/packages.mk
1915         ${_+_}@cd ${.CURDIR}; \
1916                 ${MAKE} -f Makefile.inc1 create-world-packages-jobs \
1917                 SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
1918                 .MAKE.JOB.PREFIX=
1919
1920 .if make(create-world-packages-jobs)
1921 .include "${WSTAGEDIR}/packages.mk"
1922 .endif
1923
1924 .if make(create-world-packages-jobs) || make(create-kernel-packages*)
1925 PKG_ABI!=${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI
1926 .endif
1927
1928 create-world-packages-jobs: .PHONY
1929 .for pkgname in ${_PKGS}
1930 create-world-packages-jobs: create-world-package-${pkgname}
1931 create-world-package-${pkgname}: .PHONY
1932         @sh ${SRCDIR}/release/packages/generate-ucl.sh -o ${pkgname} \
1933                 -s ${SRCDIR} -u ${WSTAGEDIR}/${pkgname}.ucl
1934         @awk -F\" ' \
1935                 /^name/ { printf("===> Creating %s-", $$2); next } \
1936                 /^version/ { print $$2; next } \
1937                 ' ${WSTAGEDIR}/${pkgname}.ucl
1938         @if [ "${pkgname}" == "runtime" ]; then \
1939                 sed -i '' -e "s/%VCS_REVISION%/${VCS_REVISION}/" ${WSTAGEDIR}/${pkgname}.ucl ; \
1940         fi
1941         ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
1942                 create -f ${PKG_FORMAT} -M ${WSTAGEDIR}/${pkgname}.ucl \
1943                 -p ${WSTAGEDIR}/${pkgname}.plist \
1944                 -r ${WSTAGEDIR} \
1945                 -o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
1946 .endfor
1947
1948 _default_flavor=        -default
1949 .if make(*package*) && exists(${KSTAGEDIR}/kernel.meta)
1950 . if ${MK_DEBUG_FILES} != "no"
1951 _debug=-dbg
1952 . endif
1953 create-kernel-packages: .PHONY
1954 . for flavor in "" ${_debug}
1955 create-kernel-packages: create-kernel-packages-flavor${flavor:C,^""$,${_default_flavor},}
1956 create-kernel-packages-flavor${flavor:C,^""$,${_default_flavor},}: _pkgbootstrap .PHONY
1957         @cd ${KSTAGEDIR}/${DISTDIR} ; \
1958         env -i LC_COLLATE=C sort ${KSTAGEDIR}/kernel.meta | \
1959         awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
1960                 -v kernel=yes -v _kernconf=${INSTALLKERNEL} ; \
1961         sed -e "s/%VERSION%/${PKG_VERSION}/" \
1962                 -e "s/%PKGNAME%/kernel-${INSTALLKERNEL:tl}${flavor}/" \
1963                 -e "s/%KERNELDIR%/kernel/" \
1964                 -e "s/%COMMENT%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
1965                 -e "s/%DESC%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
1966                 -e "s/ %VCS_REVISION%/${VCS_REVISION}/" \
1967                 -e "s/%PKG_NAME_PREFIX%/${PKG_NAME_PREFIX}/" \
1968                 -e "s/%PKG_MAINTAINER%/${PKG_MAINTAINER}/" \
1969                 -e "s|%PKG_WWW%|${PKG_WWW}|" \
1970                 ${SRCDIR}/release/packages/kernel.ucl \
1971                 > ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
1972         awk -F\" ' \
1973                 /name/ { printf("===> Creating %s-", $$2); next } \
1974                 /version/ {print $$2; next } ' \
1975                 ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
1976         ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
1977                 create -f ${PKG_FORMAT} \
1978                 -M ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl \
1979                 -p ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.plist \
1980                 -r ${KSTAGEDIR}/${DISTDIR} \
1981                 -o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
1982 . endfor
1983 .endif
1984 .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes"
1985 . for _kernel in ${BUILDKERNELS:[2..-1]}
1986 .  if exists(${KSTAGEDIR}/kernel.${_kernel}.meta)
1987 .   if ${MK_DEBUG_FILES} != "no"
1988 _debug=-dbg
1989 .   endif
1990 .   for flavor in "" ${_debug}
1991 create-kernel-packages: create-kernel-packages-extra-flavor${flavor:C,^""$,${_default_flavor},}-${_kernel}
1992 create-kernel-packages-extra-flavor${flavor:C,^""$,${_default_flavor},}-${_kernel}: _pkgbootstrap .PHONY
1993         @cd ${KSTAGEDIR}/kernel.${_kernel} ; \
1994         env -i LC_COLLATE=C sort ${KSTAGEDIR}/kernel.${_kernel}.meta | \
1995         awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
1996                 -v kernel=yes -v _kernconf=${_kernel} ; \
1997         sed -e "s/%VERSION%/${PKG_VERSION}/" \
1998                 -e "s/%PKGNAME%/kernel-${_kernel:tl}${flavor}/" \
1999                 -e "s/%KERNELDIR%/kernel.${_kernel}/" \
2000                 -e "s/%COMMENT%/FreeBSD ${_kernel} kernel ${flavor}/" \
2001                 -e "s/%DESC%/FreeBSD ${_kernel} kernel ${flavor}/" \
2002                 -e "s/ %VCS_REVISION%/${VCS_REVISION}/" \
2003                 -e "s/%PKG_NAME_PREFIX%/${PKG_NAME_PREFIX}/" \
2004                 -e "s/%PKG_MAINTAINER%/${PKG_MAINTAINER}/" \
2005                 -e "s|%PKG_WWW%|${PKG_WWW}|" \
2006                 ${SRCDIR}/release/packages/kernel.ucl \
2007                 > ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
2008         awk -F\" ' \
2009                 /name/ { printf("===> Creating %s-", $$2); next } \
2010                 /version/ {print $$2; next } ' \
2011                 ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
2012         ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname -o ALLOW_BASE_SHLIBS=yes \
2013                 create -f ${PKG_FORMAT} \
2014                 -M ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl \
2015                 -p ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.plist \
2016                 -r ${KSTAGEDIR}/kernel.${_kernel} \
2017                 -o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
2018 .   endfor
2019 .  endif
2020 . endfor
2021 .endif
2022
2023 sign-packages:  _pkgbootstrap .PHONY
2024         printf "version = 2;\npacking_format = \"${PKG_FORMAT}\";\n" > ${WSTAGEDIR}/meta
2025         @[ -L "${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/latest" ] && \
2026                 unlink ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/latest ; \
2027         ${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname repo \
2028                 -m ${WSTAGEDIR}/meta \
2029                 -o ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/${PKG_VERSION} \
2030                 ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/${PKG_VERSION} \
2031                 ${PKGSIGNKEY} ; \
2032         cd ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI); \
2033         ln -s ${PKG_OUTPUT_DIR} latest
2034
2035 #
2036 #
2037 # checkworld
2038 #
2039 # Run test suite on installed world.
2040 #
2041 checkworld: .PHONY
2042         @if [ ! -x "${LOCALBASE}/bin/kyua" ] && [ ! -x "/usr/bin/kyua" ]; then \
2043                 echo "You need kyua (devel/kyua) to run the test suite." | /usr/bin/fmt; \
2044                 exit 1; \
2045         fi
2046         ${_+_}PATH="$$PATH:${LOCALBASE}/bin" kyua test -k ${TESTSBASE}/Kyuafile
2047
2048 #
2049 #
2050 # doxygen
2051 #
2052 # Build the API documentation with doxygen
2053 #
2054 doxygen: .PHONY
2055         @if [ ! -x "${LOCALBASE}/bin/doxygen" ]; then \
2056                 echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
2057                 exit 1; \
2058         fi
2059         ${_+_}cd ${.CURDIR}/tools/kerneldoc/subsys; ${MAKE} obj all
2060
2061 #
2062 # update
2063 #
2064 # Update the source tree(s), by running svn/svnup to update to the
2065 # latest copy.
2066 #
2067 update: .PHONY
2068 .if defined(SVN_UPDATE)
2069         @echo "--------------------------------------------------------------"
2070         @echo ">>> Updating ${.CURDIR} using Subversion"
2071         @echo "--------------------------------------------------------------"
2072         @(cd ${.CURDIR}; ${SVN_CMD} update ${SVNFLAGS})
2073 .endif
2074
2075 #
2076 # ------------------------------------------------------------------------
2077 #
2078 # From here onwards are utility targets used by the 'make world' and
2079 # related targets.  If your 'world' breaks, you may like to try to fix
2080 # the problem and manually run the following targets to attempt to
2081 # complete the build.  Beware, this is *not* guaranteed to work, you
2082 # need to have a pretty good grip on the current state of the system
2083 # to attempt to manually finish it.  If in doubt, 'make world' again.
2084 #
2085
2086 #
2087 # legacy: Build compatibility shims for the next three targets. This is a
2088 # minimal set of tools and shims necessary to compensate for older systems
2089 # which don't have the APIs required by the targets built in bootstrap-tools,
2090 # build-tools or cross-tools.
2091 #
2092
2093 # libnv and libsbuf are requirements for config(8), which is an unconditional
2094 # bootstrap-tool.
2095 _config_deps= lib/libnv lib/libsbuf
2096
2097 legacy: .PHONY
2098 .if ${BOOTSTRAPPING} < ${MINIMUM_SUPPORTED_OSREL} && ${BOOTSTRAPPING} != 0
2099         @echo "ERROR: Source upgrades from versions prior to ${MINIMUM_SUPPORTED_REL} are not supported."; \
2100         false
2101 .endif
2102
2103 .for _tool in tools/build
2104         ${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,all,install)"; \
2105             cd ${.CURDIR}/${_tool}; \
2106             if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2107             ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${WORLDTMP}/legacy includes; \
2108             ${MAKE} DIRPRFX=${_tool}/ MK_INCLUDES=no all; \
2109             ${MAKE} DIRPRFX=${_tool}/ MK_INCLUDES=no \
2110                 DESTDIR=${WORLDTMP}/legacy install
2111 .endfor
2112
2113 #
2114 # bootstrap-tools: Build tools needed for compatibility. These are binaries that
2115 # are built to build other binaries in the system. However, the focus of these
2116 # binaries is usually quite narrow. Bootstrap tools use the host's compiler and
2117 # libraries, augmented by -legacy, in addition to the libraries built during
2118 # bootstrap-tools.
2119 #
2120 _bt=            _bootstrap-tools
2121
2122 # We want to run the build with only ${WORLDTMP} in $PATH to ensure we don't
2123 # accidentally run tools that are incompatible but happen to be in $PATH.
2124 # This is especially important when building on Linux/MacOS where many of the
2125 # programs used during the build accept different flags or generate different
2126 # output. On those platforms we only symlink the tools known to be compatible
2127 # (e.g. basic utilities such as mkdir) into ${WORLDTMP} and build all others
2128 # from the FreeBSD sources during the bootstrap-tools stage.
2129 # We want to build without the user's $PATH starting in the bootstrap-tools
2130 # phase so the tools used in that phase (ln, cp, etc) must have already been
2131 # linked to $WORLDTMP. The tools are listed in the _host_tools_to_symlink
2132 # variable in tools/build/Makefile and are linked during the legacy phase.
2133 # Since they could be Linux or MacOS binaries, too we must only use flags that
2134 # are portable across operating systems.
2135
2136 # If BOOTSTRAP_ALL_TOOLS is set we will build all the required tools from the
2137 # current source tree. Otherwise we create a symlink to the version found in
2138 # $PATH during the bootstrap-tools stage.
2139 # When building on non-FreeBSD systems we can't assume that the host binaries
2140 # accept compatible flags or produce compatible output. Therefore we force
2141 # BOOTSTRAP_ALL_TOOLS and just build the FreeBSD version of the binary.
2142 .if defined(CROSSBUILD_HOST)
2143 BOOTSTRAP_ALL_TOOLS:=   1
2144 .endif
2145 .if defined(BOOTSTRAP_ALL_TOOLS)
2146 # BOOTSTRAPPING will be set on the command line so we can't override it here.
2147 # Instead set BOOTSTRAPPING_OSRELDATE so that the value 0 is set ${BSARGS}
2148 BOOTSTRAPPING_OSRELDATE:=       0
2149 .endif
2150
2151 # libnv and libsbuf are requirements for config(8), which is an unconditional
2152 # bootstrap-tool.
2153 _config=usr.sbin/config lib/libnv lib/libsbuf
2154 ${_bt}-usr.sbin/config: ${_bt}-lib/libnv ${_bt}-lib/libsbuf
2155
2156 .if ${MK_GAMES} != "no"
2157 _strfile=       usr.bin/fortune/strfile
2158 .endif
2159
2160 .if ${MK_VT} != "no"
2161 _vtfontcvt=     usr.bin/vtfontcvt
2162 .endif
2163
2164 # If we are not building the bootstrap because BOOTSTRAPPING is sufficient
2165 # we symlink the host version to $WORLDTMP instead. By doing this we can also
2166 # detect when a bootstrap tool is being used without the required MK_FOO.
2167 # If you add a new bootstrap tool where we could also use the host version,
2168 # please ensure that you also add a .else case where you add the tool to the
2169 # _bootstrap_tools_links variable.
2170 .if ${BOOTSTRAPPING} < 1000033
2171 # Note: lex needs m4 to build but m4 also depends on lex (which needs m4 to
2172 # generate any files). To fix this cyclic dependency we can build a bootstrap
2173 # version of m4 (with pre-generated files) then use that to build the real m4.
2174 # We can't simply use the host m4 since e.g. the macOS version does not accept
2175 # the flags that are passed by lex.
2176 # For lex we also use the pre-gerated files since we would otherwise need to
2177 # build awk and sed first (which need lex to build)
2178 # TODO: add a _bootstrap_lex and then build the real lex afterwards
2179 _lex=           usr.bin/lex
2180 _m4=            tools/build/bootstrap-m4 usr.bin/m4
2181 ${_bt}-tools/build/bootstrap-m4: ${_bt}-usr.bin/lex ${_bt}-lib/libopenbsd ${_bt}-usr.bin/yacc
2182 ${_bt}-usr.bin/m4: ${_bt}-lib/libopenbsd ${_bt}-usr.bin/yacc ${_bt}-usr.bin/lex ${_bt}-tools/build/bootstrap-m4
2183 _bt_m4_depend=${_bt}-usr.bin/m4
2184 _bt_lex_depend=${_bt}-usr.bin/lex ${_bt_m4_depend}
2185 .else
2186 _bootstrap_tools_links+=m4 lex
2187 .endif
2188
2189 # ELF Tool Chain libraries are needed for ELF tools and dtrace tools.
2190 # r296685 fix cross-endian objcopy
2191 # r310724 fixed PR 215350, a crash in libdwarf with objects built by GCC 6.2.
2192 # r334881 added libdwarf constants used by ctfconvert.
2193 # r338478 fixed a crash in objcopy for mips64el objects
2194 # r339083 libelf: correct mips64el test to use ELF header
2195 # r348347 Add missing powerpc64 relocation support to libdwarf
2196 .if ${BOOTSTRAPPING} < 1300030
2197 _elftoolchain_libs= lib/libelf lib/libdwarf lib/libzstd
2198 ${_bt}-lib/libelf: ${_bt_m4_depend}
2199 ${_bt}-lib/libdwarf: ${_bt_m4_depend}
2200 .endif
2201
2202 # flua is required to regenerate syscall files.  It first appeared during the
2203 # 13.0-CURRENT cycle, thus needs to be built on -older releases and stable
2204 # branches.
2205 .if ${BOOTSTRAPPING} < 1300059
2206 ${_bt}-libexec/flua: ${_bt}-lib/liblua ${_bt}-lib/libucl
2207 _flua= lib/liblua lib/libucl libexec/flua
2208 .endif
2209
2210 # r245440 mtree -N support added
2211 # r313404 requires sha384.h for libnetbsd, added to libmd in r292782
2212 .if ${BOOTSTRAPPING} < 1100093
2213 _nmtree=        lib/libmd \
2214                 lib/libnetbsd \
2215                 usr.sbin/nmtree
2216
2217 ${_bt}-lib/libnetbsd: ${_bt}-lib/libmd
2218 ${_bt}-usr.sbin/nmtree: ${_bt}-lib/libnetbsd
2219 .else
2220 _bootstrap_tools_links+=mtree
2221 .endif
2222
2223 # r246097: log addition login.conf.db, passwd, pwd.db, and spwd.db with cat -l
2224 .if ${BOOTSTRAPPING} < 1000027
2225 _cat=           bin/cat
2226 .else
2227 _bootstrap_tools_links+=cat
2228 .endif
2229
2230 # r277259 crunchide: Correct 64-bit section header offset
2231 # r281674 crunchide: always include both 32- and 64-bit ELF support
2232 .if ${BOOTSTRAPPING} < 1100078
2233 _crunchide=     usr.sbin/crunch/crunchide
2234 .else
2235 _bootstrap_tools_links+=crunchide
2236 .endif
2237
2238 # r285986 crunchen: use STRIPBIN rather than STRIP
2239 # 1100113: Support MK_AUTO_OBJ
2240 # 1200006: META_MODE fixes
2241 .if ${BOOTSTRAPPING} < 1100078 || \
2242     (${MK_AUTO_OBJ} == "yes" && ${BOOTSTRAPPING} < 1100114) || \
2243     (${MK_META_MODE} == "yes" && ${BOOTSTRAPPING} < 1200006)
2244 _crunchgen=     usr.sbin/crunch/crunchgen
2245 .else
2246 _bootstrap_tools_links+=crunchgen
2247 .endif
2248
2249 # r296926 -P keymap search path, MFC to stable/10 in r298297
2250 # Note: kbdcontrol can not be bootstrapped on non-FreeBSD systems
2251 .if !defined(CROSSBUILD_HOST)
2252 .if (${BOOTSTRAPPING} < 1003501 || \
2253         (${BOOTSTRAPPING} >= 1100000 && ${BOOTSTRAPPING} < 1100103))
2254 _kbdcontrol=    usr.sbin/kbdcontrol
2255 .else
2256 _bootstrap_tools_links+=kbdcontrol
2257 .endif
2258 .endif
2259
2260 _yacc=          usr.bin/yacc
2261
2262 .if ${MK_BSNMP} != "no"
2263 _gensnmptree=   usr.sbin/bsnmpd/gensnmptree
2264 .endif
2265
2266
2267 # We need to build tblgen when we're building clang or lld, either as
2268 # bootstrap tools, or as the part of the normal build.
2269 .if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_CLANG} != "no" || \
2270     ${MK_LLD_BOOTSTRAP} != "no" || ${MK_LLD} != "no"
2271 _clang_tblgen= \
2272         lib/clang/libllvmminimal \
2273         usr.bin/clang/llvm-tblgen \
2274         usr.bin/clang/clang-tblgen \
2275         usr.bin/clang/lldb-tblgen
2276 # XXX: lldb-tblgen is not needed, if top-level MK_LLDB=no
2277
2278 ${_bt}-usr.bin/clang/clang-tblgen: ${_bt}-lib/clang/libllvmminimal
2279 ${_bt}-usr.bin/clang/llvm-tblgen: ${_bt}-lib/clang/libllvmminimal
2280 ${_bt}-usr.bin/clang/lldb-tblgen: ${_bt}-lib/clang/libllvmminimal
2281 .endif
2282
2283 .if ${MK_LOCALES} != "no"
2284 _localedef=     usr.bin/localedef
2285 ${_bt}-usr.bin/localedef: ${_bt}-usr.bin/yacc ${_bt_lex_depend}
2286 .endif
2287
2288 .if ${MK_KERBEROS} != "no"
2289 _kerberos5_bootstrap_tools= \
2290         kerberos5/tools/make-roken \
2291         kerberos5/lib/libroken \
2292         kerberos5/lib/libvers \
2293         kerberos5/tools/asn1_compile \
2294         kerberos5/tools/slc \
2295         usr.bin/compile_et
2296
2297 .ORDER: ${_kerberos5_bootstrap_tools:C/^/${_bt}-/g}
2298 .for _tool in ${_kerberos5_bootstrap_tools}
2299 ${_bt}-${_tool}: ${_bt}-usr.bin/yacc ${_bt_lex_depend}
2300 .endfor
2301 .endif
2302
2303 ${_bt}-usr.bin/mandoc: ${_bt}-lib/libopenbsd
2304
2305 # The tools listed in _basic_bootstrap_tools will generally not be
2306 # bootstrapped unless BOOTSTRAP_ALL_TOOL is set. However, when building on a
2307 # Linux or MacOS host the host versions are incompatible so we need to build
2308 # them from the source tree. Usually the link name will be the same as the subdir,
2309 # but some directories such as grep or test install multiple binaries. In that
2310 # case we use the _basic_bootstrap_tools_multilink variable which is a list of
2311 # subdirectory and comma-separated list of files.
2312 _basic_bootstrap_tools_multilink=usr.bin/grep grep,egrep,fgrep
2313 _basic_bootstrap_tools_multilink+=bin/test test,[
2314 # bootstrap tools needed by buildworld:
2315 _basic_bootstrap_tools+=usr.bin/cut bin/expr usr.bin/gencat usr.bin/join \
2316     usr.bin/mktemp bin/realpath bin/rmdir usr.bin/sed usr.bin/sort \
2317     usr.bin/truncate usr.bin/tsort
2318 # Some build scripts use nawk instead of awk (this happens at least in
2319 # cddl/contrib/opensolaris/lib/libdtrace/common/mknames.sh) so we need both awk
2320 # and nawk in ${WORLDTMP}/legacy/bin.
2321 _basic_bootstrap_tools_multilink+=usr.bin/awk awk,nawk
2322 # file2c is required for building usr.sbin/config:
2323 _basic_bootstrap_tools+=usr.bin/file2c
2324 # uuencode/uudecode required for share/tabset
2325 _basic_bootstrap_tools+=usr.bin/uuencode usr.bin/uudecode
2326 # xargs is required by mkioctls
2327 _basic_bootstrap_tools+=usr.bin/xargs
2328 # cap_mkdb is required for share/termcap:
2329 _basic_bootstrap_tools+=usr.bin/cap_mkdb
2330 # services_mkdb/pwd_mkdb are required for installworld:
2331 _basic_bootstrap_tools+=usr.sbin/services_mkdb usr.sbin/pwd_mkdb
2332 # ldd is required for installcheck (TODO: just always use /usr/bin/ldd instead?)
2333 .if !defined(CROSSBUILD_HOST)
2334 # ldd is only needed for updating the running system so we don't need to
2335 # bootstrap ldd on non-FreeBSD systems
2336 _basic_bootstrap_tools+=usr.bin/ldd
2337 .endif
2338 # sysctl/chflags are required for installkernel:
2339 .if !defined(CROSSBUILD_HOST)
2340 _basic_bootstrap_tools+=sbin/sysctl bin/chflags
2341 .else
2342 # When building on non-FreeBSD, install a fake chflags instead since the
2343 # version from the source tree cannot work. We also don't need sysctl since we
2344 # are install with -DNO_ROOT.
2345 _other_bootstrap_tools+=tools/build/cross-build/fake_chflags
2346 .endif
2347 # mkfifo is used by sys/conf/newvers.sh
2348 _basic_bootstrap_tools+=usr.bin/mkfifo
2349
2350 .if ${MK_BOOT} != "no"
2351 # md5 is used by boot/beri (and possibly others)
2352 _basic_bootstrap_tools+=sbin/md5
2353 .endif
2354
2355 .if ${MK_ZONEINFO} != "no"
2356 _basic_bootstrap_tools+=usr.sbin/zic usr.sbin/tzsetup
2357 .endif
2358
2359 .if defined(BOOTSTRAP_ALL_TOOLS)
2360 _other_bootstrap_tools+=${_basic_bootstrap_tools}
2361 .for _subdir _links in ${_basic_bootstrap_tools_multilink}
2362 _other_bootstrap_tools+=${_subdir}
2363 .endfor
2364 ${_bt}-usr.bin/awk: ${_bt_lex_depend} ${_bt}-usr.bin/yacc
2365 ${_bt}-bin/expr: ${_bt_lex_depend} ${_bt}-usr.bin/yacc
2366 # If we are bootstrapping file2c, we have to build it before config:
2367 ${_bt}-usr.sbin/config: ${_bt}-usr.bin/file2c ${_bt_lex_depend}
2368 # Note: no symlink to make/bmake in the !BOOTSTRAP_ALL_TOOLS case here since
2369 # the links to make/bmake make links will have already have been created in the
2370 # `make legacy` step. Not adding a link to make is important on non-FreeBSD
2371 # since "make" will usually point to GNU make there.
2372 _other_bootstrap_tools+=usr.bin/bmake
2373
2374 # Avoid dependency on host bz2 headers:
2375 _other_bootstrap_tools+=lib/libbz2
2376 ${_bt}-usr.bin/grep: ${_bt}-lib/libbz2
2377 .else
2378 # All tools in _basic_bootstrap_tools have the same name as the subdirectory
2379 # so we can use :T to get the name of the symlinks that we need to create.
2380 _bootstrap_tools_links+=${_basic_bootstrap_tools:T}
2381 .for _subdir _links in ${_basic_bootstrap_tools_multilink}
2382 _bootstrap_tools_links+=${_links:S/,/ /g}
2383 .endfor
2384 .endif  # defined(BOOTSTRAP_ALL_TOOLS)
2385
2386 # Link the tools that we need for building but don't need to bootstrap because
2387 # the host version is known to be compatible into ${WORLDTMP}/legacy
2388 # We do this before building any of the bootstrap tools in case they depend on
2389 # the presence of any of the links (e.g. as m4/lex/awk)
2390 ${_bt}-links: .PHONY
2391
2392 .for _tool in ${_bootstrap_tools_links}
2393 ${_bt}-link-${_tool}: .PHONY .MAKE
2394         @rm -f "${WORLDTMP}/legacy/bin/${_tool}"; \
2395         source_path=`which ${_tool}`; \
2396         if [ ! -e "$${source_path}" ] ; then \
2397                 echo "Cannot find host tool '${_tool}'"; false; \
2398         fi; \
2399         cp -pf "$${source_path}" "${WORLDTMP}/legacy/bin/${_tool}"
2400 ${_bt}-links: ${_bt}-link-${_tool}
2401 .endfor
2402
2403 bootstrap-tools: ${_bt}-links .PHONY
2404
2405 #       Please document (add comment) why something is in 'bootstrap-tools'.
2406 #       Try to bound the building of the bootstrap-tool to just the
2407 #       FreeBSD versions that need the tool built at this stage of the build.
2408 .for _tool in \
2409     ${_clang_tblgen} \
2410     ${_kerberos5_bootstrap_tools} \
2411     ${_strfile} \
2412     usr.bin/dtc \
2413     ${_cat} \
2414     ${_kbdcontrol} \
2415     ${_elftoolchain_libs} \
2416     usr.bin/lorder \
2417     lib/libopenbsd \
2418     usr.bin/mandoc \
2419     usr.bin/rpcgen \
2420     ${_yacc} \
2421     ${_m4} \
2422     ${_lex} \
2423     ${_other_bootstrap_tools} \
2424     usr.bin/xinstall \
2425     ${_gensnmptree} \
2426     ${_config} \
2427     ${_flua} \
2428     ${_crunchide} \
2429     ${_crunchgen} \
2430     ${_nmtree} \
2431     ${_vtfontcvt} \
2432     ${_localedef}
2433 ${_bt}-${_tool}: ${_bt}-links .PHONY .MAKE
2434         ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
2435                 cd ${.CURDIR}/${_tool}; \
2436                 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2437                 if [ "${_tool}" = "usr.bin/lex" ]; then \
2438                         ${MAKE} DIRPRFX=${_tool}/ bootstrap; \
2439                 fi; \
2440                 ${MAKE} DIRPRFX=${_tool}/ all; \
2441                 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${WORLDTMP}/legacy install
2442
2443 bootstrap-tools: ${_bt}-${_tool}
2444 .endfor
2445 .if target(${_bt}-lib/libmd)
2446 # If we are bootstrapping libmd (e.g. when building on macOS/Linux) add the
2447 # necessary dependencies:
2448 ${_bt}-usr.bin/sort: ${_bt}-lib/libmd
2449 ${_bt}-usr.bin/xinstall: ${_bt}-lib/libmd
2450 ${_bt}-sbin/md5: ${_bt}-lib/libmd
2451 .endif
2452
2453
2454 #
2455 # build-tools: Build special purpose build tools
2456 #
2457 .if !defined(NO_SHARE) && ${MK_SYSCONS} != "no"
2458 _share= share/syscons/scrnmaps
2459 .endif
2460
2461 .if ${MK_RESCUE} != "no"
2462 # rescue includes programs that have build-tools targets
2463 _rescue=rescue/rescue
2464 .endif
2465
2466 .if ${MK_TCSH} != "no"
2467 _tcsh=bin/csh
2468 .endif
2469 .if ${MK_FILE} != "no"
2470 _libmagic=lib/libmagic
2471 .endif
2472
2473 .if ${MK_PMC} != "no" && \
2474     (${TARGET_ARCH} == "aarch64" || ${TARGET_ARCH} == "amd64" || \
2475     ${TARGET_ARCH} == "i386")
2476 _jevents=lib/libpmc/pmu-events
2477 .endif
2478
2479 # kernel-toolchain skips _cleanobj, so handle cleaning up previous
2480 # build-tools directories if needed.
2481 .if !defined(NO_CLEAN) && make(kernel-toolchain)
2482 _bt_clean=      ${CLEANDIR}
2483 .endif
2484
2485 .for _tool in \
2486     ${_tcsh} \
2487     bin/sh \
2488     ${LOCAL_TOOL_DIRS} \
2489     ${_jevents} \
2490     lib/ncurses/ncurses \
2491     lib/ncurses/ncursesw \
2492     ${_rescue} \
2493     ${_share} \
2494     usr.bin/awk \
2495     ${_libmagic} \
2496     usr.bin/mkesdb_static \
2497     usr.bin/mkcsmapper_static \
2498     usr.bin/vi/catalog
2499 build-tools_${_tool}: .PHONY
2500         ${_+_}@${ECHODIR} "===> ${_tool} (${_bt_clean:D${_bt_clean},}obj,build-tools)"; \
2501                 cd ${.CURDIR}/${_tool}; \
2502                 if [ -n "${_bt_clean}" ]; then ${MAKE} DIRPRFX=${_tool}/ ${_bt_clean}; fi; \
2503                 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2504                 ${MAKE} DIRPRFX=${_tool}/ build-tools
2505 build-tools: build-tools_${_tool}
2506 .endfor
2507
2508 #
2509 # kernel-tools: Build kernel-building tools
2510 #
2511 kernel-tools: .PHONY
2512         mkdir -p ${WORLDTMP}/usr
2513         ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2514             -p ${WORLDTMP}/usr >/dev/null
2515
2516 #
2517 # cross-tools: All the tools needed to build the rest of the system after
2518 # we get done with the earlier stages. It is the last set of tools needed
2519 # to begin building the target binaries.
2520 #
2521 .if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${BUILD_WITH_STRICT_TMPPATH} != 0
2522 .if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
2523 _btxld=         usr.sbin/btxld
2524 .endif
2525 .endif
2526
2527 # Rebuild ctfconvert and ctfmerge to avoid difficult-to-diagnose failures
2528 # resulting from missing bug fixes or ELF Toolchain updates.
2529 .if ${MK_CDDL} != "no"
2530 _dtrace_tools= cddl/lib/libctf cddl/lib/libspl cddl/usr.bin/ctfconvert \
2531     cddl/usr.bin/ctfmerge
2532 .endif
2533
2534 # If we're given an XAS, don't build binutils.
2535 .if ${XAS:M/*} == ""
2536 .if ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no"
2537 _elftctools=    lib/libelftc \
2538                 lib/libpe \
2539                 usr.bin/objcopy \
2540                 usr.bin/nm \
2541                 usr.bin/size \
2542                 usr.bin/strings
2543 # These are not required by the build, but can be useful for developers who
2544 # cross-build on a FreeBSD 10 host:
2545 _elftctools+=   usr.bin/addr2line
2546 .endif
2547 .elif ${TARGET_ARCH} != ${MACHINE_ARCH} && ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no"
2548 # If cross-building with an external binutils we still need to build strip for
2549 # the target (for at least crunchide).
2550 _elftctools=    lib/libelftc \
2551                 lib/libpe \
2552                 usr.bin/objcopy
2553 .endif
2554
2555 .if ${MK_CLANG_BOOTSTRAP} != "no"
2556 _clang=         usr.bin/clang
2557 .endif
2558 .if ${MK_LLD_BOOTSTRAP} != "no"
2559 _lld=           usr.bin/clang/lld
2560 .endif
2561 .if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_LLD_BOOTSTRAP} != "no"
2562 _clang_libs=    lib/clang
2563 .endif
2564 .if ${MK_USB} != "no"
2565 _usb_tools=     stand/usb/tools
2566 .endif
2567
2568 .if ${BUILD_WITH_STRICT_TMPPATH} != 0 || defined(BOOTSTRAP_ALL_TOOLS)
2569 _ar=usr.bin/ar
2570 .endif
2571
2572 cross-tools: .MAKE .PHONY
2573 .for _tool in \
2574     ${LOCAL_XTOOL_DIRS} \
2575     ${_ar} \
2576     ${_clang_libs} \
2577     ${_clang} \
2578     ${_lld} \
2579     ${_elftctools} \
2580     ${_dtrace_tools} \
2581     ${_btxld} \
2582     ${_usb_tools}
2583         ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
2584                 cd ${.CURDIR}/${_tool}; \
2585                 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
2586                 ${MAKE} DIRPRFX=${_tool}/ all; \
2587                 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${WORLDTMP} install
2588 .endfor
2589
2590 #
2591 # native-xtools is the current target for qemu-user cross builds of ports
2592 # via poudriere and the imgact_binmisc kernel module.
2593 # This target merely builds a toolchan/sysroot, then builds the tools it wants
2594 # with the options it wants in a special MAKEOBJDIRPREFIX, using the toolchain
2595 # already built.  It then installs the static tools to NXBDESTDIR for Poudriere
2596 # to pickup.
2597 #
2598 NXBOBJROOT=     ${OBJROOT}${MACHINE}.${MACHINE_ARCH}/nxb/
2599 NXBOBJTOP=      ${NXBOBJROOT}${NXB_TARGET}.${NXB_TARGET_ARCH}
2600 NXTP?=          /nxb-bin
2601 .if ${NXTP:N/*}
2602 .error NXTP variable should be an absolute path
2603 .endif
2604 NXBDESTDIR?=    ${DESTDIR}${NXTP}
2605
2606 # This is the list of tools to be built/installed as static and where
2607 # appropriate to build for the given TARGET.TARGET_ARCH.
2608 NXBDIRS+= \
2609     bin/cat \
2610     bin/chmod \
2611     bin/cp \
2612     ${_tcsh} \
2613     bin/echo \
2614     bin/expr \
2615     bin/hostname \
2616     bin/ln \
2617     bin/ls \
2618     bin/mkdir \
2619     bin/mv \
2620     bin/ps \
2621     bin/realpath \
2622     bin/rm \
2623     bin/rmdir \
2624     bin/sh \
2625     bin/sleep \
2626     sbin/md5 \
2627     sbin/sysctl \
2628     usr.bin/addr2line \
2629     usr.bin/ar \
2630     usr.bin/awk \
2631     usr.bin/basename \
2632     usr.bin/bmake \
2633     usr.bin/bzip2 \
2634     usr.bin/cmp \
2635     usr.bin/diff \
2636     usr.bin/dirname \
2637     usr.bin/objcopy \
2638     usr.bin/env \
2639     usr.bin/fetch \
2640     usr.bin/find \
2641     usr.bin/grep \
2642     usr.bin/gzip \
2643     usr.bin/head \
2644     usr.bin/id \
2645     usr.bin/lex \
2646     usr.bin/limits \
2647     usr.bin/lorder \
2648     usr.bin/mandoc \
2649     usr.bin/mktemp \
2650     usr.bin/mt \
2651     usr.bin/nm \
2652     usr.bin/patch \
2653     usr.bin/readelf \
2654     usr.bin/sed \
2655     usr.bin/size \
2656     usr.bin/sort \
2657     usr.bin/strings \
2658     usr.bin/tar \
2659     usr.bin/touch \
2660     usr.bin/tr \
2661     usr.bin/true \
2662     usr.bin/uniq \
2663     usr.bin/unzip \
2664     usr.bin/wc \
2665     usr.bin/xargs \
2666     usr.bin/xinstall \
2667     usr.bin/xz \
2668     usr.bin/yacc \
2669     usr.sbin/chown
2670
2671 SUBDIR_DEPEND_usr.bin/clang=    lib/clang
2672 .if ${MK_CLANG} != "no"
2673 NXBDIRS+=       lib/clang
2674 NXBDIRS+=       usr.bin/clang
2675 .endif
2676 # XXX: native-xtools passes along ${NXBDIRS} in SUBDIR_OVERRIDE that needs
2677 # to be evaluated after NXBDIRS is set.
2678 .if make(install) && !empty(SUBDIR_OVERRIDE)
2679 SUBDIR= ${SUBDIR_OVERRIDE}
2680 .endif
2681
2682 NXBMAKEARGS+= \
2683         OBJTOP=${NXBOBJTOP:Q} \
2684         OBJROOT=${NXBOBJROOT:Q} \
2685         MAKEOBJDIRPREFIX= \
2686         -DNO_SHARED \
2687         -DNO_CPU_CFLAGS \
2688         -DNO_PIC \
2689         SSP_CFLAGS= \
2690         MK_CASPER=no \
2691         MK_CLANG_EXTRAS=no \
2692         MK_CLANG_FORMAT=no \
2693         MK_CLANG_FULL=no \
2694         MK_CTF=no \
2695         MK_DEBUG_FILES=no \
2696         MK_GDB=no \
2697         MK_HTML=no \
2698         MK_LLDB=no \
2699         MK_MAN=no \
2700         MK_MAN_UTILS=yes \
2701         MK_OFED=no \
2702         MK_OPENSSH=no \
2703         MK_PROFILE=no \
2704         MK_RETPOLINE=no \
2705         MK_SENDMAIL=no \
2706         MK_SVNLITE=no \
2707         MK_TESTS=no \
2708         MK_WARNS=no \
2709         MK_ZFS=no
2710
2711 .if make(native-xtools*) && \
2712     (!defined(NXB_TARGET) || !defined(NXB_TARGET_ARCH))
2713 .error Missing NXB_TARGET / NXB_TARGET_ARCH
2714 .endif
2715 # For 'toolchain' we want to produce native binaries that themselves generate
2716 # native binaries.
2717 NXBTMAKE=       ${NXBMAKEENV} ${MAKE} ${NXBMAKEARGS:N-DNO_PIC:N-DNO_SHARED} \
2718                 TARGET=${MACHINE} TARGET_ARCH=${MACHINE_ARCH}
2719 # For 'everything' we want to produce native binaries (hence -target to
2720 # be MACHINE) that themselves generate TARGET.TARGET_ARCH binaries.
2721 # TARGET/TARGET_ARCH are still passed along from user.
2722 #
2723 # Use the toolchain we create as an external toolchain.
2724 .if ${USING_SYSTEM_COMPILER} == "yes" || ${XCC:N${CCACHE_BIN}:M/*}
2725 NXBMAKE+=       XCC="${XCC}" \
2726                 XCXX="${XCXX}" \
2727                 XCPP="${XCPP}"
2728 .else
2729 NXBMAKE+=       XCC="${NXBOBJTOP}/tmp/usr/bin/cc" \
2730                 XCXX="${NXBOBJTOP}/tmp/usr/bin/c++" \
2731                 XCPP="${NXBOBJTOP}/tmp/usr/bin/cpp"
2732 .endif
2733 NXBMAKE+=       ${NXBMAKEENV} ${MAKE} -f Makefile.inc1 ${NXBMAKEARGS} \
2734                 MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH} \
2735                 TARGET=${NXB_TARGET} TARGET_ARCH=${NXB_TARGET_ARCH} \
2736                 TARGET_TRIPLE=${MACHINE_TRIPLE:Q}
2737 # NXBDIRS is improperly based on MACHINE rather than NXB_TARGET.  Need to
2738 # invoke a sub-make to reevaluate MK_CLANG, etc, for NXBDIRS.
2739 NXBMAKE+=       SUBDIR_OVERRIDE='$${NXBDIRS:M*}'
2740 # Need to avoid the -isystem logic when using clang as an external toolchain
2741 # even if the TARGET being built for wants GCC.
2742 NXBMAKE+=       WANT_COMPILER_TYPE='$${X_COMPILER_TYPE}'
2743 native-xtools: .PHONY
2744         ${_+_}cd ${.CURDIR}; ${NXBTMAKE} _cleanobj
2745         # Build the bootstrap/host/cross tools that produce native binaries
2746         ${_+_}cd ${.CURDIR}; ${NXBTMAKE} kernel-toolchain
2747         # Populate includes/libraries sysroot that produce native binaries.
2748         # This is split out from 'toolchain' above mostly so that target LLVM
2749         # libraries have a proper LLVM_DEFAULT_TARGET_TRIPLE without
2750         # polluting the cross-compiler build.  The LLVM/GCC libs are skipped
2751         # here to avoid the problem but are kept in 'toolchain' so that
2752         # needed build tools are built.
2753         ${_+_}cd ${.CURDIR}; ${NXBTMAKE} _includes MK_CLANG=no
2754         ${_+_}cd ${.CURDIR}; ${NXBTMAKE} _libraries MK_CLANG=no
2755 .if !defined(NO_OBJWALK)
2756         ${_+_}cd ${.CURDIR}; ${NXBMAKE} _obj
2757 .endif
2758         ${_+_}cd ${.CURDIR}; ${NXBMAKE} everything
2759         @echo ">> native-xtools done.  Use 'make native-xtools-install' to install to a given DESTDIR"
2760
2761 native-xtools-install: .PHONY
2762         mkdir -p ${NXBDESTDIR}/bin ${NXBDESTDIR}/sbin ${NXBDESTDIR}/usr
2763         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2764             -p ${NXBDESTDIR}/usr >/dev/null
2765         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
2766             -p ${NXBDESTDIR}/usr/include >/dev/null
2767         ${_+_}cd ${.CURDIR}; ${NXBMAKE} \
2768             DESTDIR=${NXBDESTDIR} \
2769             -DNO_ROOT \
2770             install
2771
2772 #
2773 # hierarchy - ensure that all the needed directories are present
2774 #
2775 hierarchy hier: .MAKE .PHONY
2776         ${_+_}cd ${.CURDIR}/etc; ${HMAKE} distrib-dirs
2777
2778 #
2779 # libraries - build all libraries, and install them under ${DESTDIR}.
2780 #
2781 # The list of libraries with dependents (${_prebuild_libs}) and their
2782 # interdependencies (__L) are built automatically by the
2783 # ${.CURDIR}/tools/make_libdeps.sh script.
2784 #
2785 libraries: .MAKE .PHONY
2786         ${_+_}cd ${.CURDIR}; \
2787             ${MAKE} -f Makefile.inc1 _prereq_libs; \
2788             ${MAKE} -f Makefile.inc1 _startup_libs; \
2789             ${MAKE} -f Makefile.inc1 _prebuild_libs; \
2790             ${MAKE} -f Makefile.inc1 _generic_libs
2791
2792 #
2793 # static libgcc.a prerequisite for shared libc
2794 #
2795 _prereq_libs= lib/libcompiler_rt
2796 .if ${MK_SSP} != "no"
2797 _prereq_libs+= lib/libssp_nonshared
2798 .endif
2799
2800 # These dependencies are not automatically generated:
2801 #
2802 # lib/csu and lib/libc must be built before
2803 # all shared libraries for ELF.
2804 #
2805 _startup_libs=  lib/csu
2806 _startup_libs+= lib/libc
2807 _startup_libs+= lib/libc_nonshared
2808 .if ${MK_LIBCPLUSPLUS} != "no"
2809 _startup_libs+= lib/libcxxrt
2810 .endif
2811
2812 _prereq_libs+=  lib/libgcc_eh lib/libgcc_s
2813 _startup_libs+= lib/libgcc_eh lib/libgcc_s
2814
2815 lib/libgcc_s__L: lib/libc__L
2816 lib/libgcc_s__L: lib/libc_nonshared__L
2817 .if ${MK_LIBCPLUSPLUS} != "no"
2818 lib/libcxxrt__L: lib/libgcc_s__L
2819 .endif
2820
2821 _prebuild_libs= ${_kerberos5_lib_libasn1} \
2822                 ${_kerberos5_lib_libhdb} \
2823                 ${_kerberos5_lib_libheimbase} \
2824                 ${_kerberos5_lib_libheimntlm} \
2825                 ${_libsqlite3} \
2826                 ${_kerberos5_lib_libheimipcc} \
2827                 ${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
2828                 ${_kerberos5_lib_libroken} \
2829                 ${_kerberos5_lib_libwind} \
2830                 lib/libbz2 ${_libcom_err} lib/libcrypt \
2831                 lib/libelf lib/libexpat \
2832                 lib/libfigpar \
2833                 ${_lib_libgssapi} \
2834                 lib/libkiconv lib/libkvm lib/liblzma lib/libmd lib/libnv \
2835                 lib/libzstd \
2836                 ${_lib_casper} \
2837                 lib/ncurses/ncurses lib/ncurses/ncursesw \
2838                 lib/libopie lib/libpam/libpam ${_lib_libthr} \
2839                 ${_lib_libradius} lib/libsbuf lib/libtacplus \
2840                 lib/libgeom \
2841                 ${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \
2842                 ${_cddl_lib_libuutil} \
2843                 ${_cddl_lib_libavl} \
2844                 ${_cddl_lib_libicp} \
2845                 ${_cddl_lib_libicp_rescue} \
2846                 ${_cddl_lib_libspl} \
2847                 ${_cddl_lib_libtpool} \
2848                 ${_cddl_lib_libzfs_core} ${_cddl_lib_libzfs} \
2849                 ${_cddl_lib_libzutil} \
2850                 ${_cddl_lib_libctf} \
2851                 lib/libufs \
2852                 lib/libutil lib/libpjdlog ${_lib_libypclnt} lib/libz lib/msun \
2853                 ${_secure_lib_libcrypto} ${_secure_lib_libssl} \
2854                 ${_lib_libldns} ${_secure_lib_libssh}
2855
2856 .if ${MK_DIALOG} != "no"
2857 _prebuild_libs+= gnu/lib/libdialog
2858 gnu/lib/libdialog__L: lib/msun__L lib/ncurses/ncursesw__L
2859 .endif
2860
2861 .if ${MK_GOOGLETEST} != "no"
2862 _prebuild_libs+= lib/libregex
2863 .endif
2864
2865 .if ${MK_LIBCPLUSPLUS} != "no"
2866 _prebuild_libs+= lib/libc++
2867 .endif
2868
2869 lib/libgeom__L: lib/libexpat__L lib/libsbuf__L
2870 lib/libkvm__L: lib/libelf__L
2871
2872 .if ${MK_LIBTHR} != "no"
2873 _lib_libthr=    lib/libthr
2874 .endif
2875
2876 .if ${MK_RADIUS_SUPPORT} != "no"
2877 _lib_libradius= lib/libradius
2878 .endif
2879
2880 .if ${MK_OFED} != "no"
2881 _prebuild_libs+= \
2882         lib/ofed/libibverbs \
2883         lib/ofed/libibmad \
2884         lib/ofed/libibumad \
2885         lib/ofed/complib \
2886         lib/ofed/libmlx5
2887
2888 lib/ofed/libibmad__L:   lib/ofed/libibumad__L
2889 lib/ofed/complib__L:    lib/libthr__L
2890 lib/ofed/libmlx5__L:    lib/ofed/libibverbs__L lib/libthr__L
2891 .endif
2892
2893 .if ${MK_CASPER} != "no"
2894 _lib_casper=    lib/libcasper
2895 .endif
2896
2897 lib/libpjdlog__L: lib/libutil__L
2898 lib/libcasper__L: lib/libnv__L
2899 lib/liblzma__L: lib/libmd__L lib/libthr__L
2900 lib/libzstd__L: lib/libthr__L
2901
2902 _generic_libs=  ${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib}
2903 .if ${MK_IPFILTER} != "no"
2904 _generic_libs+= sbin/ipf/libipf
2905 .endif
2906 .for _DIR in ${LOCAL_LIB_DIRS}
2907 .if ${_DIR} == ".WAIT"  || (empty(_generic_libs:M${_DIR}) && exists(${.CURDIR}/${_DIR}/Makefile))
2908 _generic_libs+= ${_DIR}
2909 .endif
2910 .endfor
2911
2912 lib/libopie__L lib/libtacplus__L: lib/libmd__L
2913
2914 .if ${MK_CDDL} != "no"
2915 _cddl_lib_libumem= cddl/lib/libumem
2916 _cddl_lib_libnvpair= cddl/lib/libnvpair
2917 _cddl_lib_libavl= cddl/lib/libavl
2918 _cddl_lib_libuutil= cddl/lib/libuutil
2919 _cddl_lib_libspl= cddl/lib/libspl
2920
2921 cddl/lib/libuutil__L: cddl/lib/libavl__L cddl/lib/libspl__L
2922
2923 .if ${MK_ZFS} != "no"
2924 _cddl_lib_libicp= cddl/lib/libicp
2925 _cddl_lib_libicp_rescue= cddl/lib/libicp_rescue
2926 _cddl_lib_libtpool= cddl/lib/libtpool
2927 _cddl_lib_libzutil= cddl/lib/libzutil
2928 _cddl_lib_libzfs_core= cddl/lib/libzfs_core
2929 _cddl_lib_libzfs= cddl/lib/libzfs
2930
2931 cddl/lib/libtpool__L: cddl/lib/libspl__L
2932
2933 cddl/lib/libzutil__L: cddl/lib/libavl__L cddl/lib/libtpool__L
2934
2935 cddl/lib/libzfs_core__L: cddl/lib/libnvpair__L
2936
2937 cddl/lib/libzfs__L: cddl/lib/libzfs_core__L lib/msun__L lib/libutil__L
2938 cddl/lib/libzfs__L: lib/libthr__L lib/libmd__L lib/libz__L cddl/lib/libumem__L
2939 cddl/lib/libzfs__L: cddl/lib/libuutil__L cddl/lib/libavl__L lib/libgeom__L
2940 cddl/lib/libzfs__L: cddl/lib/libnvpair__L cddl/lib/libzutil__L
2941 cddl/lib/libzfs__L: secure/lib/libcrypto__L
2942
2943 lib/libbe__L: cddl/lib/libzfs__L
2944 .endif
2945 _cddl_lib_libctf= cddl/lib/libctf
2946 _cddl_lib= cddl/lib
2947 cddl/lib/libctf__L: lib/libz__L cddl/lib/libspl__L
2948 .endif
2949 # cddl/lib/libdtrace requires lib/libproc and lib/librtld_db
2950 _prebuild_libs+=        lib/libprocstat lib/libproc lib/librtld_db
2951 lib/libprocstat__L: lib/libelf__L lib/libkvm__L lib/libutil__L
2952 lib/libproc__L: lib/libprocstat__L
2953 lib/librtld_db__L: lib/libprocstat__L
2954
2955 .if ${MK_CRYPT} != "no"
2956 .if ${MK_OPENSSL} != "no"
2957 _secure_lib_libcrypto= secure/lib/libcrypto
2958 _secure_lib_libssl= secure/lib/libssl
2959 lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
2960 secure/lib/libcrypto__L: lib/libthr__L
2961 .if ${MK_LDNS} != "no"
2962 _lib_libldns= lib/libldns
2963 lib/libldns__L: secure/lib/libssl__L
2964 .endif
2965 .if ${MK_OPENSSH} != "no"
2966 _secure_lib_libssh= secure/lib/libssh
2967 secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
2968 .if ${MK_LDNS} != "no"
2969 secure/lib/libssh__L: lib/libldns__L
2970 .endif
2971 .if ${MK_GSSAPI} != "no" && ${MK_KERBEROS_SUPPORT} != "no"
2972 secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
2973     kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
2974     lib/libmd__L kerberos5/lib/libroken__L
2975 .endif
2976 .endif
2977 .endif
2978 _secure_lib=    secure/lib
2979 .endif
2980
2981 .if ${MK_KERBEROS} != "no"
2982 kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L
2983 kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2984     kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \
2985     kerberos5/lib/libwind__L lib/libsqlite3__L
2986 kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \
2987     kerberos5/lib/libroken__L lib/libcom_err__L
2988 kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2989     secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L
2990 kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2991     lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \
2992     kerberos5/lib/libroken__L kerberos5/lib/libwind__L \
2993     kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L
2994 kerberos5/lib/libroken__L: lib/libcrypt__L
2995 kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L
2996 kerberos5/lib/libheimbase__L: lib/libthr__L
2997 kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L
2998 .endif
2999
3000 lib/libsqlite3__L: lib/libthr__L
3001
3002 .if ${MK_GSSAPI} != "no"
3003 _lib_libgssapi= lib/libgssapi
3004 .endif
3005
3006 .if ${MK_KERBEROS} != "no"
3007 _kerberos5_lib= kerberos5/lib
3008 _kerberos5_lib_libasn1= kerberos5/lib/libasn1
3009 _kerberos5_lib_libhdb= kerberos5/lib/libhdb
3010 _kerberos5_lib_libheimbase= kerberos5/lib/libheimbase
3011 _kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
3012 _kerberos5_lib_libhx509= kerberos5/lib/libhx509
3013 _kerberos5_lib_libroken= kerberos5/lib/libroken
3014 _kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
3015 _libsqlite3= lib/libsqlite3
3016 _kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc
3017 _kerberos5_lib_libwind= kerberos5/lib/libwind
3018 _libcom_err= lib/libcom_err
3019 .endif
3020
3021 .if ${MK_NIS} != "no"
3022 _lib_libypclnt= lib/libypclnt
3023 .endif
3024
3025 .if ${MK_OPENSSL} == "no"
3026 lib/libradius__L: lib/libmd__L
3027 .endif
3028
3029 lib/libproc__L: \
3030     ${_cddl_lib_libctf:D${_cddl_lib_libctf}__L} lib/libelf__L lib/librtld_db__L lib/libutil__L
3031 .if ${MK_CXX} != "no" && ${MK_LIBCPLUSPLUS} != "no"
3032 lib/libproc__L: lib/libcxxrt__L
3033 .endif
3034
3035 .for _lib in ${_prereq_libs}
3036 ${_lib}__PL: .PHONY .MAKE
3037 .if !defined(_MKSHOWCONFIG) && exists(${.CURDIR}/${_lib})
3038         ${_+_}@${ECHODIR} "===> ${_lib} (obj,all,install)"; \
3039                 cd ${.CURDIR}/${_lib}; \
3040                 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; fi; \
3041                 ${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
3042                     DIRPRFX=${_lib}/ all; \
3043                 ${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
3044                     DIRPRFX=${_lib}/ install
3045 .endif
3046 .endfor
3047
3048 .for _lib in ${_startup_libs} ${_prebuild_libs} ${_generic_libs}
3049 ${_lib}__L: .PHONY .MAKE
3050 .if !defined(_MKSHOWCONFIG) && exists(${.CURDIR}/${_lib})
3051         ${_+_}@${ECHODIR} "===> ${_lib} (obj,all,install)"; \
3052                 cd ${.CURDIR}/${_lib}; \
3053                 if [ -z "${NO_OBJWALK}" ]; then ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; fi; \
3054                 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ all; \
3055                 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ install
3056 .endif
3057 .endfor
3058
3059 _prereq_libs: ${_prereq_libs:S/$/__PL/}
3060 _startup_libs: ${_startup_libs:S/$/__L/}
3061 _prebuild_libs: ${_prebuild_libs:S/$/__L/}
3062 _generic_libs: ${_generic_libs:S/$/__L/}
3063
3064 # Enable SUBDIR_PARALLEL when not calling 'make all', unless called from
3065 # 'everything' with _PARALLEL_SUBDIR_OK set.  This is because it is unlikely
3066 # that running 'make all' from the top-level, especially with a SUBDIR_OVERRIDE
3067 # or LOCAL_DIRS set, will have a reliable build if SUBDIRs are built in
3068 # parallel.  This is safe for the world stage of buildworld though since it has
3069 # already built libraries in a proper order and installed includes into
3070 # WORLDTMP. Special handling is done for SUBDIR ordering for 'install*' to
3071 # avoid trashing a system if it crashes mid-install.
3072 .if !make(all) || defined(_PARALLEL_SUBDIR_OK)
3073 SUBDIR_PARALLEL=
3074 .endif
3075
3076 .include <bsd.subdir.mk>
3077
3078 .if make(check-old) || make(check-old-dirs) || \
3079     make(check-old-files) || make(check-old-libs) || \
3080     make(delete-old) || make(delete-old-dirs) || \
3081     make(delete-old-files) || make(delete-old-libs)
3082
3083 #
3084 # check for / delete old files section
3085 #
3086
3087 .include "ObsoleteFiles.inc"
3088
3089 OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
3090 else you can not start such an application. Consult UPDATING for more \
3091 information regarding how to cope with the removal/revision bump of a \
3092 specific library."
3093
3094 .if !defined(BATCH_DELETE_OLD_FILES)
3095 RM_I=-i
3096 .else
3097 RM_I=-v
3098 .endif
3099
3100 delete-old-files: .PHONY
3101         @echo ">>> Removing old files (only deletes safe to delete libs)"
3102 # Ask for every old file if the user really wants to remove it.
3103 # It's annoying, but better safe than sorry.
3104 # NB: We cannot pass the list of OLD_FILES as a parameter because the
3105 # argument list will get too long. Using .for/.endfor make "loops" will make
3106 # the Makefile parser segfault.
3107         @exec 3<&0; \
3108         cd ${.CURDIR}; \
3109         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3110             -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | sort | \
3111         while read file; do \
3112                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3113                         chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
3114                         rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
3115                 fi; \
3116                 for ext in debug symbols; do \
3117                   if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
3118                       "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3119                           rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
3120                               <&3; \
3121                   fi; \
3122                 done; \
3123         done
3124 # Remove catpages without corresponding manpages.
3125         @exec 3<&0; \
3126         find ${DESTDIR}/usr/share/man/cat* ! -type d 2>/dev/null | sort | \
3127         sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
3128         while read catpage; do \
3129                 read manpage; \
3130                 if [ ! -e "$${manpage}" ]; then \
3131                         rm ${RM_I} $${catpage} <&3; \
3132                 fi; \
3133         done
3134         @echo ">>> Old files removed"
3135
3136 check-old-files: .PHONY
3137         @echo ">>> Checking for old files"
3138         @cd ${.CURDIR}; \
3139         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3140             -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
3141         while read file; do \
3142                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3143                         echo "${DESTDIR}/$${file}"; \
3144                 fi; \
3145                 for ext in debug symbols; do \
3146                   if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3147                           echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
3148                   fi; \
3149                 done; \
3150         done | sort
3151 # Check for catpages without corresponding manpages.
3152         @find ${DESTDIR}/usr/share/man/cat* ! -type d 2>/dev/null | \
3153         sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
3154         while read catpage; do \
3155                 read manpage; \
3156                 if [ ! -e "$${manpage}" ]; then \
3157                         echo $${catpage}; \
3158                 fi; \
3159         done | sort
3160
3161 delete-old-libs: .PHONY
3162         @echo ">>> Removing old libraries"
3163         @echo "${OLD_LIBS_MESSAGE}" | fmt
3164         @exec 3<&0; \
3165         cd ${.CURDIR}; \
3166         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3167             -V OLD_LIBS | xargs -n1 | sort | \
3168         while read file; do \
3169                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3170                         chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
3171                         rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
3172                 fi; \
3173                 for ext in debug symbols; do \
3174                   if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
3175                       "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3176                           rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
3177                               <&3; \
3178                   fi; \
3179                 done; \
3180         done
3181         @echo ">>> Old libraries removed"
3182
3183 check-old-libs: .PHONY
3184         @echo ">>> Checking for old libraries"
3185         @cd ${.CURDIR}; \
3186         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3187             -V OLD_LIBS | xargs -n1 | \
3188         while read file; do \
3189                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
3190                         echo "${DESTDIR}/$${file}"; \
3191                 fi; \
3192                 for ext in debug symbols; do \
3193                   if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
3194                           echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
3195                   fi; \
3196                 done; \
3197         done | sort
3198
3199 delete-old-dirs: .PHONY
3200         @echo ">>> Removing old directories"
3201         @cd ${.CURDIR}; \
3202         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3203             -V OLD_DIRS | xargs -n1 | sort -r | \
3204         while read dir; do \
3205                 if [ -d "${DESTDIR}/$${dir}" ]; then \
3206                         rmdir -v "${DESTDIR}/$${dir}" || true; \
3207                 elif [ -L "${DESTDIR}/$${dir}" ]; then \
3208                         echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
3209                 fi; \
3210                 if [ -d "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3211                         rmdir -v "${DESTDIR}${DEBUGDIR}/$${dir}" || true; \
3212                 elif [ -L "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3213                         echo "${DESTDIR}${DEBUGDIR}/$${dir} is a link, please remove everything manually."; \
3214                 fi; \
3215         done
3216         @echo ">>> Old directories removed"
3217
3218 check-old-dirs: .PHONY
3219         @echo ">>> Checking for old directories"
3220         @cd ${.CURDIR}; \
3221         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
3222             -V OLD_DIRS | xargs -n1 | sort -r | \
3223         while read dir; do \
3224                 if [ -d "${DESTDIR}/$${dir}" ]; then \
3225                         echo "${DESTDIR}/$${dir}"; \
3226                 elif [ -L "${DESTDIR}/$${dir}" ]; then \
3227                         echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
3228                 fi; \
3229                 if [ -d "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3230                         echo "${DESTDIR}${DEBUGDIR}/$${dir}"; \
3231                 elif [ -L "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \
3232                         echo "${DESTDIR}${DEBUGDIR}/$${dir} is a link, please remove everything manually."; \
3233                 fi; \
3234         done
3235
3236 delete-old: delete-old-files delete-old-dirs .PHONY
3237         @echo "To remove old libraries run '${MAKE_CMD} delete-old-libs'."
3238
3239 check-old: check-old-files check-old-libs check-old-dirs .PHONY
3240         @echo "To remove old files and directories run '${MAKE_CMD} delete-old'."
3241         @echo "To remove old libraries run '${MAKE_CMD} delete-old-libs'."
3242
3243 .endif
3244
3245 #
3246 # showconfig - show build configuration.
3247 #
3248 showconfig: .PHONY
3249         @(${MAKE} -n -f ${.CURDIR}/sys/conf/kern.opts.mk -V dummy -dg1 UPDATE_DEPENDFILE=no NO_OBJ=yes; \
3250           ${MAKE} -n -f ${.CURDIR}/share/mk/src.opts.mk -V dummy -dg1 UPDATE_DEPENDFILE=no NO_OBJ=yes) 2>&1 | grep ^MK_ | sort -u
3251
3252 .if !empty(KRNLOBJDIR) && !empty(KERNCONF)
3253 DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
3254
3255 .if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
3256 .if !defined(_MKSHOWCONFIG) && exists(${KERNCONFDIR}/${KERNCONF})
3257 FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
3258         '${KERNCONFDIR}/${KERNCONF}' ; echo
3259 .endif
3260 .endif
3261
3262 .endif
3263
3264 .if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
3265 DTBOUTPUTPATH= ${.CURDIR}
3266 .endif
3267
3268 #
3269 # Build 'standalone' Device Tree Blob
3270 #
3271 builddtb: .PHONY
3272         @PATH=${TMPPATH} MACHINE=${TARGET} \
3273         sh ${.CURDIR}/sys/tools/fdt/make_dtb.sh ${.CURDIR}/sys \
3274             "${FDT_DTS_FILE}" ${DTBOUTPUTPATH}
3275
3276 ###############
3277
3278 # cleanworld
3279 # In the following, the first 'rm' in a series will usually remove all
3280 # files and directories.  If it does not, then there are probably some
3281 # files with file flags set, so this unsets them and tries the 'rm' a
3282 # second time.  There are situations where this target will be cleaning
3283 # some directories via more than one method, but that duplication is
3284 # needed to correctly handle all the possible situations.  Removing all
3285 # files without file flags set in the first 'rm' instance saves time,
3286 # because 'chflags' will need to operate on fewer files afterwards.
3287 #
3288 # It is expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
3289 # created by bsd.obj.mk, except that we don't want to .include that file
3290 # in this makefile.  We don't do a cleandir walk if MK_AUTO_OBJ is yes
3291 # since it is not possible for files to land in the wrong place.
3292 #
3293 .if make(cleanworld)
3294 BW_CANONICALOBJDIR:=${OBJTOP}/
3295 .elif make(cleanuniverse)
3296 BW_CANONICALOBJDIR:=${OBJROOT}
3297 .if ${MK_UNIFIED_OBJDIR} == "no"
3298 .error ${.TARGETS} only supported with WITH_UNIFIED_OBJDIR enabled.
3299 .endif
3300 .endif
3301 cleanworld cleanuniverse: .PHONY
3302 .if !empty(BW_CANONICALOBJDIR) && exists(${BW_CANONICALOBJDIR}) && \
3303     ${.CURDIR:tA} != ${BW_CANONICALOBJDIR:tA}
3304         -rm -rf ${BW_CANONICALOBJDIR}*
3305         -chflags -R 0 ${BW_CANONICALOBJDIR}
3306         rm -rf ${BW_CANONICALOBJDIR}*
3307 .endif
3308 .if make(cleanworld) && ${MK_AUTO_OBJ} == "no" && \
3309     (empty(BW_CANONICALOBJDIR) || ${.CURDIR:tA} == ${BW_CANONICALOBJDIR:tA})
3310 .if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
3311         #   To be safe in this case, fall back to a 'make cleandir'
3312         ${_+_}@cd ${.CURDIR}; ${MAKE} cleandir
3313 .endif
3314 .endif
3315
3316 .if ${TARGET} == ${MACHINE} && ${TARGET_ARCH} == ${MACHINE_ARCH}
3317 XDEV_CPUTYPE?=${CPUTYPE}
3318 .else
3319 XDEV_CPUTYPE?=${TARGET_CPUTYPE}
3320 .endif
3321
3322 NOFUN=-DNO_FSCHG MK_HTML=no -DNO_LINT \
3323         MK_MAN=no MK_NLS=no MK_PROFILE=no \
3324         MK_KERBEROS=no MK_RESCUE=no MK_TESTS=no MK_WARNS=no \
3325         TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
3326         CPUTYPE=${XDEV_CPUTYPE}
3327
3328 XDDIR=${TARGET_ARCH}-freebsd
3329 XDTP?=/usr/${XDDIR}
3330 .if ${XDTP:N/*}
3331 .error XDTP variable should be an absolute path
3332 .endif
3333
3334 CDBOBJROOT=     ${OBJROOT}${MACHINE}.${MACHINE_ARCH}/xdev/
3335 CDBOBJTOP=      ${CDBOBJROOT}${XDDIR}
3336 CDBENV= \
3337         INSTALL="sh ${.CURDIR}/tools/install.sh"
3338 CDENV= ${CDBENV} \
3339         TOOLS_PREFIX=${XDTP}
3340 CDMAKEARGS= \
3341         OBJTOP=${CDBOBJTOP:Q} \
3342         OBJROOT=${CDBOBJROOT:Q}
3343 CD2MAKEARGS= ${CDMAKEARGS}
3344
3345 .if ${WANT_COMPILER_TYPE} == gcc || \
3346     (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
3347 # GCC requires -isystem and -L when using a cross-compiler.  --sysroot
3348 # won't set header path and -L is used to ensure the base library path
3349 # is added before the port PREFIX library path.
3350 CD2CFLAGS+=     -isystem ${XDDESTDIR}/usr/include -L${XDDESTDIR}/usr/lib
3351 # GCC requires -B to find /usr/lib/crti.o when using a cross-compiler
3352 # combined with --sysroot.
3353 CD2CFLAGS+=     -B${XDDESTDIR}/usr/lib
3354 # Force using libc++ for external GCC.
3355 .if defined(X_COMPILER_TYPE) && \
3356     ${X_COMPILER_TYPE} == gcc && ${X_COMPILER_VERSION} >= 40800
3357 CD2CXXFLAGS+=   -isystem ${XDDESTDIR}/usr/include/c++/v1 -std=c++11 \
3358                 -nostdinc++
3359 .endif
3360 .endif
3361 CD2CFLAGS+=     --sysroot=${XDDESTDIR}/
3362 CD2ENV=${CDENV} CC="${CC} ${CD2CFLAGS}" CXX="${CXX} ${CD2CXXFLAGS} ${CD2CFLAGS}" \
3363         CPP="${CPP} ${CD2CFLAGS}" \
3364         MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH}
3365
3366 CDTMP=  ${OBJTOP}/${XDDIR}/tmp
3367 CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${CDMAKEARGS} ${NOFUN}
3368 CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/usr/bin:${PATH} \
3369         ${MAKE} ${CD2MAKEARGS} ${NOFUN}
3370 .if ${MK_META_MODE} != "no"
3371 # Don't rebuild build-tools targets during normal build.
3372 CD2MAKE+=       BUILD_TOOLS_META=.NOMETA
3373 .endif
3374 XDDESTDIR=${DESTDIR}${XDTP}
3375
3376 .ORDER: xdev-build xdev-install xdev-links
3377 xdev: xdev-build xdev-install .PHONY
3378
3379 .ORDER: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
3380 xdev-build: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools .PHONY
3381
3382 _xb-worldtmp: .PHONY
3383         mkdir -p ${CDTMP}/usr
3384         ${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
3385             -p ${CDTMP}/usr >/dev/null
3386
3387 _xb-bootstrap-tools: .PHONY
3388 .for _tool in \
3389     ${_clang_tblgen} \
3390     ${_yacc}
3391         ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
3392         cd ${.CURDIR}/${_tool}; \
3393         if [ -z "${NO_OBJWALK}" ]; then ${CDMAKE} DIRPRFX=${_tool}/ obj; fi; \
3394         ${CDMAKE} DIRPRFX=${_tool}/ all; \
3395         ${CDMAKE} DIRPRFX=${_tool}/ DESTDIR=${CDTMP} install
3396 .endfor
3397
3398 _xb-build-tools: .PHONY
3399         ${_+_}@cd ${.CURDIR}; \
3400         ${CDBENV} ${MAKE} ${CDMAKEARGS} -f Makefile.inc1 ${NOFUN} build-tools
3401
3402 XDEVDIRS= \
3403     ${_clang_libs} \
3404     ${_lld} \
3405     ${_elftctools} \
3406     usr.bin/ar \
3407     ${_clang}
3408
3409 _xb-cross-tools: .PHONY
3410 .for _tool in ${XDEVDIRS}
3411         ${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,all)"; \
3412         cd ${.CURDIR}/${_tool}; \
3413         if [ -z "${NO_OBJWALK}" ]; then ${CDMAKE} DIRPRFX=${_tool}/ obj; fi; \
3414         ${CDMAKE} DIRPRFX=${_tool}/ all
3415 .endfor
3416
3417 _xi-mtree: .PHONY
3418         ${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
3419         mkdir -p ${XDDESTDIR}
3420         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.root.dist \
3421             -p ${XDDESTDIR} >/dev/null
3422         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
3423             -p ${XDDESTDIR}/usr >/dev/null
3424         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
3425             -p ${XDDESTDIR}/usr/include >/dev/null
3426 .if defined(_LIBCOMPAT)
3427         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
3428             -p ${XDDESTDIR}/usr >/dev/null
3429 .endif
3430 .if ${MK_TESTS} != "no"
3431         mkdir -p ${XDDESTDIR}${TESTSBASE}
3432         ${DESTDIR_MTREE} -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
3433             -p ${XDDESTDIR}${TESTSBASE} >/dev/null
3434 .endif
3435
3436 .ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries
3437 xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries .PHONY
3438
3439 _xi-cross-tools: .PHONY
3440         @echo "_xi-cross-tools"
3441 .for _tool in ${XDEVDIRS}
3442         ${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
3443         cd ${.CURDIR}/${_tool}; \
3444         ${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
3445 .endfor
3446
3447 _xi-includes: .PHONY
3448 .if !defined(NO_OBJWALK)
3449         ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 _obj \
3450                 DESTDIR=${XDDESTDIR}
3451 .endif
3452         ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 includes \
3453                 DESTDIR=${XDDESTDIR}
3454
3455 _xi-libraries: .PHONY
3456         ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
3457                 DESTDIR=${XDDESTDIR}
3458
3459 xdev-links: .PHONY
3460         ${_+_}cd ${XDDESTDIR}/usr/bin; \
3461         mkdir -p ../../../../usr/bin; \
3462                 for i in *; do \
3463                         ln -sf ../../${XDTP}/usr/bin/$$i \
3464                             ../../../../usr/bin/${XDDIR}-$$i; \
3465                         ln -sf ../../${XDTP}/usr/bin/$$i \
3466                             ../../../../usr/bin/${XDDIR}${_REVISION}-$$i; \
3467                 done