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