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