build-m5 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. import common
  3. from shell_helpers import LF
  4. class Main(common.BuildCliFunction):
  5. def __init__(self):
  6. super().__init__(
  7. description='''\
  8. Build the gem5 m5 executable.
  9. See: https://cirosantilli.com/linux-kernel-module-cheat#gem5-m5-executable
  10. '''
  11. )
  12. def _get_make_cmd(self):
  13. allowed_toolchains = ['buildroot']
  14. return [
  15. 'scons', LF,
  16. '-C', self.env['gem5_m5_source_dir'], LF,
  17. '-j', str(self.env['nproc']), LF,
  18. 'CROSS_COMPILE={}'.format(self.env['toolchain_prefix_dash']), LF,
  19. self.env['gem5_m5_source_dir_build'], LF
  20. ]
  21. def build(self):
  22. self.sh.mkdir_p(self.env['gem5_m5_build_dir'])
  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. )
  29. self.sh.mkdir_p(self.env['out_rootfs_overlay_bin_dir'])
  30. self.sh.cp(
  31. self.env['gem5_m5_source_dir_build'],
  32. self.env['out_rootfs_overlay_bin_dir']
  33. )
  34. def clean(self):
  35. self.sh.run_cmd(
  36. self._get_make_cmd() + ['--clean', LF],
  37. )
  38. if __name__ == '__main__':
  39. Main().cli()