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