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