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