adam@1368: # =========================================================================== adam@1368: # http://www.gnu.org/software/autoconf-archive/ax_check_openssl.html adam@1368: # =========================================================================== adam@1368: # adam@1368: # SYNOPSIS adam@1368: # adam@1368: # AX_CHECK_OPENSSL([action-if-found[, action-if-not-found]]) adam@1368: # adam@1368: # DESCRIPTION adam@1368: # adam@1368: # Look for OpenSSL in a number of default spots, or in a user-selected adam@1368: # spot (via --with-openssl). Sets adam@1368: # adam@1368: # OPENSSL_INCLUDES to the include directives required adam@1368: # OPENSSL_LIBS to the -l directives required adam@1368: # OPENSSL_LDFLAGS to the -L or -R flags required adam@1368: # adam@1368: # and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately adam@1368: # adam@1368: # This macro sets OPENSSL_INCLUDES such that source files should use the adam@1368: # openssl/ directory in include directives: adam@1368: # adam@1368: # #include adam@1368: # adam@1368: # LICENSE adam@1368: # adam@1368: # Copyright (c) 2009,2010 Zmanda Inc. adam@1368: # Copyright (c) 2009,2010 Dustin J. Mitchell adam@1368: # adam@1368: # Copying and distribution of this file, with or without modification, are adam@1368: # permitted in any medium without royalty provided the copyright notice adam@1368: # and this notice are preserved. This file is offered as-is, without any adam@1368: # warranty. adam@1368: adam@1368: #serial 7 adam@1368: adam@1368: AU_ALIAS([CHECK_SSL], [AX_CHECK_OPENSSL]) adam@1368: AC_DEFUN([AX_CHECK_OPENSSL], [ adam@1368: found=false adam@1368: AC_ARG_WITH(openssl, adam@1368: AS_HELP_STRING([--with-openssl=DIR], adam@1368: [root of the OpenSSL directory]), adam@1368: [ adam@1368: case "$withval" in adam@1368: "" | y | ye | yes | n | no) adam@1368: AC_MSG_ERROR([Invalid --with-openssl value]) adam@1368: ;; adam@1368: *) ssldirs="$withval" adam@1368: ;; adam@1368: esac adam@1368: ], [ adam@1368: # if pkg-config is installed and openssl has installed a .pc file, adam@1368: # then use that information and don't search ssldirs adam@1368: AC_PATH_PROG(PKG_CONFIG, pkg-config) adam@1368: if test x"$PKG_CONFIG" != x""; then adam@1368: OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null` adam@1368: if test $? = 0; then adam@1368: OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null` adam@1368: OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 2>/dev/null` adam@1368: found=true adam@1368: fi adam@1368: fi adam@1368: adam@1368: # no such luck; use some default ssldirs adam@1368: if ! $found; then adam@1368: ssldirs="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr" adam@1368: fi adam@1368: ] adam@1368: ) adam@1368: adam@1368: adam@1368: # note that we #include , so the OpenSSL headers have to be in adam@1368: # an 'openssl' subdirectory adam@1368: adam@1368: if ! $found; then adam@1368: OPENSSL_INCLUDES= adam@1368: for ssldir in $ssldirs; do adam@1368: AC_MSG_CHECKING([for openssl/ssl.h in $ssldir]) adam@1368: if test -f "$ssldir/include/openssl/ssl.h"; then adam@1368: OPENSSL_INCLUDES="-I$ssldir/include" adam@1368: OPENSSL_LDFLAGS="-L$ssldir/lib" adam@1368: OPENSSL_LIBS="-lssl -lcrypto" adam@1368: found=true adam@1368: AC_MSG_RESULT([yes]) adam@1368: break adam@1368: else adam@1368: AC_MSG_RESULT([no]) adam@1368: fi adam@1368: done adam@1368: adam@1368: # if the file wasn't found, well, go ahead and try the link anyway -- maybe adam@1368: # it will just work! adam@1368: fi adam@1368: adam@1368: # try the preprocessor and linker with our new flags, adam@1368: # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS adam@1368: adam@1368: AC_MSG_CHECKING([whether compiling and linking against OpenSSL works]) adam@1368: echo "Trying link with OPENSSL_LDFLAGS=$OPENSSL_LDFLAGS;" \ adam@1368: "OPENSSL_LIBS=$OPENSSL_LIBS; OPENSSL_INCLUDES=$OPENSSL_INCLUDES" >&AS_MESSAGE_LOG_FD adam@1368: adam@1368: save_LIBS="$LIBS" adam@1368: save_LDFLAGS="$LDFLAGS" adam@1368: save_CPPFLAGS="$CPPFLAGS" adam@1368: LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS" adam@1368: LIBS="$OPENSSL_LIBS $LIBS" adam@1368: CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS" adam@1368: AC_LINK_IFELSE( adam@1368: AC_LANG_PROGRAM([#include ], [SSL_new(NULL)]), adam@1368: [ adam@1368: AC_MSG_RESULT([yes]) adam@1368: $1 adam@1368: ], [ adam@1368: AC_MSG_RESULT([no]) adam@1368: $2 adam@1368: ]) adam@1368: CPPFLAGS="$save_CPPFLAGS" adam@1368: LDFLAGS="$save_LDFLAGS" adam@1368: LIBS="$save_LIBS" adam@1368: adam@1368: AC_SUBST([OPENSSL_INCLUDES]) adam@1368: AC_SUBST([OPENSSL_LIBS]) adam@1368: AC_SUBST([OPENSSL_LDFLAGS]) adam@1368: ])