Newer
Older
from waflib.TaskGen import feature, after_method
from waflib.extras import test_base
from waflib.extras.test_base import summary
from waflib.extras.symwaf2ic import get_toplevel_path
from waflib.Errors import BuildError, ConfigurationError
# we can't build the full stack in the wafer app
if "wafer" not in os.environ["SINGULARITY_APPNAME"]:
dep("libnux", "test")
hopts = opt.add_option_group('libnux options')
hopts.add_option("--enable-stack-protector",
default=False,
action='store_true',
dest='stack_protector',
help="Enable stack frame overflow check.")
hopts.add_option("--enable-stack-redzone",
default=False,
action='store_true',
dest='stack_redzone',
help="Enable stack redzone check towards the program memory region.")
hopts.add_option("--disable-mailbox",
default=False,
action='store_true',
dest='disable_mailbox',
help="Disable mailbox memory region.")
hopts.add_withoption('libnux-test-hostcode', default=True,
help='Toggle the generation and build of with_hostcode tests')
if getattr(conf.options, 'with_libnux_test_hostcode', True):
# host-based python stuff also needed for cross-env tests
conf.load('pytest')
# now configure for nux cross compiler
env = conf.env
conf.setenv('nux')
have_ppu_toolchain = True
try:
conf.load('nux_assembler')
conf.load('nux_compiler')
except ConfigurationError:
have_ppu_toolchain = False
conf.env.append_value('LINKFLAGS', '-T%s' % conf.path.find_node('libnux/elf32nux.x').abspath())
conf.env.append_value('ASLINKFLAGS', '-T%s' % conf.path.find_node('libnux/elf32nux.x').abspath())
if(conf.options.stack_protector):
conf.define("LIBNUX_STACK_PROTECTOR", True)
conf.env.append_value('LIBNUX_STACK_PROTECTOR_ENABLED', 'True')
conf.env.append_value('CFLAGS', '-fstack-protector-all')
conf.env.append_value('CXXFLAGS', '-fstack-protector-all')
else:
conf.env.append_value('LIBNUX_STACK_PROTECTOR_ENABLED', 'False')
if(conf.options.stack_redzone):
conf.define("LIBNUX_STACK_REDZONE", True)
conf.env.append_value('LIBNUX_STACK_REDZONE_ENABLED', 'True')
conf.env.append_value('CFLAGS', '-fstack-limit-symbol=stack_redzone')
conf.env.append_value('CXXFLAGS', '-fstack-limit-symbol=stack_redzone')
else:
conf.env.append_value('LIBNUX_STACK_REDZONE_ENABLED', 'False')
if(not conf.options.disable_mailbox):
conf.env.append_value('ASLINKFLAGS', '--defsym=mailbox_size=4096')
conf.env.append_value('LINKFLAGS', '-Wl,--defsym=mailbox_size=4096')
# specialize for vx
conf.setenv('nux_vx', env=conf.all_envs['nux'])
conf.env.append_value('CXXFLAGS', '-mcpu=s2pp_hx')
# specialize for vx-v1
conf.setenv('nux_vx_v1', env=conf.all_envs['nux_vx'])
conf.setenv('nux_vx_v2', env=conf.all_envs['nux_vx'])
# specialize for vx-v3
conf.setenv('nux_vx_v3', env=conf.all_envs['nux_vx'])
# restore env
conf.setenv('', env=env)
conf.env.have_ppu_toolchain = have_ppu_toolchain
def build(bld):
if not bld.env.have_ppu_toolchain:
return
env = bld.all_envs["nux_vx"]
bld(
target = 'nux_inc_host_vx',
export_includes = ['.']
)
bld(
target = "nux_inc_vx",
export_includes = ["."],
env = env,
)
bld.stlib(
target = "nux_vx",
source = bld.path.ant_glob("src/vx/*.cpp"),
use = ["nux_inc_vx"],
env = env,
)
env = bld.all_envs[f"nux_vx_v{chip_version_number}"]
bld(
target = f"nux_inc_vx_v{chip_version_number}",
export_includes = ["."],
env = env,
)
bld.stlib(
target = f"nux_vx_v{chip_version_number}",
source = bld.path.ant_glob("src/vx/*.cpp")
+ bld.path.ant_glob(f"src/vx/v{chip_version_number}/*.cpp"),
use = [f"nux_inc_vx_v{chip_version_number}", 'hate_inc'],
env = env,
)
bld(
features = "cxx",
name = f"nux_runtime_obj_vx_v{chip_version_number}",
source = ["src/start.cpp",
"src/initdeinit.cpp",
"src/cxa_pure_virtual.cpp",
"src/stack_guards.cpp"],
use = f"nux_inc_vx_v{chip_version_number}",
env = env,
)
bld(
name = f"nux_runtime_shutdown_vx_v{chip_version_number}",
target = "crt_shutdown.o",
source = ["src/crt_shutdown.s"],
features = "use asm",
env = env,
)
bld(
name = f"nux_runtime_vx_v{chip_version_number}",
target = "crt.o",
source = ["src/crt.s"],
features = "use asm",
use = [f"nux_runtime_obj_vx_v{chip_version_number}",
f"nux_runtime_shutdown_vx_v{chip_version_number}"],
env=env,
)
program_list = ["examples/stdp.cpp"]
bld.program(
features = "cxx",
target = f"{program.replace('.cpp', '')}_vx_v{chip_version_number}.bin",
source = [program],
use = [f"nux_vx_v{chip_version_number}",
f"nux_runtime_vx_v{chip_version_number}"],
env = bld.all_envs[f"nux_vx_v{chip_version_number}"],
)