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