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