X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=tmk_core%2Frules.mk;h=53e79ef47a57650b443646dedc14d0d19ba2aa08;hb=bc98b0d9eb5eb1a4df140ab6e2158904e5e100e5;hp=7b2c842ed6042499264df5ced7c321d005c7d08e;hpb=33fbd3be36bf58c6a02fb6b4ae99dc5bca7c8e58;p=qmk_firmware.git diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index 7b2c842ed..53e79ef47 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk @@ -21,13 +21,14 @@ VPATH_SRC := $(VPATH) vpath %.c $(VPATH_SRC) vpath %.h $(VPATH_SRC) vpath %.cpp $(VPATH_SRC) +vpath %.cc $(VPATH_SRC) vpath %.hpp $(VPATH_SRC) vpath %.S $(VPATH_SRC) VPATH := # Convert all SRC to OBJ define OBJ_FROM_SRC -$(patsubst %.c,$1/%.o,$(patsubst %.cpp,$1/%.o,$(patsubst %.S,$1/%.o,$($1_SRC)))) +$(patsubst %.c,$1/%.o,$(patsubst %.cpp,$1/%.o,$(patsubst %.cc,$1/%.o,$(patsubst %.S,$1/%.o,$($1_SRC))))) endef $(foreach OUTPUT,$(OUTPUTS),$(eval $(OUTPUT)_OBJ +=$(call OBJ_FROM_SRC,$(OUTPUT)))) @@ -91,6 +92,9 @@ endif endif CFLAGS += -Wall CFLAGS += -Wstrict-prototypes +ifneq ($(strip $(ALLOW_WARNINGS)), yes) + CFLAGS += -Werror +endif #CFLAGS += -mshort-calls #CFLAGS += -fno-unit-at-a-time #CFLAGS += -Wundef @@ -98,9 +102,6 @@ CFLAGS += -Wstrict-prototypes #CFLAGS += -Wsign-compare CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst) CFLAGS += $(CSTANDARD) -ifdef CONFIG_H - CFLAGS += -include $(CONFIG_H) -endif #---------------- Compiler Options C++ ---------------- @@ -117,6 +118,9 @@ CPPFLAGS += -O$(OPT) CPPFLAGS += -w CPPFLAGS += -Wall CPPFLAGS += -Wundef +ifneq ($(strip $(ALLOW_WARNINGS)), yes) + CPPFLAGS += -Werror +endif #CPPFLAGS += -mshort-calls #CPPFLAGS += -fno-unit-at-a-time #CPPFLAGS += -Wstrict-prototypes @@ -124,10 +128,6 @@ CPPFLAGS += -Wundef #CPPFLAGS += -Wsign-compare CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst) #CPPFLAGS += $(CSTANDARD) -ifdef CONFIG_H - CPPFLAGS += -include $(CONFIG_H) -endif - #---------------- Assembler Options ---------------- # -Wa,...: tell GCC to pass this to the assembler. @@ -140,9 +140,6 @@ endif # dump that will be displayed for a given single line of source input. ASFLAGS += $(ADEFS) ASFLAGS += -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100 -ifdef CONFIG_H - ASFLAGS += -include $(CONFIG_H) -endif #---------------- Library Options ---------------- # Minimalistic printf version @@ -170,6 +167,7 @@ SCANF_LIB = MATH_LIB = -lm +CREATE_MAP ?= yes #---------------- Linker Options ---------------- @@ -180,7 +178,10 @@ MATH_LIB = -lm # Comennt out "--relax" option to avoid a error such: # (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12' # -LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref + +ifeq ($(CREATE_MAP),yes) + LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref +endif #LDFLAGS += -Wl,--relax LDFLAGS += $(EXTMEMOPTS) LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS)) @@ -212,14 +213,6 @@ ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS) MOVE_DEP = mv -f $(patsubst %.o,%.td,$@) $(patsubst %.o,%.d,$@) -# Default target. -all: build sizeafter - -# Change the build target to build a HEX file or a library. -build: elf hex -#build: elf hex eep lss sym -#build: lib - elf: $(BUILD_DIR)/$(TARGET).elf hex: $(BUILD_DIR)/$(TARGET).hex @@ -254,8 +247,8 @@ gccversion : $(eval CMD=$(HEX) $< $@) @$(BUILD_CMD) @if $(AUTOGEN); then \ - $(SILENT) || printf "Copying $(TARGET).hex to keymaps/$(KEYMAP)/$(KEYBOARD)_$(KEYMAP).hex\n"; \ - $(COPY) $@ $(KEYMAP_PATH)/$(KEYBOARD)_$(KEYMAP).hex; \ + $(SILENT) || printf "Copying $(TARGET).hex to keymaps/$(KEYMAP)/$(TARGET).hex\n"; \ + $(COPY) $@ $(KEYMAP_PATH)/$(TARGET).hex; \ else \ $(COPY) $@ $(TARGET).hex; \ fi @@ -296,10 +289,12 @@ BEGIN = gccversion sizebefore define GEN_OBJRULE $1_INCFLAGS := $$(patsubst %,-I%,$$($1_INC)) -$1_CFLAGS = $$(ALL_CFLAGS) $$($1_DEFS) $$($1_INCFLAGS) -$1_CPPFLAGS= $$(ALL_CPPFLAGS) $$($1_DEFS) $$($1_INCFLAGS) -$1_ASFLAGS= $$(ALL_ASFLAGS) $$($1_DEFS) $$($1_INCFLAGS) -$$(info $$($1_INCFLAGS)) +ifdef $1_CONFIG +$1_CONFIG_FLAGS += $$(patsubst %,-include %,$$($1_CONFIG)) +endif +$1_CFLAGS = $$(ALL_CFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) +$1_CPPFLAGS= $$(ALL_CPPFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) +$1_ASFLAGS= $$(ALL_ASFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) # Compile: create object files from C source files. $1/%.o : %.c $1/%.d $1/cflags.txt $1/compiler.txt | $(BEGIN) @@ -313,7 +308,13 @@ $1/%.o : %.cpp $1/%.d $1/cppflags.txt $1/compiler.txt | $(BEGIN) @mkdir -p $$(@D) @$$(SILENT) || printf "$$(MSG_COMPILING_CPP) $$<" | $$(AWK_CMD) $$(eval CMD=$$(CC) -c $$($1_CPPFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) - @$(BUILD_CMD) + @$$(BUILD_CMD) + +$1/%.o : %.cc $1/%.d $1/cppflags.txt $1/compiler.txt | $(BEGIN) + @mkdir -p $$(@D) + @$$(SILENT) || printf "$$(MSG_COMPILING_CPP) $$<" | $$(AWK_CMD) + $$(eval CMD=$$(CC) -c $$($1_CPPFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) + @$$(BUILD_CMD) # Assemble: create object files from assembler source files. $1/%.o : %.S $1/asflags.txt $1/compiler.txt | $(BEGIN) @@ -337,11 +338,13 @@ $1/compiler.txt: $1/force $$(CC) --version | cmp -s - $$@ || $$(CC) --version > $$@ endef +.PRECIOUS: $(MASTER_OUTPUT)/obj.txt $(MASTER_OUTPUT)/obj.txt: $(MASTER_OUTPUT)/force - echo '$(OBJ)' | cmp -s - $$@ || echo '$(OBJ)' > $$@ + echo '$(OBJ)' | cmp -s - $@ || echo '$(OBJ)' > $@ +.PRECIOUS: $(MASTER_OUTPUT)/ldflags.txt $(MASTER_OUTPUT)/ldflags.txt: $(MASTER_OUTPUT)/force - echo '$(LDFLAGS)' | cmp -s - $$@ || echo '$(LDFLAGS)' > $$@ + echo '$(LDFLAGS)' | cmp -s - $@ || echo '$(LDFLAGS)' > $@ # We have to use static rules for the .d files for some reason @@ -360,8 +363,7 @@ $(foreach OUTPUT,$(OUTPUTS),$(eval $(call GEN_OBJRULE,$(OUTPUT)))) # Target: clean project. clean: - $(REMOVE) -r $(OBJDIR) 2>/dev/null - $(REMOVE) -r $(KBOBJDIR) 2>/dev/null + $(foreach OUTPUT,$(OUTPUTS), $(REMOVE) -r $(OUTPUT) 2>/dev/null) $(REMOVE) $(BUILD_DIR)/$(TARGET).* show_path: @@ -370,17 +372,17 @@ show_path: @echo OBJ=$(OBJ) # Create build directory -$(shell mkdir $(BUILD_DIR) 2>/dev/null) +$(shell mkdir -p $(BUILD_DIR) 2>/dev/null) # Create object files directory -$(eval $(foreach OUTPUT,$(OUTPUTS),$(shell mkdir $(OUTPUT) 2>/dev/null))) +$(eval $(foreach OUTPUT,$(OUTPUTS),$(shell mkdir -p $(OUTPUT) 2>/dev/null))) # Include the dependency files. -include $(patsubst %.o,%.d,$(OBJ)) # Listing of phony targets. -.PHONY : all finish sizebefore sizeafter gccversion \ -build elf hex eep lss sym coff extcoff \ +.PHONY : all finish sizebefore sizeafter qmkversion \ +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 \ No newline at end of file +program teensy dfu flip dfu-ee flip-ee dfu-start