public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/3] GDB: Fix `pkg-config' issues with configuring for Guile
@ 2022-11-24 23:50 Maciej W. Rozycki
  2022-11-24 23:51 ` [PATCH 1/3] GDB: Run `pkg-config' with `--static' to pull libguile dependencies Maciej W. Rozycki
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Maciej W. Rozycki @ 2022-11-24 23:50 UTC (permalink / raw)
  To: gdb-patches

Hi,

 In the course of verifying an earlier change against multiple versions of 
Guile I have come across several issues with how `pkg-config' is used to 
pull Guile in our configuration leading to build failures.  I have fixed 
them in this small patch series.  See individual change descriptions for 
details.

 These changes were build-tested only as regression-testing does not apply 
to such build issues.  Nevertheless I have run native `x86_64-linux-gnu' 
testing with other changes applied on top of these and that didn't trigger 
any regressions.

 OK to apply?

  Maciej

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] GDB: Run `pkg-config' with `--static' to pull libguile dependencies
  2022-11-24 23:50 [PATCH 0/3] GDB: Fix `pkg-config' issues with configuring for Guile Maciej W. Rozycki
@ 2022-11-24 23:51 ` Maciej W. Rozycki
  2022-11-25  7:56   ` Eli Zaretskii
  2022-11-24 23:51 ` [PATCH 2/3] GDB: Permit a lone version of Guile with `--with-guile=' Maciej W. Rozycki
  2022-11-24 23:51 ` [PATCH 3/3] GDB: Use standard autoconf macros for `pkg-config' Maciej W. Rozycki
  2 siblings, 1 reply; 9+ messages in thread
From: Maciej W. Rozycki @ 2022-11-24 23:51 UTC (permalink / raw)
  To: gdb-patches

Fix a configuration error:

checking whether to use guile... guile-2.2
checking for pkg-config... /usr/bin/pkg-config
checking for usable guile from /usr/bin/pkg-config... checking for scm_set_automatic_finalization_enabled... no
configure: error: in `.../gdb':
configure: error: linking guile version guile-2.2 test program failed
See `config.log' for more details
make[1]: *** [Makefile:12160: configure-gdb] Error 1

coming from link errors as recorded in `config.log' referred:

configure:19349: checking for scm_set_automatic_finalization_enabled
configure:19349: gcc -o conftest -pipe -O2      -pthread -I.../include/guile/2.2   conftest.c -lncursesw -lm -ldl  -L.../lib -lguile-2.2 -lgc >&5
/usr/bin/ld: .../lib/libguile-2.2.a(libguile_2.2_la-ports.o): in function `scm_ungetc':
(.text+0x5561): undefined reference to `u32_conv_to_encoding'
/usr/bin/ld: (.text+0x56e1): undefined reference to `u32_to_u8'

etc., etc., in a valid configuration where a static version of libguile 
has only been installed, which is a pefectly valid system configuration.  
This is due to symbols being required from libguile's dependencies that 
have not been included in the linker invocation.

In configurations using the ELF format dynamic libguile implicitly pulls 
indirect dependencies in the link, but to satisfy static libguile they 
need to be named explicitly.  These dependencies have been recorded and 
can be supplied by `pkg-config', but for that to happen the tool has to 
be invoked with the `--static' option in addition to `--libs'.  Moreover 
it is recommended, at least with systems using the ELF format, to have 
indirect dependencies included with static linker invocation even where 
they all are satisfied by dynamic libraries.

Therefore fix the issue by using the `--static' option unconditionally 
with `pkg-config', adding the dependencies required:

configure:19349: gcc -o conftest -pipe -O2      -pthread -I.../include/guile/2.2   conftest.c -lncursesw -lm -ldl  -L.../lib -lguile-2.2 -lgc -lgmp -lltdl -lffi -lunistring -lcrypt -lm >&5

and removing the errors quoted above.
---
 gdb/configure    |   10 +++++-----
 gdb/configure.ac |    6 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)

gdb-pkgconfig-static.diff
Index: src/gdb/configure
===================================================================
--- src.orig/gdb/configure
+++ src/gdb/configure
@@ -22917,7 +22917,7 @@ $as_echo_n "checking for usable guile fr
     if test $? != 0; then
       as_fn_error $? "failure running pkg-config --cflags ${guile_version}" "$LINENO" 5
     fi
-    new_LIBS=`${pkg_config} --libs ${guile_version}`
+    new_LIBS=`${pkg_config} --static --libs ${guile_version}`
     if test $? != 0; then
       as_fn_error $? "failure running pkg-config --libs ${guile_version}" "$LINENO" 5
     fi
@@ -23001,7 +23001,7 @@ $as_echo_n "checking for usable guile fr
     if test $? != 0; then
       as_fn_error $? "failure running pkg-config --cflags ${guile_version}" "$LINENO" 5
     fi
-    new_LIBS=`${pkg_config} --libs ${guile_version}`
+    new_LIBS=`${pkg_config} --static --libs ${guile_version}`
     if test $? != 0; then
       as_fn_error $? "failure running pkg-config --libs ${guile_version}" "$LINENO" 5
     fi
@@ -23082,7 +23082,7 @@ $as_echo_n "checking for usable guile fr
     if test $? != 0; then
       as_fn_error $? "failure running pkg-config --cflags ${guile_version}" "$LINENO" 5
     fi
-    new_LIBS=`${pkg_config} --libs ${guile_version}`
+    new_LIBS=`${pkg_config} --static --libs ${guile_version}`
     if test $? != 0; then
       as_fn_error $? "failure running pkg-config --libs ${guile_version}" "$LINENO" 5
     fi
@@ -23173,7 +23173,7 @@ $as_echo_n "checking for usable guile fr
     if test $? != 0; then
       as_fn_error $? "failure running pkg-config --cflags ${guile_version}" "$LINENO" 5
     fi
-    new_LIBS=`${pkg_config} --libs ${guile_version}`
+    new_LIBS=`${pkg_config} --static --libs ${guile_version}`
     if test $? != 0; then
       as_fn_error $? "failure running pkg-config --libs ${guile_version}" "$LINENO" 5
     fi
@@ -23418,7 +23418,7 @@ $as_echo "no - pkg-config not found" >&6
       esac
 
       srchigh_pkg_cflags=`${pkg_config_prog_path} --cflags source-highlight`
-      srchigh_pkg_libs=`${pkg_config_prog_path} --libs source-highlight`
+      srchigh_pkg_libs=`${pkg_config_prog_path} --static --libs source-highlight`
 
       # Now that we have found a source-highlight library, check if we can use
       # it.  In particular, we're trying to detect the situation that the
Index: src/gdb/configure.ac
===================================================================
--- src.orig/gdb/configure.ac
+++ src/gdb/configure.ac
@@ -1020,7 +1020,7 @@ AC_DEFUN([AC_TRY_LIBGUILE],
     if test $? != 0; then
       AC_MSG_ERROR([failure running pkg-config --cflags ${guile_version}])
     fi
-    new_LIBS=`${pkg_config} --libs ${guile_version}`
+    new_LIBS=`${pkg_config} --static --libs ${guile_version}`
     if test $? != 0; then
       AC_MSG_ERROR([failure running pkg-config --libs ${guile_version}])
     fi
@@ -1082,7 +1082,7 @@ dnl        NOTE: This needn't be the "re
 dnl        It could be a shell script.  It is invoked as:
 dnl        pkg-config --exists $version
 dnl        pkg-config --cflags $version
-dnl        pkg-config --libs $version
+dnl        pkg-config --static --libs $version
 dnl        pkg-config --variable guild $version
 dnl        The script will be called with $version having each value in
 dnl        $try_guile_versions until --exists indicates success.
@@ -1212,7 +1212,7 @@ either use --disable-source-highlight or
       esac
 
       srchigh_pkg_cflags=`${pkg_config_prog_path} --cflags source-highlight`
-      srchigh_pkg_libs=`${pkg_config_prog_path} --libs source-highlight`
+      srchigh_pkg_libs=`${pkg_config_prog_path} --static --libs source-highlight`
 
       # Now that we have found a source-highlight library, check if we can use
       # it.  In particular, we're trying to detect the situation that the

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/3] GDB: Permit a lone version of Guile with `--with-guile='
  2022-11-24 23:50 [PATCH 0/3] GDB: Fix `pkg-config' issues with configuring for Guile Maciej W. Rozycki
  2022-11-24 23:51 ` [PATCH 1/3] GDB: Run `pkg-config' with `--static' to pull libguile dependencies Maciej W. Rozycki
@ 2022-11-24 23:51 ` Maciej W. Rozycki
  2022-11-26 23:38   ` Mike Frysinger
  2022-11-24 23:51 ` [PATCH 3/3] GDB: Use standard autoconf macros for `pkg-config' Maciej W. Rozycki
  2 siblings, 1 reply; 9+ messages in thread
From: Maciej W. Rozycki @ 2022-11-24 23:51 UTC (permalink / raw)
  To: gdb-patches

Our documentation in `gdb/README' says one can use a version number as 
an argument to `--with-guile=' to get the desired version of Guile used, 
hovever such syntax is actually not supported:

checking whether to use guile... 2.2
checking for pkg-config... /usr/bin/pkg-config
checking for usable guile from /usr/bin/pkg-config... configure: error: 
unable to find usable guile version from "2.2"
make[1]: *** [Makefile:12160: configure-gdb] Error 1

This is confirmed with inline documentation in `configure.ac':

dnl There are several different values for --with-guile:
[...]
dnl guile-version [guile-version-choice-2 ...] -
dnl        A space-separated list of guile package versions to try.
dnl        These are passed to pkg-config as-is.
dnl        E.g., guile-2.0 or guile-2.2-uninstalled

Not only it is contrary to what user documentation says, but it seems 
counter-intuitive and indeed rather weakly justified as well, given that 
in virtually all configurations the package carrying Guile will actually 
be called "guile".

Implement the documented semantics then and accept a lone version number 
as an argument to `--with-guile=' as well, using a simple heuristics to
tell it apart: a string comprised of digits and point characters only is 
considered a lone version number to which "guile-" is prepended in the 
`pkg-config' invocation and other strings are handled as before.  This 
follows an observation that packages do not have solely numeric names.
---
 gdb/configure    |   28 ++++++++++++++++++++++++++++
 gdb/configure.ac |   16 ++++++++++++----
 2 files changed, 40 insertions(+), 4 deletions(-)

gdb-pkgconfig-guile-version.diff
Index: src/gdb/configure
===================================================================
--- src.orig/gdb/configure
+++ src/gdb/configure
@@ -22909,6 +22909,13 @@ $as_echo "$as_me: WARNING: pkg-config no
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for usable guile from ${pkg_config}" >&5
 $as_echo_n "checking for usable guile from ${pkg_config}... " >&6; }
   for guile_version in ${guile_version_list}; do
+    case "${guile_version}" in
+    *[^.0-9]*)
+      ;;
+    *)
+      guile_version=guile-"${guile_version}"
+      ;;
+    esac
     ${pkg_config} --exists ${guile_version} 2>/dev/null
     if test $? != 0; then
       continue
@@ -22993,6 +23000,13 @@ yes)
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for usable guile from ${pkg_config}" >&5
 $as_echo_n "checking for usable guile from ${pkg_config}... " >&6; }
   for guile_version in ${guile_version_list}; do
+    case "${guile_version}" in
+    *[^.0-9]*)
+      ;;
+    *)
+      guile_version=guile-"${guile_version}"
+      ;;
+    esac
     ${pkg_config} --exists ${guile_version} 2>/dev/null
     if test $? != 0; then
       continue
@@ -23074,6 +23088,13 @@ $as_echo "${found_usable_guile}" >&6; }
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for usable guile from ${pkg_config}" >&5
 $as_echo_n "checking for usable guile from ${pkg_config}... " >&6; }
   for guile_version in ${guile_version_list}; do
+    case "${guile_version}" in
+    *[^.0-9]*)
+      ;;
+    *)
+      guile_version=guile-"${guile_version}"
+      ;;
+    esac
     ${pkg_config} --exists ${guile_version} 2>/dev/null
     if test $? != 0; then
       continue
@@ -23165,6 +23186,13 @@ $as_echo "${found_usable_guile}" >&6; }
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for usable guile from ${pkg_config}" >&5
 $as_echo_n "checking for usable guile from ${pkg_config}... " >&6; }
   for guile_version in ${guile_version_list}; do
+    case "${guile_version}" in
+    *[^.0-9]*)
+      ;;
+    *)
+      guile_version=guile-"${guile_version}"
+      ;;
+    esac
     ${pkg_config} --exists ${guile_version} 2>/dev/null
     if test $? != 0; then
       continue
Index: src/gdb/configure.ac
===================================================================
--- src.orig/gdb/configure.ac
+++ src/gdb/configure.ac
@@ -996,7 +996,7 @@ AM_CONDITIONAL(HAVE_PYTHON, test "${have
 
 dnl Utility to simplify finding libguile.
 dnl $1 = pkg-config-program
-dnl $2 = space-separate list of guile versions to try
+dnl $2 = space-separated list of guile version numbers or package names to try
 dnl $3 = yes|no, indicating whether to flag errors or ignore them
 dnl $4 = the shell variable to assign the result to
 dnl      If libguile is found we store "yes" here.
@@ -1010,6 +1010,13 @@ AC_DEFUN([AC_TRY_LIBGUILE],
   found_usable_guile=checking
   AC_MSG_CHECKING([for usable guile from ${pkg_config}])
   for guile_version in ${guile_version_list}; do
+    case "${guile_version}" in
+    *[[^.0-9]]*)
+      ;;
+    *)
+      guile_version=guile-"${guile_version}"
+      ;;
+    esac
     ${pkg_config} --exists ${guile_version} 2>/dev/null
     if test $? != 0; then
       continue
@@ -1072,9 +1079,10 @@ dnl        The pkg-config program must b
 dnl auto - Same as "yes", but if guile is missing from the system,
 dnl        fall back to "no".
 dnl guile-version [guile-version-choice-2 ...] -
-dnl        A space-separated list of guile package versions to try.
-dnl        These are passed to pkg-config as-is.
-dnl        E.g., guile-2.0 or guile-2.2-uninstalled
+dnl        A space-separated list of guile package version numbers
+dnl        or names to try.  Numbers have "guile-" prepended while
+dnl        names are passed to pkg-config as-is.
+dnl        E.g. 3.0, guile-2.0 or guile-2.2-uninstalled.
 dnl        This requires making sure PKG_CONFIG_PATH is set appropriately.
 dnl /path/to/pkg-config -
 dnl        Use this pkg-config program.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/3] GDB: Use standard autoconf macros for `pkg-config'
  2022-11-24 23:50 [PATCH 0/3] GDB: Fix `pkg-config' issues with configuring for Guile Maciej W. Rozycki
  2022-11-24 23:51 ` [PATCH 1/3] GDB: Run `pkg-config' with `--static' to pull libguile dependencies Maciej W. Rozycki
  2022-11-24 23:51 ` [PATCH 2/3] GDB: Permit a lone version of Guile with `--with-guile=' Maciej W. Rozycki
@ 2022-11-24 23:51 ` Maciej W. Rozycki
  2 siblings, 0 replies; 9+ messages in thread
From: Maciej W. Rozycki @ 2022-11-24 23:51 UTC (permalink / raw)
  To: gdb-patches

We use standard autoconf macros for `pkg-config' with other directories 
outside gdb/ already and we have them available in config/pkg.m4.

Use them for GDB too then, taking advantage of shared cached results 
where available, respecting the PKG_CONFIG command-line `configure' 
variable, making standard GUILE_CFLAGS, GUILE_LIBS, SRCHIGH_CFLAGS and 
SRCHIGH_LIBS command-line `configure' variables available automatically, 
and reducing code duplicated locally in `configure.ac'.

The only complication is our local non-standard `/path/to/pkg-config' 
override available as an argument to `--with-guile=', not handled by 
standard macros, where the PKG_CONFIG command-line `configure' variable, 
is the documented way to override the automatically determined location 
of the `pkg-config' program, but it applies globally rather than just 
for Guile configuration under gdb/.

This is handled by temporarily overriding the ac_cv_path_PKG_CONFIG 
cache variable, replacing any global value already set.  While not a 
documented interface and subject to change with future versions of 
`pkg-config' it is not supposed to be an issue because we are also in 
control of the macros in config/pkg.m4, so when updating those we can 
adjust the references here accordingly if required.
---
 gdb/Makefile.in  |    2 
 gdb/configure    |  824 +++++++++++++++++++++++++++++++++++++------------------
 gdb/configure.ac |  155 ++++------
 3 files changed, 631 insertions(+), 350 deletions(-)

Index: src/gdb/Makefile.in
===================================================================
--- src.orig/gdb/Makefile.in
+++ src/gdb/Makefile.in
@@ -623,7 +623,7 @@ CPPFLAGS = @CPPFLAGS@
 # are sometimes a little generic, we think that the risk of collision
 # with other header files is high.  If that happens, we try to mitigate
 # a bit the consequences by putting the Python includes last in the list.
-INTERNAL_CPPFLAGS = $(CPPFLAGS) @GUILE_CPPFLAGS@ @PYTHON_CPPFLAGS@ \
+INTERNAL_CPPFLAGS = $(CPPFLAGS) @GUILE_CFLAGS@ @PYTHON_CPPFLAGS@ \
 	@LARGEFILE_CPPFLAGS@
 
 # INTERNAL_CFLAGS is the aggregate of all other *CFLAGS macros.
Index: src/gdb/configure
===================================================================
--- src.orig/gdb/configure
+++ src/gdb/configure
@@ -724,15 +724,14 @@ PTHREAD_LIBS
 PTHREAD_CC
 ax_pthread_config
 ALLOCA
-SRCHIGH_CFLAGS
 SRCHIGH_LIBS
+SRCHIGH_CFLAGS
 HAVE_GUILE_FALSE
 HAVE_GUILE_TRUE
-GUILE_LIBS
-GUILE_CPPFLAGS
 GUILD_TARGET_FLAG
 GUILD
-pkg_config_prog_path
+GUILE_LIBS
+GUILE_CFLAGS
 HAVE_PYTHON_FALSE
 HAVE_PYTHON_TRUE
 PYTHON_LIBS
@@ -995,6 +994,10 @@ YACC
 YFLAGS
 ZSTD_CFLAGS
 ZSTD_LIBS
+GUILE_CFLAGS
+GUILE_LIBS
+SRCHIGH_CFLAGS
+SRCHIGH_LIBS
 XMKMF'
 ac_subdirs_all='testsuite
 gdbtk'
@@ -1768,6 +1771,13 @@ if test -n "$ac_init_help"; then
               default value of `-d' given by some make applications.
   ZSTD_CFLAGS C compiler flags for ZSTD, overriding pkg-config
   ZSTD_LIBS   linker flags for ZSTD, overriding pkg-config
+  GUILE_CFLAGS
+              C compiler flags for GUILE, overriding pkg-config
+  GUILE_LIBS  linker flags for GUILE, overriding pkg-config
+  SRCHIGH_CFLAGS
+              C compiler flags for SRCHIGH, overriding pkg-config
+  SRCHIGH_LIBS
+              linker flags for SRCHIGH, overriding pkg-config
   XMKMF       Path to xmkmf, Makefile generator for X Window System
 
 Use these variables to override the choices made by `configure' or to help
@@ -11451,7 +11461,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11454 "configure"
+#line 11464 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11557,7 +11567,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11560 "configure"
+#line 11570 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -22846,16 +22856,97 @@ $as_echo_n "checking whether to use guil
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_guile" >&5
 $as_echo "$with_guile" >&6; }
 
-# Extract the first word of "pkg-config", so it can be a program name with args.
+try_guile_versions="guile-3.0 guile-2.2 guile-2.0"
+case "${with_guile}" in
+no|auto|yes)
+  try_guile=${with_guile}
+  ;;
+[\\/]* | ?:[\\/]*)
+  try_guile=yes
+  if test ! -x "${with_guile}"; then
+    as_fn_error $? "Guile config program not executable: ${with_guile}" "$LINENO" 5
+  fi
+  guile_PKG_CONFIG_set=yes
+  guile_PKG_CONFIG=${PKG_CONFIG}
+  guile_cache_PKG_CONFIG=${ac_cv_path_PKG_CONFIG}
+  PKG_CONFIG=${with_guile}
+  ac_cv_path_PKG_CONFIG=${with_guile}
+  ;;
+"" | */*)
+  # Disallow --with=guile="" and --with-guile=foo/bar.
+  as_fn_error $? "invalid value for --with-guile" "$LINENO" 5
+  ;;
+*)
+  try_guile=yes
+  try_guile_versions=${with_guile}
+  ;;
+esac
+
+
+
+
+
+
+
+
+
+
+
+if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
+	if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args.
+set dummy ${ac_tool_prefix}pkg-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_PKG_CONFIG+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+PKG_CONFIG=$ac_cv_path_PKG_CONFIG
+if test -n "$PKG_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5
+$as_echo "$PKG_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_PKG_CONFIG"; then
+  ac_pt_PKG_CONFIG=$PKG_CONFIG
+  # Extract the first word of "pkg-config", so it can be a program name with args.
 set dummy pkg-config; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_pkg_config_prog_path+:} false; then :
+if ${ac_cv_path_ac_pt_PKG_CONFIG+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $pkg_config_prog_path in
+  case $ac_pt_PKG_CONFIG in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_pkg_config_prog_path="$pkg_config_prog_path" # Let the user override the test with a path.
+  ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -22865,7 +22956,7 @@ do
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
   if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_path_pkg_config_prog_path="$as_dir/$ac_word$ac_exec_ext"
+    ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -22873,41 +22964,62 @@ done
   done
 IFS=$as_save_IFS
 
-  test -z "$ac_cv_path_pkg_config_prog_path" && ac_cv_path_pkg_config_prog_path="missing"
   ;;
 esac
 fi
-pkg_config_prog_path=$ac_cv_path_pkg_config_prog_path
-if test -n "$pkg_config_prog_path"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $pkg_config_prog_path" >&5
-$as_echo "$pkg_config_prog_path" >&6; }
+ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG
+if test -n "$ac_pt_PKG_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5
+$as_echo "$ac_pt_PKG_CONFIG" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
+  if test "x$ac_pt_PKG_CONFIG" = x; then
+    PKG_CONFIG=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    PKG_CONFIG=$ac_pt_PKG_CONFIG
+  fi
+else
+  PKG_CONFIG="$ac_cv_path_PKG_CONFIG"
+fi
 
+fi
+if test -n "$PKG_CONFIG"; then
+	_pkg_min_version=0.29
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking pkg-config is at least version $_pkg_min_version" >&5
+$as_echo_n "checking pkg-config is at least version $_pkg_min_version... " >&6; }
+	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	else
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+		PKG_CONFIG=""
+	fi
+fi
 
-try_guile_versions="guile-3.0 guile-2.2 guile-2.0"
 have_libguile=no
-case "${with_guile}" in
-no)
-  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: guile support disabled; some features will be unavailable." >&5
-$as_echo "$as_me: WARNING: guile support disabled; some features will be unavailable." >&2;}
-  ;;
+case "${try_guile}" in
 auto)
-  if test "${pkg_config_prog_path}" = "missing"; then
+  if test x"${PKG_CONFIG}" = x; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: pkg-config not found, guile support disabled" >&5
 $as_echo "$as_me: WARNING: pkg-config not found, guile support disabled" >&2;}
   else
 
-  pkg_config=${pkg_config_prog_path}
   guile_version_list=${try_guile_versions}
   flag_errors=no
 
   found_usable_guile=checking
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for usable guile from ${pkg_config}" >&5
-$as_echo_n "checking for usable guile from ${pkg_config}... " >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for usable guile from ${PKG_CONFIG}" >&5
+$as_echo_n "checking for usable guile from ${PKG_CONFIG}... " >&6; }
   for guile_version in ${guile_version_list}; do
     case "${guile_version}" in
     *[^.0-9]*)
@@ -22916,111 +23028,107 @@ $as_echo_n "checking for usable guile fr
       guile_version=guile-"${guile_version}"
       ;;
     esac
-    ${pkg_config} --exists ${guile_version} 2>/dev/null
-    if test $? != 0; then
-      continue
-    fi
-            new_CPPFLAGS=`${pkg_config} --cflags ${guile_version}`
-    if test $? != 0; then
-      as_fn_error $? "failure running pkg-config --cflags ${guile_version}" "$LINENO" 5
-    fi
-    new_LIBS=`${pkg_config} --static --libs ${guile_version}`
-    if test $? != 0; then
-      as_fn_error $? "failure running pkg-config --libs ${guile_version}" "$LINENO" 5
-    fi
-        found_usable_guile=${guile_version}
-    break
-  done
-  if test "${found_usable_guile}" = "checking"; then
-    if test "${flag_errors}" = "yes"; then
-      as_fn_error $? "unable to find usable guile version from \"${guile_version_list}\"" "$LINENO" 5
-    else
-      found_usable_guile=no
-    fi
-  fi
-      if test "${found_usable_guile}" != no; then
-    save_CPPFLAGS=$CPPFLAGS
-    save_LIBS=$LIBS
-    CPPFLAGS="$CPPFLAGS $new_CPPFLAGS"
-    LIBS="$LIBS $new_LIBS"
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+    _save_PKG_CONFIG=$PKG_CONFIG
+PKG_CONFIG="$PKG_CONFIG --static"
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${guile_version}" >&5
+$as_echo_n "checking for ${guile_version}... " >&6; }
+
+if test -n "$GUILE_CFLAGS"; then
+    pkg_cv_GUILE_CFLAGS="$GUILE_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"\${guile_version}\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "${guile_version}") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GUILE_CFLAGS=`$PKG_CONFIG --cflags "${guile_version}" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$GUILE_LIBS"; then
+    pkg_cv_GUILE_LIBS="$GUILE_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"\${guile_version}\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "${guile_version}") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GUILE_LIBS=`$PKG_CONFIG --libs "${guile_version}" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+if test $pkg_failed = no; then
+  pkg_save_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $pkg_cv_GUILE_LIBS"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#include "libguile.h"
+
 int
 main ()
 {
-scm_init_guile ();
+
   ;
   return 0;
 }
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-  have_libguile=yes
-                    GUILE_CPPFLAGS=$new_CPPFLAGS
-                    GUILE_LIBS=$new_LIBS
+
 else
-  found_usable_guile=no
+  pkg_failed=yes
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
-        ac_fn_c_check_func "$LINENO" "scm_set_automatic_finalization_enabled" "ac_cv_func_scm_set_automatic_finalization_enabled"
-if test "x$ac_cv_func_scm_set_automatic_finalization_enabled" = xyes; then :
-
-$as_echo "#define HAVE_GUILE_MANUAL_FINALIZATION 1" >>confdefs.h
-
-
+  LDFLAGS=$pkg_save_LDFLAGS
 fi
 
-    CPPFLAGS=$save_CPPFLAGS
-    LIBS=$save_LIBS
-    if test "${found_usable_guile}" = no; then
-      if test "${flag_errors}" = yes; then
-        { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "linking guile version ${guile_version} test program failed
-See \`config.log' for more details" "$LINENO" 5; }
-      fi
-    fi
-  fi
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${found_usable_guile}" >&5
-$as_echo "${found_usable_guile}" >&6; }
 
-  fi
-  ;;
-yes)
-  if test "${pkg_config_prog_path}" = "missing"; then
-    as_fn_error $? "pkg-config not found" "$LINENO" 5
-  fi
 
-  pkg_config=${pkg_config_prog_path}
-  guile_version_list=${try_guile_versions}
-  flag_errors=yes
+if test $pkg_failed = yes; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 
-  found_usable_guile=checking
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for usable guile from ${pkg_config}" >&5
-$as_echo_n "checking for usable guile from ${pkg_config}... " >&6; }
-  for guile_version in ${guile_version_list}; do
-    case "${guile_version}" in
-    *[^.0-9]*)
-      ;;
-    *)
-      guile_version=guile-"${guile_version}"
-      ;;
-    esac
-    ${pkg_config} --exists ${guile_version} 2>/dev/null
-    if test $? != 0; then
-      continue
-    fi
-            new_CPPFLAGS=`${pkg_config} --cflags ${guile_version}`
-    if test $? != 0; then
-      as_fn_error $? "failure running pkg-config --cflags ${guile_version}" "$LINENO" 5
-    fi
-    new_LIBS=`${pkg_config} --static --libs ${guile_version}`
-    if test $? != 0; then
-      as_fn_error $? "failure running pkg-config --libs ${guile_version}" "$LINENO" 5
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        GUILE_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "${guile_version}" 2>&1`
+        else
+	        GUILE_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "${guile_version}" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$GUILE_PKG_ERRORS" >&5
+
+	:
+elif test $pkg_failed = untried; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	:
+else
+	GUILE_CFLAGS=$pkg_cv_GUILE_CFLAGS
+	GUILE_LIBS=$pkg_cv_GUILE_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	found_usable_guile=${guile_version}
+fi
+PKG_CONFIG=$_save_PKG_CONFIG
+    if test "${found_usable_guile}" != "checking"; then
+      break
     fi
-        found_usable_guile=${guile_version}
-    break
   done
   if test "${found_usable_guile}" = "checking"; then
     if test "${flag_errors}" = "yes"; then
@@ -23032,8 +23140,8 @@ $as_echo_n "checking for usable guile fr
       if test "${found_usable_guile}" != no; then
     save_CPPFLAGS=$CPPFLAGS
     save_LIBS=$LIBS
-    CPPFLAGS="$CPPFLAGS $new_CPPFLAGS"
-    LIBS="$LIBS $new_LIBS"
+    CPPFLAGS="$CPPFLAGS $GUILE_CFLAGS"
+    LIBS="$LIBS $GUILE_LIBS"
     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include "libguile.h"
@@ -23047,8 +23155,6 @@ scm_init_guile ();
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
   have_libguile=yes
-                    GUILE_CPPFLAGS=$new_CPPFLAGS
-                    GUILE_LIBS=$new_LIBS
 else
   found_usable_guile=no
 fi
@@ -23071,22 +23177,26 @@ $as_echo "$as_me: error: in \`$ac_pwd':"
 as_fn_error $? "linking guile version ${guile_version} test program failed
 See \`config.log' for more details" "$LINENO" 5; }
       fi
+      unset GUILE_CFLAGS
+      unset GUILE_LIBS
     fi
   fi
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${found_usable_guile}" >&5
 $as_echo "${found_usable_guile}" >&6; }
 
+  fi
   ;;
-[\\/]* | ?:[\\/]*)
-  if test -x "${with_guile}"; then
+yes)
+  if test x"${PKG_CONFIG}" = x; then
+    as_fn_error $? "pkg-config not found" "$LINENO" 5
+  fi
 
-  pkg_config=${with_guile}
   guile_version_list=${try_guile_versions}
   flag_errors=yes
 
   found_usable_guile=checking
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for usable guile from ${pkg_config}" >&5
-$as_echo_n "checking for usable guile from ${pkg_config}... " >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for usable guile from ${PKG_CONFIG}" >&5
+$as_echo_n "checking for usable guile from ${PKG_CONFIG}... " >&6; }
   for guile_version in ${guile_version_list}; do
     case "${guile_version}" in
     *[^.0-9]*)
@@ -23095,118 +23205,107 @@ $as_echo_n "checking for usable guile fr
       guile_version=guile-"${guile_version}"
       ;;
     esac
-    ${pkg_config} --exists ${guile_version} 2>/dev/null
-    if test $? != 0; then
-      continue
-    fi
-            new_CPPFLAGS=`${pkg_config} --cflags ${guile_version}`
-    if test $? != 0; then
-      as_fn_error $? "failure running pkg-config --cflags ${guile_version}" "$LINENO" 5
-    fi
-    new_LIBS=`${pkg_config} --static --libs ${guile_version}`
-    if test $? != 0; then
-      as_fn_error $? "failure running pkg-config --libs ${guile_version}" "$LINENO" 5
-    fi
-        found_usable_guile=${guile_version}
-    break
-  done
-  if test "${found_usable_guile}" = "checking"; then
-    if test "${flag_errors}" = "yes"; then
-      as_fn_error $? "unable to find usable guile version from \"${guile_version_list}\"" "$LINENO" 5
-    else
-      found_usable_guile=no
-    fi
-  fi
-      if test "${found_usable_guile}" != no; then
-    save_CPPFLAGS=$CPPFLAGS
-    save_LIBS=$LIBS
-    CPPFLAGS="$CPPFLAGS $new_CPPFLAGS"
-    LIBS="$LIBS $new_LIBS"
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+    _save_PKG_CONFIG=$PKG_CONFIG
+PKG_CONFIG="$PKG_CONFIG --static"
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${guile_version}" >&5
+$as_echo_n "checking for ${guile_version}... " >&6; }
+
+if test -n "$GUILE_CFLAGS"; then
+    pkg_cv_GUILE_CFLAGS="$GUILE_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"\${guile_version}\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "${guile_version}") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GUILE_CFLAGS=`$PKG_CONFIG --cflags "${guile_version}" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$GUILE_LIBS"; then
+    pkg_cv_GUILE_LIBS="$GUILE_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"\${guile_version}\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "${guile_version}") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GUILE_LIBS=`$PKG_CONFIG --libs "${guile_version}" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+if test $pkg_failed = no; then
+  pkg_save_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $pkg_cv_GUILE_LIBS"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#include "libguile.h"
+
 int
 main ()
 {
-scm_init_guile ();
+
   ;
   return 0;
 }
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-  have_libguile=yes
-                    GUILE_CPPFLAGS=$new_CPPFLAGS
-                    GUILE_LIBS=$new_LIBS
+
 else
-  found_usable_guile=no
+  pkg_failed=yes
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
-        ac_fn_c_check_func "$LINENO" "scm_set_automatic_finalization_enabled" "ac_cv_func_scm_set_automatic_finalization_enabled"
-if test "x$ac_cv_func_scm_set_automatic_finalization_enabled" = xyes; then :
-
-$as_echo "#define HAVE_GUILE_MANUAL_FINALIZATION 1" >>confdefs.h
-
-
+  LDFLAGS=$pkg_save_LDFLAGS
 fi
 
-    CPPFLAGS=$save_CPPFLAGS
-    LIBS=$save_LIBS
-    if test "${found_usable_guile}" = no; then
-      if test "${flag_errors}" = yes; then
-        { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "linking guile version ${guile_version} test program failed
-See \`config.log' for more details" "$LINENO" 5; }
-      fi
-    fi
-  fi
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${found_usable_guile}" >&5
-$as_echo "${found_usable_guile}" >&6; }
 
-  else
-    as_fn_error $? "Guile config program not executable: ${with_guile}" "$LINENO" 5
-  fi
-  ;;
-"" | */*)
-  # Disallow --with=guile="" and --with-guile=foo/bar.
-  as_fn_error $? "invalid value for --with-guile" "$LINENO" 5
-  ;;
-*)
-  # A space separate list of guile versions to try, in order.
-  if test "${pkg_config_prog_path}" = "missing"; then
-    as_fn_error $? "pkg-config not found" "$LINENO" 5
-  fi
 
-  pkg_config=${pkg_config_prog_path}
-  guile_version_list=${with_guile}
-  flag_errors=yes
+if test $pkg_failed = yes; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 
-  found_usable_guile=checking
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for usable guile from ${pkg_config}" >&5
-$as_echo_n "checking for usable guile from ${pkg_config}... " >&6; }
-  for guile_version in ${guile_version_list}; do
-    case "${guile_version}" in
-    *[^.0-9]*)
-      ;;
-    *)
-      guile_version=guile-"${guile_version}"
-      ;;
-    esac
-    ${pkg_config} --exists ${guile_version} 2>/dev/null
-    if test $? != 0; then
-      continue
-    fi
-            new_CPPFLAGS=`${pkg_config} --cflags ${guile_version}`
-    if test $? != 0; then
-      as_fn_error $? "failure running pkg-config --cflags ${guile_version}" "$LINENO" 5
-    fi
-    new_LIBS=`${pkg_config} --static --libs ${guile_version}`
-    if test $? != 0; then
-      as_fn_error $? "failure running pkg-config --libs ${guile_version}" "$LINENO" 5
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        GUILE_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "${guile_version}" 2>&1`
+        else
+	        GUILE_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "${guile_version}" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$GUILE_PKG_ERRORS" >&5
+
+	:
+elif test $pkg_failed = untried; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	:
+else
+	GUILE_CFLAGS=$pkg_cv_GUILE_CFLAGS
+	GUILE_LIBS=$pkg_cv_GUILE_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	found_usable_guile=${guile_version}
+fi
+PKG_CONFIG=$_save_PKG_CONFIG
+    if test "${found_usable_guile}" != "checking"; then
+      break
     fi
-        found_usable_guile=${guile_version}
-    break
   done
   if test "${found_usable_guile}" = "checking"; then
     if test "${flag_errors}" = "yes"; then
@@ -23218,8 +23317,8 @@ $as_echo_n "checking for usable guile fr
       if test "${found_usable_guile}" != no; then
     save_CPPFLAGS=$CPPFLAGS
     save_LIBS=$LIBS
-    CPPFLAGS="$CPPFLAGS $new_CPPFLAGS"
-    LIBS="$LIBS $new_LIBS"
+    CPPFLAGS="$CPPFLAGS $GUILE_CFLAGS"
+    LIBS="$LIBS $GUILE_LIBS"
     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include "libguile.h"
@@ -23233,8 +23332,6 @@ scm_init_guile ();
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
   have_libguile=yes
-                    GUILE_CPPFLAGS=$new_CPPFLAGS
-                    GUILE_LIBS=$new_LIBS
 else
   found_usable_guile=no
 fi
@@ -23257,61 +23354,35 @@ $as_echo "$as_me: error: in \`$ac_pwd':"
 as_fn_error $? "linking guile version ${guile_version} test program failed
 See \`config.log' for more details" "$LINENO" 5; }
       fi
+      unset GUILE_CFLAGS
+      unset GUILE_LIBS
     fi
   fi
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${found_usable_guile}" >&5
 $as_echo "${found_usable_guile}" >&6; }
 
   ;;
+*)
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: guile support disabled; some features will be unavailable." >&5
+$as_echo "$as_me: WARNING: guile support disabled; some features will be unavailable." >&2;}
+  ;;
 esac
 
 if test "${have_libguile}" != no; then
-    case "${with_guile}" in
-  [\\/]* | ?:[\\/]*)
 
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the absolute file name of the 'guild' command" >&5
 $as_echo_n "checking for the absolute file name of the 'guild' command... " >&6; }
 if ${ac_cv_guild_program_name+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  ac_cv_guild_program_name="`"${with_guile}" --variable guild "${guile_version}"`"
-
-     # In Guile up to 2.0.11 included, guile-2.0.pc would not define
-     # the 'guild' and 'bindir' variables.  In that case, try to guess
-     # what the program name is, at the risk of getting it wrong if
-     # Guile was configured with '--program-suffix' or similar.
-     if test "x$ac_cv_guild_program_name" = "x"; then
-       guile_exec_prefix="`"${with_guile}" --variable exec_prefix "${guile_version}"`"
-       ac_cv_guild_program_name="$guile_exec_prefix/bin/guild"
-     fi
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_guild_program_name" >&5
-$as_echo "$ac_cv_guild_program_name" >&6; }
-
-  if ! "$ac_cv_guild_program_name" --version >&5 2>&5; then
-    as_fn_error $? "'$ac_cv_guild_program_name' appears to be unusable" "$LINENO" 5
-  fi
-
-  GUILD="$ac_cv_guild_program_name"
-
-
-    ;;
-  *)
-
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the absolute file name of the 'guild' command" >&5
-$as_echo_n "checking for the absolute file name of the 'guild' command... " >&6; }
-if ${ac_cv_guild_program_name+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_cv_guild_program_name="`"${pkg_config_prog_path}" --variable guild "${guile_version}"`"
+  ac_cv_guild_program_name="`"${PKG_CONFIG}" --variable guild "${guile_version}"`"
 
      # In Guile up to 2.0.11 included, guile-2.0.pc would not define
      # the 'guild' and 'bindir' variables.  In that case, try to guess
      # what the program name is, at the risk of getting it wrong if
      # Guile was configured with '--program-suffix' or similar.
      if test "x$ac_cv_guild_program_name" = "x"; then
-       guile_exec_prefix="`"${pkg_config_prog_path}" --variable exec_prefix "${guile_version}"`"
+       guile_exec_prefix="`"${PKG_CONFIG}" --variable exec_prefix "${guile_version}"`"
        ac_cv_guild_program_name="$guile_exec_prefix/bin/guild"
      fi
 
@@ -23326,8 +23397,6 @@ $as_echo "$ac_cv_guild_program_name" >&6
   GUILD="$ac_cv_guild_program_name"
 
 
-    ;;
-  esac
 
 
   if test "$cross_compiling" = no; then
@@ -23356,6 +23425,8 @@ $as_echo "$ac_cv_guild_ok" >&6; }
 
     if test "$ac_cv_guild_ok" = no; then
     have_libguile=no
+    unset GUILE_CFLAGS
+    unset GUILE_LIBS
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: disabling guile support" >&5
 $as_echo "$as_me: WARNING: disabling guile support" >&2;}
   fi
@@ -23374,7 +23445,7 @@ $as_echo "#define HAVE_GUILE 1" >>confde
     save_LIBS="$LIBS"
   save_CPPFLAGS="$CPPFLAGS"
   LIBS="$GUILE_LIBS"
-  CPPFLAGS="$GUILE_CPPFLAGS"
+  CPPFLAGS="$GUILE_CFLAGS"
   for ac_func in scm_new_smob
 do :
   ac_fn_c_check_func "$LINENO" "scm_new_smob" "ac_cv_func_scm_new_smob"
@@ -23394,8 +23465,6 @@ else
   CONFIG_OBS="$CONFIG_OBS guile/guile.o"
   CONFIG_SRCS="$CONFIG_SRCS guile/guile.c"
 fi
-
-
  if test "${have_libguile}" != no; then
   HAVE_GUILE_TRUE=
   HAVE_GUILE_FALSE='#'
@@ -23405,6 +23474,132 @@ else
 fi
 
 
+if test x"${guile_PKG_CONFIG_set}" != x; then
+  PKG_CONFIG=${guile_PKG_CONFIG}
+  ac_cv_path_PKG_CONFIG=${guile_cache_PKG_CONFIG}
+
+
+
+
+
+
+
+
+if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
+	if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args.
+set dummy ${ac_tool_prefix}pkg-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_PKG_CONFIG+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+PKG_CONFIG=$ac_cv_path_PKG_CONFIG
+if test -n "$PKG_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5
+$as_echo "$PKG_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_PKG_CONFIG"; then
+  ac_pt_PKG_CONFIG=$PKG_CONFIG
+  # Extract the first word of "pkg-config", so it can be a program name with args.
+set dummy pkg-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_pt_PKG_CONFIG+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG
+if test -n "$ac_pt_PKG_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5
+$as_echo "$ac_pt_PKG_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_PKG_CONFIG" = x; then
+    PKG_CONFIG=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    PKG_CONFIG=$ac_pt_PKG_CONFIG
+  fi
+else
+  PKG_CONFIG="$ac_cv_path_PKG_CONFIG"
+fi
+
+fi
+if test -n "$PKG_CONFIG"; then
+	_pkg_min_version=0.29
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking pkg-config is at least version $_pkg_min_version" >&5
+$as_echo_n "checking pkg-config is at least version $_pkg_min_version... " >&6; }
+	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	else
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+		PKG_CONFIG=""
+	fi
+fi
+fi
+
 # ---------------------------- #
 # Check for source highlight.  #
 # ---------------------------- #
@@ -23431,23 +23626,118 @@ fi
 if test "${enable_source_highlight}" != "no"; then
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the source-highlight library" >&5
 $as_echo_n "checking for the source-highlight library... " >&6; }
-  if test "${pkg_config_prog_path}" = "missing"; then
+  if test x"${PKG_CONFIG}" = x; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no - pkg-config not found" >&5
 $as_echo "no - pkg-config not found" >&6; }
     if test "${enable_source_highlight}" = "yes"; then
       as_fn_error $? "pkg-config was not found in your system" "$LINENO" 5
     fi
   else
-    if ${pkg_config_prog_path} --exists source-highlight; then
+    _save_PKG_CONFIG=$PKG_CONFIG
+PKG_CONFIG="$PKG_CONFIG --static"
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for source-highlight" >&5
+$as_echo_n "checking for source-highlight... " >&6; }
+
+if test -n "$SRCHIGH_CFLAGS"; then
+    pkg_cv_SRCHIGH_CFLAGS="$SRCHIGH_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"source-highlight\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "source-highlight") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_SRCHIGH_CFLAGS=`$PKG_CONFIG --cflags "source-highlight" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$SRCHIGH_LIBS"; then
+    pkg_cv_SRCHIGH_LIBS="$SRCHIGH_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"source-highlight\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "source-highlight") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_SRCHIGH_LIBS=`$PKG_CONFIG --libs "source-highlight" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+if test $pkg_failed = no; then
+  pkg_save_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $pkg_cv_SRCHIGH_LIBS"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+  pkg_failed=yes
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+  LDFLAGS=$pkg_save_LDFLAGS
+fi
+
+
+
+if test $pkg_failed = yes; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        SRCHIGH_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "source-highlight" 2>&1`
+        else
+	        SRCHIGH_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "source-highlight" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$SRCHIGH_PKG_ERRORS" >&5
+
+	have_source_highlight=no
+elif test $pkg_failed = untried; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	have_source_highlight=no
+else
+	SRCHIGH_CFLAGS=$pkg_cv_SRCHIGH_CFLAGS
+	SRCHIGH_LIBS=$pkg_cv_SRCHIGH_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	have_source_highlight=yes
+fi
+PKG_CONFIG=$_save_PKG_CONFIG
+    if test x"${have_source_highlight}" = xyes; then
       case "$LDFLAGS" in
         *static-libstdc*)
           as_fn_error $? "source highlight is incompatible with -static-libstdc++; either use --disable-source-highlight or --without-static-standard-libraries" "$LINENO" 5
           ;;
       esac
 
-      srchigh_pkg_cflags=`${pkg_config_prog_path} --cflags source-highlight`
-      srchigh_pkg_libs=`${pkg_config_prog_path} --static --libs source-highlight`
-
       # Now that we have found a source-highlight library, check if we can use
       # it.  In particular, we're trying to detect the situation that the
       # library is using the new libstdc++ library abi ( see
@@ -23465,8 +23755,8 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 
       save_CXXFLAGS="$CXXFLAGS"
       save_LIBS="$LIBS"
-      CXXFLAGS="$CXXFLAGS $srchigh_pkg_cflags"
-      LIBS="$LIBS $srchigh_pkg_libs"
+      CXXFLAGS="$CXXFLAGS $SRCHIGH_CFLAGS"
+      LIBS="$LIBS $SRCHIGH_LIBS"
       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <srchilite/sourcehighlight.h>
@@ -23503,14 +23793,14 @@ $as_echo "#define HAVE_SOURCE_HIGHLIGHT
 
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
-        SRCHIGH_CFLAGS="$srchigh_pkg_cflags"
-        SRCHIGH_LIBS="$srchigh_pkg_libs"
       else
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
         if test "${enable_source_highlight}" = "yes"; then
           as_fn_error $? "source-highlight in your system could not be used" "$LINENO" 5
         fi
+        unset SRCHIGH_CFLAGS
+        unset SRCHIGH_LIBS
       fi
     else
       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
@@ -23522,8 +23812,6 @@ $as_echo "no" >&6; }
   fi
 fi
 
-
-
 # ------------------------- #
 # Checks for header files.  #
 # ------------------------- #
Index: src/gdb/configure.ac
===================================================================
--- src.orig/gdb/configure.ac
+++ src/gdb/configure.ac
@@ -995,20 +995,18 @@ AM_CONDITIONAL(HAVE_PYTHON, test "${have
 # -------------------- #
 
 dnl Utility to simplify finding libguile.
-dnl $1 = pkg-config-program
-dnl $2 = space-separated list of guile version numbers or package names to try
-dnl $3 = yes|no, indicating whether to flag errors or ignore them
-dnl $4 = the shell variable to assign the result to
+dnl $1 = space-separated list of guile version numbers or package names to try
+dnl $2 = yes|no, indicating whether to flag errors or ignore them
+dnl $3 = the shell variable to assign the result to
 dnl      If libguile is found we store "yes" here.
 
 AC_DEFUN([AC_TRY_LIBGUILE],
 [
-  pkg_config=$1
-  guile_version_list=$2
-  flag_errors=$3
-  define([have_libguile_var],$4)
+  guile_version_list=$1
+  flag_errors=$2
+  define([have_libguile_var],$3)
   found_usable_guile=checking
-  AC_MSG_CHECKING([for usable guile from ${pkg_config}])
+  AC_MSG_CHECKING([for usable guile from ${PKG_CONFIG}])
   for guile_version in ${guile_version_list}; do
     case "${guile_version}" in
     *[[^.0-9]]*)
@@ -1017,23 +1015,11 @@ AC_DEFUN([AC_TRY_LIBGUILE],
       guile_version=guile-"${guile_version}"
       ;;
     esac
-    ${pkg_config} --exists ${guile_version} 2>/dev/null
-    if test $? != 0; then
-      continue
-    fi
-    dnl pkg-config says the package exists, so if we get an error now,
-    dnl that's bad.
-    new_CPPFLAGS=`${pkg_config} --cflags ${guile_version}`
-    if test $? != 0; then
-      AC_MSG_ERROR([failure running pkg-config --cflags ${guile_version}])
-    fi
-    new_LIBS=`${pkg_config} --static --libs ${guile_version}`
-    if test $? != 0; then
-      AC_MSG_ERROR([failure running pkg-config --libs ${guile_version}])
+    PKG_CHECK_MODULES_STATIC([GUILE], [${guile_version}],
+			     [found_usable_guile=${guile_version}], [:])
+    if test "${found_usable_guile}" != "checking"; then
+      break
     fi
-    dnl If we get this far, great.
-    found_usable_guile=${guile_version}
-    break
   done
   if test "${found_usable_guile}" = "checking"; then
     if test "${flag_errors}" = "yes"; then
@@ -1047,13 +1033,11 @@ AC_DEFUN([AC_TRY_LIBGUILE],
   if test "${found_usable_guile}" != no; then
     save_CPPFLAGS=$CPPFLAGS
     save_LIBS=$LIBS
-    CPPFLAGS="$CPPFLAGS $new_CPPFLAGS"
-    LIBS="$LIBS $new_LIBS"
+    CPPFLAGS="$CPPFLAGS $GUILE_CFLAGS"
+    LIBS="$LIBS $GUILE_LIBS"
     AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include "libguile.h"]],
                                    [[scm_init_guile ();]])],
-                   [have_libguile_var=yes
-                    GUILE_CPPFLAGS=$new_CPPFLAGS
-                    GUILE_LIBS=$new_LIBS],
+                   [have_libguile_var=yes],
                    [found_usable_guile=no])
     dnl scm_set_automatic_finalization_enabled added in Guile 2.2.
     AC_CHECK_FUNC(scm_set_automatic_finalization_enabled,
@@ -1066,6 +1050,8 @@ AC_DEFUN([AC_TRY_LIBGUILE],
       if test "${flag_errors}" = yes; then
         AC_MSG_FAILURE([linking guile version ${guile_version} test program failed])
       fi
+      unset GUILE_CFLAGS
+      unset GUILE_LIBS
     fi
   fi
   AC_MSG_RESULT([${found_usable_guile}])
@@ -1079,13 +1065,13 @@ dnl        The pkg-config program must b
 dnl auto - Same as "yes", but if guile is missing from the system,
 dnl        fall back to "no".
 dnl guile-version [guile-version-choice-2 ...] -
-dnl        A space-separated list of guile package version numbers
-dnl        or names to try.  Numbers have "guile-" prepended while
-dnl        names are passed to pkg-config as-is.
+dnl        Same as "yes", with a space-separated list of guile package
+dnl        version numbers or names to try.  Numbers have "guile-"
+dnl        prepended while names are passed to pkg-config as-is.
 dnl        E.g. 3.0, guile-2.0 or guile-2.2-uninstalled.
 dnl        This requires making sure PKG_CONFIG_PATH is set appropriately.
 dnl /path/to/pkg-config -
-dnl        Use this pkg-config program.
+dnl        Same as "yes", but use this pkg-config program.
 dnl        NOTE: This needn't be the "real" pkg-config program.
 dnl        It could be a shell script.  It is invoked as:
 dnl        pkg-config --exists $version
@@ -1101,64 +1087,67 @@ AC_ARG_WITH(guile,
 AC_MSG_CHECKING([whether to use guile])
 AC_MSG_RESULT([$with_guile])
 
-dnl We check guile with pkg-config.
-AC_PATH_PROG(pkg_config_prog_path, pkg-config, missing)
-
 try_guile_versions="guile-3.0 guile-2.2 guile-2.0"
-have_libguile=no
 case "${with_guile}" in
-no)
-  AC_MSG_WARN([guile support disabled; some features will be unavailable.])
-  ;;
-auto)
-  if test "${pkg_config_prog_path}" = "missing"; then
-    AC_MSG_WARN([pkg-config not found, guile support disabled])
-  else
-    AC_TRY_LIBGUILE(${pkg_config_prog_path}, ${try_guile_versions}, no, have_libguile)
-  fi
-  ;;
-yes)
-  if test "${pkg_config_prog_path}" = "missing"; then
-    AC_MSG_ERROR([pkg-config not found])
-  fi
-  AC_TRY_LIBGUILE(${pkg_config_prog_path}, ${try_guile_versions}, yes, have_libguile)
+no|auto|yes)
+  try_guile=${with_guile}
   ;;
 [[\\/]]* | ?:[[\\/]]*)
-  if test -x "${with_guile}"; then
-    AC_TRY_LIBGUILE(${with_guile}, ${try_guile_versions}, yes, have_libguile)
-  else
+  try_guile=yes
+  if test ! -x "${with_guile}"; then
     AC_MSG_ERROR([Guile config program not executable: ${with_guile}])
   fi
+  guile_PKG_CONFIG_set=yes
+  guile_PKG_CONFIG=${PKG_CONFIG}
+  guile_cache_PKG_CONFIG=${ac_cv_path_PKG_CONFIG}
+  PKG_CONFIG=${with_guile}
+  ac_cv_path_PKG_CONFIG=${with_guile}
   ;;
 "" | */*)
   # Disallow --with=guile="" and --with-guile=foo/bar.
   AC_MSG_ERROR([invalid value for --with-guile])
   ;;
 *)
-  # A space separate list of guile versions to try, in order.
-  if test "${pkg_config_prog_path}" = "missing"; then
+  try_guile=yes
+  try_guile_versions=${with_guile}
+  ;;
+esac
+
+dnl We check guile with pkg-config.
+PKG_PREREQ([0.29])
+PKG_PROG_PKG_CONFIG([0.29])
+
+have_libguile=no
+case "${try_guile}" in
+auto)
+  if test x"${PKG_CONFIG}" = x; then
+    AC_MSG_WARN([pkg-config not found, guile support disabled])
+  else
+    AC_TRY_LIBGUILE(${try_guile_versions}, no, have_libguile)
+  fi
+  ;;
+yes)
+  if test x"${PKG_CONFIG}" = x; then
     AC_MSG_ERROR([pkg-config not found])
   fi
-  AC_TRY_LIBGUILE(${pkg_config_prog_path}, ${with_guile}, yes, have_libguile)
+  AC_TRY_LIBGUILE(${try_guile_versions}, yes, have_libguile)
+  ;;
+*)
+  AC_MSG_WARN([guile support disabled; some features will be unavailable.])
   ;;
 esac
 
 if test "${have_libguile}" != no; then
   dnl Get the name of the 'guild' program.
-  case "${with_guile}" in
-  [[\\/]]* | ?:[[\\/]]*)
-    GDB_GUILE_PROGRAM_NAMES(["${with_guile}"], ["${guile_version}"])
-    ;;
-  *)
-    GDB_GUILE_PROGRAM_NAMES(["${pkg_config_prog_path}"], ["${guile_version}"])
-    ;;
-  esac
+  GDB_GUILE_PROGRAM_NAMES(["${PKG_CONFIG}"], ["${guile_version}"])
 
   dnl Make sure guild can handle this host.
   GDB_TRY_GUILD([$srcdir/guile/lib/gdb/support.scm])
   dnl If not, disable guile support.
   if test "$ac_cv_guild_ok" = no; then
     have_libguile=no
+    unset GUILE_CFLAGS
+    unset GUILE_LIBS
     AC_MSG_WARN(disabling guile support, $GUILD fails compiling for $host)
   fi
 fi
@@ -1175,7 +1164,7 @@ if test "${have_libguile}" != no; then
   save_LIBS="$LIBS"
   save_CPPFLAGS="$CPPFLAGS"
   LIBS="$GUILE_LIBS"
-  CPPFLAGS="$GUILE_CPPFLAGS"
+  CPPFLAGS="$GUILE_CFLAGS"
   AC_CHECK_FUNCS([scm_new_smob])
   LIBS="$save_LIBS"
   CPPFLAGS="$save_CPPFLAGS"
@@ -1185,10 +1174,16 @@ else
   CONFIG_OBS="$CONFIG_OBS guile/guile.o"
   CONFIG_SRCS="$CONFIG_SRCS guile/guile.c"
 fi
-AC_SUBST(GUILE_CPPFLAGS)
-AC_SUBST(GUILE_LIBS)
 AM_CONDITIONAL(HAVE_GUILE, test "${have_libguile}" != no)
 
+if test x"${guile_PKG_CONFIG_set}" != x; then
+  PKG_CONFIG=${guile_PKG_CONFIG}
+  ac_cv_path_PKG_CONFIG=${guile_cache_PKG_CONFIG}
+
+  dnl Rerun with the override removed.
+  PKG_PROG_PKG_CONFIG([0.29])
+fi
+
 # ---------------------------- #
 # Check for source highlight.  #
 # ---------------------------- #
@@ -1204,13 +1199,16 @@ AC_ARG_ENABLE([source-highlight],
 
 if test "${enable_source_highlight}" != "no"; then
   AC_MSG_CHECKING([for the source-highlight library])
-  if test "${pkg_config_prog_path}" = "missing"; then
+  if test x"${PKG_CONFIG}" = x; then
     AC_MSG_RESULT([no - pkg-config not found])
     if test "${enable_source_highlight}" = "yes"; then
       AC_MSG_ERROR([pkg-config was not found in your system])
     fi
   else
-    if ${pkg_config_prog_path} --exists source-highlight; then
+    PKG_CHECK_MODULES_STATIC([SRCHIGH], [source-highlight],
+			     [have_source_highlight=yes],
+			     [have_source_highlight=no])
+    if test x"${have_source_highlight}" = xyes; then
       case "$LDFLAGS" in
         *static-libstdc*)
           AC_MSG_ERROR([source highlight is incompatible with -static-libstdc++; dnl
@@ -1219,9 +1217,6 @@ either use --disable-source-highlight or
           ;;
       esac
 
-      srchigh_pkg_cflags=`${pkg_config_prog_path} --cflags source-highlight`
-      srchigh_pkg_libs=`${pkg_config_prog_path} --static --libs source-highlight`
-
       # Now that we have found a source-highlight library, check if we can use
       # it.  In particular, we're trying to detect the situation that the
       # library is using the new libstdc++ library abi ( see
@@ -1234,8 +1229,8 @@ either use --disable-source-highlight or
       AC_LANG_PUSH(C++)
       save_CXXFLAGS="$CXXFLAGS"
       save_LIBS="$LIBS"
-      CXXFLAGS="$CXXFLAGS $srchigh_pkg_cflags"
-      LIBS="$LIBS $srchigh_pkg_libs"
+      CXXFLAGS="$CXXFLAGS $SRCHIGH_CFLAGS"
+      LIBS="$LIBS $SRCHIGH_LIBS"
       AC_LINK_IFELSE(
         [AC_LANG_PROGRAM(
           [#include <srchilite/sourcehighlight.h>],
@@ -1253,13 +1248,13 @@ either use --disable-source-highlight or
         AC_DEFINE([HAVE_SOURCE_HIGHLIGHT], 1,
                   [Define to 1 if the source-highlight library is available])
         AC_MSG_RESULT([yes])
-        SRCHIGH_CFLAGS="$srchigh_pkg_cflags"
-        SRCHIGH_LIBS="$srchigh_pkg_libs"
       else
         AC_MSG_RESULT([no])
         if test "${enable_source_highlight}" = "yes"; then
           AC_MSG_ERROR([source-highlight in your system could not be used])
         fi
+        unset SRCHIGH_CFLAGS
+        unset SRCHIGH_LIBS
       fi
     else
       AC_MSG_RESULT([no])
@@ -1269,8 +1264,6 @@ either use --disable-source-highlight or
     fi
   fi
 fi
-AC_SUBST(SRCHIGH_LIBS)
-AC_SUBST(SRCHIGH_CFLAGS)
 
 # ------------------------- #
 # Checks for header files.  #

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] GDB: Run `pkg-config' with `--static' to pull libguile dependencies
  2022-11-24 23:51 ` [PATCH 1/3] GDB: Run `pkg-config' with `--static' to pull libguile dependencies Maciej W. Rozycki
@ 2022-11-25  7:56   ` Eli Zaretskii
  2022-11-28 12:59     ` Maciej W. Rozycki
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2022-11-25  7:56 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: gdb-patches

> Date: Thu, 24 Nov 2022 23:51:09 +0000 (GMT)
> From: "Maciej W. Rozycki" <macro@embecosm.com>
> 
> Fix a configuration error:
> 
> checking whether to use guile... guile-2.2
> checking for pkg-config... /usr/bin/pkg-config
> checking for usable guile from /usr/bin/pkg-config... checking for scm_set_automatic_finalization_enabled... no
> configure: error: in `.../gdb':
> configure: error: linking guile version guile-2.2 test program failed
> See `config.log' for more details
> make[1]: *** [Makefile:12160: configure-gdb] Error 1
> 
> coming from link errors as recorded in `config.log' referred:
> 
> configure:19349: checking for scm_set_automatic_finalization_enabled
> configure:19349: gcc -o conftest -pipe -O2      -pthread -I.../include/guile/2.2   conftest.c -lncursesw -lm -ldl  -L.../lib -lguile-2.2 -lgc >&5
> /usr/bin/ld: .../lib/libguile-2.2.a(libguile_2.2_la-ports.o): in function `scm_ungetc':
> (.text+0x5561): undefined reference to `u32_conv_to_encoding'
> /usr/bin/ld: (.text+0x56e1): undefined reference to `u32_to_u8'
> 
> etc., etc., in a valid configuration where a static version of libguile 
> has only been installed, which is a pefectly valid system configuration.  
> This is due to symbols being required from libguile's dependencies that 
> have not been included in the linker invocation.
> 
> In configurations using the ELF format dynamic libguile implicitly pulls 
> indirect dependencies in the link, but to satisfy static libguile they 
> need to be named explicitly.  These dependencies have been recorded and 
> can be supplied by `pkg-config', but for that to happen the tool has to 
> be invoked with the `--static' option in addition to `--libs'.  Moreover 
> it is recommended, at least with systems using the ELF format, to have 
> indirect dependencies included with static linker invocation even where 
> they all are satisfied by dynamic libraries.

If only a static version of the Guile library is installed, how come
"pkg-config --libs" doesn't produce the list of all the dependency libraries
for static linking?  Isn't that a bug in Guile installation on that system?

> Therefore fix the issue by using the `--static' option unconditionally 
> with `pkg-config', adding the dependencies required:

I don't think I've every seen a configure script that explicitly includes
the --static switch to pkg-config.  Did you?  If not, how do they deal with
this issue?  Almost any external library with which GDB is linked can be
installed as a static-only library, so do we need to use --static in all
pkg-config tests?  I see that your proposed patch only changes the tests for
Guile and for source-highlight libraries.

Thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] GDB: Permit a lone version of Guile with `--with-guile='
  2022-11-24 23:51 ` [PATCH 2/3] GDB: Permit a lone version of Guile with `--with-guile=' Maciej W. Rozycki
@ 2022-11-26 23:38   ` Mike Frysinger
  2022-11-28 13:00     ` Maciej W. Rozycki
  0 siblings, 1 reply; 9+ messages in thread
From: Mike Frysinger @ 2022-11-26 23:38 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 396 bytes --]

On 24 Nov 2022 23:51, Maciej W. Rozycki wrote:
> --- src.orig/gdb/configure.ac
> +++ src/gdb/configure.ac
> +    case "${guile_version}" in
> +    *[[^.0-9]]*)

in POSIX shell, don't you need to use ! instead of ^ ?
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_04_05
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] GDB: Run `pkg-config' with `--static' to pull libguile dependencies
  2022-11-25  7:56   ` Eli Zaretskii
@ 2022-11-28 12:59     ` Maciej W. Rozycki
  2022-11-28 13:35       ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Maciej W. Rozycki @ 2022-11-28 12:59 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

On Fri, 25 Nov 2022, Eli Zaretskii wrote:

> > In configurations using the ELF format dynamic libguile implicitly pulls 
> > indirect dependencies in the link, but to satisfy static libguile they 
> > need to be named explicitly.  These dependencies have been recorded and 
> > can be supplied by `pkg-config', but for that to happen the tool has to 
> > be invoked with the `--static' option in addition to `--libs'.  Moreover 
> > it is recommended, at least with systems using the ELF format, to have 
> > indirect dependencies included with static linker invocation even where 
> > they all are satisfied by dynamic libraries.
> 
> If only a static version of the Guile library is installed, how come
> "pkg-config --libs" doesn't produce the list of all the dependency libraries
> for static linking?  Isn't that a bug in Guile installation on that system?

 If anything, it's a bug in Guile itself, or more likely a design issue 
with pkg-config.  Looking at its .pc template I can see no provision for a 
different library arrangement depending on whether `--enable-shared' or 
`--disable-shared' is in effect with `configure':

Libs: -L${libdir} -lguile-@GUILE_EFFECTIVE_VERSION@ @BDW_GC_LIBS@
Libs.private: @LIB_CLOCK_GETTIME@ @LIBGMP@ @LIBLTDL@ @LIBFFI_LIBS@	\
  @LIBUNISTRING@ @GUILE_LIBS@ @LIBICONV@ @LIBINTL@ @LIBSOCKET@		\
  @SERVENT_LIB@ @HOSTENT_LIB@ @GETADDRINFO_LIB@ @INET_NTOP_LIB@		\
  @INET_PTON_LIB@

 I have skimmed over the very few .pc templates I could find around on my 
system and they all seem to do essentially the same.  For example have a 
look at zlib/contrib/minizip/minizip.pc.in in our very own tree.  While 
not used by us it's taken verbatim from the upstream zlib distribution and 
supplied with libminizip, which has a dependency on libz.

 But the template has just:

Libs: -L${libdir} -lminizip
Libs.private: -lz

i.e. it's all fixed with no `configure' processing whatsoever and there is 
no provision for pulling `-lz' unless `--static' has been explicitly given 
to `pkg-config'.

 But any such provision looks to me like a lot of effort for software 
writers, to take away which is the very purpose of pkg-config.  So what I 
think pkg-config should do is to provide a flag for the .pc file to be set 
by `configure' or otherwise, which would tell pkg-config that said package 
has been built with no shared libraries available, via `--disable-shared' 
or an equivalent.

 In such a case pkg-config would always include Libs.private along with 
Libs when requested by `--libs', even if no `--static' option has been 
given.  Which leads me to a conclusion it's an oversight in the pkg-config 
design that it does not provide for the static-only link scenario in a 
reasonable way.

> > Therefore fix the issue by using the `--static' option unconditionally 
> > with `pkg-config', adding the dependencies required:
> 
> I don't think I've every seen a configure script that explicitly includes
> the --static switch to pkg-config.  Did you?  If not, how do they deal with
> this issue?  Almost any external library with which GDB is linked can be
> installed as a static-only library, so do we need to use --static in all
> pkg-config tests?  I see that your proposed patch only changes the tests for
> Guile and for source-highlight libraries.

 It seems to me that distributions universally build libraries as shared 
and do not provide for installing static libraries without their shared 
counterparts.  And that people hardly ever build from sources nowadays.

 So it looks to me like this issue is not dealt with at all, and while we 
might try to fix the world outside, it could be a futile effort.  And in 
any case it'd be long until any solution lands downstream.  Then as I say 
indirect dependencies are best included in ELF links involving dynamic 
shared objects anyway, so I think using `--static' is in my opinion a 
reasonable solution.  I think it's also needed for the `CFLAGS=-static' 
case too.  Cf. <https://bugs.freedesktop.org/show_bug.cgi?id=19541>.

 I haven't looked at pieces coming from outside gdb/, and I can see now 
that the debuginfod library isn't handled at this point (I don't know if 
it has any indirect dependencies).  It's use here is a strong argument in 
favour of 3/3, so that we don't use $pkg_config and $PKG_CONFIG variables 
both at a time for the same thing in a single script (what a mess!).

 Do you find my observations a sufficient justification for my proposed 
change now?  Thank you for your insights!

  Maciej

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] GDB: Permit a lone version of Guile with `--with-guile='
  2022-11-26 23:38   ` Mike Frysinger
@ 2022-11-28 13:00     ` Maciej W. Rozycki
  0 siblings, 0 replies; 9+ messages in thread
From: Maciej W. Rozycki @ 2022-11-28 13:00 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: gdb-patches

On Sun, 27 Nov 2022, Mike Frysinger wrote:

> On 24 Nov 2022 23:51, Maciej W. Rozycki wrote:
> > --- src.orig/gdb/configure.ac
> > +++ src/gdb/configure.ac
> > +    case "${guile_version}" in
> > +    *[[^.0-9]]*)
> 
> in POSIX shell, don't you need to use ! instead of ^ ?
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_04_05
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13

 I guess you are right, although I have never come across it in my 25+ 
years' shell programming experience.  Bash manual says either character is 
accepted, which is I suppose why I have never had an issue with using `^'.  
I'll send v2.

 Well-spotted, thank you!

  Maciej

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] GDB: Run `pkg-config' with `--static' to pull libguile dependencies
  2022-11-28 12:59     ` Maciej W. Rozycki
@ 2022-11-28 13:35       ` Eli Zaretskii
  0 siblings, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2022-11-28 13:35 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: gdb-patches

> Date: Mon, 28 Nov 2022 12:59:52 +0000 (GMT)
> From: "Maciej W. Rozycki" <macro@embecosm.com>
> cc: gdb-patches@sourceware.org
> 
> > If only a static version of the Guile library is installed, how come
> > "pkg-config --libs" doesn't produce the list of all the dependency libraries
> > for static linking?  Isn't that a bug in Guile installation on that system?
> 
>  If anything, it's a bug in Guile itself

Well, "bug in Guile installation" and "bug in Guile itself" are almost
synonymous...

> or more likely a design issue with pkg-config.

That I don't think.

Basically, I think a static-library only installation should have the same
list of libraries in Libs and in Libs.private.  And this should be produced
by the build when the user selects --disable-shared.

>  But any such provision looks to me like a lot of effort for software 
> writers, to take away which is the very purpose of pkg-config.  So what I 
> think pkg-config should do is to provide a flag for the .pc file to be set 
> by `configure' or otherwise, which would tell pkg-config that said package 
> has been built with no shared libraries available, via `--disable-shared' 
> or an equivalent.

That "flag" is the value of Libs, AFAIU.

>  In such a case pkg-config would always include Libs.private along with 
> Libs when requested by `--libs', even if no `--static' option has been 
> given.  Which leads me to a conclusion it's an oversight in the pkg-config 
> design that it does not provide for the static-only link scenario in a 
> reasonable way.

I'm not sure it's an oversight in the design of pkg-config, but I'm not an
expert on that enough to be sure.

> > > Therefore fix the issue by using the `--static' option unconditionally 
> > > with `pkg-config', adding the dependencies required:
> > 
> > I don't think I've every seen a configure script that explicitly includes
> > the --static switch to pkg-config.  Did you?  If not, how do they deal with
> > this issue?  Almost any external library with which GDB is linked can be
> > installed as a static-only library, so do we need to use --static in all
> > pkg-config tests?  I see that your proposed patch only changes the tests for
> > Guile and for source-highlight libraries.
> 
>  It seems to me that distributions universally build libraries as shared 
> and do not provide for installing static libraries without their shared 
> counterparts.  And that people hardly ever build from sources nowadays.

If that is what happens, maybe we shouldn't support this use case so easily
and OOTB?

>  So it looks to me like this issue is not dealt with at all, and while we 
> might try to fix the world outside, it could be a futile effort.  And in 
> any case it'd be long until any solution lands downstream.  Then as I say 
> indirect dependencies are best included in ELF links involving dynamic 
> shared objects anyway, so I think using `--static' is in my opinion a 
> reasonable solution.  I think it's also needed for the `CFLAGS=-static' 
> case too.  Cf. <https://bugs.freedesktop.org/show_bug.cgi?id=19541>.
> 
>  I haven't looked at pieces coming from outside gdb/, and I can see now 
> that the debuginfod library isn't handled at this point (I don't know if 
> it has any indirect dependencies).  It's use here is a strong argument in 
> favour of 3/3, so that we don't use $pkg_config and $PKG_CONFIG variables 
> both at a time for the same thing in a single script (what a mess!).
> 
>  Do you find my observations a sufficient justification for my proposed 
> change now?  Thank you for your insights!

I'm not opposed to installing your changes, as they cannot do any harm,
AFAICT.  maybe just add enough commentary about this unusual practice to
explain why we do it.

Thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-11-28 13:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-24 23:50 [PATCH 0/3] GDB: Fix `pkg-config' issues with configuring for Guile Maciej W. Rozycki
2022-11-24 23:51 ` [PATCH 1/3] GDB: Run `pkg-config' with `--static' to pull libguile dependencies Maciej W. Rozycki
2022-11-25  7:56   ` Eli Zaretskii
2022-11-28 12:59     ` Maciej W. Rozycki
2022-11-28 13:35       ` Eli Zaretskii
2022-11-24 23:51 ` [PATCH 2/3] GDB: Permit a lone version of Guile with `--with-guile=' Maciej W. Rozycki
2022-11-26 23:38   ` Mike Frysinger
2022-11-28 13:00     ` Maciej W. Rozycki
2022-11-24 23:51 ` [PATCH 3/3] GDB: Use standard autoconf macros for `pkg-config' Maciej W. Rozycki

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).