#!/bin/sh
set -x

if test `uname` = Plan9; then
    export MYR_MUSE=`pwd`/muse/6.out
    export MYR_MC=`pwd`/6/6.out
    export MYR_RT=`pwd`/rt/_myrrt.6
else
    export MYR_MUSE=`pwd`/muse/muse
    export MYR_MC=`pwd`/6/6m
    export MYR_RT=`pwd`/rt/_myrrt.o
fi

# build without an obj/ dir, so we don't need to deal with
# creating the heirarchy for the compiler. mbld usually
# deals with that, but the bootstrap doesn't have it.
./mbldwrap.sh
cp obj/mbld/mbld xmbld
./xmbld -o '' clean

bootscript=mk/bootstrap/bootstrap+`uname -s`-`uname -m`.sh
echo '#!/bin/sh' > $bootscript
echo '# This script is generated by genbootstrap.sh' >> $bootscript
echo '# to regenerate, run "make bootstrap"' >> $bootscript
echo '#######################################'
echo 'pwd=`pwd`' >> $bootscript
echo 'set -x' >> $bootscript
# mbld needs to be run without an output dir so we dont
# run into mkdir issues.
./xmbld -o '' -j1 -Bnone mbld:mbld | \
    grep '^	' | \
    sed "s:`pwd`:\$pwd:g" | \
    tee -a $bootscript
echo 'true' >> $bootscript
chmod +x $bootscript
rm ./xmbld
