Subject: [PATCH] Search for gcc-ar

From: Sam James <[email-masked]>
Date: Thu, 15 May 2025 03:46:55 +0100

GCC requires `ar` to have plugin support when using LTO. While the situation
has improved as many distributions install the GCC plugin to a location
that GNU Binutils can automatically find, this isn't required and isn't done
by default.

By searching for `gcc-ar` first, we can make this case work without
intervention from the user.

Problem reported by R. Diez in: https://savannah.gnu.org/support/?110475

	* m4/ar-lib.m4 (AM_PROG_AR): Search for gcc-ar.
---
I'm still testing this and going to play with it some more in the wild,
but how does this look in principle?

 NEWS         | 3 +++
 m4/ar-lib.m4 | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 30c0cd2c7..d448dba26 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,9 @@ New in 1.17.92:
 
   - Support for Algol 68 added, based on the GNU Algol 68 compiler. (bug#75807)
 
+  - AM_PROG_AR now searches for 'gcc-ar' first.
+    (https://savannah.gnu.org/support/?110475)
+
 * Bugs fixed
 
   - Do not make Perl warnings fatal, per Perl's recommendation.
diff --git a/m4/ar-lib.m4 b/m4/ar-lib.m4
index 568ea0798..c00c1a51e 100644
--- a/m4/ar-lib.m4
+++ b/m4/ar-lib.m4
@@ -16,7 +16,7 @@ AC_BEFORE([$0], [AC_PROG_LIBTOOL])dnl
 AC_BEFORE([$0], [AC_PROG_AR])dnl
 AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
 AC_REQUIRE_AUX_FILE([ar-lib])dnl
-AC_CHECK_TOOLS([AR], [ar lib "link -lib"], [false])
+AC_CHECK_TOOLS([AR], [gcc-ar ar lib "link -lib"], [false])
 : ${AR=ar}
 : ${ARFLAGS=cr}
 
-- 
2.49.0