build-m5 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python3
  2. import os
  3. import common
  4. from shell_helpers import LF
  5. class Main(common.BuildCliFunction):
  6. def _get_make_cmd(self):
  7. allowed_toolchains = ['buildroot']
  8. if self.env['arch'] == 'x86_64':
  9. arch = 'x86'
  10. else:
  11. arch = self.env['arch']
  12. return [
  13. 'make', LF,
  14. '-j', str(self.env['nproc']), LF,
  15. '-f', 'Makefile.{}'.format(arch), LF,
  16. 'CC={}'.format(self.env['gcc_path']), LF,
  17. 'CROSS_COMPILE={}'.format(self.env['toolchain_prefix_dash']), LF,
  18. 'LD={}'.format(self.env['ld_path']), LF,
  19. 'PWD={}'.format(self.env['gem5_m5_source_dir']), LF,
  20. ]
  21. def build(self):
  22. os.makedirs(self.env['gem5_m5_build_dir'], exist_ok=True)
  23. # We must clean first or else the build outputs of one arch can conflict with the other.
  24. # I should stop being lazy and go actually patch gem5 to support out of tree m5 build...
  25. self.clean()
  26. self.sh.run_cmd(
  27. self._get_make_cmd(),
  28. cwd=self.env['gem5_m5_source_dir'],
  29. )
  30. os.makedirs(self.env['out_rootfs_overlay_bin_dir'], exist_ok=True)
  31. self.sh.cp(
  32. os.path.join(self.env['gem5_m5_source_dir'], 'm5'),
  33. self.env['out_rootfs_overlay_bin_dir']
  34. )
  35. def clean(self):
  36. self.sh.run_cmd(
  37. self._get_make_cmd() + ['clean', LF],
  38. cwd=self.env['gem5_m5_source_dir'],
  39. )
  40. return None
  41. if __name__ == '__main__':
  42. Main().cli()