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