:

mydir=$1
tls_ok=''

old="$tls_dir"
tls_dir=''
tls_include_dir=''
tls_lib_dir=''

while $test "$tls_ok" = "" ; do

    for a in $old /usr/local/ssl /usr/local none; do
	case "$tls_dir" in 
	'')
		case "$a" in
			none)
			tls_dir=none
			;;
			system)
			tls_dir=system
			;;
			*)
			if $test -r $a/include/openssl/ssl.h -a  -r $a/$libdirname/libssl.* 
			then
				tls_dir="$a"
				echo "Found OpenSSL from $tls_dir"
			elif $test -r $a/include/openssl/ssl.h -a  -r $a/lib/libssl.* 
			then
				tls_dir="$a"
				echo "Found OpenSSL from $tls_dir"
			fi
			;;
		esac
	;;
	esac
    done

    cat <<EOM

Elm ME+ can use OpenSSL library for TLS support. Support is
implemented as shared library libelmme-tls.so. Give directory
under which there are library and include files of OpenSSL. Give "none"
to disabled generation of shared library. Give "system" to indicate
that OpenSSL include and library files are search path of compiler.

EOM
    dflt="$tls_dir"

    rp="OpenSSL directory prefix? [$dflt]"
    echo $n "$rp $c"
    . myread

    case "$ans" in
	none)
	    tls_dir=none
	    tls_ok="$undef"
	    echo "TLS disabled"
	;;
	system)
	    tls_include_dir=''
	    tls_lib_dir=''
	    tls_dir=system
	    tls_ok="$define"
	    echo "OpenSSL is assumed to found from system locations"
	;;
	*)
	    tls_dir="$ans"
	    tls_include_dir="$tls_dir/include"
	    if $test -r $tls_dir/$libdirname/libssl.* 
	    then
		tls_lib_dir="$tls_dir/$libdirname"
	    else
	    	tls_lib_dir="$tls_dir/lib"
	    fi
	    tls_ok="$define"
	    echo "OpenSSL is assumed to found from $tls_dir directory"
	;;
   esac

   if $test "$tls_ok" = "$define"; then
	$cat >try.c <<'EOF'
#include "stdio.h"
#include <openssl/ssl.h>

int main(argc,argv)
    int argc;
    char **argv;
{

    SSL_load_error_strings(); 
    SSL_library_init();

    exit(0);
}
EOF
   
	rpathlist=''
	linklist=''
	if $test "$tls_lib_dir" != "" ; then
	    linklist="-L$tls_lib_dir"
	    rpathlist="$rpath_opt$tls_lib_dir"
	fi

	inclist=''
	if $test "$tls_include_dir" != "" ; then
	    inclist="-I$tls_include_dir"
	fi

	if $cc $ccflags -o try $inclist $linklist $rpathlist try.c -lssl -lcrypto > try.log 2>&1
	then
	    echo "Test compilation with OpenSSL succeed..."

	    if ./try ; then
		echo "Calling of OpenSSL succeed..."
	    else
		tls_ok=''
		echo "Calling of OpenSSL failed..."
	    fi

	else
	    tls_ok=''
	    echo "Failed to compile and link with OpenSSL".
	    cat try.log
	fi

	rm -f try.log try.c

	case "$tls_ok" in
	'')
	    cat <<EOF

OpenSSL location $tls_dir seems not work. Select on of following
    d) Disable TLS support
    c) Change OpenSSL directory prefix

EOF
	    dflt=d
	    rp="Your selection? [$dflt]"
	    echo $n "$rp $c"
	    . myread

	    if $test "$ans" = d; then
		tls_dir=none
		tls_ok="$undef"
		echo "TLS disabled"	
	    fi
	;;
	esac
    fi
done

$spitshell <<EOT > ../$mydir/config.res 
#  Support for TLS
tls_ok='$tls_ok'
tls_dir='$tls_dir'
tls_include_dir='$tls_include_dir'
tls_lib_dir='$tls_lib_dir'

EOT


