Adding a file to help test git commands.
[asdcplib.git] / m4 / ax_lib_openssl.m4
index b8eaf5456d3642cc3cac4eeaed9fdcabed566794..8a70f992e6bfd4daf5cfd3d6140c0969bfc5f5e8 100644 (file)
@@ -8,9 +8,9 @@
 #
 # DESCRIPTION
 #
-#   This macro provides tests of availability of OpenSSL of
+#   This macro provides tests of availability of OpenSSL of a
 #   particular version or newer. This macros checks for OpenSSL
-#   headers and libraries and defines compilation flags
+#   headers and libraries and defines compilation flags.
 #
 #   Macro supports following options and their values:
 #
 #
 #     HAVE_OPENSSL
 #
-# LAST MODIFICATION
+# Copyright (c) 2008-2009 CineCert, LLC
+# All rights reserved.
 #
-#   2008-04-12
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. The name of the author may not be used to endorse or promote products
+#    derived from this software without specific prior written permission.
 #
-# COPYLEFT
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
-#   Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net>
-#
-#   Copying and distribution of this file, with or without modification, are
-#   permitted in any medium without royalty provided the copyright notice
-#   and this notice are preserved.
 
 AC_DEFUN([AX_LIB_OPENSSL],
 [
@@ -48,10 +62,16 @@ AC_DEFUN([AX_LIB_OPENSSL],
         ),
         [
         if test "$withval" = "yes"; then
-            if test -d /usr/local/ssl/include ; then
+            if test -d /var/local/ssl/include ; then
+                openssl_prefix=/var/local/ssl
+            elif test -d /var/local/include/openssl ; then
+                openssl_prefix=/var/local
+            elif test -d /usr/local/ssl/include ; then
                 openssl_prefix=/usr/local/ssl
             elif test -d /usr/lib/ssl/include ; then
                 openssl_prefix=/usr/lib/ssl
+            elif test -d /usr/include/openssl ; then
+                openssl_prefix=/usr
             else
                 openssl_prefix=""
             fi
@@ -66,10 +86,16 @@ AC_DEFUN([AX_LIB_OPENSSL],
         ],
         [
         dnl Default behavior is implicit yes
-        if test -d /usr/local/ssl/include ; then
+        if test -d /var/local/ssl/include ; then
+            openssl_prefix=/var/local/ssl
+        elif test -d /var/local/include/openssl ; then
+            openssl_prefix=/var/local
+        elif test -d /usr/local/ssl/include ; then
             openssl_prefix=/usr/local/ssl
         elif test -d /usr/lib/ssl/include ; then
             openssl_prefix=/usr/lib/ssl
+        elif test -d /usr/include/openssl ; then
+            openssl_prefix=/usr
         else
             openssl_prefix=""
         fi
@@ -87,7 +113,7 @@ AC_DEFUN([AX_LIB_OPENSSL],
 
     if test -n "$openssl_prefix"; then
         openssl_include_dir="$openssl_prefix/include"
-        openssl_ldflags="-L$openssl_prefix/lib"
+        openssl_ldflags="-L$openssl_prefix/lib64 -L$openssl_prefix/lib"
         run_openssl_test="yes"
     elif test "$openssl_requested" = "yes"; then
         if test -n "$openssl_include_dir" -a -n "$openssl_lib_flags"; then
@@ -155,7 +181,6 @@ AC_DEFUN([AX_LIB_OPENSSL],
 @%:@include <openssl/ssl.h>
 @%:@include <openssl/crypto.h>
 #if (OPENSSL_VERSION_NUMBER < 0x0090700f)
-deliberate syntax error
 #endif
                     ]],
                     [[
@@ -209,50 +234,43 @@ SSLeay();
 
                 AC_MSG_CHECKING([if OpenSSL version is >= $openssl_version_req])
 
-                if test -f "$openssl_include_dir/xercesc/util/XercesVersion.hpp"; then
-
-                    openssl_major=`cat $xerces_include_dir/xercesc/util/XercesVersion.hpp | \
-                                    grep '^#define.*OPENSSL_VERSION_MAJOR.*[0-9]$' | \
-                                    sed -e 's/#define OPENSSL_VERSION_MAJOR.//'`
-
-                    openssl_minor=`cat $xerces_include_dir/xercesc/util/XercesVersion.hpp | \
-                                    grep '^#define.*OPENSSL_VERSION_MINOR.*[0-9]$' | \
-                                    sed -e 's/#define OPENSSL_VERSION_MINOR.//'`
+                if test -f "$openssl_include_dir/openssl/opensslv.h"; then
 
-                    openssl_revision=`cat $xerces_include_dir/xercesc/util/XercesVersion.hpp | \
-                                    grep '^#define.*OPENSSL_VERSION_REVISION.*[0-9]$' | \
-                                    sed -e 's/#define OPENSSL_VERSION_REVISION.//'`
-
-                    OPENSSL_VERSION="$xerces_major.$xerces_minor.$xerces_revision"
+                    OPENSSL_VERSION=`grep OPENSSL_VERSION_TEXT $openssl_include_dir/openssl/opensslv.h \
+                                    | grep -v fips | grep -v PTEXT | cut -f 2 | tr -d \"`
                     AC_SUBST([OPENSSL_VERSION])
 
                     dnl Decompose required version string and calculate numerical representation
-                    xerces_version_req_major=`expr $xerces_version_req : '\([[0-9]]*\)'`
-                    xerces_version_req_minor=`expr $xerces_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
-                    xerces_version_req_revision=`expr $xerces_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+                    openssl_version_req_major=`expr $openssl_version_req : '\([[0-9]]*\)'`
+                    openssl_version_req_minor=`expr $openssl_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
+                    openssl_version_req_revision=`expr $openssl_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+                    openssl_version_req_patch=`expr $openssl_version_req : '[[0-9]]*\.[[0-9]]*\.[[0-9]]*\([[a-z]]*\)'`
                     if test "x$openssl_version_req_revision" = "x"; then
                         openssl_version_req_revision="0"
                     fi
+                    if test "x$openssl_version_req_patch" = "x"; then
+                        openssl_version_req_patch="\`"
+                    fi
 
-                    openssl_version_req_number=`expr $xerces_version_req_major \* 10000 \
-                                               \+ $xerces_version_req_minor \* 100 \
-                                               \+ $xerces_version_req_revision`
+                    openssl_version_req_number=`expr $openssl_version_req_major \* $((0x10000000)) \
+                                               \+ $openssl_version_req_minor \* $((0x100000)) \
+                                               \+ $openssl_version_req_revision \* $((0x1000)) \
+                                               \+ $((1 + $(printf "%d" \'$openssl_version_req_patch) - $(printf "%d" \'a))) \* $((0x10)) \
+                                               \+ $((0xf))`
 
                     dnl Calculate numerical representation of detected version
-                    openssl_version_number=`expr $xerces_major \* 10000 \
-                                          \+ $xerces_minor \* 100 \
-                                           \+ $xerces_revision`
+                    openssl_version_number=`expr $(($(grep OPENSSL_VERSION_NUMBER $openssl_include_dir/openssl/opensslv.h | cut -f 2 | tr -d L)))`
 
                     openssl_version_check=`expr $openssl_version_number \>\= $openssl_version_req_number`
                     if test "$openssl_version_check" = "1"; then
                         AC_MSG_RESULT([yes])
                     else
                         AC_MSG_RESULT([no])
-                        AC_MSG_WARN([Found OpenSSL $OPENSSL_VERSION, which is older than required. Possible compilation failure.])
+                        AC_MSG_WARN([Found $OPENSSL_VERSION, which is older than required. Possible compilation failure.])
                     fi
                 else
                     AC_MSG_RESULT([no])
-                    AC_MSG_WARN([Missing header XercesVersion.hpp. Unable to determine Xerces version.])
+                    AC_MSG_WARN([Missing header openssl/opensslv.h. Unable to determine OpenSSL version.])
                 fi
             fi
         fi