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