meson-buildoptions.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #! /usr/bin/env python3
  2. # Generate configure command line options handling code, based on Meson's
  3. # user build options introspection data
  4. #
  5. # Copyright (C) 2021 Red Hat, Inc.
  6. #
  7. # Author: Paolo Bonzini <pbonzini@redhat.com>
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2, or (at your option)
  12. # any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. import json
  22. import textwrap
  23. import shlex
  24. import sys
  25. def sh_print(line=""):
  26. print(' printf "%s\\n"', shlex.quote(line))
  27. def load_options(json):
  28. json = [
  29. x
  30. for x in json
  31. if x["section"] == "user"
  32. and ":" not in x["name"]
  33. and x["name"] not in SKIP_OPTIONS
  34. ]
  35. return sorted(json, key=lambda x: x["name"])
  36. def print_help(options):
  37. print("meson_options_help() {")
  38. sh_print()
  39. sh_print("Optional features, enabled with --enable-FEATURE and")
  40. sh_print("disabled with --disable-FEATURE, default is enabled if available")
  41. sh_print("(unless built with --without-default-features):")
  42. sh_print()
  43. print("}")
  44. def print_parse(options):
  45. print("_meson_option_parse() {")
  46. print(" case $1 in")
  47. print(" *) return 1 ;;")
  48. print(" esac")
  49. print("}")
  50. options = load_options(json.load(sys.stdin))
  51. print("# This file is generated by meson-buildoptions.py, do not edit!")
  52. print_help(options)
  53. print_parse(options)