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