build-qemu 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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('--configure')
  9. self.add_argument(
  10. '--extra-config-args',
  11. default='',
  12. help='''\
  13. Extra arguments to pass to configure
  14. '''
  15. )
  16. self._add_argument('extra_make_args')
  17. def build(self):
  18. build_dir = self.get_build_dir()
  19. os.makedirs(build_dir, exist_ok=True)
  20. if self.env['verbose']:
  21. verbose = ['V=1']
  22. else:
  23. verbose = []
  24. if self.env['mode'] == 'userland':
  25. target_list = '{}-linux-user'.format(self.env['arch'])
  26. else:
  27. target_list = '{}-softmmu'.format(self.env['arch'])
  28. if self.env['qemu_build_type'] == 'debug':
  29. # https://stackoverflow.com/questions/4689136/debug-qemu-with-gdb
  30. build_type_cmd = ['--enable-debug', LF]
  31. else:
  32. build_type_cmd = []
  33. if self.env['configure']:
  34. self.sh.run_cmd(
  35. [
  36. os.path.join(self.env['qemu_source_dir'], 'configure'), LF,
  37. '--enable-trace-backends=simple', LF,
  38. '--target-list={}'.format(target_list), LF,
  39. '--enable-sdl', LF,
  40. ] +
  41. build_type_cmd +
  42. self.sh.shlex_split(self.env['extra_config_args']),
  43. extra_paths=[self.env['ccache_dir']],
  44. cwd=build_dir
  45. )
  46. self.sh.run_cmd(
  47. (
  48. [
  49. 'make', LF,
  50. '-j', str(self.env['nproc']), LF,
  51. ] +
  52. verbose +
  53. self.sh.add_newlines(self.env['extra_make_args'])
  54. ),
  55. cwd=build_dir,
  56. extra_paths=[self.env['ccache_dir']],
  57. )
  58. def get_build_dir(self):
  59. return self.env['qemu_build_dir']
  60. if __name__ == '__main__':
  61. Main().cli()