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