summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-07-30 18:16:34 +0300
committerFred Sundvik <fsundvik@gmail.com>2016-07-31 13:36:30 +0300
commite58e9af2ab2c0e66a8456b48d46f4d71a66af27a (patch)
tree5d6dd4a50b1ee5b344a9380a095edb2c2628b201
parentabdf42573ac6e01432fdf69847f4259540c1a38d (diff)
More reliable .d file generation
Also generated inside the obj dir instead of separate deps folder.
-rw-r--r--tmk_core/rules.mk24
1 files changed, 16 insertions, 8 deletions
diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk
index f6819d7c31..8acb439321 100644
--- a/tmk_core/rules.mk
+++ b/tmk_core/rules.mk
@@ -278,7 +278,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 /,_,$(subst $(BUILD_DIR)/,,$@)).d
+GENDEPFLAGS = -MMD -MP -MF $(patsubst %.o,%.td,$@)
# Combine all necessary flags and optional flags.
@@ -288,6 +288,8 @@ ALL_CFLAGS = $(MCUFLAGS) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
ALL_CPPFLAGS = $(MCUFLAGS) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
+MOVE_DEP = mv -f $(patsubst %.o,%.td,$@) $(patsubst %.o,%.d,$@)
+
# Default target.
all: build sizeafter
@@ -390,17 +392,17 @@ BEGIN = gccversion check_submodule sizebefore
define GEN_OBJRULE
# Compile: create object files from C source files.
-$1/%.o : %.c | $(BEGIN)
+$1/%.o : %.c $1/%.d | $(BEGIN)
@mkdir -p $$(@D)
@$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD)
- $$(eval CMD=$$(CC) -c $$(ALL_CFLAGS) $$< -o $$@)
+ $$(eval CMD=$$(CC) -c $$(ALL_CFLAGS) $$< -o $$@ && $$(MOVE_DEP))
@$$(BUILD_CMD)
# Compile: create object files from C++ source files.
-$1/%.o : %.cpp | $(BEGIN)
+$1/%.o : %.cpp $1/%.d | $(BEGIN)
@mkdir -p $$(@D)
@$$(SILENT) || printf "$$(MSG_COMPILING_CPP) $$<" | $$(AWK_CMD)
- $$(eval CMD=$$(CC) -c $$(ALL_CPPFLAGS) $$< -o $$@)
+ $$(eval CMD=$$(CC) -c $$(ALL_CPPFLAGS) $$< -o $$@ && $$(MOVE_DEP))
@$(BUILD_CMD)
# Assemble: create object files from assembler source files.
@@ -409,9 +411,15 @@ $1/%.o : %.S | $(BEGIN)
@$(SILENT) || printf "$$(MSG_ASSEMBLING) $$<" | $$(AWK_CMD)
$$(eval CMD=$$(CC) -c $$(ALL_ASFLAGS) $$< -o $$@)
@$$(BUILD_CMD)
-
endef
+# We have to use static rules for the .d files for some reason
+DEPS = $(patsubst %.o,%.d,$(OBJ))
+# Keep the .d files
+.PRECIOUS: $(DEPS)
+# Empty rule to force recompilation if the .d file is missing
+$(DEPS):
+
# Since the object files could be in two different folders, generate
# separate rules for them, rather than having too generic rules
$(eval $(call GEN_OBJRULE,$(OBJDIR)))
@@ -434,7 +442,7 @@ $(eval $(call GEN_OBJRULE,$(KBOBJDIR)))
$(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@
# Target: clean project.
-clean:
+clean:
show_path:
@echo VPATH=$(VPATH)
@@ -515,7 +523,7 @@ $(shell mkdir $(OBJDIR) 2>/dev/null)
$(shell mkdir $(KBOBJDIR) 2>/dev/null)
# Include the dependency files.
--include $(shell mkdir $(BUILD_DIR)/.dep 2>/dev/null) $(wildcard $(BUILD_DIR)/.dep/*)
+-include $(patsubst %.o,%.d,$(OBJ))
# Listing of phony targets.