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