From b175f0b66edc1bd44b6624db0f74acdfa1bc500c Mon Sep 17 00:00:00 2001
From: Virgile Prevosto <virgile.prevosto@m4x.org>
Date: Fri, 17 Feb 2023 14:16:14 +0100
Subject: [PATCH] [machdep] give meta-info (compiler, version, arch flags) in
 machdep generation

---
 make_machdep/make_machdep.py | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/make_machdep/make_machdep.py b/make_machdep/make_machdep.py
index 200d6f966dd..246bcd1995b 100755
--- a/make_machdep/make_machdep.py
+++ b/make_machdep/make_machdep.py
@@ -63,8 +63,12 @@ my_path = Path(sys.argv[0]).parent
 parser = argparse.ArgumentParser(prog="make_machdep")
 parser.add_argument("-v", "--verbose", action="store_true")
 parser.add_argument("-o", default=sys.stdout, type=argparse.FileType("w"), dest="dest_file")
-parser.add_argument("--compiler", default="cc", help="which compiler to use. Default is 'cc'")
-parser.add_argument("--compiler-version")
+parser.add_argument("--compiler", default="cc", help="which compiler to use; default is 'cc'")
+parser.add_argument(
+    "--compiler-version",
+    default="--version",
+    help="option to pass to the compiler to obtain its version; default is --version"
+)
 parser.add_argument(
     "--cpp-arch-flags",
     nargs="+",
@@ -75,7 +79,7 @@ parser.add_argument(
     "--compiler-flags",
     nargs="+",
     default=["-c"],
-    help="flags to be given to the compiler (other than those set by --cpp-arch-flags); by default, '-c'",
+    help="flags to be given to the compiler (other than those set by --cpp-arch-flags); default is '-c'",
 )
 parser.add_argument("--check", action="store_true")
 args, other_args = parser.parse_known_args()
@@ -225,6 +229,15 @@ for (f, typ) in source_files:
         continue
     find_value(p.stem, typ, proc.stderr.decode())
 
+version_output = subprocess.run(
+    [args.compiler, args.compiler_version], capture_output=True, text=True
+)
+version = version_output.stdout.splitlines()[0]
+
+machdep["compiler"] = args.compiler
+machdep["cpp_arch_flags"] = ' '.join(args.cpp_arch_flags)
+machdep["version"] = version
+
 missing_fields = [f for [f, v] in machdep.items() if v is None]
 
 if missing_fields:
-- 
GitLab