]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - Makefile.inc1
MFV ntp 4.2.8p1 (r258945, r275970, r276091, r276092, r276093, r278284)
[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,DEPEND,OBJ}
11 #       -DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
12 #       -DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
13 #       -DNO_KERNELDEPEND do not run ${MAKE} depend in ${MAKE} buildkernel
14 #       -DNO_KERNELOBJ do not run ${MAKE} obj in ${MAKE} buildkernel
15 #       -DNO_PORTSUPDATE do not update ports in ${MAKE} update
16 #       -DNO_ROOT install without using root privilege
17 #       -DNO_DOCUPDATE do not update doc in ${MAKE} update
18 #       -DWITHOUT_CTF do not run the DTrace CTF conversion tools on built objects
19 #       LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
20 #       LOCAL_ITOOLS="list of tools" to add additional tools to the ITOOLS list
21 #       LOCAL_LIB_DIRS="list of dirs" to add additional dirs to libraries target
22 #       LOCAL_MTREE="list of mtree files" to process to allow local directories
23 #           to be created before files are installed
24 #       LOCAL_TOOL_DIRS="list of dirs" to add additional dirs to the build-tools
25 #           list
26 #       METALOG="path to metadata log" to write permission and ownership
27 #           when NO_ROOT is set.  (default: ${DESTDIR}/METALOG)
28 #       TARGET="machine" to crossbuild world for a different machine type
29 #       TARGET_ARCH= may be required when a TARGET supports multiple endians
30 #       BUILDENV_SHELL= shell to launch for the buildenv target (def:/bin/sh)
31 #       WORLD_FLAGS= additional flags to pass to make(1) during buildworld
32 #       KERNEL_FLAGS= additional flags to pass to make(1) during buildkernel
33
34 #
35 # The intended user-driven targets are:
36 # buildworld  - rebuild *everything*, including glue to help do upgrades
37 # installworld- install everything built by "buildworld"
38 # doxygen     - build API documentation of the kernel
39 # update      - convenient way to update your source tree (eg: svn/svnup)
40 #
41 # Standard targets (not defined here) are documented in the makefiles in
42 # /usr/share/mk.  These include:
43 #               obj depend all install clean cleandepend cleanobj
44
45 .if !defined(TARGET) || !defined(TARGET_ARCH)
46 .error "Both TARGET and TARGET_ARCH must be defined."
47 .endif
48
49 .include "share/mk/src.opts.mk"
50 .include <bsd.arch.inc.mk>
51 .include <bsd.compiler.mk>
52
53 # We must do lib/ and libexec/ before bin/, because if installworld
54 # installs a new /bin/sh, the 'make' command will *immediately*
55 # use that new version.  And the new (dynamically-linked) /bin/sh
56 # will expect to find appropriate libraries in /lib and /libexec.
57 #
58 SRCDIR?=        ${.CURDIR}
59 .if defined(SUBDIR_OVERRIDE)
60 SUBDIR= ${SUBDIR_OVERRIDE}
61 .else
62 SUBDIR= lib libexec
63 SUBDIR+=bin
64 .if ${MK_GAMES} != "no"
65 SUBDIR+=games
66 .endif
67 .if ${MK_CDDL} != "no"
68 SUBDIR+=cddl
69 .endif
70 SUBDIR+=gnu include
71 .if ${MK_KERBEROS} != "no"
72 SUBDIR+=kerberos5
73 .endif
74 .if ${MK_RESCUE} != "no"
75 SUBDIR+=rescue
76 .endif
77 SUBDIR+=sbin
78 .if ${MK_CRYPT} != "no"
79 SUBDIR+=secure
80 .endif
81 .if !defined(NO_SHARE)
82 SUBDIR+=share
83 .endif
84 SUBDIR+=sys usr.bin usr.sbin
85 .if ${MK_TESTS} != "no"
86 SUBDIR+=        tests
87 .endif
88 .if ${MK_OFED} != "no"
89 SUBDIR+=contrib/ofed
90 .endif
91 #
92 # We must do etc/ last for install/distribute to work.
93 #
94 SUBDIR+=etc
95
96 # Local directories are last, since it is nice to at least get the base
97 # system rebuilt before you do them.
98 .for _DIR in ${LOCAL_DIRS}
99 .if exists(${.CURDIR}/${_DIR}/Makefile)
100 SUBDIR+=        ${_DIR}
101 .endif
102 .endfor
103 # Add LOCAL_LIB_DIRS, but only if they will not be picked up as a SUBDIR
104 # of a LOCAL_DIRS directory.  This allows LOCAL_DIRS=foo and
105 # LOCAL_LIB_DIRS=foo/lib to behave as expected.
106 .for _DIR in ${LOCAL_DIRS:M*/} ${LOCAL_DIRS:N*/:S|$|/|}
107 _REDUNDENT_LIB_DIRS+=    ${LOCAL_LIB_DIRS:M${_DIR}*}
108 .endfor
109 .for _DIR in ${LOCAL_LIB_DIRS}
110 .if empty(_REDUNDENT_LIB_DIRS:M${_DIR}) && exists(${.CURDIR}/${_DIR}/Makefile)
111 SUBDIR+=        ${_DIR}
112 .else
113 .warning ${_DIR} not added to SUBDIR list.  See UPDATING 20141121.
114 .endif
115 .endfor
116 .endif
117
118 .if defined(NOCLEAN)
119 NO_CLEAN=       ${NOCLEAN}
120 .endif
121 .if defined(NO_CLEANDIR)
122 CLEANDIR=       clean cleandepend
123 .else
124 CLEANDIR=       cleandir
125 .endif
126
127 LOCAL_TOOL_DIRS?=
128
129 BUILDENV_SHELL?=/bin/sh
130
131 SVN?=           /usr/local/bin/svn
132 SVNFLAGS?=      -r HEAD
133
134 MAKEOBJDIRPREFIX?=      /usr/obj
135 .if !defined(OSRELDATE)
136 .if exists(/usr/include/osreldate.h)
137 OSRELDATE!=     awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
138                 /usr/include/osreldate.h
139 .else
140 OSRELDATE=      0
141 .endif
142 .endif
143
144 .if !defined(VERSION)
145 REVISION!=      ${MAKE} -C ${SRCDIR}/release -V REVISION
146 BRANCH!=        ${MAKE} -C ${SRCDIR}/release -V BRANCH
147 SRCRELDATE!=    awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
148                 ${SRCDIR}/sys/sys/param.h
149 VERSION=        FreeBSD ${REVISION}-${BRANCH:C/-p[0-9]+$//} ${TARGET_ARCH} ${SRCRELDATE}
150 .endif
151
152 KNOWN_ARCHES?=  aarch64/arm64 amd64 arm armeb/arm armv6/arm armv6hf/arm i386 i386/pc98 mips mipsel/mips mips64el/mips mips64/mips mipsn32el/mips mipsn32/mips powerpc powerpc64/powerpc sparc64
153 .if ${TARGET} == ${TARGET_ARCH}
154 _t=             ${TARGET}
155 .else
156 _t=             ${TARGET_ARCH}/${TARGET}
157 .endif
158 .for _t in ${_t}
159 .if empty(KNOWN_ARCHES:M${_t})
160 .error Unknown target ${TARGET_ARCH}:${TARGET}.
161 .endif
162 .endfor
163
164 .if ${TARGET} == ${MACHINE}
165 TARGET_CPUTYPE?=${CPUTYPE}
166 .else
167 TARGET_CPUTYPE?=
168 .endif
169
170 .if !empty(TARGET_CPUTYPE)
171 _TARGET_CPUTYPE=${TARGET_CPUTYPE}
172 .else
173 _TARGET_CPUTYPE=dummy
174 .endif
175 _CPUTYPE!=      MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \
176                 -f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE
177 .if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
178 .error CPUTYPE global should be set with ?=.
179 .endif
180 .if make(buildworld)
181 BUILD_ARCH!=    uname -p
182 .if ${MACHINE_ARCH} != ${BUILD_ARCH}
183 .error To cross-build, set TARGET_ARCH.
184 .endif
185 .endif
186 .if ${MACHINE} == ${TARGET} && ${MACHINE_ARCH} == ${TARGET_ARCH} && !defined(CROSS_BUILD_TESTING)
187 OBJTREE=        ${MAKEOBJDIRPREFIX}
188 .else
189 OBJTREE=        ${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}
190 .endif
191 WORLDTMP=       ${OBJTREE}${.CURDIR}/tmp
192 BPATH=          ${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/bin
193 XPATH=          ${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin
194 STRICTTMPPATH=  ${BPATH}:${XPATH}
195 TMPPATH=        ${STRICTTMPPATH}:${PATH}
196
197 #
198 # Avoid running mktemp(1) unless actually needed.
199 # It may not be functional, e.g., due to new ABI
200 # when in the middle of installing over this system.
201 #
202 .if make(distributeworld) || make(installworld)
203 INSTALLTMP!=    /usr/bin/mktemp -d -u -t install
204 .endif
205
206 #
207 # Building a world goes through the following stages
208 #
209 # 1. legacy stage [BMAKE]
210 #       This stage is responsible for creating compatibility
211 #       shims that are needed by the bootstrap-tools,
212 #       build-tools and cross-tools stages. These are generally
213 #       APIs that tools from one of those three stages need to
214 #       build that aren't present on the host.
215 # 1. bootstrap-tools stage [BMAKE]
216 #       This stage is responsible for creating programs that
217 #       are needed for backward compatibility reasons. They
218 #       are not built as cross-tools.
219 # 2. build-tools stage [TMAKE]
220 #       This stage is responsible for creating the object
221 #       tree and building any tools that are needed during
222 #       the build process.
223 # 3. cross-tools stage [XMAKE]
224 #       This stage is responsible for creating any tools that
225 #       are needed for building the system. A cross-compiler is one
226 #       of them.
227 # 4. world stage [WMAKE]
228 #       This stage actually builds the world.
229 # 5. install stage (optional) [IMAKE]
230 #       This stage installs a previously built world.
231 #
232
233 BOOTSTRAPPING?= 0
234
235 # Common environment for world related stages
236 CROSSENV=       MAKEOBJDIRPREFIX=${OBJTREE} \
237                 MACHINE_ARCH=${TARGET_ARCH} \
238                 MACHINE=${TARGET} \
239                 CPUTYPE=${TARGET_CPUTYPE}
240 .if ${MK_GROFF} != "no"
241 CROSSENV+=      GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \
242                 GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \
243                 GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac
244 .endif
245 .if defined(TARGET_CFLAGS)
246 CROSSENV+=      ${TARGET_CFLAGS}
247 .endif
248
249 # bootstrap-tools stage
250 BMAKEENV=       INSTALL="sh ${.CURDIR}/tools/install.sh" \
251                 PATH=${BPATH}:${PATH} \
252                 WORLDTMP=${WORLDTMP} \
253                 VERSION="${VERSION}" \
254                 MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
255 BMAKE=          MAKEOBJDIRPREFIX=${WORLDTMP} \
256                 ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
257                 DESTDIR= \
258                 BOOTSTRAPPING=${OSRELDATE} \
259                 SSP_CFLAGS= \
260                 MK_HTML=no NO_LINT=yes MK_MAN=no \
261                 -DNO_PIC MK_PROFILE=no -DNO_SHARED \
262                 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
263                 MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \
264                 MK_LLDB=no MK_TESTS=no \
265                 MK_INCLUDES=yes 
266
267 # build-tools stage
268 TMAKE=          MAKEOBJDIRPREFIX=${OBJTREE} \
269                 ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
270                 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
271                 DESTDIR= \
272                 BOOTSTRAPPING=${OSRELDATE} \
273                 SSP_CFLAGS= \
274                 -DNO_LINT \
275                 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
276                 MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \
277                 MK_LLDB=no MK_TESTS=no
278
279 # cross-tools stage
280 XMAKE=          TOOLS_PREFIX=${WORLDTMP} ${BMAKE} \
281                 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
282                 MK_GDB=no MK_TESTS=no
283
284 # kernel-tools stage
285 KTMAKEENV=      INSTALL="sh ${.CURDIR}/tools/install.sh" \
286                 PATH=${BPATH}:${PATH} \
287                 WORLDTMP=${WORLDTMP} \
288                 VERSION="${VERSION}"
289 KTMAKE=         TOOLS_PREFIX=${WORLDTMP} MAKEOBJDIRPREFIX=${WORLDTMP} \
290                 ${KTMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
291                 DESTDIR= \
292                 BOOTSTRAPPING=${OSRELDATE} \
293                 SSP_CFLAGS= \
294                 MK_HTML=no -DNO_LINT MK_MAN=no \
295                 -DNO_PIC MK_PROFILE=no -DNO_SHARED \
296                 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no
297
298 # world stage
299 WMAKEENV=       ${CROSSENV} \
300                 _SHLIBDIRPREFIX=${WORLDTMP} \
301                 _LDSCRIPTROOT= \
302                 VERSION="${VERSION}" \
303                 INSTALL="sh ${.CURDIR}/tools/install.sh" \
304                 PATH=${TMPPATH}
305
306 # make hierarchy
307 HMAKE=          PATH=${TMPPATH} ${MAKE} LOCAL_MTREE=${LOCAL_MTREE:Q}
308 .if defined(NO_ROOT)
309 HMAKE+=         PATH=${TMPPATH} METALOG=${METALOG} -DNO_ROOT
310 .endif
311
312 .if ${MK_CDDL} == "no"
313 WMAKEENV+=      MK_CTF=no
314 .endif
315
316 .if defined(CROSS_TOOLCHAIN)
317 LOCALBASE?=     /usr/local
318 .include "${LOCALBASE}/share/toolchains/${CROSS_TOOLCHAIN}.mk"
319 .endif
320 .if defined(CROSS_TOOLCHAIN_PREFIX)
321 CROSS_COMPILER_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
322 CROSS_BINUTILS_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
323 .endif
324
325 # If we do not have a bootstrap binutils (because the in-tree one does not
326 # support the target architecture), provide a default cross-binutils prefix.
327 # This allows aarch64 builds, for example, to automatically use the
328 # aarch64-binutils port or package.
329 .if !empty(BROKEN_OPTIONS:MBINUTILS_BOOTSTRAP) && \
330     !defined(CROSS_BINUTILS_PREFIX)
331 CROSS_BINUTILS_PREFIX=/usr/local/${TARGET_ARCH}-freebsd/bin/
332 .if !exists(${CROSS_BINUTILS_PREFIX})
333 .error In-tree binutils does not support the ${TARGET_ARCH} architecture. Install the ${TARGET_ARCH}-binutils port or package or set CROSS_BINUTILS_PREFIX.
334 .endif
335 .endif
336
337 XCOMPILERS=     CC CXX CPP
338 .for COMPILER in ${XCOMPILERS}
339 .if defined(CROSS_COMPILER_PREFIX)
340 X${COMPILER}?=  ${CROSS_COMPILER_PREFIX}${${COMPILER}}
341 .else
342 X${COMPILER}?=  ${${COMPILER}}
343 .endif
344 .endfor
345 XBINUTILS=      AS AR LD NM OBJCOPY OBJDUMP RANLIB SIZE STRINGS
346 .for BINUTIL in ${XBINUTILS}
347 .if defined(CROSS_BINUTILS_PREFIX)
348 X${BINUTIL}?=   ${CROSS_BINUTILS_PREFIX}${${BINUTIL}}
349 .else
350 X${BINUTIL}?=   ${${BINUTIL}}
351 .endif
352 .endfor
353 WMAKEENV+=      CC="${XCC} ${XCFLAGS}" CXX="${XCXX} ${XCFLAGS} ${XCXXFLAGS}" \
354                 DEPFLAGS="${DEPFLAGS}" \
355                 CPP="${XCPP} ${XCFLAGS}" \
356                 AS="${XAS}" AR="${XAR}" LD="${XLD}" NM=${XNM} \
357                 OBJDUMP=${XOBJDUMP} OBJCOPY="${XOBJCOPY}" \
358                 RANLIB=${XRANLIB} STRINGS=${XSTRINGS} \
359                 SIZE="${XSIZE}"
360
361 .if ${XCC:M/*}
362 .if defined(CROSS_BINUTILS_PREFIX)
363 # In the case of xdev-build tools, CROSS_BINUTILS_PREFIX won't be a
364 # directory, but the compiler will look in the right place for it's
365 # tools so we don't need to tell it where to look.
366 .if exists(${CROSS_BINUTILS_PREFIX})
367 BFLAGS+=        -B${CROSS_BINUTILS_PREFIX}
368 .endif
369 .else
370 BFLAGS+=        -B${WORLDTMP}/usr/bin
371 .endif
372 .if ${TARGET} == "arm"
373 .if ${TARGET_ARCH:M*hf*} != ""
374 TARGET_ABI=     gnueabihf
375 .else
376 TARGET_ABI=     gnueabi
377 .endif
378 .endif
379 .if defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc
380 XCFLAGS+=       -isystem ${WORLDTMP}/usr/include -L${WORLDTMP}/usr/lib
381 XCXXFLAGS+=     -I${WORLDTMP}/usr/include/c++/v1 -std=gnu++11 -L${WORLDTMP}/../lib/libc++
382 DEPFLAGS+=      -I${WORLDTMP}/usr/include/c++/v1
383 .else
384 TARGET_ABI?=    unknown
385 TARGET_TRIPLE?= ${TARGET_ARCH:C/amd64/x86_64/}-${TARGET_ABI}-freebsd11.0
386 XCFLAGS+=       -target ${TARGET_TRIPLE}
387 .endif
388 XCFLAGS+=       --sysroot=${WORLDTMP} ${BFLAGS}
389 XCXXFLAGS+=     --sysroot=${WORLDTMP} ${BFLAGS}
390 .else
391 .if defined(CROSS_BINUTILS_PREFIX) && exists(${CROSS_BINUTILS_PREFIX})
392 BFLAGS+=        -B${CROSS_BINUTILS_PREFIX}
393 XCFLAGS+=       ${BFLAGS}
394 XCXXFLAGS+=     ${BFLAGS}
395 .endif
396 .endif # ${XCC:M/*}
397
398 WMAKE=          ${WMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 DESTDIR=${WORLDTMP}
399
400 .if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64"
401 # 32 bit world
402 LIB32_OBJTREE=  ${OBJTREE}${.CURDIR}/world32
403 LIB32TMP=       ${OBJTREE}${.CURDIR}/lib32
404
405 .if ${TARGET_ARCH} == "amd64"
406 .if empty(TARGET_CPUTYPE)
407 LIB32CPUFLAGS=  -march=i686 -mmmx -msse -msse2
408 .else
409 LIB32CPUFLAGS=  -march=${TARGET_CPUTYPE}
410 .endif
411 LIB32WMAKEENV=  MACHINE=i386 MACHINE_ARCH=i386 \
412                 MACHINE_CPU="i686 mmx sse sse2"
413 LIB32WMAKEFLAGS=        \
414                 AS="${AS} --32" \
415                 LD="${LD} -m elf_i386_fbsd -Y P,${LIB32TMP}/usr/lib32"
416
417 .elif ${TARGET_ARCH} == "powerpc64"
418 .if empty(TARGET_CPUTYPE)
419 LIB32CPUFLAGS=  -mcpu=powerpc
420 .else
421 LIB32CPUFLAGS=  -mcpu=${TARGET_CPUTYPE}
422 .endif
423 LIB32WMAKEENV=  MACHINE=powerpc MACHINE_ARCH=powerpc
424 LIB32WMAKEFLAGS=        \
425                 LD="${LD} -m elf32ppc_fbsd"
426 .endif
427
428
429 LIB32FLAGS=     -m32 ${LIB32CPUFLAGS} -DCOMPAT_32BIT \
430                 -isystem ${LIB32TMP}/usr/include/ \
431                 -L${LIB32TMP}/usr/lib32 \
432                 -B${LIB32TMP}/usr/lib32
433 .if ${XCC:M/*}
434 LIB32FLAGS+=            --sysroot=${WORLDTMP}
435 .endif
436
437 # Yes, the flags are redundant.
438 LIB32WMAKEENV+= MAKEOBJDIRPREFIX=${LIB32_OBJTREE} \
439                 _SHLIBDIRPREFIX=${LIB32TMP} \
440                 _LDSCRIPTROOT=${LIB32TMP} \
441                 VERSION="${VERSION}" \
442                 INSTALL="sh ${.CURDIR}/tools/install.sh" \
443                 PATH=${TMPPATH} \
444                 LIBDIR=/usr/lib32 \
445                 SHLIBDIR=/usr/lib32 \
446                 LIBPRIVATEDIR=/usr/lib32/private \
447                 DTRACE="${DTRACE} -32"
448 LIB32WMAKEFLAGS+= CC="${XCC} ${LIB32FLAGS}" \
449                 CXX="${XCXX} ${LIB32FLAGS}" \
450                 DESTDIR=${LIB32TMP} \
451                 -DCOMPAT_32BIT \
452                 -DLIBRARIES_ONLY \
453                 -DNO_CPU_CFLAGS \
454                 MK_CTF=no \
455                 -DNO_LINT \
456                 MK_TESTS=no
457
458 LIB32WMAKE=     ${LIB32WMAKEENV} ${MAKE} ${LIB32WMAKEFLAGS} \
459                 MK_MAN=no MK_HTML=no
460 LIB32IMAKE=     ${LIB32WMAKE:NINSTALL=*:NDESTDIR=*:N_LDSCRIPTROOT=*} \
461                 MK_TOOLCHAIN=no ${IMAKE_INSTALL}
462 .endif
463
464 IMAKEENV=       ${CROSSENV:N_LDSCRIPTROOT=*}
465 IMAKE=          ${IMAKEENV} ${MAKE} -f Makefile.inc1 \
466                 ${IMAKE_INSTALL} ${IMAKE_MTREE}
467 .if empty(.MAKEFLAGS:M-n)
468 IMAKEENV+=      PATH=${STRICTTMPPATH}:${INSTALLTMP} \
469                 LD_LIBRARY_PATH=${INSTALLTMP} \
470                 PATH_LOCALE=${INSTALLTMP}/locale
471 IMAKE+=         __MAKE_SHELL=${INSTALLTMP}/sh
472 .else
473 IMAKEENV+=      PATH=${TMPPATH}:${INSTALLTMP}
474 .endif
475 .if defined(DB_FROM_SRC)
476 INSTALLFLAGS+=  -N ${.CURDIR}/etc
477 MTREEFLAGS+=    -N ${.CURDIR}/etc
478 .endif
479 _INSTALL_DDIR=  ${DESTDIR}/${DISTDIR}
480 INSTALL_DDIR=   ${_INSTALL_DDIR:S://:/:g:C:/$::}
481 .if defined(NO_ROOT)
482 METALOG?=       ${DESTDIR}/${DISTDIR}/METALOG
483 IMAKE+=         -DNO_ROOT METALOG=${METALOG}
484 INSTALLFLAGS+=  -U -M ${METALOG} -D ${INSTALL_DDIR}
485 MTREEFLAGS+=    -W
486 .endif
487 .if defined(DB_FROM_SRC) || defined(NO_ROOT)
488 IMAKE_INSTALL=  INSTALL="install ${INSTALLFLAGS}"
489 IMAKE_MTREE=    MTREE_CMD="mtree ${MTREEFLAGS}"
490 .endif
491
492 # kernel stage
493 KMAKEENV=       ${WMAKEENV}
494 KMAKE=          ${KMAKEENV} ${MAKE} ${.MAKEFLAGS} ${KERNEL_FLAGS} KERNEL=${INSTKERNNAME}
495
496 #
497 # buildworld
498 #
499 # Attempt to rebuild the entire system, with reasonable chance of
500 # success, regardless of how old your existing system is.
501 #
502 _worldtmp:
503 .if ${.CURDIR:C/[^,]//g} != ""
504 #       The m4 build of sendmail files doesn't like it if ',' is used
505 #       anywhere in the path of it's files.
506         @echo
507         @echo "*** Error: path to source tree contains a comma ','"
508         @echo
509         false
510 .endif
511         @echo
512         @echo "--------------------------------------------------------------"
513         @echo ">>> Rebuilding the temporary build tree"
514         @echo "--------------------------------------------------------------"
515 .if !defined(NO_CLEAN)
516         rm -rf ${WORLDTMP}
517 .if defined(LIB32TMP)
518         rm -rf ${LIB32TMP}
519 .endif
520 .else
521         rm -rf ${WORLDTMP}/legacy/usr/include
522 #       XXX - These three can depend on any header file.
523         rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
524         rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/kdump_subr.c
525         rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
526 .endif
527 .for _dir in \
528     lib usr legacy/bin legacy/usr
529         mkdir -p ${WORLDTMP}/${_dir}
530 .endfor
531         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
532             -p ${WORLDTMP}/legacy/usr >/dev/null
533 .if ${MK_GROFF} != "no"
534         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.groff.dist \
535             -p ${WORLDTMP}/legacy/usr >/dev/null
536 .endif
537         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
538             -p ${WORLDTMP}/usr >/dev/null
539         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
540             -p ${WORLDTMP}/usr/include >/dev/null
541         ln -sf ${.CURDIR}/sys ${WORLDTMP}
542 .if ${MK_DEBUG_FILES} != "no"
543         # We could instead disable debug files for these build stages
544         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
545             -p ${WORLDTMP}/legacy/usr/lib >/dev/null
546         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
547             -p ${WORLDTMP}/usr/lib >/dev/null
548 .endif
549 .if ${MK_TESTS} != "no"
550         mkdir -p ${WORLDTMP}${TESTSBASE}
551         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
552             -p ${WORLDTMP}${TESTSBASE} >/dev/null
553 .endif
554 .for _mtree in ${LOCAL_MTREE}
555         mtree -deU -f ${.CURDIR}/${_mtree} -p ${WORLDTMP} > /dev/null
556 .endfor
557 _legacy:
558         @echo
559         @echo "--------------------------------------------------------------"
560         @echo ">>> stage 1.1: legacy release compatibility shims"
561         @echo "--------------------------------------------------------------"
562         ${_+_}cd ${.CURDIR}; ${BMAKE} legacy
563 _bootstrap-tools:
564         @echo
565         @echo "--------------------------------------------------------------"
566         @echo ">>> stage 1.2: bootstrap tools"
567         @echo "--------------------------------------------------------------"
568         ${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
569 _cleanobj:
570 .if !defined(NO_CLEAN)
571         @echo
572         @echo "--------------------------------------------------------------"
573         @echo ">>> stage 2.1: cleaning up the object tree"
574         @echo "--------------------------------------------------------------"
575         ${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
576 .if defined(LIB32TMP)
577         ${_+_}cd ${.CURDIR}; ${LIB32WMAKE} -f Makefile.inc1 ${CLEANDIR:S/^/par-/}
578 .endif
579 .endif
580 _obj:
581         @echo
582         @echo "--------------------------------------------------------------"
583         @echo ">>> stage 2.2: rebuilding the object tree"
584         @echo "--------------------------------------------------------------"
585         ${_+_}cd ${.CURDIR}; ${WMAKE} par-obj
586 _build-tools:
587         @echo
588         @echo "--------------------------------------------------------------"
589         @echo ">>> stage 2.3: build tools"
590         @echo "--------------------------------------------------------------"
591         ${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
592 _cross-tools:
593         @echo
594         @echo "--------------------------------------------------------------"
595         @echo ">>> stage 3: cross tools"
596         @echo "--------------------------------------------------------------"
597         ${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
598         ${_+_}cd ${.CURDIR}; ${XMAKE} kernel-tools
599 _includes:
600         @echo
601         @echo "--------------------------------------------------------------"
602         @echo ">>> stage 4.1: building includes"
603         @echo "--------------------------------------------------------------"
604         ${_+_}cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
605 _libraries:
606         @echo
607         @echo "--------------------------------------------------------------"
608         @echo ">>> stage 4.2: building libraries"
609         @echo "--------------------------------------------------------------"
610         ${_+_}cd ${.CURDIR}; \
611             ${WMAKE} -DNO_FSCHG MK_HTML=no -DNO_LINT MK_MAN=no \
612             MK_PROFILE=no MK_TESTS=no MK_TESTS_SUPPORT=${MK_TESTS} libraries
613 _depend:
614         @echo
615         @echo "--------------------------------------------------------------"
616         @echo ">>> stage 4.3: make dependencies"
617         @echo "--------------------------------------------------------------"
618         ${_+_}cd ${.CURDIR}; ${WMAKE} par-depend
619 everything:
620         @echo
621         @echo "--------------------------------------------------------------"
622         @echo ">>> stage 4.4: building everything"
623         @echo "--------------------------------------------------------------"
624         ${_+_}cd ${.CURDIR}; ${WMAKE} par-all
625 .if defined(LIB32TMP)
626 build32:
627         @echo
628         @echo "--------------------------------------------------------------"
629         @echo ">>> stage 5.1: building 32 bit shim libraries"
630         @echo "--------------------------------------------------------------"
631         mkdir -p ${LIB32TMP}/usr/include
632         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
633             -p ${LIB32TMP}/usr >/dev/null
634         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
635             -p ${LIB32TMP}/usr/include >/dev/null
636 .if ${MK_DEBUG_FILES} != "no"
637         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
638             -p ${LIB32TMP}/usr/lib >/dev/null
639 .endif
640         mkdir -p ${WORLDTMP}
641         ln -sf ${.CURDIR}/sys ${WORLDTMP}
642 .for _t in obj includes
643         cd ${.CURDIR}/include; ${LIB32WMAKE} DIRPRFX=include/ ${_t}
644         cd ${.CURDIR}/lib; ${LIB32WMAKE} DIRPRFX=lib/ ${_t}
645 .if ${MK_CDDL} != "no"
646         cd ${.CURDIR}/cddl/lib; ${LIB32WMAKE} DIRPRFX=cddl/lib/ ${_t}
647 .endif
648         cd ${.CURDIR}/gnu/lib; ${LIB32WMAKE} DIRPRFX=gnu/lib/ ${_t}
649 .if ${MK_CRYPT} != "no"
650         cd ${.CURDIR}/secure/lib; ${LIB32WMAKE} DIRPRFX=secure/lib/ ${_t}
651 .endif
652 .if ${MK_KERBEROS} != "no"
653         cd ${.CURDIR}/kerberos5/lib; ${LIB32WMAKE} DIRPRFX=kerberos5/lib ${_t}
654 .endif
655 .endfor
656 .for _dir in usr.bin/lex/lib
657         cd ${.CURDIR}/${_dir}; ${LIB32WMAKE} DIRPRFX=${_dir}/ obj
658 .endfor
659 .for _dir in lib/ncurses/ncurses lib/ncurses/ncursesw lib/libmagic
660         cd ${.CURDIR}/${_dir}; \
661             WORLDTMP=${WORLDTMP} \
662             MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \
663             MAKEOBJDIRPREFIX=${LIB32_OBJTREE} ${MAKE} SSP_CFLAGS= DESTDIR= \
664             DIRPRFX=${_dir}/ -DNO_LINT -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
665             build-tools
666 .endfor
667         cd ${.CURDIR}; \
668             ${LIB32WMAKE} -f Makefile.inc1 libraries
669 .for _t in obj depend all
670         cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIB32WMAKE} \
671             DIRPRFX=libexec/rtld-elf/ ${_t}
672         cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIB32WMAKE} \
673             DIRPRFX=usr.bin/ldd ${_t}
674 .endfor
675
676 distribute32 install32:
677         cd ${.CURDIR}/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
678 .if ${MK_CDDL} != "no"
679         cd ${.CURDIR}/cddl/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
680 .endif
681         cd ${.CURDIR}/gnu/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
682 .if ${MK_CRYPT} != "no"
683         cd ${.CURDIR}/secure/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
684 .endif
685 .if ${MK_KERBEROS} != "no"
686         cd ${.CURDIR}/kerberos5/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
687 .endif
688         cd ${.CURDIR}/libexec/rtld-elf; \
689             PROG=ld-elf32.so.1 ${LIB32IMAKE} ${.TARGET:S/32$//}
690         cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIB32IMAKE} ${.TARGET:S/32$//}
691 .endif
692
693 WMAKE_TGTS=
694 .if !defined(SUBDIR_OVERRIDE)
695 WMAKE_TGTS+=    _worldtmp _legacy _bootstrap-tools
696 .endif
697 WMAKE_TGTS+=    _cleanobj _obj _build-tools
698 .if !defined(SUBDIR_OVERRIDE)
699 WMAKE_TGTS+=    _cross-tools
700 .endif
701 WMAKE_TGTS+=    _includes _libraries _depend everything
702 .if defined(LIB32TMP) && ${MK_LIB32} != "no"
703 WMAKE_TGTS+=    build32
704 .endif
705
706 buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
707 .ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
708
709 buildworld_prologue:
710         @echo "--------------------------------------------------------------"
711         @echo ">>> World build started on `LC_ALL=C date`"
712         @echo "--------------------------------------------------------------"
713
714 buildworld_epilogue:
715         @echo
716         @echo "--------------------------------------------------------------"
717         @echo ">>> World build completed on `LC_ALL=C date`"
718         @echo "--------------------------------------------------------------"
719
720 #
721 # We need to have this as a target because the indirection between Makefile
722 # and Makefile.inc1 causes the correct PATH to be used, rather than a
723 # modification of the current environment's PATH.  In addition, we need
724 # to quote multiword values.
725 #
726 buildenvvars:
727         @echo ${WMAKEENV:Q}
728
729 .if ${.TARGETS:Mbuildenv}
730 .if ${.MAKEFLAGS:M-j}
731 .error The buildenv target is incompatible with -j
732 .endif
733 .endif
734 buildenv:
735         @echo Entering world for ${TARGET_ARCH}:${TARGET}
736         @cd ${.CURDIR} && env ${WMAKEENV} ${BUILDENV_SHELL} || true
737
738 TOOLCHAIN_TGTS= ${WMAKE_TGTS:N_depend:Neverything:Nbuild32}
739 toolchain: ${TOOLCHAIN_TGTS}
740 kernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries}
741
742 #
743 # installcheck
744 #
745 # Checks to be sure system is ready for installworld/installkernel.
746 #
747 installcheck: _installcheck_world _installcheck_kernel
748 _installcheck_world:
749 _installcheck_kernel:
750
751 #
752 # Require DESTDIR to be set if installing for a different architecture or
753 # using the user/group database in the source tree.
754 #
755 .if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} || \
756     defined(DB_FROM_SRC)
757 .if !make(distributeworld)
758 _installcheck_world: __installcheck_DESTDIR
759 _installcheck_kernel: __installcheck_DESTDIR
760 __installcheck_DESTDIR:
761 .if !defined(DESTDIR) || empty(DESTDIR)
762         @echo "ERROR: Please set DESTDIR!"; \
763         false
764 .endif
765 .endif
766 .endif
767
768 .if !defined(DB_FROM_SRC)
769 #
770 # Check for missing UIDs/GIDs.
771 #
772 CHECK_UIDS=     auditdistd
773 CHECK_GIDS=     audit
774 .if ${MK_SENDMAIL} != "no"
775 CHECK_UIDS+=    smmsp
776 CHECK_GIDS+=    smmsp
777 .endif
778 .if ${MK_PF} != "no"
779 CHECK_UIDS+=    proxy
780 CHECK_GIDS+=    proxy authpf
781 .endif
782 .if ${MK_UNBOUND} != "no"
783 CHECK_UIDS+=    unbound
784 CHECK_GIDS+=    unbound
785 .endif
786 _installcheck_world: __installcheck_UGID
787 __installcheck_UGID:
788 .for uid in ${CHECK_UIDS}
789         @if ! `id -u ${uid} >/dev/null 2>&1`; then \
790                 echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
791                 false; \
792         fi
793 .endfor
794 .for gid in ${CHECK_GIDS}
795         @if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
796                 echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
797                 false; \
798         fi
799 .endfor
800 .endif
801
802 #
803 # Required install tools to be saved in a scratch dir for safety.
804 #
805 .if ${MK_ZONEINFO} != "no"
806 _zoneinfo=      zic tzsetup
807 .endif
808
809 ITOOLS= [ awk cap_mkdb cat chflags chmod chown \
810         date echo egrep find grep id install ${_install-info} \
811         ln lockf make mkdir mtree mv pwd_mkdb \
812         rm sed services_mkdb sh strip sysctl test true uname wc ${_zoneinfo} \
813         ${LOCAL_ITOOLS}
814
815 # Needed for share/man
816 .if ${MK_MAN} != "no"
817 ITOOLS+=makewhatis
818 .endif
819
820 #
821 # distributeworld
822 #
823 # Distributes everything compiled by a `buildworld'.
824 #
825 # installworld
826 #
827 # Installs everything compiled by a 'buildworld'.
828 #
829
830 # Non-base distributions produced by the base system
831 EXTRA_DISTRIBUTIONS=    doc
832 .if defined(LIB32TMP) && ${MK_LIB32} != "no"
833 EXTRA_DISTRIBUTIONS+=   lib32
834 .endif
835 .if ${MK_TESTS} != "no"
836 EXTRA_DISTRIBUTIONS+=   tests
837 .endif
838
839 DEBUG_DISTRIBUTIONS=
840 .if ${MK_DEBUG_FILES} != "no"
841 DEBUG_DISTRIBUTIONS+=   base ${EXTRA_DISTRIBUTIONS:S,doc,,:S,tests,,}
842 .endif
843
844 MTREE_MAGIC?=   mtree 2.0
845
846 distributeworld installworld: _installcheck_world
847         mkdir -p ${INSTALLTMP}
848         progs=$$(for prog in ${ITOOLS}; do \
849                 if progpath=`which $$prog`; then \
850                         echo $$progpath; \
851                 else \
852                         echo "Required tool $$prog not found in PATH." >&2; \
853                         exit 1; \
854                 fi; \
855             done); \
856         libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
857             while read line; do \
858                 set -- $$line; \
859                 if [ "$$2 $$3" != "not found" ]; then \
860                         echo $$2; \
861                 else \
862                         echo "Required library $$1 not found." >&2; \
863                         exit 1; \
864                 fi; \
865             done); \
866         cp $$libs $$progs ${INSTALLTMP}
867         cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
868 .if defined(NO_ROOT)
869         echo "#${MTREE_MAGIC}" > ${METALOG}
870 .endif
871 .if make(distributeworld)
872 .for dist in ${EXTRA_DISTRIBUTIONS}
873         -mkdir ${DESTDIR}/${DISTDIR}/${dist}
874         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
875             -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null
876         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
877             -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
878         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
879             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
880 .if ${MK_DEBUG_FILES} != "no"
881         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
882             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib >/dev/null
883 .endif
884 .if ${MK_TESTS} != "no" && ${dist} == "tests"
885         -mkdir -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE}
886         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
887             -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE} >/dev/null
888 .endif
889 .if defined(NO_ROOT)
890         ${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
891             sed -e 's#^\./#./${dist}/#' >> ${METALOG}
892         ${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
893             sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
894         ${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
895             sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
896 .endif
897 .endfor
898         -mkdir ${DESTDIR}/${DISTDIR}/base
899         cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
900             METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
901             DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
902             LOCAL_MTREE=${LOCAL_MTREE:Q} distrib-dirs
903 .endif
904         ${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
905             ${IMAKEENV} rm -rf ${INSTALLTMP}
906 .if make(distributeworld)
907 .for dist in ${EXTRA_DISTRIBUTIONS}
908         find ${DESTDIR}/${DISTDIR}/${dist} -mindepth 1 -empty -delete
909 .endfor
910 .if defined(NO_ROOT)
911 .for dist in base ${EXTRA_DISTRIBUTIONS}
912         @# For each file that exists in this dist, print the corresponding
913         @# line from the METALOG.  This relies on the fact that
914         @# a line containing only the filename will sort immediatly before
915         @# the relevant mtree line.
916         cd ${DESTDIR}/${DISTDIR}; \
917         find ./${dist} | sort -u ${METALOG} - | \
918         awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
919         ${DESTDIR}/${DISTDIR}/${dist}.meta
920 .endfor
921 .for dist in ${DEBUG_DISTRIBUTIONS}
922         @# For each file that exists in this dist, print the corresponding
923         @# line from the METALOG.  This relies on the fact that
924         @# a line containing only the filename will sort immediatly before
925         @# the relevant mtree line.
926         cd ${DESTDIR}/${DISTDIR}; \
927         find ./${dist}/usr/lib/debug | sort -u ${METALOG} - | \
928         awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
929         ${DESTDIR}/${DISTDIR}/${dist}.debug.meta
930 .endfor
931 .endif
932 .endif
933
934 packageworld:
935 .for dist in base ${EXTRA_DISTRIBUTIONS}
936 .if defined(NO_ROOT)
937         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
938             tar cvf - --exclude usr/lib/debug \
939             @${DESTDIR}/${DISTDIR}/${dist}.meta | \
940             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/${dist}.txz
941 .else
942         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
943             tar cvf - --exclude usr/lib/debug . | \
944             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/${dist}.txz
945 .endif
946 .endfor
947
948 .for dist in ${DEBUG_DISTRIBUTIONS}
949 . if defined(NO_ROOT)
950         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
951             tar cvf - @${DESTDIR}/${DISTDIR}/${dist}.debug.meta | \
952             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/${dist}-dbg.txz
953 . else
954         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
955             tar cvLf - usr/lib/debug | \
956             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/${dist}-dbg.txz
957 . endif
958 .endfor
959
960 #
961 # reinstall
962 #
963 # If you have a build server, you can NFS mount the source and obj directories
964 # and do a 'make reinstall' on the *client* to install new binaries from the
965 # most recent server build.
966 #
967 reinstall: .MAKE
968         @echo "--------------------------------------------------------------"
969         @echo ">>> Making hierarchy"
970         @echo "--------------------------------------------------------------"
971         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
972             LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy
973         @echo
974         @echo "--------------------------------------------------------------"
975         @echo ">>> Installing everything"
976         @echo "--------------------------------------------------------------"
977         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
978 .if defined(LIB32TMP) && ${MK_LIB32} != "no"
979         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
980 .endif
981
982 redistribute: .MAKE
983         @echo "--------------------------------------------------------------"
984         @echo ">>> Distributing everything"
985         @echo "--------------------------------------------------------------"
986         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
987 .if defined(LIB32TMP) && ${MK_LIB32} != "no"
988         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute32 \
989             DISTRIBUTION=lib32
990 .endif
991
992 distrib-dirs distribution: .MAKE
993         cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
994             ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
995
996 #
997 # buildkernel and installkernel
998 #
999 # Which kernels to build and/or install is specified by setting
1000 # KERNCONF. If not defined a GENERIC kernel is built/installed.
1001 # Only the existing (depending TARGET) config files are used
1002 # for building kernels and only the first of these is designated
1003 # as the one being installed.
1004 #
1005 # Note that we have to use TARGET instead of TARGET_ARCH when
1006 # we're in kernel-land. Since only TARGET_ARCH is (expected) to
1007 # be set to cross-build, we have to make sure TARGET is set
1008 # properly.
1009
1010 .if defined(KERNFAST)
1011 NO_KERNELCLEAN= t
1012 NO_KERNELCONFIG=        t
1013 NO_KERNELDEPEND=        t
1014 NO_KERNELOBJ=           t
1015 # Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
1016 .if !defined(KERNCONF) && ${KERNFAST} != "1"
1017 KERNCONF=${KERNFAST}
1018 .endif
1019 .endif
1020 .if ${TARGET_ARCH} == "powerpc64"
1021 KERNCONF?=      GENERIC64
1022 .else
1023 KERNCONF?=      GENERIC
1024 .endif
1025 INSTKERNNAME?=  kernel
1026
1027 KERNSRCDIR?=    ${.CURDIR}/sys
1028 KRNLCONFDIR=    ${KERNSRCDIR}/${TARGET}/conf
1029 KRNLOBJDIR=     ${OBJTREE}${KERNSRCDIR}
1030 KERNCONFDIR?=   ${KRNLCONFDIR}
1031
1032 BUILDKERNELS=
1033 INSTALLKERNEL=
1034 .for _kernel in ${KERNCONF}
1035 .if exists(${KERNCONFDIR}/${_kernel})
1036 BUILDKERNELS+=  ${_kernel}
1037 .if empty(INSTALLKERNEL)
1038 INSTALLKERNEL= ${_kernel}
1039 .endif
1040 .endif
1041 .endfor
1042
1043 buildkernel ${WMAKE_TGTS} ${.ALLTARGETS:M_*}: .MAKE
1044
1045 #
1046 # buildkernel
1047 #
1048 # Builds all kernels defined by BUILDKERNELS.
1049 #
1050 buildkernel:
1051 .if empty(BUILDKERNELS)
1052         @echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
1053         false
1054 .endif
1055         @echo
1056 .for _kernel in ${BUILDKERNELS}
1057         @echo "--------------------------------------------------------------"
1058         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
1059         @echo "--------------------------------------------------------------"
1060         @echo "===> ${_kernel}"
1061         mkdir -p ${KRNLOBJDIR}
1062 .if !defined(NO_KERNELCONFIG)
1063         @echo
1064         @echo "--------------------------------------------------------------"
1065         @echo ">>> stage 1: configuring the kernel"
1066         @echo "--------------------------------------------------------------"
1067         cd ${KRNLCONFDIR}; \
1068                 PATH=${TMPPATH} \
1069                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
1070                         -I '${KERNCONFDIR}' '${KERNCONFDIR}/${_kernel}'
1071 .endif
1072 .if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
1073         @echo
1074         @echo "--------------------------------------------------------------"
1075         @echo ">>> stage 2.1: cleaning up the object tree"
1076         @echo "--------------------------------------------------------------"
1077         cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
1078 .endif
1079 .if !defined(NO_KERNELOBJ)
1080         @echo
1081         @echo "--------------------------------------------------------------"
1082         @echo ">>> stage 2.2: rebuilding the object tree"
1083         @echo "--------------------------------------------------------------"
1084         cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
1085 .endif
1086         @echo
1087         @echo "--------------------------------------------------------------"
1088         @echo ">>> stage 2.3: build tools"
1089         @echo "--------------------------------------------------------------"
1090         ${_+_}cd ${.CURDIR}; ${KTMAKE} kernel-tools
1091 .if !defined(NO_KERNELDEPEND)
1092         @echo
1093         @echo "--------------------------------------------------------------"
1094         @echo ">>> stage 3.1: making dependencies"
1095         @echo "--------------------------------------------------------------"
1096         cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} depend -DNO_MODULES_OBJ
1097 .endif
1098         @echo
1099         @echo "--------------------------------------------------------------"
1100         @echo ">>> stage 3.2: building everything"
1101         @echo "--------------------------------------------------------------"
1102         cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
1103         @echo "--------------------------------------------------------------"
1104         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
1105         @echo "--------------------------------------------------------------"
1106 .endfor
1107
1108 #
1109 # installkernel, etc.
1110 #
1111 # Install the kernel defined by INSTALLKERNEL
1112 #
1113 installkernel installkernel.debug \
1114 reinstallkernel reinstallkernel.debug: _installcheck_kernel
1115 .if empty(INSTALLKERNEL)
1116         @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1117         false
1118 .endif
1119         @echo "--------------------------------------------------------------"
1120         @echo ">>> Installing kernel ${INSTALLKERNEL}"
1121         @echo "--------------------------------------------------------------"
1122         cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1123             ${CROSSENV} PATH=${TMPPATH} \
1124             ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
1125
1126 distributekernel distributekernel.debug:
1127 .if empty(INSTALLKERNEL)
1128         @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1129         false
1130 .endif
1131         mkdir -p ${DESTDIR}/${DISTDIR}
1132 .if defined(NO_ROOT)
1133         echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta
1134 .endif
1135         cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1136             ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.premeta/} \
1137             ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \
1138             DESTDIR=${INSTALL_DDIR}/kernel \
1139             ${.TARGET:S/distributekernel/install/}
1140 .if defined(NO_ROOT)
1141         sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
1142             ${DESTDIR}/${DISTDIR}/kernel.meta
1143 .endif
1144 .for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
1145 .if defined(NO_ROOT)
1146         echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
1147 .endif
1148         cd ${KRNLOBJDIR}/${_kernel}; \
1149             ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.${_kernel}.premeta/} \
1150             ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} \
1151             KERNEL=${INSTKERNNAME}.${_kernel} \
1152             DESTDIR=${INSTALL_DDIR}/kernel.${_kernel} \
1153             ${.TARGET:S/distributekernel/install/}
1154 .if defined(NO_ROOT)
1155         sed -e 's|^./kernel|.|' \
1156             ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta > \
1157             ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
1158 .endif
1159 .endfor
1160
1161 packagekernel:
1162 .if defined(NO_ROOT)
1163         cd ${DESTDIR}/${DISTDIR}/kernel; \
1164             tar cvf - @${DESTDIR}/${DISTDIR}/kernel.meta | \
1165             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.txz
1166 .for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
1167         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1168             tar cvf - @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1169             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.txz
1170 .endfor
1171 .else
1172         cd ${DESTDIR}/${DISTDIR}/kernel; \
1173             tar cvf - . | \
1174             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.txz
1175 .for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
1176         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1177             tar cvf - . | \
1178             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.txz
1179 .endfor
1180 .endif
1181
1182 #
1183 # doxygen
1184 #
1185 # Build the API documentation with doxygen
1186 #
1187 doxygen:
1188         @if [ ! -x `/usr/bin/which doxygen` ]; then \
1189                 echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
1190                 exit 1; \
1191         fi
1192         cd ${.CURDIR}/tools/kerneldoc/subsys && ${MAKE} obj all
1193
1194 #
1195 # update
1196 #
1197 # Update the source tree(s), by running svn/svnup to update to the
1198 # latest copy.
1199 #
1200 update:
1201 .if (defined(CVS_UPDATE) || defined(SUP_UPDATE)) && !defined(SVN_UPDATE)
1202         @echo "--------------------------------------------------------------"
1203         @echo "CVS_UPDATE and SUP_UPDATE are no longer supported."
1204         @echo "Please see: https://wiki.freebsd.org/CvsIsDeprecated"
1205         @echo "--------------------------------------------------------------"
1206         @exit 1
1207 .endif
1208 .if defined(SVN_UPDATE)
1209         @echo "--------------------------------------------------------------"
1210         @echo ">>> Updating ${.CURDIR} using Subversion"
1211         @echo "--------------------------------------------------------------"
1212         @(cd ${.CURDIR} && ${SVN} update ${SVNFLAGS})
1213 .endif
1214
1215 #
1216 # ------------------------------------------------------------------------
1217 #
1218 # From here onwards are utility targets used by the 'make world' and
1219 # related targets.  If your 'world' breaks, you may like to try to fix
1220 # the problem and manually run the following targets to attempt to
1221 # complete the build.  Beware, this is *not* guaranteed to work, you
1222 # need to have a pretty good grip on the current state of the system
1223 # to attempt to manually finish it.  If in doubt, 'make world' again.
1224 #
1225
1226 #
1227 # legacy: Build compatibility shims for the next three targets. This is a minimal
1228 # set of tools and shims necessary to compensate for older systems which don't have
1229 # the APIs that the targets built in bootstrap-tools, build-tools or cross-tools.
1230 #
1231 legacy:
1232 .if ${BOOTSTRAPPING} < 800107 && ${BOOTSTRAPPING} != 0
1233         @echo "ERROR: Source upgrades from versions prior to 8.0 not supported."; \
1234         false
1235 .endif
1236 .for _tool in tools/build
1237         ${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \
1238             cd ${.CURDIR}/${_tool} && \
1239             ${MAKE} DIRPRFX=${_tool}/ obj && \
1240             ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes && \
1241             ${MAKE} DIRPRFX=${_tool}/ depend && \
1242             ${MAKE} DIRPRFX=${_tool}/ all && \
1243             ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1244 .endfor
1245
1246 #
1247 # bootstrap-tools: Build tools needed for compatibility. These are binaries that
1248 # are built to build other binaries in the system. However, the focus of these
1249 # binaries is usually quite narrow. Bootstrap tools use the host's compiler and
1250 # libraries, augmented by -legacy.
1251 #
1252 _bt=            _bootstrap-tools        
1253
1254 .if ${MK_GAMES} != "no"
1255 _strfile=       games/fortune/strfile
1256 .endif
1257
1258 .if ${MK_CXX} != "no"
1259 _gperf=         gnu/usr.bin/gperf
1260 .endif
1261
1262 .if ${MK_GROFF} != "no"
1263 _groff=         gnu/usr.bin/groff
1264 .endif
1265
1266 .if ${MK_VT} != "no"
1267 _vtfontcvt=     usr.bin/vtfontcvt
1268 .endif
1269
1270 .if ${BOOTSTRAPPING} < 900002
1271 _sed=           usr.bin/sed
1272 .endif
1273
1274 .if ${BOOTSTRAPPING} < 1000002
1275 _m4=            lib/libohash \
1276                 usr.bin/m4
1277
1278 ${_bt}-usr.bin/m4: ${_bt}-lib/libohash
1279 .endif
1280
1281 .if ${BOOTSTRAPPING} < 1000014
1282 _crunch=        usr.sbin/crunch
1283 .endif
1284
1285 .if ${BOOTSTRAPPING} < 1000026
1286 _nmtree=        lib/libnetbsd \
1287                 usr.sbin/nmtree
1288
1289 ${_bt}-usr.sbin/nmtree: ${_bt}-lib/libnetbsd
1290 .endif
1291
1292 .if ${BOOTSTRAPPING} < 1000027
1293 _cat=           bin/cat
1294 .endif
1295
1296 .if ${BOOTSTRAPPING} < 1000033
1297 _lex=           usr.bin/lex
1298 .endif
1299
1300 .if ${BOOTSTRAPPING} >= 900040 && ${BOOTSTRAPPING} < 900041
1301 _awk=           usr.bin/awk
1302 .endif
1303
1304 .if ${BOOTSTRAPPING} < 1001506
1305 _yacc=          lib/liby \
1306                 usr.bin/yacc
1307
1308 ${_bt}-usr.bin/yacc: ${_bt}-lib/liby
1309 .endif
1310
1311 .if ${MK_BSNMP} != "no"
1312 _gensnmptree=   usr.sbin/bsnmpd/gensnmptree
1313 .endif
1314
1315 # We need to build tblgen when we're building clang either as
1316 # the bootstrap compiler, or as the part of the normal build.
1317 .if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_CLANG} != "no"
1318 _clang_tblgen= \
1319         lib/clang/libllvmsupport \
1320         lib/clang/libllvmtablegen \
1321         usr.bin/clang/tblgen \
1322         usr.bin/clang/clang-tblgen
1323
1324 ${_bt}-usr.bin/clang/clang-tblgen: ${_bt}-lib/clang/libllvmtablegen ${_bt}-lib/clang/libllvmsupport
1325 ${_bt}-usr.bin/clang/tblgen: ${_bt}-lib/clang/libllvmtablegen ${_bt}-lib/clang/libllvmsupport
1326 .endif
1327
1328 # ELF Tool Chain libraries are needed for ELF tools and dtrace tools.
1329 # dtrace tools are required for older bootstrap env and cross-build
1330 # pre libdwarf
1331 .if ${BOOTSTRAPPING} < 1100006 || (${MACHINE} != ${TARGET} || \
1332     ${MACHINE_ARCH} != ${TARGET_ARCH})
1333 _elftoolchain_libs= lib/libelf lib/libdwarf 
1334 .if ${MK_CDDL} != "no"
1335 _dtrace_tools= cddl/usr.bin/sgsmsg cddl/lib/libctf cddl/usr.bin/ctfconvert \
1336     cddl/usr.bin/ctfmerge
1337
1338 ${_bt}-cddl/usr.bin/ctfconvert: ${_bt}-lib/libelf ${_bt}-lib/libdwarf ${_bt}-cddl/lib/libctf
1339 ${_bt}-cddl/usr.bin/ctfmerge: ${_bt}-lib/libelf ${_bt}-lib/libdwarf ${_bt}-cddl/lib/libctf
1340 .endif
1341 .endif
1342
1343 # Default to building the GPL DTC, but build the BSDL one if users explicitly
1344 # request it.
1345 _dtc= usr.bin/dtc
1346 .if ${MK_GPL_DTC} != "no"
1347 _dtc= gnu/usr.bin/dtc
1348 .endif
1349
1350 .if ${MK_KERBEROS} != "no"
1351 _kerberos5_bootstrap_tools= \
1352         kerberos5/tools/make-roken \
1353         kerberos5/lib/libroken \
1354         kerberos5/lib/libvers \
1355         kerberos5/tools/asn1_compile \
1356         kerberos5/tools/slc \
1357         usr.bin/compile_et
1358
1359 ${_bt}-kerberos5/tools/slc: ${_bt}-kerberos5/lib/libroken
1360 ${_bt}-kerberos5/tools/asn1_compile: ${_bt}-kerberos5/lib/libroken
1361 .endif
1362
1363 bootstrap-tools: .PHONY
1364
1365 #       Please document (add comment) why something is in 'bootstrap-tools'.
1366 #       Try to bound the building of the bootstrap-tool to just the
1367 #       FreeBSD versions that need the tool built at this stage of the build.
1368 .for _tool in \
1369     ${_clang_tblgen} \
1370     ${_kerberos5_bootstrap_tools} \
1371     ${_elftoolchain_libs} \
1372     ${_dtrace_tools} \
1373     ${_strfile} \
1374     ${_gperf} \
1375     ${_groff} \
1376     ${_dtc} \
1377     ${_awk} \
1378     ${_cat} \
1379     usr.bin/lorder \
1380     usr.bin/makewhatis \
1381     usr.bin/rpcgen \
1382     ${_sed} \
1383     ${_yacc} \
1384     ${_m4} \
1385     ${_lex} \
1386     lib/libmd \
1387     usr.bin/xinstall \
1388     ${_gensnmptree} \
1389     usr.sbin/config \
1390     ${_crunch} \
1391     ${_nmtree} \
1392     ${_vtfontcvt}
1393 ${_bt}-${_tool}: .PHONY .MAKE
1394         ${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1395                 cd ${.CURDIR}/${_tool} && \
1396                 ${MAKE} DIRPRFX=${_tool}/ obj && \
1397                 ${MAKE} DIRPRFX=${_tool}/ depend && \
1398                 ${MAKE} DIRPRFX=${_tool}/ all && \
1399                 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1400
1401 bootstrap-tools: ${_bt}-${_tool}
1402 .endfor
1403
1404 #
1405 # build-tools: Build special purpose build tools
1406 #
1407 .if !defined(NO_SHARE)
1408 _share= share/syscons/scrnmaps
1409 .endif
1410
1411 .if ${MK_GCC} != "no"
1412 _gcc_tools= gnu/usr.bin/cc/cc_tools
1413 .endif
1414
1415 .if ${MK_RESCUE} != "no"
1416 _rescue= rescue/rescue
1417 .endif
1418
1419 build-tools: .MAKE
1420 .for _tool in \
1421     bin/csh \
1422     bin/sh \
1423     ${_rescue} \
1424     ${LOCAL_TOOL_DIRS} \
1425     lib/ncurses/ncurses \
1426     lib/ncurses/ncursesw \
1427     ${_share} \
1428     usr.bin/awk \
1429     lib/libmagic \
1430     usr.bin/mkesdb_static \
1431     usr.bin/mkcsmapper_static \
1432     usr.bin/vi/catalog
1433         ${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
1434                 cd ${.CURDIR}/${_tool} && \
1435                 ${MAKE} DIRPRFX=${_tool}/ obj && \
1436                 ${MAKE} DIRPRFX=${_tool}/ build-tools
1437 .endfor
1438 .for _tool in \
1439     ${_gcc_tools}
1440         ${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
1441                 cd ${.CURDIR}/${_tool} && \
1442                 ${MAKE} DIRPRFX=${_tool}/ obj && \
1443                 ${MAKE} DIRPRFX=${_tool}/ depend && \
1444                 ${MAKE} DIRPRFX=${_tool}/ all
1445 .endfor
1446
1447 #
1448 # kernel-tools: Build kernel-building tools
1449 #
1450 kernel-tools: .MAKE
1451         mkdir -p ${MAKEOBJDIRPREFIX}/usr
1452         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1453             -p ${MAKEOBJDIRPREFIX}/usr >/dev/null
1454
1455 #
1456 # cross-tools: All the tools needed to build the rest of the system after
1457 # we get done with the earlier stages. It is the last set of tools needed
1458 # to begin building the target binaries.
1459 #
1460 .if ${TARGET_ARCH} != ${MACHINE_ARCH}
1461 .if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
1462 _btxld=         usr.sbin/btxld
1463 .endif
1464 .endif
1465 .if ${TARGET_ARCH} != ${MACHINE_ARCH}
1466 .if ${MK_RESCUE} != "no" || defined(RELEASEDIR)
1467 _crunchide=     usr.sbin/crunch/crunchide
1468 .endif
1469 .if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR)
1470 _kgzip=         usr.sbin/kgzip
1471 .endif
1472 .endif
1473
1474 # If we're given an XAS, don't build binutils.
1475 .if ${XAS:M/*} == ""
1476 .if ${MK_BINUTILS_BOOTSTRAP} != "no"
1477 _binutils=      gnu/usr.bin/binutils
1478 .endif
1479 .if ${MK_ELFTOOLCHAIN_TOOLS} != "no"
1480 _elftctools=    lib/libelftc \
1481                 usr.bin/elfcopy \
1482                 usr.bin/nm \
1483                 usr.bin/size \
1484                 usr.bin/strings
1485 # These are not required by the build, but can be useful for developers who
1486 # cross-build on a FreeBSD 10 host:
1487 _elftctools+=   usr.bin/addr2line
1488 .endif
1489 .elif ${TARGET_ARCH} != ${MACHINE_ARCH} && ${MK_ELFTOOLCHAIN_TOOLS} != "no"
1490 # If cross-building with an external binutils we still need to build strip for
1491 # the target (for at least crunchide).
1492 _elftctools=    lib/libelftc \
1493                 usr.bin/elfcopy
1494 .endif
1495
1496 # If an full path to an external cross compiler is given, don't build
1497 # a cross compiler.
1498 .if ${XCC:M/*} == "" && ${MK_CROSS_COMPILER} != "no"
1499 .if ${MK_CLANG_BOOTSTRAP} != "no"
1500 _clang=         usr.bin/clang
1501 _clang_libs=    lib/clang
1502 .endif
1503 .if ${MK_GCC_BOOTSTRAP} != "no"
1504 _cc=            gnu/usr.bin/cc
1505 .endif
1506 .endif
1507
1508 cross-tools: .MAKE
1509 .for _tool in \
1510     ${_clang_libs} \
1511     ${_clang} \
1512     ${_binutils} \
1513     ${_elftctools} \
1514     ${_cc} \
1515     ${_btxld} \
1516     ${_crunchide} \
1517     ${_kgzip} \
1518     sys/boot/usb/tools
1519         ${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1520                 cd ${.CURDIR}/${_tool} && \
1521                 ${MAKE} DIRPRFX=${_tool}/ obj && \
1522                 ${MAKE} DIRPRFX=${_tool}/ depend && \
1523                 ${MAKE} DIRPRFX=${_tool}/ all && \
1524                 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
1525 .endfor
1526
1527 NXBENV=         MAKEOBJDIRPREFIX=${OBJTREE}/nxb \
1528                 INSTALL="sh ${.CURDIR}/tools/install.sh" \
1529                 VERSION="${VERSION}"
1530 NXBMAKE=        ${NXBENV} ${MAKE} \
1531                 TBLGEN=${OBJTREE}/nxb-bin/usr/bin/tblgen \
1532                 CLANG_TBLGEN=${OBJTREE}/nxb-bin/usr/bin/clang-tblgen \
1533                 MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH} \
1534                 MK_GDB=no MK_TESTS=no \
1535                 SSP_CFLAGS= \
1536                 MK_HTML=no NO_LINT=yes MK_MAN=no \
1537                 -DNO_PIC MK_PROFILE=no -DNO_SHARED \
1538                 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
1539                 MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \
1540                 MK_LLDB=no
1541
1542 native-xtools: .MAKE
1543         mkdir -p ${OBJTREE}/nxb-bin/bin
1544         mkdir -p ${OBJTREE}/nxb-bin/sbin
1545         mkdir -p ${OBJTREE}/nxb-bin/usr
1546         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1547             -p ${OBJTREE}/nxb-bin/usr >/dev/null
1548         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1549             -p ${OBJTREE}/nxb-bin/usr/include >/dev/null
1550 .for _tool in \
1551     bin/cat \
1552     bin/chmod \
1553     bin/cp \
1554     bin/csh \
1555     bin/echo \
1556     bin/expr \
1557     bin/hostname \
1558     bin/ln \
1559     bin/ls \
1560     bin/mkdir \
1561     bin/mv \
1562     bin/ps \
1563     bin/realpath \
1564     bin/rm \
1565     bin/rmdir \
1566     bin/sh \
1567     bin/sleep \
1568     ${_clang_tblgen} \
1569     usr.bin/ar \
1570     ${_binutils} \
1571     ${_elftctools} \
1572     ${_cc} \
1573     ${_gcc_tools} \
1574     ${_clang_libs} \
1575     ${_clang} \
1576     sbin/md5 \
1577     sbin/sysctl \
1578     gnu/usr.bin/diff \
1579     usr.bin/awk \
1580     usr.bin/basename \
1581     usr.bin/bmake \
1582     usr.bin/bzip2 \
1583     usr.bin/cmp \
1584     usr.bin/dirname \
1585     usr.bin/env \
1586     usr.bin/fetch \
1587     usr.bin/find \
1588     usr.bin/grep \
1589     usr.bin/gzip \
1590     usr.bin/id \
1591     usr.bin/lex \
1592     usr.bin/lorder \
1593     usr.bin/mktemp \
1594     usr.bin/mt \
1595     usr.bin/patch \
1596     usr.bin/sed \
1597     usr.bin/sort \
1598     usr.bin/tar \
1599     usr.bin/touch \
1600     usr.bin/tr \
1601     usr.bin/true \
1602     usr.bin/uniq \
1603     usr.bin/unzip \
1604     usr.bin/xargs \
1605     usr.bin/xinstall \
1606     usr.bin/xz \
1607     usr.bin/yacc \
1608     usr.sbin/chown
1609         ${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1610                 cd ${.CURDIR}/${_tool} && \
1611                 ${NXBMAKE} DIRPRFX=${_tool}/ obj && \
1612                 ${NXBMAKE} DIRPRFX=${_tool}/ depend && \
1613                 ${NXBMAKE} DIRPRFX=${_tool}/ all && \
1614                 ${NXBMAKE} DIRPRFX=${_tool}/ DESTDIR=${OBJTREE}/nxb-bin install
1615 .endfor
1616
1617 #
1618 # hierarchy - ensure that all the needed directories are present
1619 #
1620 hierarchy hier: .MAKE
1621         cd ${.CURDIR}/etc && ${HMAKE} distrib-dirs
1622
1623 #
1624 # libraries - build all libraries, and install them under ${DESTDIR}.
1625 #
1626 # The list of libraries with dependents (${_prebuild_libs}) and their
1627 # interdependencies (__L) are built automatically by the
1628 # ${.CURDIR}/tools/make_libdeps.sh script.
1629 #
1630 libraries: .MAKE
1631         cd ${.CURDIR} && \
1632             ${MAKE} -f Makefile.inc1 _prereq_libs && \
1633             ${MAKE} -f Makefile.inc1 _startup_libs && \
1634             ${MAKE} -f Makefile.inc1 _prebuild_libs && \
1635             ${MAKE} -f Makefile.inc1 _generic_libs
1636
1637 #
1638 # static libgcc.a prerequisite for shared libc
1639 #
1640 _prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc lib/libcompiler_rt
1641
1642 # These dependencies are not automatically generated:
1643 #
1644 # gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before
1645 # all shared libraries for ELF.
1646 #
1647 _startup_libs=  gnu/lib/csu
1648 .if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
1649 _startup_libs+= lib/csu/${MACHINE_ARCH}-elf
1650 .elif exists(${.CURDIR}/lib/csu/${MACHINE_ARCH})
1651 _startup_libs+= lib/csu/${MACHINE_ARCH}
1652 .else
1653 _startup_libs+= lib/csu/${MACHINE_CPUARCH}
1654 .endif
1655 _startup_libs+= gnu/lib/libgcc
1656 _startup_libs+= lib/libcompiler_rt
1657 _startup_libs+= lib/libc
1658 _startup_libs+= lib/libc_nonshared
1659 .if ${MK_LIBCPLUSPLUS} != "no"
1660 _startup_libs+= lib/libcxxrt
1661 .endif
1662
1663 gnu/lib/libgcc__L: lib/libc__L
1664 gnu/lib/libgcc__L: lib/libc_nonshared__L
1665 .if ${MK_LIBCPLUSPLUS} != "no"
1666 lib/libcxxrt__L: gnu/lib/libgcc__L
1667 .endif
1668
1669 _prebuild_libs= ${_kerberos5_lib_libasn1} \
1670                 ${_kerberos5_lib_libhdb} \
1671                 ${_kerberos5_lib_libheimbase} \
1672                 ${_kerberos5_lib_libheimntlm} \
1673                 ${_kerberos5_lib_libheimsqlite} \
1674                 ${_kerberos5_lib_libheimipcc} \
1675                 ${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
1676                 ${_kerberos5_lib_libroken} \
1677                 ${_kerberos5_lib_libwind} \
1678                 lib/libbz2 ${_libcom_err} lib/libcrypt \
1679                 lib/libelf lib/libexpat \
1680                 lib/libfigpar \
1681                 ${_lib_libgssapi} \
1682                 lib/libkiconv lib/libkvm lib/liblzma lib/libmd lib/libnv \
1683                 ${_lib_libcapsicum} \
1684                 lib/ncurses/ncurses lib/ncurses/ncursesw \
1685                 lib/libopie lib/libpam ${_lib_libthr} \
1686                 ${_lib_libradius} lib/libsbuf lib/libtacplus \
1687                 lib/libgeom \
1688                 ${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \
1689                 ${_cddl_lib_libuutil} \
1690                 ${_cddl_lib_libavl} \
1691                 ${_cddl_lib_libzfs_core} \
1692                 ${_cddl_lib_libctf} \
1693                 lib/libutil lib/libpjdlog ${_lib_libypclnt} lib/libz lib/msun \
1694                 ${_secure_lib_libcrypto} ${_lib_libldns} \
1695                 ${_secure_lib_libssh} ${_secure_lib_libssl} \
1696                 gnu/lib/libdialog
1697 .if ${MK_GNUCXX} != "no"
1698 _prebuild_libs+= gnu/lib/libstdc++ gnu/lib/libsupc++
1699 gnu/lib/libstdc++__L: lib/msun__L
1700 gnu/lib/libsupc++__L: gnu/lib/libstdc++__L
1701 .endif
1702
1703 .if ${MK_LIBCPLUSPLUS} != "no"
1704 _prebuild_libs+= lib/libc++
1705 .endif
1706
1707 lib/libgeom__L: lib/libexpat__L
1708
1709 .if ${MK_LIBTHR} != "no"
1710 _lib_libthr=    lib/libthr
1711 .endif
1712
1713 .if ${MK_RADIUS_SUPPORT} != "no"
1714 _lib_libradius= lib/libradius
1715 .endif
1716
1717 .if ${MK_OFED} != "no"
1718 _ofed_lib=      contrib/ofed/usr.lib/
1719 .endif
1720
1721 .if ${MK_CASPER} != "no"
1722 _lib_libcapsicum=lib/libcapsicum
1723 .endif
1724
1725 lib/libcapsicum__L: lib/libnv__L
1726 lib/libpjdlog__L: lib/libutil__L
1727 lib/liblzma__L: lib/libthr__L
1728
1729 _generic_libs=  ${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib ${_ofed_lib}
1730 .for _DIR in ${LOCAL_LIB_DIRS}
1731 .if exists(${.CURDIR}/${_DIR}/Makefile)
1732 _generic_libs+= ${_DIR}
1733 .endif
1734 .endfor
1735
1736 lib/libopie__L lib/libtacplus__L: lib/libmd__L
1737
1738 .if ${MK_CDDL} != "no"
1739 _cddl_lib_libumem= cddl/lib/libumem
1740 _cddl_lib_libnvpair= cddl/lib/libnvpair
1741 _cddl_lib_libavl= cddl/lib/libavl
1742 _cddl_lib_libuutil= cddl/lib/libuutil
1743 _cddl_lib_libzfs_core= cddl/lib/libzfs_core
1744 _cddl_lib_libctf= cddl/lib/libctf
1745 _cddl_lib= cddl/lib
1746 cddl/lib/libzfs_core__L: cddl/lib/libnvpair__L
1747 cddl/lib/libzfs__L: lib/libgeom__L
1748 cddl/lib/libctf__L: lib/libz__L
1749 .endif
1750
1751 .if ${MK_CRYPT} != "no"
1752 .if ${MK_OPENSSL} != "no"
1753 _secure_lib_libcrypto= secure/lib/libcrypto
1754 _secure_lib_libssl= secure/lib/libssl
1755 lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1756 .if ${MK_LDNS} != "no"
1757 _lib_libldns= lib/libldns
1758 lib/libldns__L: secure/lib/libcrypto__L
1759 .endif
1760 .if ${MK_OPENSSH} != "no"
1761 _secure_lib_libssh= secure/lib/libssh
1762 secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
1763 .if ${MK_LDNS} != "no"
1764 secure/lib/libssh__L: lib/libldns__L
1765 .endif
1766 .if ${MK_KERBEROS_SUPPORT} != "no"
1767 secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
1768     kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
1769     lib/libmd__L kerberos5/lib/libroken__L
1770 .endif
1771 .endif
1772 .endif
1773 _secure_lib=    secure/lib
1774 .endif
1775
1776 .if ${MK_KERBEROS} != "no"
1777 kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L
1778 kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1779     kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \
1780     kerberos5/lib/libwind__L kerberos5/lib/libheimsqlite__L 
1781 kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \
1782     kerberos5/lib/libroken__L lib/libcom_err__L
1783 kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1784     secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L
1785 kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
1786     lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \
1787     kerberos5/lib/libroken__L kerberos5/lib/libwind__L \
1788     kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L
1789 kerberos5/lib/libroken__L: lib/libcrypt__L
1790 kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L
1791 kerberos5/lib/libheimbase__L: lib/libthr__L
1792 kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L
1793 kerberos5/lib/libheimsqlite__L: lib/libthr__L
1794 .endif
1795
1796 .if ${MK_GSSAPI} != "no"
1797 _lib_libgssapi= lib/libgssapi
1798 .endif
1799
1800 .if ${MK_KERBEROS} != "no"
1801 _kerberos5_lib= kerberos5/lib
1802 _kerberos5_lib_libasn1= kerberos5/lib/libasn1
1803 _kerberos5_lib_libhdb= kerberos5/lib/libhdb
1804 _kerberos5_lib_libheimbase= kerberos5/lib/libheimbase
1805 _kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
1806 _kerberos5_lib_libhx509= kerberos5/lib/libhx509
1807 _kerberos5_lib_libroken= kerberos5/lib/libroken
1808 _kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
1809 _kerberos5_lib_libheimsqlite= kerberos5/lib/libheimsqlite
1810 _kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc
1811 _kerberos5_lib_libwind= kerberos5/lib/libwind
1812 _libcom_err= lib/libcom_err
1813 .endif
1814
1815 .if ${MK_NIS} != "no"
1816 _lib_libypclnt= lib/libypclnt
1817 .endif
1818
1819 .if ${MK_OPENSSL} == "no"
1820 lib/libradius__L: lib/libmd__L
1821 .endif
1822
1823 gnu/lib/libdialog__L: lib/msun__L lib/ncurses/ncursesw__L
1824
1825 .for _lib in ${_prereq_libs}
1826 ${_lib}__PL: .PHONY .MAKE
1827 .if exists(${.CURDIR}/${_lib})
1828         ${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1829                 cd ${.CURDIR}/${_lib} && \
1830                 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj && \
1831                 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ depend && \
1832                 ${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
1833                     DIRPRFX=${_lib}/ all && \
1834                 ${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
1835                     DIRPRFX=${_lib}/ install
1836 .endif
1837 .endfor
1838
1839 .for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1840 ${_lib}__L: .PHONY .MAKE
1841 .if exists(${.CURDIR}/${_lib})
1842         ${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1843                 cd ${.CURDIR}/${_lib} && \
1844                 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj && \
1845                 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ depend && \
1846                 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ all && \
1847                 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ install
1848 .endif
1849 .endfor
1850
1851 # libpam is special: we need to build static PAM modules before
1852 # static PAM library, and dynamic PAM library before dynamic PAM
1853 # modules.
1854 lib/libpam__L: .PHONY .MAKE
1855         ${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \
1856                 cd ${.CURDIR}/lib/libpam && \
1857                 ${MAKE} MK_TESTS=no DIRPRFX=lib/libpam/ obj && \
1858                 ${MAKE} MK_TESTS=no DIRPRFX=lib/libpam/ depend && \
1859                 ${MAKE} MK_TESTS=no DIRPRFX=lib/libpam/ \
1860                     -D_NO_LIBPAM_SO_YET all && \
1861                 ${MAKE} MK_TESTS=no DIRPRFX=lib/libpam/ \
1862                     -D_NO_LIBPAM_SO_YET install
1863
1864 _prereq_libs: ${_prereq_libs:S/$/__PL/}
1865 _startup_libs: ${_startup_libs:S/$/__L/}
1866 _prebuild_libs: ${_prebuild_libs:S/$/__L/}
1867 _generic_libs: ${_generic_libs:S/$/__L/}
1868
1869 .for __target in all clean cleandepend cleandir depend includes obj
1870 .for entry in ${SUBDIR}
1871 ${entry}.${__target}__D: .PHONY .MAKE
1872         ${_+_}@set -e; if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1873                 ${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \
1874                 edir=${entry}.${MACHINE_ARCH}; \
1875                 cd ${.CURDIR}/$${edir}; \
1876         else \
1877                 ${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \
1878                 edir=${entry}; \
1879                 cd ${.CURDIR}/$${edir}; \
1880         fi; \
1881         ${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1882 .endfor
1883 par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
1884 .endfor
1885
1886 .include <bsd.subdir.mk>
1887
1888 .if make(check-old) || make(check-old-dirs) || \
1889     make(check-old-files) || make(check-old-libs) || \
1890     make(delete-old) || make(delete-old-dirs) || \
1891     make(delete-old-files) || make(delete-old-libs)
1892
1893 #
1894 # check for / delete old files section
1895 #
1896
1897 .include "ObsoleteFiles.inc"
1898
1899 OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
1900 else you can not start such an application. Consult UPDATING for more \
1901 information regarding how to cope with the removal/revision bump of a \
1902 specific library."
1903
1904 .if !defined(BATCH_DELETE_OLD_FILES)
1905 RM_I=-i
1906 .else
1907 RM_I=-v
1908 .endif
1909
1910 delete-old-files:
1911         @echo ">>> Removing old files (only deletes safe to delete libs)"
1912 # Ask for every old file if the user really wants to remove it.
1913 # It's annoying, but better safe than sorry.
1914 # NB: We cannot pass the list of OLD_FILES as a parameter because the
1915 # argument list will get too long. Using .for/.endfor make "loops" will make
1916 # the Makefile parser segfault.
1917         @exec 3<&0; \
1918         cd ${.CURDIR}; \
1919         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1920             -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
1921         while read file; do \
1922                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1923                         chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1924                         rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
1925                 fi; \
1926         done
1927 # Remove catpages without corresponding manpages.
1928         @exec 3<&0; \
1929         find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1930         sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1931         while read catpage; do \
1932                 read manpage; \
1933                 if [ ! -e "$${manpage}" ]; then \
1934                         rm ${RM_I} $${catpage} <&3; \
1935                 fi; \
1936         done
1937         @echo ">>> Old files removed"
1938
1939 check-old-files:
1940         @echo ">>> Checking for old files"
1941         @cd ${.CURDIR}; \
1942         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1943             -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
1944         while read file; do \
1945                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1946                         echo "${DESTDIR}/$${file}"; \
1947                 fi; \
1948         done
1949 # Check for catpages without corresponding manpages.
1950         @find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1951         sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1952         while read catpage; do \
1953                 read manpage; \
1954                 if [ ! -e "$${manpage}" ]; then \
1955                         echo $${catpage}; \
1956                 fi; \
1957         done
1958
1959 delete-old-libs:
1960         @echo ">>> Removing old libraries"
1961         @echo "${OLD_LIBS_MESSAGE}" | fmt
1962         @exec 3<&0; \
1963         cd ${.CURDIR}; \
1964         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1965             -V OLD_LIBS | xargs -n1 | \
1966         while read file; do \
1967                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1968                         chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1969                         rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
1970                 fi; \
1971                 for ext in debug symbols; do \
1972                   if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
1973                       "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
1974                           rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
1975                               <&3; \
1976                   fi; \
1977                 done; \
1978         done
1979         @echo ">>> Old libraries removed"
1980
1981 check-old-libs:
1982         @echo ">>> Checking for old libraries"
1983         @cd ${.CURDIR}; \
1984         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
1985             -V OLD_LIBS | xargs -n1 | \
1986         while read file; do \
1987                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1988                         echo "${DESTDIR}/$${file}"; \
1989                 fi; \
1990                 for ext in debug symbols; do \
1991                   if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
1992                           echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
1993                   fi; \
1994                 done; \
1995         done
1996
1997 delete-old-dirs:
1998         @echo ">>> Removing old directories"
1999         @cd ${.CURDIR}; \
2000         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2001             -V OLD_DIRS | xargs -n1 | sort -r | \
2002         while read dir; do \
2003                 if [ -d "${DESTDIR}/$${dir}" ]; then \
2004                         rmdir -v "${DESTDIR}/$${dir}" || true; \
2005                 elif [ -L "${DESTDIR}/$${dir}" ]; then \
2006                         echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
2007                 fi; \
2008         done
2009         @echo ">>> Old directories removed"
2010
2011 check-old-dirs:
2012         @echo ">>> Checking for old directories"
2013         @cd ${.CURDIR}; \
2014         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2015             -V OLD_DIRS | xargs -n1 | \
2016         while read dir; do \
2017                 if [ -d "${DESTDIR}/$${dir}" ]; then \
2018                         echo "${DESTDIR}/$${dir}"; \
2019                 elif [ -L "${DESTDIR}/$${dir}" ]; then \
2020                         echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
2021                 fi; \
2022         done
2023
2024 delete-old: delete-old-files delete-old-dirs
2025         @echo "To remove old libraries run '${MAKE} delete-old-libs'."
2026
2027 check-old: check-old-files check-old-libs check-old-dirs
2028         @echo "To remove old files and directories run '${MAKE} delete-old'."
2029         @echo "To remove old libraries run '${MAKE} delete-old-libs'."
2030
2031 .endif
2032
2033 #
2034 # showconfig - show build configuration.
2035 #
2036 showconfig:
2037         @(${MAKE} -n -f ${.CURDIR}/sys/conf/kern.opts.mk -V dummy -dg1; \
2038           ${MAKE} -n -f ${.CURDIR}/share/mk/src.opts.mk -V dummy -dg1) 2>&1 | grep ^MK_ | sort -u
2039
2040 .if !empty(KRNLOBJDIR) && !empty(KERNCONF)
2041 DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
2042
2043 .if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
2044 .if exists(${KERNCONFDIR}/${KERNCONF})
2045 FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
2046         '${KERNCONFDIR}/${KERNCONF}' ; echo
2047 .endif
2048 .endif
2049
2050 .endif
2051
2052 .if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
2053 DTBOUTPUTPATH= ${.CURDIR}
2054 .endif
2055
2056 #
2057 # Build 'standalone' Device Tree Blob
2058 #
2059 builddtb:
2060         @PATH=${TMPPATH} MACHINE=${TARGET} \
2061         ${.CURDIR}/sys/tools/fdt/make_dtb.sh ${.CURDIR}/sys \
2062             "${FDT_DTS_FILE}" ${DTBOUTPUTPATH}
2063
2064 ###############
2065
2066 .if defined(TARGET) && defined(TARGET_ARCH)
2067
2068 .if ${TARGET} == ${MACHINE} && ${TARGET_ARCH} == ${MACHINE_ARCH}
2069 XDEV_CPUTYPE?=${CPUTYPE}
2070 .else
2071 XDEV_CPUTYPE?=${TARGET_CPUTYPE}
2072 .endif
2073
2074 NOFUN=-DNO_FSCHG MK_HTML=no -DNO_LINT \
2075         MK_MAN=no MK_NLS=no MK_PROFILE=no \
2076         MK_KERBEROS=no MK_RESCUE=no MK_TESTS=no MK_WARNS=no \
2077         TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
2078         CPUTYPE=${XDEV_CPUTYPE}
2079
2080 XDDIR=${TARGET_ARCH}-freebsd
2081 XDTP?=/usr/${XDDIR}
2082 .if ${XDTP:N/*}
2083 .error XDTP variable should be an absolute path
2084 .endif
2085
2086 CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR} \
2087         INSTALL="sh ${.CURDIR}/tools/install.sh"
2088 CDENV= ${CDBENV} \
2089         _SHLIBDIRPREFIX=${XDDESTDIR} \
2090         TOOLS_PREFIX=${XDTP}
2091 CD2CFLAGS=-isystem ${XDDESTDIR}/usr/include -L${XDDESTDIR}/usr/lib \
2092         --sysroot=${XDDESTDIR}/ -B${XDDESTDIR}/usr/libexec \
2093         -B${XDDESTDIR}/usr/bin -B${XDDESTDIR}/usr/lib
2094 CD2ENV=${CDENV} CC="${CC} ${CD2CFLAGS}" CXX="${CXX} ${CD2CFLAGS}" \
2095         CPP="${CPP} ${CD2CFLAGS}" \
2096         MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH}
2097
2098 CDTMP=  ${MAKEOBJDIRPREFIX}/${XDDIR}/${.CURDIR}/tmp
2099 CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${NOFUN}
2100 CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/usr/bin:${PATH} ${MAKE} ${NOFUN}
2101 XDDESTDIR=${DESTDIR}/${XDTP}
2102 .if !defined(OSREL)
2103 OSREL!= uname -r | sed -e 's/[-(].*//'
2104 .endif
2105
2106 .ORDER: xdev-build xdev-install xdev-links
2107 xdev: xdev-build xdev-install
2108
2109 .ORDER: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
2110 xdev-build: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
2111
2112 _xb-worldtmp:
2113         mkdir -p ${CDTMP}/usr
2114         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2115             -p ${CDTMP}/usr >/dev/null
2116
2117 _xb-bootstrap-tools:
2118 .for _tool in \
2119     ${_clang_tblgen} \
2120     ${_gperf}
2121         ${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
2122         cd ${.CURDIR}/${_tool} && \
2123         ${CDMAKE} DIRPRFX=${_tool}/ obj && \
2124         ${CDMAKE} DIRPRFX=${_tool}/ depend && \
2125         ${CDMAKE} DIRPRFX=${_tool}/ all && \
2126         ${CDMAKE} DIRPRFX=${_tool}/ DESTDIR=${CDTMP} install
2127 .endfor
2128
2129 _xb-build-tools:
2130         ${_+_}@cd ${.CURDIR}; \
2131         ${CDBENV} ${MAKE} -f Makefile.inc1 ${NOFUN} build-tools
2132
2133 _xb-cross-tools:
2134 .for _tool in \
2135     ${_binutils} \
2136     ${_elftctools} \
2137     usr.bin/ar \
2138     ${_clang_libs} \
2139     ${_clang} \
2140     ${_cc}
2141         ${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,depend,all)"; \
2142         cd ${.CURDIR}/${_tool} && \
2143         ${CDMAKE} DIRPRFX=${_tool}/ obj && \
2144         ${CDMAKE} DIRPRFX=${_tool}/ depend && \
2145         ${CDMAKE} DIRPRFX=${_tool}/ all
2146 .endfor
2147
2148 _xi-mtree:
2149         ${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
2150         mkdir -p ${XDDESTDIR}
2151         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
2152             -p ${XDDESTDIR} >/dev/null
2153         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2154             -p ${XDDESTDIR}/usr >/dev/null
2155         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
2156             -p ${XDDESTDIR}/usr/include >/dev/null
2157 .if ${MK_TESTS} != "no"
2158         mkdir -p ${XDDESTDIR}${TESTSBASE}
2159         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
2160             -p ${XDDESTDIR}${TESTSBASE} >/dev/null
2161 .endif
2162
2163 .ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries
2164 xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries
2165
2166 _xi-cross-tools:
2167         @echo "_xi-cross-tools"
2168 .for _tool in \
2169     ${_binutils} \
2170     ${_elftctools} \
2171     usr.bin/ar \
2172     ${_clang_libs} \
2173     ${_clang} \
2174     ${_cc}
2175         ${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
2176         cd ${.CURDIR}/${_tool}; \
2177         ${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
2178 .endfor
2179
2180 _xi-includes:
2181         ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 par-includes \
2182                 DESTDIR=${XDDESTDIR}
2183
2184 _xi-libraries:
2185         ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
2186                 DESTDIR=${XDDESTDIR}
2187
2188 xdev-links:
2189         ${_+_}cd ${XDDESTDIR}/usr/bin; \
2190         mkdir -p ../../../../usr/bin; \
2191                 for i in *; do \
2192                         ln -sf ../../${XDTP}/usr/bin/$$i \
2193                             ../../../../usr/bin/${XDDIR}-$$i; \
2194                         ln -sf ../../${XDTP}/usr/bin/$$i \
2195                             ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \
2196                 done
2197 .else
2198 xdev xdev-build xdev-install xdev-links:
2199         @echo "*** Error: Both TARGET and TARGET_ARCH must be defined for \"${.TARGET}\" target"
2200 .endif