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