annotate m4/ax_check_openssl.m4 @ 1497:0b639858200b

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