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