每次Makefile重新编译库文件都存在问题

时间:2019-04-08 02:45:08

标签: makefile arm gnu-make

您好,我正在尝试通过遵循此repo

中的makefile模板来精简make

这是一个为stm32f407微控制器构建的项目模板。我已经修改了makefile,使其包含一些标准库。

为了节省时间和资源,不应每次我运行make时都重新编译供应商提供的标准库。但是,它正在执行我不希望它执行的操作。

我是makefile的新手。

请查看我的文件,并指出如何修复该文件。

# Name of the binaries.
PROJ_NAME=project-template

######################################################################
#                         SETUP TOOLS                                #
######################################################################

# This is the path to the toolchain
# (we don't put our toolchain on $PATH to keep the system clean)
TOOLS_DIR = ../toolchain/bin

# The tools we use
CC      = $(TOOLS_DIR)/arm-none-eabi-gcc
OBJCOPY = $(TOOLS_DIR)/arm-none-eabi-objcopy
GDB     = $(TOOLS_DIR)/arm-none-eabi-gdb
AS      = $(TOOLS_DIR)/arm-none-eabi-as

## Preprocessor options

# directories to be searched for header files
INCLUDE = $(addprefix -I,$(INC_DIRS))

# #defines needed when working with the STM library
DEFS    = -DUSE_STDPERIPH_DRIVER
# if you use the following option, you must implement the function
#    assert_failed(uint8_t* file, uint32_t line)
# because it is conditionally used in the library
# DEFS   += -DUSE_FULL_ASSERT

##### Assembler options

AFLAGS  = -mcpu=cortex-m4
AFLAGS += -mthumb
AFLAGS += -mthumb-interwork
AFLAGS += -mlittle-endian
AFLAGS += -mfloat-abi=hard
AFLAGS += -mfpu=fpv4-sp-d16

## Compiler options

CFLAGS  = -ggdb
# please do not optimize anything because we are debugging
CFLAGS += -O0
CFLAGS += -Wall -Wextra -Warray-bounds
CFLAGS += $(AFLAGS)

## Linker options

# tell ld which linker file to use
# (this file is in the current directory)
LFLAGS  = -Tstm32_flash.ld


######################################################################
#                         SETUP SOURCES                              #
######################################################################

# This is the directory containing the firmware package,
# the unzipped folder downloaded from here:
# http://www.st.com/web/en/catalog/tools/PF257904
STM_ROOT         =../stlib

# This is where the source files are located,
# which are not in the current directory
# (the sources of the standard peripheral library, which we use)
# see also "info:/make/Selective Search" in Konqueror
MY_SRC_DIR       = src
STM_SRC_DIR      = $(STM_ROOT)/Libraries/STM32F4xx_StdPeriph_Driver/src
STM_SRC_DIR     += $(STM_ROOT)/Utilities/STM32F4-Discovery
STM_STARTUP_DIR += $(STM_ROOT)/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/TrueSTUDIO

# Tell make to look in that folder if it cannot find a source
# in the current directory
vpath %.c $(MY_SRC_DIR)
vpath %.c $(STM_SRC_DIR)
vpath %.s $(STM_STARTUP_DIR)


################################################################################
#                         SETUP HEADER FILES                                   #
################################################################################

# The header files we use are located here
INC_DIRS  = ./headers
INC_DIRS += $(STM_ROOT)/Utilities/STM32F4-Discovery/
INC_DIRS += $(STM_ROOT)/Libraries/CMSIS/Include/
INC_DIRS += $(STM_ROOT)/Libraries/CMSIS/ST/STM32F4xx/Include/
INC_DIRS += $(STM_ROOT)/Libraries/STM32F4xx_StdPeriph_Driver/inc/   


################################################################################
#                   SOURCE FILES TO COMPILE                                    #
################################################################################

# My source files
SRCS   = main.c 

# Contains initialisation code and must be compiled into
# our project. This file is in the current directory and
# was writen by ST.
SRCS  += system_stm32f4xx.c

# Contain peripheral library source file
SRCS    += stm32f4xx_vectors.c
SRCS    += misc.c
SRCS    += stm32f4_discovery.c
SRCS    += stm32f4xx_rcc.c
SRCS    += stm32f4xx_gpio.c
SRCS    += stm32f4xx_syscfg.c
SRCS    += stm32f4xx_exti.c
SRCS    += systick.c

# Startup file written by ST
# The assembly code in this file is the first one to be
# executed. Normally you do not change this file.
ASRC = startup_stm32f4xx.s

# in case we have to many sources and don't want
# to compile all sources every time
OBJS := $(SRCS:.c=.o)
OBJS += $(ASRC:.s=.o)


######################################################################
#                         SETUP TARGETS                              #
######################################################################

TEMP_DIR = ./temp
OUT_DIR = ./out

.PHONY: all

all: $(PROJ_NAME).elf

%.o : %.c
    @echo "[Compiling  ]  $^"
    @mkdir -p ${TEMP_DIR}
    @$(CC) -c -o $(TEMP_DIR)/$@ $(INCLUDE) $(DEFS) $(CFLAGS) $^

%.o : %.s
    @echo "[Assembling ] $^"
    @mkdir -p ${TEMP_DIR}
    @$(AS) $(AFLAGS) $< -o $(TEMP_DIR)/$@

$(PROJ_NAME).elf: $(OBJS)
    @echo "[Linking    ]  $@"
    @mkdir -p ${OUT_DIR}
    @$(CC) $(CFLAGS) $(LFLAGS) $(foreach file, $^, $(TEMP_DIR)/$(file)) -o $(OUT_DIR)/$@
    @$(OBJCOPY) -O ihex $(OUT_DIR)/$(PROJ_NAME).elf   $(OUT_DIR)/$(PROJ_NAME).hex
    @$(OBJCOPY) -O binary $(OUT_DIR)/$(PROJ_NAME).elf $(OUT_DIR)/$(PROJ_NAME).bin

clean:
    @rm -f *.o $(OUT_DIR)/* $(TEMP_DIR)/*

flash: all
    st-flash write $(OUT_DIR)/$(PROJ_NAME).bin 0x8000000

debug:
# before you start gdb, you must start st-util
    $(GDB) -tui $(OUT_DIR)/$(PROJ_NAME).elf

这是命令行的图片 enter image description here

谢谢

0 个答案:

没有答案