From d307e38863af84f91fbfd83c05ac54a8cbf556aa Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 9 May 2016 09:51:05 +0100 Subject: [PATCH] add FIND_LIBWEBP some platforms are missing a .pc file for libwebp ... add a FIND_LIBWEBP macro as a fallback see https://github.com/jcupitt/libvips/issues/440 --- acinclude.m4 | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 13 ++++-- 2 files changed, 130 insertions(+), 3 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index d1bbc58f..3e260465 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -684,3 +684,123 @@ fi ])dnl + +dnl From FIND_MOTIF and ACX_PTHREAD, without much understanding +dnl +dnl FIND_LIBWEBP[ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]] +dnl --------------------------------------------------- +dnl +dnl Find webp libraries and headers ... useful for platforms which are missing +dnl the webp .pc file +dnl +dnl Put compile stuff in LIBWEBP_INCLUDES +dnl Put link stuff in LIBWEBP_LIBS +dnl Define HAVE_LIBWEBP if found. +dnl +AC_DEFUN([FIND_LIBWEBP], [ +AC_REQUIRE([AC_PATH_XTRA]) + +LIBWEBP_INCLUDES="" +LIBWEBP_LIBS="" + +AC_ARG_WITH(libwebp, + AS_HELP_STRING([--without-libwebp], [build without libwebp (default: test)])) +# Treat --without-libwebp like --without-libwebp-includes --without-libwebp-libraries. +if test "$with_libwebp" = "no"; then + LIBWEBP_INCLUDES=no + LIBWEBP_LIBS=no +fi + +AC_ARG_WITH(libwebp-includes, + AS_HELP_STRING([--with-libwebp-includes=DIR], [libwebp includes are in DIR]), + LIBWEBP_INCLUDES="-I$withval") +AC_ARG_WITH(libwebp-libraries, + AS_HELP_STRING([--with-libwebp-libraries=DIR], [libwebp libraries are in DIR]), + LIBWEBP_LIBS="-L$withval -lwebp") + +AC_MSG_CHECKING(for libwebp) + +# Look for webp/decode.h +if test "$LIBWEBP_INCLUDES" = ""; then + # Check the standard search path + AC_TRY_COMPILE([#include ],[int a;],[ + LIBWEBP_INCLUDES="" + ], [ + # webp/decode.h is not in the standard search path, try + # $prefix + libwebp_save_INCLUDES="$INCLUDES" + + INCLUDES="-I${prefix}/include $INCLUDES" + + AC_TRY_COMPILE([#include ],[int a;],[ + LIBWEBP_INCLUDES="-I${prefix}/include" + ], [ + LIBWEBP_INCLUDES="no" + ]) + + INCLUDES=$libwebp_save_INCLUDES + ]) +fi + +# Now for the libraries +if test "$LIBWEBP_LIBS" = ""; then + libwebp_save_LIBS="$LIBS" + libwebp_save_INCLUDES="$INCLUDES" + + LIBS="-lwebp $LIBS" + INCLUDES="$LIBWEBP_INCLUDES $INCLUDES" + + # Try the standard search path first + AC_TRY_LINK([#include ],[WebPInitDecoderConfig(0)], [ + LIBWEBP_LIBS="-lwebp" + ], [ + # libwebp is not in the standard search path, try $prefix + + LIBS="-L${prefix}/lib $LIBS" + + AC_TRY_LINK([#include ],[WebPInitDecoderConfig(0)], [ + LIBWEBP_LIBS="-L${prefix}/lib -lwebp" + ], [ + LIBWEBP_LIBS=no + ]) + ]) + + LIBS="$libwebp_save_LIBS" + INCLUDES="$libwebp_save_INCLUDES" +fi + +AC_SUBST(LIBWEBP_LIBS) +AC_SUBST(LIBWEBP_INCLUDES) + +# Print a helpful message +libwebp_libraries_result="$LIBWEBP_LIBS" +libwebp_includes_result="$LIBWEBP_INCLUDES" + +if test x"$libwebp_libraries_result" = x""; then + libwebp_libraries_result="in default path" +fi +if test x"$libwebp_includes_result" = x""; then + libwebp_includes_result="in default path" +fi + +if test "$libwebp_libraries_result" = "no"; then + libwebp_libraries_result="(none)" +fi +if test "$libwebp_includes_result" = "no"; then + libwebp_includes_result="(none)" +fi + +AC_MSG_RESULT([libraries $libwebp_libraries_result, headers $libwebp_includes_result]) + +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: +if test "$LIBWEBP_INCLUDES" != "no" && test "$LIBWEBP_LIBS" != "no"; then + AC_DEFINE(HAVE_LIBWEBP,1,[Define if you have libwebp libraries and header files.]) + $1 +else + LIBWEBP_INCLUDES="" + LIBWEBP_LIBS="" + $2 +fi + +])dnl + diff --git a/configure.ac b/configure.ac index 4ddb37fe..8bbe6492 100644 --- a/configure.ac +++ b/configure.ac @@ -673,6 +673,8 @@ if test x"$with_cfitsio" != "xno"; then fi # libwebp +# some platforms, like ubuntu 12.04, are missing the .pc files for libwebp, so +# we fall back to FIND_LIBWEBP AC_ARG_WITH([libwebp], AS_HELP_STRING([--without-libwebp], [build without libwebp (default: test)])) @@ -681,9 +683,14 @@ if test x"$with_libwebp" != "xno"; then [AC_DEFINE(HAVE_LIBWEBP,1,[define if you have libwebp installed.]) with_libwebp=yes PACKAGES_USED="$PACKAGES_USED libwebp"], - [AC_MSG_WARN([libwebp not found; disabling libwebp support]) - with_libwebp=no - ]) + [FIND_LIBWEBP([ + with_libwebp="yes (found by search)" + ], [ + AC_MSG_WARN([libwebp not found; disabling WEBP support]) + with_libwebp=no + ]) + ] + ) fi # pangoft2