[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [obfsproxy/master] Revise detection of libcrypto and winsock.



commit 7f03b8e78620d4ff20dbbea32d309ea6ec57f9d1
Author: Zack Weinberg <zackw@xxxxxxxxx>
Date:   Mon Jul 11 16:43:39 2011 -0700

    Revise detection of libcrypto and winsock.
---
 Makefile.am   |    4 ++--
 configure.ac  |   29 +++++++++++++----------------
 m4/winsock.m4 |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 18 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index a78d7d0..1c2d89b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@
 
 ACLOCAL_AMFLAGS = -I m4
-AM_CFLAGS = -DDEBUG -Wall -Werror @libevent_CFLAGS@ @openssl_CFLAGS@
-LDADD = libobfsproxy.a @libevent_LIBS@ @openssl_LIBS@ @ws32_LIBS@
+AM_CFLAGS = -DDEBUG -Wall -Werror @libevent_CFLAGS@ @libcrypto_CFLAGS@
+LDADD = libobfsproxy.a @libevent_LIBS@ @libcrypto_LIBS@ @ws32_LIBS@
 
 bin_PROGRAMS = obfsproxy
 noinst_LIBRARIES = libobfsproxy.a
diff --git a/configure.ac b/configure.ac
index 025589f..32b7138 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,32 +5,29 @@ AC_CONFIG_SRCDIR([src/main.c])
 AM_INIT_AUTOMAKE([foreign])
 
 AC_PROG_CC
-AC_PROG_CPP
 AC_PROG_RANLIB
 PKG_PROG_PKG_CONFIG
 
 PKG_CHECK_MODULES([libevent], [libevent >= 2.0])
-PKG_CHECK_MODULES([openssl], [openssl >= 0.9.7])
-
-AC_CACHE_CHECK([for winsock], [ac_cv_lib_winsock],
-  [AC_PREPROC_IFELSE(
-    [#ifndef _WIN32
-    #error "not windows"
-    #endif
-    ],
-    [ac_cv_lib_winsock=yes], [ac_cv_lib_winsock=no])
-])
-AS_IF([test "x$ac_cv_lib_winsock" = xyes],
-  [ws32_LIBS=-lws2_32],
-  [ws32_LIBS=])
-AC_SUBST(ws32_LIBS)
+# Presently no need for libssl, only libcrypto.
+PKG_CHECK_MODULES([libcrypto], [libcrypto >= 0.9.7])
 
+# We permit the use of openssl 0.9.7, which doesn't have sha256.
+# Check whether a replacement is required.
 save_LIBS="$LIBS"
-LIBS="$openssl_LIBS"
+LIBS="$libcrypto_LIBS"
 AC_CHECK_FUNC(SHA256_Init, [:], [:])
 LIBS="$save_LIBS"
 AM_CONDITIONAL(NEED_SHA256, [test x$ac_cv_func_SHA256_Init = xno])
 
+# ntohl and a bunch of related functions require a special library on Windows.
+# It is possible that libevent or libcrypto has hooked us up already.
+# This can't be done with AC_SEARCH_LIBS -- see m4/winsock.m4 for gory details.
+save_LIBS="$LIBS"
+LIBS="$libevent_LIBS $libcrypto_LIBS"
+AX_LIB_WINSOCK2
+LIBS="$save_LIBS"
+
 AC_CONFIG_FILES([Makefile])
 AC_CONFIG_HEADERS([config.h])
 AC_OUTPUT
diff --git a/m4/winsock.m4 b/m4/winsock.m4
new file mode 100644
index 0000000..a90cc50
--- /dev/null
+++ b/m4/winsock.m4
@@ -0,0 +1,56 @@
+# Copyright © 2011 Zack Weinberg <zackw@xxxxxxxxx>
+#
+# Copying and distribution of this software, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.  This software is offered as-is,
+# without any warranty.
+
+# The socket API requires a special library on Windows, but
+# AC_SEARCH_LIBS cannot be used to find it, because it will
+# mis-declare 'ntohl' on windows and cause the link to fail.
+#
+# This macro sets the substitution @ws2_LIBS@ to "-lws2_32"
+# if you need that, and "" otherwise.  It does not provide
+# any #defines for the differences in socket headers between
+# Windows and Unix -- just use #ifdef _WIN32.
+#
+# Implementation note: we use the same _cv_ variable that
+# AC_SEARCH_LIBS would, because the test is what AC_SEARCH_LIBS
+# *should* have done in this situation.
+AC_DEFUN([AX_LIB_WINSOCK2],
+  [AC_CACHE_CHECK([for library containing ntohl], [ac_cv_search_ntohl],
+    [AC_LANG_CONFTEST([AC_LANG_PROGRAM([
+      #ifdef _WIN32
+      #include <winsock2.h>
+      #else
+      #include <arpa/inet.h>
+      #endif
+    ], [
+      return (int)ntohl(42);])
+    ])
+
+    ax_lib_winsock2_save_LIBS="$LIBS"
+    for ac_lib in '' -lws2_32; do
+      if test -z "$ac_lib"; then
+        ac_res="none required"
+      else
+        ac_res=$ac_lib
+      fi
+      LIBS="$ac_lib $ax_lib_winsock2_save_LIBS"
+      AC_LINK_IFELSE([], [AS_VAR_SET([ac_cv_search_ntohl], [$ac_res])])
+      AS_VAR_SET_IF([ac_cv_search_ntohl], [break])
+    done
+    AS_VAR_SET_IF([ac_cv_search_ntohl], ,
+                  [AS_VAR_SET([ac_cv_search_ntohl], [no])])
+    rm conftest.$ac_ext
+    LIBS="$ax_lib_winsock2_save_LIBS"
+  ])
+
+  ws32_LIBS=
+  if test "x$ac_cv_search_ntohl" == "xno"; then
+    AC_MSG_ERROR([could not find ntohl])
+  elif test "x$ac_cv_search_ntohl" != "xnone required"; then
+    ws32_LIBS="$ac_cv_search_ntohl"
+  fi
+  AC_SUBST(ws32_LIBS)
+])



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits