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