builtin-version.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include "builtin.h"
  3. #include "color.h"
  4. #include "util/debug.h"
  5. #include "util/header.h"
  6. #include <tools/config.h>
  7. #include <stdbool.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <subcmd/parse-options.h>
  11. struct version {
  12. bool build_options;
  13. };
  14. static struct version version;
  15. static struct option version_options[] = {
  16. OPT_BOOLEAN(0, "build-options", &version.build_options,
  17. "display the build options"),
  18. OPT_END(),
  19. };
  20. static const char * const version_usage[] = {
  21. "perf version [<options>]",
  22. NULL
  23. };
  24. static void on_off_print(const char *status)
  25. {
  26. printf("[ ");
  27. if (!strcmp(status, "OFF"))
  28. color_fprintf(stdout, PERF_COLOR_RED, "%-3s", status);
  29. else
  30. color_fprintf(stdout, PERF_COLOR_GREEN, "%-3s", status);
  31. printf(" ]");
  32. }
  33. static void status_print(const char *name, const char *macro,
  34. const char *status)
  35. {
  36. printf("%22s: ", name);
  37. on_off_print(status);
  38. printf(" # %s\n", macro);
  39. }
  40. #define STATUS(feature) \
  41. do { \
  42. if (feature.is_builtin) \
  43. status_print(feature.name, feature.macro, "on"); \
  44. else \
  45. status_print(feature.name, feature.macro, "OFF"); \
  46. } while (0)
  47. static void library_status(void)
  48. {
  49. for (int i = 0; supported_features[i].name; ++i)
  50. STATUS(supported_features[i]);
  51. }
  52. int cmd_version(int argc, const char **argv)
  53. {
  54. argc = parse_options(argc, argv, version_options, version_usage,
  55. PARSE_OPT_STOP_AT_NON_OPTION);
  56. printf("perf version %s\n", perf_version_string);
  57. if (version.build_options || verbose > 0)
  58. library_status();
  59. return 0;
  60. }