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