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