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