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