#! /bin/sh
#
# Mastodon buildfile for my ported BSD tools
#

. ./Mastodon.inc

exedir CORE
supdir Docs DOC bsd
supdir Basic BASIC

install -d -m 755 -o root -g root $CORE/bin
install -d -m 755 -o root -g root $CORE/usr/bin
install -d -m 755 -o root -g root $CORE/etc

make -C 00library clean
CC="$SYSCC" CFLAGS=-O2 make -C 00library || exit 1

if [ $# -eq 0 ]; then
    APPS=`echo [a-z]*`
else
    APPS=$*
fi
for x in $APPS;do
    if [ -d $x ]; then
	make -C $x clean
	CC="$SYSCC" CFLAGS=-O2 make -C $x all || exit 1
	case $x in
	calendar|cmp|ctags|fmt|from|gencat|head)
	    __dest=$BASIC ;;
	hexdump|indent|join|mail|patch|ruptime)
	    __dest=$BASIC ;;
	shar|units|vacation|yacc)
	    __dest=$BASIC ;;
	*)
	    __dest=$CORE ;;
	esac
	make DESTDIR=$__dest -C $x install
    fi
done

if [ -d $CORE/usr/doc ]; then
    mkdir -p $DOC/usr
    mv $CORE/usr/doc $DOC/usr
fi

if [ -d sendmail ]; then
    mkdir -p $CORE/usr/share/sendmail
    (cd sendmail;find cf -depth -print | cpio -pdum $CORE/usr/share/sendmail)

    mkdir -p $DOC/usr/doc/sendmail
    (cd sendmail/doc;find . -depth -print | cpio -pdum $DOC/usr/doc/sendmail)
fi


exit 0
