From 02985711df432e5fa8349cec5a05f0445c1d48b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sat, 12 Nov 2016 21:38:42 +0100 Subject: [PATCH] configure: Use pkg-config to find libs whenever possible Use pkg-config to find cppunit, libxml2 and expat. All those libraries provide pkg-config files, and in all of those cases the pkg-config macro is superior to the custom macros used currently. The advantages of pkg-config files include: - Explicit static linking support via --static. Currently, e.g. 'xml2-config --libs' prints all libraries needed for static linking when doing dynamic linking unnecessary, resulting in unnecessary direct deps. - Better cross-build support. You don't have to build the additional *-config tools for target. - Better multilib support. Per-ABI pkgconfig directories are commonly supported while packages usually fail to look for per-CHOST *-config variants. - Better override support. The current macros allow little to no result overrides, the pkg-config macros let you pass FOO_CFLAGS and FOO_LIBS manually. - Cleaner version checks. The code used in libxml.m4 is really creepy. --- configure.ac | 32 ++++++++++---------------------- m4/libexpat.m4 | 19 ------------------- src/Makefile.am | 4 ++-- test/Makefile.am | 4 ++-- 4 files changed, 14 insertions(+), 45 deletions(-) delete mode 100644 m4/libexpat.m4 diff --git a/configure.ac b/configure.ac index 57100395..9cd3fc7b 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,6 @@ AC_SUBST(LT_REVISION, 0) AC_SUBST(LT_AGE, 0) AC_CONFIG_MACRO_DIR([m4]) -m4_ifdef([AM_PATH_CPPUNIT], [AM_PATH_CPPUNIT(1.10.2)]) AC_CONFIG_SRCDIR([src/a2io.h]) AC_CONFIG_HEADERS([config.h]) @@ -202,6 +201,9 @@ fi # Checks for libraries. +# Check availability of cppunit +PKG_CHECK_MODULES([CPPUNIT], [cppunit >= 1.10.2], [], []) + # Check availability of libz if test "x$with_libz" = "xyes"; then PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.3], [have_zlib=yes], [have_zlib=no]) @@ -318,13 +320,7 @@ AM_CONDITIONAL([HAVE_LIBUV], [test "x$have_libuv" = "xyes"]) have_libxml2=no if test "x$with_libxml2" = "xyes"; then - m4_ifdef([AM_PATH_XML2], [AM_PATH_XML2([2.6.24], [have_libxml2=yes])], [ - AC_MSG_WARN([configure was generated without libxml2 detection. libxml2 detection is disabled]) - XML_CPPFLAGS= - XML_LIBS= - AC_SUBST([XML_CPPFLAGS]) - AC_SUBST([XML_LIBS]) - ]) + PKG_CHECK_MODULES([LIBXML2],[libxml-2.0 >= 2.6.24],[have_libxml2=yes],[have_libxml2=no]) if test "x$have_libxml2" = "xyes"; then AC_DEFINE([HAVE_LIBXML2], [1], [Define to 1 if you have libxml2.]) elif test "x$with_libxml2_requested" = "xyes"; then @@ -334,13 +330,7 @@ fi have_libexpat=no if test "x$with_libexpat" = "xyes" && test "x$have_libxml2" != "xyes"; then - m4_ifdef([AM_PATH_LIBEXPAT], [AM_PATH_LIBEXPAT], [ - AC_MSG_WARN([configure was generated without libexpat detection. libexpat detection is disabled]) - EXPAT_CFLAGS= - EXPAT_LIBS= - AC_SUBST([EXPAT_CFLAGS]) - AC_SUBST([EXPAT_LIBS]) - ]) + PKG_CHECK_MODULES([EXPAT],[expat],[have_libexpat=yes],[have_libexpat=no]) if test "x$have_libexpat" != "xyes" && test "x$with_libexpat_requested" = "xyes"; then ARIA2_DEP_NOT_MET([libexpat]) @@ -511,14 +501,12 @@ have_libgcrypt=no if test "x$have_openssl" != "xyes"; then if test "x$with_libnettle" = "xyes" && test "x$have_nativetls" != "xyes"; then - AC_CHECK_LIB([nettle], [nettle_sha1_init], - [have_libnettle=yes], [have_libnettle=no]) + PKG_CHECK_MODULES([LIBNETTLE], [nettle], + [have_libnettle=yes], [have_libnettle=no]) if test "x$have_libnettle" = "xyes"; then - LIBNETTLE_CFLAGS= - LIBNETTLE_LIBS="-lnettle" - AC_SUBST([LIBNETTLE_CFLAGS]) - AC_SUBST([LIBNETTLE_LIBS]) AC_DEFINE([HAVE_LIBNETTLE], [1], [Define to 1 if you have libnettle.]) + elif test "x$with_libnettle_requested" = "xyes"; then + ARIA2_DEP_NOT_MET([nettle]) fi fi if test "x$with_libgmp" = "xyes" && @@ -1229,7 +1217,7 @@ CA Bundle: $ca_bundle LibNettle: $have_libnettle (CFLAGS='$LIBNETTLE_CFLAGS' LIBS='$LIBNETTLE_LIBS') LibGmp: $have_libgmp (CFLAGS='$LIBGMP_CFLAGS' LIBS='$LIBGMP_LIBS') LibGcrypt: $have_libgcrypt (CFLAGS='$LIBGCRYPT_CFLAGS' LIBS='$LIBGCRYPT_LIBS') -LibXML2: $have_libxml2 (CFLAGS='$XML_CPPFLAGS' LIBS='$XML_LIBS') +LibXML2: $have_libxml2 (CFLAGS='$LIBXML2_CFLAGS' LIBS='$LIBXML2_LIBS') LibExpat: $have_libexpat (CFLAGS='$EXPAT_CFLAGS' LIBS='$EXPAT_LIBS') LibCares: $have_libcares (CFLAGS='$LIBCARES_CFLAGS' LIBS='$LIBCARES_LIBS') Zlib: $have_zlib (CFLAGS='$ZLIB_CFLAGS' LIBS='$ZLIB_LIBS') diff --git a/m4/libexpat.m4 b/m4/libexpat.m4 deleted file mode 100644 index cee8a96a..00000000 --- a/m4/libexpat.m4 +++ /dev/null @@ -1,19 +0,0 @@ -AC_DEFUN([AM_PATH_LIBEXPAT], -[ -LIBS_save=$LIBS -CPPFLAGS_save=$CPPFLAGS - -LIBS="-lexpat $LIBS" -AC_CHECK_LIB([expat], [XML_ParserCreate], [have_libexpat=yes]) -if test "x$have_libexpat" = "xyes"; then - AC_DEFINE([HAVE_LIBEXPAT], [1], [Define to 1 if you have libexpat.]) - EXPAT_LIBS=-lexpat - EXPAT_CFLAGS= - AC_SUBST([EXPAT_LIBS]) - AC_SUBST([EXPAT_CFLAGS]) -fi - -LIBS=$LIBS_save -CPPFLAGS=$CPPFLAGS_save - -]) diff --git a/src/Makefile.am b/src/Makefile.am index 634e4796..9322112c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -711,7 +711,7 @@ AM_CPPFLAGS = \ @EXTRACPPFLAGS@ \ @ZLIB_CFLAGS@ \ @LIBUV_CFLAGS@ \ - @XML_CPPFLAGS@ \ + @LIBXML2_CFLAGS@ \ @EXPAT_CFLAGS@ \ @SQLITE3_CFLAGS@ \ @LIBGNUTLS_CFLAGS@ \ @@ -733,7 +733,7 @@ EXTLDADD = @ALLOCA@ \ @EXTRALIBS@ \ @ZLIB_LIBS@ \ @LIBUV_LIBS@ \ - @XML_LIBS@ \ + @LIBXML2_LIBS@ \ @EXPAT_LIBS@ \ @SQLITE3_LIBS@ \ @WINTLS_LIBS@ \ diff --git a/test/Makefile.am b/test/Makefile.am index 48a962ec..c7114449 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -246,7 +246,7 @@ aria2c_LDADD = \ @EXTRALIBS@ \ @ZLIB_LIBS@ \ @LIBUV_LIBS@ \ - @XML_LIBS@ \ + @LIBXML2_LIBS@ \ @EXPAT_LIBS@ \ @SQLITE3_LIBS@ \ @WINTLS_LIBS@ \ @@ -274,7 +274,7 @@ AM_CPPFLAGS = \ @EXTRACPPFLAGS@ \ @ZLIB_CFLAGS@ \ @LIBUV_CFLAGS@ \ - @XML_CPPFLAGS@ \ + @LIBXML2_CFLAGS@ \ @EXPAT_CFLAGS@ \ @SQLITE3_CFLAGS@ \ @LIBGNUTLS_CFLAGS@ \