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