initrd: cd to '/' before umounting '/var'
[dragonfly.git] / Makefile.inc1
1 #
2 # $FreeBSD: src/Makefile.inc1,v 1.141.2.62 2003/04/06 19:54:00 dwmalone Exp $
3 #
4 # This file defines the user-driven targets.
5 #
6 # Standard targets are documented in the makefiles in /usr/share/mk and include:
7 #       obj depend all install clean cleandepend cleanobj
8 #
9 # Build-time options are documented in make.conf(5).
10 #
11
12 # Put initial settings here.
13 SUBDIR=
14
15 # /libexec/ld-elf.so.2 needs to be installed first
16 # Otherwise, install(1) beeing a dynamically linked binary will fail
17 # during the first upgrade from a static to a dynamic world
18 .if exists(${.CURDIR}/libexec)
19 SUBDIR+= libexec
20 .endif
21
22 # We need to do include and lib early.
23 #
24 .if exists(${.CURDIR}/include)
25 SUBDIR+= include
26 .endif
27 .if exists(${.CURDIR}/lib)
28 SUBDIR+= lib
29 .endif
30 # This exists simply to ensure that the obj dir hierarchy is
31 # intact for nrelease, allowing the nrelease Makefile's to
32 # reference ${.OBJDIR}.
33 #
34 .if exists(${.CURDIR}/nrelease)
35 SUBDIR+= nrelease
36 .endif
37
38 .if exists(${.CURDIR}/bin)
39 SUBDIR+= bin
40 .endif
41 .if exists(${.CURDIR}/games) && !defined(NO_GAMES)
42 SUBDIR+= games
43 .endif
44 .if exists(${.CURDIR}/gnu)
45 SUBDIR+= gnu
46 .endif
47 .if exists(${.CURDIR}/sbin)
48 SUBDIR+= sbin
49 .endif
50 .if exists(${.CURDIR}/share) && !defined(NO_SHARE)
51 SUBDIR+= share
52 .endif
53 .if exists(${.CURDIR}/sys)
54 SUBDIR+= sys
55 .endif
56 .if exists(${.CURDIR}/usr.bin)
57 SUBDIR+= usr.bin
58 .endif
59 .if exists(${.CURDIR}/usr.sbin)
60 SUBDIR+= usr.sbin
61 .endif
62
63 .if exists(${.CURDIR}/etc)
64 SUBDIR+= etc
65 .endif
66
67 # These are last, since it is nice to at least get the base system
68 # rebuilt before you do them.
69 .if defined(LOCAL_DIRS)
70 .for _DIR in ${LOCAL_DIRS}
71 .if exists(${.CURDIR}/${_DIR}) & exists(${.CURDIR}/${_DIR}/Makefile)
72 SUBDIR+= ${_DIR}
73 .endif
74 .endfor
75 .endif
76
77 .if defined(SUBDIR_OVERRIDE)
78 SUBDIR=         ${SUBDIR_OVERRIDE}
79 .endif
80
81 .if defined(NOCLEANDIR)
82 CLEANDIR=       clean cleandepend
83 .else
84 CLEANDIR=       cleandir
85 .endif
86
87 .if defined(NO_CLEAN)
88 NOCLEAN=        # defined
89 .endif
90
91 # Object directory base in primary make.  Note that when we rerun make
92 # from inside this file we change MAKEOBJDIRPREFIX to the appropriate
93 # subdirectory because the rest of the build system needs it that way.
94 # The original object directory base is saved in OBJTREE.
95 #
96 MAKEOBJDIRPREFIX?=      /usr/obj
97 OBJTREE?=               ${MAKEOBJDIRPREFIX}
98
99 # Used for stage installs and pathing
100 #
101 DESTDIRBASE:=           ${OBJTREE}${.CURDIR}
102
103 # Remove DESTDIR from MAKEFLAGS.  It is present in the environment
104 # anyhow, and we need to be able to override it for stage installs
105 .MAKEFLAGS:=    ${.MAKEFLAGS:NDESTDIR=*}
106
107 # This section sets the tools used to build the world/kernel
108 WORLD_CCVER?=           gcc80
109 WORLD_LDVER?=           ld.gold
110 WORLD_BINUTILSVER?=     binutils227
111
112 # Set the backup parameters if they are not already defined
113 #
114 WORLD_BACKUP?=          /var/backups/world_backup
115 AUTO_BACKUP?=           ${OBJTREE}/world_backup/${DESTDIR}
116
117 TARGET_ARCH?=   ${MACHINE_ARCH}
118 .if ${TARGET_ARCH} == ${MACHINE_ARCH}
119 TARGET?=        ${MACHINE}
120 .else
121 TARGET?=        ${TARGET_ARCH}
122 .endif
123 .if make(buildworld)
124 BUILD_ARCH!=    sysctl -n hw.machine_arch
125
126 # temporary until everybody has converted to x86_64
127 .if ${BUILD_ARCH} == "amd64"
128 BUILD_ARCH=     x86_64
129 .endif
130
131 .if ${MACHINE_ARCH} != ${BUILD_ARCH}
132 .error To cross-build, set TARGET_ARCH.
133 .endif
134 .endif
135
136 # XXX this is ugly and we need to come up with a nicer solution
137 .if !defined(TARGET_PLATFORM)
138 .if ${TARGET_ARCH} == "x86_64"
139 TARGET_PLATFORM= pc64
140 .else
141 .error Unknown target architecture.
142 .endif
143 .endif
144
145 THREAD_LIB?=    thread_xu
146 .if ${THREAD_LIB} == "c_r"
147 .if defined(NO_LIBC_R)
148 .error libc_r is chosen as the default thread library, but NO_LIBC_R is defined
149 .endif
150 .endif
151
152 # BTOOLS        (Natively built) All non-cross-development tools that the
153 #               main build needs.  This includes things like 'mkdir' and 'rm'.
154 #               We will not use the native system's exec path once we start
155 #               on WORLD.  (bootstrap-tools and build-tools or BTOOLS)
156 #
157 # CTOOLS        (Natively built) Cross development tools which are specific
158 #               to the target architecture.
159 #
160 # WORLD         (Cross built) Our ultimate buildworld, using only BTOOLS and
161 #               CTOOLS.
162 #
163 # MACHINE_PLATFORM      Platform Architecture we are building on
164 # MACHINE               Machine Architecture (usually the same as MACHINE_ARCH)
165 # MACHINE_ARCH          CPU Architecture we are building on
166 #
167 # TARGET_PLATFORM       Platform Architecture we are building for
168 # TARGET                Machine Architecture we are building for
169 # TARGET_ARCH           CPU Architecture we are building for
170 #
171 BTOOLSDEST=     ${DESTDIRBASE}/btools_${MACHINE_ARCH}
172 CTOOLSDEST=     ${DESTDIRBASE}/ctools_${MACHINE_ARCH}_${TARGET_ARCH}
173 WORLDDEST=      ${DESTDIRBASE}/world_${TARGET_ARCH}
174
175 # The bootstrap-tools path is used by the bootstrap-tools, build-tools, and
176 # cross-tools stages to augment the existing command path to access newer
177 # versions of certain utilities such as 'patch' that the cross-tools stage
178 # might expect.
179 #
180 BTOOLSPATH= ${BTOOLSDEST}/usr/sbin:${BTOOLSDEST}/usr/bin:${BTOOLSDEST}/sbin:${BTOOLSDEST}/bin
181
182 # The cross-tools path containing the cross-tools to cross build the
183 # ultimate world.
184 #
185 CTOOLSPATH= ${CTOOLSDEST}/usr/sbin:${CTOOLSDEST}/usr/bin:${CTOOLSDEST}/sbin:${CTOOLSDEST}/bin
186
187 # The strict temporary command path contains all binaries required
188 # by the buildworld system after the cross-tools stage.
189 #
190 # NOTE: Append '/usr/local/bin:/usr/pkg/bin' to support external compilers.
191 #       See compilers.conf(5) man page for more info.
192 #
193 STRICTTMPPATH= ${CTOOLSPATH}:${BTOOLSPATH}:/usr/local/bin:/usr/pkg/bin
194
195 TMPDIR?=        /tmp
196 TMPPID!=        echo $$$$
197
198 #
199 # Building a world goes through the following stages
200 #
201 # 1. bootstrap-tool stage [BMAKE]
202 #       This stage is responsible for creating programs that
203 #       are needed for backward compatibility reasons. They
204 #       are not built as cross-tools.
205 # 2. build-tool stage [TMAKE]
206 #       This stage is responsible for creating the object
207 #       tree and building any tools that are needed during
208 #       the build process.
209 # 3. cross-tool stage [XMAKE]
210 #       This stage is responsible for creating any tools that
211 #       are needed for cross-builds. A cross-compiler is one
212 #       of them.
213 # 4. world stage [WMAKE]
214 #       This stage actually builds the world.
215 # 5. install stage (optional) [IMAKE]
216 #       This stage installs a previously built world.
217 #
218 # In all cases we must carefully adjust the environment so the proper
219 # tools and header files are used.
220 #
221 # NOTE: The M4 environment variable is used by the [f]lex binary to
222 #       override the location of the 'm4' binary.  The override is
223 #       needed for certain buildworld version transitions, specifically
224 #       past a certain point in 3.3 because the older /usr/bin/m4 will
225 #       generate output that will blow up the newer [f]lex/yacc/bison
226 #       utilities.
227 #
228
229 # bootstrap-tool stage
230 #
231 BMAKEENV=       MAKEOBJDIRPREFIX=${BTOOLSDEST} \
232                 OBJTREE=${OBJTREE} \
233                 DESTDIR=${BTOOLSDEST} \
234                 LC_ALL=C \
235                 PATH=${BTOOLSPATH}:${PATH} \
236                 M4=${BTOOLSDEST}/usr/bin/m4 \
237                 INSTALL="sh ${.CURDIR}/tools/install.sh"
238
239 BMAKE=          ${BMAKEENV} make -f Makefile.inc1 -DBOOTSTRAPPING \
240                 -DNOMAN -DNOPIC -DNOPROFILE -DNOSHARED \
241                 -DNO_WERROR -DNO_NLS -DSYSBUILD
242
243 # build-tool stage
244 #
245 TMAKEENV=       MAKEOBJDIRPREFIX=${BTOOLSDEST} \
246                 OBJTREE=${OBJTREE} \
247                 DESTDIR= \
248                 LC_ALL=C \
249                 PATH=${BTOOLSPATH}:${PATH} \
250                 M4=${BTOOLSDEST}/usr/bin/m4 \
251                 INSTALL="sh ${.CURDIR}/tools/install.sh"
252
253 TMAKE=          ${TMAKEENV} make -f Makefile.inc1 -DBOOTSTRAPPING \
254                 -DNOSHARED -DSYSBUILD
255
256 # cross-tool stage
257 #
258 # note: TOOLS_PREFIX points to the obj root holding the cross
259 #       compiler binaries, while USRDATA_PREFIX points to the obj root
260 #       holding the target environment (and also determines where cross-built
261 #       libraries, crt*.o, and include files are installed).
262 #
263 XMAKEENV=       MAKEOBJDIRPREFIX=${CTOOLSDEST} \
264                 OBJTREE=${OBJTREE} \
265                 DESTDIR=${CTOOLSDEST} \
266                 LC_ALL=C \
267                 _SHLIBDIRPREFIX=${CTOOLSDEST} \
268                 INSTALL="sh ${.CURDIR}/tools/install.sh" \
269                 TOOLS_PREFIX=${CTOOLSDEST} \
270                 USRDATA_PREFIX=${WORLDDEST} \
271                 SELECT_LINKER=${WORLD_LDVER} \
272                 M4=${BTOOLSDEST}/usr/bin/m4 \
273                 PATH=${BTOOLSPATH}:${PATH}
274
275 XMAKE=          ${XMAKEENV} make -f Makefile.inc1 -DNO_GDB \
276                 -DBOOTSTRAPPING -DNOMAN -DNOSHARED -DSYSBUILD
277
278 # world stage, note the strict path and note that TOOLS_PREFIX is left
279 # unset and USRDATA_PREFIX (which defaults to TOOLS_PREFIX) is set to empty,
280 # which is primarily for the compiler so it targets / (e.g. /usr/<blah>)
281 # for both binary and library paths, even though it is being compiled to
282 # WORLDDEST.  None of the programs in the world stage are ever actually
283 # executed during the buildworld/installworld.
284 #
285 CROSSENV=       MAKEOBJDIRPREFIX=${WORLDDEST} \
286                 OBJTREE=${OBJTREE} \
287                 MACHINE_ARCH=${TARGET_ARCH} \
288                 MACHINE=${TARGET} \
289                 MACHINE_PLATFORM=${TARGET_PLATFORM} \
290                 LC_ALL=C \
291                 OBJFORMAT_PATH=${CTOOLSDEST} \
292                 HOST_CCVER=${HOST_CCVER} \
293                 CCVER=${WORLD_CCVER} \
294                 LDVER=${WORLD_LDVER} \
295                 BINUTILSVER=${WORLD_BINUTILSVER}
296
297 WMAKEENV=       ${CROSSENV} \
298                 WORLDBUILD=1 \
299                 DESTDIR=${WORLDDEST} \
300                 _SHLIBDIRPREFIX=${WORLDDEST} \
301                 INSTALL="sh ${.CURDIR}/tools/install.sh" \
302                 M4=${BTOOLSDEST}/usr/bin/m4 \
303                 PATH=${STRICTTMPPATH}
304
305 WMAKE=          ${WMAKEENV} make -f Makefile.inc1 -DSYSBUILD
306
307 # install stage
308 #
309 IMAKEENV=       ${CROSSENV} \
310                 PATH=${STRICTTMPPATH}
311 IMAKE=          ${IMAKEENV} make -f Makefile.inc1 -DSYSBUILD
312
313 # kernel stage
314 #
315 KMAKEENV=       ${WMAKEENV}
316
317 # buildworld
318 #
319 # Attempt to rebuild the entire system, with reasonable chance of
320 # success, regardless of how old your existing system is.
321 #
322 _worldtmp: _cleantmp _mtreetmp
323 .ORDER: _cleantmp _mtreetmp
324
325 _cleantmp:
326 .if !defined(NOCLEAN)
327         rm -rf ${BTOOLSDEST} ${CTOOLSDEST} ${WORLDDEST}
328 .else
329         # XXX - These two can depend on any header file.
330         rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
331         rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
332 .endif
333
334 _mtreetmp:
335         @echo
336         @echo "--------------------------------------------------------------"
337         @echo ">>> Rebuilding the temporary build tree"
338         @echo "--------------------------------------------------------------"
339         mkdir -p ${DESTDIRBASE} ${BTOOLSDEST} ${CTOOLSDEST} ${WORLDDEST}
340 .for _dir in ${WORLDDEST} ${BTOOLSDEST} ${CTOOLSDEST}
341         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist        \
342                 -p ${_dir}/  > /dev/null
343         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist         \
344                 -p ${_dir}/usr > /dev/null
345 .endfor
346         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist     \
347                 -p ${WORLDDEST}/usr/include > /dev/null
348         ${LN} -sf ${.CURDIR}/sys ${WORLDDEST}
349
350 _bwinit:
351         @echo "--------------------------------------------------------------"
352         @echo ">>> starting buildworld target"
353         @echo "--------------------------------------------------------------"
354 _bootstrap-tools:
355         @echo
356         @echo "--------------------------------------------------------------"
357         @echo ">>> stage 1: bootstrap tools"
358         @echo "--------------------------------------------------------------"
359         cd ${.CURDIR}; ${BMAKE} bootstrap-tools
360 _cleanobj:
361         @echo
362         @echo "--------------------------------------------------------------"
363         @echo ">>> stage 2a: cleaning up the object tree"
364         @echo "--------------------------------------------------------------"
365         cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
366 _obj:
367         @echo
368         @echo "--------------------------------------------------------------"
369         @echo ">>> stage 2b: rebuilding the object tree"
370         @echo "--------------------------------------------------------------"
371         cd ${.CURDIR}; ${WMAKE} par-obj
372 _build-tools:
373         @echo
374         @echo "--------------------------------------------------------------"
375         @echo ">>> stage 2c: build tools"
376         @echo "--------------------------------------------------------------"
377         cd ${.CURDIR}; ${TMAKE} build-tools
378 _cross-tools:
379         @echo
380         @echo "--------------------------------------------------------------"
381         @echo ">>> stage 3: cross tools"
382         @echo "--------------------------------------------------------------"
383         cd ${.CURDIR}; ${XMAKE} cross-tools
384 _includes:
385         @echo
386         @echo "--------------------------------------------------------------"
387         @echo ">>> stage 4a: populating ${WORLDDEST}/usr/include"
388         @echo "--------------------------------------------------------------"
389         cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
390 _libraries:
391         @echo
392         @echo "--------------------------------------------------------------"
393         @echo ">>> stage 4b: building libraries"
394         @echo "--------------------------------------------------------------"
395         cd ${.CURDIR}; ${WMAKE} -DNOHTML -DNOMAN -DNOFSCHG libraries
396 _depend:
397         @echo
398         @echo "--------------------------------------------------------------"
399         @echo ">>> stage 4c: make dependencies"
400         @echo "--------------------------------------------------------------"
401         cd ${.CURDIR}; ${WMAKE} par-depend
402 everything:
403         @echo
404         @echo "--------------------------------------------------------------"
405         @echo ">>> stage 4d: building everything"
406         @echo "--------------------------------------------------------------"
407         cd ${.CURDIR}; ${WMAKE} all
408 _initrd:
409         @echo
410         @echo "--------------------------------------------------------------"
411         @echo ">>> stage 5: building rescue and initrd"
412         @echo "--------------------------------------------------------------"
413         cd ${.CURDIR}/initrd; ${WMAKEENV} make all
414 _bwdone:
415         @echo "--------------------------------------------------------------"
416         @echo ">>> buildworld target complete"
417         @echo "--------------------------------------------------------------"
418 _qwinit:
419         @echo "--------------------------------------------------------------"
420         @echo ">>> starting quickworld target"
421         @echo "--------------------------------------------------------------"
422 _qwdone:
423         @echo "--------------------------------------------------------------"
424         @echo ">>> quickworld target complete"
425         @echo "--------------------------------------------------------------"
426 _iwinit:
427         @echo "--------------------------------------------------------------"
428         @echo ">>> starting installworld target"
429         @echo "--------------------------------------------------------------"
430
431 # note: buildworld no longer depends on _cleanobj because we rm -rf the
432 # entire object tree and built the bootstrap tools in a different location.
433 #
434 # buildworld    - build everything from scratch
435 # quickworld    - skip the bootstrap, build, and cross-build steps
436 # realquickworld - skip the bootstrap, build, crossbuild, and depend step.
437 #
438 # note: we include _obj in realquickworld to prevent accidental creation
439 # of files in /usr/src.
440
441 WMAKE_TGTS=
442 .if !defined(SUBDIR_OVERRIDE)
443 WMAKE_TGTS+=    _worldtmp _bootstrap-tools
444 .endif
445 WMAKE_TGTS+=    _obj _build-tools
446 .if !defined(SUBDIR_OVERRIDE)
447 WMAKE_TGTS+=    _cross-tools
448 .endif
449 WMAKE_TGTS+=    _includes _libraries _depend everything _initrd
450
451 .if defined(WMAKE_TGTS_OVERRIDE)
452 SUBDIR=
453 WMAKE_TGTS=     ${WMAKE_TGTS_OVERRIDE}
454 .endif
455
456 QMAKE_TGTS=     _mtreetmp _obj _includes _libraries _depend everything _initrd
457
458 buildworld: _bwinit ${WMAKE_TGTS} _bwdone
459
460 quickworld: _qwinit ${QMAKE_TGTS} _qwdone
461
462 realquickworld: _qwinit _mtreetmp _obj _includes _libraries everything _qwdone
463
464 crossworld: _worldtmp _bootstrap-tools _obj _build-tools _cross-tools
465
466 .ORDER: _bwinit ${WMAKE_TGTS} _bwdone
467 .ORDER: _obj _includes
468 .ORDER: _qwinit _mtreetmp _obj
469 .ORDER: installcheck backupworld-auto
470 .ORDER: everything _qwdone
471
472
473 # installcheck
474 #
475 # Checks to be sure system is ready for installworld
476 #
477 installcheck: _iwinit
478 .for _user in _pflogd
479         @pw usershow ${_user} >/dev/null || { \
480             echo "You need to run 'make preupgrade' first."; \
481             /usr/bin/false; \
482         }
483 .endfor
484 .for _group in _pflogd authpf
485         @pw groupshow ${_group} >/dev/null || { \
486             echo "You need to run 'make preupgrade' first."; \
487             /usr/bin/false; \
488         }
489 .endfor
490 .if !defined(OVERRIDE_CHECKS)
491 .if !defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/"
492         @case `uname -r` in \
493             1.2*|1.3-*|1.3.*|1.4.*|1.5.0-*|1.5.1-*|1.5.2-*|1.5.3-*) \
494                 echo "You must upgrade your kernel to at least 1.5.4" \
495                      "and reboot before you can safely installworld," \
496                      "due to libc/system call ABI changes."; \
497                 /usr/bin/false; \
498         esac
499         @case `uname -r` in \
500             1.*|2.*|3.0*|3.1*|3.2*|3.3*|3.4*|3.5*|3.6*) \
501                 echo "The system is too old for a normal installworld," \
502                      "you need to use 'installworld-force'."; \
503                 /usr/bin/false; \
504         esac
505 .endif
506 .endif
507
508 # installworld
509 #
510 # Backs up the current world if ${AUTO_BACKUP} is writable.
511 # Installs everything compiled by a 'buildworld'.
512 #
513 installworld: installcheck
514         -@mkdir -p ${AUTO_BACKUP} > /dev/null 2>&1
515         @cd ${.CURDIR}; \
516             (touch ${AUTO_BACKUP}/.updating > /dev/null 2>&1 && \
517              ${IMAKE} backupworld-auto) || \
518             echo "Cannot write to ${AUTO_BACKUP} - world not backed up"
519
520         cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}
521         ${INSTALL} -o root -g wheel -m 644 ${.CURDIR}/Makefile_upgrade.inc \
522             ${DESTDIR}/etc/upgrade/
523         cd ${.CURDIR}; ${IMAKE} -DWORLDINSTALL initrd
524
525         sync
526         @echo "--------------------------------------------------------------"
527         @echo ">>> installworld target complete"
528         @echo "--------------------------------------------------------------"
529
530 installworld-force:
531         @echo "Doing a forced installworld.  This will install to a temporary directory,"
532         @echo "then copy the main binaries and libraries with a static cpdup to ${DESTDIR}/"
533         @echo "and finally will issue a normal installworld."
534         @echo
535         @echo "Starting in 5 seconds.  ^C to abort."
536         @echo
537         sleep 1
538         rm -rf /usr/obj/temp > /dev/null 2>&1 || chflags -R noschg /usr/obj/temp
539         rm -rf /usr/obj/temp
540         mkdir -p /usr/obj/temp/cpdup/bin
541         (cd ${.CURDIR}/bin/cpdup; \
542                 make clean && \
543                 make obj && \
544                 make clean && \
545                 make CFLAGS=-static all install DESTDIR=/usr/obj/temp/cpdup NOMAN=TRUE)
546         @echo "XXXXXXXXX Installing to temporary XXXXXXXXX"
547         @sleep 1
548         (cd ${.CURDIR}; ${MAKE} installworld DESTDIR=/usr/obj/temp > /dev/null 2>&1)
549         @echo "XXXXXXXXX Blasting binaries and libraries XXXXXXXXX"
550         @sleep 1
551         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/bin /bin
552         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/sbin /sbin
553         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/lib /lib
554         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/bin /usr/bin
555         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/sbin /usr/sbin
556         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/lib /usr/lib
557         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/libexec /libexec
558         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/libexec /usr/libexec
559         @echo "XXXXXXXXX Doing final installworld XXXXXXXX"
560         sleep 5
561         (cd ${.CURDIR}; ${MAKE} installworld OVERRIDE_CHECKS=TRUE)
562         (cd ${.CURDIR}; ${MAKE} upgrade OVERRIDE_CHECKS=TRUE)
563         (cd ${.CURDIR}; ${MAKE} initrd)
564
565 # reinstall
566 #
567 # If you have a build server, you can NFS mount the source and obj directories
568 # and do a 'make reinstall' on the *client* to install new binaries from the
569 # most recent server build.
570 #
571 reinstall:
572         @echo "--------------------------------------------------------------"
573         @echo ">>> Making hierarchy"
574         @echo "--------------------------------------------------------------"
575         cd ${.CURDIR}; make -f Makefile.inc1 hierarchy
576         @echo
577         @echo "--------------------------------------------------------------"
578         @echo ">>> Installing everything"
579         @echo "--------------------------------------------------------------"
580         cd ${.CURDIR}; make -f Makefile.inc1 install
581
582 # initrd
583 #
584 # Install the rescue tools and the initrd image built by 'buildworld'.
585 #
586 initrd: .PHONY
587         (cd ${.CURDIR}/initrd; ${IMAKEENV} make install)
588
589
590 # buildkernel, nativekernel, quickkernel, realquickkernel, and installkernel
591 #
592 # Which kernels to build and/or install is specified by setting
593 # KERNCONF. If not defined an X86_64_GENERIC kernel is built/installed.
594 # Only the existing (depending TARGET) config files are used
595 # for building kernels and only the first of these is designated
596 # as the one being installed.
597 #
598 # You can specify INSTALLSTRIPPED=1 if you wish the installed
599 # kernel and modules to be stripped of its debug info (required
600 # symbols are left intact).  You can specify INSTALLSTRIPPEDMODULES
601 # if you only want to strip the modules of their debug info.  These
602 # only apply if you have DEBUG=-g in your kernel config or make line.
603 #
604 # Note that we have to use TARGET instead of TARGET_ARCH when
605 # we're in kernel-land. Since only TARGET_ARCH is (expected) to
606 # be set to cross-build, we have to make sure TARGET is set
607 # properly.
608
609 .if !defined(KERNCONF) && defined(KERNEL)
610 KERNCONF=       ${KERNEL}
611 KERNWARN=       yes
612 .else
613 # XXX makeshift fix to build the right kernel for the (target) architecture
614 # We should configure this in the platform files somehow
615 .if ${TARGET_ARCH} == "x86_64"
616 KERNCONF?=      X86_64_GENERIC
617 .endif
618 .endif
619 INSTKERNNAME?=  kernel
620
621 KRNLSRCDIR=     ${.CURDIR}/sys
622 KRNLCONFDIR=    ${KRNLSRCDIR}/config
623 KRNLOBJDIR=     ${OBJTREE}${KRNLSRCDIR}
624 KERNCONFDIR?=   ${KRNLCONFDIR}
625
626 BUILDKERNELS=
627 INSTALLKERNEL=
628 .for _kernel in ${KERNCONF}
629 .if exists(${KERNCONFDIR}/${_kernel})
630 BUILDKERNELS+=  ${_kernel}
631 .if empty(INSTALLKERNEL)
632 INSTALLKERNEL= ${_kernel}
633 .endif
634 .endif
635 .endfor
636
637 # kernel version numbers survive rm -rf
638 #
639 .for _kernel in ${BUILDKERNELS}
640 .if exists(${KRNLOBJDIR}/${_kernel}/version)
641 KERNEL_VERSION_${_kernel} != cat ${KRNLOBJDIR}/${_kernel}/version
642 .endif
643 .endfor
644
645 # buildkernel
646 #
647 # Builds all kernels defined by BUILDKERNELS.
648 #
649 bk_tools:
650         @if [ ! -f ${WORLDDEST}/.libraries_done ]; then \
651             echo "You must buildworld before buildkernel.  If you wish"; \
652             echo "to build a kernel using native tools, config it manually"; \
653             echo "or use the nativekernel target if you are in a rush"; \
654             /usr/bin/false; \
655         fi
656
657 maybe_bk_tools:
658 .for _kernel in ${BUILDKERNELS}
659         @if [ ! -f ${KRNLOBJDIR}/${_kernel}/.nativekernel_run ]; then \
660             if [ ! -f ${WORLDDEST}/.libraries_done ]; then \
661                 echo "The kernel was build using buildworld tools which no" ; \
662                 echo "longer appear to exist, (real)quickkernel failed!" ; \
663                 /usr/bin/false; \
664             fi; \
665         fi
666 .endfor
667
668 bk_build_list:
669 .if empty(BUILDKERNELS)
670         @echo ">>> ERROR: Missing kernel configuration file(s)."
671         @echo ">>> ${KERNCONF} not found in ${KERNCONFDIR}."
672         @false
673 .endif
674
675 bk_kernwarn:
676 .if defined(KERNWARN)
677         @echo "--------------------------------------------------------------"
678         @echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
679         @echo "--------------------------------------------------------------"
680         @sleep 3
681 .endif
682         @echo
683
684 # The buildkernel target rebuilds the specified kernels from scratch
685 # using the crossbuild tools generated by the last buildworld.  It is
686 # the safest (but also the most time consuming) way to build a new kernel.
687 #
688 buildkernel:    bk_tools bk_build_list bk_kernwarn
689 .for _kernel in ${BUILDKERNELS}
690         @echo "--------------------------------------------------------------"
691         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
692         @echo "--------------------------------------------------------------"
693         @echo "===> ${_kernel}"
694 .if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN)
695         rm -rf ${KRNLOBJDIR}/${_kernel}
696 .else
697         @if [ -f ${KRNLOBJDIR}/${_kernel}/.nativekernel_run ]; then \
698                 echo "YOU ARE REBUILDING WITH BUILDKERNEL, REMOVING OLD NATIVEKERNEL BUILD"; \
699                 rm -rf ${KRNLOBJDIR}/${_kernel}; fi
700 .endif
701         mkdir -p ${KRNLOBJDIR}
702 .if !defined(NO_KERNELCONFIG)
703         cd ${KRNLCONFDIR}; \
704                 PATH=${STRICTTMPPATH} \
705                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
706                         ${KERNCONFDIR}/${_kernel}
707 .endif
708 .if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN) && defined(KERNEL_VERSION_${_kernel})
709         echo ${KERNEL_VERSION_${_kernel}} > ${KRNLOBJDIR}/${_kernel}/version
710 .endif
711         touch ${KRNLOBJDIR}/${_kernel}/.buildkernel_run
712 .if !defined(NO_KERNELDEPEND)
713         cd ${KRNLOBJDIR}/${_kernel}; \
714             ${KMAKEENV} make KERNEL=${INSTKERNNAME} depend
715 .endif
716         cd ${KRNLOBJDIR}/${_kernel}; \
717             ${KMAKEENV} make KERNEL=${INSTKERNNAME} all
718         @echo "--------------------------------------------------------------"
719         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
720         @echo "--------------------------------------------------------------"
721 .endfor
722
723 # The nativekernel target rebuilds the specified kernels from scratch
724 # using the system's standard compiler rather than using the crossbuild
725 # tools generated by the last buildworld.  This is fairly safe if your
726 # system is reasonable up-to-date.
727 #
728 nativekernel:   bk_build_list bk_kernwarn
729 .for _kernel in ${BUILDKERNELS}
730         @echo "--------------------------------------------------------------"
731         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
732         @echo "--------------------------------------------------------------"
733         @echo "===> ${_kernel}"
734 .if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN)
735         rm -rf ${KRNLOBJDIR}/${_kernel}
736 .else
737         @if [ -f ${KRNLOBJDIR}/${_kernel}/.buildkernel_run ]; then \
738                 echo "YOU ARE REBUILDING WITH NATIVEKERNEL, REMOVING OLD BUILDKERNEL BUILD"; \
739                 rm -rf ${KRNLOBJDIR}/${_kernel}; fi
740 .endif
741         mkdir -p ${KRNLOBJDIR}
742 .if !defined(NO_KERNELCONFIG)
743         cd ${KRNLCONFDIR}; \
744                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
745                         ${KERNCONFDIR}/${_kernel}
746 .endif
747 .if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN) && defined(KERNEL_VERSION_${_kernel})
748         echo ${KERNEL_VERSION_${_kernel}} > ${KRNLOBJDIR}/${_kernel}/version
749 .endif
750         touch ${KRNLOBJDIR}/${_kernel}/.nativekernel_run
751 .if !defined(NO_KERNELDEPEND)
752         cd ${KRNLOBJDIR}/${_kernel}; \
753             make KERNEL=${INSTKERNNAME} depend
754 .endif
755         cd ${KRNLOBJDIR}/${_kernel}; \
756             make KERNEL=${INSTKERNNAME} all
757         @echo "--------------------------------------------------------------"
758         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
759         @echo "--------------------------------------------------------------"
760 .endfor
761
762 # The (real)quickkernel target rebuilds the specified kernels as quickly
763 # as possible.  It will use the native tools or the buildworld cross tools
764 # based on whether the kernel was originally generated via buildkernel or
765 # nativekernel.  Config is rerun but the object hierarchy is not rebuilt.
766 # realquickkernel skips the depend step (analogous to realquickworld).
767 #
768 quickkernel realquickkernel:    maybe_bk_tools bk_build_list bk_kernwarn
769 .for _kernel in ${BUILDKERNELS}
770         @echo "--------------------------------------------------------------"
771         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
772         @echo "--------------------------------------------------------------"
773         @echo "===> ${_kernel}"
774 .if exists(${KRNLOBJDIR}/${_kernel}/.buildkernel_run)
775 .if !defined(NO_KERNELCONFIG)
776         cd ${KRNLCONFDIR}; \
777                 PATH=${STRICTTMPPATH} \
778                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
779                         ${KERNCONFDIR}/${_kernel}
780 .endif
781 .if !defined(NO_KERNELDEPEND) && !make(realquickkernel)
782         cd ${KRNLOBJDIR}/${_kernel}; \
783             ${KMAKEENV} make KERNEL=${INSTKERNNAME} depend
784 .endif
785         cd ${KRNLOBJDIR}/${_kernel}; \
786             ${KMAKEENV} make KERNEL=${INSTKERNNAME} all
787 .else
788 .if !defined(NO_KERNELCONFIG)
789         cd ${KRNLCONFDIR}; \
790             config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
791                 ${KERNCONFDIR}/${_kernel}
792 .endif
793 .if !defined(NO_KERNELDEPEND) && !make(realquickkernel)
794         cd ${KRNLOBJDIR}/${_kernel}; \
795             make KERNEL=${INSTKERNNAME} depend
796 .endif
797         cd ${KRNLOBJDIR}/${_kernel}; \
798             make KERNEL=${INSTKERNNAME} all
799 .endif
800         @echo "--------------------------------------------------------------"
801         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
802         @echo "--------------------------------------------------------------"
803 .endfor
804
805
806 # installkernel
807 #
808 # Install the kernel defined by INSTALLKERNEL
809 #
810 installkernel reinstallkernel:
811         @echo "--------------------------------------------------------------"
812         @echo ">>> Kernel install for ${INSTALLKERNEL} started on `LC_ALL=C date`"
813         @echo "--------------------------------------------------------------"
814 .if exists(${KRNLOBJDIR}/${INSTALLKERNEL}/.buildkernel_run)
815         cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
816             ${IMAKEENV} make KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}
817 .else
818         cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
819             make KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}
820 .endif
821         @echo "--------------------------------------------------------------"
822         @echo ">>> Kernel install for ${INSTALLKERNEL} completed on `LC_ALL=C date`"
823         @echo "--------------------------------------------------------------"
824
825
826 # ------------------------------------------------------------------------
827 #
828 # From here onwards are utility targets used by the 'make world' and
829 # related targets.  If your 'world' breaks, you may like to try to fix
830 # the problem and manually run the following targets to attempt to
831 # complete the build.  Beware, this is *not* guaranteed to work, you
832 # need to have a pretty good grip on the current state of the system
833 # to attempt to manually finish it.  If in doubt, 'make world' again.
834 #
835
836 # bootstrap-tools: Build all tools required to build all tools.  Note that
837 # order is important in a number of cases and also note that the bootstrap
838 # and build tools stages have access to earlier binaries they themselves
839 # had generated.
840 #
841 # patch:        older patch's do not have -i.  This program must be built
842 #               first so other bootstrap tools that need to apply patches
843 #               can use it.
844 # [x]install:   dependancies on various new install features
845 # rpcgen:       old rpcgen used a hardwired cpp path, newer OBJFORMAT_PATH
846 #               envs are not compatible with older objformat binaries.
847 #
848
849 # BSTRAPDIRS1 - must be built in strict order, no parallelism
850 #
851 # order is very important. yacc before m4 before flex.  flex exec's m4,
852 # m4's parser file needs the latest byacc (insanity!).
853 #
854 BSTRAPDIRS1= \
855         usr.bin/patch \
856         bin/chmod bin/cp bin/cpdup bin/dd bin/mkdir bin/rm bin/echo \
857         bin/test bin/cat bin/ln bin/mv bin/expr bin/sh \
858         bin/hostname bin/kill \
859         usr.bin/yacc usr.bin/m4 usr.bin/localedef \
860         usr.bin/uudecode usr.bin/xinstall \
861         usr.bin/rpcgen usr.bin/bmake usr.bin/awk usr.bin/stat \
862         usr.bin/find usr.bin/flex
863
864 # BSTRAPDIRS2 - may built in parallel
865 #
866 BSTRAPDIRS2= \
867         usr.bin/sed usr.bin/uname usr.bin/touch \
868         usr.bin/mkdep usr.bin/mktemp usr.bin/lorder usr.bin/file2c \
869         usr.bin/tsort usr.bin/tr usr.bin/join usr.bin/wc usr.bin/basename \
870         usr.bin/gencat usr.bin/chflags \
871         usr.bin/uuencode usr.bin/cap_mkdb usr.bin/true usr.bin/false \
872         usr.bin/cmp usr.bin/xargs usr.bin/id usr.bin/env usr.bin/dirname \
873         usr.bin/tail usr.bin/unifdef \
874         usr.sbin/chown usr.sbin/mtree usr.sbin/config \
875         usr.sbin/zic usr.sbin/pwd_mkdb \
876         gnu/usr.bin/grep usr.bin/sort usr.bin/gzip \
877         usr.bin/mkcsmapper usr.bin/mkesdb usr.bin/crunch
878
879 bootstrap-tools: bootstrap-tools-before bootstrap-tools-targets1 bootstrap-tools-targets2
880         touch ${BTOOLSDEST}/.bootstrap_done
881
882 bootstrap-tools-before:
883         ${LN} -fs /bin/date ${BTOOLSDEST}/bin/date
884
885 bootstrap-tools-targets1: ${BSTRAPDIRS1:S/^/bstrap-/}
886
887 bootstrap-tools-targets2: ${BSTRAPDIRS2:S/^/bstrap-/}
888
889 .ORDER: bootstrap-tools-before bootstrap-tools-targets1 bootstrap-tools-targets2
890
891 .ORDER: ${BSTRAPDIRS1:S/^/bstrap-/}
892
893 .for _tool in ${BSTRAPDIRS1} ${BSTRAPDIRS2}
894 bstrap-${_tool}!
895         ${ECHODIR} "===> ${_tool} (bootstrap-tools)"; \
896                 cd ${.CURDIR}/${_tool}; \
897                 make DIRPRFX=${_tool}/ obj && \
898                 make DIRPRFX=${_tool}/ depend && \
899                 make DIRPRFX=${_tool}/ all && \
900                 make DIRPRFX=${_tool}/ DESTDIR=${BTOOLSDEST} install
901 .endfor
902
903 # build-tools: Build special purpose build tools.
904 #
905 # XXX we may be able to remove or consolidate this into bootstrap-tools
906 # now that we have the native helper (.nx/.no) infrastructure.
907 #
908 # XXX we should separate this into new Makefile.inc2.
909 # Just to prepare for reduction of ORDER: that slows down parallel crossworld.
910
911 # Make sure Makefile.inc1 logic is intact.
912 .if !defined(WORLD_ALTCOMPILER)
913 .warning undefined WORLD_ALTCOMPILER
914 .endif
915
916 # gcc80 is now the default compiler.  See sys.mk for WORLD_ALTCOMPILER default
917 # and this file for WORLD_CCVER.
918 #
919 _gcc47_cross= gnu/usr.bin/cc47
920 _gcc80_cross= gnu/usr.bin/cc80
921 _gcc_common_cross= lib/libz gnu/usr.bin/gmp gnu/usr.bin/mpfr gnu/usr.bin/mpc
922
923 .if !defined(NO_ALTCOMPILER)
924 . if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc47})
925 _altcompiler_cross+= ${_gcc47_cross}
926 . endif
927 .endif
928
929 _basecompiler_cross= ${_gcc80_cross}
930
931 _custom_cross= libexec/customcc
932 _binutils= gnu/usr.bin/${WORLD_BINUTILSVER}
933
934 build-tools: build-tools-targets
935         touch ${BTOOLSDEST}/.build_done
936
937 build-tools-targets: ${BTOOLSDIRS:S/^/btools-/}
938
939 #
940 # cross-tools: Build cross-building tools
941 #
942
943 CTOOLSDIRS= usr.bin/objformat
944
945 CTOOLSDIRS+=    ${_binutils} \
946                 ${_gcc_common_cross} \
947                 ${_altcompiler_cross} \
948                 ${_basecompiler_cross} ${_custom_cross}
949
950 cross-tools: cross-tools-targets
951         touch ${CTOOLSDEST}/.cross_done
952
953 cross-tools-targets: ${CTOOLSDIRS:S/^/ctools-/}
954
955 .for _tool in ${CTOOLSDIRS}
956 ctools-${_tool}!
957         ${ECHODIR} "===> ${_tool} (cross-tools)"; \
958                 cd ${.CURDIR}/${_tool}; \
959                 make DIRPRFX=${_tool}/ obj && \
960                 make DIRPRFX=${_tool}/ depend && \
961                 make DIRPRFX=${_tool}/ all && \
962                 make DIRPRFX=${_tool}/ DESTDIR=${CTOOLSDEST} install
963 .endfor
964
965 #
966 # hierarchy - ensure that all the needed directories are present
967 #
968 hierarchy:
969         cd ${.CURDIR}/etc;              make distrib-dirs
970
971 #
972 # libraries - build all libraries, and install them under ${DESTDIR}.
973 #
974 # The list of libraries with dependents (${_prebuild_libs}) and their
975 # interdependencies (__L) are built automatically by the
976 # ${.CURDIR}/tools/make_libdeps.sh script.
977 #
978 # .makeenv does not work when bootstrapping from 4.x, so we must be sure
979 # to specify the correct CCVER or 'cc' will not exec the correct compiler.
980 #
981 libraries:
982         cd ${.CURDIR}; \
983             HOST_CCVER=${HOST_CCVER} CCVER=gcc80 \
984                 make -f Makefile.inc1 _startup_libs80 -DSYSBUILD -DLIBGCC_ONLY;
985 .if !defined(NO_ALTCOMPILER)
986 . if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc47})
987         cd ${.CURDIR}; \
988             HOST_CCVER=${HOST_CCVER} CCVER=gcc47 \
989                 make -f Makefile.inc1 _startup_libs47 -DSYSBUILD -DLIBGCC_ONLY;
990 . endif
991 .endif
992         cd ${.CURDIR}; \
993             make -f Makefile.inc1 _startup_libs -DSYSBUILD && \
994             make -f Makefile.inc1 _prebuild_libs -DSYSBUILD && \
995             make -f Makefile.inc1 _generic_libs -DSYSBUILD && \
996             touch ${WORLDDEST}/.libraries_done
997
998 # These dependencies are not automatically generated:
999 #
1000 # gnu/lib/${CCVER}/libgcc and gnu/lib/${CCVER}/csu must be built before all
1001 # shared libraries for ELF.  The target for _startup_libsXX is
1002 # specifically built using gccXX.
1003 #
1004 _startup_libs47=        gnu/usr.bin/cc47/cc_prep \
1005                         gnu/usr.bin/cc47/cc_tools \
1006                         gnu/lib/gcc47/csu \
1007                         gnu/lib/gcc47/libgcc \
1008                         gnu/lib/gcc47/libgcc_eh \
1009                         gnu/lib/gcc47/libgcc_pic
1010
1011 _startup_libs80=        gnu/usr.bin/cc80/cc_prep \
1012                         gnu/usr.bin/cc80/cc_tools \
1013                         gnu/lib/gcc80/csu \
1014                         gnu/lib/gcc80/libgcc \
1015                         gnu/lib/gcc80/libgcc_eh \
1016                         gnu/lib/gcc80/libgcc_pic
1017
1018 .if !defined(NO_ALTCOMPILER)
1019 . if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc47})
1020 _startup_libs_alt+=     _startup_libs47
1021 . endif
1022 .endif
1023
1024 _startup_libs_base=     _startup_libs80
1025
1026 _startup_libs=          lib/csu lib/libc lib/libc_rtld
1027 lib/libc__L: lib/csu__L
1028
1029 _prebuild_libs=         lib/libbz2 lib/liblzma lib/libz
1030 _prebuild_libs+=        lib/libutil
1031
1032 _prebuild_libs+=        lib/libelf
1033 _prebuild_libs+=        lib/libpcap
1034
1035 _generic_libs=  gnu/lib
1036
1037 _prebuild_libs+= lib/libcrypt lib/libncurses/libncurses
1038
1039 _generic_libs+= lib
1040
1041 _prebuild_libs+=        lib/librecrypto lib/libressl
1042 lib/libressl__L: lib/librecrypto__L
1043
1044 _prebuild_libs+=        lib/libssh
1045 lib/libssh__L: lib/librecrypto__L lib/libutil__L lib/libz__L
1046
1047 _prebuild_libs+=        lib/libradius
1048 lib/libradius__L: lib/librecrypto__L
1049
1050 _prebuild_libs+= lib/libsbuf lib/libtacplus lib/libm \
1051                 lib/libpam/libpam lib/libypclnt lib/lib${THREAD_LIB} \
1052                 lib/libpthread lib/libprop
1053
1054 _generic_libs+= usr.bin/flex/lib
1055
1056 .for _alib in ${_startup_libs_alt} ${_startup_libs_base}
1057 __startup_alibs+= ${${_alib}}
1058 .endfor
1059
1060 .for _lib in ${__startup_alibs} \
1061                 ${_startup_libs} ${_prebuild_libs} ${_generic_libs}
1062 ${_lib}__L: .PHONY
1063 .if exists(${.CURDIR}/${_lib})
1064         @${ECHODIR} "===> ${_lib}"; \
1065                 cd ${.CURDIR}/${_lib}; \
1066                 echo "STEP DEP ${_lib}" && \
1067                 make DIRPRFX=${_lib}/ depend && \
1068                 echo "STEP ALL ${_lib}" && \
1069                 make DIRPRFX=${_lib}/ all && \
1070                 echo "STEP INSTALL ${_lib}" && \
1071                 make DIRPRFX=${_lib}/ install && \
1072                 echo "STEP DONE ${_lib}";
1073 .else
1074 .warning missing ${.CURDIR}/${_lib} directory.
1075 .endif
1076 .endfor
1077
1078 _startup_libs: ${_startup_libs:S/$/__L/}
1079 .for _alib in ${_startup_libs_alt} ${_startup_libs_base}
1080 ${_alib}: ${${_alib}:C/$/__L/}
1081 .endfor
1082 _prebuild_libs: ${_prebuild_libs:S/$/__L/}
1083 _generic_libs: ${_generic_libs:S/$/__L/}
1084
1085 # library targets must be ordered because there are inter-library
1086 # races (e.g. generation of tconfig.h)
1087 #
1088 .for _alib in ${_startup_libs_base} ${_startup_libs_alt}
1089 .ORDER: ${${_alib}:C/$/__L/}
1090 .endfor
1091
1092 # uncomment if there are missing dependencies
1093 .if 0
1094 .ORDER: ${_prebuild_libs:S/$/__L/}
1095 # we can disable this one, no lib/* depend on libstdc++
1096 .ORDER: ${_generic_libs:S/$/__L/}
1097 .endif
1098
1099 .for __target in clean cleandepend cleandir obj depend includes
1100 .for entry in ${SUBDIR}
1101 ${entry}.${__target}__D: .PHONY
1102         @if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1103                 ${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH}"; \
1104                 edir=${entry}.${MACHINE_ARCH}; \
1105                 cd ${.CURDIR}/$${edir}; \
1106         else \
1107                 ${ECHODIR} "===> ${DIRPRFX}${entry}"; \
1108                 edir=${entry}; \
1109                 cd ${.CURDIR}/$${edir}; \
1110         fi; \
1111         make ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1112 .endfor
1113 par-${__target}: ${SUBDIR:C/$/.${__target}__D/}
1114 .ORDER: ${SUBDIR:C/$/.${__target}__D/}
1115 .endfor
1116 .ORDER: par-clean par-cleandepend par-cleandir par-obj par-depend par-includes
1117
1118 # The wmake target is used by /usr/bin/wmake to run make in a
1119 # world build environment.
1120 #
1121 wmake:
1122         @echo '${WMAKEENV} make ${WMAKE_ARGS} -DSYSBUILD'
1123
1124 wmakeenv:
1125         @echo '${WMAKEENV} /bin/sh'
1126
1127 bmake:
1128         @echo '${BMAKEENV} make ${BMAKE_ARGS} -DSYSBUILD'
1129
1130 bmakeenv:
1131         @echo '${BMAKEENV} /bin/sh'
1132
1133 tmake:
1134         @echo '${TMAKEENV} make ${TMAKE_ARGS} -DSYSBUILD'
1135
1136 tmakeenv:
1137         @echo '${TMAKEENV} /bin/sh'
1138
1139 xmake:
1140         @echo '${XMAKEENV} make ${XMAKE_ARGS} -DSYSBUILD'
1141
1142 xmakeenv:
1143         @echo '${XMAKEENV} /bin/sh'
1144
1145 backupworld: backup-clean
1146         @mkdir -p ${WORLD_BACKUP}
1147 .if (exists(${DESTDIR}/sbin) && exists(${DESTDIR}/bin) && \
1148      exists(${DESTDIR}/usr/sbin) && exists(${DESTDIR}/usr/bin) && \
1149      exists(${DESTDIR}/usr/lib) && exists(${DESTDIR}/usr/libexec))
1150         tar -czf ${WORLD_BACKUP}/binaries.tar.gz -C ${DESTDIR}/ \
1151                 --options gzip:compression-level=1 \
1152                 sbin bin usr/sbin usr/bin usr/lib usr/libexec
1153 .endif
1154
1155 backupworld-auto:
1156 .if !defined(NO_BACKUP)
1157         rm -f ${AUTO_BACKUP}/binaries.tar.gz
1158         @mkdir -p ${AUTO_BACKUP}
1159 .if (exists(${DESTDIR}/sbin) && exists(${DESTDIR}/bin) && \
1160      exists(${DESTDIR}/usr/sbin) && exists(${DESTDIR}/usr/bin) && \
1161      exists(${DESTDIR}/usr/lib) && exists(${DESTDIR}/usr/libexec))
1162         /usr/bin/tar -czf ${AUTO_BACKUP}/binaries.tar.gz -C ${DESTDIR}/ \
1163                 --options gzip:compression-level=1 \
1164                 sbin bin usr/sbin usr/bin usr/lib usr/libexec
1165 .endif
1166 .endif
1167
1168 backup-auto-clean:
1169         rm -f ${AUTO_BACKUP}/binaries.tar.gz
1170
1171 backup-clean:
1172         rm -f ${WORLD_BACKUP}/binaries.tar.gz
1173
1174 restoreworld:
1175 .if !exists(${WORLD_BACKUP}/binaries.tar.gz)
1176         @echo "There does not seem to be a valid archive present."
1177 .else
1178         @echo "Restoring system binaries from manual backup archive..."
1179         @chflags -R noschg ${DESTDIR}/sbin ${DESTDIR}/bin \
1180                 ${DESTDIR}/usr/sbin ${DESTDIR}/usr/bin \
1181                 ${DESTDIR}/usr/lib ${DESTDIR}/usr/libexec
1182         tar -xzf ${WORLD_BACKUP}/binaries.tar.gz -C ${DESTDIR}/
1183 .endif
1184
1185 restoreworld-auto:
1186 .if !exists(${AUTO_BACKUP}/binaries.tar.gz)
1187         @echo "There does not seem to be a valid archive present."
1188 .else
1189         @echo "Restoring system binaries from auto-backup archive..."
1190         @chflags -R noschg ${DESTDIR}/sbin ${DESTDIR}/bin \
1191                 ${DESTDIR}/usr/sbin ${DESTDIR}/usr/bin \
1192                 ${DESTDIR}/usr/lib ${DESTDIR}/usr/libexec
1193         tar -xzf ${AUTO_BACKUP}/binaries.tar.gz -C ${DESTDIR}/
1194 .endif
1195
1196 # Take advantage of bmake error response
1197 #
1198 MAKE_PRINT_VAR_ON_ERROR= \
1199         .CURDIR \
1200         .OBJDIR \
1201         .TARGETS \
1202         .ERROR_TARGET \
1203         .MAKE.LEVEL \
1204         .MAKE.MODE \
1205         PATH \
1206         LD_LIBRARY_PATH \
1207         MACHINE_ARCH \
1208         MACHINE \
1209         MAKEFILE \
1210         MAKESYSPATH \
1211         MAKEOBJDIRPREFIX \
1212         WORLD_ALTCOMPILER \
1213         DESTDIR \
1214         SHELL .SHELL
1215 .if ${.MAKE.LEVEL} > 0
1216 MAKE_PRINT_VAR_ON_ERROR+= .MAKE.MAKEFILES .PATH
1217 .endif
1218
1219 .include <bsd.subdir.mk>