#!/bin/sh -e
# See http://jdebp.uk./FGA/slashpackage.html
if [ \! -d package -o \! -d source ]
then
	echo "You are not in the right directory." 1>&2
	exit 100
fi

# Atomically update the release directories ./command, ./library, ./include, and so forth.
# The build and release directories need not be on the same disc volume.
# And the files released must not be potentially overwritable and truncatable by the compiler/linker during subsequent builds.
# But released files can be links to other released files, of course.
mkdir -p command manual
commands="redo"
aliases="redo-ifcreate redo-ifchange cubehash"
for i in ${commands}
do
	rm -f -- command/"$i"{new}
	cp -p -f -- build/"$i" command/"$i"{new}
	strip command/"$i"{new}
done
for i in ${aliases}
do
	rm -f -- command/"$i"{new}
	ln -f -- command/redo{new} command/"$i"{new}
done
for i in ${commands} ${aliases}
do
	rm -f -- manual/"$i".1{new}
	cp -p -f -- build/"$i".1 manual/"$i".1{new}
done
if [ "`uname`" = "Interix" ]
then
	for i in ${commands} ${aliases}
	do
		rm -f -- command/"$i".exe{new}
		ln -f -- command/"$i"{new} command/"$i".exe{new}
	done
fi
for i in ${commands} ${aliases}
do
	mv -f -- command/"$i"{new} command/"$i"
	mv -f -- manual/"$i".1{new} manual/"$i".1
done
if [ "`uname`" = "Interix" ]
then
	for i in ${commands} ${aliases}
	do
		mv -f -- command/"$i".exe{new} command/"$i".exe
	done
fi
