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