make.py 改为utf-8编码
This commit is contained in:
41
make.py
41
make.py
@@ -1,5 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# -*- coding: gbk -*-
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -11,7 +10,7 @@ import time
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ű<EFBFBD>֮<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
修改编译脚本之后需要全编译一次
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@@ -38,11 +37,11 @@ TARGET = 'hello.exe'
|
|||||||
|
|
||||||
# CFLAG = ["-Wall -pedantic -specs=nano.specs -mcpu=cortex-m3 -mthumb -lc -lm -lnosys -Og -Tstm32_boot.ld",
|
# 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"]
|
# f"-Wl,-Map={BUILD_DIR}/{TARGET}.map,--cref -Wl,--gc-sections"]
|
||||||
# -pedantic <EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ISO<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
# -pedantic 这一项是ISO语法检验
|
||||||
CFLAG = ["-Wall -g"]
|
CFLAG = ["-Wall -g"]
|
||||||
|
|
||||||
|
|
||||||
# <EFBFBD>ҵ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
# 找到指定后缀的文件
|
||||||
def find_type(path:str,fix:list[str]):
|
def find_type(path:str,fix:list[str]):
|
||||||
dlist=os.listdir(path)
|
dlist=os.listdir(path)
|
||||||
file_list=[]
|
file_list=[]
|
||||||
@@ -59,11 +58,11 @@ def find_type(path:str,fix:list[str]):
|
|||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
<EFBFBD><EFBFBD>.c<><63><EFBFBD><EFBFBD>Ϊ.o<>ļ<EFBFBD><C4BC><EFBFBD>
|
将.c编译为.o文件,
|
||||||
<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>
|
编译脚本需要实现 如果.c文件有修改 则重新编译对应文件的.o文件
|
||||||
gcc -c test.c -o test.o
|
gcc -c test.c -o test.o
|
||||||
|
|
||||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD>.d<>ļ<EFBFBD>
|
输出依赖关系到.d文件
|
||||||
gcc -MM main.c -o build/main.d
|
gcc -MM main.c -o build/main.d
|
||||||
|
|
||||||
|
|
||||||
@@ -82,7 +81,7 @@ def tran_path(path:str):
|
|||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
# <EFBFBD>ж<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
# 判断是否需要重新生成
|
||||||
def check_rebuild(dst:str,src:list[str]):
|
def check_rebuild(dst:str,src:list[str]):
|
||||||
# print(f"src:{src}")
|
# print(f"src:{src}")
|
||||||
if(not os.path.exists(dst)):
|
if(not os.path.exists(dst)):
|
||||||
@@ -101,7 +100,7 @@ def check_rebuild(dst:str,src:list[str]):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# <EFBFBD><EFBFBD>ȡ.d<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>б<EFBFBD>
|
# 读取.d文件,返回依赖文件列表
|
||||||
def read_depend_files(name:str):
|
def read_depend_files(name:str):
|
||||||
with open(name) as f:
|
with open(name) as f:
|
||||||
lines=f.readlines()
|
lines=f.readlines()
|
||||||
@@ -114,11 +113,11 @@ def read_depend_files(name:str):
|
|||||||
t+=line
|
t+=line
|
||||||
t=t.split(':')[-1].strip()
|
t=t.split(':')[-1].strip()
|
||||||
t=t.split(' ')
|
t=t.split(' ')
|
||||||
# print(f"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>{t}")
|
# print(f"依赖列表{t}")
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
|
||||||
# <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
# 生成依赖关系
|
||||||
def build_depend(src:list[str]):
|
def build_depend(src:list[str]):
|
||||||
flags=f"{' '.join(CINC)} {' '.join(CDEF)} {' '.join(CFLAG)}"
|
flags=f"{' '.join(CINC)} {' '.join(CDEF)} {' '.join(CFLAG)}"
|
||||||
for i in src:
|
for i in src:
|
||||||
@@ -132,9 +131,9 @@ def build_depend(src:list[str]):
|
|||||||
if(ret):
|
if(ret):
|
||||||
exit()
|
exit()
|
||||||
else:
|
else:
|
||||||
print(f"{i} û<EFBFBD>и<EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>ļ<EFBFBD>")
|
print(f"{i} 没有更新源文件")
|
||||||
|
|
||||||
# <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><EFBFBD>ļ<EFBFBD>
|
# 生成中间文件
|
||||||
def build_object(src:list[str]):
|
def build_object(src:list[str]):
|
||||||
flags=f"{' '.join(CINC)} {' '.join(CDEF)} {' '.join(CFLAG)}"
|
flags=f"{' '.join(CINC)} {' '.join(CDEF)} {' '.join(CFLAG)}"
|
||||||
for i in src:
|
for i in src:
|
||||||
@@ -150,12 +149,12 @@ def build_object(src:list[str]):
|
|||||||
if(check_rebuild(dst,read_depend_files(cd))):
|
if(check_rebuild(dst,read_depend_files(cd))):
|
||||||
cmd=f"{CC} -c {i} -o {dst} {flags}"
|
cmd=f"{CC} -c {i} -o {dst} {flags}"
|
||||||
else:
|
else:
|
||||||
print(f"{i} û<EFBFBD>и<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ")
|
print(f"{i} 没有更新依赖关系")
|
||||||
elif(file_type in ['s','S','asm','ASM']):
|
elif(file_type in ['s','S','asm','ASM']):
|
||||||
if(check_rebuild(dst,[i])):
|
if(check_rebuild(dst,[i])):
|
||||||
cmd=f"{AS} -c {i} -o {dst} {flags}"
|
cmd=f"{AS} -c {i} -o {dst} {flags}"
|
||||||
else:
|
else:
|
||||||
print(f"{i} û<EFBFBD>и<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ")
|
print(f"{i} 没有更新依赖关系")
|
||||||
if(len(cmd)>0):
|
if(len(cmd)>0):
|
||||||
print(cmd)
|
print(cmd)
|
||||||
ret=os.system(cmd)
|
ret=os.system(cmd)
|
||||||
@@ -163,7 +162,7 @@ def build_object(src:list[str]):
|
|||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
|
||||||
# <EFBFBD><EFBFBD><EFBFBD>ɿ<EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
# 生成可执行文件
|
||||||
def build_target(src:list[str]):
|
def build_target(src:list[str]):
|
||||||
flags=f"{' '.join(CINC)} {' '.join(CDEF)} {' '.join(CFLAG)}"
|
flags=f"{' '.join(CINC)} {' '.join(CDEF)} {' '.join(CFLAG)}"
|
||||||
obj_list=[]
|
obj_list=[]
|
||||||
@@ -178,7 +177,7 @@ def build_target(src:list[str]):
|
|||||||
if(ret):
|
if(ret):
|
||||||
exit()
|
exit()
|
||||||
else:
|
else:
|
||||||
print(f"{dst} û<EFBFBD>и<EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>")
|
print(f"{dst} 没有更新的链接文件")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -190,12 +189,12 @@ def main():
|
|||||||
if(not os.path.exists(BUILD_DIR)):
|
if(not os.path.exists(BUILD_DIR)):
|
||||||
os.makedirs(BUILD_DIR)
|
os.makedirs(BUILD_DIR)
|
||||||
|
|
||||||
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ")
|
print("生成依赖关系")
|
||||||
build_depend(CSRC)
|
build_depend(CSRC)
|
||||||
print("<EFBFBD><EFBFBD><EFBFBD>ɶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>")
|
print("生成对象文件")
|
||||||
build_object(CSRC)
|
build_object(CSRC)
|
||||||
# build_object(ASRC)
|
# build_object(ASRC)
|
||||||
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>")
|
print("生成目标文件")
|
||||||
build_target(CSRC+ASRC)
|
build_target(CSRC+ASRC)
|
||||||
# os.system(f"{HEX} {BUILD_DIR}/{TARGET} {BUILD_DIR}/{TARGET}.hex")
|
# os.system(f"{HEX} {BUILD_DIR}/{TARGET} {BUILD_DIR}/{TARGET}.hex")
|
||||||
# os.system(f"{BIN} {BUILD_DIR}/{TARGET} {BUILD_DIR}/{TARGET}.bin")
|
# os.system(f"{BIN} {BUILD_DIR}/{TARGET} {BUILD_DIR}/{TARGET}.bin")
|
||||||
|
Reference in New Issue
Block a user