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