#! /bin/sh
name=clsmtpc
eval `grep ^version= $name`
need_ex="bash cat dd tr od file md5sum iconv"
prefix=/usr/local
with_doc=1

help() {
echo "\`configure' configures $name $version to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print \`checking...' messages

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
			  [/usr/local]

By default, \`make install' will install all the files in
\`/usr/local/bin', \`/usr/local/lib' etc.  You can specify
an installation prefix other than \`/usr/local' using \`--prefix',
for instance \`--prefix=\$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR           user executables [PREFIX/bin]
  --datadir=DIR          read-only architecture-independent data [PREFIX/share]
  --mandir=DIR           man documentation [DATADIR/man]

Optional Packages:
  --with-doc              include man files [default]
  --without-doc           don't include man files
"
}

while [ "$1" ];do
    p=${1%%=*}
    q=${1#*=}
    case "$p" in
	--prefix )
	    prefix=$q
	    shift
	    ;;
	--bindir )
	    bindir=$q
	    shift
	    ;;
	--mandir )
	    mandir=$q
	    shift
	    ;;
	--with-doc )
	    with_doc=1
	    shift
	    ;;
	--without-doc )
	    with_doc=0
	    shift
	    ;;
	--quiet | --silent | "-q" )
	    shift
	    exec 1>/dev/null
	    ;;
	--version | -V )
	    echo $name: $version
	    exit 0
	    ;;
	--help | -h )
	    help
	    exit 0
	    ;;
	* )
	    echo $1 is not implemented. >&2
	    exit 1
	    ;;
    esac
done

if [ ! "$bindir" ];then
    bindir=$prefix/bin
fi

if [ ! "$datadir" ];then
    datadir=$prefix/share
fi

if [ ! "$mandir" ];then
    mandir=$datadir/man
fi

for t in $need_ex ;do

    echo -n checking for $t
    t1=`type -p $t`
    if [ -x $t1 ];then
	echo "... $t1"
    else
	echo "... no"
	exit 1
    fi
done

if [ $with_doc = 1 ];then
    echo -e "DESTDIR=
all: doc
doc:
\t./mkdoc.sh >$name.1
\tgzip $name.1
install:
\tinstall -D -m 755 $name \${DESTDIR}$bindir/$name
\tinstall -D -m 644 $name.1.gz \${DESTDIR}$mandir/man1/$name.1.gz
uninstall:
\trm $bindir/$name 
\trm $mandir/$name.1.gz
" >Makefile
else
    echo -e "DESTDIR=
all: install
install:
\tinstall -d -m 755 $name \${DESTDIR}$bindir/$name 
uninstall:
\trm $bindir/$name 
" >Makefile
fi
echo creating Makefile
exit 0
