Subject: Re: build just /usr/bin/iconv
To: None <netbsd-help@NetBSD.org>
From: Greg Troxel <gdt@ir.bbn.com>
List: netbsd-help
Date: 04/25/2005 08:56:11
"James K. Lowden" <jklowden@schemamania.org> writes:

> Basically, you told me if I want to build -current, I have to run
> -current.  OK, well, I've been meaning to start tracking current
> anyway....  

Not at all.  You can build current on 2.0 just fine (if not it's a
bug).  Just don't install userland parts of it to / without having
installed and booted a current kernel.  You should feel free to chroot
into the destdir to test code, with the caveat that you'll lose if new
kernel features are required.

> I have another box here, a Sun Ultra-5, with, um, 1.6 installed on it. 
> The CVS tree is on a (much faster) i386.  I guess the shortest distance
> between two points is to cross-build the Sparc kernel, install it, boot
> it, copy over the tree, build the tools, build and install userland.  Did
> I miss anything?  

IMHO the shortest way is to do a full cross build on i386, making an
iso image, and then binary upgrade the sparc-5 with it (cd, netboot).
('release' target to build.sh with -m sparc64, or -m sparc if you are
running 32-bit on the u5, and then cd to src/etc and nbmake-sparc64
iso-image'.  You need cdrecord or cdrtools-ossdvd installed to get
mkisofs.)

This is particularly true because 1.6 on sparc64 is not particularly
stable; there are critical fixes in 2.0.2 and -current.


I use the following script, which makes things look much more
complicated than they really are.  It doesn't support other arch's,
but see arch= and munge.  Part of the complexity is enabling doing
some steps, and later doing others without redoing the first ones.

You'll want to remove the etcmanage lines.  The script installs
userland first, and then the kernel.  This is ok when moving only a
bit along a stable branch.  It's of course irrelevant if you don't
install.


#!/bin/sh
# -*- shell-script -*-

## This script supports automatic building and installing of NetBSD
## along the 2 and 2.x branches (netbsd-2, netbsd-2-0, etc.).  It
## assumes that it is run as ./BUILD-2-0, and that src and xsrc are
## present in the current directory, checked out with matching tags.

## XXX This should be called BUILD-2.  The next script should be
## called BUILD-3.

if [ 0 != `id -u` ]; then
  echo "MUST BE ROOT TO RUN NETBSD BUILDALL"
  exit 1
fi

# This is possibly dangerous.  Remove uflag, or nuke /usr/obj if
# problematic.
uflag="-u"

# XXX Check for src

# Use xsrc next to src, to enable cross builds.
X11SRCDIR=`/bin/pwd`/xsrc

# Build X if -x flag is given.
if [ "$1" = "-x" ]; then
    xflag="-x"
    shift
    # XXX check for xsrc
else
    xflag=""
fi

cmd=$1
if [ "$cmd" = "" ]; then
    cmd=distribution
fi
case "$cmd" in
    distribution|build)
    cmd=distribution
    target=distribution
    ;;
    release)
    target=release
    export BUILD_DONE=t
    echo "RELEASE: ASSUMING DISTRIBUTION ALREADY COMPLETE!"
    ;;
    iso)
    target=none
    echo "ISO: ASSUMING DISTRIBUTION AND RELEASE ALREADY COMPLETE!"
    ;;
    install)
    target="install=/"
    echo "INSTALL: ASSUMING DISTRIBUTION ALREADY COMPLETE!"
    ;;
    *)
    echo "Usage: ./BUILD-2-0 [-x] [distribution|release|iso|install]"
    ;;
esac

# determine arch (do a self-hosted build)
arch=`uname -m`

# find hostname and short version
hostname=`hostname`
host=`hostname | awk -F. '{print $1}'`

# look up kernel config in database
if [ -f hostname-kernel ]; then
  kern=`egrep $hostname hostname-kernel | awk '{print $2}'`
else
  # No databse - same as not found in database
  kern=""
fi

# if found, check for existence
if [ "$kern" != "" -a ! -f src/sys/arch/$arch/conf/$kern ]; then
  echo "CANNOT FIND KERNEL CONFIG src/sys/arch/$arch/conf/$kern!"
  exit 1
fi

# if not found, look for config named by hostname (but upper case)
hostuc=`echo $host | tr '[a-z]' '[A-Z]'`
if [ "$kern" = "" -a -f src/sys/arch/$arch/conf/$hostuc ]; then
    kern=$hostuc
fi

# Otherwise, use GENERIC.
if [ "$kern" = "" ]; then
    kern=GENERIC
fi

# Avoid conflict with builds of other branches.  Do not export, since
# if "BASE" that breaks src/sys/arch/i386/stand/biosboot.
BUILDBASE=/usr/obj/auto-2-0

# Set OBJDIR to be unique for this script and architecture.
export OBJDIR=$BUILDBASE/$arch

# Put tools near our obj tree.
export TOOLDIR=$BUILDBASE/tools; export TOOLDIR
TOOLSBIN=$TOOLDIR/bin

# Set up per-arch destdir.
export DESTDIR=$BUILDBASE/$arch/destdir

# Releasedir has $arch within it, so stay one level up.
export RELEASEDIR=$BUILDBASE/releasedir

case $target in
    distribution)
    # build tools
    echo -n "BUILDALL TOOLS start "; date
    (cd src && ./build.sh -O $OBJDIR -T $TOOLDIR $uflag tools || exit 1)
    echo -n "BUILDALL TOOLS finish "; date
    ;;

    *)
    echo "ASSUMING TOOLS ALREADY BUILT"
    ;;
esac

# Put tools in path
PATH=$TOOLSBIN:$PATH

# Run main target - distribution or release.
if [ "$target" != "none" ]; then
    echo -n "BUILDALL MAIN $target start "; date
    (cd src && ./build.sh -m $arch $xflag $uflag \
	-O $OBJDIR -T $TOOLDIR -D $DESTDIR -R $RELEASEDIR \
	-X $X11SRCDIR \
	$target || exit 1)
    echo -n "BUILDALL MAIN $target finish "; date
fi

# Do extra or sole processing for this command.
case $cmd in
    distribution)
    echo -n "BUILDALL KERNEL start $kern for $arch "; date
    (cd src && ./build.sh -m $arch $xflag $uflag \
	-O $OBJDIR -T $TOOLDIR -D $DESTDIR -R $RELEASEDIR \
	-X $X11SRCDIR \
	kernel=$kern || exit 1)
    echo -n "BUILDALL KERNEL finish $kern for $arch "; date
    ;;

    release)
    ;;

    iso)
    (cd src/etc && $TOOLDIR/bin/nbmake-$arch iso-image)
    ;;

    install)
    # install kernel
    (cd $OBJDIR/sys/arch/$arch/compile/$kern && make DESTDIR=/ install)
    # run etcmanage
    for step in 0 1 2 3 4 5 6 7 8 9; do
	echo BUILDALL: etcmanage: $step
	[ -f $DESTDIR/etc/defaults/rc.conf ] && \
	    etcmanage --update $DESTDIR
    done
    ;;

esac

-- 
        Greg Troxel <gdt@ir.bbn.com>