#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/autoconf/openssl                     */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Aug  9 13:27:23 1995                          */
#*    Last change :  Tue Jan 31 16:21:09 2006 (serrano)                */
#*    -------------------------------------------------------------    */
#*    Check for the host openssl library.                              */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    flags                                                            */
#*---------------------------------------------------------------------*/
cc=gcc
cflags=
openssllibs="-lssl"
tmp=/tmp
user=bigloo
posixos="unix"

#*---------------------------------------------------------------------*/
#*    We parse the arguments                                           */
#*---------------------------------------------------------------------*/
while : ; do
  case $1 in
    "")
      break;;

    --user=*)
      user="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --cc=*|-cc=*)
      cc="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --cflags=*|-cflags=*)
      cflags="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --lib=*|-lib=*)
      openssllibs="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --tmp=*|-tmp=*)
      tmp="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --posixos=*|-posixos=*)
      posixos="`echo $1 | sed 's/^[-a-z]*=//'`";;

    -*)
      echo "Unknown option \"$1\", ignored" >&2;;
  esac
  shift
done

file=$tmp/actest$user
aout=$tmp/Xactest$user

#*---------------------------------------------------------------------*/
#*    compile                                                          */
#*---------------------------------------------------------------------*/
compile="$cc $cflags $file.c -o $aout $openssllibs >/dev/null 2> /dev/null"

#*---------------------------------------------------------------------*/
#*    The test C file                                                  */
#*---------------------------------------------------------------------*/
if( test -f $file.c ); then
   rm -f $file.c || exit $?
fi

#*---------------------------------------------------------------------*/
#*    Test                                                             */
#*---------------------------------------------------------------------*/
cat > $file.c <<EOF
#include <openssl/ssl.h>
#include <openssl/bio.h>

static SSL_CTX *ctx;

main( int argc, char *argv[] ) {
    BIO *sbio;

    SSL_library_init();
    SSL_load_error_strings();

    ctx = SSL_CTX_new( SSLv23_client_method() );
 
    sbio = BIO_new_socket( 0, BIO_NOCLOSE );
    BIO_free( sbio );
}
EOF

#*---------------------------------------------------------------------*/
#*    Compilation test                                                 */
#*---------------------------------------------------------------------*/
if eval $compile; then
   echo "$openssllibs"
else
   echo "no"
fi

\rm -f $file.*
\rm -f $aout
\rm -f $aout*

exit 0
