From 6d3afeb07540ccf612787031fb87eb6122064a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Mon, 1 Aug 2022 23:44:55 +0200 Subject: [PATCH] Update makefile to use dependenccy files and create obj folder --- .gitignore | 2 ++ Makefile | 59 +++++++++++++++++++++++++++--------------------------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 628444f..04ca85c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ project.elf +*.lss *.o *.map *.bin @@ -6,3 +7,4 @@ project.elf *.user *.user* *.user.* +obj/* diff --git a/Makefile b/Makefile index 1a6c15b..89b0105 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,9 @@ CFILES = main.c syscalls/syscalls.c setup/system_init.c startup/startup_stm32f7 ASFILES = INCLUDEPATH = -Iinclude +OBJDIR := obj -target = project +TARGET = project LIBRARYPATH = -Lstartup -Ldsp LIBRARIES = -larm_cortexM7lfsp_math @@ -29,19 +30,19 @@ SIZE=arm-none-eabi-size LFLAGS = -mlittle-endian -mthumb -mcpu=cortex-m7 -mthumb-interwork LFLAGS += -mfloat-abi=hard -mfpu=fpv5-sp-d16 --disable-newlib-supplied-syscalls -nostartfiles LFLAGS += -Tstm32f746zgt-axim.ld -Wl,-Map=$(mapfile).map -Wl,--gc-sections +LFLAGS += -Wl,--print-memory-usage -CFLAGS = -c -fmessage-length=0 -mlittle-endian -mthumb -mcpu=cortex-m7 -mthumb-interwork +CFLAGS = -fmessage-length=0 -mlittle-endian -mthumb -mcpu=cortex-m7 -mthumb-interwork CFLAGS += -mfloat-abi=hard -mfpu=fpv5-sp-d16 -nostartfiles -Wall #################################################################################### -OBJ = $(CFILES:%.c=%.c.o) -ASOBJ = $(ASFILES:%.S=%.S.o) - -default: $(target).elf - +OBJ = $(CFILES:%.c=$(OBJDIR)/%.c.o) +ASOBJ = $(ASFILES:%.S=$(OBJDIR)/%.S.o) +DEPENDENCY_FILES = $(CFILES:%.c=$(OBJDIR)/%.c.d) $(ASFILES:%.S=$(OBJDIR)/%.S.d) +default: $(TARGET).elf %.bin: %.elf $(OBJCOPY) -O binary $^ $@ @@ -50,37 +51,35 @@ default: $(target).elf #Linking -$(target).elf: $(OBJ) $(ASOBJ) - $(CC) $(LFLAGS) $(LIBRARYPATH) -o $@ $^ $(LIBRARIES) - $(SIZE) $@ +$(TARGET).elf: $(OBJ) $(ASOBJ) + @$(CC) $(LFLAGS) $(LIBRARYPATH) -o $@ $^ $(LIBRARIES) + @$(SIZE) $@ #Compiling -%.c.o: %.c - $(CC) $(CFLAGS) $(INCLUDEPATH) $(DEFINES) -o $@ $< +$(OBJ): + @echo [CC] $@ + @mkdir -p $(@D) + @$(CC) $(CFLAGS) -MMD -MT $@ $(INCLUDEPATH) $(DEFINES) -o $@ -c $(@:$(OBJDIR)/%.c.o=%.c) -%.S.o: %.S - $(CC) $(CFLAGS) $(INCLUDEPATH) $(DEFINES) -o $@ $< +$(ASOBJ): + @echo [AS] $@ + @mkdir -p $(@D) + @$(CC) $(CFLAGS) -MMD -MT $@ $(INCLUDEPATH) $(DEFINES) -o $@ -c $(@:$(OBJDIR)/%.S.o=%.S) -.PHONY: qtproject clean mrproper objcopy disassemble +.PHONY: clean mrproper objcopy disassemble -disassemble: $(target).elf - $(OBJDUMP) -D -s $< > $(target).lss +disassemble: $(TARGET).elf + $(OBJDUMP) -D -s $< > $(TARGET).lss -objcopy: $(target).bin $(target).hex +objcopy: $(TARGET).bin $(TARGET).hex mrproper: - rm -f $(target).pro + rm -f $(TARGET).pro clean: - rm -f $(target).elf $(target).bin $(target).hex $(OBJ) $(ASOBJ) $(mapfile).map $(target).lss -qtproject: - echo -e "TEMPLATE = app\nCONFIG -= console app_bundle qt" > $(target).pro - echo -e "SOURCES += $(CFILES) $(ASFILES)" >> $(target).pro - echo -ne "INCLUDEPATH += " >> $(target).pro - echo "$(INCLUDEPATH)" | sed "s!-I!./!g" >> $(target).pro - echo -ne "HEADERS += " >> $(target).pro - find -name "*.h" | tr "\\n" " " >> $(target).pro - echo -ne "\nDEFINES += " >> $(target).pro - echo "$(DEFINES)" | sed "s/-D//g" >> $(target).pro - + @echo [RM] in $(OBJDIR) + @rm -f $(TARGET).elf $(TARGET).bin $(TARGET).hex $(OBJ) $(ASOBJ) $(mapfile).map $(TARGET).lss $(DEPENDENCY_FILES) + @rm -rf $(OBJDIR)/* +# Include dependency files, if available +-include $(DEPENDENCY_FILES)