From b86b0480d530c9d5f40bbe835f120b1c1b563e47 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 8 Jul 2016 17:20:37 +0300 Subject: Speed up compilation by not using recusive make The cleaning is done outside the targets, by checking the requested target name. --- tmk_core/rules.mk | 59 ++++++++++++++++++++----------------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) (limited to 'tmk_core/rules.mk') diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index 352e9314b6..a518fc0c3f 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk @@ -271,23 +271,10 @@ ALL_CPPFLAGS = $(MCUFLAGS) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS) ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS) # Default target. -all: - @$(MAKE) begin - @$(MAKE) gccversion - @$(MAKE) sizebefore - @$(MAKE) clean_list # force clean each time - @$(MAKE) build - @$(MAKE) sizeafter - @$(MAKE) end +all: build sizeafter # Quick make that doesn't clean -quick: - @$(MAKE) begin - @$(MAKE) gccversion - @$(MAKE) sizebefore - @$(MAKE) build - @$(MAKE) sizeafter - @$(MAKE) end +quick: build sizeafter # Change the build target to build a HEX file or a library. build: elf hex @@ -303,13 +290,7 @@ sym: $(BUILD_DIR)/$(TARGET).sym LIBNAME=lib$(TARGET).a lib: $(LIBNAME) - - -# Eye candy. -# AVR Studio 3.x does not check make's exit code but relies on -# the following magic strings to be generated by the compile job. -begin: - @$(SECHO) $(MSG_BEGIN) +check_submodule: git submodule status --recursive | \ while IFS= read -r x; do \ case "$$x" in \ @@ -318,10 +299,6 @@ begin: esac \ done -end: - @$(SECHO) $(MSG_END) - - # Display size of file. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf @@ -331,7 +308,7 @@ sizebefore: @if test -f $(TARGET).hex; then $(SECHO) $(MSG_SIZE_BEFORE); $(SILENT) || $(HEXSIZE); \ 2>/dev/null; $(SECHO); fi -sizeafter: +sizeafter: $(BUILD_DIR)/$(TARGET).hex @if test -f $(TARGET).hex; then $(SECHO); $(SECHO) $(MSG_SIZE_AFTER); $(SILENT) || $(HEXSIZE); \ 2>/dev/null; $(SECHO); fi # test file sizes eventually @@ -386,9 +363,9 @@ gccversion : # Link: create ELF output file from object files. .SECONDARY : $(BUILD_DIR)/$(TARGET).elf .PRECIOUS : $(OBJ) -%.elf: $(OBJ) +%.elf: gccversion sizebefore check_submodule $(OBJ) @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD) - $(eval CMD=$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)) + $(eval CMD=$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)) @$(BUILD_CMD) # Compile: create object files from C source files. @@ -429,14 +406,7 @@ $(OBJDIR)/%.o : %.S $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@ # Target: clean project. -clean: begin clean_list end - -clean_list : - @$(REMOVE) -r $(BUILD_DIR) - @$(REMOVE) -r $(TOP_DIR)/$(BUILD_DIR) - @$(REMOVE) -r $(KEYBOARD_PATH)/$(BUILD_DIR) - @if $$SUBPROJECT; then $(REMOVE) -r $(SUBPROJECT_PATH)/$(BUILD_DIR); fi - @$(REMOVE) -r $(KEYMAP_PATH)/$(BUILD_DIR) +clean: show_path: @echo VPATH=$(VPATH) @@ -496,6 +466,19 @@ all-keymaps-%: all-keymaps: all-keymaps-all +GOAL=$(MAKECMDGOALS) +ifeq ($(MAKECMDGOALS),) +GOAL = all +endif +CLEANING_GOALS=clean clean_list all +ifneq ($(findstring $(GOAL),$(CLEANING_GOALS)),) +$(shell $(REMOVE) -r $(BUILD_DIR) 2>/dev/null) +$(shell $(REMOVE) -r $(TOP_DIR)/$(BUILD_DIR)) +$(shell $(REMOVE) -r $(KEYBOARD_PATH)/$(BUILD_DIR)) +$(shell if $$SUBPROJECT; then $(REMOVE) -r $(SUBPROJECT_PATH)/$(BUILD_DIR); fi) +$(shell $(REMOVE) -r $(KEYMAP_PATH)/$(BUILD_DIR)) +endif + # Create build directory $(shell mkdir $(BUILD_DIR) 2>/dev/null) @@ -508,7 +491,7 @@ $(shell mkdir $(OBJDIR) 2>/dev/null) # Listing of phony targets. -.PHONY : all quick begin finish end sizebefore sizeafter gccversion \ +.PHONY : all quick finish sizebefore sizeafter gccversion \ build elf hex eep lss sym coff extcoff \ clean clean_list debug gdb-config show_path \ program teensy dfu flip dfu-ee flip-ee dfu-start \ -- cgit v1.2.3 From 1e3db59097f8c396d69179fdd66ef0131a6ba80d Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 8 Jul 2016 18:18:33 +0300 Subject: Fix the link target --- tmk_core/rules.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tmk_core/rules.mk') diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index a518fc0c3f..543d3da8a0 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk @@ -365,7 +365,7 @@ gccversion : .PRECIOUS : $(OBJ) %.elf: gccversion sizebefore check_submodule $(OBJ) @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD) - $(eval CMD=$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)) + $(eval CMD=$(CC) $(ALL_CFLAGS) $(filter-out gccversion sizebefore check_submodule,$^) --output $@ $(LDFLAGS)) @$(BUILD_CMD) # Compile: create object files from C source files. -- cgit v1.2.3 From e8e300d5c4dd05b806869b648b93feeff1f8a7dc Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 8 Jul 2016 22:59:09 +0300 Subject: Fix name of makefile dep files The files can't start with a .dot, as the wildcard function wont find them. So this is fixed by removing the BUILD_DIR from the name. --- tmk_core/rules.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tmk_core/rules.mk') diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index 543d3da8a0..8d843cc983 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk @@ -260,7 +260,7 @@ LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst # Compiler flags to generate dependency files. #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d -GENDEPFLAGS = -MMD -MP -MF $(BUILD_DIR)/.dep/$(subst /,_,$@).d +GENDEPFLAGS = -MMD -MP -MF $(BUILD_DIR)/.dep/$(subst /,_,$(subst $(BUILD_DIR)/,,$@)).d # Combine all necessary flags and optional flags. -- cgit v1.2.3 From 6911ead027202da981862c9259ff4d962d51a519 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 8 Jul 2016 23:19:48 +0300 Subject: Use order only prerequisites to avoid re-linking The prerequisites at the start of the build process are order-only so that the trget don't link again. Also added as a dependency to the compilation to force the messages to be printed at the start --- tmk_core/rules.mk | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'tmk_core/rules.mk') diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index 8d843cc983..f13351ea19 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk @@ -360,49 +360,51 @@ gccversion : $(eval CMD=$(AR) $@ $(OBJ) ) @$(BUILD_CMD) +BEGIN = gccversion check_submodule sizebefore + # Link: create ELF output file from object files. .SECONDARY : $(BUILD_DIR)/$(TARGET).elf .PRECIOUS : $(OBJ) -%.elf: gccversion sizebefore check_submodule $(OBJ) +%.elf: $(OBJ) | $(BEGIN) @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD) - $(eval CMD=$(CC) $(ALL_CFLAGS) $(filter-out gccversion sizebefore check_submodule,$^) --output $@ $(LDFLAGS)) + $(eval CMD=$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)) @$(BUILD_CMD) # Compile: create object files from C source files. -$(OBJDIR)/%.o : %.c +$(OBJDIR)/%.o : %.c | $(BEGIN) @mkdir -p $(@D) @$(SILENT) || printf "$(MSG_COMPILING) $<" | $(AWK_CMD) $(eval CMD=$(CC) -c $(ALL_CFLAGS) $< -o $@) @$(BUILD_CMD) # Compile: create object files from C++ source files. -$(OBJDIR)/%.o : %.cpp +$(OBJDIR)/%.o : %.cpp | $(BEGIN) @mkdir -p $(@D) @$(SILENT) || printf "$(MSG_COMPILING_CPP) $<" | $(AWK_CMD) $(eval CMD=$(CC) -c $(ALL_CPPFLAGS) $< -o $@) @$(BUILD_CMD) # Compile: create assembler files from C source files. -%.s : %.c +%.s : %.c | $(BEGIN) @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD) $(eval CMD=$(CC) -S $(ALL_CFLAGS) $< -o $@) @$(BUILD_CMD) # Compile: create assembler files from C++ source files. -%.s : %.cpp +%.s : %.cpp | $(BEGIN) @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD) $(eval CMD=$(CC) -S $(ALL_CPPFLAGS) $< -o $@) @$(BUILD_CMD) # Assemble: create object files from assembler source files. -$(OBJDIR)/%.o : %.S +$(OBJDIR)/%.o : %.S | $(BEGIN) @mkdir -p $(@D) @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD) $(eval CMD=$(CC) -c $(ALL_ASFLAGS) $< -o $@) @$(BUILD_CMD) # Create preprocessed source for use in sending a bug report. -%.i : %.c +%.i : %.c | $(BEGIN) $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@ # Target: clean project. @@ -492,7 +494,7 @@ $(shell mkdir $(OBJDIR) 2>/dev/null) # Listing of phony targets. .PHONY : all quick finish sizebefore sizeafter gccversion \ -build elf hex eep lss sym coff extcoff \ +build elf hex eep lss sym coff extcoff check_submodule \ clean clean_list debug gdb-config show_path \ program teensy dfu flip dfu-ee flip-ee dfu-start \ all-keyboards-defaults all-keyboards all-keymaps \ -- cgit v1.2.3