From: "H.J. Lu" <hjl.tools@gmail.com>
To: Mark Wielaard <mark@klomp.org>
Cc: Aaron Merey <amerey@redhat.com>, Simon Marchi <simark@simark.ca>,
Tom Tromey <tom@tromey.com>,
GCC Patches <gcc-patches@gcc.gnu.org>,
Aaron Merey via Binutils <binutils@sourceware.org>,
GDB <gdb-patches@sourceware.org>
Subject: [PATCH] PKG_CHECK_MODULES: Properly check if $pkg_cv_[]$1[]_LIBS works
Date: Tue, 28 Jul 2020 06:27:25 -0700 [thread overview]
Message-ID: <CAMe9rOq8GFOjmXD1SVdLnsRVx3Z0fqd52NV-2Ma17vgWRrHoGA@mail.gmail.com> (raw)
In-Reply-To: <f810b31d66fb3961b4b55442b66965eb72eaacdd.camel@klomp.org>
[-- Attachment #1: Type: text/plain, Size: 1191 bytes --]
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.
[-- Attachment #2: 0001-PKG_CHECK_MODULES-Properly-check-if-pkg_cv_-1-_LIBS-.patch --]
[-- Type: text/x-patch, Size: 3036 bytes --]
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
prev parent reply other threads:[~2020-07-28 13:28 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-02 2:29 [PATCH] config/debuginfod.m4: Use PKG_CHECK_MODULES Aaron Merey
2020-05-05 16:41 ` Jeff Law
2020-05-05 21:23 ` Aaron Merey
2020-05-08 20:56 ` Tom Tromey
2020-07-16 22:17 ` Aaron Merey
2020-07-16 22:37 ` Aaron Merey
2020-07-19 15:43 ` Simon Marchi
2020-07-21 15:20 ` Tom Tromey
2020-07-21 18:11 ` Aaron Merey
2020-07-24 20:03 ` Aaron Merey
2020-07-25 16:01 ` H.J. Lu
2020-07-27 15:31 ` [PATCH] config/debuginfod.m4: Restore AC_CHECK_LIB check H.J. Lu
2020-07-27 16:11 ` Aaron Merey
2020-07-27 19:14 ` [PATCH] PKG_CHECK_MODULES: Check if $pkg_cv_[]$1[]_LIBS works H.J. Lu
2020-07-27 19:32 ` V2 " H.J. Lu
2020-07-28 10:45 ` H.J. Lu
2020-07-28 12:46 ` Simon Marchi
2020-07-28 13:33 ` H.J. Lu
2020-07-28 13:51 ` Andreas Schwab
2020-07-28 13:56 ` H.J. Lu
2020-07-28 14:01 ` Simon Marchi
2020-07-28 14:11 ` H.J. Lu
2020-07-28 14:34 ` Simon Marchi
2020-07-28 15:05 ` H.J. Lu
2020-07-28 15:13 ` Simon Marchi
2020-07-28 16:07 ` H.J. Lu
2020-07-28 16:28 ` Simon Marchi
2020-07-28 17:26 ` H.J. Lu
2020-07-28 17:43 ` Simon Marchi
2020-07-28 18:31 ` H.J. Lu
2020-07-28 18:47 ` Simon Marchi
2020-07-28 18:57 ` H.J. Lu
2020-07-28 14:54 ` Andreas Schwab
2020-07-28 13:53 ` H.J. Lu
2020-07-28 13:54 ` Simon Marchi
2020-07-28 12:54 ` Mark Wielaard
2020-07-28 13:27 ` H.J. Lu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMe9rOq8GFOjmXD1SVdLnsRVx3Z0fqd52NV-2Ma17vgWRrHoGA@mail.gmail.com \
--to=hjl.tools@gmail.com \
--cc=amerey@redhat.com \
--cc=binutils@sourceware.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=mark@klomp.org \
--cc=simark@simark.ca \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).