]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/rules.mk
Merge remote-tracking branch 'upstream/master'
[qmk_firmware.git] / tmk_core / rules.mk
1 # Hey Emacs, this is a -*- makefile -*-
2 #----------------------------------------------------------------------------
3 # WinAVR Makefile Template written by Eric B. Weddington, Jg Wunsch, et al.
4 #
5 # Released to the Public Domain
6 #
7 # Additional material for this makefile was written by:
8 # Peter Fleury
9 # Tim Henigan
10 # Colin O'Flynn
11 # Reiner Patommel
12 # Markus Pfaff
13 # Sander Pool
14 # Frederik Rouleau
15 # Carlos Lamas
16 #
17
18
19 # Output format. (can be srec, ihex, binary)
20 FORMAT = ihex
21
22 # Optimization level, can be [0, 1, 2, 3, s].
23 #     0 = turn off optimization. s = optimize for size.
24 #     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
25 OPT = s
26
27 COLOR ?= true
28
29 ifeq ($(COLOR),true)
30         NO_COLOR=\033[0m
31         OK_COLOR=\033[32;01m
32         ERROR_COLOR=\033[31;01m
33         WARN_COLOR=\033[33;01m
34         BLUE=\033[0;34m
35         BOLD=\033[1m
36 endif
37
38 ifdef quick
39         QUICK = $(quick)
40 endif
41
42 QUICK ?= false
43 AUTOGEN ?= false
44
45 ifneq ($(shell awk --version 2>/dev/null),)
46         AWK=awk
47 else
48         AWK=cat && test
49 endif
50
51 OK_STRING=$(OK_COLOR)[OK]$(NO_COLOR)\n
52 ERROR_STRING=$(ERROR_COLOR)[ERRORS]$(NO_COLOR)\n
53 WARN_STRING=$(WARN_COLOR)[WARNINGS]$(NO_COLOR)\n
54
55 ifndef $(SILENT)
56         SILENT = false
57 endif
58
59 TAB_LOG = printf "\n$$LOG\n\n" | $(AWK) '{ sub(/^/," | "); print }'
60 TAB_LOG_PLAIN = printf "$$LOG\n"
61 AWK_STATUS = $(AWK) '{ printf " %-10s\n", $$1; }'
62 AWK_CMD = $(AWK) '{ printf "%-99s", $$0; }'
63 PRINT_ERROR = ($(SILENT) ||printf " $(ERROR_STRING)" | $(AWK_STATUS)) && $(TAB_LOG) && exit 1
64 PRINT_WARNING = ($(SILENT) || printf " $(WARN_STRING)" | $(AWK_STATUS)) && $(TAB_LOG)
65 PRINT_ERROR_PLAIN = ($(SILENT) ||printf " $(ERROR_STRING)" | $(AWK_STATUS)) && $(TAB_LOG_PLAIN) && exit 1
66 PRINT_WARNING_PLAIN = ($(SILENT) || printf " $(WARN_STRING)" | $(AWK_STATUS)) && $(TAB_LOG_PLAIN)
67 PRINT_OK = $(SILENT) || printf " $(OK_STRING)" | $(AWK_STATUS)
68 BUILD_CMD = LOG=$$($(CMD) 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING); else $(PRINT_OK); fi;
69
70 # List any extra directories to look for include files here.
71 #     Each directory must be seperated by a space.
72 #     Use forward slashes for directory separators.
73 #     For a directory that has spaces, enclose it in quotes.
74 EXTRAINCDIRS += $(subst :, ,$(VPATH))
75
76
77 # Compiler flag to set the C Standard level.
78 #     c89   = "ANSI" C
79 #     gnu89 = c89 plus GCC extensions
80 #     c99   = ISO C99 standard (not yet fully implemented)
81 #     gnu99 = c99 plus GCC extensions
82 CSTANDARD = -std=gnu99
83
84
85 # Place -D or -U options here for C sources
86 CDEFS += $(OPT_DEFS)
87
88
89 # Place -D or -U options here for ASM sources
90 ADEFS += $(OPT_DEFS)
91
92
93 # Place -D or -U options here for C++ sources
94 #CPPDEFS += -D__STDC_LIMIT_MACROS
95 #CPPDEFS += -D__STDC_CONSTANT_MACROS
96 CPPDEFS += $(OPT_DEFS)
97
98
99
100 #---------------- Compiler Options C ----------------
101 #  -g*:          generate debugging information
102 #  -O*:          optimization level
103 #  -f...:        tuning, see GCC manual and avr-libc documentation
104 #  -Wall...:     warning level
105 #  -Wa,...:      tell GCC to pass this to the assembler.
106 #    -adhlns...: create assembler listing
107 CFLAGS += -g$(DEBUG)
108 CFLAGS += $(CDEFS)
109 CFLAGS += -O$(OPT)
110 # add color
111 ifeq ($(COLOR),true)
112 ifeq ("$(shell echo "int main(){}" | $(CC) -fdiagnostics-color -x c - -o /dev/null 2>&1)", "")
113         CFLAGS+= -fdiagnostics-color
114 endif
115 endif
116 CFLAGS += -Wall
117 CFLAGS += -Wstrict-prototypes
118 #CFLAGS += -mshort-calls
119 #CFLAGS += -fno-unit-at-a-time
120 #CFLAGS += -Wundef
121 #CFLAGS += -Wunreachable-code
122 #CFLAGS += -Wsign-compare
123 CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
124 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
125 CFLAGS += $(CSTANDARD)
126 ifdef CONFIG_H
127     CFLAGS += -include $(CONFIG_H)
128 endif
129
130
131 #---------------- Compiler Options C++ ----------------
132 #  -g*:          generate debugging information
133 #  -O*:          optimization level
134 #  -f...:        tuning, see GCC manual and avr-libc documentation
135 #  -Wall...:     warning level
136 #  -Wa,...:      tell GCC to pass this to the assembler.
137 #    -adhlns...: create assembler listing
138 CPPFLAGS += -g$(DEBUG)
139 CPPFLAGS += $(CPPDEFS)
140 CPPFLAGS += -O$(OPT)
141 # to supress "warning: only initialized variables can be placed into program memory area"
142 CPPFLAGS += -w
143 CPPFLAGS += -Wall
144 CPPFLAGS += -Wundef
145 #CPPFLAGS += -mshort-calls
146 #CPPFLAGS += -fno-unit-at-a-time
147 #CPPFLAGS += -Wstrict-prototypes
148 #CPPFLAGS += -Wunreachable-code
149 #CPPFLAGS += -Wsign-compare
150 CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
151 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
152 #CPPFLAGS += $(CSTANDARD)
153 ifdef CONFIG_H
154     CPPFLAGS += -include $(CONFIG_H)
155 endif
156
157
158 #---------------- Assembler Options ----------------
159 #  -Wa,...:   tell GCC to pass this to the assembler.
160 #  -adhlns:   create listing
161 #  -gstabs:   have the assembler create line number information; note that
162 #             for use in COFF files, additional information about filenames
163 #             and function names needs to be present in the assembler source
164 #             files -- see avr-libc docs [FIXME: not yet described there]
165 #  -listing-cont-lines: Sets the maximum number of continuation lines of hex
166 #       dump that will be displayed for a given single line of source input.
167 ASFLAGS += $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
168 ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
169 ifdef CONFIG_H
170     ASFLAGS += -include $(CONFIG_H)
171 endif
172
173 #---------------- Library Options ----------------
174 # Minimalistic printf version
175 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
176
177 # Floating point printf version (requires MATH_LIB = -lm below)
178 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
179
180 # If this is left blank, then it will use the Standard printf version.
181 PRINTF_LIB =
182 #PRINTF_LIB = $(PRINTF_LIB_MIN)
183 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
184
185
186 # Minimalistic scanf version
187 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
188
189 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
190 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
191
192 # If this is left blank, then it will use the Standard scanf version.
193 SCANF_LIB =
194 #SCANF_LIB = $(SCANF_LIB_MIN)
195 #SCANF_LIB = $(SCANF_LIB_FLOAT)
196
197
198 MATH_LIB = -lm
199
200
201 #---------------- Linker Options ----------------
202 #  -Wl,...:     tell GCC to pass this to linker.
203 #    -Map:      create map file
204 #    --cref:    add cross reference to  map file
205 #
206 # Comennt out "--relax" option to avoid a error such:
207 #       (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12'
208 #
209 LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref
210 #LDFLAGS += -Wl,--relax
211 LDFLAGS += $(EXTMEMOPTS)
212 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
213 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
214 #LDFLAGS += -T linker_script.x
215 # You can give EXTRALDFLAGS at 'make' command line.
216 LDFLAGS += $(EXTRALDFLAGS)
217
218 # Define programs and commands.
219 SHELL = sh
220 REMOVE = rm -f
221 REMOVEDIR = rmdir
222 COPY = cp
223 WINSHELL = cmd
224 SECHO = $(SILENT) || echo
225
226 # Define Messages
227 # English
228 MSG_ERRORS_NONE = Errors: none
229 MSG_BEGIN = -------- begin --------
230 MSG_END = --------  end  --------
231 MSG_SIZE_BEFORE = Size before:
232 MSG_SIZE_AFTER = Size after:
233 MSG_COFF = Converting to AVR COFF:
234 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
235 MSG_FLASH = Creating load file for Flash:
236 MSG_EEPROM = Creating load file for EEPROM:
237 MSG_BIN = Creating binary load file for Flash:
238 MSG_EXTENDED_LISTING = Creating Extended Listing:
239 MSG_SYMBOL_TABLE = Creating Symbol Table:
240 MSG_LINKING = Linking:
241 MSG_COMPILING = Compiling:
242 MSG_COMPILING_CPP = Compiling:
243 MSG_ASSEMBLING = Assembling:
244 MSG_CLEANING = Cleaning project:
245 MSG_CREATING_LIBRARY = Creating library:
246 MSG_SUBMODULE_DIRTY = $(WARN_COLOR)WARNING:$(NO_COLOR)\n \
247         Some git sub-modules are out of date or modified, please consider runnning:$(BOLD)\n\
248         git submodule sync --recursive\n\
249         git submodule update --init --recursive$(NO_COLOR)\n\n\
250         You can ignore this warning if you are not compiling any ChibiOS keyboards,\n\
251         or if you have modified the ChibiOS libraries yourself. \n\n
252
253
254 # Define all object files.
255 OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC))))
256 # The files in the lib folder are shared between all keymaps, so generate that folder name by removing
257 # the keymap from the name
258 KBOBJDIR=$(subst _$(KEYMAP),,$(OBJDIR))
259 # And fixup the object files to match
260 LIBOBJ = $(foreach v,$(OBJ),$(if $(findstring /lib/,$v),$v))
261 NONLIBOBJ := $(filter-out $(LIBOBJ),$(OBJ))
262 LIBOBJ := $(subst _$(KEYMAP)/,/,$(LIBOBJ))
263 OBJ := $(LIBOBJ) $(NONLIBOBJ)
264
265 # Define all listing files.
266 LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst %.S,$(OBJDIR)/%.lst,$(SRC))))
267
268
269 # Compiler flags to generate dependency files.
270 #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
271 GENDEPFLAGS = -MMD -MP -MF $(BUILD_DIR)/.dep/$(subst /,_,$(subst $(BUILD_DIR)/,,$@)).d
272
273
274 # Combine all necessary flags and optional flags.
275 # Add target processor to flags.
276 # You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar
277 ALL_CFLAGS = $(MCUFLAGS) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
278 ALL_CPPFLAGS = $(MCUFLAGS) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
279 ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
280
281 # Default target.
282 all: build sizeafter
283
284 # Quick make that doesn't clean
285 quick: build sizeafter
286
287 # Change the build target to build a HEX file or a library.
288 build: elf hex
289 #build: elf hex eep lss sym
290 #build: lib
291
292
293 elf: $(BUILD_DIR)/$(TARGET).elf
294 hex: $(BUILD_DIR)/$(TARGET).hex
295 eep: $(BUILD_DIR)/$(TARGET).eep
296 lss: $(BUILD_DIR)/$(TARGET).lss
297 sym: $(BUILD_DIR)/$(TARGET).sym
298 LIBNAME=lib$(TARGET).a
299 lib: $(LIBNAME)
300
301 check_submodule:
302         git submodule status --recursive | \
303         while IFS= read -r x; do \
304                 case "$$x" in \
305                         \ *) ;; \
306                         *) printf "$(MSG_SUBMODULE_DIRTY)";break;; \
307                 esac \
308         done
309
310 # Display size of file.
311 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
312 #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
313 ELFSIZE = $(SIZE) $(BUILD_DIR)/$(TARGET).elf
314
315 sizebefore:
316         @if test -f $(TARGET).hex; then $(SECHO) $(MSG_SIZE_BEFORE); $(SILENT) || $(HEXSIZE); \
317         2>/dev/null; $(SECHO); fi
318
319 sizeafter: $(BUILD_DIR)/$(TARGET).hex
320         @if test -f $(TARGET).hex; then $(SECHO); $(SECHO) $(MSG_SIZE_AFTER); $(SILENT) || $(HEXSIZE); \
321         2>/dev/null; $(SECHO); fi
322         # test file sizes eventually
323         # @if [[ $($(SIZE) --target=$(FORMAT) $(TARGET).hex | $(AWK) 'NR==2 {print "0x"$5}') -gt 0x200 ]]; then $(SECHO) "File is too big!"; fi
324
325 # Display compiler version information.
326 gccversion :
327         @$(SILENT) || $(CC) --version
328
329 # Create final output files (.hex, .eep) from ELF output file.
330 %.hex: %.elf
331         @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD)
332         $(eval CMD=$(HEX) $< $@)
333         @$(BUILD_CMD)
334         @if $(AUTOGEN); then \
335                 $(SILENT) || printf "Copying $(TARGET).hex to keymaps/$(KEYMAP)/$(KEYBOARD)_$(KEYMAP).hex\n"; \
336                 $(COPY) $@ $(KEYMAP_PATH)/$(KEYBOARD)_$(KEYMAP).hex; \
337         else \
338                 $(COPY) $@ $(TARGET).hex; \
339         fi
340
341 %.eep: %.elf
342         @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD)
343         $(eval CMD=$(EEP) $< $@ || exit 0)
344         @$(BUILD_CMD)
345
346 # Create extended listing file from ELF output file.
347 %.lss: %.elf
348         @$(SILENT) || printf "$(MSG_EXTENDED_LISTING) $@" | $(AWK_CMD)
349         $(eval CMD=$(OBJDUMP) -h -S -z $< > $@)
350         @$(BUILD_CMD)
351
352 # Create a symbol table from ELF output file.
353 %.sym: %.elf
354         @$(SILENT) || printf "$(MSG_SYMBOL_TABLE) $@" | $(AWK_CMD)
355         $(eval CMD=$(NM) -n $< > $@ )
356         @$(BUILD_CMD)
357
358 %.bin: %.elf
359         @$(SILENT) || printf "$(MSG_BIN) $@" | $(AWK_CMD)
360         $(eval CMD=$(BIN) $< $@ || exit 0)
361         @$(BUILD_CMD)
362
363 # Create library from object files.
364 .SECONDARY : $(BUILD_DIR)/$(TARGET).a
365 .PRECIOUS : $(OBJ)
366 %.a: $(OBJ)
367         @$(SILENT) || printf "$(MSG_CREATING_LIBRARY) $@" | $(AWK_CMD)
368         $(eval CMD=$(AR) $@ $(OBJ) )
369         @$(BUILD_CMD)
370
371 BEGIN = gccversion check_submodule sizebefore
372
373 # Link: create ELF output file from object files.
374 .SECONDARY : $(BUILD_DIR)/$(TARGET).elf
375 .PRECIOUS : $(OBJ)
376 %.elf: $(OBJ) | $(BEGIN)
377         @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD)
378         $(eval CMD=$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS))
379         @$(BUILD_CMD)
380
381 define GEN_OBJRULE
382 # Compile: create object files from C source files.
383 $1/%.o : %.c | $(BEGIN)
384         @mkdir -p $$(@D)
385         @$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD)
386         $$(eval CMD=$$(CC) -c $$(ALL_CFLAGS) $$< -o $$@)
387         @$$(BUILD_CMD)
388
389 # Compile: create object files from C++ source files.
390 $1/%.o : %.cpp | $(BEGIN)
391         @mkdir -p $$(@D)
392         @$$(SILENT) || printf "$$(MSG_COMPILING_CPP) $$<" | $$(AWK_CMD)
393         $$(eval CMD=$$(CC) -c $$(ALL_CPPFLAGS) $$< -o $$@)
394         @$(BUILD_CMD)
395
396 # Assemble: create object files from assembler source files.
397 $1/%.o : %.S | $(BEGIN)
398         @mkdir -p $$(@D)
399         @$(SILENT) || printf "$$(MSG_ASSEMBLING) $$<" | $$(AWK_CMD)
400         $$(eval CMD=$$(CC) -c $$(ALL_ASFLAGS) $$< -o $$@)
401         @$$(BUILD_CMD)
402
403 endef
404
405 # Since the object files could be in two different folders, generate
406 # separate rules for them, rather than having too generic rules
407 $(eval $(call GEN_OBJRULE,$(OBJDIR)))
408 $(eval $(call GEN_OBJRULE,$(KBOBJDIR)))
409
410 # Compile: create assembler files from C source files.
411 %.s : %.c | $(BEGIN)
412         @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
413         $(eval CMD=$(CC) -S $(ALL_CFLAGS) $< -o $@)
414         @$(BUILD_CMD)
415
416 # Compile: create assembler files from C++ source files.
417 %.s : %.cpp | $(BEGIN)
418         @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
419         $(eval CMD=$(CC) -S $(ALL_CPPFLAGS) $< -o $@)
420         @$(BUILD_CMD)
421
422 # Create preprocessed source for use in sending a bug report.
423 %.i : %.c | $(BEGIN)
424         $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@
425
426 # Target: clean project.
427 clean: 
428
429 show_path:
430         @echo VPATH=$(VPATH)
431         @echo SRC=$(SRC)
432
433 SUBDIRS := $(filter-out %/util/ %/doc/ %/keymaps/ %/old_keymap_files/,$(dir $(wildcard $(TOP_DIR)/keyboards/**/*/Makefile)))
434 SUBDIRS := $(SUBDIRS) $(dir $(wildcard $(TOP_DIR)/keyboards/*/.))
435 SUBDIRS := $(sort $(SUBDIRS))
436 # $(error $(SUBDIRS))
437 all-keyboards-defaults-%:
438         @for x in $(SUBDIRS) ; do \
439                 printf "Compiling with default: $$x" | $(AWK_CMD); \
440                 LOG=$$($(MAKE) -C $$x $(subst all-keyboards-defaults-,,$@) VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=true 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR_PLAIN); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING_PLAIN); else $(PRINT_OK); fi; \
441         done
442
443 all-keyboards-defaults: all-keyboards-defaults-all
444
445 KEYBOARDS := $(SUBDIRS:$(TOP_DIR)/keyboards/%/=/keyboards/%)
446 all-keyboards-all: $(addsuffix -all,$(KEYBOARDS))
447 all-keyboards-quick: $(addsuffix -quick,$(KEYBOARDS))
448 all-keyboards-clean: $(addsuffix -clean,$(KEYBOARDS))
449 all-keyboards: all-keyboards-all
450
451 define make_keyboard
452 $(eval KEYBOARD=$(patsubst /keyboards/%,%,$1))
453 $(eval SUBPROJECT=$(lastword $(subst /, ,$(KEYBOARD))))
454 $(eval KEYBOARD=$(firstword $(subst /, ,$(KEYBOARD))))
455 $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/keymaps/*/.))))
456 $(eval KEYMAPS+=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/*/.))))
457 @for x in $(KEYMAPS) ; do \
458         printf "Compiling $(BOLD)$(KEYBOARD)/$(SUBPROJECT)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-118s", $$0; }'; \
459         LOG=$$($(MAKE) -C $(TOP_DIR)$1 $2 keymap=$$x VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=true 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR_PLAIN); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING_PLAIN); else $(PRINT_OK); fi; \
460 done
461 endef
462
463 define make_keyboard_helper
464 # Just remove the -quick, -all and so on from the first argument and pass it forward
465 $(call make_keyboard,$(subst -$2,,$1),$2)
466 endef
467
468 /keyboards/%-quick:
469         $(call make_keyboard_helper,$@,quick)
470 /keyboards/%-all:
471         $(call make_keyboard_helper,$@,all)
472 /keyboards/%-clean:
473         $(call make_keyboard_helper,$@,clean)
474 /keyboards/%:
475         $(call make_keyboard_helper,$@,all)
476
477 all-keymaps-%:
478         $(eval MAKECONFIG=$(call get_target,all-keymaps,$@))
479         $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/keymaps/*/.))))
480         @for x in $(KEYMAPS) ; do \
481                 printf "Compiling $(BOLD)$(KEYBOARD)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-118s", $$0; }'; \
482                 LOG=$$($(MAKE) $(subst all-keymaps-,,$@) keyboard=$(KEYBOARD) keymap=$$x VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=true 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR_PLAIN); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING_PLAIN); else $(PRINT_OK); fi; \
483         done
484
485 all-keymaps: all-keymaps-all
486
487 GOAL=$(MAKECMDGOALS)
488 ifeq ($(MAKECMDGOALS),)
489 GOAL = all
490 endif
491 CLEANING_GOALS=clean clean_list all
492 ifneq ($(findstring $(GOAL),$(CLEANING_GOALS)),)
493 $(shell $(REMOVE) -r $(BUILD_DIR) 2>/dev/null)
494 $(shell $(REMOVE) -r $(TOP_DIR)/$(BUILD_DIR))
495 $(shell $(REMOVE) -r $(KEYBOARD_PATH)/$(BUILD_DIR))
496 $(shell if $$SUBPROJECT; then $(REMOVE) -r $(SUBPROJECT_PATH)/$(BUILD_DIR); fi)
497 $(shell $(REMOVE) -r $(KEYMAP_PATH)/$(BUILD_DIR))
498 endif
499
500 # Create build directory
501 $(shell mkdir $(BUILD_DIR) 2>/dev/null)
502
503 # Create object files directory
504 $(shell mkdir $(OBJDIR) 2>/dev/null)
505 $(shell mkdir $(KBOBJDIR) 2>/dev/null)
506
507 # Include the dependency files.
508 -include $(shell mkdir $(BUILD_DIR)/.dep 2>/dev/null) $(wildcard $(BUILD_DIR)/.dep/*)
509
510
511 # Listing of phony targets.
512 .PHONY : all quick finish sizebefore sizeafter gccversion \
513 build elf hex eep lss sym coff extcoff check_submodule \
514 clean clean_list debug gdb-config show_path \
515 program teensy dfu flip dfu-ee flip-ee dfu-start \
516 all-keyboards-defaults all-keyboards all-keymaps \
517 all-keyboards-defaults-% all-keyboards-% all-keymaps-%