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