优化编译脚本
This commit is contained in:
@@ -87,7 +87,6 @@ def create_lambda(text:str):
|
||||
|
||||
# 生成lambda展开后的文件 返回新的源文件列表
|
||||
def search_lambda(src_list:list) -> list:
|
||||
file_index=0
|
||||
for index,item in enumerate(src_list):
|
||||
with open(item,encoding='utf-8') as f:
|
||||
d=f.read()
|
||||
@@ -98,18 +97,20 @@ def search_lambda(src_list:list) -> list:
|
||||
if(lam_index!=0 and d[lam_index-1]!='\n'):
|
||||
continue
|
||||
# 获取lambda文件名
|
||||
dst_file_name=f"lambda_{file_index}_"+ os.path.basename(item)
|
||||
file_index+=1
|
||||
dst_path=os.path.join(TMP_DIR,dst_file_name)
|
||||
src_list[index]=dst_path
|
||||
base_path=os.path.join(TMP_DIR,os.path.dirname(item))
|
||||
if not os.path.exists(base_path):
|
||||
os.makedirs(base_path)
|
||||
dst_file_name=os.path.join(base_path, os.path.basename(item))
|
||||
src_list[index]=dst_file_name
|
||||
# 不需要重新生成lambda文件
|
||||
if(not check_rebuild(dst_path,[item])):
|
||||
if(not check_rebuild(dst_file_name,[item])):
|
||||
continue
|
||||
lam_list=calc_lambda_text(d)
|
||||
lambda_funs=[]
|
||||
for lam in lam_list:
|
||||
lambda_funs.append(create_lambda(lam))
|
||||
with open(dst_path,mode='w+',encoding='utf-8') as f:
|
||||
print(f"生成 {dst_file_name}")
|
||||
with open(dst_file_name,mode='w+',encoding='utf-8') as f:
|
||||
lambda_funs_text=""
|
||||
for lam,fun in zip(lam_list,lambda_funs):
|
||||
lambda_funs_text+=f"static {fun.return_type} {fun.name}({','.join(fun.params)}){'{'}{fun.body}{'}'}\n"
|
||||
|
@@ -125,9 +125,9 @@ def def_slot_fun_str(slot_fun:str,pars:list):
|
||||
pars_names=get_pars_names(pars)
|
||||
for index,item in enumerate(pars_names):
|
||||
if(index<len(pars)-1):
|
||||
pars_str+=f"a->{item},"
|
||||
pars_str+=f"self->{item},"
|
||||
else:
|
||||
pars_str+=f"a->{item}"
|
||||
pars_str+=f"self->{item}"
|
||||
unsued_pars=""
|
||||
for item in pars_names:
|
||||
unsued_pars+=f" (void){item};\n"
|
||||
@@ -136,7 +136,7 @@ __attribute__((weak)) void {slot_fun}({','.join(pars)}){'{'}
|
||||
{unsued_pars}{'}'}
|
||||
|
||||
static void {slot_fun}_caller(void *args){'{'}
|
||||
{slot_fun}_args *a = args;
|
||||
{slot_fun}_args *self = args;
|
||||
{slot_fun}({pars_str});
|
||||
{'}'}
|
||||
"""
|
||||
@@ -263,6 +263,7 @@ def moc_file_create(out_file_path,scan_path_list):
|
||||
# 不需要重新生成
|
||||
if(not check_rebuild(out_file_path,list_file)):
|
||||
return
|
||||
print(f"生成 {out_file_path}")
|
||||
with open(out_file_path,"w+") as f:
|
||||
f.write("#include \"stdlib.h\"\n")
|
||||
f.write("#include \"string.h\"\n")
|
||||
|
30
make.py
30
make.py
@@ -75,12 +75,11 @@ gcc -MM main.c -o build/main.d
|
||||
|
||||
|
||||
def tran_path(path:str):
|
||||
p=path.replace('\\','/')
|
||||
p=p.replace('/','_')
|
||||
if(p[0]=='.'):
|
||||
return p[1:]
|
||||
else:
|
||||
return p
|
||||
path=os.path.normpath(os.path.join(BUILD_DIR,path))
|
||||
base_path=os.path.dirname(path)
|
||||
if not os.path.exists(base_path):
|
||||
os.makedirs(base_path)
|
||||
return path
|
||||
|
||||
|
||||
# 判断是否需要重新生成
|
||||
@@ -123,9 +122,8 @@ def read_depend_files(name:str):
|
||||
def build_depend(src:list):
|
||||
flags=f"{' '.join(CINC)} {' '.join(CDEF)} {' '.join(CFLAG)}"
|
||||
for i in src:
|
||||
name=tran_path(i).split('.')[0]
|
||||
name=os.path.splitext(tran_path(i))[0]
|
||||
dst='.'.join([name,'d'])
|
||||
dst=os.path.join(BUILD_DIR,dst)
|
||||
if(check_rebuild(dst,[i])):
|
||||
cmd=f"{CC} -MM {i} -o {dst} {flags}"
|
||||
print(f"更新 {dst}")
|
||||
@@ -140,21 +138,19 @@ def build_depend(src:list):
|
||||
def build_object(src:list):
|
||||
flags=f"{' '.join(CINC)} {' '.join(CDEF)} {' '.join(CFLAG)}"
|
||||
for i in src:
|
||||
name_l=tran_path(i).split('.')
|
||||
name=name_l[0]
|
||||
file_type=name_l[-1]
|
||||
name_t=os.path.splitext(tran_path(i))
|
||||
name=name_t[0]
|
||||
file_type=name_t[-1]
|
||||
dst='.'.join([name,'o'])
|
||||
dst=os.path.join(BUILD_DIR,dst)
|
||||
cd='.'.join([name,'d'])
|
||||
cmd = ''
|
||||
if(file_type in ['c','.C']):
|
||||
cd=os.path.join(BUILD_DIR,cd)
|
||||
if(file_type in ['.c','.C']):
|
||||
if(check_rebuild(dst,read_depend_files(cd))):
|
||||
cmd=f"{CC} -c {i} -o {dst} {flags}"
|
||||
else:
|
||||
# print(f"{i} 没有更新依赖关系")
|
||||
pass
|
||||
elif(file_type in ['s','S','asm','ASM']):
|
||||
elif(file_type in ['.s','.S','.asm','.ASM']):
|
||||
if(check_rebuild(dst,[i])):
|
||||
# cmd=f"{AS} -c {i} -o {dst} {flags}"
|
||||
pass
|
||||
@@ -173,8 +169,8 @@ def build_target(src:list):
|
||||
flags=f"{' '.join(CINC)} {' '.join(CDEF)} {' '.join(CFLAG)}"
|
||||
obj_list=[]
|
||||
for i in src:
|
||||
name=tran_path(i).split('.')[0]
|
||||
obj_list.append(BUILD_DIR+'/'+'.'.join([name,'o']))
|
||||
name=os.path.splitext(tran_path(i))[0]
|
||||
obj_list.append('.'.join([name,'o']))
|
||||
dst=os.path.join(BUILD_DIR,TARGET)
|
||||
if(check_rebuild(dst,obj_list)):
|
||||
cmd=f"{CC} {' '.join(obj_list)} -o {dst} {flags}"
|
||||
|
@@ -12,7 +12,7 @@ OBJCPY="riscv64-unknown-elf-objcopy"
|
||||
OBJDUMP="riscv64-unknown-elf-objdump"
|
||||
|
||||
CFLAG=[
|
||||
"-march=rv32i_zicsr",
|
||||
"-march=rv32i",
|
||||
"-mabi=ilp32",
|
||||
"-ffunction-sections",
|
||||
"-fdata-sections",
|
||||
@@ -75,7 +75,7 @@ SRC=[
|
||||
"riscv/rtthread/components/drivers/core/device.c"
|
||||
]
|
||||
|
||||
LD_FILE="riscv.ld"
|
||||
LD_FILE="riscv/riscv.ld"
|
||||
|
||||
TARGET="riscv"
|
||||
|
||||
@@ -84,12 +84,11 @@ OUTPUT="output"
|
||||
|
||||
|
||||
def tran_path(path:str):
|
||||
p=path.replace('\\','/')
|
||||
p=p.replace('/','_')
|
||||
if(p[0]=='.'):
|
||||
return p[1:]
|
||||
else:
|
||||
return p
|
||||
path=os.path.normpath(os.path.join(OUTPUT,path))
|
||||
base_path=os.path.dirname(path)
|
||||
if not os.path.exists(base_path):
|
||||
os.makedirs(base_path)
|
||||
return path
|
||||
|
||||
|
||||
# 判断是否需要重新生成
|
||||
@@ -132,9 +131,8 @@ def read_depend_files(name:str):
|
||||
def build_depend(src:list):
|
||||
flags=f"{' '.join(INC)} {' '.join(DEF)} {' '.join(CFLAG)}"
|
||||
for i in src:
|
||||
name=tran_path(i).split('.')[0]
|
||||
name=os.path.splitext(tran_path(i))[0]
|
||||
dst='.'.join([name,'d'])
|
||||
dst=os.path.join(OUTPUT,dst)
|
||||
if(check_rebuild(dst,[i])):
|
||||
cmd=f"{CC} -MM {i} -o {dst} {flags}"
|
||||
print(f"更新 {dst}")
|
||||
@@ -149,22 +147,20 @@ def build_depend(src:list):
|
||||
def build_object(src:list):
|
||||
flags=f"{' '.join(INC)} {' '.join(DEF)} {' '.join(CFLAG)}"
|
||||
for i in src:
|
||||
name_l=tran_path(i).split('.')
|
||||
name=name_l[0]
|
||||
file_type=name_l[-1]
|
||||
name_t=os.path.splitext(tran_path(i))
|
||||
name=name_t[0]
|
||||
file_type=name_t[-1]
|
||||
dst='.'.join([name,'o'])
|
||||
dst=os.path.join(OUTPUT,dst)
|
||||
cd='.'.join([name,'d'])
|
||||
cmd = ''
|
||||
if(file_type in ['c','.C']):
|
||||
cd=os.path.join(OUTPUT,cd)
|
||||
if(file_type in ['.c','.C']):
|
||||
if(check_rebuild(dst,read_depend_files(cd))):
|
||||
cmd=f"{CC} -c {i} -o {dst} {flags}"
|
||||
else:
|
||||
# print(f"{i} 没有更新依赖关系")
|
||||
pass
|
||||
elif(file_type in ['s','S','asm','ASM']):
|
||||
if(check_rebuild(dst,[i])):
|
||||
elif(file_type in ['.s','.S','.asm','.ASM']):
|
||||
if(check_rebuild(dst,read_depend_files(cd))):
|
||||
cmd=f"{CC} -c {i} -o {dst} {flags}"
|
||||
else:
|
||||
# print(f"{i} 没有更新依赖关系")
|
||||
@@ -181,8 +177,8 @@ def build_target(src:list):
|
||||
flags=f"{' '.join(INC)} {' '.join(DEF)} {' '.join(CFLAG)}"
|
||||
obj_list=[]
|
||||
for i in src:
|
||||
name=tran_path(i).split('.')[0]
|
||||
obj_list.append(OUTPUT+'/'+'.'.join([name,'o']))
|
||||
name=os.path.splitext(tran_path(i))[0]
|
||||
obj_list.append('.'.join([name,'o']))
|
||||
dst=os.path.join(OUTPUT,TARGET)+".elf"
|
||||
if(check_rebuild(dst,obj_list)):
|
||||
cmd=f"{CC} {' '.join(obj_list)} -o {dst} {flags} -T{LD_FILE} -Wall -Wextra -nostartfiles -Wl,-Map,\"{OUTPUT}/{TARGET}.map\""
|
||||
|
Reference in New Issue
Block a user