annotate m4/ax_check_openssl.m4 @ 57:748dd8a2e3a2

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