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