build-stream 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. import os
  3. import shutil
  4. import common
  5. import shlex
  6. from shell_helpers import LF
  7. class Main(common.BuildCliFunction):
  8. def __init__(self):
  9. super().__init__(
  10. description='''\
  11. https://cirosantilli.com/linux-kernel-module-cheat#stream-benchmark
  12. '''
  13. )
  14. self._add_argument('--ccflags')
  15. self._add_argument('--force-rebuild')
  16. self._add_argument('--optimization-level')
  17. def setup(self, env):
  18. self.root_relpath = os.path.join('submodules', 'stream-benchmark')
  19. def build(self):
  20. build_dir = self.get_build_dir()
  21. cflags = ['-O{}'.format(self.env['optimization_level'])]
  22. extra_flags = []
  23. if self.env['static']:
  24. cflags.extend(['-static'])
  25. if self.env['force_rebuild']:
  26. extra_flags.extend(['-B', LF])
  27. if self.env['mode'] == 'baremetal':
  28. extra_objs = [
  29. self.env['baremetal_syscalls_obj'],
  30. self.env['baremetal_syscalls_asm_obj']
  31. ]
  32. else:
  33. extra_objs = []
  34. ret = self.sh.run_cmd(
  35. [
  36. 'make', LF,
  37. '-j', str(self.env['nproc']), LF,
  38. '-C', os.path.join(self.env['submodules_dir'], 'stream-benchmark'), LF,
  39. 'CC={}'.format(self.env['gcc_path']), LF,
  40. 'CFLAGS_EXTRA={}'.format(' '.join(cflags)), LF,
  41. 'EXTRA_OBJS={}'.format(' '.join(extra_objs)), LF,
  42. 'FC={}'.format(self.env['gfortran_path']), LF,
  43. 'OUT_DIR={}'.format(build_dir), LF,
  44. ]
  45. + extra_flags
  46. )
  47. if ret == 0 and self.env['copy_overlay']:
  48. self.sh.copy_file_if_update(
  49. os.path.join(build_dir, 'stream_c.exe'),
  50. os.path.join(self.env['out_rootfs_overlay_lkmc_dir'], self.root_relpath, 'stream-benchmark'),
  51. )
  52. return ret
  53. def get_build_dir(self):
  54. return os.path.join(self.env['build_dir'], self.root_relpath)
  55. if __name__ == '__main__':
  56. Main().cli()