aboutsummaryrefslogtreecommitdiff
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)
downloadqmk_firmware-e58e9af2ab2c0e66a8456b48d46f4d71a66af27a.tar.gz
qmk_firmware-e58e9af2ab2c0e66a8456b48d46f4d71a66af27a.zip
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 f6819d7c3..8acb43932 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
278 278
279# Compiler flags to generate dependency files. 279# Compiler flags to generate dependency files.
280#GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d 280#GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
281GENDEPFLAGS = -MMD -MP -MF $(BUILD_DIR)/.dep/$(subst /,_,$(subst $(BUILD_DIR)/,,$@)).d 281GENDEPFLAGS = -MMD -MP -MF $(patsubst %.o,%.td,$@)
282 282
283 283
284# Combine all necessary flags and optional flags. 284# Combine all necessary flags and optional flags.
@@ -288,6 +288,8 @@ ALL_CFLAGS = $(MCUFLAGS) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
288ALL_CPPFLAGS = $(MCUFLAGS) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS) 288ALL_CPPFLAGS = $(MCUFLAGS) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
289ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS) 289ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
290 290
291MOVE_DEP = mv -f $(patsubst %.o,%.td,$@) $(patsubst %.o,%.d,$@)
292
291# Default target. 293# Default target.
292all: build sizeafter 294all: build sizeafter
293 295
@@ -390,17 +392,17 @@ BEGIN = gccversion check_submodule sizebefore
390 392
391define GEN_OBJRULE 393define GEN_OBJRULE
392# Compile: create object files from C source files. 394# Compile: create object files from C source files.
393$1/%.o : %.c | $(BEGIN) 395$1/%.o : %.c $1/%.d | $(BEGIN)
394 @mkdir -p $$(@D) 396 @mkdir -p $$(@D)
395 @$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD) 397 @$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD)
396 $$(eval CMD=$$(CC) -c $$(ALL_CFLAGS) $$< -o $$@) 398 $$(eval CMD=$$(CC) -c $$(ALL_CFLAGS) $$< -o $$@ && $$(MOVE_DEP))
397 @$$(BUILD_CMD) 399 @$$(BUILD_CMD)
398 400
399# Compile: create object files from C++ source files. 401# Compile: create object files from C++ source files.
400$1/%.o : %.cpp | $(BEGIN) 402$1/%.o : %.cpp $1/%.d | $(BEGIN)
401 @mkdir -p $$(@D) 403 @mkdir -p $$(@D)
402 @$$(SILENT) || printf "$$(MSG_COMPILING_CPP) $$<" | $$(AWK_CMD) 404 @$$(SILENT) || printf "$$(MSG_COMPILING_CPP) $$<" | $$(AWK_CMD)
403 $$(eval CMD=$$(CC) -c $$(ALL_CPPFLAGS) $$< -o $$@) 405 $$(eval CMD=$$(CC) -c $$(ALL_CPPFLAGS) $$< -o $$@ && $$(MOVE_DEP))
404 @$(BUILD_CMD) 406 @$(BUILD_CMD)
405 407
406# Assemble: create object files from assembler source files. 408# Assemble: create object files from assembler source files.
@@ -409,9 +411,15 @@ $1/%.o : %.S | $(BEGIN)
409 @$(SILENT) || printf "$$(MSG_ASSEMBLING) $$<" | $$(AWK_CMD) 411 @$(SILENT) || printf "$$(MSG_ASSEMBLING) $$<" | $$(AWK_CMD)
410 $$(eval CMD=$$(CC) -c $$(ALL_ASFLAGS) $$< -o $$@) 412 $$(eval CMD=$$(CC) -c $$(ALL_ASFLAGS) $$< -o $$@)
411 @$$(BUILD_CMD) 413 @$$(BUILD_CMD)
412
413endef 414endef
414 415
416# We have to use static rules for the .d files for some reason
417DEPS = $(patsubst %.o,%.d,$(OBJ))
418# Keep the .d files
419.PRECIOUS: $(DEPS)
420# Empty rule to force recompilation if the .d file is missing
421$(DEPS):
422
415# Since the object files could be in two different folders, generate 423# Since the object files could be in two different folders, generate
416# separate rules for them, rather than having too generic rules 424# separate rules for them, rather than having too generic rules
417$(eval $(call GEN_OBJRULE,$(OBJDIR))) 425$(eval $(call GEN_OBJRULE,$(OBJDIR)))
@@ -434,7 +442,7 @@ $(eval $(call GEN_OBJRULE,$(KBOBJDIR)))
434 $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@ 442 $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@
435 443
436# Target: clean project. 444# Target: clean project.
437clean: 445clean:
438 446
439show_path: 447show_path:
440 @echo VPATH=$(VPATH) 448 @echo VPATH=$(VPATH)
@@ -515,7 +523,7 @@ $(shell mkdir $(OBJDIR) 2>/dev/null)
515$(shell mkdir $(KBOBJDIR) 2>/dev/null) 523$(shell mkdir $(KBOBJDIR) 2>/dev/null)
516 524
517# Include the dependency files. 525# Include the dependency files.
518-include $(shell mkdir $(BUILD_DIR)/.dep 2>/dev/null) $(wildcard $(BUILD_DIR)/.dep/*) 526-include $(patsubst %.o,%.d,$(OBJ))
519 527
520 528
521# Listing of phony targets. 529# Listing of phony targets.