Subject: Re: bug#61988: error compiling emacs

From: Po Lu <[email-masked]>
Date: Tue, 07 Mar 2023 13:03:55 +0800

Eli Zaretskii <[email-masked]> writes:

>> From: Po Lu <[email-masked]>
>> Cc: [email-masked],  [email-masked]
>> Date: Tue, 07 Mar 2023 08:34:18 +0800
>> 
>> Eli Zaretskii <[email-masked]> writes:
>> 
>> > I'd like to know why requiring libwebpdecoder is essential for the
>> > build to work on the OP's system.  It isn't on mine, and if you look
>> > at init_webp_functions, you will see that on Windows we load functions
>> > only from libwebp and libwebpdemux.  Why is the third library needed?
>> 
>> It is here, because Emacs needs the function ``WebPGetInfo'', and on
>> GNU/Linux systems that function is in libwebpdecoder.so:
>
> Then the unconditional test for libwebpdecoder being installed is not
> TRT.  We should instead do that only if that library is required, for
> example by trying to link a program that calls WebPGetInfo without
> libwebpdecoder first.
>
>> and here, I have a pkg-config file named libwebpdecoder.pc
>
> I see that file in the source directory, but it is not installed by
> "make install", and neither is libwebpdecoder library itself.
> Evidently, the way I configured and built libwebp doesn't require that
> library to be installed.  And once again, in my case the offending
> function is in libwebpdemux, not in libwebpdecoder.
>
> So the test needs to be rewritten to be safe and correct.
>
>> GNU ld does not allow you to link to symbols in dependencies of shared
>> libraries, so asking for libwebpdemux while using symbols in
>> libwebpdecoder does not work.
>
> I know, and that's not what I suggested.  It looks like at least on
> some systems (or maybe with some versions of libwebp) the
> libwebpdecoder library is not installed and not needed.  We must
> support such installations; we did until now.

OK, would both you and [email-masked] please try this?

diff --git a/configure.ac b/configure.ac
index bc7e61048c3..1477e04b7d8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2806,6 +2806,22 @@ AC_DEFUN
       WEBP_MODULE="libwebpdemux >= $WEBP_REQUIRED"
 
       EMACS_CHECK_MODULES([WEBP], [$WEBP_MODULE])
+
+      # WebPGetInfo is sometimes not present inside libwebpdemux, so
+      # if it does not link, also check for libwebpdecoder.
+
+      OLD_CFLAGS=$CFLAGS
+      OLD_LIBS=$LIBS
+      CFLAGS="$CFLAGS $WEBP_CFLAGS"
+      LIBS="$LIBS $WEBP_LIBS"
+
+      AC_CHECK_FUNC([WebPGetInfo], [],
+        [WEBP_MODULE="$WEBP_MODULE libwebpdecoder >= $WEBP_REQUIRED"
+	 EMACS_CHECK_MODULES([WEBP], [$WEBP_MODULE])])
+
+      CFLAGS=$OLD_CFLAGS
+      LIBS=$OLD_LIBS
+
       AC_SUBST([WEBP_CFLAGS])
       AC_SUBST([WEBP_LIBS])
    fi