def configure_toolchain_gccarmemb(conf):
    # get path to toolchain
    path = None

    if 'GCC_ARM_PATH' in os.environ:
        path = [os.path.join(os.environ['GCC_ARM_PATH'],'bin')]

    # as long as it is not defined how the gcc compiler V4.9 provided by arm fits into
    # the hilscher compiler versioning system building using codesourcery gcc V4.5.2
    # the arm compiler must be explicitly enabled by means of environment variable GCC_ARM_PATH.
    # If this variable is not set, the toolchain will not be available
    # Further its not clear, how waf shall distinguish codesourcery / arm compiler if they
    # are found via path (Actually there is no need to do so, but as for now the compiler version
    # in the target names breaks everything then.)
    if path:
        conf.setup_gnu_gcc_toolchain(prefix = 'arm-none-eabi-', path_list = path)
        conf.gcc_arm_flags()

        f = conf.env.append_value

        f('LINKFLAGS', ['-Wl,-gc-sections'])

        f('CFLAGS_enable_gc_sections',    ['-ffunction-sections', '-fdata-sections'])
        f('CXXFLAGS_enable_gc_sections',  ['-ffunction-sections', '-fdata-sections'])

        f('CFLAGS_disable_unaligned_access',   ['-mno-unaligned-access'])
        f('CXXFLAGS_disable_unaligned_access', ['-mno-unaligned-access'])
    else:
        conf.fatal('GCC_ARM_PATH environment variable must be set to enable ARM V4.9 toolchain')
def configure_toolchain_hitex(conf):
    path = None
    if 'PATH_GNU_ARM' in os.environ:
        path = [os.path.join(os.environ['PATH_GNU_ARM'], 'bin')]

    conf.setup_gnu_gcc_toolchain(prefix = 'arm-hitex-elf-', path_list = path)
    conf.gcc_arm_flags()
def configure_toolchain_mingw64(conf):
    if sys.platform in ("win64"):
        conf.setup_gnu_gcc_toolchain(prefix = 'mingw64')

        conf.env['DEST_OS'] = 'win32'
        conf.gcc_modifier_platform()
        conf.env.append_value('LINKFLAGS', ['-Wl,-gc-sections'])
    else:
        conf.fatal('MinGW 64 toolchain not available none 64 bit windows os')
def configure_toolchain_codesourcery(conf):
    # get path to toolchain
    path = None

    if 'CS_PATH' in os.environ:
        path = [os.path.join(os.environ['CS_PATH'], 'bin')]
    else:
        if sys.platform.startswith("win"):
            try:
                import _winreg as winreg
            except:
                import winreg

            aReg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
            aKey = None

            try:
                aKey = winreg.OpenKey(
                    aReg,
                    r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Sourcery G++ Lite for ARM EABI"
                )
            except:
                # Try Wow6432-Node, as Python x64 looks in native 64bit keys
                aKey = winreg.OpenKey(
                    aReg,
                    r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Sourcery G++ Lite for ARM EABI",
                    0, winreg.KEY_READ | winreg.KEY_WOW64_32KEY)
            finally:
                if aKey is not None:
                    try:
                        install_loc, type = winreg.QueryValueEx(
                            aKey, "InstallLocation")
                        assert type is winreg.REG_SZ
                        if sys.version_info[0] == 2:
                            install_loc = install_loc.encode('ascii', 'ignore')
                        path = [os.path.join(install_loc, 'bin')]
                    except EnvironmentError:
                        pass

                    winreg.CloseKey(aKey)

            winreg.CloseKey(aReg)

    conf.setup_gnu_gcc_toolchain(prefix='arm-none-eabi-', path_list=path)
    conf.gcc_arm_flags()

    f = conf.env.append_value

    f('LINKFLAGS', ['-Wl,-gc-sections'])

    f('CFLAGS_enable_gc_sections', ['-ffunction-sections', '-fdata-sections'])
    f('CXXFLAGS_enable_gc_sections',
      ['-ffunction-sections', '-fdata-sections'])
def configure_toolchain_custom(conf):
    opt = Options.options

    conf.setup_gnu_gcc_toolchain(prefix=opt.custom_toolchain_prefix + '-',
                                 compiler=opt.custom_toolchain_driver,
                                 cxxcompiler=opt.custom_toolchain_cxxdriver,
                                 path_list=[opt.custom_toolchain_path])

    conf.gcc_arm_flags()

    f = conf.env.append_value

    f('CFLAGS', ['-ffunction-sections', '-fdata-sections'])
    f('CXXFLAGS', ['-ffunction-sections', '-fdata-sections'])
    f('LINKFLAGS', ['-Wl,-gc-sections'])
def configure_toolchain_arm_eabi(conf):
    exc = None
    for x in 'arm-none-eabi- arm-eabi-'.split():
        try:
            conf.setup_gnu_gcc_toolchain(prefix = x)
            break
        except conf.errors.ConfigurationError as e:
            exc = exc or e
    else:
        raise exc

    conf.gcc_arm_flags()

    f = conf.env.append_value

    f('CFLAGS',    ['-ffunction-sections', '-fdata-sections'])
    f('CXXFLAGS',  ['-ffunction-sections', '-fdata-sections'])
    f('LINKFLAGS', ['-Wl,-gc-sections'])
def configure_toolchain_codesourcery(conf):
    # get path to toolchain
    path = None

    if 'CS_PATH' in os.environ:
        path = [os.path.join(os.environ['CS_PATH'],'bin')]
    else:
        if sys.platform.startswith("win"):
          install_loc = get_registry_string_value(r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Sourcery G++ Lite for ARM EABI", "InstallLocation")

          if install_loc is not None:
            path = [os.path.join(install_loc, 'bin')]

    conf.setup_gnu_gcc_toolchain(prefix = 'arm-none-eabi-', path_list=path)
    conf.gcc_arm_flags()

    f = conf.env.append_value

    f('LINKFLAGS', ['-Wl,-gc-sections'])

    f('CFLAGS_enable_gc_sections',    ['-ffunction-sections', '-fdata-sections'])
    f('CXXFLAGS_enable_gc_sections',  ['-ffunction-sections', '-fdata-sections'])
def configure_toolchain_gcc_linux(conf):
    if sys.platform in ("linux","linux2"):
        conf.setup_gnu_gcc_toolchain(prefix='')
        conf.env.append_value('LINKFLAGS', ['-Wl,-gc-sections'])
    else:
        conf.fatal('GCC Linux toolchain not available none linux os')