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