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