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