build-qemu 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. import os
  3. import common
  4. from shell_helpers import LF
  5. class Main(common.BuildCliFunction):
  6. def __init__(self):
  7. super().__init__()
  8. self.add_argument(
  9. 'extra_config_args',
  10. default=[],
  11. metavar='extra-config-args',
  12. nargs='*'
  13. )
  14. def build(self):
  15. build_dir = self.get_build_dir()
  16. os.makedirs(build_dir, exist_ok=True)
  17. if self.env['verbose']:
  18. verbose = ['V=1']
  19. else:
  20. verbose = []
  21. if self.env['mode'] == 'userland':
  22. target_list = '{}-linux-user'.format(self.env['arch'])
  23. else:
  24. target_list = '{}-softmmu'.format(self.env['arch'])
  25. if self.env['qemu_build_type'] == 'debug':
  26. # https://stackoverflow.com/questions/4689136/debug-qemu-with-gdb
  27. build_type_cmd = ['--enable-debug', LF]
  28. else:
  29. build_type_cmd = []
  30. self.sh.run_cmd(
  31. [
  32. os.path.join(self.env['qemu_source_dir'], 'configure'), LF,
  33. '--enable-trace-backends=simple', LF,
  34. '--target-list={}'.format(target_list), LF,
  35. '--enable-sdl', LF,
  36. ] +
  37. build_type_cmd +
  38. self.sh.add_newlines(self.env['extra_config_args']),
  39. extra_paths=[self.env['ccache_dir']],
  40. cwd=build_dir
  41. )
  42. self.sh.run_cmd(
  43. (
  44. [
  45. 'make', LF,
  46. '-j', str(self.env['nproc']), LF,
  47. ] +
  48. verbose
  49. ),
  50. cwd=build_dir,
  51. extra_paths=[self.env['ccache_dir']],
  52. )
  53. def get_build_dir(self):
  54. return self.env['qemu_build_dir']
  55. if __name__ == '__main__':
  56. Main().cli()