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