diff mbox series

[v2] gdb/configure.ac: Fix AC_DEFINE_DIR to work with Windows path separator

Message ID 20240615040345.1824744-1-thiago.bauermann@linaro.org
State New
Headers show
Series [v2] gdb/configure.ac: Fix AC_DEFINE_DIR to work with Windows path separator | expand

Commit Message

Thiago Jung Bauermann June 15, 2024, 4:03 a.m. UTC
Both --with-auto-load-dir and --with-auto-load-safe-path accept a list of
directories, which are separated by ':' on Unix and ';' on Windows.
However, as mentioned in PR 18898 this doesn't work on the latter OS.

This is because the AC_DEFINE_DIR macro calls eval twice on the value
provided via these configure options, causing the ';' to be interpreted by
the shell.  E.g.,

  $ ~/src/binutils-gdb/configure \
      --disable-{binutils,ld,gold,gas,sim,gprof,gprofng} \
      --with-auto-load-dir='foo;bar' && make
      ⋮
  checking for default auto-load directory... /home/bauermann/src/binutils-gdb/gdb/configure: line 18004: bar: command not found
  foo;bar
  checking for default auto-load safe-path... /home/bauermann/src/binutils-gdb/gdb/configure: line 18031: bar: command not found
  foo;bar

Line 18004 is:

  ac_define_dir=`eval echo $escape_dir`

Line 18031 is identical.

AC_DEFINE_DIR originally came from autoconf-archive.  It was since
removed from there, but we ship it in gdb/include.m4.

Andrew noticed that the last version of the macro had improvements
around quoting.  And indeed, adopting the latest version does fix the
problem:

  $ ~/src/binutils-gdb/configure \
      --disable-{binutils,ld,gold,gas,sim,gprof,gprofng} \
      --with-auto-load-dir='foo;bar' && make
      ⋮
  checking for default auto-load directory... foo;bar
  checking for default auto-load safe-path... foo;bar
      ⋮
  $ grep AUTO_LOAD gdb/config.h
  #define AUTO_LOAD_DIR "foo;bar"
  #define AUTO_LOAD_SAFE_PATH "foo;bar"

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=18898
Suggested-by: Andrew Burgess <aburgess@redhat.com>
---

Hello,

This is a different approach to solve PR 18898.  v1 used the approach of
adding a MinGW special case in the definitions of --with-auto-load-dir and
--with-auto-load-safe-path to escape the ';' in them.

Andrew Burgess noticed that there was a newer definition of the
AC_DEFINE_DIR macro in autoconf-archive and suggested that it could fix
the problem. I tested it, and indeed it does! Though for completeness it
would be nice if Eli could confirm that it also solves the problem for
him.

So v2's approach is to update our definition of AC_DEFINE_DIR.

Changes since v1:
- Everything.

 gdb/acinclude.m4 |  19 +++---
 gdb/configure    | 148 +++++++++++++++++++++++++++++++++--------------
 2 files changed, 118 insertions(+), 49 deletions(-)
diff mbox series

Patch

diff --git a/gdb/acinclude.m4 b/gdb/acinclude.m4
index 915082056dd9..61f9d9fb5052 100644
--- a/gdb/acinclude.m4
+++ b/gdb/acinclude.m4
@@ -60,13 +60,18 @@  dnl Version 1.3 (2001/03/02)
 dnl source http://www.gnu.org/software/ac-archive/Miscellaneous/ac_define_dir.html
 
 AC_DEFUN([AC_DEFINE_DIR], [
-  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
-  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-  ac_define_dir=`eval echo [$]$2`
-  ac_define_dir=`eval echo [$]ac_define_dir`
-  ifelse($3, ,
-    AC_DEFINE_UNQUOTED($1, "$ac_define_dir"),
-    AC_DEFINE_UNQUOTED($1, "$ac_define_dir", $3))
+  prefix_NONE=
+  exec_prefix_NONE=
+  test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix
+  test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix
+dnl In Autoconf 2.60, ${datadir} refers to ${datarootdir}, which in turn
+dnl refers to ${prefix}.  Thus we have to use `eval' twice.
+  eval ac_define_dir="\"[$]$2\""
+  eval ac_define_dir="\"$ac_define_dir\""
+  AC_SUBST($1, "$ac_define_dir")
+  AC_DEFINE_UNQUOTED($1, "$ac_define_dir", [$3])
+  test "$prefix_NONE" && prefix=NONE
+  test "$exec_prefix_NONE" && exec_prefix=NONE
 ])
 
 dnl See whether we need a declaration for a function.
diff --git a/gdb/configure b/gdb/configure
index 15ececfefa26..8cb95e14a9a1 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -763,7 +763,11 @@  AMD_DBGAPI_CFLAGS
 ENABLE_BFD_64_BIT_FALSE
 ENABLE_BFD_64_BIT_TRUE
 subdirs
+AUTO_LOAD_SAFE_PATH
+AUTO_LOAD_DIR
+RELOC_SRCDIR
 GDB_DATADIR
+BINDIR
 DEBUGDIR
 MAKEINFO_EXTRA_FLAGS
 MAKEINFOFLAGS
@@ -11499,7 +11503,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11502 "configure"
+#line 11506 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11605,7 +11609,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11608 "configure"
+#line 11612 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -24620,15 +24624,21 @@  else
 fi
 
 
-  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
-  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-  ac_define_dir=`eval echo $DEBUGDIR`
-  ac_define_dir=`eval echo $ac_define_dir`
+  prefix_NONE=
+  exec_prefix_NONE=
+  test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix
+  test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix
+  eval ac_define_dir="\"$DEBUGDIR\""
+  eval ac_define_dir="\"$ac_define_dir\""
+  DEBUGDIR="$ac_define_dir"
+
 
 cat >>confdefs.h <<_ACEOF
 #define DEBUGDIR "$ac_define_dir"
 _ACEOF
 
+  test "$prefix_NONE" && prefix=NONE
+  test "$exec_prefix_NONE" && exec_prefix=NONE
 
 
 
@@ -24674,15 +24684,21 @@  fi
 # This breaks GDB's relocatable path conversions since paths passed in
 # config.h would not get so translated, the path prefixes no longer match.
 
-  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
-  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-  ac_define_dir=`eval echo $bindir`
-  ac_define_dir=`eval echo $ac_define_dir`
+  prefix_NONE=
+  exec_prefix_NONE=
+  test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix
+  test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix
+  eval ac_define_dir="\"$bindir\""
+  eval ac_define_dir="\"$ac_define_dir\""
+  BINDIR="$ac_define_dir"
+
 
 cat >>confdefs.h <<_ACEOF
 #define BINDIR "$ac_define_dir"
 _ACEOF
 
+  test "$prefix_NONE" && prefix=NONE
+  test "$exec_prefix_NONE" && exec_prefix=NONE
 
 
 # GDB's datadir relocation
@@ -24698,15 +24714,21 @@  else
 fi
 
 
-  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
-  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-  ac_define_dir=`eval echo $GDB_DATADIR`
-  ac_define_dir=`eval echo $ac_define_dir`
+  prefix_NONE=
+  exec_prefix_NONE=
+  test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix
+  test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix
+  eval ac_define_dir="\"$GDB_DATADIR\""
+  eval ac_define_dir="\"$ac_define_dir\""
+  GDB_DATADIR="$ac_define_dir"
+
 
 cat >>confdefs.h <<_ACEOF
 #define GDB_DATADIR "$ac_define_dir"
 _ACEOF
 
+  test "$prefix_NONE" && prefix=NONE
+  test "$exec_prefix_NONE" && exec_prefix=NONE
 
 
 
@@ -24739,15 +24761,21 @@  _ACEOF
 if test "${with_relocated_sources+set}" = set; then :
   withval=$with_relocated_sources; reloc_srcdir="${withval}"
 
-  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
-  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-  ac_define_dir=`eval echo $reloc_srcdir`
-  ac_define_dir=`eval echo $ac_define_dir`
+  prefix_NONE=
+  exec_prefix_NONE=
+  test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix
+  test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix
+  eval ac_define_dir="\"$reloc_srcdir\""
+  eval ac_define_dir="\"$ac_define_dir\""
+  RELOC_SRCDIR="$ac_define_dir"
+
 
 cat >>confdefs.h <<_ACEOF
 #define RELOC_SRCDIR "$ac_define_dir"
 _ACEOF
 
+  test "$prefix_NONE" && prefix=NONE
+  test "$exec_prefix_NONE" && exec_prefix=NONE
 
 
 fi
@@ -24765,15 +24793,21 @@  fi
 
 escape_dir=`echo $with_auto_load_dir | sed -e 's/[$]datadir\>/\\\\\\\\\\\\&/g' -e 's/[$]debugdir\>/\\\\\\\\\\\\&/g'`
 
-  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
-  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-  ac_define_dir=`eval echo $escape_dir`
-  ac_define_dir=`eval echo $ac_define_dir`
+  prefix_NONE=
+  exec_prefix_NONE=
+  test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix
+  test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix
+  eval ac_define_dir="\"$escape_dir\""
+  eval ac_define_dir="\"$ac_define_dir\""
+  AUTO_LOAD_DIR="$ac_define_dir"
+
 
 cat >>confdefs.h <<_ACEOF
 #define AUTO_LOAD_DIR "$ac_define_dir"
 _ACEOF
 
+  test "$prefix_NONE" && prefix=NONE
+  test "$exec_prefix_NONE" && exec_prefix=NONE
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_auto_load_dir" >&5
 $as_echo "$with_auto_load_dir" >&6; }
@@ -24792,15 +24826,21 @@  fi
 
 escape_dir=`echo $with_auto_load_safe_path | sed -e 's/[$]datadir\>/\\\\\\\\\\\\&/g' -e 's/[$]debugdir\>/\\\\\\\\\\\\&/g'`
 
-  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
-  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-  ac_define_dir=`eval echo $escape_dir`
-  ac_define_dir=`eval echo $ac_define_dir`
+  prefix_NONE=
+  exec_prefix_NONE=
+  test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix
+  test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix
+  eval ac_define_dir="\"$escape_dir\""
+  eval ac_define_dir="\"$ac_define_dir\""
+  AUTO_LOAD_SAFE_PATH="$ac_define_dir"
+
 
 cat >>confdefs.h <<_ACEOF
 #define AUTO_LOAD_SAFE_PATH "$ac_define_dir"
 _ACEOF
 
+  test "$prefix_NONE" && prefix=NONE
+  test "$exec_prefix_NONE" && exec_prefix=NONE
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_auto_load_safe_path" >&5
 $as_echo "$with_auto_load_safe_path" >&6; }
@@ -27343,15 +27383,21 @@  else
 fi
 
 
-  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
-  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-  ac_define_dir=`eval echo $JIT_READER_DIR`
-  ac_define_dir=`eval echo $ac_define_dir`
+  prefix_NONE=
+  exec_prefix_NONE=
+  test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix
+  test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix
+  eval ac_define_dir="\"$JIT_READER_DIR\""
+  eval ac_define_dir="\"$ac_define_dir\""
+  JIT_READER_DIR="$ac_define_dir"
+
 
 cat >>confdefs.h <<_ACEOF
 #define JIT_READER_DIR "$ac_define_dir"
 _ACEOF
 
+  test "$prefix_NONE" && prefix=NONE
+  test "$exec_prefix_NONE" && exec_prefix=NONE
 
 
 
@@ -30964,15 +31010,21 @@  else
 fi
 
 
-  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
-  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-  ac_define_dir=`eval echo $TARGET_SYSTEM_ROOT`
-  ac_define_dir=`eval echo $ac_define_dir`
+  prefix_NONE=
+  exec_prefix_NONE=
+  test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix
+  test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix
+  eval ac_define_dir="\"$TARGET_SYSTEM_ROOT\""
+  eval ac_define_dir="\"$ac_define_dir\""
+  TARGET_SYSTEM_ROOT="$ac_define_dir"
+
 
 cat >>confdefs.h <<_ACEOF
 #define TARGET_SYSTEM_ROOT "$ac_define_dir"
 _ACEOF
 
+  test "$prefix_NONE" && prefix=NONE
+  test "$exec_prefix_NONE" && exec_prefix=NONE
 
 
 
@@ -31010,15 +31062,21 @@  else
 fi
 
 
-  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
-  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-  ac_define_dir=`eval echo $SYSTEM_GDBINIT`
-  ac_define_dir=`eval echo $ac_define_dir`
+  prefix_NONE=
+  exec_prefix_NONE=
+  test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix
+  test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix
+  eval ac_define_dir="\"$SYSTEM_GDBINIT\""
+  eval ac_define_dir="\"$ac_define_dir\""
+  SYSTEM_GDBINIT="$ac_define_dir"
+
 
 cat >>confdefs.h <<_ACEOF
 #define SYSTEM_GDBINIT "$ac_define_dir"
 _ACEOF
 
+  test "$prefix_NONE" && prefix=NONE
+  test "$exec_prefix_NONE" && exec_prefix=NONE
 
 
 
@@ -31056,15 +31114,21 @@  else
 fi
 
 
-  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
-  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-  ac_define_dir=`eval echo $SYSTEM_GDBINIT_DIR`
-  ac_define_dir=`eval echo $ac_define_dir`
+  prefix_NONE=
+  exec_prefix_NONE=
+  test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix
+  test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix
+  eval ac_define_dir="\"$SYSTEM_GDBINIT_DIR\""
+  eval ac_define_dir="\"$ac_define_dir\""
+  SYSTEM_GDBINIT_DIR="$ac_define_dir"
+
 
 cat >>confdefs.h <<_ACEOF
 #define SYSTEM_GDBINIT_DIR "$ac_define_dir"
 _ACEOF
 
+  test "$prefix_NONE" && prefix=NONE
+  test "$exec_prefix_NONE" && exec_prefix=NONE