From 9c0f97e12dd807b4efff68ab7a94364bbdf8a5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 1 Sep 2019 12:51:06 +0200 Subject: [PATCH] Build System Changes * Compiler now puts all objects in a separate directory. * Add support for dependency files * Add obj directory to .gitignore --- .gitignore | 2 +- Makefile | 36 +++++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 7c2174b..f53b0c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *.elf -*.c.o memmap.map +obj/ diff --git a/Makefile b/Makefile index c686526..889a0f5 100644 --- a/Makefile +++ b/Makefile @@ -2,12 +2,20 @@ #CPU: STM32F030 #Compiler: arm-none-eabi ##################################################################################### + +ifneq ($(VERBOSE),true) +QUIET=@ +else +QUIET= +endif + + #Add Files and Folders below######################################################### CFILES = main.c syscalls/syscalls.c setup/system_init.c startup/startup_stm32f0xx.c ASFILES = INCLUDEPATH = -Iinclude -Iinclude/cmsis - +OBJDIR=obj target = project LIBRARYPATH = -Lstartup LIBRARIES = @@ -35,8 +43,8 @@ CFLAGS += -mfloat-abi=soft -nostartfiles -Wall -g #################################################################################### -OBJ = $(CFILES:%.c=%.c.o) -ASOBJ = $(ASFILES:%.S=%.S.o) +OBJ = $(CFILES:%.c=$(OBJDIR)/%.c.o) +ASOBJ = $(ASFILES:%.S=$(OBJDIR)/%.S.o) default: $(target).elf @@ -49,15 +57,22 @@ binary: $(target).bin $(target).hex #Linking $(target).elf: $(OBJ) $(ASOBJ) - $(CC) $(LFLAGS) $(LIBRARYPATH) -o $@ $^ $(LIBRARIES) - $(SIZE) $@ + @echo Linking $@ + $(QUIET)$(CC) $(LFLAGS) $(LIBRARYPATH) -o $@ $^ $(LIBRARIES) + $(QUIET)$(SIZE) $@ #Compiling -%.c.o: %.c - $(CC) $(CFLAGS) $(INCLUDEPATH) $(DEFINES) -o $@ $< +$(OBJ): + @echo Compiling $@ + $(eval OUTPATH=$(dir $@)) + @mkdir -p $(OUTPATH) + $(QUIET)$(CC) $(CFLAGS) -MMD -MT $@ $(INCLUDEPATH) $(DEFINES) -o $@ $(@:$(OBJDIR)/%.c.o=%.c) -%.S.o: %.S - $(CC) $(CFLAGS) $(INCLUDEPATH) $(DEFINES) -o $@ $< +$(ASOBJ): + @echo Compiling $@ + $(eval OUTPATH=$(dir $@)) + @mkdir -p $(OUTPATH) + $(QUIET)$(CC) $(CFLAGS) -MMD -MT $@ $(INCLUDEPATH) $(DEFINES) -o $@ $(@:$(OBJDIR)/%.S.o=%.S) .PHONY: qtproject clean mrproper objcopy disassemble @@ -71,6 +86,8 @@ mrproper: clean: rm -f $(target).elf $(target).bin $(target).hex $(OBJ) $(ASOBJ) $(mapfile).map $(target).lss + rm -rfv $(OBJDIR) + qtproject: echo -e "TEMPLATE = app\nCONFIG -= console app_bundle qt" > $(target).pro echo -e "SOURCES += $(CFILES) $(ASFILES)" >> $(target).pro @@ -81,4 +98,5 @@ qtproject: echo -ne "\nDEFINES += " >> $(target).pro echo "$(DEFINES)" | sed "s/-D//g" >> $(target).pro +-include $(CFILES:%.c=$(OBJDIR)/%.c.d) $(ASFILES:%.S=($OBJDIR)/%.S.d)