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