Files
Colmi_P80_Smart_Watch/linux_toolchain/jieli-linux-toolchains-20250324.1/common/bin/lto-wrapper

59 lines
2.0 KiB
Python
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# 调用对应的 ld 以及加载同文件夹下的 LLVMgold.dll 来完成链接过程
# 同时处理 --extra-arguments-from-file 和
# --output-version-info 参数
# --extra-arguments-from-file filepath
# 接受一个参数、是一个文件路径,里面每一行都是一个需要
# 传递给 ld 的参数,这样方便把一些 ld 的参数放到文件中
# --output-version-info output-file-path
# 接受一个参数,指定 version 信息的输出文件
# 当指定这个参数时候、会调用同文件夹下的 pi32-link-version 产生
# 版本信息(聚合了所有库的版本信息,即 version.o 的内容 )
import sys
import subprocess
import os
import os.path
def read_from_file(out_argv, file_name):
"""
read arguments from file, one argument per line
"""
with open(file_name) as fin:
for line in fin:
out_argv.append(line.strip())
if __name__ == "__main__":
exe_path = os.path.abspath(__file__)
exe_path = os.path.dirname(exe_path) # get path of this file
linker_path = os.path.join(exe_path, "ld")
link_version_path = os.path.join(exe_path, "link-version")
gold_plugin = os.path.join(exe_path, "LLVMgold.so")
out_argv = [linker_path, '--plugin', gold_plugin]
link_argv = [link_version_path]
end = len(sys.argv)
i = 1
need_link_version = False
while i < end:
if sys.argv[i] == '--extra-arguments-from-file':
read_from_file(out_argv, sys.argv[i+1])
read_from_file(link_argv, sys.argv[i+1])
i += 1
elif sys.argv[i] == '--output-version-info':
need_link_version = True
link_argv.append(sys.argv[i])
if i != end - 1:
i += 1
link_argv.append(sys.argv[i])
else:
out_argv.append(sys.argv[i])
link_argv.append(sys.argv[i])
i += 1
# print(" ".join(out_argv))
if need_link_version:
# if we need version
subprocess.call(link_argv)
sys.exit(subprocess.call(out_argv))