这个脚本可以自动扫描目录下的.c和.s文件并编译,同时生成hex和bin文件
,可以代替Makefile工作。cortex-m 单片机
# -*- coding: gbk -*-
import os
import sys
import time
'''
修改编译脚本之后需要全编译一次
'''
# 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"]
# 找到指定后缀的文件
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
'''
将.c编译为.o文件,
编译脚本需要实现 如果.c文件有修改 则重新编译对应文件的.o文件
gcc -c test.c -o test.o
输出依赖关系到.d文件
gcc -MM main.c -o build/main.d
'''
def tran_path(path:str):
p=path.replace('\\','/')
p=p.replace('/','_')
if(p[0]=='.'):