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