build-m5 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. 'LD={}'.format(self.env['ld_path']), LF,
  18. 'PWD={}'.format(self.env['gem5_m5_source_dir']), LF,
  19. ]
  20. def build(self):
  21. os.makedirs(self.env['gem5_m5_build_dir'], exist_ok=True)
  22. # We must clean first or else the build outputs of one arch can conflict with the other.
  23. # I should stop being lazy and go actually patch gem5 to support out of tree m5 build...
  24. self.clean()
  25. self.sh.run_cmd(
  26. self._get_make_cmd(),
  27. cwd=self.env['gem5_m5_source_dir'],
  28. )
  29. os.makedirs(self.env['out_rootfs_overlay_bin_dir'], exist_ok=True)
  30. self.sh.cp(os.path.join(self.env['gem5_m5_source_dir'], 'm5'), self.env['out_rootfs_overlay_bin_dir'])
  31. def clean(self):
  32. self.sh.run_cmd(
  33. self._get_make_cmd() + ['clean', LF],
  34. cwd=self.env['gem5_m5_source_dir'],
  35. )
  36. return None
  37. if __name__ == '__main__':
  38. Main().cli()