]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/rules.mk
Also depend on the gcc version
[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 $(patsubst %.o,%.td,$@)
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) $(EXTRAFLAGS)
288 ALL_CPPFLAGS = $(MCUFLAGS) -x c++ $(CPPFLAGS) $(EXTRAFLAGS)
289 ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
290
291 MOVE_DEP = mv -f $(patsubst %.o,%.td,$@) $(patsubst %.o,%.d,$@)
292
293 # Default target.
294 all: build sizeafter
295
296 # Quick make that doesn't clean
297 quick: build sizeafter
298
299 # Change the build target to build a HEX file or a library.
300 build: elf hex
301 #build: elf hex eep lss sym
302 #build: lib
303
304
305 elf: $(BUILD_DIR)/$(TARGET).elf
306 hex: $(BUILD_DIR)/$(TARGET).hex
307 eep: $(BUILD_DIR)/$(TARGET).eep
308 lss: $(BUILD_DIR)/$(TARGET).lss
309 sym: $(BUILD_DIR)/$(TARGET).sym
310 LIBNAME=lib$(TARGET).a
311 lib: $(LIBNAME)
312
313 check_submodule:
314         git submodule status --recursive | \
315         while IFS= read -r x; do \
316                 case "$$x" in \
317                         \ *) ;; \
318                         *) printf "$(MSG_SUBMODULE_DIRTY)";break;; \
319                 esac \
320         done
321
322 # Display size of file.
323 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
324 #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
325 ELFSIZE = $(SIZE) $(BUILD_DIR)/$(TARGET).elf
326
327 sizebefore:
328         @if test -f $(TARGET).hex; then $(SECHO) $(MSG_SIZE_BEFORE); $(SILENT) || $(HEXSIZE); \
329         2>/dev/null; $(SECHO); fi
330
331 sizeafter: $(BUILD_DIR)/$(TARGET).hex
332         @if test -f $(TARGET).hex; then $(SECHO); $(SECHO) $(MSG_SIZE_AFTER); $(SILENT) || $(HEXSIZE); \
333         2>/dev/null; $(SECHO); fi
334         # test file sizes eventually
335         # @if [[ $($(SIZE) --target=$(FORMAT) $(TARGET).hex | $(AWK) 'NR==2 {print "0x"$5}') -gt 0x200 ]]; then $(SECHO) "File is too big!"; fi
336
337 # Display compiler version information.
338 gccversion :
339         @$(SILENT) || $(CC) --version
340
341 # Create final output files (.hex, .eep) from ELF output file.
342 %.hex: %.elf
343         @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD)
344         $(eval CMD=$(HEX) $< $@)
345         @$(BUILD_CMD)
346         @if $(AUTOGEN); then \
347                 $(SILENT) || printf "Copying $(TARGET).hex to keymaps/$(KEYMAP)/$(KEYBOARD)_$(KEYMAP).hex\n"; \
348                 $(COPY) $@ $(KEYMAP_PATH)/$(KEYBOARD)_$(KEYMAP).hex; \
349         else \
350                 $(COPY) $@ $(TARGET).hex; \
351         fi
352
353 %.eep: %.elf
354         @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD)
355         $(eval CMD=$(EEP) $< $@ || exit 0)
356         @$(BUILD_CMD)
357
358 # Create extended listing file from ELF output file.
359 %.lss: %.elf
360         @$(SILENT) || printf "$(MSG_EXTENDED_LISTING) $@" | $(AWK_CMD)
361         $(eval CMD=$(OBJDUMP) -h -S -z $< > $@)
362         @$(BUILD_CMD)
363
364 # Create a symbol table from ELF output file.
365 %.sym: %.elf
366         @$(SILENT) || printf "$(MSG_SYMBOL_TABLE) $@" | $(AWK_CMD)
367         $(eval CMD=$(NM) -n $< > $@ )
368         @$(BUILD_CMD)
369
370 %.bin: %.elf
371         @$(SILENT) || printf "$(MSG_BIN) $@" | $(AWK_CMD)
372         $(eval CMD=$(BIN) $< $@ || exit 0)
373         @$(BUILD_CMD)
374
375 # Create library from object files.
376 .SECONDARY : $(BUILD_DIR)/$(TARGET).a
377 .PRECIOUS : $(OBJ)
378 %.a: $(OBJ)
379         @$(SILENT) || printf "$(MSG_CREATING_LIBRARY) $@" | $(AWK_CMD)
380         $(eval CMD=$(AR) $@ $(OBJ) )
381         @$(BUILD_CMD)
382
383 BEGIN = gccversion check_submodule sizebefore
384
385 # Link: create ELF output file from object files.
386 .SECONDARY : $(BUILD_DIR)/$(TARGET).elf
387 .PRECIOUS : $(OBJ)
388 # Note the obj.txt depeendency is there to force linking if a source file is deleted
389 %.elf: $(OBJ) $(OBJDIR)/cflags.txt $(OBJDIR)/ldflags.txt $(OBJDIR)/obj.txt | $(BEGIN)
390         @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD)
391         $(eval CMD=$(CC) $(ALL_CFLAGS) $(filter-out %.txt,$^) --output $@ $(LDFLAGS))
392         @$(BUILD_CMD)
393
394 define GEN_OBJRULE
395 # Compile: create object files from C source files.
396 $1/%.o : %.c $1/%.d $1/cflags.txt $1/compiler.txt | $(BEGIN)
397         @mkdir -p $$(@D)
398         @$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD)
399         $$(eval CMD=$$(CC) -c $$(ALL_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP))
400         @$$(BUILD_CMD)
401
402 # Compile: create object files from C++ source files.
403 $1/%.o : %.cpp $1/%.d $1/cppflags.txt $1/compiler.txt | $(BEGIN)
404         @mkdir -p $$(@D)
405         @$$(SILENT) || printf "$$(MSG_COMPILING_CPP) $$<" | $$(AWK_CMD)
406         $$(eval CMD=$$(CC) -c $$(ALL_CPPFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP))
407         @$(BUILD_CMD)
408
409 # Assemble: create object files from assembler source files.
410 $1/%.o : %.S $1/asflags.txt $1/compiler.txt | $(BEGIN)
411         @mkdir -p $$(@D)
412         @$(SILENT) || printf "$$(MSG_ASSEMBLING) $$<" | $$(AWK_CMD)
413         $$(eval CMD=$$(CC) -c $$(ALL_ASFLAGS) $$< -o $$@)
414         @$$(BUILD_CMD)
415
416 $1/force:
417
418 $1/cflags.txt: $1/force
419         echo '$$(ALL_CFLAGS)' | cmp -s - $$@ || echo '$$(ALL_CFLAGS)' > $$@
420
421 $1/cppflags.txt: $1/force
422         echo '$$(ALL_CPPFLAGS)' | cmp -s - $$@ || echo '$$(ALL_CPPFLAGS)' > $$@
423
424 $1/asflags.txt: $1/force
425         echo '$$(ALL_ASFLAGS)' | cmp -s - $$@ || echo '$$(ALL_ASFLAGS)' > $$@
426
427 $1/ldflags.txt: $1/force
428         echo '$$(LDFLAGS)' | cmp -s - $$@ || echo '$$(LDFLAGS)' > $$@
429
430 $1/obj.txt: $1/force
431         echo '$$(OBJ)' | cmp -s - $$@ || echo '$$(OBJ)' > $$@
432
433 $1/compiler.txt: $1/force
434         $$(CC) --version | cmp -s - $$@ || $$(CC) --version > $$@
435 endef
436
437 # We have to use static rules for the .d files for some reason
438 DEPS = $(patsubst %.o,%.d,$(OBJ))
439 # Keep the .d files
440 .PRECIOUS: $(DEPS)
441 # Empty rule to force recompilation if the .d file is missing
442 $(DEPS):
443
444 # Since the object files could be in two different folders, generate
445 # separate rules for them, rather than having too generic rules
446 $(eval $(call GEN_OBJRULE,$(OBJDIR)))
447 $(eval $(call GEN_OBJRULE,$(KBOBJDIR)))
448
449 # Compile: create assembler files from C source files.
450 %.s : %.c | $(BEGIN)
451         @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
452         $(eval CMD=$(CC) -S $(ALL_CFLAGS) $< -o $@)
453         @$(BUILD_CMD)
454
455 # Compile: create assembler files from C++ source files.
456 %.s : %.cpp | $(BEGIN)
457         @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
458         $(eval CMD=$(CC) -S $(ALL_CPPFLAGS) $< -o $@)
459         @$(BUILD_CMD)
460
461 # Create preprocessed source for use in sending a bug report.
462 %.i : %.c | $(BEGIN)
463         $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@
464
465 # Target: clean project.
466 clean:
467
468 show_path:
469         @echo VPATH=$(VPATH)
470         @echo SRC=$(SRC)
471
472 SUBDIRS := $(filter-out %/util/ %/doc/ %/keymaps/ %/old_keymap_files/,$(dir $(wildcard $(TOP_DIR)/keyboards/**/*/Makefile)))
473 SUBDIRS := $(SUBDIRS) $(dir $(wildcard $(TOP_DIR)/keyboards/*/.))
474 SUBDIRS := $(sort $(SUBDIRS))
475 # $(error $(SUBDIRS))
476 all-keyboards-defaults-%:
477         @for x in $(SUBDIRS) ; do \
478                 printf "Compiling with default: $$x" | $(AWK_CMD); \
479                 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; \
480         done
481
482 all-keyboards-defaults: all-keyboards-defaults-all
483
484 KEYBOARDS := $(SUBDIRS:$(TOP_DIR)/keyboards/%/=/keyboards/%)
485 all-keyboards-all: $(addsuffix -all,$(KEYBOARDS))
486 all-keyboards-quick: $(addsuffix -quick,$(KEYBOARDS))
487 all-keyboards-clean: $(addsuffix -clean,$(KEYBOARDS))
488 all-keyboards: all-keyboards-all
489
490 define make_keyboard
491 $(eval KEYBOARD=$(patsubst /keyboards/%,%,$1))
492 $(eval SUBPROJECT=$(lastword $(subst /, ,$(KEYBOARD))))
493 $(eval KEYBOARD=$(firstword $(subst /, ,$(KEYBOARD))))
494 $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/keymaps/*/.))))
495 $(eval KEYMAPS+=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/*/.))))
496 @for x in $(KEYMAPS) ; do \
497         printf "Compiling $(BOLD)$(KEYBOARD)/$(SUBPROJECT)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-118s", $$0; }'; \
498         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; \
499 done
500 endef
501
502 define make_keyboard_helper
503 # Just remove the -quick, -all and so on from the first argument and pass it forward
504 $(call make_keyboard,$(subst -$2,,$1),$2)
505 endef
506
507 /keyboards/%-quick:
508         $(call make_keyboard_helper,$@,quick)
509 /keyboards/%-all:
510         $(call make_keyboard_helper,$@,all)
511 /keyboards/%-clean:
512         $(call make_keyboard_helper,$@,clean)
513 /keyboards/%:
514         $(call make_keyboard_helper,$@,all)
515
516 all-keymaps-%:
517         $(eval MAKECONFIG=$(call get_target,all-keymaps,$@))
518         $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/keymaps/*/.))))
519         @for x in $(KEYMAPS) ; do \
520                 printf "Compiling $(BOLD)$(KEYBOARD)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-118s", $$0; }'; \
521                 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; \
522         done
523
524 all-keymaps: all-keymaps-all
525
526 GOAL=$(MAKECMDGOALS)
527 ifeq ($(MAKECMDGOALS),)
528 GOAL = all
529 endif
530 CLEANING_GOALS=clean clean_list all
531 ifneq ($(findstring $(GOAL),$(CLEANING_GOALS)),)
532 $(shell $(REMOVE) -r $(BUILD_DIR) 2>/dev/null)
533 $(shell $(REMOVE) -r $(TOP_DIR)/$(BUILD_DIR))
534 $(shell $(REMOVE) -r $(KEYBOARD_PATH)/$(BUILD_DIR))
535 $(shell if $$SUBPROJECT; then $(REMOVE) -r $(SUBPROJECT_PATH)/$(BUILD_DIR); fi)
536 $(shell $(REMOVE) -r $(KEYMAP_PATH)/$(BUILD_DIR))
537 endif
538
539 # Create build directory
540 $(shell mkdir $(BUILD_DIR) 2>/dev/null)
541
542 # Create object files directory
543 $(shell mkdir $(OBJDIR) 2>/dev/null)
544 $(shell mkdir $(KBOBJDIR) 2>/dev/null)
545
546 # Include the dependency files.
547 -include $(patsubst %.o,%.d,$(OBJ))
548
549
550 # Listing of phony targets.
551 .PHONY : all quick finish sizebefore sizeafter gccversion \
552 build elf hex eep lss sym coff extcoff check_submodule \
553 clean clean_list debug gdb-config show_path \
554 program teensy dfu flip dfu-ee flip-ee dfu-start \
555 all-keyboards-defaults all-keyboards all-keymaps \
556 all-keyboards-defaults-% all-keyboards-% all-keymaps-%