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