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