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