#!/bin/bash

root=/usr/share/logidee-tools
directories=""

while (test "$1" != "")
do
    case $1 in
    -r)
        root=`eval echo -n $2`
	shift 2
    ;;
      
    -h)
	echo "Usage: $0 [ -r <dir> ] [ -h ] directories ..."
	echo "-r <dir> : use <dir> as the logidee-tools root directory"
	echo "-h       : display this help message"
	exit 0
    ;;
      
    *)
        directories="$directories $1"
	shift
    ;;
    esac
done


if [ ! -d "$root" ]
then
    echo "Where is the main directory of logidee-tools ?"
    while (test ! -d $root)
    do
	read -p "Main directory of logidee-tools: " -e root
	root=`eval echo -n $root`
    done
    echo ""
fi


if [ "$directories" = "" ]
then
    echo "Which directories may contain xml documents ?"
    read -p "Give a space delimited list of directories : " -e directories
fi


# Install what's needed
cp $root/Makefile $root/Makefile.generic ./
test -L xsl && rm -f xsl
test -L dtd && rm -f dtd
test -d xsl || ln -sf $root/xsl xsl
test -d dtd || ln -sf $root/dtd dtd
test -d charte || mkdir charte

ln -sf $root/charte/* charte/
ln -sf $root/bin/verif_dep.sh .

# Setup
perl -pi -e "s|^REP\s*=.*$|REP=$directories|" Makefile
perl -pi -e "s|^DIR\s*=.*$|DIR=`pwd`|" Makefile.generic

make makefiles

