Update makefile to use dependenccy files and create obj folder

This commit is contained in:
Mario Hüttel 2022-08-01 23:44:55 +02:00
parent 3861b82515
commit 6d3afeb075
2 changed files with 31 additions and 30 deletions

2
.gitignore vendored
View File

@ -1,4 +1,5 @@
project.elf
*.lss
*.o
*.map
*.bin
@ -6,3 +7,4 @@ project.elf
*.user
*.user*
*.user.*
obj/*

View File

@ -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)