]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - tmk_core/rules.mk
several improvements for mitosis:datagrok (#1960)
[qmk_firmware.git] / tmk_core / rules.mk
index 9f6d8d9dfd35f99986627857f68ed3dab881e632..53e79ef47a57650b443646dedc14d0d19ba2aa08 100644 (file)
@@ -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))))
 
@@ -49,13 +50,6 @@ OPT = s
 AUTOGEN ?= false
 
 
-# List any extra directories to look for include files here.
-#     Each directory must be seperated by a space.
-#     Use forward slashes for directory separators.
-#     For a directory that has spaces, enclose it in quotes.
-EXTRAINCDIRS += $(subst :, ,$(VPATH_SRC))
-
-
 # Compiler flag to set the C Standard level.
 #     c89   = "ANSI" C
 #     gnu89 = c89 plus GCC extensions
@@ -98,17 +92,16 @@ 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
 #CFLAGS += -Wunreachable-code
 #CFLAGS += -Wsign-compare
 CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
-CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
 CFLAGS += $(CSTANDARD)
-ifdef CONFIG_H
-    CFLAGS += -include $(CONFIG_H)
-endif
 
 
 #---------------- Compiler Options C++ ----------------
@@ -125,18 +118,16 @@ 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
 #CPPFLAGS += -Wunreachable-code
 #CPPFLAGS += -Wsign-compare
 CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
-CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
 #CPPFLAGS += $(CSTANDARD)
-ifdef CONFIG_H
-    CPPFLAGS += -include $(CONFIG_H)
-endif
-
 
 #---------------- Assembler Options ----------------
 #  -Wa,...:   tell GCC to pass this to the assembler.
@@ -149,10 +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
-ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
-ifdef CONFIG_H
-    ASFLAGS += -include $(CONFIG_H)
-endif
 
 #---------------- Library Options ----------------
 # Minimalistic printf version
@@ -180,6 +167,7 @@ SCANF_LIB =
 
 
 MATH_LIB = -lm
+CREATE_MAP ?= yes
 
 
 #---------------- Linker Options ----------------
@@ -190,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))
@@ -222,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
@@ -264,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
@@ -305,9 +288,13 @@ BEGIN = gccversion sizebefore
        
 
 define GEN_OBJRULE
-$1_CFLAGS = $$(ALL_CFLAGS) $$($1_DEFS)
-$1_CPPFLAGS= $$(ALL_CPPFLAGS) $$($1_DEFS)
-$1_ASFLAGS= $$(ALL_ASFLAGS) $$($1_DEFS)
+$1_INCFLAGS := $$(patsubst %,-I%,$$($1_INC))
+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)
@@ -321,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)
@@ -345,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
@@ -368,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:
@@ -378,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