纪念一下完整的Makefile

TARGET =main

CC = arm-none-eabi-gcc
AS = arm-none-eabi-as
LD = arm-none-eabi-ld 
CFLAGS =-mthumb -mcpu=cortex-m4 -g -I /home/fxx/Desktop/Project/CMSIS/Inc/ -I /home/fxx/Desktop/Project/Dev/Inc/ -DSTM32F40_41xxx 
#LDFLAGS = --static -L /usr/arm-none-eabi/lib/ -L /usr/lib/gcc/arm-none-eabi/11.2.0/
LDFLAGS = --static -specs=nosys.specs -Wl,-Map=main.map -g
ASFLAGS = -mthumb -mcpu=cortex-m4

vpath %.c ./CMSIS/Src
vpath %.c ./Dev/Src
vpath %.c ./User
vpath %.h ./Dev/Inc
vpath %.h ./CMSIS/Inc
vpath %.o ./Build



C_INCLUDE = stm32f4xx_gpio.c \
system_stm32f4xx.c \
stm32f4xx_rcc.c \
main.c
OBJ_SOURCE = $(C_INCLUDE:%.c=%.o)
ASM_SOURCE = ./startup_stm32f40_41xxx.s
LD_SOURCE = ./STM32F407IGHx_FLASH.ld
ASMOBJ_SOURCE =$(ASM_SOURCE:%.s=%.o)

$(warning $(C_INCLUDE))
$(warning $(OBJ_SOURCE))

all:$(OBJ_SOURCE) $(ASMOBJ_SOURCE) 
	$(CC) $(LDFLAGS) $(sort $(addprefix ./Build/,$(C_INCLUDE:%.c=%.o))) $(sort $(addprefix ./Build/,$(ASMOBJ_SOURCE)))  -T $(LD_SOURCE) -o $(TARGET).elf 
$(OBJ_SOURCE):%.o:%.c
	$(CC) $(CFLAGS) -c $< -o ./Build/$@ -Wall
$(ASMOBJ_SOURCE):$(ASM_SOURCE)
	$(AS) $(ASFLAGS) -c $^ -o ./Build/$@
clean:
	@rm -rf ./Build/*.o
	@rm -rf ./*.elf
	@rm -rf ./main.map
download:
	openocd -f /usr/share/openocd/scripts/interface/stlink.cfg -f /usr/share/openocd/scripts/target/stm32f4x.cfg  -c init -c halt -c "flash write_image erase /home/fxx/Desktop/Project/main.elf" -c reset 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一个人创造世界

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值