nrelease: kernel moved to boot, make kernel.BOOTP there
[dragonfly.git] / nrelease / Makefile
index 08538b8..60c673d 100644 (file)
@@ -1,42 +1,15 @@
-# $DragonFly: src/nrelease/Makefile,v 1.81 2008/06/29 10:23:23 corecode Exp $
+# $DragonFly: src/nrelease/Makefile,v 1.90 2008/09/01 21:20:30 swildner Exp $
 #
 
 #########################################################################
 #                              ENHANCEMENTS                            #
 #########################################################################
 
-# These targets are now obsolete and should not be used 
-#
-installer_release: warning release
-installer_quickrel: warning quickrel
-installer_realquickrel: warning realquickrel
-installer_fetch: warning fetch
-
-.if make(installer_release) || make(installer_quickrel) || make(installer_realquickrel) || make(installer_fetch)
-WITH_INSTALLER=
-WITH_LOCAL_INSTALLER=
-.endif
-
-# New method e.g. 'make installer fetch'.  A series of enhancement
+# New method e.g. 'make gui release'.  A series of enhancement
 # targes may be specified which set make variables which enhance
 # the build in various ways.
 #
-gui installer:
-
-warning:
-       @echo "WARNING: The installer_* targets are now obsolete, please"
-       @echo "use 'make installer blah' instead of 'make installer_blah'"
-       @echo ""
-       @echo "will continue in 10 seconds"
-       @sleep 10
-
-.if make(gui)
-WITH_GUI=
-.endif
-.if make(installer)
-WITH_INSTALLER=
-WITH_LOCAL_INSTALLER=
-.endif
+gui installer img:
 
 #########################################################################
 #                               SETUP                                  #
@@ -45,7 +18,12 @@ WITH_LOCAL_INSTALLER=
 ISODIR ?= /usr/release
 ISOROOT ?= ${ISODIR}/root
 OBJSYS= ${.OBJDIR}/../sys
+
+.if make(gui)
+KERNCONF ?= DFLYLIVE VKERNEL DFLYLIVE-SMP DFLYLIVE-SMP-NOAPIC
+.else
 KERNCONF ?= GENERIC VKERNEL
+.endif
 
 PKGSRC_PREFIX?=                /usr/pkg
 PKGBIN_PKG_ADD?=       ${PKGSRC_PREFIX}/sbin/pkg_add
@@ -55,135 +33,190 @@ PKGBIN_MKISOFS?=  ${PKGSRC_PREFIX}/bin/mkisofs
 PKGSRC_PKG_PATH?=      ${ISODIR}/packages
 PKGSRC_DB?=            /var/db/pkg
 PKGSRC_BOOTSTRAP_URL?= http://pkgbox.dragonflybsd.org/DragonFly-pkgsrc-packages/i386/1.12.0-RELEASE-BUILD
+CVSUP_BOOTSTRAP_KIT?=  cvsup-bootstrap-20070716
 
-ENVCMD?=       env
-TAR?=  tar
+# We use env -i in the chroot, so that environment variables won't
+# disturb any (pkgsrc) build.  This has happened for TARGET_ARCH,
+# which is used by gmake in completely different context.
+#
+CHROOT_CMD?=           env -i CCVER=${CCVER:Q} /usr/sbin/chroot ${ISOROOT} sh -c
 
-PKGSRC_CDRECORD?=      cdrtools-ossdvd-2.01.1.36nb2.tgz
-PKGSRC_BOOTSTRAP_KIT?= bootstrap-kit-20080211
-CVSUP_BOOTSTRAP_KIT?=  cvsup-bootstrap-20070716
+# User may specify extra packages in addition to the defaults
+#
+PKGSRC_EXTRA_PACKAGES?=
 
-# Default packages to be installed on the release ISO.
+# Pkgsrc packages to be built and installed on the release ISO
 #
-PKGSRC_PACKAGES?=      cdrtools-ossdvd-2.01.1.36nb2.tgz
+PKGSRC_PACKAGES?=      pkgtools/pkg_leaves \
+                       pkgtools/pkg_tarup \
+                       devel/scmgit \
+                       net/isc-dhcp4 \
+                       net/isc-dhcpd4 \
+                       sysutils/cdrtools \
+                       ${PKGSRC_EXTRA_PACKAGES}
+
+# pkgsrc options to use when building packages
+#
+.if !make(gui)
+PKGSRC_OPTIONS?=       PKG_OPTIONS.scmgit=-scmgit-gui
+.endif
 
 # Even though buildiso wipes the packages, our check target has to run
 # first and old packages (listed as they appear in pkg_info) must be
 # cleaned out in order for the pkg_add -n test we use in the check target
 # to operate properly.
 #
-OLD_PKGSRC_PACKAGES?= cdrtools-2.01.01.27nb1 cdrecord-2.00.3nb2 \
-                     bootstrap-kit-20070205
+OLD_PKGSRC_PACKAGES?=  cdrtools-2.01.01.27nb1 \
+                       cdrecord-2.00.3nb2 \
+                       bootstrap-kit-20070205 \
+                       dfuibe_installer-1.1.6 \
+                       gettext-lib-0.14.5 \
+                       dfuibe_installer-1.1.7nb1 \
+                       dfuife_curses-1.5 \
+                       gettext-lib-0.14.6 \
+                       gettext-tools-0.14.6nb1 \
+                       libaura-3.1 \
+                       libdfui-4.2 \
+                       libinstaller-5.1 \
+                       bootstrap-kit-20080211 \
+                       cdrtools-ossdvd-2.01.1.36nb2 \
+                       isc-dhcp-base-4.0.0 \
+                       isc-dhcp-server-4.0.0
 
 # Specify which root skeletons are required, and let the user include
-# their own.  They are copied into ISODIR during the `pkgcustomizeiso'
+# their own.  They are copied into ISODIR during the `customizeiso'
 # target; each overwrites the last.
 #
-REQ_ROOTSKELS= ${.CURDIR}/root
+REQ_ROOTSKELS= ${.CURDIR}/root \
+               ${.CURDIR}/installer
 ROOTSKELS?=    ${REQ_ROOTSKELS}
 
-.if defined(WITH_GUI)
+.if make(gui)
 ISOFILE?=              ${ISODIR}/dfly-gui.iso
-PKGSRC_PACKAGES+=      modular-xorg-apps \
-                       modular-xorg-drivers \
-                       modular-xorg-fonts \
-                       modular-xorg-libs \
-                       fluxbox
+IMGFILE?=              ${ISODIR}/dfly-gui.img
+PKGSRC_PACKAGES+=      meta-pkgs/modular-xorg-apps \
+                       meta-pkgs/modular-xorg-drivers \
+                       meta-pkgs/modular-xorg-fonts \
+                       meta-pkgs/modular-xorg-libs \
+                       wm/fluxbox \
+                       wm/fvwm \
+                       www/firefox3 \
+                       print/xpdf \
+                       shells/zsh \
+                       editors/emacs \
+                       editors/vim \
+                       chat/pidgin \
+                       chat/irssi \
+                       chat/xchat \
+                       x11/modular-xorg-server \
+                       x11/rxvt-unicode \
+                       x11/eterm \
+                       lang/perl5 \
+                       editors/nano \
+                       shells/bash \
+                       devel/exctags \
+                       archivers/zip \
+                       security/sudo \
+                       www/links-gui \
+                       net/nmap \
+                       net/wget \
+                       fonts/terminus-font \
+                       net/rsync \
+                       sysutils/idesk \
+                       time/asclock \
+                       misc/screen
 ROOTSKELS+=            ${.CURDIR}/gui
 .endif
 
-.if defined(WITH_INSTALLER) || defined(WITH_LOCAL_INSTALLER)
-.if !defined(WITH_LOCAL_INSTALLER)
-# note: the old dfuibe_install and curses depend on the old gettext and
-# must be removed for the old gettext to be removed.  The new dfuibe install
-# and curses are named the same as the old.
-#
-OLD_PKGSRC_PACKAGES+=  dfuibe_installer-1.1.6 gettext-lib-0.14.5 \
-#                      dfuibe_installer-1.1.7nb1 dfuife_curses-1.5
-PKGSRC_PACKAGES+=      dfuibe_installer-1.1.7nb1.tgz dfuife_curses-1.5.tgz
-PKGSRC_PACKAGES+=      gettext-lib-0.14.6.tgz gettext-tools-0.14.6nb1.tgz
-PKGSRC_PACKAGES+=      libaura-3.1.tgz libdfui-4.2.tgz libinstaller-5.1.tgz
-.endif
-ROOTSKELS+=            ${.CURDIR}/installer
-.endif
-
 ISOFILE ?= ${ISODIR}/dfly.iso
+IMGFILE ?= ${ISODIR}/dfly.img
+
+IMGMNT ?= ${ISODIR}/mnt
+IMGUSBDEV ?= /dev/da0
 
 # note: we use the '${NRLOBJDIR}/nrelease' construct, that is we add
 # the additional '/nrelease' manually, as a safety measure.
 #
 NRLOBJDIR?= /usr/obj
 
-WORLD_CCVER ?= ${CCVER}
-KERNEL_CCVER ?= ${CCVER}
-
 #########################################################################
 #                              BASE ISO TARGETS                        #
 #########################################################################
 
-release:       localinstaller check clean buildworld1 buildkernel1 \
-               buildiso syssrcs customizeiso mklocatedb mkiso
+release:       check clean buildworld1 buildkernel1 \
+               buildiso srcs customizeiso mkaliases mklocatedb \
+               mkiso mkimg
+
+quickrel:      check clean buildworld2 buildkernel2 \
+               buildiso srcs customizeiso mkaliases mklocatedb \
+               mkiso mkimg
 
-quickrel:      localinstaller check clean buildworld2 buildkernel2 \
-               buildiso syssrcs customizeiso mklocatedb mkiso
+realquickrel:  check clean buildiso srcs customizeiso \
+               mkaliases mklocatedb \
+               mkiso mkimg
 
-realquickrel:  localinstaller check clean buildiso syssrcs customizeiso mklocatedb mkiso
+restartpkgs:   check customizeiso mkaliases mklocatedb mkiso mkimg
 
 quick:         quickrel
 
 realquick:     realquickrel
 
+
 #########################################################################
 #                         CORE SUPPORT TARGETS                         #
 #########################################################################
-localinstaller:
-.if defined(WITH_LOCAL_INSTALLER)
-       cd ${.CURDIR}/../usr.sbin/installer; make       
-.endif
 
 check:
-.if !exists(${PKGBIN_PKG_ADD})
-       @echo "Unable to find ${PKGBIN_PKG_ADD}.  You can use the following"
-       @echo "command to bootstrap pkgsrc:"
+.if !exists(${PKGBIN_PKG_ADMIN})
+       @echo "You never bootstrapped pkgsrc on your machine.  You can install it with:"
        @echo "    make pkgsrc_bootstrap"
-       @exit 1
 .endif
-.for PKG in ${OLD_PKGSRC_PACKAGES}
-       @${ENVCMD} PKG_PATH=${PKGSRC_PKG_PATH} ${PKGBIN_PKG_DELETE} -K ${ISOROOT}${PKGSRC_DB} ${PKG} > /dev/null 2>&1 || exit 0
-.endfor
-.for PKG in ${PKGSRC_PACKAGES}
-       @${ENVCMD} PKG_PATH=${PKGSRC_PKG_PATH} ${PKGBIN_PKG_ADD} -K ${ISOROOT}${PKGSRC_DB} -n ${PKG} > /dev/null 2>&1 || \
-               (echo "Unable to find ${PKG}, use the following command to fetch required packages:"; echo "    make [installer] fetch"; exit 1)
-.endfor
-.if !exists(${PKGBIN_MKISOFS})
-       @echo "mkisofs is not installed.  It is part of the cdrecord package."
-       @echo "You can install it with:"
+.if !exists(${PKGSRC_PKG_PATH}/${CVSUP_BOOTSTRAP_KIT}.tgz)
+       @echo "The cvsup bootstrap kit is not installed.  You can install it with:"
+       @echo "    make fetch"
+.endif
+.if !exists (${PKGBIN_MKISOFS})
+       @echo
+       @echo "Your machine does not have cdrtools installed.  You can install it with:"
        @echo "    make pkgsrc_cdrecord"
+.endif
+.if !defined(PKGSRC_PATH)
+       @echo "Please set PKGSRC_PATH to the pkgsrc tree that shall be used for"
+       @echo "package building.  For example /usr/pkgsrc.  See the Makefile"
+       @echo "in /usr if you are unfamiliar with pkgsrc."
+.endif
+.if !exists(${PKGSRC_PKG_PATH}/${CVSUP_BOOTSTRAP_KIT}.tgz)
        @exit 1
 .endif
-.if !exists(${PKGSRC_PKG_PATH}/${PKGSRC_BOOTSTRAP_KIT}.tgz)
-       @echo "The pkgsrc bootstrap kit is not installed.  You can install it with:"
-       @echo "    make [installer] fetch"
+.if !exists (${PKGBIN_MKISOFS})
        @exit 1
 .endif
-.if !exists(${PKGSRC_PKG_PATH}/${CVSUP_BOOTSTRAP_KIT}.tgz)
-       @echo "The cvsup bootstrap kit is not installed.  You can install it with:"
-       @echo "    make [installer] fetch"
+.if !defined(PKGSRC_PATH)
        @exit 1
 .endif
 
 buildworld1 buildworld2:
-       cd ${.CURDIR}/..; CCVER=${WORLD_CCVER} make ${.TARGET:C/build(.*)2/quick\1/:C/1//}
+       cd ${.CURDIR}/..; ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} make -DWANT_INSTALLER ${.TARGET:C/build(.*)2/quick\1/:C/1//}
 
 buildkernel1 buildkernel2:
+.if make(gui)
+       cd ${.CURDIR}/..; \
+       for kernconf in ${KERNCONF}; do \
+               ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
+               make ${.TARGET:C/build(.*)2/quick\1/:C/1//} \
+                       KERNCONF=$${kernconf} KERNCONFDIR=${.CURDIR}/gui/root; \
+       done
+.else
        cd ${.CURDIR}/..; \
        first=; \
        for kernconf in ${KERNCONF}; do \
-               CCVER=${KERNEL_CCVER} make ${.TARGET:C/build(.*)2/quick\1/:C/1//} \
+               ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
+               make ${.TARGET:C/build(.*)2/quick\1/:C/1//} \
                        KERNCONF=$${kernconf} \
                        $${first:+-DNO_MODULES}; \
                first=done; \
        done
+.endif
 
 # note that we do not want to mess with any /usr/obj directories not related
 # to buildworld, buildkernel, or nrelease, so we must supply the proper
@@ -193,15 +226,26 @@ buildkernel1 buildkernel2:
 buildiso:
        if [ ! -d ${ISOROOT} ]; then mkdir -p ${ISOROOT}; fi
        if [ ! -d ${NRLOBJDIR}/nrelease ]; then mkdir -p ${NRLOBJDIR}/nrelease; fi
-       ( cd ${.CURDIR}/..; make DESTDIR=${ISOROOT} installworld )
-.if defined(WITH_LOCAL_INSTALLER)
-       ( cd ${.CURDIR}/../usr.sbin/installer; make DESTDIR=${ISOROOT} install )
-       ( cd ${.CURDIR}/../share/installer; make DESTDIR=${ISOROOT} install )   
-.endif
+       ( cd ${.CURDIR}/..; make -DWANT_INSTALLER DESTDIR=${ISOROOT} installworld )
        ( cd ${.CURDIR}/../etc; MAKEOBJDIRPREFIX=${NRLOBJDIR}/nrelease \
                make -m ${.CURDIR}/../share/mk DESTDIR=${ISOROOT} distribution )
-       /usr/libexec/sendmail/sendmail -bi -O AliasFile=${ISOROOT}/etc/mail/aliases -O DontBlameSendmail=mapinunsafedirpath
        cpdup ${ISOROOT}/etc ${ISOROOT}/etc.hdd
+.if make(gui)
+       if [ ! -d ${ISOROOT}/kernel.smp/boot ]; then mkdir -p ${ISOROOT}/kernel.smp/boot; fi
+       cd ${.CURDIR}/..; \
+       make installkernel DESTDIR=${ISOROOT} \
+       KERNCONF=DFLYLIVE DESTKERNNAME=kernel KERNCONFDIR=${.CURDIR}/gui/root; \
+       cd ${.CURDIR}/..; \
+       make installkernel DESTDIR=${ISOROOT} \
+       KERNCONF=VKERNEL DESTKERNNAME=kernel.VKERNEL -DNO_MODULES KERNCONFDIR=${.CURDIR}/gui/root; \
+       cd ${.CURDIR}/..; \
+       make installkernel DESTDIR=${ISOROOT}/kernel.smp \
+       KERNCONF=DFLYLIVE-SMP DESTKERNNAME=kernel KERNCONFDIR=${.CURDIR}/gui/root; \
+       cd ${.CURDIR}/..; \
+       make installkernel DESTDIR=${ISOROOT}/kernel.smp \
+       KERNCONF=DFLYLIVE-SMP-NOAPIC DESTKERNNAME=kernel.noapic \
+               KERNCONFDIR=${.CURDIR}/gui/root -DNO_MODULES;
+.else
        cd ${.CURDIR}/..; \
        first=; \
        for kernconf in ${KERNCONF}; do \
@@ -211,30 +255,46 @@ buildiso:
                        $${first:+-DNO_MODULES}; \
                first=done; \
        done
-       ln -s kernel ${ISOROOT}/kernel.BOOTP
+.endif
+       ln -s kernel ${ISOROOT}/boot/kernel.BOOTP
        mtree -deU -f ${.CURDIR}/../etc/mtree/BSD.local.dist -p ${ISOROOT}/usr/local/
        mtree -deU -f ${.CURDIR}/../etc/mtree/BSD.var.dist -p ${ISOROOT}/var
        dev_mkdb -f ${ISOROOT}/var/run/dev.db ${ISOROOT}/dev
 
-# Include kernel sources on the release CD (~14MB)
+# Release CD: Kernel sources (~16M) and the full pkgsrc tree (~27M)
+# Release DVD: Full sources (~90M) and the full pkgsrc tree (~27M)
 #
-syssrcs:
+srcs:
 .if !defined(WITHOUT_SRCS)
-       ( cd ${.CURDIR}/../..; tar --exclude CVS -cf - src/Makefile src/Makefile.inc1 src/sys | bzip2 -9 > ${ISOROOT}/usr/src-sys.tar.bz2 )
+       rm -f ${ISOROOT}/usr/pkgsrc-all.tgz
+       cd ${PKGSRC_PATH} && tar --exclude distfiles --exclude packages --exclude work --exclude CVS --exclude .git \
+               -czf ${ISOROOT}/usr/pkgsrc-all.tgz .
+.if make(gui)
+       rm -f ${ISOROOT}/usr/src-all.tgz
+       cd ${.CURDIR}/../.. && tar --exclude .git --exclude CVS \
+               -czf ${ISOROOT}/usr/src-all.tgz src
+.else
+       rm -f ${ISOROOT}/usr/src-sys.tgz
+       cd ${.CURDIR}/../.. && tar --exclude .git --exclude CVS \
+               -czf ${ISOROOT}/usr/src-sys.tgz src/Makefile src/Makefile.inc1 src/sys
+.endif
 .endif
 
+# Customize the ISO by copying rootskels in reverse priority order,
+# building packages, and doing other post-install tasks.
+#
 customizeiso:
-       (cd ${PKGSRC_PKG_PATH}; tar xzpf ${CVSUP_BOOTSTRAP_KIT}.tgz)
+       # Copy the rootskels.  Allow sources to be owned by someone other
+       # then root (as is common when checked out via git).
+       #
 .for ROOTSKEL in ${ROOTSKELS}
        cpdup -X cpignore -o ${ROOTSKEL} ${ISOROOT}
+       @test -O ${.CURDIR} || echo "chowning copied files to root:wheel"
+       @test -O ${.CURDIR} || ((cd ${ROOTSKEL} && find .) | fgrep -v cpignore | (cd ${ISOROOT} && xargs chown root:wheel))
 .endfor
-       rm -rf ${ISOROOT}/tmp/bootstrap ${ISOROOT}/usr/obj/pkgsrc
-       cd ${ISOROOT}; tar xvzpf ${PKGSRC_PKG_PATH}/${PKGSRC_BOOTSTRAP_KIT}.tgz
+       (cd ${PKGSRC_PKG_PATH}; tar xzpf ${CVSUP_BOOTSTRAP_KIT}.tgz)
        cp -p ${PKGSRC_PKG_PATH}/${CVSUP_BOOTSTRAP_KIT}/usr/local/bin/cvsup ${ISOROOT}/usr/local/bin/cvsup
        cp -p ${PKGSRC_PKG_PATH}/${CVSUP_BOOTSTRAP_KIT}/usr/local/man/man1/cvsup.1 ${ISOROOT}/usr/local/man/man1/cvsup.1
-       rm -rf ${ISOROOT}/tmp/bootstrap ${ISOROOT}/usr/obj/pkgsrc
-       rm -rf `find ${ISOROOT} -type d -name CVS -print`
-       rm -rf ${ISOROOT}/usr/local/share/pristine
        pwd_mkdb -p -d ${ISOROOT}/etc ${ISOROOT}/etc/master.passwd
 .for UPGRADE_ITEM in Makefile                  \
                     etc.${MACHINE_ARCH}        \
@@ -247,21 +307,80 @@ customizeiso:
                     periodic/monthly/Makefile
        cp -R ${.CURDIR}/../etc/${UPGRADE_ITEM} ${ISOROOT}/etc/${UPGRADE_ITEM}
 .endfor
-       # There seems to be no reliable way to install a package to a target
-       # directory prefix so we mount_null our package directory into the
-       # ISO root and do the install chrooted.
+       #
+       # Setup some things & mount pkgsrc tree.  Use defensive umounts and
+       # rm -rf's to allow restarts.  Allow /usr/pkgsrc to be read-only.
+       #
+       # If we did not get past the bootstrap we clean out the entire
+       # /usr/pkg infrastructure.  Otherwise we attempt to pick up where
+       # we left off.
+       #
+       cp -p /etc/resolv.conf ${ISOROOT}/etc
+       ${CHROOT_CMD} "ldconfig -elf /usr/lib /usr/lib/gcc* /usr/lib/compat"
+       -@umount ${ISOROOT}/usr/pkgsrc/distfiles
+       -@umount ${ISOROOT}/usr/pkgsrc
+       mkdir -p ${ISODIR}/distfiles
+       rm -rf ${ISOROOT}/usr/pkgobj
+       #
+       # Mount /usr/pkgsrc, make sure /usr/pkgsrc/distfiles is writable
+       #
+       mkdir -p ${ISOROOT}/usr/pkgobj
+       mkdir -p ${ISOROOT}/usr/pkgobj/bootstrap/work
+       mkdir -p ${ISOROOT}/usr/pkgsrc
+       mount_null ${PKGSRC_PATH} ${ISOROOT}/usr/pkgsrc
+       cp /etc/shells ${ISOROOT}/usr/pkgsrc/distfiles/.test > /dev/null 2>&1 \
+           || mount_null ${ISODIR}/distfiles ${ISOROOT}/usr/pkgsrc/distfiles
+       #
+       # Bootstrap, if not already installed, and add licenses needed
+       # for the gui release
+       #
+       test -e ${ISODIR}/.didbootstrap || \
+           rm -rf ${ISOROOT}/usr/pkg ${ISOROOT}/var/db/pkg \
+                   ${ISOROOT}/var/db/pkg.refcount
+       test -e ${ISODIR}/.didbootstrap || \
+           ${CHROOT_CMD} "cd /usr/pkgsrc/bootstrap;    \
+               ./bootstrap --workdir /usr/pkgobj/bootstrap/work"
+       test -e ${ISODIR}/.didbootstrap || \
+           echo ".ifdef BSD_PKG_MK     # added by nrelease" \
+               >> ${ISOROOT}/usr/pkg/etc/mk.conf
+       test -e ${ISODIR}/.didbootstrap || \
+           echo "ACCEPTABLE_LICENSES+=openmotif-license" \
+               >> ${ISOROOT}/usr/pkg/etc/mk.conf
+       test -e ${ISODIR}/.didbootstrap || \
+           echo "ACCEPTABLE_LICENSES+=vim-license" \
+               >> ${ISOROOT}/usr/pkg/etc/mk.conf
+       test -e ${ISODIR}/.didbootstrap || \
+           echo ".endif                        # added by nrelease" \
+               >> ${ISOROOT}/usr/pkg/etc/mk.conf
+       test -e ${ISODIR}/.didbootstrap || sync
+       test -e ${ISODIR}/.didbootstrap || touch ${ISODIR}/.didbootstrap
+       #
+       # Build and install packages, skip packages already installed
        #
 .for PKG in ${PKGSRC_PACKAGES}
-       ${ENVCMD} PKG_PATH=${PKGSRC_PKG_PATH} ${PKGBIN_PKG_ADD} -K ${ISOROOT}${PKGSRC_DB} -I ${PKG}
-.endfor
-       find ${ISOROOT}${PKGSRC_DB} -name +CONTENTS -type f -exec sed -i '' -e 's,${ISOROOT},,' -- {} \;
-       ${PKGBIN_PKG_ADMIN} -K ${ISOROOT}${PKGSRC_DB} rebuild
-.if defined(WITH_GUI)
-.for FONT in 75dpi 100dpi misc Type1 TTF
-       chroot ${ISOROOT} /usr/pkg/bin/mkfontdir /usr/pkg/lib/X11/fonts/${FONT}
+       ${CHROOT_CMD} "cd /usr/pkgsrc/${PKG} && \
+           (bmake WRKOBJDIR=/usr/pkgobj check > /dev/null 2>&1 || \
+           bmake WRKOBJDIR=/usr/pkgobj ${PKGSRC_OPTIONS} clean build install)"
 .endfor
-.endif
+       #
+       # Remove packages which nothing depends on and clean up
+       #
+       ${CHROOT_CMD} "pkg_leaves | xargs pkg_delete -R"
+       -umount ${ISOROOT}/usr/pkgsrc/distfiles
+       umount ${ISOROOT}/usr/pkgsrc
+       rmdir ${ISOROOT}/usr/pkgsrc
+       rm -rf ${ISOROOT}/usr/pkgobj
+       rm -f ${ISOROOT}/etc/resolv.conf
+       makewhatis ${ISOROOT}/usr/local/man
+       makewhatis ${ISOROOT}/usr/pkg/man
+
+# So a CD boot does not complain about a missing aliases database
+#
+mkaliases:
+       ${CHROOT_CMD} "newaliases"
 
+# So locate works
+#
 mklocatedb:
        ( find -s ${ISOROOT} -path ${ISOROOT}/tmp -or \
                -path ${ISOROOT}/usr/tmp -or -path ${ISOROOT}/var/tmp \
@@ -271,52 +390,95 @@ mklocatedb:
 
 mkiso:
        ( cd ${ISOROOT}; ${PKGBIN_MKISOFS} -b boot/cdboot -no-emul-boot \
-               -R -J -V DragonFly -o ${ISOFILE} . )
+               -R -J -o ${ISOFILE} \
+               -V DragonFly-`${.CURDIR}/../tools/gitrev.sh | cut -c -22` . )
+
+
+mkimg:
+.if make(img)
+       if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
+
+       echo "determine required image size" > /dev/null;               \
+       sz=`du -ck ${ISOROOT} | tail -n 1 | cut -f 1`;                  \
+       echo "add 15% more space as required" > /dev/null;              \
+       sz=`bc -e "(($${sz}) / 1024) * 1.15" -equit | cut -f1 -d.`;     \
+       dd if=/dev/zero of=${IMGFILE} bs=1m count=$${sz};               \
+       fdisk -IB -p ${IMGFILE};                                        \
+       echo "determine free vn device" > /dev/null;                    \
+       vn=`vnconfig -l | grep "not in use" | head -n 1 | cut -f 1 -d:`; \
+       vnconfig -e -s labels $${vn} ${IMGFILE};                        \
+       echo "write standard disklabel" > /dev/null;                    \
+       disklabel -w -r $${vn}s1 auto;                                  \
+       echo "read disklabel back" > /dev/null;                         \
+       disklabel -r $${vn}s1 > ${IMGFILE}.label;                       \
+       echo "determine number of sectors of whole disk" > /dev/null;   \
+       secs=`tail -n 1 ${IMGFILE}.label | cut -f 3 -w`;                \
+       echo "and add a: partition" > /dev/null;                        \
+       echo "  a:  $${secs} 0 4.2BSD" >> ${IMGFILE}.label;             \
+       echo "write modified disklabel back" > /dev/null;               \
+       disklabel -R -r $${vn}s1 ${IMGFILE}.label;                      \
+       rm ${IMGFILE}.label;                                            \
+       echo "write bootsector" >  /dev/null;                           \
+       disklabel -B $${vn}s1;                                          \
+       newfs /dev/$${vn}s1a;                                           \
+       mount /dev/$${vn}s1a ${IMGMNT};                                 \
+       cpdup -vvv ${ISOROOT} ${IMGMNT};                                \
+       echo "fix /etc/fstab" > /dev/null;                              \
+       echo "${IMGUSBDEV}s1a / ufs rw 0 0" > ${IMGMNT}/etc/fstab;      \
+       echo "proc /proc procfs rw 0 0" >> ${IMGMNT}/etc/fstab;         \
+       df ${IMGMNT};                                                   \
+       umount ${IMGMNT};                                               \
+       vnconfig -u $${vn};                                             \
+       rmdir ${IMGMNT}
+.endif
 
 clean:
-       -umount ${ISOROOT}/tmp/packages
+       -umount ${ISOROOT}/usr/pkgsrc/distfiles > /dev/null 2>&1
+       -umount ${ISOROOT}/usr/pkgsrc > /dev/null 2>&1
        if [ -d ${ISOROOT} ]; then chflags -R noschg ${ISOROOT}; fi
-       if [ -d ${ISOROOT} ]; then rm -rf ${ISOROOT}/*; fi
-       if [ -d ${NRLOBJDIR}/nrelease ]; then rm -rf ${NRLOBJDIR}/nrelease; fi
+       rm -rf ${ISOROOT}
+       rm -rf ${NRLOBJDIR}/nrelease
+       rm -f ${ISODIR}/.didbootstrap
 
 realclean:     clean
        rm -rf ${OBJSYS}/${KERNCONF}
+       #
        # do not use PKGSRC_PKG_PATH here, we do not want to destroy an
        # override location.
-       if [ -d ${ISODIR}/packages ]; then rm -rf ${ISODIR}/packages; fi
+       #
+       rm -rf ${ISODIR}/packages
+       rm -rf ${ISODIR}/distfiles
 
 fetch:
        @if [ ! -d ${PKGSRC_PKG_PATH} ]; then mkdir -p ${PKGSRC_PKG_PATH}; fi
-.for PKG in ${PKGSRC_PACKAGES}
-       @${ENVCMD} PKG_PATH=${PKGSRC_PKG_PATH} ${PKGBIN_PKG_ADD} -K ${ISOROOT}${PKGSRC_DB} -n ${PKG} > /dev/null 2>&1 || \
-       (cd ${PKGSRC_PKG_PATH}; echo "Fetching ${PKGSRC_BOOTSTRAP_URL}/${PKG}"; fetch ${PKGSRC_BOOTSTRAP_URL}/${PKG})
-.endfor
-.if !exists(${PKGSRC_PKG_PATH}/${PKGSRC_BOOTSTRAP_KIT}.tgz)
-       (cd ${PKGSRC_PKG_PATH}; fetch ${PKGSRC_BOOTSTRAP_URL}/${PKGSRC_BOOTSTRAP_KIT}.tgz)
-.endif
 .if !exists(${PKGSRC_PKG_PATH}/${CVSUP_BOOTSTRAP_KIT}.tgz)
        (cd ${PKGSRC_PKG_PATH}; fetch ${PKGSRC_BOOTSTRAP_URL}/${CVSUP_BOOTSTRAP_KIT}.tgz)
 .endif
 
 pkgsrc_bootstrap:
-       mkdir -p ${PKGSRC_PKG_PATH}
 .if !exists(${PKGSRC_PKG_PATH}/${PKGSRC_BOOTSTRAP_KIT}.tgz)
-       (cd ${PKGSRC_PKG_PATH}; fetch ${PKGSRC_BOOTSTRAP_URL}/${PKGSRC_BOOTSTRAP_KIT}.tgz)
+       mkdir -p /usr/release/bootstrap
+       (cd ${PKGSRC_PATH}/bootstrap; ./bootstrap --workdir /usr/release/bootstrap)
 .endif
-       (cd ${PKGSRC_PKG_PATH}; tar xzpf ${PKGSRC_BOOTSTRAP_KIT}.tgz)
-       (cd ${PKGSRC_PKG_PATH}/${PKGSRC_BOOTSTRAP_KIT}/bootstrap; ./bootstrap)
 
 pkgsrc_cdrecord:
 .if !exists (${PKGBIN_MKISOFS})
-       ${PKGBIN_PKG_ADD} ${PKGSRC_PKG_PATH}/cdrtools*
+       (cd ${PKGSRC_PATH}/sysutils/cdrtools; bmake clean build install)
 .endif
 
+help all:
+       @echo "make [gui] release   - complete build from scratch"
+       @echo "make [gui] quick     - attempt to do an incremental rebuild"
+       @echo "make [gui] realquick - attempt to restart after world & kernel"
+       @echo "make [gui] restartpkgs - attempt to restart at the pkg building stage"
+       @echo ""
+       @echo "Extra packages may be specified with PKGSRC_EXTRA_PACKAGES"
 
-.PHONY: all release installer_release quickrel installer_quickrel realquickrel
-.PHONY: installer_fetch installer
+.PHONY: release quickrel realquickrel
+.PHONY: installer
 .PHONY: quick realquick
-.PHONY: installer_realquickrel check buildworld1 buildworld2
-.PHONY: buildkernel1 buildkernel2 buildiso customizeiso mklocatedb mkiso
-.PHONY: clean realclean fetch
+.PHONY: check buildworld1 buildworld2
+.PHONY: buildkernel1 buildkernel2 buildiso customizeiso mklocatedb mkiso mkimg
+.PHONY: clean realclean fetch help all mkaliases srcs
 
 .include <bsd.prog.mk>