Subject: Re: building the X stuff
To: Paul (NCC/CS). <pts@bom.gov.au>
From: Greg Troxel <gdt@ir.bbn.com>
List: port-sparc64
Date: 09/23/2005 13:10:24
  & how do I install this X now once X is built?

Note that 'build.sh -x' builds the whole system including X, not just
X.  So you certainly could have build with x from the beginning.  I
just built a current sparc64 install cd on a 2.99.15 i386 box.

  Should I have built X before I ran the main install?

You don't need to if you don't mind not having X.  Just build with
build.sh -x  and then install, which will reinstall the base system,
but that's almost certainly ok.

You may want to use '-u' to avoid the implicit 'make clean' in
build.sh.

The following script is hairier than you need, but is a reasonable
commented example.  I like to have a script to set
{OBJ,RELEASE,DEST,TOOL}DIR consistently; it can cause problems to
change them around.

#!/bin/sh
# -*- shell-script -*-
# $Id: BUILD-current,v 1.11 2005/08/31 23:39:56 gdt Exp $

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

SRCFILE=src/sys/arch/i386/conf/GENERIC
X11SRCFILE=xfree/xc/RELNOTES.txt

# Check a source file to verify that we (probably) have a source tree.
if [ ! -f $SRCFILE ]; then
    echo "$SRCFILE not present"
    exit 1
fi

## Find branch for use in OBJDIR etc.

# Check that the source tree is from CVS.
# XXX For trees not in CVS, find branch somehow.
SRCDIR=src
if [ ! -d $SRCDIR/CVS ]; then
    echo "$SRCDIR/CVS" not present
    exit 1
fi
# Look at src, and see what branch it's on
if [ -f src/CVS/Tag ]; then
    cvstag=`cat src/CVS/Tag`
else
    cvstag='Tcurrent'
fi
# Set token for directory name based on branch.
case "$cvstag" in
    Tcurrent)
	branch=current
	;;
    Tnetbsd-3)
    	branch=3
	;;
    Tnetbsd-2)
    	X11SRCFILE=xfree/xc/RELNOTES
    	branch=2
	;;
    Tnetbsd-2-0)
    	X11SRCFILE=xfree/xc/RELNOTES
    	branch=2-0
	;;
    # netbsd-1-6 builds differently
    *)
    	echo "UNKNOWN BRANCH $progname"
	exit 1
	;;
esac
echo "Building with branch token $branch"

# 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
    # Check that X11 sources are present.
    if [ ! -f $X11SRCDIR/$X11SRCFILE ]; then
	echo "$X11SRCFILE not present."
	exit 1
    fi
else
    xflag=""
fi

# Parse fixed arguments.
cmd=$1
arch=$2

# Make first-cut decision about UNPRIV (UNPRIV if non-root)
if [ 0 != `id -u` ]; then
  echo "Not ROOT: doing UNPRIVed build"
  pflag="-U"
else
  pflag=""
fi

# Function to check for root at install time, and set -U if build
# was done UNPRIVed.
installrootcheck () {
    if [ 0 != `id -u` ]; then
	echo "MUST BE ROOT TO INSTALL"
	exit 1
    fi
    if [ -f $DESTDIR/METALOG ]; then
	echo "INSTALL with METALOG: doing UNPRIVed install"
	pflag="-U"
    else
	echo "INSTALL without METALOG: not setting UNPRIVed"
	pflag=""
    fi
}

# Set 'update' flag to avoid make clean. This is possibly dangerous.
# Remove uflag, or nuke /usr/obj if problematic.
uflag="-u"

## Compute and set build.sh environment variables.

# determine arch (do a self-hosted build if not given)
if [ "$arch" = "" ]; then
  arch=`uname -m`
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-$branch

# Put tools within base (not dependent on $arch).  Put tools bin in PATH
# so we can run nbmake-$arch later.
export TOOLDIR=$BUILDBASE/tools; export TOOLDIR
TOOLSBIN=$TOOLDIR/bin

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

# Place all destdirs together, separated by architecture.
export DESTDIR=$BUILDBASE/destdir/$arch

# Releasedir has $arch subdirs by default, so omit implied "/$arch".
export RELEASEDIR=$BUILDBASE/releasedir

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!"
    ;;
    all)
    # This means distribution, release, iso.
    target=release
    echo "ALL: doing full build to iso"
    ;;
    install)
    target="install=/"
    installrootcheck
    echo "INSTALL: ASSUMING DISTRIBUTION ALREADY COMPLETE!"
    ;;
    *)
    echo "Usage: ./BUILD-current [-x] [distribution|release|iso|install]"
    ;;
esac

# 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 database - 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

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

# For some commands, do extra precmds.
case $cmd in
    install)
    # install kernel
    (cd $OBJDIR/sys/arch/$arch/compile/$kern && make DESTDIR=/ install)
    # perhaps install gzipped kernels for GRUB/XEN
    for k in `(cd / &&
        ls netbsd-*.gz |
	egrep 'netbsd-[A-Z0-9_]*.gz' |
	sed 's/netbsd-\([A-Z0-9_]*\).gz/\1/')`; do
      echo "COPYING gzipped KERNEL $k"
      cp -pf /netbsd-$k.gz /netbsd-$k.ok.gz
      cp -pf $RELEASEDIR/$arch/binary/kernel/netbsd-$k.gz /
    done
    ;;
esac

# 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 $pflag \
	-O $OBJDIR -T $TOOLDIR -D $DESTDIR -R $RELEASEDIR \
	-X $X11SRCDIR \
	$target) || exit 1
    echo -n "BUILDALL MAIN $target finish "; date
fi

# For some commands, do extra postcmds.
case $cmd in
    distribution|all)
    echo -n "BUILDALL KERNEL start $kern for $arch "; date
    (cd src && ./build.sh -m $arch $xflag $uflag $pflag \
	-O $OBJDIR -T $TOOLDIR -D $DESTDIR -R $RELEASEDIR \
	-X $X11SRCDIR \
	kernel=$kern) || exit 1
    echo -n "BUILDALL KERNEL finish $kern for $arch "; date
    ;;

    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

# Perhaps build an iso image.  (Separate from above because cmd=all
# must build a custom kernel and an iso image.)
case $cmd in
    iso|all)
    (cd src/etc && $TOOLDIR/bin/nbmake-$arch iso-image)
    ;;
esac


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