1

我知道这已经是一个长期讨论的话题,但我还不能完全理解/实现适合我的文件夹系统和要求的 makefile。

这是我的任何项目的文件夹系统的样子:

project_name
|-Inc
|-Src
|-Classes
|-Startup
|-Debug
  Makefile
  |- Src
     subdir_src.mk
  |- Classes
     subdir_class.mk
  |- Startup
     subdir_startup.mk

我想要每个子文件夹(即 subdir_x.mk)的本地生成文件,其源文件是一个级别的(即../Src/file1.cpp),为此我构建了一个这样的生成文件(在这种情况下以 subdir_src.mk 为例)

C_SOURCES=$(wildcard ../Src/*.c)
C_OBJECTS=$(patsubst %.c, %.o, $(C_SOURCES))

CXX_SOURCES=$(wildcard ../Src/*.cpp)
CXX_OBJECTS=$(patsubst %.cpp, %.o, $(CXX_SOURCES))


CC=arm-none-eabi-g++ 
MACH=cortex-m4
STD=gnu++14
CFLAGS= -c -mcpu=$(MACH) -mthumb -std=$(STD) -I ../Inc -O0 -g3 -fno-exceptions -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti -fno-use-cxa-atexit -Wall --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard 


.PHONY: all
.PHONY: objects
.PHONY: clean

objects:$(CXX_OBJECTS) $(C_OBJECTS)

#I want to store the .o files in the /Debug/Src instead of /Src so I think this is the right way to do it  
$(CXX_OBJECTS): /Src/%.o : ../Src/%.cpp
    $(CC) $(CFLAGS) $< -o $@

$(C_OBJECTS): /Src/%.o : ../Src/%.cpp
        $(CC) $(CFLAGS) $< -o $@ 

clean:
    rm -rf *.o *.elf *.dat *.map *.txt

当我得到输出时,这种方式似乎不起作用: make: *** No targets specified and no makefile found. Stop. 当我在 cmd 中键入“make objects”时

我希望当我提示 /Debug/Makefile 时,我希望该 makefile 使用每个 subdir.mk 来构建对象,然后“大”makefile 链接所有对象。

我试图看看 stm32 构建系统,但我就是不太明白......所以我来了。

我很欣赏关于如何制作这个 makefile 的想法和评论,因为我目前的做法很陈旧。

另外我需要知道如何明确清除每个子文件夹中的相应文件。

4

0 回答 0