Hi!  This patch fixes the detection of openssl/libz to use more normal
header+library detection code.  It should work fine on common platforms,
but it may change detection on weirder systems, but nothing that cannot
be fixed by appropriate use of --with-foo-prefix.  It also sets up -R
parameters if needed.  It definitely will fix the -I/usr/include
additions that cause problems for Mingw.

With this I can actually cross-compile libssh2 on a debian x86 box to
mingw and even run the self-tests under Wine via 'make check'.

The patch below is rather hard to read.  To simplify review of the new
code, the relevant configure.in snippet to detect libz+openssl is with
the patch reduced to the following.  Much less code than before, neat.

What do you think?  Ok to commit?

# Configure parameters
AC_ARG_WITH(libgcrypt,
  AC_HELP_STRING([--with-libgcrypt],[Use Libgcrypt for crypto]),
  use_libgcrypt=$withval,use_libgcrypt=auto)
AC_ARG_WITH(openssl,
  AC_HELP_STRING([--with-openssl],[Use OpenSSL for crypto]),
  use_openssl=$withval,use_openssl=auto)
AC_ARG_WITH(libz,
  AC_HELP_STRING([--with-libz],[Use Libz for compression]),
  use_libz=$withval,use_libz=auto)

# Look for OpenSSL (default)
if test "$use_openssl" != "no" && test "$use_libgcrypt" != "yes"; then
  AC_LIB_HAVE_LINKFLAGS([ssl], [], [#include <openssl/ssl.h>])
fi

# Look for libgcrypt
if test "$ac_cv_libssl" != "yes" && test "$use_libgcrypt" != "no"; then
  AC_LIB_HAVE_LINKFLAGS([gcrypt], [], [#include <gcrypt.h>])
fi

if test "$ac_cv_libssl" != "yes" && test "$ac_cv_libgcrypt" != "yes"; then
  AC_MSG_ERROR([cannot find OpenSSL or Libgcrypt,
try --with-libssl-prefix=PATH or --with-libgcrypt-prefix=PATH])
fi

if test "$ac_cv_libgcrypt" = "yes"; then
  AC_DEFINE(LIBSSH2_LIBGCRYPT, 1, [Use libgcrypt])
fi
AM_CONDITIONAL(LIBGCRYPT, test "$ac_cv_libgcrypt" = "yes")

# Look for Libz
if test "$use_libz" != "no"; then
  AC_LIB_HAVE_LINKFLAGS([z], [], [#include <zlib.h>])
  if test "$ac_cv_libz" != yes; then
    AC_MSG_NOTICE([Cannot find libz, disabling compression])
    AC_MSG_NOTICE([Try --with-libz-prefix=PATH if you know you have it])
  else
    AC_DEFINE(LIBSSH2_HAVE_ZLIB, 1, [Compile in zlib support])
  fi
fi

/Simon

Index: configure.in
===================================================================
RCS file: /cvsroot/libssh2/libssh2/configure.in,v
retrieving revision 1.58
diff -u -p -r1.58 configure.in
--- configure.in        10 Nov 2008 16:48:41 -0000      1.58
+++ configure.in        18 Nov 2008 16:53:00 -0000
@@ -71,144 +71,46 @@ fi
 dnl check for how to do large files
 AC_SYS_LARGEFILE
 
-# Look for libgcrypt.
+# Configure parameters
 AC_ARG_WITH(libgcrypt,
-  AC_HELP_STRING([--with-libgcrypt],[Use libgcrypt for crypto]),
-  use_libgcrypt=$withval,use_libgcrypt=no)
-if test "$use_libgcrypt" != "no"; then
-  AC_LIB_HAVE_LINKFLAGS([gcrypt], [], [#include <gcrypt.h>])
-fi
-if test "$ac_cv_libgcrypt" = yes; then
-  use_libgcrypt=yes
-  AC_DEFINE(LIBSSH2_LIBGCRYPT, 1, [Use libgcrypt])
-fi
-AM_CONDITIONAL(LIBGCRYPT, test "$use_libgcrypt" != "no")
-
-# Need to define SHLIB_SUFFIX_NAME before checking for libcrypt and libz
-# $shrext_cmds (from libtool) can contain commands so it must be eval'd
-# Simon's note: replace the find-openssl/libz logic with Bruno's
-# AC_LIB_LINKFLAGS which is more portable and flexible.
-eval SHLIB_SUFFIX_NAME=\"$shrext_cmds\"
-AC_SUBST(SHLIB_SUFFIX_NAME)
-
-#
-# Look for OpenSSL
-#
+  AC_HELP_STRING([--with-libgcrypt],[Use Libgcrypt for crypto]),
+  use_libgcrypt=$withval,use_libgcrypt=auto)
 AC_ARG_WITH(openssl,
-  AC_HELP_STRING([--with-openssl=DIR],[Look for OpenSSL in PATH]),
-  [LIBSSH2_OPENSSL_DIR=$withval],[LIBSSH2_OPENSSL_DIR=yes])
-
-if test "$use_libgcrypt" = "no"; then
-
-if test "$LIBSSH2_OPENSSL_DIR" = "no" || test "$LIBSSH2_OPENSSL_DIR" = "yes"; 
then
-  unset LIBSSH2_OPENSSL_DIR
-fi
-
-found_openssl=no
-pkgcfg_openssl=no
-unset OPENSSL_INCDIR
-unset OPENSSL_INCLINE
-unset OPENSSL_LIBLINE
-
-AC_MSG_CHECKING([for OpenSSL])
-
-# Explicit path given, use it rather than pkg-config
-if test ! -z "$LIBSSH2_OPENSSL_DIR"; then
-  found_openssl=yes
-  OPENSSL_LIBLINE="-L$LIBSSH2_OPENSSL_DIR/lib -lcrypto"
-  OPENSSL_INCLINE="-I$LIBSSH2_OPENSSL_DIR/include"
-  OPENSSL_INCDIR=$LIBSSH2_OPENSSL_DIR/include
-  AC_MSG_RESULT([Using explicit path $LIBSSH2_OPENSSL_DIR])
-fi
-
-# If pkg-config is found try using it
-if test "$found_openssl" = "no" && test -x "$PKG_CONFIG" && $PKG_CONFIG 
--exists openssl; then
-  found_openssl=yes
-  pkgcfg_openssl=yes
-  OPENSSL_LIBLINE=`$PKG_CONFIG --libs openssl`
-  OPENSSL_INCLINE=`$PKG_CONFIG --cflags-only-I openssl`
-  AC_MSG_RESULT([Using paths from pkg-config])
-fi
-
-# Elsewise, search for OpenSSL wherever it might be
-if test "$found_openssl" = "no"; then
-  OPENSSL_SEARCH_PATH="/usr/local/ssl /usr/local /usr /usr/local/openssl"
-
-  for i in $OPENSSL_SEARCH_PATH; do
-    if test -r $i/include/openssl/evp.h; then
-      OPENSSL_INCLINE="-I$i/include"
-      OPENSSL_INCDIR=$i/include
-    fi
-    if test -r $i/include/openssl/hmac.h; then
-      OPENSSL_INCLINE="-I$i/include"
-      OPENSSL_INCDIR=$i/include
-    fi
-    if test -r $i/lib/libcrypto.a -o -r $i/lib/libcrypto$SHLIB_SUFFIX_NAME; 
then
-      OPENSSL_LIBLINE="-L$i/lib -lcrypto"
-    fi
-    test -n "$OPENSSL_INCLINE" && test -n "$OPENSSL_LIBLINE" && break
-  done
-
-  if test -z "$OPENSSL_INCLINE"; then
-    AC_MSG_ERROR([Cannot find OpenSSL's <evp.h> or <hmac.h>])
-  fi
-
-  if test -z "$OPENSSL_LIBLINE"; then
-    AC_MSG_ERROR([Cannot find OpenSSL's libcrypto])
-  fi
+  AC_HELP_STRING([--with-openssl],[Use OpenSSL for crypto]),
+  use_openssl=$withval,use_openssl=auto)
+AC_ARG_WITH(libz,
+  AC_HELP_STRING([--with-libz],[Use Libz for compression]),
+  use_libz=$withval,use_libz=auto)
 
-  AC_MSG_RESULT([$OPENSSL_INCLINE $OPENSSL_LIBLINE])
+# Look for OpenSSL (default)
+if test "$use_openssl" != "no" && test "$use_libgcrypt" != "yes"; then
+  AC_LIB_HAVE_LINKFLAGS([ssl], [], [#include <openssl/ssl.h>])
 fi
 
-#
-# Confirm required OpenSSL libs
-#
-if test ! "$pkgcfg_openssl" = "yes"; then
-  if test ! -r $OPENSSL_INCDIR/openssl/bn.h || test ! -r 
$OPENSSL_INCDIR/openssl/evp.h || \
-     test ! -r $OPENSSL_INCDIR/openssl/hmac.h || test ! -r 
$OPENSSL_INCDIR/openssl/pem.h || \
-     test ! -r $OPENSSL_INCDIR/openssl/sha.h; then
-       AC_MSG_ERROR([Missing one or more of <openssl/bn.h>, <openssl/evp.h>, 
<openssl/hmac.h>, <openssl/pem.h>, <openssl/sha.h>])
-  fi
+# Look for libgcrypt
+if test "$ac_cv_libssl" != "yes" && test "$use_libgcrypt" != "no"; then
+  AC_LIB_HAVE_LINKFLAGS([gcrypt], [], [#include <gcrypt.h>])
 fi
 
-CFLAGS="$CFLAGS $OPENSSL_INCLINE"
-LDFLAGS="$LDFLAGS $OPENSSL_LIBLINE"
-
+if test "$ac_cv_libssl" != "yes" && test "$ac_cv_libgcrypt" != "yes"; then
+  AC_MSG_ERROR([cannot find OpenSSL or Libgcrypt,
+try --with-libssl-prefix=PATH or --with-libgcrypt-prefix=PATH])
 fi
 
-#
-# zlib
-#
-AC_ARG_WITH(libz,
-  AC_HELP_STRING([--with-libz=PATH],[Look for libz in PATH]),
-  [LIBSSH2_LIBZ_DIR=$withval],[LIBSSH2_LIBZ_DIR="/usr/local /usr 
/usr/local/libz /usr/libz /usr/local/zlib /usr/zlib"])
-
-if test "$LIBSSH2_LIBZ_DIR" = "no" || test "$LIBSSH2_LIBZ_DIR" = "yes"; then
-  unset LIBSSH2_LIBZ_DIR
+if test "$ac_cv_libgcrypt" = "yes"; then
+  AC_DEFINE(LIBSSH2_LIBGCRYPT, 1, [Use libgcrypt])
 fi
+AM_CONDITIONAL(LIBGCRYPT, test "$ac_cv_libgcrypt" = "yes")
 
-unset LIBZ_INCDIR
-unset LIBZ_LIBDIR
-
-AC_MSG_CHECKING([for libz])
-
-for i in $LIBSSH2_LIBZ_DIR; do
-  if test -r $i/include/zlib.h; then
-    LIBZ_INCDIR=$i/include
-  fi
-  if test -r $i/lib/libz.a -o -r $i/lib/libz$SHLIB_SUFFIX_NAME; then
-    LIBZ_LIBDIR=$i/lib
+# Look for Libz
+if test "$use_libz" != "no"; then
+  AC_LIB_HAVE_LINKFLAGS([z], [], [#include <zlib.h>])
+  if test "$ac_cv_libz" != yes; then
+    AC_MSG_NOTICE([Cannot find libz, disabling compression])
+    AC_MSG_NOTICE([Try --with-libz-prefix=PATH if you know you have it])
+  else
+    AC_DEFINE(LIBSSH2_HAVE_ZLIB, 1, [Compile in zlib support])
   fi
-  test -n "$LIBZ_INCDIR" && test -n "$LIBZ_LIBDIR" && break
-done
-
-if test -n "$LIBZ_INCDIR" && test -n "$LIBZ_LIBDIR"; then
-  AC_MSG_RESULT([Found in $LIBZ_INCDIR $LIBZ_LIBDIR])
-  CFLAGS="$CFLAGS -I$LIBZ_INCDIR"
-  LDFLAGS="$LDFLAGS -L$LIBZ_LIBDIR -lz"
-  AC_DEFINE(LIBSSH2_HAVE_ZLIB, 1, [Compile in zlib support])
-else
-  AC_MSG_RESULT([Cannot find libz's <zlib.h>])
 fi
 
 #
Index: src/Makefile.am
===================================================================
RCS file: /cvsroot/libssh2/libssh2/src/Makefile.am,v
retrieving revision 1.10
diff -u -p -r1.10 Makefile.am
--- src/Makefile.am     17 Jul 2007 13:22:55 -0000      1.10
+++ src/Makefile.am     18 Nov 2008 16:53:00 -0000
@@ -50,4 +50,5 @@ VERSION=-version-info 1:0:0
 # set age to 0. (c:r:a=0)
 #
 
-libssh2_la_LDFLAGS = $(VERSION) -no-undefined $(LTLIBGCRYPT)
+libssh2_la_LDFLAGS = $(VERSION) -no-undefined \
+       $(LTLIBGCRYPT) $(LTLIBSSL) $(LTLIBZ)

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
libssh2-devel mailing list
libssh2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel

Reply via email to