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