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