summaryrefslogtreecommitdiff
path: root/tmk_core/rules.mk
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/rules.mk')
-rw-r--r--tmk_core/rules.mk75
1 files changed, 30 insertions, 45 deletions
diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk
index 352e9314b6..f13351ea19 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.
@@ -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
@@ -383,60 +360,55 @@ 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: $(OBJ)
+%.elf: $(OBJ) | $(BEGIN)
@$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD)
$(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.
-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 +468,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,8 +493,8 @@ $(shell mkdir $(OBJDIR) 2>/dev/null)
# Listing of phony targets.
-.PHONY : all quick begin finish end sizebefore sizeafter gccversion \
-build elf hex eep lss sym coff extcoff \
+.PHONY : all quick finish sizebefore sizeafter gccversion \
+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 \