build.gn自动添加 Makefile输出的src_files.txt文件
This commit is contained in:
@@ -59,6 +59,13 @@ template("kernel_module") {
|
||||
public_configs += [ ":public" ]
|
||||
}
|
||||
}
|
||||
# 自动把src_files.txt 中的文件添加进来
|
||||
src=exec_script("//build/python_scripts/read_files.py",[rebase_path("."),"src_files.txt","src"],"string")
|
||||
source_list=string_split(src)
|
||||
sources+=source_list
|
||||
inc=exec_script("//build/python_scripts/read_files.py",[rebase_path("."),"src_files.txt","inc"],"string")
|
||||
inc_list=string_split(inc)
|
||||
include_dirs+=inc_list
|
||||
}
|
||||
}
|
||||
not_needed([ "auto_config" ])
|
||||
|
@@ -85,6 +85,7 @@ SRCS += $(EXT_SRC)
|
||||
OBJECTS = $(addprefix $(BIN_DIR)/, $(patsubst %.S, %.o, $(patsubst %.c, %.o, $(patsubst %.cpp, %.o, $(SRCS)))))
|
||||
|
||||
$(shell echo $(SRCS) > "src_files.txt")
|
||||
$(shell echo $(ADD_INCLUDE) >> "src_files.txt")
|
||||
endif
|
||||
|
||||
PLATFORM ?= FPGA
|
||||
|
36
build/python_scripts/read_files.py
Executable file
36
build/python_scripts/read_files.py
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def read_srcs(base_dir:str,file_name:str,type:str="src"):
|
||||
file_path=os.path.join(base_dir,file_name)
|
||||
ret=[]
|
||||
with open(file_path,mode='r',encoding='utf-8') as f:
|
||||
d=f.read()
|
||||
str_list=d.split()
|
||||
for item in str_list:
|
||||
if(type=="src"):
|
||||
if(item.endswith(('.c','.S'))):
|
||||
if(item[0]=='/'):
|
||||
path=os.path.relpath(os.path.normpath(item),base_dir)
|
||||
else:
|
||||
path=os.path.normpath(item)
|
||||
if not (path in ret):
|
||||
ret.append(path)
|
||||
elif(type=="inc"):
|
||||
if not (item.endswith(('.c','.S'))):
|
||||
if(item[0]=='/'):
|
||||
path=os.path.relpath(os.path.normpath(item),base_dir)
|
||||
else:
|
||||
path=os.path.normpath(item)
|
||||
if(os.path.exists(os.path.join(base_dir,path))):
|
||||
if not (path in ret):
|
||||
ret.append(path)
|
||||
return ret
|
||||
|
||||
if __name__ == "__main__":
|
||||
ret=read_srcs(sys.argv[1],sys.argv[2],sys.argv[3])
|
||||
for item in ret:
|
||||
print(item)
|
Reference in New Issue
Block a user