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