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