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