From 4ddfb0080bca10093774142e79fbe97eeb056782 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 1 Nov 2014 14:09:33 +0530 Subject: [PATCH] use pkg-config to check for libraries Newer versions of zlib, openssl, gnutls, libuuid and pcre packages ship with pkg-config files, so if we can detect it via those, do so. If that fails, fall back to the old methods. --- ChangeLog | 4 ++ configure.ac | 203 ++++++++++++++++++++++++++++++++++++----------------------- 2 files changed, 129 insertions(+), 78 deletions(-) diff --git a/ChangeLog b/ChangeLog index 87366e4..7d8b2f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-11-01 Mike Frysinger + + * configure.ac: Use pkg-config to search for zlib, openssl, gnutls, libuuid and pcre + 2014-11-01 Darshit Shah * configure.ac: Fix check for libpsl diff --git a/configure.ac b/configure.ac index 5d063df..01d3eef 100644 --- a/configure.ac +++ b/configure.ac @@ -265,48 +265,64 @@ dnl dnl Checks for libraries. dnl +PKG_PROG_PKG_CONFIG + AS_IF([test x"$with_zlib" != xno], [ with_zlib=yes - AC_CHECK_LIB(z, compress) + PKG_CHECK_MODULES([ZLIB], zlib, [ + LIBS="$ZLIB_LIBS $LIBS" + CFLAGS="$ZLIB_CFLAGS $CFLAGS" + AC_DEFINE([HAVE_LIBZ], [1], [Define if using zlib.]) + ], [ + AC_CHECK_LIB(z, compress) + ]) ]) AS_IF([test x"$with_ssl" = xopenssl], [ - dnl As of this writing (OpenSSL 0.9.6), the libcrypto shared library - dnl doesn't record its dependency on libdl, so we need to make sure - dnl -ldl ends up in LIBS on systems that have it. Most OSes use - dnl dlopen(), but HP-UX uses shl_load(). - AC_CHECK_LIB(dl, dlopen, [], [ - AC_CHECK_LIB(dl, shl_load) - ]) - - ssl_found=no - case $host_os in - *mingw32* ) - dnl prefer link to openssl dlls if possible. if not then fallback on static libs. if not then error - - AC_CHECK_LIB(eay32, EVP_MD_CTX_init) - if test x"$ac_cv_lib_eay32_EVP_MD_CTX_init" != xno - then - AC_CHECK_LIB(ssl32, SSL_connect, [ - ssl_found=yes - AC_MSG_NOTICE([Enabling support for SSL via OpenSSL (shared)]) - AC_LIBOBJ([openssl]) - LIBS="${LIBS} -lssl32" - AC_DEFINE([HAVE_LIBSSL32], [1], [Define to 1 if you have the `ssl32' library (-lssl32).]) - ], - AC_MSG_ERROR([openssl not found: shared lib eay32 found but ssl32 not found])) - - else - LIBS+=' -lgdi32' - dnl fallback and test static libs - fi - dnl add zdll lib as dep for above tests? - ;; - esac + PKG_CHECK_MODULES([OPENSSL], [openssl], [ + AC_MSG_NOTICE([compiling in support for SSL via OpenSSL]) + AC_LIBOBJ([openssl]) + LIBS="$OPENSSL_LIBS $LIBS" + CFLAGS="$OPENSSL_CFLAGS -DHAVE_LIBSSL $CFLAGS" + LIBSSL=" " # ntlm check below wants this + AC_DEFINE([HAVE_LIBSSL], [1], [Define if using openssl.]) + ], [ + dnl As of this writing (OpenSSL 0.9.6), the libcrypto shared library + dnl doesn't record its dependency on libdl, so we need to make sure + dnl -ldl ends up in LIBS on systems that have it. Most OSes use + dnl dlopen(), but HP-UX uses shl_load(). + AC_CHECK_LIB(dl, dlopen, [], [ + AC_CHECK_LIB(dl, shl_load) + ]) + + ssl_found=no + case $host_os in + *mingw32* ) + dnl prefer link to openssl dlls if possible. if not then fallback on static libs. if not then error + + AC_CHECK_LIB(eay32, EVP_MD_CTX_init) + if test x"$ac_cv_lib_eay32_EVP_MD_CTX_init" != xno + then + AC_CHECK_LIB(ssl32, SSL_connect, [ + ssl_found=yes + AC_MSG_NOTICE([Enabling support for SSL via OpenSSL (shared)]) + AC_LIBOBJ([openssl]) + LIBS="${LIBS} -lssl32" + AC_DEFINE([HAVE_LIBSSL32], [1], [Define to 1 if you have the `ssl32' library (-lssl32).]) + ], + AC_MSG_ERROR([openssl not found: shared lib eay32 found but ssl32 not found])) + + else + LIBS+=' -lgdi32' + dnl fallback and test static libs + fi + dnl add zdll lib as dep for above tests? + ;; + esac - AS_IF([test x$ssl_found != xyes], [ - dnl Now actually check for -lssl if it wasn't already found - AC_LIB_HAVE_LINKFLAGS([ssl], [crypto], [ + AS_IF([test x$ssl_found != xyes], [ + dnl Now actually check for -lssl if it wasn't already found + AC_LIB_HAVE_LINKFLAGS([ssl], [crypto], [ #include #include #include @@ -314,19 +330,19 @@ AS_IF([test x"$with_ssl" = xopenssl], [ #include #include #include - ], [SSL_library_init ()]) - if test x"$LIBSSL" != x - then - ssl_found=yes - AC_MSG_NOTICE([compiling in support for SSL via OpenSSL]) - AC_LIBOBJ([openssl]) - LIBS="$LIBSSL $LIBS" - elif test x"$with_ssl" != x - then - AC_MSG_ERROR([--with-ssl=openssl was given, but SSL is not available.]) - fi + ], [SSL_library_init ()]) + if test x"$LIBSSL" != x + then + ssl_found=yes + AC_MSG_NOTICE([compiling in support for SSL via OpenSSL]) + AC_LIBOBJ([openssl]) + LIBS="$LIBSSL $LIBS" + elif test x"$with_ssl" != x + then + AC_MSG_ERROR([--with-ssl=openssl was given, but SSL is not available.]) + fi + ]) ]) - ], [ # --with-ssl is not openssl: check if it's no AS_IF([test x"$with_ssl" != xno], [ @@ -334,18 +350,26 @@ AS_IF([test x"$with_ssl" = xopenssl], [ with_ssl=gnutls dnl Now actually check for -lgnutls - AC_LIB_HAVE_LINKFLAGS([gnutls], [], [ -#include - ], [gnutls_global_init()]) - if test x"$LIBGNUTLS" != x - then - ssl_found=yes + PKG_CHECK_MODULES([GNUTLS], [gnutls], [ AC_MSG_NOTICE([compiling in support for SSL via GnuTLS]) AC_LIBOBJ([gnutls]) - LIBS="$LIBGNUTLS $LIBS" - else - AC_MSG_ERROR([--with-ssl=gnutls was given, but GNUTLS is not available.]) - fi + LIBS="$GNUTLS_LIBS $LIBS" + CFLAGS="$GNUTLS_CFLAGS -DHAVE_LIBGNUTLS $CFLAGS" + AC_DEFINE([HAVE_LIBGNUTLS], [1], [Define if using gnutls.]) + ], [ + AC_LIB_HAVE_LINKFLAGS([gnutls], [], [ +#include + ], [gnutls_global_init()]) + if test x"$LIBGNUTLS" != x + then + ssl_found=yes + AC_MSG_NOTICE([compiling in support for SSL via GnuTLS]) + AC_LIBOBJ([gnutls]) + LIBS="$LIBGNUTLS $LIBS" + else + AC_MSG_ERROR([--with-ssl=gnutls was given, but GNUTLS is not available.]) + fi + ]) AC_CHECK_FUNCS(gnutls_priority_set_direct) ]) # endif: --with-ssl != no? @@ -563,32 +587,55 @@ fi dnl dnl Check for UUID dnl -AC_CHECK_HEADER(uuid.h, - AC_CHECK_FUNC(uuid, uuid_create, - [AC_DEFINE([HAVE_UUID_CREATE], 1, - [Define if uuid_create is available.]) - ]) -) -AC_CHECK_HEADER(uuid/uuid.h, - AC_CHECK_LIB(uuid, uuid_generate, - [LIBS="${LIBS} -luuid" - AC_DEFINE([HAVE_LIBUUID], 1, - [Define if libuuid is available.]) - ]) -) +AC_ARG_WITH(libuuid, AC_HELP_STRING([--without-libuuid], + [Generate UUIDs for WARC files via libuuid])) + +AS_IF([test "X$with_libuuid" != "Xno"],[ + PKG_CHECK_MODULES([UUID], uuid, [ + LIBS="$UUID_LIBS $LIBS" + CFLAGS="$UUID_CFLAGS $CFLAGS" + AC_DEFINE([HAVE_LIBUUID], [1], [Define if using libuuid.]) + ], [ + AC_CHECK_HEADER(uuid.h, + AC_CHECK_FUNC(uuid, uuid_create, + [AC_DEFINE([HAVE_UUID_CREATE], 1, + [Define if uuid_create is available.]) + ]) + ) + + AC_CHECK_HEADER(uuid/uuid.h, + AC_CHECK_LIB(uuid, uuid_generate, + [LIBS="${LIBS} -luuid" + AC_DEFINE([HAVE_LIBUUID], 1, + [Define if libuuid is available.]) + ]) + ) + ]) +]) dnl dnl Check for PCRE dnl -AC_CHECK_HEADER(pcre.h, - AC_CHECK_LIB(pcre, pcre_compile, - [LIBS="${LIBS} -lpcre" - AC_DEFINE([HAVE_LIBPCRE], 1, - [Define if libpcre is available.]) - ]) -) +AC_ARG_ENABLE(pcre, AC_HELP_STRING([--disable-pcre], + [Disable PCRE style regular expressions])) + +AS_IF([test "X$enable_pcre" != "Xno"],[ + PKG_CHECK_MODULES([PCRE], libpcre, [ + LIBS="$PCRE_LIBS $LIBS" + CFLAGS="$PCRE_CFLAGS $CFLAGS" + AC_DEFINE([HAVE_LIBPCRE], [1], [Define if using libpcre.]) + ], [ + AC_CHECK_HEADER(pcre.h, + AC_CHECK_LIB(pcre, pcre_compile, + [LIBS="${LIBS} -lpcre" + AC_DEFINE([HAVE_LIBPCRE], 1, + [Define if libpcre is available.]) + ]) + ) + ]) +]) dnl Needed by src/Makefile.am -- 2.1.3