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