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