build-qemu 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. '--user-mode',
  10. default=False,
  11. help='Build QEMU user mode instead of system.',
  12. )
  13. self.add_argument(
  14. 'extra_config_args',
  15. default=[],
  16. metavar='extra-config-args',
  17. nargs='*'
  18. )
  19. def build(self):
  20. build_dir = self.get_build_dir()
  21. os.makedirs(build_dir, exist_ok=True)
  22. if self.env['verbose']:
  23. verbose = ['V=1']
  24. else:
  25. verbose = []
  26. if self.env['user_mode']:
  27. target_list = '{}-linux-user'.format(self.env['arch'])
  28. else:
  29. target_list = '{}-softmmu'.format(self.env['arch'])
  30. self.sh.run_cmd(
  31. [
  32. os.path.join(self.env['qemu_source_dir'], 'configure'), LF,
  33. '--enable-debug', LF,
  34. '--enable-trace-backends=simple', LF,
  35. '--target-list={}'.format(target_list), LF,
  36. '--enable-sdl', LF,
  37. '--with-sdlabi=2.0', LF,
  38. ] +
  39. self.sh.add_newlines(self.env['extra_config_args']),
  40. extra_paths=[self.env['ccache_dir']],
  41. cwd=build_dir
  42. )
  43. self.sh.run_cmd(
  44. (
  45. [
  46. 'make', LF,
  47. '-j', str(self.env['nproc']), LF,
  48. ] +
  49. verbose
  50. ),
  51. cwd=build_dir,
  52. extra_paths=[self.env['ccache_dir']],
  53. )
  54. def get_build_dir(self):
  55. return self.env['qemu_build_dir']
  56. if __name__ == '__main__':
  57. Main().cli()