build-crosstool-ng 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. description='''\
  9. Build crosstool-NG with Newlib for bare metal compilation
  10. ''',
  11. supported_archs=common.consts['crosstool_ng_supported_archs']
  12. )
  13. def build(self):
  14. build_dir = self.get_build_dir()
  15. defconfig_dest = os.path.join(self.env['crosstool_ng_util_dir'], 'defconfig')
  16. os.makedirs(self.env['crosstool_ng_util_dir'], exist_ok=True)
  17. os.makedirs(self.env['crosstool_ng_download_dir'], exist_ok=True)
  18. # Bootstrap out-ot-tree WONTFIX. I've tried.
  19. # https://github.com/crosstool-ng/crosstool-ng/issues/1021
  20. os.chdir(self.env['crosstool_ng_source_dir'])
  21. self.sh.run_cmd(
  22. [os.path.join(self.env['crosstool_ng_source_dir'], 'bootstrap'), LF],
  23. )
  24. os.chdir(self.env['crosstool_ng_util_dir'])
  25. self.sh.run_cmd(
  26. [
  27. os.path.join(self.env['crosstool_ng_source_dir'], 'configure'), LF,
  28. '--enable-local', LF,
  29. ],
  30. )
  31. self.sh.run_cmd(['make', '-j', str(self.env['nproc']), LF])
  32. # Build the toolchain.
  33. self.sh.cp(
  34. os.path.join(self.env['root_dir'], 'crosstool_ng_config', self.env['arch']),
  35. defconfig_dest
  36. )
  37. self.sh.write_configs(
  38. self.env['crosstool_ng_defconfig'],
  39. [
  40. 'CT_PREFIX_DIR="{}"'.format(self.env['crosstool_ng_install_dir']),
  41. 'CT_WORK_DIR="{}"'.format(build_dir),
  42. 'CT_LOCAL_TARBALLS_DIR="{}"'.format(self.env['crosstool_ng_download_dir']),
  43. ]
  44. )
  45. self.sh.run_cmd(
  46. [
  47. self.env['crosstool_ng_executable'], LF,
  48. 'defconfig', LF,
  49. ],
  50. )
  51. self.sh.rmrf(defconfig_dest)
  52. self.sh.run_cmd(
  53. [
  54. self.env['crosstool_ng_executable'], LF,
  55. 'build', LF,
  56. 'CT_JOBS={}'.format(str(self.env['nproc'])), LF,
  57. ],
  58. out_file=os.path.join(build_dir, self.env['repo_short_id'] + '.log'),
  59. delete_env=['LD_LIBRARY_PATH'],
  60. extra_paths=[self.env['ccache_dir']],
  61. )
  62. def get_build_dir(self):
  63. return self.env['crosstool_ng_build_dir']
  64. if __name__ == '__main__':
  65. Main().cli()