]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - Makefile.inc1
Remove redundant logic from the pkg-base merge.
[FreeBSD/FreeBSD.git] / Makefile.inc1
1 #
2 # $FreeBSD$
3 #
4 # Make command line options:
5 #       -DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
6 #       -DNO_CLEAN do not clean at all
7 #       -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,OBJ}
11 #       -DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
12 #       -DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
13 #       -DNO_KERNELOBJ do not run ${MAKE} obj in ${MAKE} buildkernel
14 #       -DNO_PORTSUPDATE do not update ports in ${MAKE} update
15 #       -DNO_ROOT install without using root privilege
16 #       -DNO_DOCUPDATE do not update doc in ${MAKE} update
17 #       -DWITHOUT_CTF do not run the DTrace CTF conversion tools on built objects
18 #       LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
19 #       LOCAL_ITOOLS="list of tools" to add additional tools to the ITOOLS list
20 #       LOCAL_LIB_DIRS="list of dirs" to add additional dirs to libraries target
21 #       LOCAL_MTREE="list of mtree files" to process to allow local directories
22 #           to be created before files are installed
23 #       LOCAL_TOOL_DIRS="list of dirs" to add additional dirs to the build-tools
24 #           list
25 #       METALOG="path to metadata log" to write permission and ownership
26 #           when NO_ROOT is set.  (default: ${DESTDIR}/METALOG)
27 #       TARGET="machine" to crossbuild world for a different machine type
28 #       TARGET_ARCH= may be required when a TARGET supports multiple endians
29 #       BUILDENV_SHELL= shell to launch for the buildenv target (def:${SHELL})
30 #       WORLD_FLAGS= additional flags to pass to make(1) during buildworld
31 #       KERNEL_FLAGS= additional flags to pass to make(1) during buildkernel
32 #       SUBDIR_OVERRIDE="list of dirs" to build rather than everything.
33 #           All libraries and includes, and some build tools will still build.
34
35 #
36 # The intended user-driven targets are:
37 # buildworld  - rebuild *everything*, including glue to help do upgrades
38 # installworld- install everything built by "buildworld"
39 # checkworld  - run test suite on installed world
40 # doxygen     - build API documentation of the kernel
41 # update      - convenient way to update your source tree (eg: svn/svnup)
42 #
43 # Standard targets (not defined here) are documented in the makefiles in
44 # /usr/share/mk.  These include:
45 #               obj depend all install clean cleandepend cleanobj
46
47 .if !defined(TARGET) || !defined(TARGET_ARCH)
48 .error "Both TARGET and TARGET_ARCH must be defined."
49 .endif
50
51 LOCALBASE?=     /usr/local
52
53 # Cross toolchain changes must be in effect before bsd.compiler.mk
54 # so that gets the right CC, and pass CROSS_TOOLCHAIN to submakes.
55 .if defined(CROSS_TOOLCHAIN)
56 .include "${LOCALBASE}/share/toolchains/${CROSS_TOOLCHAIN}.mk"
57 CROSSENV+=CROSS_TOOLCHAIN="${CROSS_TOOLCHAIN}"
58 .endif
59 .include <bsd.compiler.mk>              # don't depend on src.opts.mk doing it
60 .include "share/mk/src.opts.mk" 
61
62 # We must do lib/ and libexec/ before bin/ in case of a mid-install error to
63 # keep the users system reasonably usable.  For static->dynamic root upgrades,
64 # we don't want to install a dynamic binary without rtld and the needed
65 # libraries.  More commonly, for dynamic root, we don't want to install a
66 # binary that requires a newer library version that hasn't been installed yet.
67 # This ordering is not a guarantee though.  The only guarantee of a working
68 # system here would require fine-grained ordering of all components based
69 # on their dependencies.
70 SRCDIR?=        ${.CURDIR}
71 .if !empty(SUBDIR_OVERRIDE)
72 SUBDIR= ${SUBDIR_OVERRIDE}
73 .else
74 SUBDIR= lib libexec
75 .if !defined(NO_ROOT) && (make(installworld) || make(install))
76 # Ensure libraries are installed before progressing.
77 SUBDIR+=.WAIT
78 .endif
79 SUBDIR+=bin
80 .if ${MK_CDDL} != "no"
81 SUBDIR+=cddl
82 .endif
83 SUBDIR+=gnu include
84 .if ${MK_KERBEROS} != "no"
85 SUBDIR+=kerberos5
86 .endif
87 .if ${MK_RESCUE} != "no"
88 SUBDIR+=rescue
89 .endif
90 SUBDIR+=sbin
91 .if ${MK_CRYPT} != "no"
92 SUBDIR+=secure
93 .endif
94 .if !defined(NO_SHARE)
95 SUBDIR+=share
96 .endif
97 SUBDIR+=sys usr.bin usr.sbin
98 .if ${MK_TESTS} != "no"
99 SUBDIR+=        tests
100 .endif
101 .if ${MK_OFED} != "no"
102 SUBDIR+=contrib/ofed
103 .endif
104
105 # Local directories are last, since it is nice to at least get the base
106 # system rebuilt before you do them.
107 .for _DIR in ${LOCAL_DIRS}
108 .if exists(${.CURDIR}/${_DIR}/Makefile)
109 SUBDIR+=        ${_DIR}
110 .endif
111 .endfor
112 # Add LOCAL_LIB_DIRS, but only if they will not be picked up as a SUBDIR
113 # of a LOCAL_DIRS directory.  This allows LOCAL_DIRS=foo and
114 # LOCAL_LIB_DIRS=foo/lib to behave as expected.
115 .for _DIR in ${LOCAL_DIRS:M*/} ${LOCAL_DIRS:N*/:S|$|/|}
116 _REDUNDENT_LIB_DIRS+=    ${LOCAL_LIB_DIRS:M${_DIR}*}
117 .endfor
118 .for _DIR in ${LOCAL_LIB_DIRS}
119 .if empty(_REDUNDENT_LIB_DIRS:M${_DIR}) && exists(${.CURDIR}/${_DIR}/Makefile)
120 SUBDIR+=        ${_DIR}
121 .else
122 .warning ${_DIR} not added to SUBDIR list.  See UPDATING 20141121.
123 .endif
124 .endfor
125
126 # We must do etc/ last as it hooks into building the man whatis file
127 # by calling 'makedb' in share/man.  This is only relevant for
128 # install/distribute so they build the whatis file after every manpage is
129 # installed.
130 .if make(installworld) || make(install)
131 SUBDIR+=.WAIT
132 .endif
133 SUBDIR+=etc
134
135 .endif  # !empty(SUBDIR_OVERRIDE)
136
137 .if defined(NOCLEAN)
138 .warning NOCLEAN option is deprecated. Use NO_CLEAN instead.
139 NO_CLEAN=       ${NOCLEAN}
140 .endif
141 .if defined(NO_CLEANDIR)
142 CLEANDIR=       clean cleandepend
143 .else
144 CLEANDIR=       cleandir
145 .endif
146
147 .if ${MK_META_MODE} == "yes"
148 # If filemon is used then we can rely on the build being incremental-safe.
149 # The .meta files will also track the build command and rebuild should
150 # it change.
151 .if empty(.MAKE.MODE:Mnofilemon)
152 NO_CLEAN=       t
153 .endif
154 .endif
155
156 LOCAL_TOOL_DIRS?=
157 PACKAGEDIR?=    ${DESTDIR}/${DISTDIR}
158
159 .if empty(SHELL:M*csh*)
160 BUILDENV_SHELL?=${SHELL}
161 .else
162 BUILDENV_SHELL?=/bin/sh
163 .endif
164
165 .if !defined(SVN) || empty(SVN)
166 . for _P in /usr/bin /usr/local/bin
167 .  for _S in svn svnlite
168 .   if exists(${_P}/${_S})
169 SVN=   ${_P}/${_S}
170 .   endif
171 .  endfor
172 . endfor
173 .endif
174 SVNFLAGS?=      -r HEAD
175
176 MAKEOBJDIRPREFIX?=      /usr/obj
177 .if !defined(OSRELDATE)
178 .if exists(/usr/include/osreldate.h)
179 OSRELDATE!=     awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
180                 /usr/include/osreldate.h
181 .else
182 OSRELDATE=      0
183 .endif
184 .export OSRELDATE
185 .endif
186
187 # Set VERSION for CTFMERGE to use via the default CTFFLAGS=-L VERSION.
188 .if !defined(VERSION)
189 REVISION!=      MK_AUTO_OBJ=no ${MAKE} -C ${SRCDIR}/release -V REVISION
190 BRANCH!=        MK_AUTO_OBJ=no ${MAKE} -C ${SRCDIR}/release -V BRANCH
191 SRCRELDATE!=    awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
192                 ${SRCDIR}/sys/sys/param.h
193 VERSION=        FreeBSD ${REVISION}-${BRANCH:C/-p[0-9]+$//} ${TARGET_ARCH} ${SRCRELDATE}
194 .export VERSION
195 .endif
196
197 .if !defined(PKG_VERSION)
198 .if ${BRANCH:MSTABLE*} || ${BRANCH:MCURRENT*}
199 TIMENOW=        %Y%m%d%H%M%S
200 EXTRA_REVISION= .s${TIMENOW:gmtime}
201 .endif
202 .if ${BRANCH:M*-p*}
203 EXTRA_REVISION= _${BRANCH:C/.*-p([0-9]+$)/\1/}
204 .endif
205 PKG_VERSION=    ${REVISION}${EXTRA_REVISION}
206 .endif
207
208 KNOWN_ARCHES?=  aarch64/arm64 \
209                 amd64 \
210                 arm \
211                 armeb/arm \
212                 armv6/arm \
213                 armv6hf/arm \
214                 i386 \
215                 i386/pc98 \
216                 mips \
217                 mipsel/mips \
218                 mips64el/mips \
219                 mips64/mips \
220                 mipsn32el/mips \
221                 mipsn32/mips \
222                 powerpc \
223                 powerpc64/powerpc \
224                 riscv64/riscv \
225                 sparc64
226
227 .if ${TARGET} == ${TARGET_ARCH}
228 _t=             ${TARGET}
229 .else
230 _t=             ${TARGET_ARCH}/${TARGET}
231 .endif
232 .for _t in ${_t}
233 .if empty(KNOWN_ARCHES:M${_t})
234 .error Unknown target ${TARGET_ARCH}:${TARGET}.
235 .endif
236 .endfor
237
238 .if ${TARGET} == ${MACHINE}
239 TARGET_CPUTYPE?=${CPUTYPE}
240 .else
241 TARGET_CPUTYPE?=
242 .endif
243
244 .if !empty(TARGET_CPUTYPE)
245 _TARGET_CPUTYPE=${TARGET_CPUTYPE}
246 .else
247 _TARGET_CPUTYPE=dummy
248 .endif
249 _CPUTYPE!=      MK_AUTO_OBJ=no MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \
250                 -f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE
251 .if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
252 .error CPUTYPE global should be set with ?=.
253 .endif
254 .if make(buildworld)
255 BUILD_ARCH!=    uname -p
256 .if ${MACHINE_ARCH} != ${BUILD_ARCH}
257 .error To cross-build, set TARGET_ARCH.
258 .endif
259 .endif
260 .if ${MACHINE} == ${TARGET} && ${MACHINE_ARCH} == ${TARGET_ARCH} && !defined(CROSS_BUILD_TESTING)
261 OBJTREE=        ${MAKEOBJDIRPREFIX}
262 .else
263 OBJTREE=        ${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}
264 .endif
265 WORLDTMP=       ${OBJTREE}${.CURDIR}/tmp
266 BPATH=          ${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/bin
267 XPATH=          ${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin
268 STRICTTMPPATH=  ${BPATH}:${XPATH}
269 TMPPATH=        ${STRICTTMPPATH}:${PATH}
270
271 #
272 # Avoid running mktemp(1) unless actually needed.
273 # It may not be functional, e.g., due to new ABI
274 # when in the middle of installing over this system.
275 #
276 .if make(distributeworld) || make(installworld) || make(stageworld)
277 INSTALLTMP!=    /usr/bin/mktemp -d -u -t install
278 .endif
279
280 .if make(stagekernel) || make(distributekernel)
281 TAGS+=          kernel
282 PACKAGE=        kernel
283 .endif
284
285 #
286 # Building a world goes through the following stages
287 #
288 # 1. legacy stage [BMAKE]
289 #       This stage is responsible for creating compatibility
290 #       shims that are needed by the bootstrap-tools,
291 #       build-tools and cross-tools stages. These are generally
292 #       APIs that tools from one of those three stages need to
293 #       build that aren't present on the host.
294 # 1. bootstrap-tools stage [BMAKE]
295 #       This stage is responsible for creating programs that
296 #       are needed for backward compatibility reasons. They
297 #       are not built as cross-tools.
298 # 2. build-tools stage [TMAKE]
299 #       This stage is responsible for creating the object
300 #       tree and building any tools that are needed during
301 #       the build process. Some programs are listed during
302 #       this phase because they build binaries to generate
303 #       files needed to build these programs. This stage also
304 #       builds the 'build-tools' target rather than 'all'.
305 # 3. cross-tools stage [XMAKE]
306 #       This stage is responsible for creating any tools that
307 #       are needed for building the system. A cross-compiler is one
308 #       of them. This differs from build tools in two ways:
309 #       1. the 'all' target is built rather than 'build-tools'
310 #       2. these tools are installed into TMPPATH for stage 4.
311 # 4. world stage [WMAKE]
312 #       This stage actually builds the world.
313 # 5. install stage (optional) [IMAKE]
314 #       This stage installs a previously built world.
315 #
316
317 BOOTSTRAPPING?= 0
318
319 # Common environment for world related stages
320 CROSSENV+=      MAKEOBJDIRPREFIX=${OBJTREE} \
321                 MACHINE_ARCH=${TARGET_ARCH} \
322                 MACHINE=${TARGET} \
323                 CPUTYPE=${TARGET_CPUTYPE}
324 .if ${MK_META_MODE} != "no"
325 # Don't rebuild build-tools targets during normal build.
326 CROSSENV+=      BUILD_TOOLS_META=.NOMETA_CMP
327 .endif
328 .if ${MK_GROFF} != "no"
329 CROSSENV+=      GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \
330                 GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \
331                 GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac
332 .endif
333 .if defined(TARGET_CFLAGS)
334 CROSSENV+=      ${TARGET_CFLAGS}
335 .endif
336
337 # bootstrap-tools stage
338 BMAKEENV=       INSTALL="sh ${.CURDIR}/tools/install.sh" \
339                 TOOLS_PREFIX=${WORLDTMP} \
340                 PATH=${BPATH}:${PATH} \
341                 WORLDTMP=${WORLDTMP} \
342                 MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
343 # need to keep this in sync with targets/pseudo/bootstrap-tools/Makefile
344 BSARGS=         DESTDIR= \
345                 BOOTSTRAPPING=${OSRELDATE} \
346                 SSP_CFLAGS= \
347                 MK_HTML=no NO_LINT=yes MK_MAN=no \
348                 -DNO_PIC MK_PROFILE=no -DNO_SHARED \
349                 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
350                 MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \
351                 MK_LLDB=no MK_TESTS=no \
352                 MK_INCLUDES=yes
353
354 BMAKE=          MAKEOBJDIRPREFIX=${WORLDTMP} \
355                 ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
356                 ${BSARGS}
357
358 # build-tools stage
359 TMAKE=          MAKEOBJDIRPREFIX=${OBJTREE} \
360                 ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
361                 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
362                 DESTDIR= \
363                 BOOTSTRAPPING=${OSRELDATE} \
364                 SSP_CFLAGS= \
365                 -DNO_LINT \
366                 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
367                 MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \
368                 MK_LLDB=no MK_TESTS=no
369
370 # cross-tools stage
371 XMAKE=          TOOLS_PREFIX=${WORLDTMP} ${BMAKE} \
372                 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
373                 MK_GDB=no MK_TESTS=no
374
375 # kernel-tools stage
376 KTMAKEENV=      INSTALL="sh ${.CURDIR}/tools/install.sh" \
377                 PATH=${BPATH}:${PATH} \
378                 WORLDTMP=${WORLDTMP}
379 KTMAKE=         TOOLS_PREFIX=${WORLDTMP} MAKEOBJDIRPREFIX=${WORLDTMP} \
380                 ${KTMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
381                 DESTDIR= \
382                 BOOTSTRAPPING=${OSRELDATE} \
383                 SSP_CFLAGS= \
384                 MK_HTML=no -DNO_LINT MK_MAN=no \
385                 -DNO_PIC MK_PROFILE=no -DNO_SHARED \
386                 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no
387
388 # world stage
389 WMAKEENV=       ${CROSSENV} \
390                 INSTALL="sh ${.CURDIR}/tools/install.sh" \
391                 PATH=${TMPPATH}
392
393 # make hierarchy
394 HMAKE=          PATH=${TMPPATH} ${MAKE} LOCAL_MTREE=${LOCAL_MTREE:Q}
395 .if defined(NO_ROOT)
396 HMAKE+=         PATH=${TMPPATH} METALOG=${METALOG} -DNO_ROOT
397 .endif
398
399 .if defined(CROSS_TOOLCHAIN_PREFIX)
400 CROSS_COMPILER_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
401 CROSS_BINUTILS_PREFIX?=${CROSS_TOOLCHAIN_PREFIX}
402 .endif
403
404 # If we do not have a bootstrap binutils (because the in-tree one does not
405 # support the target architecture), provide a default cross-binutils prefix.
406 # This allows aarch64 builds, for example, to automatically use the
407 # aarch64-binutils port or package.
408 .if !make(showconfig)
409 .if !empty(BROKEN_OPTIONS:MBINUTILS_BOOTSTRAP) && \
410     !defined(CROSS_BINUTILS_PREFIX)
411 CROSS_BINUTILS_PREFIX=/usr/local/${TARGET_ARCH}-freebsd/bin/
412 .if !exists(${CROSS_BINUTILS_PREFIX})
413 .error In-tree binutils does not support the ${TARGET_ARCH} architecture. Install the ${TARGET_ARCH}-binutils port or package or set CROSS_BINUTILS_PREFIX.
414 .endif
415 .endif
416 .endif
417
418 XCOMPILERS=     CC CXX CPP
419 .for COMPILER in ${XCOMPILERS}
420 .if defined(CROSS_COMPILER_PREFIX)
421 X${COMPILER}?=  ${CROSS_COMPILER_PREFIX}${${COMPILER}}
422 .else
423 X${COMPILER}?=  ${${COMPILER}}
424 .endif
425 .endfor
426 XBINUTILS=      AS AR LD NM OBJCOPY OBJDUMP RANLIB SIZE STRINGS
427 .for BINUTIL in ${XBINUTILS}
428 .if defined(CROSS_BINUTILS_PREFIX) && \
429     exists(${CROSS_BINUTILS_PREFIX}${${BINUTIL}})
430 X${BINUTIL}?=   ${CROSS_BINUTILS_PREFIX}${${BINUTIL}}
431 .else
432 X${BINUTIL}?=   ${${BINUTIL}}
433 .endif
434 .endfor
435 CROSSENV+=      CC="${XCC} ${XCFLAGS}" CXX="${XCXX} ${XCFLAGS} ${XCXXFLAGS}" \
436                 CPP="${XCPP} ${XCFLAGS}" \
437                 AS="${XAS}" AR="${XAR}" LD="${XLD}" NM=${XNM} \
438                 OBJDUMP=${XOBJDUMP} OBJCOPY="${XOBJCOPY}" \
439                 RANLIB=${XRANLIB} STRINGS=${XSTRINGS} \
440                 SIZE="${XSIZE}"
441
442 .if defined(CROSS_BINUTILS_PREFIX) && exists(${CROSS_BINUTILS_PREFIX})
443 # In the case of xdev-build tools, CROSS_BINUTILS_PREFIX won't be a
444 # directory, but the compiler will look in the right place for its
445 # tools so we don't need to tell it where to look.
446 BFLAGS+=        -B${CROSS_BINUTILS_PREFIX}
447 .endif
448
449 # External compiler needs sysroot and target flags.
450 .if ${XCC:N${CCACHE_BIN}:M/*} || ${MK_CROSS_COMPILER} == "no"
451 .if !defined(CROSS_BINUTILS_PREFIX) || !exists(${CROSS_BINUTILS_PREFIX})
452 BFLAGS+=        -B${WORLDTMP}/usr/bin
453 .endif
454 .if ${TARGET} == "arm"
455 .if ${TARGET_ARCH:M*hf*} != ""
456 TARGET_ABI=     gnueabihf
457 .else
458 TARGET_ABI=     gnueabi
459 .endif
460 .endif
461 .if defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc
462 # GCC requires -isystem and -L when using a cross-compiler.
463 XCFLAGS+=       -isystem ${WORLDTMP}/usr/include -L${WORLDTMP}/usr/lib
464 # Force using libc++ for external GCC.
465 XCXXFLAGS+=     -isystem ${WORLDTMP}/usr/include/c++/v1 -std=c++11 \
466                 -nostdinc++ -L${WORLDTMP}/../lib/libc++
467 .else
468 TARGET_ABI?=    unknown
469 TARGET_TRIPLE?= ${TARGET_ARCH:C/amd64/x86_64/}-${TARGET_ABI}-freebsd11.0
470 XCFLAGS+=       -target ${TARGET_TRIPLE}
471 .endif
472 XCFLAGS+=       --sysroot=${WORLDTMP}
473 .else
474 .endif # ${XCC:M/*} || ${MK_CROSS_COMPILER} == "no"
475
476 .if !empty(BFLAGS)
477 XCFLAGS+=       ${BFLAGS}
478 .endif
479
480 .if ${MK_LIB32} != "no" && (${TARGET_ARCH} == "amd64" || \
481     ${TARGET_ARCH} == "powerpc64")
482 LIBCOMPAT= 32
483 .include "Makefile.libcompat"
484 .elif ${MK_LIBSOFT} != "no" && ${TARGET_ARCH} == "armv6"
485 LIBCOMPAT= SOFT
486 .include "Makefile.libcompat"
487 .endif
488
489 WMAKE=          ${WMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 DESTDIR=${WORLDTMP}
490
491 IMAKEENV=       ${CROSSENV}
492 IMAKE=          ${IMAKEENV} ${MAKE} -f Makefile.inc1 \
493                 ${IMAKE_INSTALL} ${IMAKE_MTREE}
494 .if empty(.MAKEFLAGS:M-n)
495 IMAKEENV+=      PATH=${STRICTTMPPATH}:${INSTALLTMP} \
496                 LD_LIBRARY_PATH=${INSTALLTMP} \
497                 PATH_LOCALE=${INSTALLTMP}/locale
498 IMAKE+=         __MAKE_SHELL=${INSTALLTMP}/sh
499 .else
500 IMAKEENV+=      PATH=${TMPPATH}:${INSTALLTMP}
501 .endif
502 .if defined(DB_FROM_SRC)
503 INSTALLFLAGS+=  -N ${.CURDIR}/etc
504 MTREEFLAGS+=    -N ${.CURDIR}/etc
505 .endif
506 _INSTALL_DDIR=  ${DESTDIR}/${DISTDIR}
507 INSTALL_DDIR=   ${_INSTALL_DDIR:S://:/:g:C:/$::}
508 .if defined(NO_ROOT)
509 METALOG?=       ${DESTDIR}/${DISTDIR}/METALOG
510 IMAKE+=         -DNO_ROOT METALOG=${METALOG}
511 INSTALLFLAGS+=  -U -M ${METALOG} -D ${INSTALL_DDIR}
512 MTREEFLAGS+=    -W
513 .endif
514 .if defined(BUILD_PKGS)
515 INSTALLFLAGS+=  -h sha256
516 .endif
517 .if defined(DB_FROM_SRC) || defined(NO_ROOT)
518 IMAKE_INSTALL=  INSTALL="install ${INSTALLFLAGS}"
519 IMAKE_MTREE=    MTREE_CMD="mtree ${MTREEFLAGS}"
520 .endif
521
522 # kernel stage
523 KMAKEENV=       ${WMAKEENV}
524 KMAKE=          ${KMAKEENV} ${MAKE} ${.MAKEFLAGS} ${KERNEL_FLAGS} KERNEL=${INSTKERNNAME}
525
526 #
527 # buildworld
528 #
529 # Attempt to rebuild the entire system, with reasonable chance of
530 # success, regardless of how old your existing system is.
531 #
532 _worldtmp: .PHONY
533 .if ${.CURDIR:C/[^,]//g} != ""
534 #       The m4 build of sendmail files doesn't like it if ',' is used
535 #       anywhere in the path of it's files.
536         @echo
537         @echo "*** Error: path to source tree contains a comma ','"
538         @echo
539         false
540 .endif
541         @echo
542         @echo "--------------------------------------------------------------"
543         @echo ">>> Rebuilding the temporary build tree"
544         @echo "--------------------------------------------------------------"
545 .if !defined(NO_CLEAN)
546         rm -rf ${WORLDTMP}
547 .if defined(LIBCOMPAT)
548         rm -rf ${LIBCOMPATTMP}
549 .endif
550 .else
551         rm -rf ${WORLDTMP}/legacy/usr/include
552 #       XXX - These can depend on any header file.
553         rm -f ${OBJTREE}${.CURDIR}/lib/libsysdecode/ioctl.c
554         rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/kdump_subr.c
555 .endif
556 .for _dir in \
557     lib lib/casper usr legacy/bin legacy/usr
558         mkdir -p ${WORLDTMP}/${_dir}
559 .endfor
560         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
561             -p ${WORLDTMP}/legacy/usr >/dev/null
562 .if ${MK_GROFF} != "no"
563         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.groff.dist \
564             -p ${WORLDTMP}/legacy/usr >/dev/null
565 .endif
566         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
567             -p ${WORLDTMP}/usr >/dev/null
568         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
569             -p ${WORLDTMP}/usr/include >/dev/null
570         ln -sf ${.CURDIR}/sys ${WORLDTMP}
571 .if ${MK_DEBUG_FILES} != "no"
572         # We could instead disable debug files for these build stages
573         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
574             -p ${WORLDTMP}/legacy/usr/lib >/dev/null
575         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
576             -p ${WORLDTMP}/usr/lib >/dev/null
577 .endif
578 .if defined(LIBCOMPAT)
579         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
580             -p ${WORLDTMP}/usr >/dev/null
581 .if ${MK_DEBUG_FILES} != "no"
582         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
583             -p ${WORLDTMP}/legacy/usr/lib/debug/usr >/dev/null
584         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
585             -p ${WORLDTMP}/usr/lib/debug/usr >/dev/null
586 .endif
587 .endif
588 .if ${MK_TESTS} != "no"
589         mkdir -p ${WORLDTMP}${TESTSBASE}
590         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
591             -p ${WORLDTMP}${TESTSBASE} >/dev/null
592 .if ${MK_DEBUG_FILES} != "no"
593         mkdir -p ${WORLDTMP}/usr/lib/debug/${TESTSBASE}
594         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
595             -p ${WORLDTMP}/usr/lib/debug/${TESTSBASE} >/dev/null
596 .endif
597 .endif
598 .for _mtree in ${LOCAL_MTREE}
599         mtree -deU -f ${.CURDIR}/${_mtree} -p ${WORLDTMP} > /dev/null
600 .endfor
601 _legacy:
602         @echo
603         @echo "--------------------------------------------------------------"
604         @echo ">>> stage 1.1: legacy release compatibility shims"
605         @echo "--------------------------------------------------------------"
606         ${_+_}cd ${.CURDIR}; ${BMAKE} legacy
607 _bootstrap-tools:
608         @echo
609         @echo "--------------------------------------------------------------"
610         @echo ">>> stage 1.2: bootstrap tools"
611         @echo "--------------------------------------------------------------"
612         ${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
613 _cleanobj:
614 .if !defined(NO_CLEAN)
615         @echo
616         @echo "--------------------------------------------------------------"
617         @echo ">>> stage 2.1: cleaning up the object tree"
618         @echo "--------------------------------------------------------------"
619         ${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR}
620 .if defined(LIBCOMPAT)
621         ${_+_}cd ${.CURDIR}; ${LIBCOMPATWMAKE} -f Makefile.inc1 ${CLEANDIR}
622 .endif
623 .endif
624 _obj:
625         @echo
626         @echo "--------------------------------------------------------------"
627         @echo ">>> stage 2.2: rebuilding the object tree"
628         @echo "--------------------------------------------------------------"
629         ${_+_}cd ${.CURDIR}; ${WMAKE} obj
630 _build-tools:
631         @echo
632         @echo "--------------------------------------------------------------"
633         @echo ">>> stage 2.3: build tools"
634         @echo "--------------------------------------------------------------"
635         ${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
636 _cross-tools:
637         @echo
638         @echo "--------------------------------------------------------------"
639         @echo ">>> stage 3: cross tools"
640         @echo "--------------------------------------------------------------"
641         ${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
642         ${_+_}cd ${.CURDIR}; ${XMAKE} kernel-tools
643 _includes:
644         @echo
645         @echo "--------------------------------------------------------------"
646         @echo ">>> stage 4.1: building includes"
647         @echo "--------------------------------------------------------------"
648 # Special handling for SUBDIR_OVERRIDE in buildworld as they most likely need
649 # headers from default SUBDIR.  Do SUBDIR_OVERRIDE includes last.
650         ${_+_}cd ${.CURDIR}; ${WMAKE} SUBDIR_OVERRIDE= SHARED=symlinks \
651             MK_INCLUDES=yes includes
652 .if !empty(SUBDIR_OVERRIDE) && make(buildworld)
653         ${_+_}cd ${.CURDIR}; ${WMAKE} MK_INCLUDES=yes SHARED=symlinks includes
654 .endif
655 _libraries:
656         @echo
657         @echo "--------------------------------------------------------------"
658         @echo ">>> stage 4.2: building libraries"
659         @echo "--------------------------------------------------------------"
660         ${_+_}cd ${.CURDIR}; \
661             ${WMAKE} -DNO_FSCHG MK_HTML=no -DNO_LINT MK_MAN=no \
662             MK_PROFILE=no MK_TESTS=no MK_TESTS_SUPPORT=${MK_TESTS} libraries
663 everything:
664         @echo
665         @echo "--------------------------------------------------------------"
666         @echo ">>> stage 4.3: building everything"
667         @echo "--------------------------------------------------------------"
668         ${_+_}cd ${.CURDIR}; _PARALLEL_SUBDIR_OK=1 ${WMAKE} all
669
670 WMAKE_TGTS=
671 WMAKE_TGTS+=    _worldtmp _legacy
672 .if empty(SUBDIR_OVERRIDE)
673 WMAKE_TGTS+=    _bootstrap-tools
674 .endif
675 WMAKE_TGTS+=    _cleanobj _obj _build-tools _cross-tools
676 WMAKE_TGTS+=    _includes _libraries
677 WMAKE_TGTS+=    everything
678 .if defined(LIBCOMPAT) && empty(SUBDIR_OVERRIDE)
679 WMAKE_TGTS+=    build${libcompat}
680 .endif
681
682 buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
683 .ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
684
685 buildworld_prologue: .PHONY
686         @echo "--------------------------------------------------------------"
687         @echo ">>> World build started on `LC_ALL=C date`"
688         @echo "--------------------------------------------------------------"
689
690 buildworld_epilogue: .PHONY
691         @echo
692         @echo "--------------------------------------------------------------"
693         @echo ">>> World build completed on `LC_ALL=C date`"
694         @echo "--------------------------------------------------------------"
695
696 #
697 # We need to have this as a target because the indirection between Makefile
698 # and Makefile.inc1 causes the correct PATH to be used, rather than a
699 # modification of the current environment's PATH.  In addition, we need
700 # to quote multiword values.
701 #
702 buildenvvars: .PHONY
703         @echo ${WMAKEENV:Q} ${.MAKE.EXPORTED:@v@$v=\"${$v}\"@}
704
705 .if ${.TARGETS:Mbuildenv}
706 .if ${.MAKEFLAGS:M-j}
707 .error The buildenv target is incompatible with -j
708 .endif
709 .endif
710 BUILDENV_DIR?=  ${.CURDIR}
711 buildenv: .PHONY
712         @echo Entering world for ${TARGET_ARCH}:${TARGET}
713 .if ${BUILDENV_SHELL:M*zsh*}
714         @echo For ZSH you must run: export CPUTYPE=${TARGET_CPUTYPE}
715 .endif
716         @cd ${BUILDENV_DIR} && env ${WMAKEENV} BUILDENV=1 ${BUILDENV_SHELL} \
717             || true
718
719 TOOLCHAIN_TGTS= ${WMAKE_TGTS:Neverything:Nbuild${libcompat}}
720 toolchain: ${TOOLCHAIN_TGTS}
721 kernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries}
722
723 #
724 # installcheck
725 #
726 # Checks to be sure system is ready for installworld/installkernel.
727 #
728 installcheck: _installcheck_world _installcheck_kernel .PHONY
729 _installcheck_world: .PHONY
730 _installcheck_kernel: .PHONY
731
732 #
733 # Require DESTDIR to be set if installing for a different architecture or
734 # using the user/group database in the source tree.
735 #
736 .if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} || \
737     defined(DB_FROM_SRC)
738 .if !make(distributeworld)
739 _installcheck_world: __installcheck_DESTDIR
740 _installcheck_kernel: __installcheck_DESTDIR
741 __installcheck_DESTDIR: .PHONY
742 .if !defined(DESTDIR) || empty(DESTDIR)
743         @echo "ERROR: Please set DESTDIR!"; \
744         false
745 .endif
746 .endif
747 .endif
748
749 .if !defined(DB_FROM_SRC)
750 #
751 # Check for missing UIDs/GIDs.
752 #
753 CHECK_UIDS=     auditdistd
754 CHECK_GIDS=     audit
755 .if ${MK_SENDMAIL} != "no"
756 CHECK_UIDS+=    smmsp
757 CHECK_GIDS+=    smmsp
758 .endif
759 .if ${MK_PF} != "no"
760 CHECK_UIDS+=    proxy
761 CHECK_GIDS+=    proxy authpf
762 .endif
763 .if ${MK_UNBOUND} != "no"
764 CHECK_UIDS+=    unbound
765 CHECK_GIDS+=    unbound
766 .endif
767 _installcheck_world: __installcheck_UGID
768 __installcheck_UGID: .PHONY
769 .for uid in ${CHECK_UIDS}
770         @if ! `id -u ${uid} >/dev/null 2>&1`; then \
771                 echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
772                 false; \
773         fi
774 .endfor
775 .for gid in ${CHECK_GIDS}
776         @if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
777                 echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
778                 false; \
779         fi
780 .endfor
781 .endif
782
783 #
784 # Required install tools to be saved in a scratch dir for safety.
785 #
786 .if ${MK_ZONEINFO} != "no"
787 _zoneinfo=      zic tzsetup
788 .endif
789
790 ITOOLS= [ awk cap_mkdb cat chflags chmod chown cmp cp \
791         date echo egrep find grep id install ${_install-info} \
792         ln make mkdir mtree mv pwd_mkdb \
793         rm sed services_mkdb sh strip sysctl test true uname wc ${_zoneinfo} \
794         ${LOCAL_ITOOLS}
795
796 # Needed for share/man
797 .if ${MK_MAN} != "no"
798 ITOOLS+=makewhatis
799 .endif
800
801 #
802 # distributeworld
803 #
804 # Distributes everything compiled by a `buildworld'.
805 #
806 # installworld
807 #
808 # Installs everything compiled by a 'buildworld'.
809 #
810
811 # Non-base distributions produced by the base system
812 EXTRA_DISTRIBUTIONS=    doc
813 .if defined(LIBCOMPAT)
814 EXTRA_DISTRIBUTIONS+=   lib${libcompat}
815 .endif
816 .if ${MK_TESTS} != "no"
817 EXTRA_DISTRIBUTIONS+=   tests
818 .endif
819
820 DEBUG_DISTRIBUTIONS=
821 .if ${MK_DEBUG_FILES} != "no"
822 DEBUG_DISTRIBUTIONS+=   base ${EXTRA_DISTRIBUTIONS:S,doc,,:S,tests,,}
823 .endif
824
825 MTREE_MAGIC?=   mtree 2.0
826
827 distributeworld installworld stageworld: _installcheck_world
828         mkdir -p ${INSTALLTMP}
829         progs=$$(for prog in ${ITOOLS}; do \
830                 if progpath=`which $$prog`; then \
831                         echo $$progpath; \
832                 else \
833                         echo "Required tool $$prog not found in PATH." >&2; \
834                         exit 1; \
835                 fi; \
836             done); \
837         libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
838             while read line; do \
839                 set -- $$line; \
840                 if [ "$$2 $$3" != "not found" ]; then \
841                         echo $$2; \
842                 else \
843                         echo "Required library $$1 not found." >&2; \
844                         exit 1; \
845                 fi; \
846             done); \
847         cp $$libs $$progs ${INSTALLTMP}
848         cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
849 .if defined(NO_ROOT)
850         -mkdir -p ${METALOG:H}
851         echo "#${MTREE_MAGIC}" > ${METALOG}
852 .endif
853 .if make(distributeworld)
854 .for dist in ${EXTRA_DISTRIBUTIONS}
855         -mkdir ${DESTDIR}/${DISTDIR}/${dist}
856         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
857             -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null
858         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
859             -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
860         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
861             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
862 .if ${MK_DEBUG_FILES} != "no"
863         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
864             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib >/dev/null
865 .endif
866 .if defined(LIBCOMPAT)
867         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
868             -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
869 .if ${MK_DEBUG_FILES} != "no"
870         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
871             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/usr >/dev/null
872 .endif
873 .endif
874 .if ${MK_TESTS} != "no" && ${dist} == "tests"
875         -mkdir -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE}
876         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
877             -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE} >/dev/null
878 .if ${MK_DEBUG_FILES} != "no"
879         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
880             -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/${TESTSBASE} >/dev/null
881 .endif
882 .endif
883 .if defined(NO_ROOT)
884         ${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
885             sed -e 's#^\./#./${dist}/#' >> ${METALOG}
886         ${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
887             sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
888         ${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
889             sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
890 .if defined(LIBCOMPAT)
891         ${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist | \
892             sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
893 .endif
894 .endif
895 .endfor
896         -mkdir ${DESTDIR}/${DISTDIR}/base
897         ${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
898             METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
899             DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
900             LOCAL_MTREE=${LOCAL_MTREE:Q} distrib-dirs
901 .endif
902         ${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
903             ${IMAKEENV} rm -rf ${INSTALLTMP}
904 .if make(distributeworld)
905 .for dist in ${EXTRA_DISTRIBUTIONS}
906         find ${DESTDIR}/${DISTDIR}/${dist} -mindepth 1 -empty -delete
907 .endfor
908 .if defined(NO_ROOT)
909 .for dist in base ${EXTRA_DISTRIBUTIONS}
910         @# For each file that exists in this dist, print the corresponding
911         @# line from the METALOG.  This relies on the fact that
912         @# a line containing only the filename will sort immediatly before
913         @# the relevant mtree line.
914         cd ${DESTDIR}/${DISTDIR}; \
915         find ./${dist} | sort -u ${METALOG} - | \
916         awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
917         ${DESTDIR}/${DISTDIR}/${dist}.meta
918 .endfor
919 .for dist in ${DEBUG_DISTRIBUTIONS}
920         @# For each file that exists in this dist, print the corresponding
921         @# line from the METALOG.  This relies on the fact that
922         @# a line containing only the filename will sort immediatly before
923         @# the relevant mtree line.
924         cd ${DESTDIR}/${DISTDIR}; \
925         find ./${dist}/usr/lib/debug | sort -u ${METALOG} - | \
926         awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
927         ${DESTDIR}/${DISTDIR}/${dist}.debug.meta
928 .endfor
929 .endif
930 .endif
931
932 packageworld: .PHONY
933 .for dist in base ${EXTRA_DISTRIBUTIONS}
934 .if defined(NO_ROOT)
935         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
936             tar cvf - --exclude usr/lib/debug \
937             @${DESTDIR}/${DISTDIR}/${dist}.meta | \
938             ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
939 .else
940         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
941             tar cvf - --exclude usr/lib/debug . | \
942             ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz
943 .endif
944 .endfor
945
946 .for dist in ${DEBUG_DISTRIBUTIONS}
947 . if defined(NO_ROOT)
948         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
949             tar cvf - @${DESTDIR}/${DISTDIR}/${dist}.debug.meta | \
950             ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
951 . else
952         ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
953             tar cvLf - usr/lib/debug | \
954             ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz
955 . endif
956 .endfor
957
958 #
959 # reinstall
960 #
961 # If you have a build server, you can NFS mount the source and obj directories
962 # and do a 'make reinstall' on the *client* to install new binaries from the
963 # most recent server build.
964 #
965 reinstall: .MAKE .PHONY
966         @echo "--------------------------------------------------------------"
967         @echo ">>> Making hierarchy"
968         @echo "--------------------------------------------------------------"
969         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
970             LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy
971         @echo
972         @echo "--------------------------------------------------------------"
973         @echo ">>> Installing everything"
974         @echo "--------------------------------------------------------------"
975         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
976 .if defined(LIBCOMPAT)
977         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install${libcompat}
978 .endif
979
980 restage: .MAKE .PHONY
981         @echo "--------------------------------------------------------------"
982         @echo ">>> Making hierarchy"
983         @echo "--------------------------------------------------------------"
984         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
985             LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy distribution
986         @echo
987         @echo "--------------------------------------------------------------"
988         @echo ">>> Installing everything"
989         @echo "--------------------------------------------------------------"
990         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
991 .if defined(LIB32TMP) && ${MK_LIB32} != "no"
992         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
993 .endif
994
995 redistribute: .MAKE .PHONY
996         @echo "--------------------------------------------------------------"
997         @echo ">>> Distributing everything"
998         @echo "--------------------------------------------------------------"
999         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
1000 .if defined(LIBCOMPAT)
1001         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute${libcompat} \
1002             DISTRIBUTION=lib${libcompat}
1003 .endif
1004
1005 distrib-dirs distribution: .MAKE .PHONY
1006         ${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
1007             ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
1008 .if make(distribution)
1009         ${_+_}cd ${.CURDIR}; ${CROSSENV} PATH=${TMPPATH} \
1010                 ${MAKE} -f Makefile.inc1 ${IMAKE_INSTALL} \
1011                 METALOG=${METALOG} MK_TESTS=no installconfig
1012 .endif
1013
1014 #
1015 # buildkernel and installkernel
1016 #
1017 # Which kernels to build and/or install is specified by setting
1018 # KERNCONF. If not defined a GENERIC kernel is built/installed.
1019 # Only the existing (depending TARGET) config files are used
1020 # for building kernels and only the first of these is designated
1021 # as the one being installed.
1022 #
1023 # Note that we have to use TARGET instead of TARGET_ARCH when
1024 # we're in kernel-land. Since only TARGET_ARCH is (expected) to
1025 # be set to cross-build, we have to make sure TARGET is set
1026 # properly.
1027
1028 .if defined(KERNFAST)
1029 NO_KERNELCLEAN= t
1030 NO_KERNELCONFIG=        t
1031 NO_KERNELOBJ=           t
1032 # Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
1033 .if !defined(KERNCONF) && ${KERNFAST} != "1"
1034 KERNCONF=${KERNFAST}
1035 .endif
1036 .endif
1037 .if ${TARGET_ARCH} == "powerpc64"
1038 KERNCONF?=      GENERIC64
1039 .else
1040 KERNCONF?=      GENERIC
1041 .endif
1042 INSTKERNNAME?=  kernel
1043
1044 KERNSRCDIR?=    ${.CURDIR}/sys
1045 KRNLCONFDIR=    ${KERNSRCDIR}/${TARGET}/conf
1046 KRNLOBJDIR=     ${OBJTREE}${KERNSRCDIR}
1047 KERNCONFDIR?=   ${KRNLCONFDIR}
1048
1049 BUILDKERNELS=
1050 INSTALLKERNEL=
1051 .if defined(NO_INSTALLKERNEL)
1052 # All of the BUILDKERNELS loops start at index 1.
1053 BUILDKERNELS+= dummy
1054 .endif
1055 .for _kernel in ${KERNCONF}
1056 .if exists(${KERNCONFDIR}/${_kernel})
1057 BUILDKERNELS+=  ${_kernel}
1058 .if empty(INSTALLKERNEL) && !defined(NO_INSTALLKERNEL)
1059 INSTALLKERNEL= ${_kernel}
1060 .endif
1061 .endif
1062 .endfor
1063
1064 ${WMAKE_TGTS:N_worldtmp:Nbuild${libcompat}} ${.ALLTARGETS:M_*:N_worldtmp}: .MAKE .PHONY
1065
1066 #
1067 # buildkernel
1068 #
1069 # Builds all kernels defined by BUILDKERNELS.
1070 #
1071 buildkernel: .MAKE .PHONY
1072 .if empty(BUILDKERNELS:Ndummy)
1073         @echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
1074         false
1075 .endif
1076         @echo
1077 .for _kernel in ${BUILDKERNELS:Ndummy}
1078         @echo "--------------------------------------------------------------"
1079         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
1080         @echo "--------------------------------------------------------------"
1081         @echo "===> ${_kernel}"
1082         mkdir -p ${KRNLOBJDIR}
1083 .if !defined(NO_KERNELCONFIG)
1084         @echo
1085         @echo "--------------------------------------------------------------"
1086         @echo ">>> stage 1: configuring the kernel"
1087         @echo "--------------------------------------------------------------"
1088         cd ${KRNLCONFDIR}; \
1089                 PATH=${TMPPATH} \
1090                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
1091                         -I '${KERNCONFDIR}' '${KERNCONFDIR}/${_kernel}'
1092 .endif
1093 .if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
1094         @echo
1095         @echo "--------------------------------------------------------------"
1096         @echo ">>> stage 2.1: cleaning up the object tree"
1097         @echo "--------------------------------------------------------------"
1098         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
1099 .endif
1100 .if !defined(NO_KERNELOBJ)
1101         @echo
1102         @echo "--------------------------------------------------------------"
1103         @echo ">>> stage 2.2: rebuilding the object tree"
1104         @echo "--------------------------------------------------------------"
1105         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
1106 .endif
1107         @echo
1108         @echo "--------------------------------------------------------------"
1109         @echo ">>> stage 2.3: build tools"
1110         @echo "--------------------------------------------------------------"
1111         ${_+_}cd ${.CURDIR}; ${KTMAKE} kernel-tools
1112         @echo
1113         @echo "--------------------------------------------------------------"
1114         @echo ">>> stage 3.1: building everything"
1115         @echo "--------------------------------------------------------------"
1116         ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
1117         @echo "--------------------------------------------------------------"
1118         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
1119         @echo "--------------------------------------------------------------"
1120 .endfor
1121
1122 #
1123 # installkernel, etc.
1124 #
1125 # Install the kernel defined by INSTALLKERNEL
1126 #
1127 installkernel installkernel.debug \
1128 reinstallkernel reinstallkernel.debug: _installcheck_kernel .PHONY
1129 .if !defined(NO_INSTALLKERNEL)
1130 .if empty(INSTALLKERNEL)
1131         @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1132         false
1133 .endif
1134         @echo "--------------------------------------------------------------"
1135         @echo ">>> Installing kernel ${INSTALLKERNEL}"
1136         @echo "--------------------------------------------------------------"
1137         cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1138             ${CROSSENV} PATH=${TMPPATH} \
1139             ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
1140 .endif
1141 .if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS)
1142 .for _kernel in ${BUILDKERNELS:[2..-1]}
1143         @echo "--------------------------------------------------------------"
1144         @echo ">>> Installing kernel ${_kernel}"
1145         @echo "--------------------------------------------------------------"
1146         cd ${KRNLOBJDIR}/${_kernel}; \
1147             ${CROSSENV} PATH=${TMPPATH} \
1148             ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME}.${_kernel} ${.TARGET:S/kernel//}
1149 .endfor
1150 .endif
1151
1152 distributekernel distributekernel.debug: .PHONY
1153 .if !defined(NO_INSTALLKERNEL)
1154 .if empty(INSTALLKERNEL)
1155         @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
1156         false
1157 .endif
1158         mkdir -p ${DESTDIR}/${DISTDIR}
1159 .if defined(NO_ROOT)
1160         @echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta
1161 .endif
1162         cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
1163             ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.premeta/} \
1164             ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \
1165             DESTDIR=${INSTALL_DDIR}/kernel \
1166             ${.TARGET:S/distributekernel/install/}
1167 .if defined(NO_ROOT)
1168         @sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
1169             ${DESTDIR}/${DISTDIR}/kernel.meta
1170 .endif
1171 .endif
1172 .if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS)
1173 .for _kernel in ${BUILDKERNELS:[2..-1]}
1174 .if defined(NO_ROOT)
1175         @echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
1176 .endif
1177         cd ${KRNLOBJDIR}/${_kernel}; \
1178             ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.${_kernel}.premeta/} \
1179             ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} \
1180             KERNEL=${INSTKERNNAME}.${_kernel} \
1181             DESTDIR=${INSTALL_DDIR}/kernel.${_kernel} \
1182             ${.TARGET:S/distributekernel/install/}
1183 .if defined(NO_ROOT)
1184         @sed -e "s|^./kernel.${_kernel}|.|" \
1185             ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta > \
1186             ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
1187 .endif
1188 .endfor
1189 .endif
1190
1191 packagekernel: .PHONY
1192 .if defined(NO_ROOT)
1193 .if !defined(NO_INSTALLKERNEL)
1194         cd ${DESTDIR}/${DISTDIR}/kernel; \
1195             tar cvf - --exclude '*.debug' \
1196             @${DESTDIR}/${DISTDIR}/kernel.meta | \
1197             ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1198 .endif
1199         cd ${DESTDIR}/${DISTDIR}/kernel; \
1200             tar cvf - --include '*/*/*.debug' \
1201             @${DESTDIR}/${DISTDIR}/kernel.meta | \
1202             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1203 .if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS)
1204 .for _kernel in ${BUILDKERNELS:[2..-1]}
1205         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1206             tar cvf - --exclude '*.debug' \
1207             @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1208             ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1209         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1210             tar cvf - --include '*/*/*.debug' \
1211             @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
1212             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1213 .endfor
1214 .endif
1215 .else
1216 .if !defined(NO_INSTALLKERNEL)
1217         cd ${DESTDIR}/${DISTDIR}/kernel; \
1218             tar cvf - --exclude '*.debug' . | \
1219             ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz
1220 .endif
1221         cd ${DESTDIR}/${DISTDIR}/kernel; \
1222             tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1223             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz
1224 .if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS)
1225 .for _kernel in ${BUILDKERNELS:[2..-1]}
1226         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1227             tar cvf - --exclude '*.debug' . | \
1228             ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz
1229         cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
1230             tar cvf - --include '*/*/*.debug' $$(eval find .) | \
1231             ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz
1232 .endfor
1233 .endif
1234 .endif
1235
1236 stagekernel: .PHONY
1237         ${_+_}${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} distributekernel
1238
1239 PORTSDIR?=      /usr/ports
1240 WSTAGEDIR?=     ${MAKEOBJDIRPREFIX}${.CURDIR}/${TARGET}.${TARGET_ARCH}/worldstage
1241 KSTAGEDIR?=     ${MAKEOBJDIRPREFIX}${.CURDIR}/${TARGET}.${TARGET_ARCH}/kernelstage
1242 REPODIR?=       ${MAKEOBJDIRPREFIX}${.CURDIR}/repo
1243 PKGSIGNKEY?=    # empty
1244
1245 .ORDER:         stage-packages create-packages
1246 .ORDER:         create-packages create-world-packages
1247 .ORDER:         create-packages create-kernel-packages
1248 .ORDER:         create-packages sign-packages
1249
1250 _pkgbootstrap: .PHONY
1251 .if !exists(${LOCALBASE}/sbin/pkg)
1252         @env ASSUME_ALWAYS_YES=YES pkg bootstrap
1253 .endif
1254
1255 packages: .PHONY
1256         ${_+_}${MAKE} -C ${.CURDIR} PKG_VERSION=${PKG_VERSION} real-packages
1257
1258 package-pkg: .PHONY
1259         rm -rf /tmp/ports.${TARGET} || :
1260         env ${WMAKEENV:Q} SRCDIR=${.CURDIR} PORTSDIR=${PORTSDIR} REVISION=${REVISION} \
1261                 PKG_VERSION=${PKG_VERSION} REPODIR=${REPODIR} WSTAGEDIR=${WSTAGEDIR} \
1262                 sh ${.CURDIR}/release/scripts/make-pkg-package.sh
1263
1264 real-packages:  stage-packages create-packages sign-packages .PHONY
1265
1266 stage-packages: .PHONY
1267         @mkdir -p ${REPODIR} ${WSTAGEDIR} ${KSTAGEDIR}
1268         ${_+_}@cd ${.CURDIR}; \
1269                 ${MAKE} DESTDIR=${WSTAGEDIR} -DNO_ROOT -B stageworld ; \
1270                 ${MAKE} DESTDIR=${KSTAGEDIR} -DNO_ROOT -B stagekernel
1271
1272 create-packages:        _pkgbootstrap .PHONY
1273         @mkdir -p ${REPODIR}
1274         ${_+_}@cd ${.CURDIR}; \
1275                 ${MAKE} DESTDIR=${WSTAGEDIR} \
1276                         PKG_VERSION=${PKG_VERSION} create-world-packages ; \
1277                 ${MAKE} DESTDIR=${KSTAGEDIR} \
1278                         PKG_VERSION=${PKG_VERSION} DISTDIR=kernel \
1279                         create-kernel-packages
1280
1281 create-world-packages:  _pkgbootstrap .PHONY
1282         @rm -f ${WSTAGEDIR}/*.plist 2>/dev/null || :
1283         @cd ${WSTAGEDIR} ; \
1284                 awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
1285                 ${WSTAGEDIR}/METALOG
1286         @for plist in ${WSTAGEDIR}/*.plist; do \
1287                 plist=$${plist##*/} ; \
1288                 pkgname=$${plist%.plist} ; \
1289                 sh ${SRCDIR}/release/packages/generate-ucl.sh -o $${pkgname} \
1290                         -s ${SRCDIR} -u ${WSTAGEDIR}/$${pkgname}.ucl ; \
1291         done
1292         @for plist in ${WSTAGEDIR}/*.plist; do \
1293                 plist=$${plist##*/} ; \
1294                 pkgname=$${plist%.plist} ; \
1295                 awk -F\" ' \
1296                         /^name/ { printf("===> Creating %s-", $$2); next } \
1297                         /^version/ { print $$2; next } \
1298                         ' ${WSTAGEDIR}/$${pkgname}.ucl ; \
1299                 pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh -o ALLOW_BASE_SHLIBS=yes \
1300                         create -M ${WSTAGEDIR}/$${pkgname}.ucl \
1301                         -p ${WSTAGEDIR}/$${pkgname}.plist \
1302                         -r ${WSTAGEDIR} \
1303                         -o ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} ; \
1304         done
1305
1306 create-kernel-packages: _pkgbootstrap .PHONY
1307 .if exists(${KSTAGEDIR}/kernel.meta)
1308 .for flavor in "" -debug
1309         @cd ${KSTAGEDIR}/${DISTDIR} ; \
1310         awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
1311                 -v kernel=yes -v _kernconf=${INSTALLKERNEL} \
1312                 ${KSTAGEDIR}/kernel.meta ; \
1313         cap_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VCAP_MKDB_ENDIAN` ; \
1314         pwd_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VPWD_MKDB_ENDIAN` ; \
1315         sed -e "s/%VERSION%/${PKG_VERSION}/" \
1316                 -e "s/%PKGNAME%/kernel-${INSTALLKERNEL:tl}${flavor}/" \
1317                 -e "s/%COMMENT%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
1318                 -e "s/%DESC%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
1319                 -e "s/%CAP_MKDB_ENDIAN%/$${cap_arg}/g" \
1320                 -e "s/%PWD_MKDB_ENDIAN%/$${pwd_arg}/g" \
1321                 ${SRCDIR}/release/packages/kernel.ucl \
1322                 > ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
1323         awk -F\" ' \
1324                 /name/ { printf("===> Creating %s-", $$2); next } \
1325                 /version/ {print $$2; next } ' \
1326                 ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
1327         pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh -o ALLOW_BASE_SHLIBS=yes \
1328                 create -M ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl \
1329                 -p ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.plist \
1330                 -r ${KSTAGEDIR}/${DISTDIR} \
1331                 -o ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION}
1332 .endfor
1333 .endif
1334 .if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS)
1335 .for _kernel in ${BUILDKERNELS:[2..-1]}
1336 .if exists(${KSTAGEDIR}/kernel.${_kernel}.meta)
1337 .for flavor in "" -debug
1338         @cd ${KSTAGEDIR}/kernel.${_kernel} ; \
1339         awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
1340                 -v kernel=yes -v _kernconf=${_kernel} \
1341                 ${KSTAGEDIR}/kernel.${_kernel}.meta ; \
1342         cap_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VCAP_MKDB_ENDIAN` ; \
1343         pwd_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VPWD_MKDB_ENDIAN` ; \
1344         sed -e "s/%VERSION%/${PKG_VERSION}/" \
1345                 -e "s/%PKGNAME%/kernel-${_kernel:tl}${flavor}/" \
1346                 -e "s/%COMMENT%/FreeBSD ${_kernel} kernel ${flavor}/" \
1347                 -e "s/%DESC%/FreeBSD ${_kernel} kernel ${flavor}/" \
1348                 -e "s/%CAP_MKDB_ENDIAN%/$${cap_arg}/g" \
1349                 -e "s/%PWD_MKDB_ENDIAN%/$${pwd_arg}/g" \
1350                 ${SRCDIR}/release/packages/kernel.ucl \
1351                 > ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
1352         awk -F\" ' \
1353                 /name/ { printf("===> Creating %s-", $$2); next } \
1354                 /version/ {print $$2; next } ' \
1355                 ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
1356         pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh -o ALLOW_BASE_SHLIBS=yes \
1357                 create -M ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl \
1358                 -p ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.plist \
1359                 -r ${KSTAGEDIR}/kernel.${_kernel} \
1360                 -o ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION}
1361 .endfor
1362 .endif
1363 .endfor
1364 .endif
1365
1366 sign-packages:  _pkgbootstrap .PHONY
1367         @[ -L "${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/latest" ] && \
1368                 unlink ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/latest ; \
1369         pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh repo \
1370                 -o ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} \
1371                 ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} \
1372                 ${PKGSIGNKEY} ; \
1373         ln -s ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} \
1374                 ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/latest
1375
1376 #
1377 #
1378 # checkworld
1379 #
1380 # Run test suite on installed world.
1381 #
1382 checkworld: .PHONY
1383         @if [ ! -x ${LOCALBASE}/bin/kyua ]; then \
1384                 echo "You need kyua (devel/kyua) to run the test suite." | /usr/bin/fmt; \
1385                 exit 1; \
1386         fi
1387         ${_+_}${LOCALBASE}/bin/kyua test -k ${TESTSBASE}/Kyuafile
1388
1389 #
1390 #
1391 # doxygen
1392 #
1393 # Build the API documentation with doxygen
1394 #
1395 doxygen: .PHONY
1396         @if [ ! -x ${LOCALBASE}/bin/doxygen ]; then \
1397                 echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
1398                 exit 1; \
1399         fi
1400         ${_+_}cd ${.CURDIR}/tools/kerneldoc/subsys; ${MAKE} obj all
1401
1402 #
1403 # update
1404 #
1405 # Update the source tree(s), by running svn/svnup to update to the
1406 # latest copy.
1407 #
1408 update: .PHONY
1409 .if defined(SVN_UPDATE)
1410         @echo "--------------------------------------------------------------"
1411         @echo ">>> Updating ${.CURDIR} using Subversion"
1412         @echo "--------------------------------------------------------------"
1413         @(cd ${.CURDIR}; ${SVN} update ${SVNFLAGS})
1414 .endif
1415
1416 #
1417 # ------------------------------------------------------------------------
1418 #
1419 # From here onwards are utility targets used by the 'make world' and
1420 # related targets.  If your 'world' breaks, you may like to try to fix
1421 # the problem and manually run the following targets to attempt to
1422 # complete the build.  Beware, this is *not* guaranteed to work, you
1423 # need to have a pretty good grip on the current state of the system
1424 # to attempt to manually finish it.  If in doubt, 'make world' again.
1425 #
1426
1427 #
1428 # legacy: Build compatibility shims for the next three targets. This is a
1429 # minimal set of tools and shims necessary to compensate for older systems
1430 # which don't have the APIs required by the targets built in bootstrap-tools,
1431 # build-tools or cross-tools.
1432 #
1433
1434 # ELF Tool Chain libraries are needed for ELF tools and dtrace tools.
1435 # r296685 fix cross-endian objcopy
1436 .if ${BOOTSTRAPPING} < 1100102
1437 _elftoolchain_libs= lib/libelf lib/libdwarf
1438 .endif
1439
1440 legacy: .PHONY
1441 .if ${BOOTSTRAPPING} < 800107 && ${BOOTSTRAPPING} != 0
1442         @echo "ERROR: Source upgrades from versions prior to 8.0 are not supported."; \
1443         false
1444 .endif
1445 .for _tool in tools/build ${_elftoolchain_libs}
1446         ${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,all,install)"; \
1447             cd ${.CURDIR}/${_tool}; \
1448             ${MAKE} DIRPRFX=${_tool}/ obj; \
1449             ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes; \
1450             ${MAKE} DIRPRFX=${_tool}/ all; \
1451             ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1452 .endfor
1453
1454 #
1455 # bootstrap-tools: Build tools needed for compatibility. These are binaries that
1456 # are built to build other binaries in the system. However, the focus of these
1457 # binaries is usually quite narrow. Bootstrap tools use the host's compiler and
1458 # libraries, augmented by -legacy.
1459 #
1460 _bt=            _bootstrap-tools
1461
1462 .if ${MK_GAMES} != "no"
1463 _strfile=       usr.bin/fortune/strfile
1464 .endif
1465
1466 .if ${MK_GCC} != "no" && ${MK_CXX} != "no"
1467 _gperf=         gnu/usr.bin/gperf
1468 .endif
1469
1470 .if ${MK_GROFF} != "no"
1471 _groff=         gnu/usr.bin/groff \
1472                 usr.bin/soelim
1473 .endif
1474
1475 .if ${MK_VT} != "no"
1476 _vtfontcvt=     usr.bin/vtfontcvt
1477 .endif
1478
1479 .if ${BOOTSTRAPPING} < 900002
1480 _sed=           usr.bin/sed
1481 .endif
1482
1483 .if ${BOOTSTRAPPING} < 1000033
1484 _libopenbsd=    lib/libopenbsd
1485 _m4=            usr.bin/m4
1486 _lex=           usr.bin/lex
1487
1488 ${_bt}-usr.bin/m4: ${_bt}-lib/libopenbsd
1489 ${_bt}-usr.bin/lex: ${_bt}-usr.bin/m4
1490 .endif
1491
1492 .if ${BOOTSTRAPPING} < 1000026
1493 _nmtree=        lib/libnetbsd \
1494                 usr.sbin/nmtree
1495
1496 ${_bt}-usr.sbin/nmtree: ${_bt}-lib/libnetbsd
1497 .endif
1498
1499 .if ${BOOTSTRAPPING} < 1000027
1500 _cat=           bin/cat
1501 .endif
1502
1503 # r264059 support for status=
1504 .if ${BOOTSTRAPPING} < 1100017
1505 _dd=            bin/dd
1506 .endif
1507
1508 # r277259 crunchide: Correct 64-bit section header offset
1509 # r281674 crunchide: always include both 32- and 64-bit ELF support
1510 # r285986 crunchen: use STRIPBIN rather than STRIP
1511 .if ${BOOTSTRAPPING} < 1100078
1512 _crunch=        usr.sbin/crunch
1513 .endif
1514
1515 .if ${BOOTSTRAPPING} >= 900040 && ${BOOTSTRAPPING} < 900041
1516 _awk=           usr.bin/awk
1517 .endif
1518
1519 # r296926 -P keymap search path, MFC to stable/10 in r298297
1520 .if ${BOOTSTRAPPING} < 1003501 || \
1521         (${BOOTSTRAPPING} >= 1100000 && ${BOOTSTRAPPING} < 1100103)
1522 _kbdcontrol=    usr.sbin/kbdcontrol
1523 .endif
1524
1525 _yacc=          lib/liby \
1526                 usr.bin/yacc
1527
1528 ${_bt}-usr.bin/yacc: ${_bt}-lib/liby
1529
1530 .if ${MK_BSNMP} != "no"
1531 _gensnmptree=   usr.sbin/bsnmpd/gensnmptree
1532 .endif
1533
1534 # We need to build tblgen when we're building clang either as
1535 # the bootstrap compiler, or as the part of the normal build.
1536 .if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_CLANG} != "no"
1537 _clang_tblgen= \
1538         lib/clang/libllvmsupport \
1539         lib/clang/libllvmtablegen \
1540         usr.bin/clang/llvm-tblgen \
1541         usr.bin/clang/clang-tblgen
1542
1543 ${_bt}-usr.bin/clang/clang-tblgen: ${_bt}-lib/clang/libllvmtablegen ${_bt}-lib/clang/libllvmsupport
1544 ${_bt}-usr.bin/clang/llvm-tblgen: ${_bt}-lib/clang/libllvmtablegen ${_bt}-lib/clang/libllvmsupport
1545 .endif
1546
1547 # Default to building the GPL DTC, but build the BSDL one if users explicitly
1548 # request it.
1549 _dtc= usr.bin/dtc
1550 .if ${MK_GPL_DTC} != "no"
1551 _dtc= gnu/usr.bin/dtc
1552 .endif
1553
1554 .if ${MK_KERBEROS} != "no"
1555 _kerberos5_bootstrap_tools= \
1556         kerberos5/tools/make-roken \
1557         kerberos5/lib/libroken \
1558         kerberos5/lib/libvers \
1559         kerberos5/tools/asn1_compile \
1560         kerberos5/tools/slc \
1561         usr.bin/compile_et
1562
1563 .ORDER: ${_kerberos5_bootstrap_tools:C/^/${_bt}-/g}
1564 .endif
1565
1566 # r283777 makewhatis(1) replaced with mandoc version which builds a database.
1567 .if ${MK_MANDOCDB} != "no" && ${BOOTSTRAPPING} < 1100075
1568 _libopenbsd?=   lib/libopenbsd
1569 _makewhatis=    lib/libsqlite3 \
1570                 usr.bin/mandoc
1571 ${_bt}-usr.bin/mandoc: ${_bt}-lib/libopenbsd ${_bt}-lib/libsqlite3
1572 .endif
1573
1574 bootstrap-tools: .PHONY
1575
1576 #       Please document (add comment) why something is in 'bootstrap-tools'.
1577 #       Try to bound the building of the bootstrap-tool to just the
1578 #       FreeBSD versions that need the tool built at this stage of the build.
1579 .for _tool in \
1580     ${_clang_tblgen} \
1581     ${_kerberos5_bootstrap_tools} \
1582     ${_strfile} \
1583     ${_gperf} \
1584     ${_groff} \
1585     ${_dtc} \
1586     ${_awk} \
1587     ${_cat} \
1588     ${_dd} \
1589     ${_kbdcontrol} \
1590     usr.bin/lorder \
1591     ${_libopenbsd} \
1592     ${_makewhatis} \
1593     usr.bin/rpcgen \
1594     ${_sed} \
1595     ${_yacc} \
1596     ${_m4} \
1597     ${_lex} \
1598     usr.bin/xinstall \
1599     ${_gensnmptree} \
1600     usr.sbin/config \
1601     ${_crunch} \
1602     ${_nmtree} \
1603     ${_vtfontcvt} \
1604     usr.bin/localedef
1605 ${_bt}-${_tool}: .PHONY .MAKE
1606         ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
1607                 cd ${.CURDIR}/${_tool}; \
1608                 ${MAKE} DIRPRFX=${_tool}/ obj; \
1609                 ${MAKE} DIRPRFX=${_tool}/ all; \
1610                 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
1611
1612 bootstrap-tools: ${_bt}-${_tool}
1613 .endfor
1614
1615 #
1616 # build-tools: Build special purpose build tools
1617 #
1618 .if !defined(NO_SHARE)
1619 _share= share/syscons/scrnmaps
1620 .endif
1621
1622 .if ${MK_GCC} != "no"
1623 _gcc_tools= gnu/usr.bin/cc/cc_tools
1624 .endif
1625
1626 .if ${MK_RESCUE} != "no"
1627 # rescue includes programs that have build-tools targets
1628 _rescue=rescue/rescue
1629 .endif
1630
1631 .for _tool in \
1632     bin/csh \
1633     bin/sh \
1634     ${LOCAL_TOOL_DIRS} \
1635     lib/ncurses/ncurses \
1636     lib/ncurses/ncursesw \
1637     ${_rescue} \
1638     ${_share} \
1639     usr.bin/awk \
1640     lib/libmagic \
1641     usr.bin/mkesdb_static \
1642     usr.bin/mkcsmapper_static \
1643     usr.bin/vi/catalog
1644 build-tools_${_tool}: .PHONY
1645         ${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
1646                 cd ${.CURDIR}/${_tool}; \
1647                 ${MAKE} DIRPRFX=${_tool}/ obj; \
1648                 ${MAKE} DIRPRFX=${_tool}/ build-tools
1649 build-tools: build-tools_${_tool}
1650 .endfor
1651 .for _tool in \
1652     ${_gcc_tools}
1653 build-tools_${_tool}: .PHONY
1654         ${_+_}@${ECHODIR} "===> ${_tool} (obj,all)"; \
1655                 cd ${.CURDIR}/${_tool}; \
1656                 ${MAKE} DIRPRFX=${_tool}/ obj; \
1657                 ${MAKE} DIRPRFX=${_tool}/ all
1658 build-tools: build-tools_${_tool}
1659 .endfor
1660
1661 #
1662 # kernel-tools: Build kernel-building tools
1663 #
1664 kernel-tools: .PHONY
1665         mkdir -p ${MAKEOBJDIRPREFIX}/usr
1666         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1667             -p ${MAKEOBJDIRPREFIX}/usr >/dev/null
1668
1669 #
1670 # cross-tools: All the tools needed to build the rest of the system after
1671 # we get done with the earlier stages. It is the last set of tools needed
1672 # to begin building the target binaries.
1673 #
1674 .if ${TARGET_ARCH} != ${MACHINE_ARCH}
1675 .if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
1676 _btxld=         usr.sbin/btxld
1677 .endif
1678 .endif
1679
1680 # Rebuild ctfconvert and ctfmerge to avoid difficult-to-diagnose failures
1681 # resulting from missing bug fixes or ELF Toolchain updates.
1682 .if ${MK_CDDL} != "no"
1683 _dtrace_tools= cddl/lib/libctf cddl/usr.bin/ctfconvert \
1684     cddl/usr.bin/ctfmerge
1685 .endif
1686
1687 # If we're given an XAS, don't build binutils.
1688 .if ${XAS:M/*} == ""
1689 .if ${MK_BINUTILS_BOOTSTRAP} != "no"
1690 _binutils=      gnu/usr.bin/binutils
1691 .endif
1692 .if ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no"
1693 _elftctools=    lib/libelftc \
1694                 lib/libpe \
1695                 usr.bin/elfcopy \
1696                 usr.bin/nm \
1697                 usr.bin/size \
1698                 usr.bin/strings
1699 # These are not required by the build, but can be useful for developers who
1700 # cross-build on a FreeBSD 10 host:
1701 _elftctools+=   usr.bin/addr2line
1702 .endif
1703 .elif ${TARGET_ARCH} != ${MACHINE_ARCH} && ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no"
1704 # If cross-building with an external binutils we still need to build strip for
1705 # the target (for at least crunchide).
1706 _elftctools=    lib/libelftc \
1707                 lib/libpe \
1708                 usr.bin/elfcopy
1709 .endif
1710
1711 # If an full path to an external cross compiler is given, don't build
1712 # a cross compiler.
1713 .if ${XCC:N${CCACHE_BIN}:M/*} == "" && ${MK_CROSS_COMPILER} != "no"
1714 .if ${MK_CLANG_BOOTSTRAP} != "no"
1715 _clang=         usr.bin/clang
1716 _clang_libs=    lib/clang
1717 .endif
1718 .if ${MK_GCC_BOOTSTRAP} != "no"
1719 _cc=            gnu/usr.bin/cc
1720 .endif
1721 .endif
1722 .if ${MK_USB} != "no"
1723 _usb_tools=     sys/boot/usb/tools
1724 .endif
1725
1726 cross-tools: .MAKE .PHONY
1727 .for _tool in \
1728     ${_clang_libs} \
1729     ${_clang} \
1730     ${_binutils} \
1731     ${_elftctools} \
1732     ${_dtrace_tools} \
1733     ${_cc} \
1734     ${_btxld} \
1735     ${_crunchide} \
1736     ${_usb_tools}
1737         ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
1738                 cd ${.CURDIR}/${_tool}; \
1739                 ${MAKE} DIRPRFX=${_tool}/ obj; \
1740                 ${MAKE} DIRPRFX=${_tool}/ all; \
1741                 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
1742 .endfor
1743
1744 NXBDESTDIR=     ${OBJTREE}/nxb-bin
1745 NXBENV=         MAKEOBJDIRPREFIX=${OBJTREE}/nxb \
1746                 INSTALL="sh ${.CURDIR}/tools/install.sh" \
1747                 PATH=${PATH}:${OBJTREE}/gperf_for_gcc/usr/bin
1748 NXBMAKE=        ${NXBENV} ${MAKE} \
1749                 LLVM_TBLGEN=${NXBDESTDIR}/usr/bin/llvm-tblgen \
1750                 CLANG_TBLGEN=${NXBDESTDIR}/usr/bin/clang-tblgen \
1751                 MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH} \
1752                 MK_GDB=no MK_TESTS=no \
1753                 SSP_CFLAGS= \
1754                 MK_HTML=no NO_LINT=yes MK_MAN=no \
1755                 -DNO_PIC MK_PROFILE=no -DNO_SHARED \
1756                 -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
1757                 MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \
1758                 MK_LLDB=no MK_DEBUG_FILES=no
1759
1760 # native-xtools is the current target for qemu-user cross builds of ports
1761 # via poudriere and the imgact_binmisc kernel module.
1762 # For non-clang enabled targets that are still using the in tree gcc
1763 # we must build a gperf binary for one instance of its Makefiles.  On
1764 # clang-enabled systems, the gperf binary is obsolete.
1765 native-xtools: .PHONY
1766 .if ${MK_GCC_BOOTSTRAP} != "no"
1767         mkdir -p ${OBJTREE}/gperf_for_gcc/usr/bin
1768         ${_+_}@${ECHODIR} "===> ${_gperf} (obj,all,install)"; \
1769         cd ${.CURDIR}/${_gperf}; \
1770         ${NXBMAKE} DIRPRFX=${_gperf}/ obj; \
1771         ${NXBMAKE} DIRPRFX=${_gperf}/ all; \
1772         ${NXBMAKE} DIRPRFX=${_gperf}/ DESTDIR=${OBJTREE}/gperf_for_gcc install
1773 .endif
1774         mkdir -p ${NXBDESTDIR}/bin ${NXBDESTDIR}/sbin ${NXBDESTDIR}/usr
1775         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1776             -p ${NXBDESTDIR}/usr >/dev/null
1777         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1778             -p ${NXBDESTDIR}/usr/include >/dev/null
1779 .if ${MK_DEBUG_FILES} != "no"
1780         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
1781             -p ${NXBDESTDIR}/usr/lib >/dev/null
1782 .endif
1783 .for _tool in \
1784     bin/cat \
1785     bin/chmod \
1786     bin/cp \
1787     bin/csh \
1788     bin/echo \
1789     bin/expr \
1790     bin/hostname \
1791     bin/ln \
1792     bin/ls \
1793     bin/mkdir \
1794     bin/mv \
1795     bin/ps \
1796     bin/realpath \
1797     bin/rm \
1798     bin/rmdir \
1799     bin/sh \
1800     bin/sleep \
1801     ${_clang_tblgen} \
1802     usr.bin/ar \
1803     ${_binutils} \
1804     ${_elftctools} \
1805     ${_cc} \
1806     ${_gcc_tools} \
1807     ${_clang_libs} \
1808     ${_clang} \
1809     sbin/md5 \
1810     sbin/sysctl \
1811     gnu/usr.bin/diff \
1812     usr.bin/awk \
1813     usr.bin/basename \
1814     usr.bin/bmake \
1815     usr.bin/bzip2 \
1816     usr.bin/cmp \
1817     usr.bin/dirname \
1818     usr.bin/env \
1819     usr.bin/fetch \
1820     usr.bin/find \
1821     usr.bin/grep \
1822     usr.bin/gzip \
1823     usr.bin/id \
1824     usr.bin/lex \
1825     usr.bin/lorder \
1826     usr.bin/mktemp \
1827     usr.bin/mt \
1828     usr.bin/patch \
1829     usr.bin/sed \
1830     usr.bin/sort \
1831     usr.bin/tar \
1832     usr.bin/touch \
1833     usr.bin/tr \
1834     usr.bin/true \
1835     usr.bin/uniq \
1836     usr.bin/unzip \
1837     usr.bin/xargs \
1838     usr.bin/xinstall \
1839     usr.bin/xz \
1840     usr.bin/yacc \
1841     usr.sbin/chown
1842         ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
1843                 cd ${.CURDIR}/${_tool}; \
1844                 ${NXBMAKE} DIRPRFX=${_tool}/ obj; \
1845                 ${NXBMAKE} DIRPRFX=${_tool}/ all; \
1846                 ${NXBMAKE} DIRPRFX=${_tool}/ DESTDIR=${NXBDESTDIR} install
1847 .endfor
1848
1849 #
1850 # hierarchy - ensure that all the needed directories are present
1851 #
1852 hierarchy hier: .MAKE .PHONY
1853         ${_+_}cd ${.CURDIR}/etc; ${HMAKE} distrib-dirs
1854
1855 #
1856 # libraries - build all libraries, and install them under ${DESTDIR}.
1857 #
1858 # The list of libraries with dependents (${_prebuild_libs}) and their
1859 # interdependencies (__L) are built automatically by the
1860 # ${.CURDIR}/tools/make_libdeps.sh script.
1861 #
1862 libraries: .MAKE .PHONY
1863         ${_+_}cd ${.CURDIR}; \
1864             ${MAKE} -f Makefile.inc1 _prereq_libs; \
1865             ${MAKE} -f Makefile.inc1 _startup_libs; \
1866             ${MAKE} -f Makefile.inc1 _prebuild_libs; \
1867             ${MAKE} -f Makefile.inc1 _generic_libs
1868
1869 #
1870 # static libgcc.a prerequisite for shared libc
1871 #
1872 _prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc lib/libcompiler_rt
1873
1874 # These dependencies are not automatically generated:
1875 #
1876 # gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before
1877 # all shared libraries for ELF.
1878 #
1879 _startup_libs=  gnu/lib/csu
1880 _startup_libs+= lib/csu
1881 _startup_libs+= gnu/lib/libgcc
1882 _startup_libs+= lib/libcompiler_rt
1883 _startup_libs+= lib/libc
1884 _startup_libs+= lib/libc_nonshared
1885 .if ${MK_LIBCPLUSPLUS} != "no"
1886 _startup_libs+= lib/libcxxrt
1887 .endif
1888
1889 gnu/lib/libgcc__L: lib/libc__L
1890 gnu/lib/libgcc__L: lib/libc_nonshared__L
1891 .if ${MK_LIBCPLUSPLUS} != "no"
1892 lib/libcxxrt__L: gnu/lib/libgcc__L
1893 .endif
1894
1895 _prebuild_libs= ${_kerberos5_lib_libasn1} \
1896                 ${_kerberos5_lib_libhdb} \
1897                 ${_kerberos5_lib_libheimbase} \
1898                 ${_kerberos5_lib_libheimntlm} \
1899                 ${_libsqlite3} \
1900                 ${_kerberos5_lib_libheimipcc} \
1901                 ${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
1902                 ${_kerberos5_lib_libroken} \
1903                 ${_kerberos5_lib_libwind} \
1904                 lib/libbz2 ${_libcom_err} lib/libcrypt \
1905                 lib/libelf lib/libexpat \
1906                 lib/libfigpar \
1907                 ${_lib_libgssapi} \
1908                 lib/libkiconv lib/libkvm lib/liblzma lib/libmd lib/libnv \
1909                 ${_lib_casper} \
1910                 lib/ncurses/ncurses lib/ncurses/ncursesw \
1911                 lib/libopie lib/libpam/libpam ${_lib_libthr} \
1912                 ${_lib_libradius} lib/libsbuf lib/libtacplus \
1913                 lib/libgeom \
1914                 ${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \
1915                 ${_cddl_lib_libuutil} \
1916                 ${_cddl_lib_libavl} \
1917                 ${_cddl_lib_libzfs_core} \
1918                 ${_cddl_lib_libctf} \
1919                 lib/libutil lib/libpjdlog ${_lib_libypclnt} lib/libz lib/msun \
1920                 ${_secure_lib_libcrypto} ${_lib_libldns} \
1921                 ${_secure_lib_libssh} ${_secure_lib_libssl} \
1922                 gnu/lib/libdialog
1923
1924 .if ${MK_GNUCXX} != "no"
1925 _prebuild_libs+= gnu/lib/libstdc++ gnu/lib/libsupc++
1926 gnu/lib/libstdc++__L: lib/msun__L
1927 gnu/lib/libsupc++__L: gnu/lib/libstdc++__L
1928 .endif
1929
1930 .if ${MK_LIBCPLUSPLUS} != "no"
1931 _prebuild_libs+= lib/libc++
1932 .endif
1933
1934 lib/libgeom__L: lib/libexpat__L
1935 lib/libkvm__L: lib/libelf__L
1936
1937 .if ${MK_LIBTHR} != "no"
1938 _lib_libthr=    lib/libthr
1939 .endif
1940
1941 .if ${MK_RADIUS_SUPPORT} != "no"
1942 _lib_libradius= lib/libradius
1943 .endif
1944
1945 .if ${MK_OFED} != "no"
1946 _ofed_lib=              contrib/ofed/usr.lib
1947 _prebuild_libs+=        contrib/ofed/usr.lib/libosmcomp
1948 _prebuild_libs+=        contrib/ofed/usr.lib/libopensm
1949 _prebuild_libs+=        contrib/ofed/usr.lib/libibcommon
1950 _prebuild_libs+=        contrib/ofed/usr.lib/libibverbs
1951 _prebuild_libs+=        contrib/ofed/usr.lib/libibumad
1952
1953 contrib/ofed/usr.lib/libopensm__L: lib/libthr__L
1954 contrib/ofed/usr.lib/libosmcomp__L: lib/libthr__L
1955 contrib/ofed/usr.lib/libibumad__L: contrib/ofed/usr.lib/libibcommon__L
1956 .endif
1957
1958 .if ${MK_CASPER} != "no"
1959 _lib_casper=    lib/libcasper
1960 .endif
1961
1962 lib/libpjdlog__L: lib/libutil__L
1963 lib/libcasper__L: lib/libnv__L
1964 lib/liblzma__L: lib/libthr__L
1965
1966 _generic_libs=  ${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib ${_ofed_lib}
1967 .for _DIR in ${LOCAL_LIB_DIRS}
1968 .if exists(${.CURDIR}/${_DIR}/Makefile) && empty(_generic_libs:M${_DIR})
1969 _generic_libs+= ${_DIR}
1970 .endif
1971 .endfor
1972
1973 lib/libopie__L lib/libtacplus__L: lib/libmd__L
1974
1975 .if ${MK_CDDL} != "no"
1976 _cddl_lib_libumem= cddl/lib/libumem
1977 _cddl_lib_libnvpair= cddl/lib/libnvpair
1978 _cddl_lib_libavl= cddl/lib/libavl
1979 _cddl_lib_libuutil= cddl/lib/libuutil
1980 _cddl_lib_libzfs_core= cddl/lib/libzfs_core
1981 _cddl_lib_libctf= cddl/lib/libctf
1982 _cddl_lib= cddl/lib
1983 cddl/lib/libzfs_core__L: cddl/lib/libnvpair__L
1984 cddl/lib/libzfs__L: lib/libgeom__L
1985 cddl/lib/libctf__L: lib/libz__L
1986 .endif
1987 # cddl/lib/libdtrace requires lib/libproc and lib/librtld_db; it's only built
1988 # on select architectures though (see cddl/lib/Makefile)
1989 .if ${MACHINE_CPUARCH} != "sparc64"
1990 _prebuild_libs+=        lib/libproc lib/librtld_db
1991 .endif
1992
1993 .if ${MK_CRYPT} != "no"
1994 .if ${MK_OPENSSL} != "no"
1995 _secure_lib_libcrypto= secure/lib/libcrypto
1996 _secure_lib_libssl= secure/lib/libssl
1997 lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1998 .if ${MK_LDNS} != "no"
1999 _lib_libldns= lib/libldns
2000 lib/libldns__L: secure/lib/libcrypto__L
2001 .endif
2002 .if ${MK_OPENSSH} != "no"
2003 _secure_lib_libssh= secure/lib/libssh
2004 secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
2005 .if ${MK_LDNS} != "no"
2006 secure/lib/libssh__L: lib/libldns__L
2007 .endif
2008 .if ${MK_KERBEROS_SUPPORT} != "no"
2009 secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
2010     kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
2011     lib/libmd__L kerberos5/lib/libroken__L
2012 .endif
2013 .endif
2014 .endif
2015 _secure_lib=    secure/lib
2016 .endif
2017
2018 .if ${MK_KERBEROS} != "no"
2019 kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L
2020 kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2021     kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \
2022     kerberos5/lib/libwind__L lib/libsqlite3__L
2023 kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \
2024     kerberos5/lib/libroken__L lib/libcom_err__L
2025 kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2026     secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L
2027 kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \
2028     lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \
2029     kerberos5/lib/libroken__L kerberos5/lib/libwind__L \
2030     kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L
2031 kerberos5/lib/libroken__L: lib/libcrypt__L
2032 kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L
2033 kerberos5/lib/libheimbase__L: lib/libthr__L
2034 kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L
2035 .endif
2036
2037 lib/libsqlite3__L: lib/libthr__L
2038
2039 .if ${MK_GSSAPI} != "no"
2040 _lib_libgssapi= lib/libgssapi
2041 .endif
2042
2043 .if ${MK_KERBEROS} != "no"
2044 _kerberos5_lib= kerberos5/lib
2045 _kerberos5_lib_libasn1= kerberos5/lib/libasn1
2046 _kerberos5_lib_libhdb= kerberos5/lib/libhdb
2047 _kerberos5_lib_libheimbase= kerberos5/lib/libheimbase
2048 _kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
2049 _kerberos5_lib_libhx509= kerberos5/lib/libhx509
2050 _kerberos5_lib_libroken= kerberos5/lib/libroken
2051 _kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
2052 _libsqlite3= lib/libsqlite3
2053 _kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc
2054 _kerberos5_lib_libwind= kerberos5/lib/libwind
2055 _libcom_err= lib/libcom_err
2056 .endif
2057
2058 .if ${MK_NIS} != "no"
2059 _lib_libypclnt= lib/libypclnt
2060 .endif
2061
2062 .if ${MK_OPENSSL} == "no"
2063 lib/libradius__L: lib/libmd__L
2064 .endif
2065
2066 lib/libproc__L: \
2067     ${_cddl_lib_libctf:D${_cddl_lib_libctf}__L} lib/libelf__L lib/librtld_db__L lib/libutil__L
2068 .if ${MK_CXX} != "no"
2069 .if ${MK_LIBCPLUSPLUS} != "no"
2070 lib/libproc__L: lib/libcxxrt__L
2071 .else # This implies MK_GNUCXX != "no"; see lib/libproc
2072 lib/libproc__L: gnu/lib/libsupc++__L
2073 .endif
2074 .endif
2075
2076 gnu/lib/libdialog__L: lib/msun__L lib/ncurses/ncursesw__L
2077
2078 .for _lib in ${_prereq_libs}
2079 ${_lib}__PL: .PHONY .MAKE
2080 .if exists(${.CURDIR}/${_lib})
2081         ${_+_}@${ECHODIR} "===> ${_lib} (obj,all,install)"; \
2082                 cd ${.CURDIR}/${_lib}; \
2083                 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; \
2084                 ${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
2085                     DIRPRFX=${_lib}/ all; \
2086                 ${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \
2087                     DIRPRFX=${_lib}/ install
2088 .endif
2089 .endfor
2090
2091 .for _lib in ${_startup_libs} ${_prebuild_libs} ${_generic_libs}
2092 ${_lib}__L: .PHONY .MAKE
2093 .if exists(${.CURDIR}/${_lib})
2094         ${_+_}@${ECHODIR} "===> ${_lib} (obj,all,install)"; \
2095                 cd ${.CURDIR}/${_lib}; \
2096                 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; \
2097                 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ all; \
2098                 ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ install
2099 .endif
2100 .endfor
2101
2102 _prereq_libs: ${_prereq_libs:S/$/__PL/}
2103 _startup_libs: ${_startup_libs:S/$/__L/}
2104 _prebuild_libs: ${_prebuild_libs:S/$/__L/}
2105 _generic_libs: ${_generic_libs:S/$/__L/}
2106
2107 # Enable SUBDIR_PARALLEL when not calling 'make all', unless called from
2108 # 'everything' with _PARALLEL_SUBDIR_OK set.  This is because it is unlikely
2109 # that running 'make all' from the top-level, especially with a SUBDIR_OVERRIDE
2110 # or LOCAL_DIRS set, will have a reliable build if SUBDIRs are built in
2111 # parallel.  This is safe for the world stage of buildworld though since it has
2112 # already built libraries in a proper order and installed includes into
2113 # WORLDTMP. Special handling is done for SUBDIR ordering for 'install*' to
2114 # avoid trashing a system if it crashes mid-install.
2115 .if !make(all) || defined(_PARALLEL_SUBDIR_OK)
2116 SUBDIR_PARALLEL=
2117 .endif
2118
2119 .include <bsd.subdir.mk>
2120
2121 .if make(check-old) || make(check-old-dirs) || \
2122     make(check-old-files) || make(check-old-libs) || \
2123     make(delete-old) || make(delete-old-dirs) || \
2124     make(delete-old-files) || make(delete-old-libs)
2125
2126 #
2127 # check for / delete old files section
2128 #
2129
2130 .include "ObsoleteFiles.inc"
2131
2132 OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
2133 else you can not start such an application. Consult UPDATING for more \
2134 information regarding how to cope with the removal/revision bump of a \
2135 specific library."
2136
2137 .if !defined(BATCH_DELETE_OLD_FILES)
2138 RM_I=-i
2139 .else
2140 RM_I=-v
2141 .endif
2142
2143 delete-old-files: .PHONY
2144         @echo ">>> Removing old files (only deletes safe to delete libs)"
2145 # Ask for every old file if the user really wants to remove it.
2146 # It's annoying, but better safe than sorry.
2147 # NB: We cannot pass the list of OLD_FILES as a parameter because the
2148 # argument list will get too long. Using .for/.endfor make "loops" will make
2149 # the Makefile parser segfault.
2150         @exec 3<&0; \
2151         cd ${.CURDIR}; \
2152         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2153             -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
2154         while read file; do \
2155                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
2156                         chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
2157                         rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
2158                 fi; \
2159                 for ext in debug symbols; do \
2160                   if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
2161                       "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
2162                           rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
2163                               <&3; \
2164                   fi; \
2165                 done; \
2166         done
2167 # Remove catpages without corresponding manpages.
2168         @exec 3<&0; \
2169         find ${DESTDIR}/usr/share/man/cat* ! -type d | \
2170         sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
2171         while read catpage; do \
2172                 read manpage; \
2173                 if [ ! -e "$${manpage}" ]; then \
2174                         rm ${RM_I} $${catpage} <&3; \
2175                 fi; \
2176         done
2177         @echo ">>> Old files removed"
2178
2179 check-old-files: .PHONY
2180         @echo ">>> Checking for old files"
2181         @cd ${.CURDIR}; \
2182         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2183             -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \
2184         while read file; do \
2185                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
2186                         echo "${DESTDIR}/$${file}"; \
2187                 fi; \
2188                 for ext in debug symbols; do \
2189                   if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
2190                           echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
2191                   fi; \
2192                 done; \
2193         done
2194 # Check for catpages without corresponding manpages.
2195         @find ${DESTDIR}/usr/share/man/cat* ! -type d | \
2196         sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
2197         while read catpage; do \
2198                 read manpage; \
2199                 if [ ! -e "$${manpage}" ]; then \
2200                         echo $${catpage}; \
2201                 fi; \
2202         done
2203
2204 delete-old-libs: .PHONY
2205         @echo ">>> Removing old libraries"
2206         @echo "${OLD_LIBS_MESSAGE}" | fmt
2207         @exec 3<&0; \
2208         cd ${.CURDIR}; \
2209         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2210             -V OLD_LIBS | xargs -n1 | \
2211         while read file; do \
2212                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
2213                         chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
2214                         rm ${RM_I} "${DESTDIR}/$${file}" <&3; \
2215                 fi; \
2216                 for ext in debug symbols; do \
2217                   if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \
2218                       "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
2219                           rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \
2220                               <&3; \
2221                   fi; \
2222                 done; \
2223         done
2224         @echo ">>> Old libraries removed"
2225
2226 check-old-libs: .PHONY
2227         @echo ">>> Checking for old libraries"
2228         @cd ${.CURDIR}; \
2229         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2230             -V OLD_LIBS | xargs -n1 | \
2231         while read file; do \
2232                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
2233                         echo "${DESTDIR}/$${file}"; \
2234                 fi; \
2235                 for ext in debug symbols; do \
2236                   if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \
2237                           echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \
2238                   fi; \
2239                 done; \
2240         done
2241
2242 delete-old-dirs: .PHONY
2243         @echo ">>> Removing old directories"
2244         @cd ${.CURDIR}; \
2245         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2246             -V OLD_DIRS | xargs -n1 | sort -r | \
2247         while read dir; do \
2248                 if [ -d "${DESTDIR}/$${dir}" ]; then \
2249                         rmdir -v "${DESTDIR}/$${dir}" || true; \
2250                 elif [ -L "${DESTDIR}/$${dir}" ]; then \
2251                         echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
2252                 fi; \
2253         done
2254         @echo ">>> Old directories removed"
2255
2256 check-old-dirs: .PHONY
2257         @echo ">>> Checking for old directories"
2258         @cd ${.CURDIR}; \
2259         ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \
2260             -V OLD_DIRS | xargs -n1 | \
2261         while read dir; do \
2262                 if [ -d "${DESTDIR}/$${dir}" ]; then \
2263                         echo "${DESTDIR}/$${dir}"; \
2264                 elif [ -L "${DESTDIR}/$${dir}" ]; then \
2265                         echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
2266                 fi; \
2267         done
2268
2269 delete-old: delete-old-files delete-old-dirs .PHONY
2270         @echo "To remove old libraries run '${MAKE} delete-old-libs'."
2271
2272 check-old: check-old-files check-old-libs check-old-dirs .PHONY
2273         @echo "To remove old files and directories run '${MAKE} delete-old'."
2274         @echo "To remove old libraries run '${MAKE} delete-old-libs'."
2275
2276 .endif
2277
2278 #
2279 # showconfig - show build configuration.
2280 #
2281 showconfig: .PHONY
2282         @(${MAKE} -n -f ${.CURDIR}/sys/conf/kern.opts.mk -V dummy -dg1; \
2283           ${MAKE} -n -f ${.CURDIR}/share/mk/src.opts.mk -V dummy -dg1) 2>&1 | grep ^MK_ | sort -u
2284
2285 .if !empty(KRNLOBJDIR) && !empty(KERNCONF)
2286 DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/
2287
2288 .if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE)
2289 .if exists(${KERNCONFDIR}/${KERNCONF})
2290 FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \
2291         '${KERNCONFDIR}/${KERNCONF}' ; echo
2292 .endif
2293 .endif
2294
2295 .endif
2296
2297 .if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH})
2298 DTBOUTPUTPATH= ${.CURDIR}
2299 .endif
2300
2301 #
2302 # Build 'standalone' Device Tree Blob
2303 #
2304 builddtb: .PHONY
2305         @PATH=${TMPPATH} MACHINE=${TARGET} \
2306         ${.CURDIR}/sys/tools/fdt/make_dtb.sh ${.CURDIR}/sys \
2307             "${FDT_DTS_FILE}" ${DTBOUTPUTPATH}
2308
2309 ###############
2310
2311 # cleanworld
2312 # In the following, the first 'rm' in a series will usually remove all
2313 # files and directories.  If it does not, then there are probably some
2314 # files with file flags set, so this unsets them and tries the 'rm' a
2315 # second time.  There are situations where this target will be cleaning
2316 # some directories via more than one method, but that duplication is
2317 # needed to correctly handle all the possible situations.  Removing all
2318 # files without file flags set in the first 'rm' instance saves time,
2319 # because 'chflags' will need to operate on fewer files afterwards.
2320 #
2321 # It is expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
2322 # created by bsd.obj.mk, except that we don't want to .include that file
2323 # in this makefile.
2324 #
2325 BW_CANONICALOBJDIR:=${OBJTREE}${.CURDIR}
2326 cleanworld: .PHONY
2327 .if exists(${BW_CANONICALOBJDIR}/)
2328         -rm -rf ${BW_CANONICALOBJDIR}/*
2329         -chflags -R 0 ${BW_CANONICALOBJDIR}
2330         rm -rf ${BW_CANONICALOBJDIR}/*
2331 .endif
2332 .if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
2333         #   To be safe in this case, fall back to a 'make cleandir'
2334         ${_+_}@cd ${.CURDIR}; ${MAKE} cleandir
2335 .endif
2336
2337 .if defined(TARGET) && defined(TARGET_ARCH)
2338
2339 .if ${TARGET} == ${MACHINE} && ${TARGET_ARCH} == ${MACHINE_ARCH}
2340 XDEV_CPUTYPE?=${CPUTYPE}
2341 .else
2342 XDEV_CPUTYPE?=${TARGET_CPUTYPE}
2343 .endif
2344
2345 NOFUN=-DNO_FSCHG MK_HTML=no -DNO_LINT \
2346         MK_MAN=no MK_NLS=no MK_PROFILE=no \
2347         MK_KERBEROS=no MK_RESCUE=no MK_TESTS=no MK_WARNS=no \
2348         TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
2349         CPUTYPE=${XDEV_CPUTYPE}
2350
2351 XDDIR=${TARGET_ARCH}-freebsd
2352 XDTP?=/usr/${XDDIR}
2353 .if ${XDTP:N/*}
2354 .error XDTP variable should be an absolute path
2355 .endif
2356
2357 CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR} \
2358         INSTALL="sh ${.CURDIR}/tools/install.sh"
2359 CDENV= ${CDBENV} \
2360         TOOLS_PREFIX=${XDTP}
2361 CD2CFLAGS=-isystem ${XDDESTDIR}/usr/include -L${XDDESTDIR}/usr/lib \
2362         --sysroot=${XDDESTDIR}/ -B${XDDESTDIR}/usr/libexec \
2363         -B${XDDESTDIR}/usr/bin -B${XDDESTDIR}/usr/lib
2364 CD2ENV=${CDENV} CC="${CC} ${CD2CFLAGS}" CXX="${CXX} ${CD2CFLAGS}" \
2365         CPP="${CPP} ${CD2CFLAGS}" \
2366         MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH}
2367
2368 CDTMP=  ${MAKEOBJDIRPREFIX}/${XDDIR}/${.CURDIR}/tmp
2369 CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${NOFUN}
2370 CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/usr/bin:${PATH} ${MAKE} ${NOFUN}
2371 XDDESTDIR=${DESTDIR}/${XDTP}
2372 .if !defined(OSREL)
2373 OSREL!= uname -r | sed -e 's/[-(].*//'
2374 .endif
2375
2376 .ORDER: xdev-build xdev-install xdev-links
2377 xdev: xdev-build xdev-install .PHONY
2378
2379 .ORDER: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools
2380 xdev-build: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools .PHONY
2381
2382 _xb-worldtmp: .PHONY
2383         mkdir -p ${CDTMP}/usr
2384         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2385             -p ${CDTMP}/usr >/dev/null
2386
2387 _xb-bootstrap-tools: .PHONY
2388 .for _tool in \
2389     ${_clang_tblgen} \
2390     ${_gperf}
2391         ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
2392         cd ${.CURDIR}/${_tool}; \
2393         ${CDMAKE} DIRPRFX=${_tool}/ obj; \
2394         ${CDMAKE} DIRPRFX=${_tool}/ all; \
2395         ${CDMAKE} DIRPRFX=${_tool}/ DESTDIR=${CDTMP} install
2396 .endfor
2397
2398 _xb-build-tools: .PHONY
2399         ${_+_}@cd ${.CURDIR}; \
2400         ${CDBENV} ${MAKE} -f Makefile.inc1 ${NOFUN} build-tools
2401
2402 _xb-cross-tools: .PHONY
2403 .for _tool in \
2404     ${_binutils} \
2405     ${_elftctools} \
2406     usr.bin/ar \
2407     ${_clang_libs} \
2408     ${_clang} \
2409     ${_cc}
2410         ${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,all)"; \
2411         cd ${.CURDIR}/${_tool}; \
2412         ${CDMAKE} DIRPRFX=${_tool}/ obj; \
2413         ${CDMAKE} DIRPRFX=${_tool}/ all
2414 .endfor
2415
2416 _xi-mtree: .PHONY
2417         ${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
2418         mkdir -p ${XDDESTDIR}
2419         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
2420             -p ${XDDESTDIR} >/dev/null
2421         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
2422             -p ${XDDESTDIR}/usr >/dev/null
2423         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
2424             -p ${XDDESTDIR}/usr/include >/dev/null
2425 .if defined(LIBCOMPAT)
2426         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
2427             -p ${XDDESTDIR}/usr >/dev/null
2428 .endif
2429 .if ${MK_TESTS} != "no"
2430         mkdir -p ${XDDESTDIR}${TESTSBASE}
2431         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \
2432             -p ${XDDESTDIR}${TESTSBASE} >/dev/null
2433 .endif
2434
2435 .ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries
2436 xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries .PHONY
2437
2438 _xi-cross-tools: .PHONY
2439         @echo "_xi-cross-tools"
2440 .for _tool in \
2441     ${_binutils} \
2442     ${_elftctools} \
2443     usr.bin/ar \
2444     ${_clang_libs} \
2445     ${_clang} \
2446     ${_cc}
2447         ${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
2448         cd ${.CURDIR}/${_tool}; \
2449         ${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
2450 .endfor
2451
2452 _xi-includes: .PHONY
2453         ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 includes \
2454                 DESTDIR=${XDDESTDIR}
2455
2456 _xi-libraries: .PHONY
2457         ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
2458                 DESTDIR=${XDDESTDIR}
2459
2460 xdev-links: .PHONY
2461         ${_+_}cd ${XDDESTDIR}/usr/bin; \
2462         mkdir -p ../../../../usr/bin; \
2463                 for i in *; do \
2464                         ln -sf ../../${XDTP}/usr/bin/$$i \
2465                             ../../../../usr/bin/${XDDIR}-$$i; \
2466                         ln -sf ../../${XDTP}/usr/bin/$$i \
2467                             ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \
2468                 done
2469 .else
2470 xdev xdev-build xdev-install xdev-links: .PHONY
2471         @echo "*** Error: Both TARGET and TARGET_ARCH must be defined for \"${.TARGET}\" target"
2472 .endif