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