diff options
Diffstat (limited to 'tmk_core/rules.mk')
| -rw-r--r-- | tmk_core/rules.mk | 125 |
1 files changed, 40 insertions, 85 deletions
diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index e8e3de571..9f6d8d9df 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk | |||
| @@ -25,6 +25,18 @@ vpath %.hpp $(VPATH_SRC) | |||
| 25 | vpath %.S $(VPATH_SRC) | 25 | vpath %.S $(VPATH_SRC) |
| 26 | VPATH := | 26 | VPATH := |
| 27 | 27 | ||
| 28 | # Convert all SRC to OBJ | ||
| 29 | define OBJ_FROM_SRC | ||
| 30 | $(patsubst %.c,$1/%.o,$(patsubst %.cpp,$1/%.o,$(patsubst %.S,$1/%.o,$($1_SRC)))) | ||
| 31 | endef | ||
| 32 | $(foreach OUTPUT,$(OUTPUTS),$(eval $(OUTPUT)_OBJ +=$(call OBJ_FROM_SRC,$(OUTPUT)))) | ||
| 33 | |||
| 34 | # Define a list of all objects | ||
| 35 | OBJ := $(foreach OUTPUT,$(OUTPUTS),$($(OUTPUT)_OBJ)) | ||
| 36 | |||
| 37 | MASTER_OUTPUT := $(firstword $(OUTPUTS)) | ||
| 38 | |||
| 39 | |||
| 28 | 40 | ||
| 29 | # Output format. (can be srec, ihex, binary) | 41 | # Output format. (can be srec, ihex, binary) |
| 30 | FORMAT = ihex | 42 | FORMAT = ihex |
| @@ -53,17 +65,18 @@ CSTANDARD = -std=gnu99 | |||
| 53 | 65 | ||
| 54 | 66 | ||
| 55 | # Place -D or -U options here for C sources | 67 | # Place -D or -U options here for C sources |
| 56 | CDEFS += $(OPT_DEFS) | 68 | #CDEFS += |
| 57 | 69 | ||
| 58 | 70 | ||
| 59 | # Place -D or -U options here for ASM sources | 71 | # Place -D or -U options here for ASM sources |
| 60 | ADEFS += $(OPT_DEFS) | 72 | #ADEFS += |
| 61 | 73 | ||
| 62 | 74 | ||
| 63 | # Place -D or -U options here for C++ sources | 75 | # Place -D or -U options here for C++ sources |
| 64 | #CPPDEFS += -D__STDC_LIMIT_MACROS | 76 | #CPPDEFS += -D__STDC_LIMIT_MACROS |
| 65 | #CPPDEFS += -D__STDC_CONSTANT_MACROS | 77 | #CPPDEFS += -D__STDC_CONSTANT_MACROS |
| 66 | CPPDEFS += $(OPT_DEFS) | 78 | #CPPDEFS += |
| 79 | |||
| 67 | 80 | ||
| 68 | 81 | ||
| 69 | 82 | ||
| @@ -134,7 +147,8 @@ endif | |||
| 134 | # files -- see avr-libc docs [FIXME: not yet described there] | 147 | # files -- see avr-libc docs [FIXME: not yet described there] |
| 135 | # -listing-cont-lines: Sets the maximum number of continuation lines of hex | 148 | # -listing-cont-lines: Sets the maximum number of continuation lines of hex |
| 136 | # dump that will be displayed for a given single line of source input. | 149 | # dump that will be displayed for a given single line of source input. |
| 137 | ASFLAGS += $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100 | 150 | ASFLAGS += $(ADEFS) |
| 151 | ASFLAGS += -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100 | ||
| 138 | ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) | 152 | ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) |
| 139 | ifdef CONFIG_H | 153 | ifdef CONFIG_H |
| 140 | ASFLAGS += -include $(CONFIG_H) | 154 | ASFLAGS += -include $(CONFIG_H) |
| @@ -193,48 +207,6 @@ COPY = cp | |||
| 193 | WINSHELL = cmd | 207 | WINSHELL = cmd |
| 194 | SECHO = $(SILENT) || echo | 208 | SECHO = $(SILENT) || echo |
| 195 | 209 | ||
| 196 | # Define Messages | ||
| 197 | # English | ||
| 198 | MSG_ERRORS_NONE = Errors: none | ||
| 199 | MSG_BEGIN = -------- begin -------- | ||
| 200 | MSG_END = -------- end -------- | ||
| 201 | MSG_SIZE_BEFORE = Size before: | ||
| 202 | MSG_SIZE_AFTER = Size after: | ||
| 203 | MSG_COFF = Converting to AVR COFF: | ||
| 204 | MSG_EXTENDED_COFF = Converting to AVR Extended COFF: | ||
| 205 | MSG_FLASH = Creating load file for Flash: | ||
| 206 | MSG_EEPROM = Creating load file for EEPROM: | ||
| 207 | MSG_BIN = Creating binary load file for Flash: | ||
| 208 | MSG_EXTENDED_LISTING = Creating Extended Listing: | ||
| 209 | MSG_SYMBOL_TABLE = Creating Symbol Table: | ||
| 210 | MSG_LINKING = Linking: | ||
| 211 | MSG_COMPILING = Compiling: | ||
| 212 | MSG_COMPILING_CPP = Compiling: | ||
| 213 | MSG_ASSEMBLING = Assembling: | ||
| 214 | MSG_CLEANING = Cleaning project: | ||
| 215 | MSG_CREATING_LIBRARY = Creating library: | ||
| 216 | MSG_SUBMODULE_DIRTY = $(WARN_COLOR)WARNING:$(NO_COLOR)\n \ | ||
| 217 | Some git sub-modules are out of date or modified, please consider runnning:$(BOLD)\n\ | ||
| 218 | git submodule sync --recursive\n\ | ||
| 219 | git submodule update --init --recursive$(NO_COLOR)\n\n\ | ||
| 220 | You can ignore this warning if you are not compiling any ChibiOS keyboards,\n\ | ||
| 221 | or if you have modified the ChibiOS libraries yourself. \n\n | ||
| 222 | |||
| 223 | |||
| 224 | # Define all object files. | ||
| 225 | OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC)))) | ||
| 226 | # The files in the lib folder are shared between all keymaps, so generate that folder name by removing | ||
| 227 | # the keymap from the name | ||
| 228 | KBOBJDIR=$(subst _$(KEYMAP),,$(OBJDIR)) | ||
| 229 | # And fixup the object files to match | ||
| 230 | LIBOBJ = $(foreach v,$(OBJ),$(if $(findstring /lib/,$v),$v)) | ||
| 231 | NONLIBOBJ := $(filter-out $(LIBOBJ),$(OBJ)) | ||
| 232 | LIBOBJ := $(subst _$(KEYMAP)/,/,$(LIBOBJ)) | ||
| 233 | OBJ := $(LIBOBJ) $(NONLIBOBJ) | ||
| 234 | |||
| 235 | # Define all listing files. | ||
| 236 | LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst %.S,$(OBJDIR)/%.lst,$(SRC)))) | ||
| 237 | |||
| 238 | 210 | ||
| 239 | # Compiler flags to generate dependency files. | 211 | # Compiler flags to generate dependency files. |
| 240 | #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d | 212 | #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d |
| @@ -320,68 +292,66 @@ gccversion : | |||
| 320 | $(eval CMD=$(BIN) $< $@ || exit 0) | 292 | $(eval CMD=$(BIN) $< $@ || exit 0) |
| 321 | @$(BUILD_CMD) | 293 | @$(BUILD_CMD) |
| 322 | 294 | ||
| 323 | # Create library from object files. | ||
| 324 | .SECONDARY : $(BUILD_DIR)/$(TARGET).a | ||
| 325 | .PRECIOUS : $(OBJ) | ||
| 326 | %.a: $(OBJ) | ||
| 327 | @$(SILENT) || printf "$(MSG_CREATING_LIBRARY) $@" | $(AWK_CMD) | ||
| 328 | $(eval CMD=$(AR) $@ $(OBJ) ) | ||
| 329 | @$(BUILD_CMD) | ||
| 330 | |||
| 331 | BEGIN = gccversion sizebefore | 295 | BEGIN = gccversion sizebefore |
| 332 | 296 | ||
| 333 | # Link: create ELF output file from object files. | 297 | # Link: create ELF output file from object files. |
| 334 | .SECONDARY : $(BUILD_DIR)/$(TARGET).elf | 298 | .SECONDARY : $(BUILD_DIR)/$(TARGET).elf |
| 335 | .PRECIOUS : $(OBJ) | 299 | .PRECIOUS : $(OBJ) |
| 336 | # Note the obj.txt depeendency is there to force linking if a source file is deleted | 300 | # Note the obj.txt depeendency is there to force linking if a source file is deleted |
| 337 | %.elf: $(OBJ) $(OBJDIR)/cflags.txt $(OBJDIR)/ldflags.txt $(OBJDIR)/obj.txt | $(BEGIN) | 301 | %.elf: $(OBJ) $(MASTER_OUTPUT)/cflags.txt $(MASTER_OUTPUT)/ldflags.txt $(MASTER_OUTPUT)/obj.txt | $(BEGIN) |
| 338 | @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD) | 302 | @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD) |
| 339 | $(eval CMD=$(CC) $(ALL_CFLAGS) $(filter-out %.txt,$^) --output $@ $(LDFLAGS)) | 303 | $(eval CMD=$(CC) $(ALL_CFLAGS) $(filter-out %.txt,$^) --output $@ $(LDFLAGS)) |
| 340 | @$(BUILD_CMD) | 304 | @$(BUILD_CMD) |
| 305 | |||
| 341 | 306 | ||
| 342 | define GEN_OBJRULE | 307 | define GEN_OBJRULE |
| 308 | $1_CFLAGS = $$(ALL_CFLAGS) $$($1_DEFS) | ||
| 309 | $1_CPPFLAGS= $$(ALL_CPPFLAGS) $$($1_DEFS) | ||
| 310 | $1_ASFLAGS= $$(ALL_ASFLAGS) $$($1_DEFS) | ||
| 311 | |||
| 343 | # Compile: create object files from C source files. | 312 | # Compile: create object files from C source files. |
| 344 | $1/%.o : %.c $1/%.d $1/cflags.txt $1/compiler.txt | $(BEGIN) | 313 | $1/%.o : %.c $1/%.d $1/cflags.txt $1/compiler.txt | $(BEGIN) |
| 345 | @mkdir -p $$(@D) | 314 | @mkdir -p $$(@D) |
| 346 | @$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD) | 315 | @$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD) |
| 347 | $$(eval CMD=$$(CC) -c $$(ALL_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) | 316 | $$(eval CMD := $$(CC) -c $$($1_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) |
| 348 | @$$(BUILD_CMD) | 317 | @$$(BUILD_CMD) |
| 349 | 318 | ||
| 350 | # Compile: create object files from C++ source files. | 319 | # Compile: create object files from C++ source files. |
| 351 | $1/%.o : %.cpp $1/%.d $1/cppflags.txt $1/compiler.txt | $(BEGIN) | 320 | $1/%.o : %.cpp $1/%.d $1/cppflags.txt $1/compiler.txt | $(BEGIN) |
| 352 | @mkdir -p $$(@D) | 321 | @mkdir -p $$(@D) |
| 353 | @$$(SILENT) || printf "$$(MSG_COMPILING_CPP) $$<" | $$(AWK_CMD) | 322 | @$$(SILENT) || printf "$$(MSG_COMPILING_CPP) $$<" | $$(AWK_CMD) |
| 354 | $$(eval CMD=$$(CC) -c $$(ALL_CPPFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) | 323 | $$(eval CMD=$$(CC) -c $$($1_CPPFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) |
| 355 | @$(BUILD_CMD) | 324 | @$(BUILD_CMD) |
| 356 | 325 | ||
| 357 | # Assemble: create object files from assembler source files. | 326 | # Assemble: create object files from assembler source files. |
| 358 | $1/%.o : %.S $1/asflags.txt $1/compiler.txt | $(BEGIN) | 327 | $1/%.o : %.S $1/asflags.txt $1/compiler.txt | $(BEGIN) |
| 359 | @mkdir -p $$(@D) | 328 | @mkdir -p $$(@D) |
| 360 | @$(SILENT) || printf "$$(MSG_ASSEMBLING) $$<" | $$(AWK_CMD) | 329 | @$(SILENT) || printf "$$(MSG_ASSEMBLING) $$<" | $$(AWK_CMD) |
| 361 | $$(eval CMD=$$(CC) -c $$(ALL_ASFLAGS) $$< -o $$@) | 330 | $$(eval CMD=$$(CC) -c $$($1_ASFLAGS) $$< -o $$@) |
| 362 | @$$(BUILD_CMD) | 331 | @$$(BUILD_CMD) |
| 363 | 332 | ||
| 364 | $1/force: | 333 | $1/force: |
| 365 | 334 | ||
| 366 | $1/cflags.txt: $1/force | 335 | $1/cflags.txt: $1/force |
| 367 | echo '$$(ALL_CFLAGS)' | cmp -s - $$@ || echo '$$(ALL_CFLAGS)' > $$@ | 336 | echo '$$($1_CFLAGS)' | cmp -s - $$@ || echo '$$($1_CFLAGS)' > $$@ |
| 368 | 337 | ||
| 369 | $1/cppflags.txt: $1/force | 338 | $1/cppflags.txt: $1/force |
| 370 | echo '$$(ALL_CPPFLAGS)' | cmp -s - $$@ || echo '$$(ALL_CPPFLAGS)' > $$@ | 339 | echo '$$($1_CPPFLAGS)' | cmp -s - $$@ || echo '$$($1_CPPFLAGS)' > $$@ |
| 371 | 340 | ||
| 372 | $1/asflags.txt: $1/force | 341 | $1/asflags.txt: $1/force |
| 373 | echo '$$(ALL_ASFLAGS)' | cmp -s - $$@ || echo '$$(ALL_ASFLAGS)' > $$@ | 342 | echo '$$($1_ASFLAGS)' | cmp -s - $$@ || echo '$$($1_ASFLAGS)' > $$@ |
| 374 | |||
| 375 | $1/ldflags.txt: $1/force | ||
| 376 | echo '$$(LDFLAGS)' | cmp -s - $$@ || echo '$$(LDFLAGS)' > $$@ | ||
| 377 | |||
| 378 | $1/obj.txt: $1/force | ||
| 379 | echo '$$(OBJ)' | cmp -s - $$@ || echo '$$(OBJ)' > $$@ | ||
| 380 | 343 | ||
| 381 | $1/compiler.txt: $1/force | 344 | $1/compiler.txt: $1/force |
| 382 | $$(CC) --version | cmp -s - $$@ || $$(CC) --version > $$@ | 345 | $$(CC) --version | cmp -s - $$@ || $$(CC) --version > $$@ |
| 383 | endef | 346 | endef |
| 384 | 347 | ||
| 348 | $(MASTER_OUTPUT)/obj.txt: $(MASTER_OUTPUT)/force | ||
| 349 | echo '$(OBJ)' | cmp -s - $$@ || echo '$(OBJ)' > $$@ | ||
| 350 | |||
| 351 | $(MASTER_OUTPUT)/ldflags.txt: $(MASTER_OUTPUT)/force | ||
| 352 | echo '$(LDFLAGS)' | cmp -s - $$@ || echo '$(LDFLAGS)' > $$@ | ||
| 353 | |||
| 354 | |||
| 385 | # We have to use static rules for the .d files for some reason | 355 | # We have to use static rules for the .d files for some reason |
| 386 | DEPS = $(patsubst %.o,%.d,$(OBJ)) | 356 | DEPS = $(patsubst %.o,%.d,$(OBJ)) |
| 387 | # Keep the .d files | 357 | # Keep the .d files |
| @@ -390,22 +360,7 @@ DEPS = $(patsubst %.o,%.d,$(OBJ)) | |||
| 390 | $(DEPS): | 360 | $(DEPS): |
| 391 | 361 | ||
| 392 | 362 | ||
| 393 | # Since the object files could be in two different folders, generate | 363 | $(foreach OUTPUT,$(OUTPUTS),$(eval $(call GEN_OBJRULE,$(OUTPUT)))) |
| 394 | # separate rules for them, rather than having too generic rules | ||
| 395 | $(eval $(call GEN_OBJRULE,$(OBJDIR))) | ||
| 396 | $(eval $(call GEN_OBJRULE,$(KBOBJDIR))) | ||
| 397 | |||
| 398 | # Compile: create assembler files from C source files. | ||
| 399 | %.s : %.c | $(BEGIN) | ||
| 400 | @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD) | ||
| 401 | $(eval CMD=$(CC) -S $(ALL_CFLAGS) $< -o $@) | ||
| 402 | @$(BUILD_CMD) | ||
| 403 | |||
| 404 | # Compile: create assembler files from C++ source files. | ||
| 405 | %.s : %.cpp | $(BEGIN) | ||
| 406 | @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD) | ||
| 407 | $(eval CMD=$(CC) -S $(ALL_CPPFLAGS) $< -o $@) | ||
| 408 | @$(BUILD_CMD) | ||
| 409 | 364 | ||
| 410 | # Create preprocessed source for use in sending a bug report. | 365 | # Create preprocessed source for use in sending a bug report. |
| 411 | %.i : %.c | $(BEGIN) | 366 | %.i : %.c | $(BEGIN) |
| @@ -420,13 +375,13 @@ clean: | |||
| 420 | show_path: | 375 | show_path: |
| 421 | @echo VPATH=$(VPATH) | 376 | @echo VPATH=$(VPATH) |
| 422 | @echo SRC=$(SRC) | 377 | @echo SRC=$(SRC) |
| 378 | @echo OBJ=$(OBJ) | ||
| 423 | 379 | ||
| 424 | # Create build directory | 380 | # Create build directory |
| 425 | $(shell mkdir $(BUILD_DIR) 2>/dev/null) | 381 | $(shell mkdir $(BUILD_DIR) 2>/dev/null) |
| 426 | 382 | ||
| 427 | # Create object files directory | 383 | # Create object files directory |
| 428 | $(shell mkdir $(OBJDIR) 2>/dev/null) | 384 | $(eval $(foreach OUTPUT,$(OUTPUTS),$(shell mkdir $(OUTPUT) 2>/dev/null))) |
| 429 | $(shell mkdir $(KBOBJDIR) 2>/dev/null) | ||
| 430 | 385 | ||
| 431 | # Include the dependency files. | 386 | # Include the dependency files. |
| 432 | -include $(patsubst %.o,%.d,$(OBJ)) | 387 | -include $(patsubst %.o,%.d,$(OBJ)) |
