我有以下 Makefile
CC=arm-none-eabi-gcc
AR=arm-none-eabi-ar
vpath %.c src src/peripherals
vpath %.o out
CFLAGS = -g -O2 -Wall -DUSE_STDPERIPH_DRIVER
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
CFLAGS += -ffreestanding -nostdlib
CFLAGS += -Iinc -Iinc/cmsis -Iinc/peripherals -Iinc/stm32f4xx
OUT_DIR=out
SRCS = misc.c stm32f4xx_adc.c stm32f4xx_can.c stm32f4xx_crc.c stm32f4xx_cryp.c stm32f4xx_cryp_aes.c \
stm32f4xx_cryp_des.c stm32f4xx_cryp_tdes.c stm32f4xx_dac.c stm32f4xx_dbgmcu.c stm32f4xx_dcmi.c stm32f4xx_dma.c \
stm32f4xx_exti.c stm32f4xx_flash.c stm32f4xx_fsmc.c stm32f4xx_gpio.c stm32f4xx_hash.c stm32f4xx_hash_md5.c \
stm32f4xx_hash_sha1.c stm32f4xx_i2c.c stm32f4xx_iwdg.c stm32f4xx_pwr.c stm32f4xx_rcc.c stm32f4xx_rng.c \
stm32f4xx_rtc.c stm32f4xx_sdio.c stm32f4xx_spi.c stm32f4xx_syscfg.c stm32f4xx_tim.c stm32f4xx_usart.c \
stm32f4xx_wwdg.c
OBJS = $(SRCS:.c=.o)
.PHONY: libstm32f4.a
all: libstm32f4.a
%.o : %.c
mkdir -p $(OUT_DIR)
$(CC) $(CFLAGS) -c -o $(OUT_DIR)/$@ $^
libstm32f4.a: $(OBJS)
$(AR) -r $(OUT_DIR)/$@ $(OUT_DIR)/$(OBJS)
clean:
rm -rf $(OUT_DIR)
但是在运行 make 时,我的 .o 文件构建得很好,但是在调用 arm-none-eabi-ar 的时候,我弄得一团糟。
线
$(AR) -r $(OUT_DIR)/$@ $(OUT_DIR)/$(OBJS)
可能是我出错的地方,它的输出是:
arm-none-eabi-ar -r out/libstm32f4.a out/misc.o stm32f4xx_adc.o stm32f4xx_can.o stm32f4xx_crc.o stm32f4xx_cryp.o stm32f4xx_cryp_aes.o stm32f4xx_cryp_des.o stm32f4xx_cryp_tdes.o stm32f4xx_dac.o stm32f4xx_dbgmcu.o stm32f4xx_dcmi.o stm32f4xx_dma.o stm32f4xx_exti.o stm32f4xx_flash.o stm32f4xx_fsmc.o stm32f4xx_gpio.o stm32f4xx_hash.o stm32f4xx_hash_md5.o stm32f4xx_hash_sha1.o stm32f4xx_i2c.o stm32f4xx_iwdg.o stm32f4xx_pwr.o stm32f4xx_rcc.o stm32f4xx_rng.o stm32f4xx_rtc.o stm32f4xx_sdio.o stm32f4xx_spi.o stm32f4xx_syscfg.o stm32f4xx_tim.o stm32f4xx_usart.o stm32f4xx_wwdg.o
arm-none-eabi-ar: creating out/libstm32f4.a
arm-none-eabi-ar: stm32f4xx_adc.o: No such file or directory
make: *** [libstm32f4.a] Error 1
看这个时,out/libstm32f4.a 是正确的,但是所有 *.o 文件的第二个子句是完全错误的,只有 out/misc.o 以 out/ 文件夹为前缀,而不是其余的,导致一个错误?
如何修复我的 Makefile 以让它在 ./out/ 中查找 .o 文件?我在用吗
vpath %.o out
不正确,还是我在 Makefile 中的 arm-none-eabi-ar 指令不正确?