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