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