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