polling.4: Add ix(4)
[dragonfly.git] / Makefile.inc1
index 244a078..860362c 100644 (file)
 # realquickworld - skip the glue and depend stages and just build the meat
 # crossworld  - only build the glue (particularly the cross-build environment)
 # installworld- install everything built by "buildworld"
+# backupworld - copies /bin /sbin /usr/bin /usr/sbin /usr/lib /usr/libexec
+#               to manual backup dir
+# restoreworld- installs binaries from manual backup dir to world
+# restoreworld-auto - installs binaries from auto-backup dir to world
 # most        - build user commands, no libraries or include files
 # installmost - install user commands, no libraries or include files
+# backup-clean - delete backup from manual backup dir
+# backup-auto-clean - delete backup from auto-backup dir
 #
 # Standard targets (not defined here) are documented in the makefiles in
 # /usr/share/mk.  These include:
 # Put initial settings here.
 SUBDIR=
 
+# /libexec/ld-elf.so.2 needs to be installed first
+# Otherwise, install(1) beeing a dynamically linked binary will fail
+# during the first upgrade from a static to a dynamic world
+.if exists(${.CURDIR}/libexec)
+SUBDIR+= libexec
+.endif
+
 # We must do share/info early so that installation of info `dir'
 # entries works correctly.  Do it first since it is less likely to
 # grow dependencies on include and lib than vice versa.
@@ -52,9 +65,6 @@ SUBDIR+= games
 .if exists(${.CURDIR}/gnu)
 SUBDIR+= gnu
 .endif
-.if exists(${.CURDIR}/libexec)
-SUBDIR+= libexec
-.endif
 .if exists(${.CURDIR}/sbin)
 SUBDIR+= sbin
 .endif
@@ -112,22 +122,21 @@ OBJTREE?=         ${MAKEOBJDIRPREFIX}
 
 # Used for stage installs and pathing
 #
-DESTDIRBASE?=          ${OBJTREE}${.CURDIR}
+DESTDIRBASE:=          ${OBJTREE}${.CURDIR}
 
 # Remove DESTDIR from MAKEFLAGS.  It is present in the environment
 # anyhow, and we need to be able to override it for stage installs
 .MAKEFLAGS:=   ${.MAKEFLAGS:NDESTDIR=*}
 
 # This section sets the tools used to build the world/kernel
-WORLD_CCVER?=          gcc44
+WORLD_CCVER?=          gcc47
 WORLD_LDVER?=          ld.bfd
-WORLD_BINUTILSVER?=    binutils222
+WORLD_BINUTILSVER?=    binutils224
 
-# temporary until everybody has converted to x86_64
-.if ${MACHINE_ARCH} == "amd64"
-MACHINE_ARCH=  x86_64
-.makeenv MACHINE_ARCH
-.endif
+# Set the backup parameters if they are not already defined
+#
+WORLD_BACKUP?=         /var/backups/world_backup
+AUTO_BACKUP?=          ${OBJTREE}/world_backup/${DESTDIR}
 
 TARGET_ARCH?=  ${MACHINE_ARCH}
 .if ${TARGET_ARCH} == ${MACHINE_ARCH}
@@ -206,7 +215,7 @@ BTOOLSPATH= ${BTOOLSDEST}/usr/sbin:${BTOOLSDEST}/usr/bin:${BTOOLSDEST}/bin:${BTO
 # The strict temporary command path contains all binaries required
 # by the buildworld system after the cross-tools stage.
 #
-STRICTTMPPATH= ${CTOOLSDEST}/usr/sbin:${CTOOLSDEST}/usr/bin:${CTOOLSDEST}/bin:${CTOOLSDEST}/usr/games:${BTOOLSDEST}/usr/sbin:${BTOOLSDEST}/usr/bin:${BTOOLSDEST}/bin:${BTOOLSDEST}/usr/games:/usr/pkg/bin
+STRICTTMPPATH= ${CTOOLSDEST}/usr/sbin:${CTOOLSDEST}/usr/bin:${CTOOLSDEST}/bin:${CTOOLSDEST}/usr/games:${BTOOLSDEST}/usr/sbin:${BTOOLSDEST}/usr/bin:${BTOOLSDEST}/bin:${BTOOLSDEST}/usr/games:/usr/local/bin:/usr/pkg/bin
 
 TMPDIR?=       /tmp
 TMPPID!=       echo $$$$
@@ -231,6 +240,16 @@ TMPPID!=   echo $$$$
 # 5. install stage (optional) [IMAKE]
 #      This stage installs a previously built world.
 #
+# In all cases we must carefully adjust the environment so the proper
+# tools and header files are used.
+#
+# NOTE: The M4 environment variable is used by the [f]lex binary to
+#      override the location of the 'm4' binary.  The override is
+#      needed for certain buildworld version transitions, specifically
+#      past a certain point in 3.3 because the older /usr/bin/m4 will
+#      generate output that will blow up the newer [f]lex/yacc/bison
+#      utilities.
+#
 
 # bootstrap-tool stage
 #
@@ -238,9 +257,10 @@ BMAKEENV=  MAKEOBJDIRPREFIX=${BTOOLSDEST} \
                OBJTREE=${OBJTREE} \
                DESTDIR=${BTOOLSDEST} \
                PATH=${BTOOLSPATH}:${PATH} \
+               M4=${BTOOLSDEST}/usr/bin/m4 \
                INSTALL="sh ${.CURDIR}/tools/install.sh"
 
-BMAKE=         ${BMAKEENV} ${MAKE} -f Makefile.inc1 -DBOOTSTRAPPING \
+BMAKE=         ${BMAKEENV} make -f Makefile.inc1 -DBOOTSTRAPPING \
                -DNOINFO -DNOMAN -DNOPIC -DNOPROFILE -DNOSHARED \
                -DNO_WERROR -DNO_NLS
 
@@ -250,9 +270,10 @@ TMAKEENV=  MAKEOBJDIRPREFIX=${BTOOLSDEST} \
                OBJTREE=${OBJTREE} \
                DESTDIR= \
                PATH=${BTOOLSPATH}:${PATH} \
+               M4=${BTOOLSDEST}/usr/bin/m4 \
                INSTALL="sh ${.CURDIR}/tools/install.sh"
 
-TMAKE=         ${TMAKEENV} ${MAKE} -f Makefile.inc1 -DBOOTSTRAPPING \
+TMAKE=         ${TMAKEENV} make -f Makefile.inc1 -DBOOTSTRAPPING \
                -DNO_FORTRAN -DNOSHARED
 
 # cross-tool stage
@@ -265,12 +286,14 @@ TMAKE=            ${TMAKEENV} ${MAKE} -f Makefile.inc1 -DBOOTSTRAPPING \
 XMAKEENV=      MAKEOBJDIRPREFIX=${CTOOLSDEST} \
                OBJTREE=${OBJTREE} \
                DESTDIR=${CTOOLSDEST} \
+               _SHLIBDIRPREFIX=${CTOOLSDEST} \
                INSTALL="sh ${.CURDIR}/tools/install.sh" \
                TOOLS_PREFIX=${CTOOLSDEST} \
                USRDATA_PREFIX=${WORLDDEST} \
+               M4=${BTOOLSDEST}/usr/bin/m4 \
                PATH=${BTOOLSPATH}:${PATH}
 
-XMAKE=         ${XMAKEENV} ${MAKE} -f Makefile.inc1 -DNO_FORTRAN -DNO_GDB \
+XMAKE=         ${XMAKEENV} make -f Makefile.inc1 -DNO_FORTRAN -DNO_GDB \
                -DBOOTSTRAPPING -DNOSHARED
 
 # world stage, note the strict path and note that TOOLS_PREFIX is left
@@ -293,16 +316,18 @@ CROSSENV= MAKEOBJDIRPREFIX=${WORLDDEST} \
 
 WMAKEENV=      ${CROSSENV} \
                DESTDIR=${WORLDDEST} \
+               _SHLIBDIRPREFIX=${WORLDDEST} \
                INSTALL="sh ${.CURDIR}/tools/install.sh" \
+               M4=${BTOOLSDEST}/usr/bin/m4 \
                PATH=${STRICTTMPPATH}
 
-WMAKE=         ${WMAKEENV} ${MAKE} -f Makefile.inc1
+WMAKE=         ${WMAKEENV} make -f Makefile.inc1
 
 # install stage
 #
 IMAKEENV=      ${CROSSENV} \
                PATH=${STRICTTMPPATH}
-IMAKE=         ${IMAKEENV} ${MAKE} -f Makefile.inc1
+IMAKE=         ${IMAKEENV} make -f Makefile.inc1
 
 # kernel stage
 #
@@ -427,6 +452,7 @@ crossworld: _worldtmp _bootstrap-tools _obj _build-tools _cross-tools
 .ORDER: ${WMAKE_TGTS}
 .ORDER: _obj _includes
 .ORDER: _mtreetmp _obj
+.ORDER: installcheck backupworld-auto
 
 #
 # installcheck
@@ -435,23 +461,32 @@ crossworld: _worldtmp _bootstrap-tools _obj _build-tools _cross-tools
 #
 installcheck:
 .if !defined(NO_SENDMAIL)
-       @pw usershow smmsp || (echo "You may need to run 'make preupgrade' first"; exit 1)
-       @pw groupshow smmsp || (echo "You may need to run 'make preupgrade' first"; exit 1)
+       @pw usershow smmsp || (echo "You may need to run 'make preupgrade' first"; /usr/bin/false)
+       @pw groupshow smmsp || (echo "You may need to run 'make preupgrade' first"; /usr/bin/false)
 .endif
-       @pw usershow _pflogd || (echo "You may need to run 'make preupgrade' first"; exit 1)
-       @pw groupshow authpf || (echo "You may need to run 'make preupgrade' first"; exit 1)
-       @pw groupshow _pflogd || (echo "You may need to run 'make preupgrade' first"; exit 1)
+       @pw usershow _pflogd || (echo "You may need to run 'make preupgrade' first"; /usr/bin/false)
+       @pw groupshow authpf || (echo "You may need to run 'make preupgrade' first"; /usr/bin/false)
+       @pw groupshow _pflogd || (echo "You may need to run 'make preupgrade' first"; /usr/bin/false)
 .if !defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/"
-       @case `uname -r` in 1.2*|1.3-*|1.3.*|1.4.*|1.5.0-*|1.5.1-*|1.5.2-*|1.5.3-*) echo "You must upgrade your kernel to at least 1.5.4 and reboot before you can safely installworld, due to libc/system call ABI changes" ; exit 1;; esac
+       @case `uname -r` in 1.2*|1.3-*|1.3.*|1.4.*|1.5.0-*|1.5.1-*|1.5.2-*|1.5.3-*) echo "You must upgrade your kernel to at least 1.5.4 and reboot before you can safely installworld, due to libc/system call ABI changes" ; /usr/bin/false ; esac
 .endif
+
 #
 # installworld
 #
+# Backs up the current world if ${AUTO_BACKUP} is writable.
 # Installs everything compiled by a 'buildworld'.
-#
+
 installworld: installcheck
+       -@mkdir -p ${AUTO_BACKUP} > /dev/null 2>&1
+       @cd ${.CURDIR}; \
+           (touch ${AUTO_BACKUP}/.updating > /dev/null 2>&1 && \
+            ${IMAKE} backupworld-auto) || \
+           echo "Cannot write to ${AUTO_BACKUP} - world not backed up"
+
        cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}
        ${INSTALL} -o root -g wheel -m 644 ${.CURDIR}/Makefile_upgrade.inc ${DESTDIR}/etc/upgrade/
+       mkinitrd -b ${DESTDIR}/boot
 
 #
 # reinstall
@@ -464,12 +499,12 @@ reinstall:
        @echo "--------------------------------------------------------------"
        @echo ">>> Making hierarchy"
        @echo "--------------------------------------------------------------"
-       cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 hierarchy
+       cd ${.CURDIR}; make -f Makefile.inc1 hierarchy
        @echo
        @echo "--------------------------------------------------------------"
        @echo ">>> Installing everything.."
        @echo "--------------------------------------------------------------"
-       cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
+       cd ${.CURDIR}; make -f Makefile.inc1 install
 
 #
 # buildkernel, nativekernel, quickkernel, and installkernel
@@ -539,7 +574,7 @@ bk_tools:
            echo "You must buildworld before buildkernel.  If you wish"; \
            echo "to build a kernel using native tools, config it manually"; \
            echo "or use the nativekernel target if you are in a rush"; \
-           exit 1; \
+           /usr/bin/false; \
        fi
 
 maybe_bk_tools:
@@ -548,7 +583,7 @@ maybe_bk_tools:
            if [ ! -f ${WORLDDEST}/.libraries_done ]; then \
                echo "The kernel was build using buildworld tools which no" ; \
                echo "longer appear to exist, quickkernel failed!" ; \
-               exit 1; \
+               /usr/bin/false; \
            fi; \
        fi
 .endfor
@@ -599,10 +634,10 @@ buildkernel:      bk_tools bk_build_list bk_kernwarn
        touch ${KRNLOBJDIR}/${_kernel}/.buildkernel_run
 .if !defined(NO_KERNELDEPEND)
        cd ${KRNLOBJDIR}/${_kernel}; \
-           ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} depend
+           ${KMAKEENV} make KERNEL=${INSTKERNNAME} depend
 .endif
        cd ${KRNLOBJDIR}/${_kernel}; \
-           ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} all
+           ${KMAKEENV} make KERNEL=${INSTKERNNAME} all
        @echo "--------------------------------------------------------------"
        @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
        @echo "--------------------------------------------------------------"
@@ -638,13 +673,13 @@ nativekernel:     bk_build_list bk_kernwarn
        touch ${KRNLOBJDIR}/${_kernel}/.nativekernel_run
        cd ${KRNLOBJDIR}/${_kernel}; \
            MAKESRCPATH=${KRNLSRCDIR}/dev/disk/aic7xxx/aicasm \
-           ${MAKE} -DBOOTSTRAPPING -f ${KRNLSRCDIR}/dev/disk/aic7xxx/aicasm/Makefile
+           make -DBOOTSTRAPPING -f ${KRNLSRCDIR}/dev/disk/aic7xxx/aicasm/Makefile
 .if !defined(NO_KERNELDEPEND)
        cd ${KRNLOBJDIR}/${_kernel}; \
-           ${MAKE} KERNEL=${INSTKERNNAME} depend
+           make KERNEL=${INSTKERNNAME} depend
 .endif
        cd ${KRNLOBJDIR}/${_kernel}; \
-           ${MAKE} KERNEL=${INSTKERNNAME} all
+           make KERNEL=${INSTKERNNAME} all
        @echo "--------------------------------------------------------------"
        @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
        @echo "--------------------------------------------------------------"
@@ -670,7 +705,7 @@ quickkernel:        maybe_bk_tools bk_build_list bk_kernwarn
                        ${KERNCONFDIR}/${_kernel}
 .endif
        cd ${KRNLOBJDIR}/${_kernel}; \
-           ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} all
+           ${KMAKEENV} make KERNEL=${INSTKERNNAME} all
 .else
 .if !defined(NO_KERNELCONFIG)
        cd ${KRNLCONFDIR}; \
@@ -678,7 +713,7 @@ quickkernel:        maybe_bk_tools bk_build_list bk_kernwarn
                ${KERNCONFDIR}/${_kernel}
 .endif
        cd ${KRNLOBJDIR}/${_kernel}; \
-           ${MAKE} KERNEL=${INSTKERNNAME} all
+           make KERNEL=${INSTKERNNAME} all
 .endif
        @echo "--------------------------------------------------------------"
        @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
@@ -696,10 +731,10 @@ installkernel reinstallkernel:
        @echo "--------------------------------------------------------------"
 .if exists(${KRNLOBJDIR}/${INSTALLKERNEL}/.buildkernel_run)
        cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
-           ${IMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}
+           ${IMAKEENV} make KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}
 .else
        cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
-           ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}
+           make KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}
 .endif
 
 #
@@ -712,7 +747,7 @@ most:
        @echo ">>> Building programs only"
        @echo "--------------------------------------------------------------"
 .for _dir in bin sbin libexec usr.bin usr.sbin gnu/libexec gnu/usr.bin gnu/usr.sbin
-       cd ${.CURDIR}/${_dir};          ${MAKE} DIRPRFX=${_dir}/ all
+       cd ${.CURDIR}/${_dir};          make DIRPRFX=${_dir}/ all
 .endfor
 
 #
@@ -726,7 +761,7 @@ installmost:
        @echo ">>> Installing programs only"
        @echo "--------------------------------------------------------------"
 .for _dir in bin sbin libexec usr.bin usr.sbin gnu/libexec gnu/usr.bin gnu/usr.sbin
-       cd ${.CURDIR}/${_dir};          ${MAKE} DIRPRFX=${_dir}/ install
+       cd ${.CURDIR}/${_dir};          make DIRPRFX=${_dir}/ install
 .endfor
 
 #
@@ -756,44 +791,60 @@ installmost:
 _strfile=      games/fortune/strfile
 .endif
 
-BSTRAPDIRS= ${_strfile} \
+# BSTRAPDIRS1 - must be built in strict order, no parallelism
+#
+# order is very important. yacc before m4 before flex.  flex exec's m4,
+# m4's parser file needs the latest byacc (insanity!).
+#
+BSTRAPDIRS1= ${_strfile} \
        usr.bin/patch \
        bin/chmod bin/cp bin/cpdup bin/dd bin/mkdir bin/rm bin/echo \
        bin/test bin/cat bin/ln bin/mv bin/csh bin/expr bin/sh \
        bin/hostname bin/kill \
-       usr.bin/yacc usr.bin/colldef usr.bin/uudecode usr.bin/xinstall \
-       usr.bin/m4 usr.bin/rpcgen usr.bin/make usr.bin/awk usr.bin/stat \
-       usr.bin/find usr.bin/lex usr.bin/sed usr.bin/uname usr.bin/touch \
+       usr.bin/yacc usr.bin/m4 usr.bin/colldef \
+       usr.bin/uudecode usr.bin/xinstall \
+       usr.bin/rpcgen usr.bin/bmake usr.bin/awk usr.bin/stat \
+       usr.bin/find usr.bin/flex
+
+# BSTRAPDIRS2 - may built in parallel
+#
+BSTRAPDIRS2= \
+       usr.bin/sed usr.bin/uname usr.bin/touch \
        usr.bin/mkdep usr.bin/mktemp usr.bin/lorder usr.bin/file2c \
        usr.bin/tsort usr.bin/tr usr.bin/join usr.bin/wc usr.bin/basename \
        usr.bin/gencat usr.bin/chflags usr.bin/expand usr.bin/paste \
        usr.bin/mklocale usr.bin/uuencode usr.bin/compile_et usr.bin/hexdump \
        usr.bin/cap_mkdb usr.bin/true usr.bin/false \
        usr.bin/cmp usr.bin/xargs usr.bin/id usr.bin/env usr.bin/dirname \
-       usr.bin/tail usr.bin/unifdef \
+       usr.bin/tail usr.bin/unifdef usr.bin/tic \
        usr.sbin/chown usr.sbin/mtree usr.sbin/config \
        usr.sbin/btxld usr.sbin/zic usr.sbin/makewhatis \
        gnu/usr.bin/texinfo gnu/usr.bin/grep usr.bin/sort \
-       usr.bin/gzip usr.bin/bzip2 usr.bin/mkcsmapper usr.bin/mkesdb
+       usr.bin/gzip usr.bin/bzip2 usr.bin/mkcsmapper usr.bin/mkesdb \
+       usr.bin/crunch
 
-bootstrap-tools: bootstrap-tools-before bootstrap-tools-targets
+bootstrap-tools: bootstrap-tools-before bootstrap-tools-targets1 bootstrap-tools-targets2
        touch ${BTOOLSDEST}/.bootstrap_done
 
 bootstrap-tools-before:
        ${LN} -fs /bin/date ${BTOOLSDEST}/bin/date
 
-bootstrap-tools-targets: ${BSTRAPDIRS:S/^/bstrap-/}
+bootstrap-tools-targets1: ${BSTRAPDIRS1:S/^/bstrap-/}
+
+bootstrap-tools-targets2: ${BSTRAPDIRS2:S/^/bstrap-/}
 
-.ORDER: bootstrap-tools-before bootstrap-tools-targets
+.ORDER: bootstrap-tools-before bootstrap-tools-targets1 bootstrap-tools-targets2
 
-.for _tool in ${BSTRAPDIRS}
+.ORDER: ${BSTRAPDIRS1:S/^/bstrap-/}
+
+.for _tool in ${BSTRAPDIRS1} ${BSTRAPDIRS2}
 bstrap-${_tool}!
        ${ECHODIR} "===> ${_tool} (bootstrap-tools)"; \
                cd ${.CURDIR}/${_tool}; \
-               ${MAKE} DIRPRFX=${_tool}/ obj; \
-               ${MAKE} DIRPRFX=${_tool}/ depend; \
-               ${MAKE} DIRPRFX=${_tool}/ all; \
-               ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${BTOOLSDEST} install
+               make DIRPRFX=${_tool}/ obj; \
+               make DIRPRFX=${_tool}/ depend; \
+               make DIRPRFX=${_tool}/ all; \
+               make DIRPRFX=${_tool}/ DESTDIR=${BTOOLSDEST} install
 .endfor
 
 # build-tools: Build special purpose build tools.
@@ -805,33 +856,34 @@ bstrap-${_tool}!
 _share=        share/syscons/scrnmaps
 .endif
 
-.if !defined(NO_GCC41)
-_gcc41_cross= gnu/usr.bin/cc41
-_gcc41_tools= gnu/usr.bin/cc41/cc_prep gnu/usr.bin/cc41/cc_tools
-.endif
+_gcc_common_cross= gnu/usr.bin/gmp gnu/usr.bin/mpfr
+.if !defined(NO_GCC44)
 _gcc44_cross= gnu/usr.bin/cc44
 _gcc44_tools= gnu/usr.bin/cc44/cc_prep gnu/usr.bin/cc44/cc_tools
+.endif
+_gcc47_cross= lib/libz gnu/usr.bin/mpc gnu/usr.bin/cc47
+_gcc47_tools= gnu/usr.bin/cc47/cc_prep gnu/usr.bin/cc47/cc_tools
 _custom_cross= libexec/customcc
 _binutils= gnu/usr.bin/${WORLD_BINUTILSVER}
 
-BTOOLSDIRS= ${_gcc41_tools} ${_gcc44_tools} ${_share}
+BTOOLSDIRS= ${_gcc44_tools} ${_gcc47_tools} ${_share}
 
 build-tools: build-tools-targets
        touch ${BTOOLSDEST}/.build_done
 
 build-tools-targets: ${BTOOLSDIRS:S/^/btools-/}
 
-.ORDER: ${_gcc41_tools:S/^/btools-/}
 .ORDER: ${_gcc44_tools:S/^/btools-/}
+.ORDER: ${_gcc47_tools:S/^/btools-/}
 
 .for _tool in ${BTOOLSDIRS}
 btools-${_tool}!
        ${ECHODIR} "===> ${_tool} (build-tools)"; \
                cd ${.CURDIR}/${_tool}; \
-               ${MAKE} DIRPRFX=${_tool}/ obj; \
-               ${MAKE} DIRPRFX=${_tool}/ depend; \
-               ${MAKE} DIRPRFX=${_tool}/ all; \
-               ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${BTOOLSDEST} install
+               make DIRPRFX=${_tool}/ obj; \
+               make DIRPRFX=${_tool}/ depend; \
+               make DIRPRFX=${_tool}/ all; \
+               make DIRPRFX=${_tool}/ DESTDIR=${BTOOLSDEST} install
 .endfor
 
 #
@@ -841,8 +893,10 @@ btools-${_tool}!
 _btxld=        usr.sbin/btxld
 .endif
 
-CTOOLSDIRS= ${_btxld} ${_binutils} usr.bin/objformat \
-               ${_gcc41_cross} ${_gcc44_cross} ${_custom_cross}
+CTOOLSDIRS= ${_btxld} ${_binutils} \
+               usr.bin/objformat usr.bin/crunch/crunchide \
+               ${_gcc_common_cross} \
+               ${_gcc44_cross} ${_gcc47_cross} ${_custom_cross}
 
 cross-tools: cross-tools-targets
        touch ${CTOOLSDEST}/.cross_done
@@ -853,17 +907,17 @@ cross-tools-targets: ${CTOOLSDIRS:S/^/ctools-/}
 ctools-${_tool}!
        ${ECHODIR} "===> ${_tool} (cross-tools)"; \
                cd ${.CURDIR}/${_tool}; \
-               ${MAKE} DIRPRFX=${_tool}/ obj; \
-               ${MAKE} DIRPRFX=${_tool}/ depend; \
-               ${MAKE} DIRPRFX=${_tool}/ all; \
-               ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${CTOOLSDEST} install
+               make DIRPRFX=${_tool}/ obj; \
+               make DIRPRFX=${_tool}/ depend; \
+               make DIRPRFX=${_tool}/ all; \
+               make DIRPRFX=${_tool}/ DESTDIR=${CTOOLSDEST} install
 .endfor
 
 #
 # hierarchy - ensure that all the needed directories are present
 #
 hierarchy:
-       cd ${.CURDIR}/etc;              ${MAKE} distrib-dirs
+       cd ${.CURDIR}/etc;              make distrib-dirs
 
 #
 # libraries - build all libraries, and install them under ${DESTDIR}.
@@ -876,18 +930,18 @@ hierarchy:
 # to specify the correct CCVER or 'cc' will not exec the correct compiler.
 #
 libraries:
-.if !defined(NO_GCC41)
        cd ${.CURDIR}; \
-           HOST_CCVER=${HOST_CCVER} CCVER=gcc41 \
-               ${MAKE} -f Makefile.inc1 _startup_libs41;
-.endif
+           HOST_CCVER=${HOST_CCVER} CCVER=gcc47 \
+               make -f Makefile.inc1 _startup_libs47;
+.if !defined(NO_GCC44)
        cd ${.CURDIR}; \
            HOST_CCVER=${HOST_CCVER} CCVER=gcc44 \
-               ${MAKE} -f Makefile.inc1 _startup_libs44;
+               make -f Makefile.inc1 _startup_libs44;
+.endif
        cd ${.CURDIR}; \
-           ${MAKE} -f Makefile.inc1 _startup_libs; \
-           ${MAKE} -f Makefile.inc1 _prebuild_libs; \
-           ${MAKE} -f Makefile.inc1 _generic_libs;
+           make -f Makefile.inc1 _startup_libs; \
+           make -f Makefile.inc1 _prebuild_libs; \
+           make -f Makefile.inc1 _generic_libs;
        touch ${WORLDDEST}/.libraries_done
 
 # These dependencies are not automatically generated:
@@ -896,8 +950,16 @@ libraries:
 # shared libraries for ELF.  The target for _startup_libsXX is
 # specifically built using gccXX.
 #
-_startup_libs41=       gnu/lib/gcc41/csu gnu/lib/gcc41/libgcc
-_startup_libs44=       gnu/lib/gcc44/csu gnu/lib/gcc44/libgcc
+_startup_libs47=       gnu/usr.bin/cc47/cc_prep \
+                       gnu/usr.bin/cc47/cc_tools \
+                       gnu/lib/gcc47/csu \
+                       gnu/lib/gcc47/libgcc \
+                       gnu/lib/gcc47/libgcc_eh \
+                       gnu/lib/gcc47/libgcc_pic
+_startup_libs44=       gnu/usr.bin/cc44/cc_prep \
+                       gnu/usr.bin/cc44/cc_tools \
+                       gnu/lib/gcc44/csu \
+                       gnu/lib/gcc44/libgcc
 _startup_libs=         lib/csu lib/libc lib/libc_rtld
 
 _prebuild_libs=                lib/libbz2 lib/liblzma lib/libz
@@ -906,10 +968,7 @@ _prebuild_libs+=   lib/libutil
 _generic_libs= gnu/lib
 
 _prebuild_libs+= lib/libcom_err lib/libcrypt lib/libmd \
-               lib/libncurses/libncurses lib/libopie lib/libradius \
-               lib/libsbuf lib/libtacplus lib/libm \
-               lib/libpam lib/libypclnt lib/lib${THREAD_LIB} \
-               lib/libpthread lib/libprop lib/libdevattr
+               lib/libncurses/libncurses lib/libopie
 
 lib/libopie__L lib/libradius__L lib/libtacplus__L: lib/libmd__L
 
@@ -926,22 +985,26 @@ secure/lib/libssh__L: secure/lib/libcrypto__L lib/libz__L
 _generic_libs+=        secure/lib
 .endif
 
-_generic_libs+=        usr.bin/lex/lib
+_prebuild_libs+= lib/libradius lib/libsbuf lib/libtacplus lib/libm \
+               lib/libpam lib/libypclnt lib/lib${THREAD_LIB} \
+               lib/libpthread lib/libprop lib/libdevattr
+
+_generic_libs+=        usr.bin/flex/lib
 
-.for _lib in ${_startup_libs41} ${_startup_libs44} \
+.for _lib in ${_startup_libs44} ${_startup_libs47} \
                ${_startup_libs} ${_prebuild_libs} ${_generic_libs}
 ${_lib}__L: .PHONY
 .if exists(${.CURDIR}/${_lib})
        ${ECHODIR} "===> ${_lib}"; \
                cd ${.CURDIR}/${_lib}; \
-               ${MAKE} DIRPRFX=${_lib}/ depend; \
-               ${MAKE} DIRPRFX=${_lib}/ all; \
-               ${MAKE} DIRPRFX=${_lib}/ install
+               make DIRPRFX=${_lib}/ depend; \
+               make DIRPRFX=${_lib}/ all; \
+               make DIRPRFX=${_lib}/ install
 .endif
 .endfor
 
 _startup_libs: ${_startup_libs:S/$/__L/}
-_startup_libs41: ${_startup_libs41:S/$/__L/}
+_startup_libs47: ${_startup_libs47:S/$/__L/}
 _startup_libs44: ${_startup_libs44:S/$/__L/}
 _prebuild_libs: ${_prebuild_libs:S/$/__L/}
 _generic_libs: ${_generic_libs:S/$/__L/}
@@ -949,7 +1012,7 @@ _generic_libs: ${_generic_libs:S/$/__L/}
 # library targets must be ordered because there are inter-library
 # races (e.g. generation of tconfig.h)
 #
-.ORDER: ${_startup_libs41:S/$/__L/}
+.ORDER: ${_startup_libs47:S/$/__L/}
 .ORDER: ${_startup_libs44:S/$/__L/}
 .ORDER: ${_startup_libs:S/$/__L/}
 .ORDER: ${_prebuild_libs:S/$/__L/}
@@ -967,7 +1030,7 @@ ${entry}.${__target}__D: .PHONY
                edir=${entry}; \
                cd ${.CURDIR}/$${edir}; \
        fi; \
-       ${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
+       make ${__target} DIRPRFX=${DIRPRFX}$${edir}/
 .endfor
 par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
 .ORDER: ${SUBDIR:S/$/.${__target}__D/}
@@ -978,28 +1041,91 @@ par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
 # world build environment.
 #
 wmake:
-       @echo '${WMAKEENV} ${MAKE} -m ${.CURDIR}/share/mk ${WMAKE_ARGS}'
+       @echo '${WMAKEENV} make ${WMAKE_ARGS}'
 
 wmakeenv:
        @echo '${WMAKEENV} /bin/sh'
 
 bmake:
-       @echo '${BMAKEENV} ${MAKE} -m ${.CURDIR}/share/mk ${BMAKE_ARGS}'
+       @echo '${BMAKEENV} make ${BMAKE_ARGS}'
 
 bmakeenv:
        @echo '${BMAKEENV} /bin/sh'
 
 tmake:
-       @echo '${TMAKEENV} ${MAKE} -m ${.CURDIR}/share/mk ${TMAKE_ARGS}'
+       @echo '${TMAKEENV} make ${TMAKE_ARGS}'
 
 tmakeenv:
        @echo '${TMAKEENV} /bin/sh'
 
 xmake:
-       @echo '${XMAKEENV} ${MAKE} -m ${.CURDIR}/share/mk ${XMAKE_ARGS}'
+       @echo '${XMAKEENV} make ${XMAKE_ARGS}'
 
 xmakeenv:
        @echo '${XMAKEENV} /bin/sh'
 
-.include <bsd.subdir.mk>
+backupworld: backup-clean
+       @mkdir -p ${WORLD_BACKUP}
+.if (exists(${DESTDIR}/sbin) && exists(${DESTDIR}/bin) && \
+     exists(${DESTDIR}/usr/sbin) && exists(${DESTDIR}/usr/bin) && \
+     exists(${DESTDIR}/usr/lib) && exists(${DESTDIR}/usr/libexec))
+       tar -czf ${WORLD_BACKUP}/binaries.tar.gz -C ${DESTDIR}/ \
+               --options gzip:compression-level=1 \
+               sbin bin usr/sbin usr/bin usr/lib usr/libexec
+.endif
+
+backupworld-auto:
+.if !defined(NO_BACKUP)
+       rm -f ${AUTO_BACKUP}/binaries.tar.gz
+       @mkdir -p ${AUTO_BACKUP}
+.if (exists(${DESTDIR}/sbin) && exists(${DESTDIR}/bin) && \
+     exists(${DESTDIR}/usr/sbin) && exists(${DESTDIR}/usr/bin) && \
+     exists(${DESTDIR}/usr/lib) && exists(${DESTDIR}/usr/libexec))
+       tar -czf ${AUTO_BACKUP}/binaries.tar.gz -C ${DESTDIR}/ \
+               --options gzip:compression-level=1 \
+               sbin bin usr/sbin usr/bin usr/lib usr/libexec
+.endif
+.endif
 
+backup-auto-clean:
+       rm -f ${AUTO_BACKUP}/binaries.tar.gz
+
+backup-clean:
+       rm -f ${WORLD_BACKUP}/binaries.tar.gz
+
+restoreworld:
+.if !exists(${WORLD_BACKUP}/binaries.tar.gz)
+       @echo "There does not seem to be a valid archive present."
+.else
+       @echo "Restoring system binaries from manual backup archive..."
+       @chflags -R noschg ${DESTDIR}/sbin ${DESTDIR}/bin \
+               ${DESTDIR}/usr/sbin ${DESTDIR}/usr/bin \
+               ${DESTDIR}/usr/lib ${DESTDIR}/usr/libexec
+       tar -xzf ${WORLD_BACKUP}/binaries.tar.gz -C ${DESTDIR}/
+.endif
+
+restoreworld-auto:
+.if !exists(${AUTO_BACKUP}/binaries.tar.gz)
+       @echo "There does not seem to be a valid archive present."
+.else
+       @echo "Restoring system binaries from auto-backup archive..."
+       @chflags -R noschg ${DESTDIR}/sbin ${DESTDIR}/bin \
+               ${DESTDIR}/usr/sbin ${DESTDIR}/usr/bin \
+               ${DESTDIR}/usr/lib ${DESTDIR}/usr/libexec
+       tar -xzf ${AUTO_BACKUP}/binaries.tar.gz -C ${DESTDIR}/
+.endif
+
+# Take advantage of bmake error response
+#
+MAKE_PRINT_VAR_ON_ERROR= \
+       .CURDIR \
+       .OBJDIR \
+       LD_LIBRARY_PATH \
+       MACHINE_ARCH \
+       MACHINE \
+       MAKEFILE \
+       .TARGETS \
+       .ERROR_TARGET \
+       .MAKE.LEVEL
+
+.include <bsd.subdir.mk>