#! /bin/sh
# Written by Michael O'Reilly (oreill_m@dropbear.cs.uwa.oz.au)
# auto configure for LPmud 3.0
#
# Maybe something more general should be made, to be used by config.h ?
#
if (test -f config.data) then
    echo config.data exists
    echo -n 'read in config file ? (y/n):'
    read ans
    echo ans = $ans
    if (test a$ans = ay) then
        echo reading from config.data
        read bin_dir mud_dir gcc nodebug < config.data
    else
        ASK=yes
        fi
else
    ASK=yes
    fi
if (test $ASK) then
    echo What directory is your binary directory?
    echo -n :
    read bin_dir
    echo What directory is your mudlib in?
    echo -n :
    read mud_dir
    gcc=no
    if (test `which gcc|grep -v 'no gcc'` ) then
	echo -n 'gcc found. Use it ? (Y/n):'
        read ans
	if (test a$ans != an) then
            gcc=yes
            fi
        fi
    echo -n 'Would you like run time debugging. (Y/n) :'
    read ans
    if (test an != a$ans) then
        nodebug=no
    else
	nodebug=yes
        fi
    echo Writing a config.data
    echo $bin_dir $mud_dir $gcc $nodebug > config.data
    fi
echo bin = $bin_dir mud = $mud_dir
cp Makefile Makefile.old
chmod u+w Makefile
cat Makefile | sed 's!^BINDIR.*$!BINDIR = '$bin_dir'!' > Makefile.new
cat Makefile.new | sed 's!^MUD_LIB.*$!MUD_LIB = '$mud_dir'!' > Makefile
if (test $gcc = no) then
    cat Makefile | sed 's!^WARN=.*$!WARN=!' | \
    sed 's!CC=gcc!CC=cc!' > Makefile.new
    mv Makefile.new Makefile 
    fi
if (test $nodebug = yes) then
    cat Makefile | sed 's!^DEBUG=!#DEBUG=!' > Makefile.new
    mv Makefile.new Makefile
    fi
rm -f Makefile.new