STM32项⽬的makefile模版(带注释)#STM32 makefile template
# ⽣成的⽂件名<;项⽬名>
PROJECT = stm32_Mini_Led
# 定义⽂件格式和⽂件名
TARGET :=$(PROJECT)
TARGET_ELF :=$(TARGET).elf
TARGET_BIN :=$(TARGET).bin
TARGET_HEX :=$(TARGET).hex
OBJCPFLAGS_ELF_TO_BIN = -Obinary
OBJCPFLAGS_ELF_TO_HEX = -Oihex
OBJCPFLAGS_BIN_TO_HEX = -Ibinary -Oihex
# 定义路径
TOP_DIR =.
SCRIPT_DIR :=$(TOP_DIR)/scripts
STARTUP_DIR :=$(TOP_DIR)/third_party/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup
INC_DIR := -I $(TOP_DIR)/src -I $(TOP_DIR)/src/Driver -I $(TOP_DIR)/src/EDP -I $(TOP_DIR)/src/Network
# 设置shell环境变量
#export LD_LIBRARY_PATH = $LD_LIBRARY_PATH:/Users/ch-yanghl/gcc-arm-none-eabi/arm-none-eabi/lib/thumb/ # 设置ld链接脚本⽂件
LDSCRIPT :=$(SCRIPT_DIR)/stm32_flash.ld
# 定义编译⼯具
CC = arm-none-eabi-gcc
AS = arm-none-eabi-as
LD = arm-none-eabi-ld
AR = arm-none-eabi-ar
OBJCP = arm-none-eabi-objcopy
# 定义编译标志
CCFLAGS += -Wall -mcpu=cortex-m3 -mthumb -g -mfloat-abi=soft -march=armv7-m
ASFLAGS += -Wall -mcpu=cortex-m3 -mthumb
LDFLAGS += -T $(LDSCRIPT)#-A armv7-m
LDFLAGS += -L /Users/ch-yanghl/gcc-arm-none-eabi/lib/gcc/arm-none-eabi/5.4.1
LDFLAGS += -L /Users/ch-yanghl/gcc-arm-none-eabi/arm-none-eabi/lib/thumb
# 要链接的静态库
#LDLIBS += /Users/ch-yanghl/gcc-arm-none-eabi/arm-none-eabi/lib/thumb/libc.a
#LDLIBS += /Users/ch-yanghl/gcc-arm-none-eabi/arm-none-eabi/lib/thumb/libg.a
#LDLIBS += /Users/ch-yanghl/gcc-arm-none-eabi/arm-none-eabi/lib/thumb/libm.a
#LDLIBS += /Users/ch-yanghl/gcc-arm-none-eabi/lib/gcc/arm-none-eabi/5.4.1/libgcc.a
#LDLIBS += /Users/ch-yanghl/gcc-arm-none-eabi/arm-none-eabi/lib/thumb/libnosys.a
# .c⽂件中的头⽂件引⽤查路径
CCFLAGS +=$(INC_DIR)
# .s⽂件的flags
#ASFLAGS +=
# .c⽂件编译时定义宏
CCFLAGS += -D STM32F10X_MD -D USE_STDPERIPH_DRIVER
# 添加启动⽂件
#SOURCE += $(SCRIPT_DIR)/startup_stm32f10x_md.c
SOURCE_ASM +=$(STARTUP_DIR)/gcc_ride7/startup_stm32f10x_md.s
# 展开⼯作⼦⽬录中的inc⽂件(inc⽂件中添加需要编译链接的.c,.s等⽂件)
-include $(TOP_DIR)/src/make.inc
-include $(TOP_DIR)/src/make.inc
-include $(TOP_DIR)/third_party/make.inc
# 替换⽂件后缀
C_OBJS :=$(SOURCE:%.c=%.o)
ASM_OBJS :=$(SOURCE_ASM:%.s=%.o)
# 编译命令的定义
COMPILE =$(CC)$(CCFLAGS) -c $< -o $@
ASSEMBLE =$(AS)$(ASFLAGS) -c $< -o $@
LINK =$(LD) $+ $(LDFLAGS)$(LDLIBS) -o $@
ELF_TO_BIN =$(OBJCP)$(OBJCPFLAGS_ELF_TO_BIN) $<$@
BIN_TO_HEX =$(OBJCP)$(OBJCPFLAGS_BIN_TO_HEX) $<$@
# 定义伪⽬标
.PHONY: all clean printf
# 定义规则
all: $(TARGET_HEX)
@echo "build done"
$(TARGET_HEX):$(TARGET_BIN)
$(BIN_TO_HEX)
$(TARGET_BIN):$(TARGET_ELF)
$(ELF_TO_BIN)
$(TARGET_ELF):$(C_OBJS)$(ASM_OBJS)
$(LINK)
$(C_OBJS):%.o:%.c
$(COMPILE)
$(ASM_OBJS):%.o:%.s
$(ASSEMBLE)
printf:
@echo $(ASM_OBJS)
@echo $(ASSEMBLE)
# 清理项
clean:
rm -f $(TARGET_HEX)
rm -f $(TARGET_BIN)
rm -f $(TARGET_ELF)
rm -f $(C_OBJS)$(ASM_OBJS)
@echo "clean done"
要链接的静态库
#LDLIBS += /Users/ch-yanghl/gcc-arm-none-eabi/arm-none-eabi/lib/thumb/libc.a
#LDLIBS += /Users/ch-yanghl/gcc-arm-none-eabi/arm-none-eabi/lib/thumb/libg.a
#LDLIBS += /Users/ch-yanghl/gcc-arm-none-eabi/arm-none-eabi/lib/thumb/libm.a #LDLIBS += /Users/ch-yanghl/gcc-arm-none-eabi/lib/gcc/arm-none-eabi/5.4.1/libgcc.a #LDLIBS += /Users/ch-yanghl/gcc-arm-none-eabi/arm-none-eabi/lib/thumb/libnosys.a -这⼀块为什么要注释:因为⽂中使⽤了
设置ld链接脚本⽂件
LDSCRIPT :=$(SCRIPT_DIR)/stm32_flash.ld
/stm32_flash.ld⽂件中最后部分内容/
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )makefile phony
libg.a ( * )
libgcc.a ( * )
}
这个ld脚本⽂件,该⽂件中已经包含了这些库。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论