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