1、 这一章节原子哥主要是整理代码和修改Makefil
image.png2、Makefil变得复杂:
需要注意有些命令是需要空格
CROSS_COMPILE ?=arm-linux-gnueabihf-
TARGET ?=bsp
CC :=$(CROSS_COMPILE)gcc
LD :=$(CROSS_COMPILE)ld
OBJCOPY :=$(CROSS_COMPILE)objcopy
OBJDUMP :=$(CROSS_COMPILE)objdump
INCDIRS := imx6ul \
bsp/clk \
bsp/led \
bsp/delay
SRCDIRS := project \
bsp/clk \
bsp/led \
bsp/delay
INCLUDE :=$(patsubst %, -I %, $(INCDIRS))
SFILES :=$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.S))
CFILES :=$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c))
SFILENDIR :=$(notdir $(SFILES))
CFILENDIR :=$(notdir $(CFILES))
SOBJS :=$(patsubst %, obj/%, $(SFILENDIR:.S=.o))
COBJS :=$(patsubst %, obj/%, $(CFILENDIR:.c=.o))
OBJS :=$(SOBJS) $(COBJS)
VPATH :=$(SRCDIRS)
.PHONY:clean
.PHONY: clean
$(TARGET).bin : $(OBJS)
$(LD) -Timx6ul.lds -o $(TARGET).elf $^
$(OBJCOPY) -O binary -S $(TARGET).elf $@
$(OBJDUMP) -D -m arm $(TARGET).elf > $(TARGET).dis
$(SOBJS) : obj/%.o:%.S
$(CC) -Wall -nostdlib -c -O2 $(INCLUDE) -o $@ $<
$(COBJS) : obj/%.o:%.c
$(CC) -Wall -nostdlib -c -O2 $(INCLUDE) -o $@ $<
clean:
rm -rf *.o $(TARGET).bin $(TARGET).elf $(TARGET).dis $(COBJS) $(SOBJS)
3、 编译&&测试
image.png
网友评论