1 year ago
#167594
Juan_David
About how to properly makefile arm stm32
I know this is already a long discussed topic on here, yet I have not been able to fully understand/implement a makefile that suits my folder system and requirements.
here is what my any of my project's folder system looks like:
project_name
|-Inc
|-Src
|-Classes
|-Startup
|-Debug
Makefile
|- Src
subdir_src.mk
|- Classes
subdir_class.mk
|- Startup
subdir_startup.mk
I want local makefiles for each subfolder(that is subdir_x.mk) for which the source files are one level up (i.e ../Src/file1.cpp) and for that purpose I've built a makefile like this (in the case of subdir_src.mk as an example)
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
This way does not seem to work as I get the output:
make: *** No targets specified and no makefile found. Stop.
when I type "make objects" in cmd
I want that when I prompt /Debug/Makefile I want that makefile to make use of each subdir.mk to build the objects and then the "big"makefile link all the objects.
I've Tried to take a look at stm32 build system but I just could not understand quite well... so here I am.
I appreciate the thoughts and comments on how might I make this makefiles since my current way to do it is quite archaic.
Also I need to know how to make make clear to clear the corresponding files in each subfolder.
c++
stm32
gnu-make
iot
arm-none-eabi-gcc
0 Answers
Your Answer