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