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