Debian Codegraph @

libmowgli-2/m4/ax_check_openssl.m4

raw
1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_check_openssl.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 # AX_CHECK_OPENSSL([action-if-found[, action-if-not-found]])
8 #
9 # DESCRIPTION
10 #
11 # Look for OpenSSL in a number of default spots, or in a user-selected
12 # spot (via --with-openssl). Sets
13 #
14 # OPENSSL_INCLUDES to the include directives required
15 # OPENSSL_LIBS to the -l directives required
16 # OPENSSL_LDFLAGS to the -L or -R flags required
17 #
18 # and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
19 #
20 # This macro sets OPENSSL_INCLUDES such that source files should use the
21 # openssl/ directory in include directives:
22 #
23 # #include <openssl/hmac.h>
24 #
25 # LICENSE
26 #
27 # Copyright (c) 2009,2010 Zmanda Inc. <http://www.zmanda.com/>
28 # Copyright (c) 2009,2010 Dustin J. Mitchell <[email protected]>
29 #
30 # Copying and distribution of this file, with or without modification, are
31 # permitted in any medium without royalty provided the copyright notice
32 # and this notice are preserved. This file is offered as-is, without any
33 # warranty.
34
35 #serial 8
36
37 AU_ALIAS([CHECK_SSL], [AX_CHECK_OPENSSL])
38 AC_DEFUN([AX_CHECK_OPENSSL], [
39 found=false
40 skip=false
41 founddir=
42 ssldirs=
43 AC_ARG_WITH([openssl],
44 [AS_HELP_STRING([--with-openssl=DIR],
45 [root of the OpenSSL directory])],
46 [
47 case "$withval" in
48 n | no | N | NO)
49 skip=true
50 ;;
51 y | ye | yes | Y | YE | YES | "")
52 ;;
53 *)
54 ssldirs="$withval"
55 ;;
56 esac
57 ], []
58 )
59
60 # if pkg-config is installed and openssl has installed a .pc file,
61 # then use that information and don't search ssldirs
62 AC_PATH_PROG([PKG_CONFIG], [pkg-config])
63 if test x"$ssldirs" = x"" && test x"$PKG_CONFIG" != x""; then
64 OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null`
65 if test $? = 0; then
66 OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null`
67 OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 2>/dev/null`
68 founddir=`$PKG_CONFIG openssl --variable=includedir 2>/dev/null`
69 found=true
70 fi
71 fi
72
73 # no such luck; use some default ssldirs
74 if ! $found; then
75 ssldirs="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr"
76 fi
77
78 # note that we #include <openssl/foo.h>, so the OpenSSL headers have to be in
79 # an 'openssl' subdirectory
80
81 if ! $found && ! $skip; then
82 OPENSSL_INCLUDES=
83 for ssldir in $ssldirs; do
84 AC_MSG_CHECKING([for openssl/ssl.h in $ssldir])
85 if test -f "$ssldir/include/openssl/ssl.h"; then
86 OPENSSL_INCLUDES="-I$ssldir/include"
87 OPENSSL_LDFLAGS="-L$ssldir/lib"
88 OPENSSL_LIBS="-lssl -lcrypto"
89 founddir="$ssldir/include"
90 found=true
91 AC_MSG_RESULT([yes])
92 break
93 else
94 AC_MSG_RESULT([no])
95 fi
96 done
97 fi
98
99 # if the file wasn't found, well, go ahead and try the link anyway -- maybe
100 # it will just work!
101
102 # try the preprocessor and linker with our new flags,
103 # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
104
105 if ! $skip; then
106 AC_MSG_CHECKING([whether compiling and linking against OpenSSL works])
107 echo "Trying link with OPENSSL_LDFLAGS=$OPENSSL_LDFLAGS;" \
108 "OPENSSL_LIBS=$OPENSSL_LIBS; OPENSSL_INCLUDES=$OPENSSL_INCLUDES" >&AS_MESSAGE_LOG_FD
109
110 save_LIBS="$LIBS"
111 save_LDFLAGS="$LDFLAGS"
112 save_CPPFLAGS="$CPPFLAGS"
113 LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS"
114 LIBS="$OPENSSL_LIBS $LIBS"
115 CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS"
116 AC_LINK_IFELSE(
117 [AC_LANG_PROGRAM([#include <openssl/ssl.h>], [SSL_new(NULL)])],
118 [
119 AC_MSG_RESULT([yes])
120 $1
121 ], [
122 AC_MSG_RESULT([no])
123 $2
124 ])
125 CPPFLAGS="$save_CPPFLAGS"
126 LDFLAGS="$save_LDFLAGS"
127 LIBS="$save_LIBS"
128
129 if test -f "$founddir/openssl/ec.h"; then
130 AC_DEFINE([OPENSSL_EC_AVAILABLE], [1], [Whether openssl/ec.h exists])
131 fi
132
133 AC_SUBST([OPENSSL_INCLUDES])
134 AC_SUBST([OPENSSL_LIBS])
135 AC_SUBST([OPENSSL_LDFLAGS])
136 fi
137 ])