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