1

我正在尝试编写一个 Makefile,它将从源构建一个 .o 文件列表,然后在一个单独的 make 目标中,设置链接等。我的 Makefile 目前看起来像这样:

CC=arm-none-eabi-gcc

vpath %.c src src/peripherals
vpath %.o out

OUT_DIR = out

CFLAGS  = -DUSE_STDPERIPH_DRIVER
CFLAGS += -c -fmessage-length=0 -g3 -gdwarf-2 -O0 -Wall -Wa,-adhlns="$@.lst"
CFLAGS += -mthumb -mcpu=cortex-m4
CFLAGS += -MMD -MP -MF"$@.d" -MT"$@.d"
CFLAGS += -Iinc -Iinc/cmsis -Iinc/peripherals -Iinc/stm32f4xx

SRC = 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

OBJ = $(SRC:.c=.o)

%.o : %.c 
    $(CC) -c -o $@ $< $(CFLAGS)

all: $(OBJ)
    $(CC) -o $@ $^ $(CFLAGS)

我知道这是非常错误的,我不是在 Makefile 中工作的专家,但我想把它做好,因为它有助于更​​好地理解这个过程。

基本上需要的是获取 $(SRC) 中的 .c 文件列表并将它们构建到 .o 文件列表中,这些文件在 lib/out 中输出

我知道我的目标和 %.o... 规则非常混乱。我如何获得 all: 目标来构建单个 .o 文件。

这里的项目结构仅供参考,我正在处理的 Makefile 在 ./lib 文件夹中。

.
├── Makefile
├── inc
│   └── main.h
├── lib
│   ├── Makefile
│   ├── inc
│   │   ├── cmsis
│   │   │   ├── arm_common_tables.h
│   │   │   ├── ...
│   │   ├── peripherals
│   │   │   ├── misc.h
│   │   │   ├── stm32f4xx_adc.h
│   │   │   ├── ...
│   │   └── stm32f4xx
│   │       ├── stm32f4xx.h
│   │       ├── stm32f4xx_conf.h
│   │       └── system_stm32f4xx.h
│   ├── src
│   │   └── peripherals
│   │       ├── misc.c
│   │       ├── stm32f4xx_adc.c
│   │       ├── ...
│   ├── startup_stm32f4xx.s
│   └── ~Makefile
├── readme.md
├── src
│   └── main.c
├── stm32f4.ld
├── stm32f4discovery.cfg
├── system_stm32f4xx.c
└── ~Makefile
4

1 回答 1

1

错字OBJ = $(SRCS:.c=.o)更改为OBJ = $(SRC:.c=.o),看起来您的依赖文件生成也有些混乱。

于 2013-02-26T09:40:15.913 回答