#!/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)