From: Guy Harris Date: Sun, 13 Jan 2019 23:10:49 +0000 (-0800) Subject: Check for OpenSSL/libressl as a system library first. X-Git-Tag: libpcap-1.10-bp~610 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/9c395d488be64aa5fa79663c0d7b37b4e5198caf Check for OpenSSL/libressl as a system library first. Make sure we don't get non-usable system libraries, such as the one in later versions of macOS. --- diff --git a/configure b/configure index 3736f405..1231aed5 100755 --- a/configure +++ b/configure @@ -7788,86 +7788,75 @@ fi # Optionally, we may want to support SSL. # Check for OpenSSL/libressl. # - # We check for it first with pkg-config, in case you're - # unlucky enough to be running on one of the versions - # of macOS where Apple decided to get everybody to use - # their Shiny New SSL and took away the OpenSSL header - # files, even though they keep the shared libraries - # around for binary compatibility, and installed your - # own version. + # First, try looking for it as a regular system library. + # Make sure we can find SSL_library_init() using the + # standard headers, just in case we're running a version + # of macOS that ships with the OpenSSL library but not + # the OpenSSL headers, and have also installed another + # version of OpenSSL with headers. # - if test "x$PKGCONFIG" != "xno"; then - # - # We have pkg-config; see if we have it installed - # as a package. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for OpenSSL/libressl with pkg-config" >&5 -$as_echo_n "checking for OpenSSL/libressl with pkg-config... " >&6; } - if "$PKGCONFIG" openssl; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: found" >&5 -$as_echo "found" >&6; } - OPENSSL_CFLAGS=`"$PKGCONFIG" --cflags openssl` - OPENSSL_LIBS=`"$PKGCONFIG" --libs openssl` - HAVE_OPENSSL=yes - else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5 -$as_echo "not found" >&6; } - fi - fi - if test "x$HAVE_OPENSSL" != "xyes"; then - # - # We didn't find it as a package; try looking for - # it as a regular system library. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SSL_library_init in -lssl" >&5 -$as_echo_n "checking for SSL_library_init in -lssl... " >&6; } -if ${ac_cv_lib_ssl_SSL_library_init+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lssl $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext + save_LIBS="$LIBS" + LIBS="-lssl -lcrypto" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we have a system OpenSSL/libressl that we can use" >&5 +$as_echo_n "checking whether we have a system OpenSSL/libressl that we can use... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char SSL_library_init (); +#include + int main () { -return SSL_library_init (); + +SSL_library_init(); +return 0; + ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_ssl_SSL_library_init=yes + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + HAVE_OPENSSL=yes + OPENSSL_LIBS="-lssl -lcrypto" + else - ac_cv_lib_ssl_SSL_library_init=no + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ssl_SSL_library_init" >&5 -$as_echo "$ac_cv_lib_ssl_SSL_library_init" >&6; } -if test "x$ac_cv_lib_ssl_SSL_library_init" = xyes; then : + LIBS="$save_LIBS" + # + # If we didn't find it, check for it with pkg-config. + # + if test "x$HAVE_OPENSSL" != "xyes"; then + if test "x$PKGCONFIG" != "xno"; then # - # Yes - add -lssl. + # We have pkg-config; see if we have OpenSSL/ + # libressl installed as a package. # - HAVE_OPENSSL=yes - OPENSSL_LIBS="-lssl -lcrypto" - -else - -lcrypto -fi - + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for OpenSSL/libressl with pkg-config" >&5 +$as_echo_n "checking for OpenSSL/libressl with pkg-config... " >&6; } + if "$PKGCONFIG" openssl; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: found" >&5 +$as_echo "found" >&6; } + HAVE_OPENSSL=yes + OPENSSL_CFLAGS=`"$PKGCONFIG" --cflags openssl` + OPENSSL_LIBS=`"$PKGCONFIG" --libs openssl` + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5 +$as_echo "not found" >&6; } + fi + fi fi + + # + # OK, did we find it? + # if test "x$HAVE_OPENSSL" = "xyes"; then $as_echo "#define HAVE_OPENSSL 1" >>confdefs.h diff --git a/configure.ac b/configure.ac index 3f22dc4c..968cc6b2 100644 --- a/configure.ac +++ b/configure.ac @@ -1501,43 +1501,56 @@ yes) AC_MSG_RESULT(yes) # Optionally, we may want to support SSL. # Check for OpenSSL/libressl. # - # We check for it first with pkg-config, in case you're - # unlucky enough to be running on one of the versions - # of macOS where Apple decided to get everybody to use - # their Shiny New SSL and took away the OpenSSL header - # files, even though they keep the shared libraries - # around for binary compatibility, and installed your - # own version. + # First, try looking for it as a regular system library. + # Make sure we can find SSL_library_init() using the + # standard headers, just in case we're running a version + # of macOS that ships with the OpenSSL library but not + # the OpenSSL headers, and have also installed another + # version of OpenSSL with headers. + # + save_LIBS="$LIBS" + LIBS="-lssl -lcrypto" + AC_MSG_CHECKING(whether we have a system OpenSSL/libressl that we can use) + AC_TRY_LINK( + [ +#include + ], + [ +SSL_library_init(); +return 0; + ], + [ + AC_MSG_RESULT(yes) + HAVE_OPENSSL=yes + OPENSSL_LIBS="-lssl -lcrypto" + ], + AC_MSG_RESULT(no)) + LIBS="$save_LIBS" + + # + # If we didn't find it, check for it with pkg-config. # - if test "x$PKGCONFIG" != "xno"; then - # - # We have pkg-config; see if we have it installed - # as a package. - # - AC_MSG_CHECKING([for OpenSSL/libressl with pkg-config]) - if "$PKGCONFIG" openssl; then - AC_MSG_RESULT([found]) - OPENSSL_CFLAGS=`"$PKGCONFIG" --cflags openssl` - OPENSSL_LIBS=`"$PKGCONFIG" --libs openssl` - HAVE_OPENSSL=yes - else - AC_MSG_RESULT([not found]) - fi - fi if test "x$HAVE_OPENSSL" != "xyes"; then - # - # We didn't find it as a package; try looking for - # it as a regular system library. - # - AC_CHECK_LIB(ssl, SSL_library_init, - [ + if test "x$PKGCONFIG" != "xno"; then # - # Yes - add -lssl. + # We have pkg-config; see if we have OpenSSL/ + # libressl installed as a package. # - HAVE_OPENSSL=yes - OPENSSL_LIBS="-lssl -lcrypto" - ], -lcrypto) + AC_MSG_CHECKING([for OpenSSL/libressl with pkg-config]) + if "$PKGCONFIG" openssl; then + AC_MSG_RESULT([found]) + HAVE_OPENSSL=yes + OPENSSL_CFLAGS=`"$PKGCONFIG" --cflags openssl` + OPENSSL_LIBS=`"$PKGCONFIG" --libs openssl` + else + AC_MSG_RESULT([not found]) + fi + fi fi + + # + # OK, did we find it? + # if test "x$HAVE_OPENSSL" = "xyes"; then AC_DEFINE([HAVE_OPENSSL], [1], [Use OpenSSL]) CFLAGS="$CFLAGS $OPENSSL_CFLAGS"