Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,94 @@ else
AC_MSG_ERROR([Cannot find a type with size of 64 bits])
fi])

dnl
dnl Macro: unet_TLS
dnl
dnl Set unet_cv_with_tls and TLS_C to an available TLS implementation.
dnl
AC_DEFUN([unet_TLS],
[dnl Perform some preliminary checks for system TLS libraries.
AX_CHECK_OPENSSL(, [:])
PKG_CHECK_MODULES([GNUTLS], [gnutls], , [:])

dnl --with-tls allows selection of the TLS library.
AC_MSG_CHECKING([for a TLS library])
AC_ARG_WITH([tls],
[ --with-tls=library TLS library to use (none, openssl, gnutls, libtls)],
[unet_cv_with_tls=$with_tls],
[AC_CACHE_VAL(unet_cv_with_tls,
[unet_cv_with_tls=yes])])
TLS_C=""

dnl If --with-tls or --with-tls=yes, try to autodetect: OpenSSL first.
if test x"$unet_cv_with_tls" = xyes ; then
if test x"$OPENSSL_LIBS" != x ; then
unet_cv_with_tls=openssl
fi
fi
dnl Try gnutls next.
if test x"$unet_cv_with_tls" = xyes ; then
if test x"$GNUTLS_LIBS" != x ; then
unet_cv_with_tls=gnutls
fi
fi
dnl Try libtls next.
if test x"$unet_cv_with_tls" = xyes ; then
dnl Temporarily disable pkg-config to force fallback path
dnl PKG_CHECK_MODULES([LIBTLS], [libtls], [
dnl unet_cv_with_tls=libtls
dnl ], [
dnl Fallback for OpenBSD base (no .pc): header + symbol link test.
AC_CHECK_HEADER([tls.h], [
AC_CHECK_LIB([tls], [tls_init], [
unet_cv_with_tls=libtls
LIBTLS_LIBS="-ltls"
LIBTLS_CFLAGS=""
LIBTLS_LDFLAGS=""
])
])
dnl ])
fi

case x"$unet_cv_with_tls" in
xopenssl)
CFLAGS="$CFLAGS $OPENSSL_CFLAGS"
LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS"
LIBS="$LIBS $OPENSSL_LIBS"
TLS_C="tls_openssl.c"
;;
xgnutls)
CFLAGS="$CFLAGS $GNUTLS_CFLAGS"
LDFLAGS="$LDFLAGS $GNUTLS_LDFLAGS"
LIBS="$LIBS $GNUTLS_LIBS"
TLS_C="tls_gnutls.c"
;;
xlibtls)
# Ensure LIBTLS_LIBS is set even when explicitly specified
if test x"$LIBTLS_LIBS" = x ; then
LIBTLS_LIBS="-ltls"
fi
CFLAGS="$CFLAGS $LIBTLS_CFLAGS"
LDFLAGS="$LDFLAGS $LIBTLS_LDFLAGS"
LIBS="$LIBS $LIBTLS_LIBS"
TLS_C="tls_libtls.c"
;;
xyes|xno)
unet_cv_with_tls="none"
TLS_C="tls_none.c"
;;
esac
if test x"$TLS_C" = x ; then
AC_MSG_WARN([Unknown TLS library $unet_cv_with_tls])
TLS_C="tls_none.c"
fi
AC_MSG_RESULT([$unet_cv_with_tls])
AC_SUBST([TLS_C])

if test x"$unet_cv_with_tls" = xopenssl ; then
AC_CHECK_FUNCS([SSL_set_ciphersuites])
fi])

dnl Written by John Hawkinson <[email protected]>. This code is in the Public
dnl Domain.
dnl
Expand Down
125 changes: 125 additions & 0 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,131 @@
# PARTICULAR PURPOSE.

m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_check_openssl.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_CHECK_OPENSSL([action-if-found[, action-if-not-found]])
#
# DESCRIPTION
#
# Look for OpenSSL in a number of default spots, or in a user-selected
# spot (via --with-openssl). Sets
#
# OPENSSL_INCLUDES to the include directives required
# OPENSSL_LIBS to the -l directives required
# OPENSSL_LDFLAGS to the -L or -R flags required
#
# and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
#
# This macro sets OPENSSL_INCLUDES such that source files should use the
# openssl/ directory in include directives:
#
# #include <openssl/hmac.h>
#
# LICENSE
#
# Copyright (c) 2009,2010 Zmanda Inc. <http://www.zmanda.com/>
# Copyright (c) 2009,2010 Dustin J. Mitchell <[email protected]>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 11

AU_ALIAS([CHECK_SSL], [AX_CHECK_OPENSSL])
AC_DEFUN([AX_CHECK_OPENSSL], [
found=false
AC_ARG_WITH([openssl],
[AS_HELP_STRING([--with-openssl=DIR],
[root of the OpenSSL directory])],
[
case "$withval" in
"" | y | ye | yes | n | no)
AC_MSG_ERROR([Invalid --with-openssl value])
;;
*) ssldirs="$withval"
;;
esac
], [
# if pkg-config is installed and openssl has installed a .pc file,
# then use that information and don't search ssldirs
AC_CHECK_TOOL([PKG_CONFIG], [pkg-config])
if test x"$PKG_CONFIG" != x""; then
OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null`
if test $? = 0; then
OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null`
OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 2>/dev/null`
found=true
fi
fi

# no such luck; use some default ssldirs
if ! $found; then
ssldirs="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr"
fi
]
)


# note that we #include <openssl/foo.h>, so the OpenSSL headers have to be in
# an 'openssl' subdirectory

if ! $found; then
OPENSSL_INCLUDES=
for ssldir in $ssldirs; do
AC_MSG_CHECKING([for include/openssl/ssl.h in $ssldir])
if test -f "$ssldir/include/openssl/ssl.h"; then
OPENSSL_INCLUDES="-I$ssldir/include"
OPENSSL_LDFLAGS="-L$ssldir/lib"
OPENSSL_LIBS="-lssl -lcrypto"
found=true
AC_MSG_RESULT([yes])
break
else
AC_MSG_RESULT([no])
fi
done

# if the file wasn't found, well, go ahead and try the link anyway -- maybe
# it will just work!
fi

# try the preprocessor and linker with our new flags,
# being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS

AC_MSG_CHECKING([whether compiling and linking against OpenSSL works])
echo "Trying link with OPENSSL_LDFLAGS=$OPENSSL_LDFLAGS;" \
"OPENSSL_LIBS=$OPENSSL_LIBS; OPENSSL_INCLUDES=$OPENSSL_INCLUDES" >&AS_MESSAGE_LOG_FD

save_LIBS="$LIBS"
save_LDFLAGS="$LDFLAGS"
save_CPPFLAGS="$CPPFLAGS"
LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS"
LIBS="$OPENSSL_LIBS $LIBS"
CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <openssl/ssl.h>], [SSL_new(NULL)])],
[
AC_MSG_RESULT([yes])
$1
], [
AC_MSG_RESULT([no])
$2
])
CPPFLAGS="$save_CPPFLAGS"
LDFLAGS="$save_LDFLAGS"
LIBS="$save_LIBS"

AC_SUBST([OPENSSL_INCLUDES])
AC_SUBST([OPENSSL_LIBS])
AC_SUBST([OPENSSL_LDFLAGS])
])

# pkg.m4 - Macros to locate and use pkg-config. -*- Autoconf -*-
# serial 12 (pkg-config-0.29.2)

Expand Down
Loading