初步实现异常捕获机制
This commit is contained in:
189
make.py
Normal file
189
make.py
Normal file
@@ -0,0 +1,189 @@
|
||||
|
||||
# -*- coding: gbk -*-
|
||||
|
||||
|
||||
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
'''
|
||||
|
||||
<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ű<EFBFBD>֮<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
||||
|
||||
'''
|
||||
|
||||
|
||||
CC = 'gcc'
|
||||
# CC = 'C:\\ARM_GCC\\bin\\arm-none-eabi-gcc'
|
||||
|
||||
# AS = CC + ' -x assembler-with-cpp'
|
||||
|
||||
# HEX = 'C:\\ARM_GCC\\bin\\arm-none-eabi-objcopy' + ' -O ihex'
|
||||
# BIN = 'C:\\ARM_GCC\\bin\\arm-none-eabi-objcopy' + ' -O binary -S'
|
||||
|
||||
CSRC = []
|
||||
|
||||
CINC = ['-Isoft']
|
||||
|
||||
CDEF = ["-DTEST"]
|
||||
|
||||
ASRC = []
|
||||
|
||||
BUILD_DIR = 'build'
|
||||
|
||||
TARGET = 'hello'
|
||||
|
||||
# CFLAG = ["-Wall -pedantic -specs=nano.specs -mcpu=cortex-m3 -mthumb -lc -lm -lnosys -Og -Tstm32_boot.ld",
|
||||
# f"-Wl,-Map={BUILD_DIR}/{TARGET}.map,--cref -Wl,--gc-sections"]
|
||||
CFLAG = ["-Wall -pedantic -g"]
|
||||
|
||||
# <20>ҵ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><D7BA><EFBFBD>ļ<EFBFBD>
|
||||
def find_type(path:str,fix:list[str]):
|
||||
dlist=os.listdir(path)
|
||||
file_list=[]
|
||||
for i in dlist:
|
||||
ps=os.path.join(path, i)
|
||||
if os.path.isdir(ps):
|
||||
file_list+=find_type(ps,fix)
|
||||
else:
|
||||
suf=ps.split('.')[-1]
|
||||
if(suf in fix):
|
||||
file_list.append(ps)
|
||||
return file_list
|
||||
|
||||
|
||||
|
||||
'''
|
||||
<EFBFBD><EFBFBD>.c<><63><EFBFBD><EFBFBD>Ϊ.o<>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ű<EFBFBD><EFBFBD><EFBFBD>Ҫʵ<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.c<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>.o<>ļ<EFBFBD>
|
||||
gcc -c test.c -o test.o
|
||||
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD>.d<>ļ<EFBFBD>
|
||||
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
|
||||
|
||||
|
||||
# <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
def check_rebuild(dst:str,src:list[str]):
|
||||
if(not os.path.exists(dst)):
|
||||
return True
|
||||
dst_time=os.path.getmtime(dst)
|
||||
src_time=[]
|
||||
for i in src:
|
||||
src_time.append(os.path.getmtime(i))
|
||||
src_time.sort()
|
||||
if(src_time[-1]>dst_time):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
||||
# <20><>ȡ.d<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>б<EFBFBD>
|
||||
def read_depend_files(name:str):
|
||||
with open(name) as f:
|
||||
t=f.readline()
|
||||
t=t.split(':')[-1].strip()
|
||||
t=t.split(' ')
|
||||
# print(f"<22><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>{t}")
|
||||
return t
|
||||
|
||||
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
||||
def build_depend(src:list[str]):
|
||||
flags=f"{' '.join(CINC)} {' '.join(CDEF)} {' '.join(CFLAG)}"
|
||||
for i in src:
|
||||
name=tran_path(i).split('.')[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(cmd)
|
||||
ret=os.system(cmd)
|
||||
if(ret):
|
||||
exit()
|
||||
|
||||
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC>ļ<EFBFBD>
|
||||
def build_object(src:list[str]):
|
||||
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]
|
||||
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(check_rebuild(dst,read_depend_files(cd))):
|
||||
cmd=f"{CC} -c {i} -o {dst} {flags}"
|
||||
elif(file_type in ['s','S','asm','ASM']):
|
||||
if(check_rebuild(dst,[i])):
|
||||
cmd=f"{AS} -c {i} -o {dst} {flags}"
|
||||
if(len(cmd)>0):
|
||||
print(cmd)
|
||||
ret=os.system(cmd)
|
||||
if(ret):
|
||||
exit()
|
||||
|
||||
|
||||
# <20><><EFBFBD>ɿ<EFBFBD>ִ<EFBFBD><D6B4><EFBFBD>ļ<EFBFBD>
|
||||
def build_target(src:list[str]):
|
||||
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']))
|
||||
dst=os.path.join(BUILD_DIR,TARGET)
|
||||
if(check_rebuild(dst,obj_list)):
|
||||
cmd=f"{CC} {' '.join(obj_list)} -o {dst} {flags}"
|
||||
print(cmd)
|
||||
ret=os.system(cmd)
|
||||
if(ret):
|
||||
exit()
|
||||
else:
|
||||
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD>Ŀ<EFBFBD><EFBFBD>")
|
||||
|
||||
|
||||
def main():
|
||||
global CSRC
|
||||
global ASRC
|
||||
CSRC+=find_type('./',['c','C'])
|
||||
# ASRC+=find_type('./',['s','S','asm','ASM'])
|
||||
|
||||
if(not os.path.exists(BUILD_DIR)):
|
||||
os.makedirs(BUILD_DIR)
|
||||
|
||||
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ")
|
||||
build_depend(CSRC)
|
||||
print("<EFBFBD><EFBFBD><EFBFBD>ɶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>")
|
||||
build_object(CSRC)
|
||||
build_object(ASRC)
|
||||
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>")
|
||||
build_target(CSRC+ASRC)
|
||||
# os.system(f"{HEX} {BUILD_DIR}/{TARGET} {BUILD_DIR}/{TARGET}.hex")
|
||||
# os.system(f"{BIN} {BUILD_DIR}/{TARGET} {BUILD_DIR}/{TARGET}.bin")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user