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