def METHOD_NAME(env):
    def _lookup_in_ldpath(script):
        for d in env.get("LIBPATH", []):
            path = os.path.join(env.subst(d), script)
            if os.path.isfile(path):
                return path
        return None
    script = None
    script_in_next = False
    for f in env.get("LINKFLAGS", []):
        raw_script = None
        if f == "-T":
            script_in_next = True
            continue
        if script_in_next:
            script_in_next = False
            raw_script = f
        elif f.startswith("-Wl,-T"):
            raw_script = f[6:]
        else:
            continue
        script = env.subst(raw_script.replace('"', "").strip())
        if os.path.isfile(script):
            return script
        path = _lookup_in_ldpath(script)
        if path:
            return path
    if script:
        sys.stderr.write(
            "Error: Could not find '%s' LD script in LDPATH '%s'\n"
            % (script, env.subst("$LIBPATH"))
        )
        env.Exit(1)
    if not script and "LDSCRIPT_PATH" in env:
        path = _lookup_in_ldpath(env["LDSCRIPT_PATH"])
        if path:
            return path
    sys.stderr.write("Error: Could not find LD script\n")
    env.Exit(1)