PKG_CHECK_MODULES: Properly check if $pkg_cv_[]$1[]_LIBS works

Message ID CAMe9rOq8GFOjmXD1SVdLnsRVx3Z0fqd52NV-2Ma17vgWRrHoGA@mail.gmail.com
State New
Headers show
Series
  • PKG_CHECK_MODULES: Properly check if $pkg_cv_[]$1[]_LIBS works
Related show

Commit Message

Eli Zaretskii via Gdb-patches July 28, 2020, 1:27 p.m.
On Tue, Jul 28, 2020 at 5:54 AM Mark Wielaard <mark@klomp.org> wrote:
>

> Hi,

>

> On Mon, 2020-07-27 at 12:32 -0700, H.J. Lu via Binutils wrote:

> > diff --git a/config/pkg.m4 b/config/pkg.m4

> > index 13a8890178..45587e97c8 100644

> > --- a/config/pkg.m4

> > +++ b/config/pkg.m4

> > @@ -147,6 +147,12 @@ AC_MSG_CHECKING([for $2])

> >  _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])

> >  _PKG_CONFIG([$1][_LIBS], [libs], [$2])

> >

> > +dnl Check whether $pkg_cv_[]$1[]_LIBS works.

> > +pkg_save_LDFLAGS="$LDFLAGS"

> > +LDFLAGS="$LDFLAGS $pkg_cv_[]$1[]_LIBS"

> > +AC_TRY_LINK([],[return 0;], [pkg_failed=no], [pkg_failed=yes])

> > +LDFLAGS=$pkg_save_LDFLAGS

> > +

> >  m4_define([_PKG_TEXT], [Alternatively, you may set the environment

> > variables $1[]_CFLAGS

> >  and $1[]_LIBS to avoid the need to call pkg-config.

> >  See the pkg-config man page for more details.])

>

> This hunk seems wrong. You are testing whether the $pkg_cv_[]$1[]_LIBS

> flags work, but they might be empty if the library wasn't found

> (pkg_failed=yes). Then the AC_TRY_LINK will obviously succeed, and then

> you set pkg_failed=no. But that indicates that the library was found.

>


This fixes it.

Thanks.

-- 
H.J.

Patch

From cd63fb898517cedf3366871f546375cf5e25c734 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 28 Jul 2020 06:18:50 -0700
Subject: [PATCH] PKG_CHECK_MODULES: Properly check if $pkg_cv_[]$1[]_LIBS
 works

There is no need to check $pkg_cv_[]$1[]_LIBS works if package check
failed.

config/

	PR binutils/26301
	* pkg.m4 (PKG_CHECK_MODULES): Use AC_TRY_LINK only if
	$pkg_failed = no.

binutils/

	PR binutils/26301
	* configure: Regenerated.

gdb/

	PR binutils/26301
	* configure: Regenerated.
---
 binutils/configure | 14 ++++++++------
 config/pkg.m4      | 10 ++++++----
 gdb/configure      | 14 ++++++++------
 3 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/binutils/configure b/binutils/configure
index 4620a6b105..18316b7696 100755
--- a/binutils/configure
+++ b/binutils/configure
@@ -12439,27 +12439,29 @@  fi
     pkg_failed=untried
 fi
 
-pkg_save_LDFLAGS="$LDFLAGS"
-LDFLAGS="$LDFLAGS $pkg_cv_DEBUGINFOD_LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+if test $pkg_failed = no; then
+  pkg_save_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $pkg_cv_DEBUGINFOD_LIBS"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
 int
 main ()
 {
-return 0;
+
   ;
   return 0;
 }
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-  pkg_failed=no
+
 else
   pkg_failed=yes
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
-LDFLAGS=$pkg_save_LDFLAGS
+  LDFLAGS=$pkg_save_LDFLAGS
+fi
 
 
 
diff --git a/config/pkg.m4 b/config/pkg.m4
index 45587e97c8..7ebf517cd6 100644
--- a/config/pkg.m4
+++ b/config/pkg.m4
@@ -148,10 +148,12 @@  _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
 _PKG_CONFIG([$1][_LIBS], [libs], [$2])
 
 dnl Check whether $pkg_cv_[]$1[]_LIBS works.
-pkg_save_LDFLAGS="$LDFLAGS"
-LDFLAGS="$LDFLAGS $pkg_cv_[]$1[]_LIBS"
-AC_TRY_LINK([],[return 0;], [pkg_failed=no], [pkg_failed=yes])
-LDFLAGS=$pkg_save_LDFLAGS
+if test $pkg_failed = no; then
+  pkg_save_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $pkg_cv_[]$1[]_LIBS"
+  AC_TRY_LINK([],[], [], [pkg_failed=yes])
+  LDFLAGS=$pkg_save_LDFLAGS
+fi
 
 m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
 and $1[]_LIBS to avoid the need to call pkg-config.
diff --git a/gdb/configure b/gdb/configure
index eb38aaacfc..5ef85e8c86 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -7037,27 +7037,29 @@  fi
     pkg_failed=untried
 fi
 
-pkg_save_LDFLAGS="$LDFLAGS"
-LDFLAGS="$LDFLAGS $pkg_cv_DEBUGINFOD_LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+if test $pkg_failed = no; then
+  pkg_save_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $pkg_cv_DEBUGINFOD_LIBS"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
 int
 main ()
 {
-return 0;
+
   ;
   return 0;
 }
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-  pkg_failed=no
+
 else
   pkg_failed=yes
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
-LDFLAGS=$pkg_save_LDFLAGS
+  LDFLAGS=$pkg_save_LDFLAGS
+fi
 
 
 
-- 
2.26.2