#! /bin/sh

# This script is for bootstrapping a new install.  It should live in
#  /local/src or equivalent and must be run from that same directory.

if [ ! \( -d c-publish -a -d makefiles -a -d makewrapper \) ]; then
	echo Incorrect current directory '(subdirs)'. 1>&2
	exit 1
fi

lr="`pwd`"

case "$lr" in
	*/src)	;;
	*)	echo Incorrect current directory '(not src)'. 1>&2
		exit 1
		;;
esac

lr=${lr%/src}

set -x

export LOCALROOT=$lr

cd $LOCALROOT
mkdir -p .bin .etc .include .lib .man bin etc include lib man pkg src
cd man
mkdir -p man1 man2 man3 man4 man5 man6 man7 man8 man9
mkdir -p cat1 cat2 cat3 cat4 cat5 cat6 cat7 cat8 cat9

cd $LOCALROOT
ln -s makefiles lib/make
ln -s makewrapper bin/make

(cd src/makefiles && sh TRANSCRIPT)
(cd src/makewrapper && sh TRANSCRIPT)
ln -s $LOCALROOT/.bin/makewrapper*/makewrapper $LOCALROOT/bin/makewrapper
ln -s $LOCALROOT/.lib/makefiles*/makefiles $LOCALROOT/lib/makefiles

PATH=$LOCALROOT/bin:$PATH

(cd src/c-publish && sh TRANSCRIPT && $LOCALROOT/.bin/c-publish*/publish .)
rm -f $LOCALROOT/bin/makewrapper
(cd src/makewrapper && $LOCALROOT/bin/publish .)
rm -f $LOCALROOT/lib/makefiles
(cd src/makefiles && $LOCALROOT/bin/publish -L .)
