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