$OpenBSD: patch-scripts_buildversion_py,v 1.2 2021/09/01 11:04:21 sthen Exp $

Fixup "clean version" strings for packaging; it only allows this if there's
a consistent version number detected for all binutils tools, however this
detection is too simplistic to cope with older binutils (mix of
"GNU assembler 2.17" and "GNU ld version 2.17" etc).

Index: scripts/buildversion.py
--- scripts/buildversion.py.orig
+++ scripts/buildversion.py
@@ -4,7 +4,7 @@
 # Copyright (C) 2015  Kevin O'Connor <kevin@koconnor.net>
 #
 # This file may be distributed under the terms of the GNU GPLv3 license.
-import sys, os, subprocess, shlex, time, socket, optparse, logging, traceback
+import sys, os, subprocess, shlex, time, socket, optparse, logging, traceback, re
 
 VERSION_FORMAT = """
 /* DO NOT EDIT!  This is an autogenerated file.  See scripts/buildversion.py. */
@@ -74,6 +74,8 @@ def tool_versions(tools):
         verstr = check_output("%s --version" % (tool,)).split('\n')[0]
         # Check if this tool looks like a binutils program
         isbinutils = 0
+        if verstr.startswith('GNU ld version'):
+            verstr = re.sub('ld version', 'version', verstr)
         if verstr.startswith('GNU '):
             isbinutils = 1
             verstr = verstr[4:]
