@@ -3292,7 +3292,20 @@ endif
# Generated sources #
#####################
-genh += configure_file(output: 'config-host.h', configuration: config_host_data)
+config_host_h = configure_file(output: 'config-host.h', configuration: config_host_data)
+genh += config_host_h
+
+build_info_h = custom_target('build-info.h',
+ output: 'build-info.h',
+ command: [
+ find_program('scripts/build_info_gen.py'),
+ '--config-headers',
+ config_host_h
+ ],
+ capture: true,
+ build_by_default: true,
+ build_always_stale: true)
+genh += build_info_h
hxtool = find_program('scripts/hxtool')
shaderinclude = find_program('scripts/shaderinclude.py')
@@ -24,6 +24,21 @@ SRST
Display version information and exit
ERST
+DEF("build-info", 0, QEMU_OPTION_build_info,
+ "-build-info display build information of executable and exit\n", QEMU_ARCH_ALL)
+SRST
+``-build-info``
+ Display build information of executable and exit
+ERST
+
+DEF("build-info-json", 0, QEMU_OPTION_build_info_json,
+ "-build-info-json\n"
+ " dump build information of executable in JSON format and exit\n", QEMU_ARCH_ALL)
+SRST
+``-build-info-json``
+ Dump build information of executable in JSON format and exit
+ERST
+
DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
"-machine [type=]name[,prop[=value][,...]]\n"
" selects emulated machine ('-machine help' for list)\n"
new file mode 100755
@@ -0,0 +1,91 @@
+#!/usr/bin/env python3
+
+"""
+Generate build information header, build-info.h,
+for output of -build-info* command line arguments.
+
+SPDX-FileContributor: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
+SPDX-FileCopyrightText: 2024 Linaro Ltd.
+SPDX-License-Identifier: GPL-2.0-or-later
+"""
+
+# Formatted with black --line-length 80 scripts/build-info-gen.py
+
+import argparse
+import logging
+
+
+def generate_key_val(header: str) -> str:
+ # pylint: disable=missing-function-docstring
+
+ with open(header, encoding="utf-8") as cfg:
+ config = [l.split()[1:] for l in cfg if l.startswith("#define")]
+
+ for cfg in config:
+ if cfg[0].startswith("HAVE_"):
+ yield (cfg[0].removeprefix("HAVE_").lower(), None)
+ continue
+ yield (
+ cfg[0].removeprefix("CONFIG_").lower(),
+ (
+ cfg[1]
+ if len(cfg) == 2
+ else "".join(cfg[1:]).replace('"', "") if len(cfg) > 2 else None
+ ),
+ )
+
+
+def main() -> None:
+ # pylint: disable=missing-function-docstring
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-v", "--verbose", action="store_true")
+ parser.add_argument(
+ "--config-headers",
+ metavar="CONFIG_HEADER",
+ action="append",
+ dest="config_headers",
+ help="paths to configuration host C headers (*.h files)",
+ required=False,
+ default=[],
+ )
+ args = parser.parse_args()
+ if args.verbose:
+ logging.basicConfig(level=logging.ERROR)
+ logging.debug("args: %s", args)
+ print(
+ """// @generated by scripts/build-info-gen.py
+
+#include <stddef.h>"""
+ )
+ print(
+ """static struct build_info_t {
+ const char *key;
+ const char *value;
+} BUILD_INFO[] = {"""
+ )
+ total = 0
+ header_width = 0
+ for header in args.config_headers:
+ for key, val in generate_key_val(header):
+ total += 1
+ header_width = max(header_width, len(key))
+ print(
+ '{"',
+ key,
+ '", "',
+ val.strip('"').strip(",").strip('"') if val else "",
+ '"},',
+ sep="",
+ )
+ print("};")
+ print("\nstatic size_t BUILD_INFO_SIZE = ", total, ";", sep="")
+ print(
+ "static unsigned int BUILD_INFO_HEADER_WIDTH = ",
+ header_width,
+ ";",
+ sep="",
+ )
+
+
+if __name__ == "__main__":
+ main()
@@ -908,6 +908,41 @@ static void help(int exitcode)
exit(exitcode);
}
+static void build_info(const char *execname, bool as_json)
+{
+#include "build-info.h"
+ if (as_json) {
+ printf("{\n");
+ for (size_t i = 0; i + 1 < BUILD_INFO_SIZE ; i++) {
+ printf("\"%s\":\"%s\",\n",
+ BUILD_INFO[i].key,
+ BUILD_INFO[i].value);
+ }
+ if (BUILD_INFO_SIZE > 0) {
+ printf("\"%s\":\"%s\"\n",
+ BUILD_INFO[BUILD_INFO_SIZE - 1].key,
+ BUILD_INFO[BUILD_INFO_SIZE - 1].value);
+ }
+ printf("}\n");
+ } else {
+ printf("%s version "
+ QEMU_FULL_VERSION
+ " build information\n\n", execname ?:"QEMU");
+ printf(" %-*s key value\n",
+ BUILD_INFO_HEADER_WIDTH,
+ "configuration key");
+ printf(" %-*s ---------\n",
+ BUILD_INFO_HEADER_WIDTH,
+ "-----------------");
+ for (size_t i = 0; i < BUILD_INFO_SIZE ; i++) {
+ printf(" %-*s %s\n",
+ BUILD_INFO_HEADER_WIDTH,
+ BUILD_INFO[i].key,
+ BUILD_INFO[i].value);
+ }
+ }
+}
+
enum {
#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
@@ -3019,6 +3054,12 @@ void qemu_init(int argc, char **argv)
version();
exit(0);
break;
+ case QEMU_OPTION_build_info:
+ /* fallthrough */
+ case QEMU_OPTION_build_info_json:
+ build_info(argv[0], popt->index != QEMU_OPTION_build_info);
+ exit(0);
+ break;
case QEMU_OPTION_m:
opts = qemu_opts_parse_noisily(qemu_find_opts("memory"), optarg, true);
if (opts == NULL) {