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