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