2023-05-03 08:48:49 +03:00
|
|
|
import subprocess
|
|
|
|
|
2022-06-26 15:00:03 +03:00
|
|
|
import gdb
|
|
|
|
import objdump
|
2023-08-16 04:23:09 +03:00
|
|
|
import shutil
|
|
|
|
|
2023-05-03 08:48:49 +03:00
|
|
|
import strip
|
2022-06-26 15:00:03 +03:00
|
|
|
from SCons.Action import _subproc
|
2023-05-03 08:48:49 +03:00
|
|
|
from SCons.Errors import StopError
|
|
|
|
from SCons.Tool import ar, asm, gcc, gnulink, gxx
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
def prefix_commands(env, command_prefix, cmd_list):
|
|
|
|
for command in cmd_list:
|
|
|
|
if command in env:
|
2023-08-16 04:23:09 +03:00
|
|
|
env[command] = shutil.which(command_prefix + env[command])
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
def _get_tool_version(env, tool):
|
|
|
|
verstr = "version unknown"
|
|
|
|
proc = _subproc(
|
|
|
|
env,
|
|
|
|
env.subst("${%s} --version" % tool),
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr="devnull",
|
|
|
|
stdin="devnull",
|
|
|
|
universal_newlines=True,
|
|
|
|
error="raise",
|
|
|
|
shell=True,
|
|
|
|
)
|
|
|
|
if proc:
|
|
|
|
verstr = proc.stdout.readline()
|
|
|
|
proc.communicate()
|
|
|
|
return verstr
|
|
|
|
|
|
|
|
|
|
|
|
def generate(env, **kw):
|
2022-11-02 18:15:40 +03:00
|
|
|
if not env.get("VERBOSE", False):
|
|
|
|
env.SetDefault(
|
|
|
|
CCCOMSTR="\tCC\t${SOURCE}",
|
|
|
|
CXXCOMSTR="\tCPP\t${SOURCE}",
|
|
|
|
ASCOMSTR="\tASM\t${SOURCE}",
|
|
|
|
ARCOMSTR="\tAR\t${TARGET}",
|
|
|
|
RANLIBCOMSTR="\tRANLIB\t${TARGET}",
|
|
|
|
LINKCOMSTR="\tLINK\t${TARGET}",
|
|
|
|
INSTALLSTR="\tINSTALL\t${TARGET}",
|
|
|
|
APPSCOMSTR="\tAPPS\t${TARGET}",
|
|
|
|
VERSIONCOMSTR="\tVERSION\t${TARGET}",
|
|
|
|
STRIPCOMSTR="\tSTRIP\t${TARGET}",
|
|
|
|
OBJDUMPCOMSTR="\tOBJDUMP\t${TARGET}",
|
|
|
|
)
|
|
|
|
|
2022-08-13 01:17:11 +03:00
|
|
|
for orig_tool in (asm, gcc, gxx, ar, gnulink, strip, gdb, objdump):
|
2022-06-26 15:00:03 +03:00
|
|
|
orig_tool.generate(env)
|
|
|
|
env.SetDefault(
|
|
|
|
TOOLCHAIN_PREFIX=kw.get("toolchain_prefix"),
|
|
|
|
)
|
|
|
|
prefix_commands(
|
|
|
|
env,
|
|
|
|
env.subst("$TOOLCHAIN_PREFIX"),
|
|
|
|
[
|
|
|
|
"AR",
|
|
|
|
"AS",
|
|
|
|
"CC",
|
|
|
|
"CXX",
|
|
|
|
"OBJCOPY",
|
|
|
|
"RANLIB",
|
|
|
|
"STRIP",
|
|
|
|
"GDB",
|
|
|
|
"GDBPY",
|
|
|
|
"OBJDUMP",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
# Call CC to check version
|
|
|
|
if whitelisted_versions := kw.get("versions", ()):
|
|
|
|
cc_version = _get_tool_version(env, "CC")
|
|
|
|
# print("CC version =", cc_version)
|
|
|
|
# print(list(filter(lambda v: v in cc_version, whitelisted_versions)))
|
|
|
|
if not any(filter(lambda v: v in cc_version, whitelisted_versions)):
|
2022-07-14 19:24:26 +03:00
|
|
|
raise StopError(
|
2022-06-26 15:00:03 +03:00
|
|
|
f"Toolchain version is not supported. Allowed: {whitelisted_versions}, toolchain: {cc_version} "
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
return True
|