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