crosscc.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from SCons.Tool import asm
  2. from SCons.Tool import gcc
  3. from SCons.Tool import gxx
  4. from SCons.Tool import ar
  5. from SCons.Tool import gnulink
  6. import strip
  7. import gdb
  8. import objdump
  9. from SCons.Action import _subproc
  10. import subprocess
  11. def prefix_commands(env, command_prefix, cmd_list):
  12. for command in cmd_list:
  13. if command in env:
  14. env[command] = command_prefix + env[command]
  15. def _get_tool_version(env, tool):
  16. verstr = "version unknown"
  17. proc = _subproc(
  18. env,
  19. env.subst("${%s} --version" % tool),
  20. stdout=subprocess.PIPE,
  21. stderr="devnull",
  22. stdin="devnull",
  23. universal_newlines=True,
  24. error="raise",
  25. shell=True,
  26. )
  27. if proc:
  28. verstr = proc.stdout.readline()
  29. proc.communicate()
  30. return verstr
  31. def generate(env, **kw):
  32. for orig_tool in (asm, gcc, gxx, ar, gnulink, strip, gdb, objdump):
  33. orig_tool.generate(env)
  34. env.SetDefault(
  35. TOOLCHAIN_PREFIX=kw.get("toolchain_prefix"),
  36. )
  37. prefix_commands(
  38. env,
  39. env.subst("$TOOLCHAIN_PREFIX"),
  40. [
  41. "AR",
  42. "AS",
  43. "CC",
  44. "CXX",
  45. "OBJCOPY",
  46. "RANLIB",
  47. "STRIP",
  48. "GDB",
  49. "GDBPY",
  50. "OBJDUMP",
  51. ],
  52. )
  53. # Call CC to check version
  54. if whitelisted_versions := kw.get("versions", ()):
  55. cc_version = _get_tool_version(env, "CC")
  56. # print("CC version =", cc_version)
  57. # print(list(filter(lambda v: v in cc_version, whitelisted_versions)))
  58. if not any(filter(lambda v: v in cc_version, whitelisted_versions)):
  59. raise Exception(
  60. f"Toolchain version is not supported. Allowed: {whitelisted_versions}, toolchain: {cc_version} "
  61. )
  62. def exists(env):
  63. return True