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