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