build-crosstool-ng 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python3
  2. import os
  3. import common
  4. class CrosstoolNgComponent(self.Component):
  5. def do_build(self, args):
  6. self.assert_crosstool_ng_supports_arch(kwargs['arch'])
  7. build_dir = self.get_build_dir(args)
  8. defconfig_dest = os.path.join(kwargs['crosstool_ng_util_dir'], 'defconfig')
  9. os.makedirs(kwargs['crosstool_ng_util_dir'], exist_ok=True)
  10. os.makedirs(kwargs['crosstool_ng_download_dir'], exist_ok=True)
  11. # Bootstrap out-ot-tree WONTFIX. I've tried.
  12. # https://github.com/crosstool-ng/crosstool-ng/issues/1021
  13. os.chdir(kwargs['crosstool_ng_src_dir'])
  14. self.sh.run_cmd(
  15. [os.path.join(kwargs['crosstool_ng_src_dir'], 'bootstrap'), LF],
  16. )
  17. os.chdir(kwargs['crosstool_ng_util_dir'])
  18. self.sh.run_cmd(
  19. [
  20. os.path.join(kwargs['crosstool_ng_src_dir'], 'configure'), LF,
  21. '--enable-local', LF,
  22. ],
  23. )
  24. self.sh.run_cmd(
  25. [
  26. 'make', LF,
  27. '-j', str(kwargs['nproc']), LF,
  28. ],
  29. )
  30. # Build the toolchain.
  31. self.sh.cp(
  32. os.path.join(kwargs['root_dir'], 'crosstool_ng_config', kwargs['arch']),
  33. defconfig_dest
  34. )
  35. self.write_configs(
  36. kwargs['crosstool_ng_defconfig'],
  37. [
  38. 'CT_PREFIX_DIR="{}"'.format(kwargs['crosstool_ng_install_dir']),
  39. 'CT_WORK_DIR="{}"'.format(build_dir),
  40. 'CT_LOCAL_TARBALLS_DIR="{}"'.format(kwargs['crosstool_ng_download_dir']),
  41. ]
  42. )
  43. self.sh.run_cmd(
  44. [
  45. kwargs['crosstool_ng_executable'], LF,
  46. 'defconfig', LF,
  47. ],
  48. )
  49. os.unlink(defconfig_dest)
  50. self.sh.run_cmd(
  51. [
  52. kwargs['crosstool_ng_executable'], LF,
  53. 'build', LF,
  54. 'CT_JOBS={}'.format(str(kwargs['nproc'])), LF,
  55. ],
  56. out_file=os.path.join(build_dir, 'lkmc.log'),
  57. delete_env=['LD_LIBRARY_PATH'],
  58. extra_paths=[kwargs['ccache_dir']],
  59. )
  60. def get_argparse_args(self):
  61. return {
  62. 'description': '''\
  63. Build crosstool-NG with Newlib for bare metal compilation'
  64. '''
  65. }
  66. def get_build_dir(self, args):
  67. return kwargs['crosstool_ng_build_dir']
  68. if __name__ == '__main__':
  69. CrosstoolNgComponent().build()