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