build-crosstool-ng 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. defaults={
  9. 'mode': 'baremetal',
  10. },
  11. description='''\
  12. Build crosstool-NG with Newlib for bare metal compilation
  13. ''',
  14. )
  15. def build(self):
  16. build_dir = self.get_build_dir()
  17. defconfig_dest = os.path.join(self.env['crosstool_ng_source_copy_dir'], 'defconfig')
  18. os.makedirs(self.env['crosstool_ng_download_dir'], exist_ok=True)
  19. # Bootstrap out-ot-tree WONTFIX. I've tried.
  20. # https://github.com/crosstool-ng/crosstool-ng/issues/1021
  21. #
  22. # Then out-of-tree ./ctng usage also started to fail in 1.24.0.
  23. #
  24. # So instead of fighting upstream, I'll just take the Buildroot approach
  25. # to life and rsync the entire source tree into the build tree. Fun times.
  26. self.sh.copy_dir_if_update(
  27. self.env['crosstool_ng_source_dir'],
  28. self.env['crosstool_ng_source_copy_dir'],
  29. )
  30. self.sh.run_cmd(
  31. [os.path.join(self.env['crosstool_ng_source_copy_dir'], 'bootstrap'), LF],
  32. cwd=self.env['crosstool_ng_source_copy_dir'],
  33. )
  34. self.sh.run_cmd(
  35. [
  36. # abspath here makes Ubuntu 16.04 fail with:
  37. # configure: error: source directory already configured; run "make distclean" there first
  38. # after another build has been done. Don't ask me why.
  39. os.path.join(os.curdir, 'configure'), LF,
  40. '--enable-local', LF,
  41. ],
  42. cwd=self.env['crosstool_ng_source_copy_dir'],
  43. )
  44. self.sh.run_cmd(
  45. ['make', '-j', str(self.env['nproc']), LF],
  46. cwd=self.env['crosstool_ng_source_copy_dir'],
  47. )
  48. # Build the toolchain.
  49. self.sh.cp(
  50. os.path.join(self.env['root_dir'], 'crosstool_ng_config', self.env['arch']),
  51. defconfig_dest
  52. )
  53. self.sh.write_configs(
  54. self.env['crosstool_ng_defconfig'],
  55. [
  56. 'CT_PREFIX_DIR="{}"'.format(self.env['crosstool_ng_install_dir']),
  57. 'CT_WORK_DIR="{}"'.format(build_dir),
  58. 'CT_LOCAL_TARBALLS_DIR="{}"'.format(self.env['crosstool_ng_download_dir']),
  59. ]
  60. )
  61. self.sh.run_cmd(
  62. [
  63. self.env['crosstool_ng_executable'], LF,
  64. 'defconfig', LF,
  65. ],
  66. cwd=self.env['crosstool_ng_source_copy_dir'],
  67. )
  68. self.sh.rmrf(defconfig_dest)
  69. self.sh.run_cmd(
  70. [
  71. self.env['crosstool_ng_executable'], LF,
  72. 'build', LF,
  73. 'CT_JOBS={}'.format(str(self.env['nproc'])), LF,
  74. ],
  75. cwd=self.env['crosstool_ng_source_copy_dir'],
  76. out_file=os.path.join(build_dir, self.env['repo_short_id'] + '.log'),
  77. delete_env=['LD_LIBRARY_PATH'],
  78. extra_paths=[self.env['ccache_dir']],
  79. )
  80. def get_build_dir(self):
  81. return self.env['crosstool_ng_build_dir']
  82. if __name__ == '__main__':
  83. Main().cli()