Subject: Re: q3test + riva tnt working..
To: None <port-i386@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: port-i386
Date: 06/05/1999 15:33:17
In article <19990604222721.E434@acheron.middleboro.ma.us> mason@acheron.middleboro.ma.us (Mason Loring Bliss) writes:
>On Thu, Jun 03, 1999 at 03:08:04AM -0400, Andrew Gillham wrote:
>
>> I have a native 'glx.so' running on my NetBSD/i386 ELF system right now. 
>
>How would one go about building an ELF-based system? Does the kernel and
>userland build in ELF? I don't know much about ELF, but I'm curious. The
>only relevant thing I can find is this, in /usr/share/mk/bsd.README:

make sure that you are running a kernel with COMPAT_AOUT first...

You can try something like the following:

#!/bin/sh
#
# Copyright (c) 1999 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Christos Zoulas.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#        This product includes software developed by the NetBSD
#        Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

VERSION=1.4
FREESPACE=10000
EMDIR=/emul/aout/.
LIB="lib*.so.*"
LIBEXEC="cc1 cc1obj cc1plus collect2 cpp f771 ld.so"
BIN="ar as c89 cc cpp nm g++ g77 gcc ld strip"
DIRECTORIES="usr/lib usr/libexec usr/bin"
MKCONF=/etc/mk.conf
GNU=/usr/src/gnu

bail()
{
    echo "$0: *ERROR*: $@" 1>&2
    exit 1
}

nospace()
{
    bail "$EMDIR has only ${1}K free and I need ${FREESPACE}K"
}

noaout()
{
    bail "Please create $EMDIR with at least ${FREESPACE}K free"
}

badcopy() 
{
    bail "An error occured while copying [exit $1]"
}

nodirectory() 
{
    bail "Cannot make directory $1"
}

bademul()
{
    bail "You kernel does not appear to search in $EMDIR" 
}

badkernel()
{
    bail "You kernel does not appear to support COMPAT_AOUT" 
}

baddotdot()
{
    bail "You kernel does not appear to support '/../' in COMPAT_AOUT" 
}

notroot()
{
    bail "This program needs to be run as root"
}

makefailed()
{
    bail "Make had errors"
}

copy()
{
    echo -n "$0: Copying from $1..."
    eval cd $1 && tar -czf - $2 | (cd $EMDIR/new/$1 && tar -xzpf -)
    if [ $? != 0 ]; then
	badcopy $?
    else
	echo "done"
    fi
}

makeone()
{
    make $1 > /dev/null
    if [ $? != 0 ]
    then
	makefailed
    fi
}

makeme()
{
    cd $1
    echo -n "$0: running make in $1: cleaning..."
    makeone clean
    echo -n "depending..."
    makeone depend
    echo -n "including..."
    makeone includes
    echo -n "building..."
    makeone 
    echo "done"
}

getobjfmt()
{
    printf '.include "'$MKCONF'"\nall:\n\t@echo $(OBJECT_FMT)\n' | make -f -
}

uid=`id -u`
if [ $uid != 0 ]; then
    notroot
fi

if [ -d $EMDIR ]; then
    echo "$0: Cool, you have $EMDIR already made for me"
else
    noaout
fi

space=`df -k $EMDIR | grep -v Filesystem | awk '{ print $4 }'`

if [ $space -lt $FREESPACE ]; then
    nospace $space 
else
    echo "$0: And it has ${space}K free"
fi

echo "$0: Lemme make a copy of your shared libraries, and compiler tools"

echo "$0: Making directories"
for i in $DIRECTORIES
do
    mkdir -p $EMDIR/new/$i
    if [ $? != 0 ]; then
	nodirectory $EMDIR/new/$i
    fi
done

copy /usr/lib "$LIB"
copy /usr/libexec "$LIBEXEC"
copy /usr/bin "$BIN"

echo "$0: Making sure that your a.out emulation works properly."

cd $EMDIR && mv new/usr .	# enable emulation paths
cd /usr/lib; DIR=`pwd`
if [ $DIR = "/usr/lib" ]; then
    cd $EMDIR && mv usr new	# disable emulation paths
    bademul
fi
cd /../usr/lib; DIR=`pwd`
if [ $DIR != "/usr/lib" ]; then
    cd $EMDIR && mv usr new	# disable emulation paths
    baddotdot
fi

cd /../usr/libexec
mv ld.so ld.so.save
/usr/bin/who 1>&2 2> /dev/null
if [ $? != 0 ]; then
    mv ld.so.save ld.so
    cd $EMDIR && mv usr new	# disable emulation paths
    badkernel
fi

# Setup destdir so that it references the real root.
DESTDIR=/..
export DESTDIR

OBJECT_FMT=`getobjfmt`

if [ "$OBJECT_FMT" = "ELF" ]; then
    echo "$0: Removing OBJECT_FMT=ELF from $MKCONF"
    grep -v OBJECT_FMT $MKCONF > $MKCONF.new && mv $MKCONF.new $MKCONF
else
    echo "$0: Ok, there is no OBJECT_FMT statement in your $MKCONF"
fi

echo "$0: Now I am going to try to build the compiler tools"

echo "$0: Making sure that libbfd is up-to-date"
makeme $GNU/lib/libbfd

echo "$0: Making sure that the common binutils code is up-to-date"
makeme $GNU/usr.bin/binutils/common

if [ "$OBJECT_FMT" != "ELF" ]; then
    echo "$0: Adding OBJECT_FMT=ELF to $MKCONF"
    echo "OBJECT_FMT=ELF" >> $MKCONF
else
    echo "$0: Cool, you already have set OBJECT_FMT=ELF in your $MKCONF"
fi

echo "$0: Making fake crtbegin.o and crtend.o in /usr/lib"
cd / && cd usr && cd lib
for i in crtbegin.o crtbeginS.o crtend.o crtendS.o; do
    touch $i
done

for i in binutils/nm binutils/strip binutils/ar ld.new gas.new; do
    makeme $GNU/usr.bin/$i
done

for i in binutils/nm binutils/strip binutils/ar ld.new gas.new; do
    cd $GNU/usr.bin/$i
    makeone install
done

echo "$0: We are all done. We have installed the new compile tools"
echo "$0: and now you can make build and end up with an elf system"
echo "$0: Remember to set DESTDIR=/.. in your makes; Good luck"