Subject: 29.0.50; Failure configuring Emacs with animated WebP support

From: Daniel Martín <[email-masked]>
Date: Thu, 25 Aug 2022 23:59:40 +0200

I have a computer that cannot build Emacs since the animated WebP
support was added.

Details of the system:

aarch64-apple-darwin21.1.0, NS appkit-2113.00 Version 12.0.1 (Build
21A559)
Windowing system distributor 'Apple', version 10.3.2113
System Description:  macOS 12.4

Library WebP is installed via the Homebrew package manager.

$ pkg-config --libs libwebp

-L/opt/homebrew/Cellar/webp/1.2.2/lib -lwebp

Steps to reproduce the problem:

make -j

[...]

checking for libwebp >= 0.6.0... yes

[...]

ld: library not found for -lwebp
clang: error: linker command failed with exit code 1 (use -v to see invocation)

One workaround I've been using to build Emacs is to configure it
--with-webp=no

I think this is a bug that was introduced when animated WebP support was
added.  From commit d82e1a873df381b2c35bc9036da5665468bdfd31:

diff --git a/configure.ac b/configure.ac
index 6b834a2f65..185e4d0862 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2695,6 +2695,9 @@ AC_DEFUN
       WEBP_MODULE="libwebp >= $WEBP_REQUIRED"
 
       EMACS_CHECK_MODULES([WEBP], [$WEBP_MODULE])
+      if test "$HAVE_WEBP" = "yes"; then
+        WEBP_LIBS="-lwebp -lwebpdemux"
+      fi
       AC_SUBST(WEBP_CFLAGS)
       AC_SUBST(WEBP_LIBS)
    fi

The problem I see with this part of the patch is that, after you call
EMACS_CHECK_MODULES, the variable WEBP_LIBS is correctly set to
"-L/opt/homebrew/Cellar/webp/1.2.2/lib -lwebp" via pkg-config.  However,
it is overriden to contain "-lwebp -lwebpdemux", so the library path got
removed.

If WebP animated support requires -lwebpdemux, I think we could require
the libwebpdemux module instead (part of the libwebp package), whose
linker flags include "-lwebp -lwebpdemux".  The following patch fixes
the compilation for me:

diff --git a/configure.ac b/configure.ac
index 6ca3052ea3..4590ed3506 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2773,12 +2773,9 @@ AC_DEFUN
    || test "${HAVE_W32}" = "yes" || test "${HAVE_NS}" = "yes" \
    || test "${HAVE_BE_APP}" = "yes" || test "${HAVE_PGTK}" = "yes"; then
       WEBP_REQUIRED=0.6.0
-      WEBP_MODULE="libwebp >= $WEBP_REQUIRED"
+      WEBP_MODULE="libwebpdemux >= $WEBP_REQUIRED"
 
       EMACS_CHECK_MODULES([WEBP], [$WEBP_MODULE])
-      if test "$HAVE_WEBP" = "yes"; then
-        WEBP_LIBS="-lwebp -lwebpdemux"
-      fi
       AC_SUBST([WEBP_CFLAGS])
       AC_SUBST([WEBP_LIBS])
    fi

I checked that the built Emacs has WebP support.

What do you think? I'd need an build system expert to verify that this
is TRT in GNU/Linux, Windows, or when pkg-config is not available.