From daf19e17615fdc58503ead8ebff252d7ade90fc0 Mon Sep 17 00:00:00 2001
From: Chris Packham <judge.packham@gmail.com>
Date: Sun, 29 Oct 2023 17:08:44 +1300
Subject: gdb: Use correct arguments for static linking

As of version 13.x GDB uses libtool for linking instead of g++ these
take different arguments for static linking.  Commit 6146b5a6 ("use
-all-static when building a static gdb") attempted to deal with this but
had the effect of causing older GDB versions to fail to build
statically. Add a new internal flag GDB_CC_LD_LIBTOOL and use this to
decide whether to pass `-static` or `-all-static`.

Fixes #2053
Signed-off-by: Chris Packham <judge.packham@gmail.com>
---
 scripts/build/debug/300-gdb.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

(limited to 'scripts')

diff --git a/scripts/build/debug/300-gdb.sh b/scripts/build/debug/300-gdb.sh
index 8860b541..de8d1b14 100644
--- a/scripts/build/debug/300-gdb.sh
+++ b/scripts/build/debug/300-gdb.sh
@@ -348,7 +348,11 @@ do_gdb_backend()
         "${extra_config[@]}"                        \
 
     if [ "${static}" = "y" ]; then
-        extra_make_flags+=("LDFLAGS=${ldflags} -all-static")
+        if [ "${GDB_CC_LD_LIBTOOL}" = "y" ]; then
+            extra_make_flags+=("LDFLAGS=${ldflags} -all-static")
+        else
+            extra_make_flags+=("LDFLAGS=${ldflags} -static")
+        fi
         CT_DoLog EXTRA "Prepare gdb for static build"
         CT_DoExecLog ALL make ${CT_JOBSFLAGS} configure-host
     fi
-- 
cgit v1.2.3