Change _delay_ms to wait_ms in algernon keymap
[jackhill/qmk/firmware.git] / tmk_core / rules.mk
CommitLineData
a074364c 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#
a8375fa1 17
a074364c 18
a074364c 19# Output format. (can be srec, ihex, binary)
20FORMAT = ihex
21
e175b8d5 22# Optimization level, can be [0, 1, 2, 3, s].
a074364c 23# 0 = turn off optimization. s = optimize for size.
24# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
25OPT = s
26
13bb6b4b 27COLOR ?= true
d9e4dad0
JH
28
29ifeq ($(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
36endif
37
215c2119
JH
38ifdef quick
39 QUICK = $(quick)
40endif
41
42QUICK ?= false
43AUTOGEN ?= false
44
91b469d8 45ifneq ($(shell awk --version 2>/dev/null),)
33e83aaa
JH
46 AWK=awk
47else
48 AWK=cat && test
49endif
50
51OK_STRING=$(OK_COLOR)[OK]$(NO_COLOR)\n
52ERROR_STRING=$(ERROR_COLOR)[ERRORS]$(NO_COLOR)\n
53WARN_STRING=$(WARN_COLOR)[WARNINGS]$(NO_COLOR)\n
d9e4dad0
JH
54
55ifndef $(SILENT)
56 SILENT = false
57endif
58
33e83aaa 59TAB_LOG = printf "\n$$LOG\n\n" | $(AWK) '{ sub(/^/," | "); print }'
d9e4dad0 60TAB_LOG_PLAIN = printf "$$LOG\n"
33e83aaa 61AWK_STATUS = $(AWK) '{ printf " %-10s\n", $$1; }'
7db2ec15 62AWK_CMD = $(AWK) '{ printf "%-99s", $$0; }'
dd770547 63PRINT_ERROR = ($(SILENT) ||printf " $(ERROR_STRING)" | $(AWK_STATUS)) && $(TAB_LOG) && exit 1
33e83aaa 64PRINT_WARNING = ($(SILENT) || printf " $(WARN_STRING)" | $(AWK_STATUS)) && $(TAB_LOG)
dd770547 65PRINT_ERROR_PLAIN = ($(SILENT) ||printf " $(ERROR_STRING)" | $(AWK_STATUS)) && $(TAB_LOG_PLAIN) && exit 1
33e83aaa
JH
66PRINT_WARNING_PLAIN = ($(SILENT) || printf " $(WARN_STRING)" | $(AWK_STATUS)) && $(TAB_LOG_PLAIN)
67PRINT_OK = $(SILENT) || printf " $(OK_STRING)" | $(AWK_STATUS)
d9e4dad0 68BUILD_CMD = LOG=$$($(CMD) 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING); else $(PRINT_OK); fi;
a074364c 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.
4d4f7684 74EXTRAINCDIRS += $(subst :, ,$(VPATH))
a074364c 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
82CSTANDARD = -std=gnu99
83
84
85# Place -D or -U options here for C sources
a074364c 86CDEFS += $(OPT_DEFS)
87
88
89# Place -D or -U options here for ASM sources
a074364c 90ADEFS += $(OPT_DEFS)
91
92
93# Place -D or -U options here for C++ sources
a074364c 94#CPPDEFS += -D__STDC_LIMIT_MACROS
95#CPPDEFS += -D__STDC_CONSTANT_MACROS
96CPPDEFS += $(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
4d4f7684 107CFLAGS += -g$(DEBUG)
a074364c 108CFLAGS += $(CDEFS)
109CFLAGS += -O$(OPT)
d9e4dad0
JH
110# add color
111ifeq ($(COLOR),true)
13bb6b4b 112ifeq ("$(shell echo "int main(){}" | $(CC) -fdiagnostics-color -x c - -o /dev/null 2>&1)", "")
d9e4dad0 113 CFLAGS+= -fdiagnostics-color
d9e4dad0
JH
114endif
115endif
a074364c 116CFLAGS += -Wall
117CFLAGS += -Wstrict-prototypes
118#CFLAGS += -mshort-calls
119#CFLAGS += -fno-unit-at-a-time
120#CFLAGS += -Wundef
121#CFLAGS += -Wunreachable-code
122#CFLAGS += -Wsign-compare
123CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
124CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
125CFLAGS += $(CSTANDARD)
126ifdef CONFIG_H
127 CFLAGS += -include $(CONFIG_H)
128endif
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
4d4f7684 138CPPFLAGS += -g$(DEBUG)
a074364c 139CPPFLAGS += $(CPPDEFS)
140CPPFLAGS += -O$(OPT)
a074364c 141# to supress "warning: only initialized variables can be placed into program memory area"
142CPPFLAGS += -w
143CPPFLAGS += -Wall
144CPPFLAGS += -Wundef
145#CPPFLAGS += -mshort-calls
146#CPPFLAGS += -fno-unit-at-a-time
147#CPPFLAGS += -Wstrict-prototypes
148#CPPFLAGS += -Wunreachable-code
149#CPPFLAGS += -Wsign-compare
150CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
151CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
152#CPPFLAGS += $(CSTANDARD)
153ifdef CONFIG_H
154 CPPFLAGS += -include $(CONFIG_H)
155endif
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]
e175b8d5 165# -listing-cont-lines: Sets the maximum number of continuation lines of hex
a074364c 166# dump that will be displayed for a given single line of source input.
4d4f7684 167ASFLAGS += $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
a074364c 168ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
169ifdef CONFIG_H
170 ASFLAGS += -include $(CONFIG_H)
171endif
a074364c 172
173#---------------- Library Options ----------------
174# Minimalistic printf version
175PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
176
177# Floating point printf version (requires MATH_LIB = -lm below)
178PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
179
180# If this is left blank, then it will use the Standard printf version.
e175b8d5 181PRINTF_LIB =
a074364c 182#PRINTF_LIB = $(PRINTF_LIB_MIN)
183#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
184
185
186# Minimalistic scanf version
187SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
188
189# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
190SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
191
192# If this is left blank, then it will use the Standard scanf version.
e175b8d5 193SCANF_LIB =
a074364c 194#SCANF_LIB = $(SCANF_LIB_MIN)
195#SCANF_LIB = $(SCANF_LIB_FLOAT)
196
197
198MATH_LIB = -lm
199
200
a074364c 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#
4d4f7684 209LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref
a074364c 210#LDFLAGS += -Wl,--relax
a074364c 211LDFLAGS += $(EXTMEMOPTS)
212LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
213LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
214#LDFLAGS += -T linker_script.x
215# You can give EXTRALDFLAGS at 'make' command line.
216LDFLAGS += $(EXTRALDFLAGS)
217
a074364c 218# Define programs and commands.
219SHELL = sh
a074364c 220REMOVE = rm -f
221REMOVEDIR = rmdir
222COPY = cp
223WINSHELL = cmd
d9e4dad0 224SECHO = $(SILENT) || echo
a074364c 225
226# Define Messages
227# English
228MSG_ERRORS_NONE = Errors: none
229MSG_BEGIN = -------- begin --------
230MSG_END = -------- end --------
e175b8d5 231MSG_SIZE_BEFORE = Size before:
a074364c 232MSG_SIZE_AFTER = Size after:
233MSG_COFF = Converting to AVR COFF:
234MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
235MSG_FLASH = Creating load file for Flash:
236MSG_EEPROM = Creating load file for EEPROM:
f9a6e34c 237MSG_BIN = Creating binary load file for Flash:
a074364c 238MSG_EXTENDED_LISTING = Creating Extended Listing:
239MSG_SYMBOL_TABLE = Creating Symbol Table:
240MSG_LINKING = Linking:
d9e4dad0
JH
241MSG_COMPILING = Compiling:
242MSG_COMPILING_CPP = Compiling:
a074364c 243MSG_ASSEMBLING = Assembling:
244MSG_CLEANING = Cleaning project:
245MSG_CREATING_LIBRARY = Creating library:
1b319151 246MSG_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
a074364c 252
253
a074364c 254# Define all object files.
255OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC))))
256
257# Define all listing files.
258LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst %.S,$(OBJDIR)/%.lst,$(SRC))))
259
260
261# Compiler flags to generate dependency files.
262#GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
e8e300d5 263GENDEPFLAGS = -MMD -MP -MF $(BUILD_DIR)/.dep/$(subst /,_,$(subst $(BUILD_DIR)/,,$@)).d
a074364c 264
265
266# Combine all necessary flags and optional flags.
267# Add target processor to flags.
268# You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar
4d4f7684 269ALL_CFLAGS = $(MCUFLAGS) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
270ALL_CPPFLAGS = $(MCUFLAGS) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
271ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
a074364c 272
a074364c 273# Default target.
b86b0480 274all: build sizeafter
d9e4dad0
JH
275
276# Quick make that doesn't clean
b86b0480 277quick: build sizeafter
a074364c 278
279# Change the build target to build a HEX file or a library.
d9e4dad0
JH
280build: elf hex
281#build: elf hex eep lss sym
a074364c 282#build: lib
283
284
d9e4dad0
JH
285elf: $(BUILD_DIR)/$(TARGET).elf
286hex: $(BUILD_DIR)/$(TARGET).hex
287eep: $(BUILD_DIR)/$(TARGET).eep
288lss: $(BUILD_DIR)/$(TARGET).lss
289sym: $(BUILD_DIR)/$(TARGET).sym
a074364c 290LIBNAME=lib$(TARGET).a
291lib: $(LIBNAME)
292
b86b0480 293check_submodule:
1b319151 294 git submodule status --recursive | \
295 while IFS= read -r x; do \
296 case "$$x" in \
297 \ *) ;; \
298 *) printf "$(MSG_SUBMODULE_DIRTY)";break;; \
299 esac \
300 done
a074364c 301
a074364c 302# Display size of file.
303HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
304#ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
d9e4dad0 305ELFSIZE = $(SIZE) $(BUILD_DIR)/$(TARGET).elf
a074364c 306
307sizebefore:
d9e4dad0
JH
308 @if test -f $(TARGET).hex; then $(SECHO) $(MSG_SIZE_BEFORE); $(SILENT) || $(HEXSIZE); \
309 2>/dev/null; $(SECHO); fi
a074364c 310
b86b0480 311sizeafter: $(BUILD_DIR)/$(TARGET).hex
d9e4dad0
JH
312 @if test -f $(TARGET).hex; then $(SECHO); $(SECHO) $(MSG_SIZE_AFTER); $(SILENT) || $(HEXSIZE); \
313 2>/dev/null; $(SECHO); fi
314 # test file sizes eventually
33e83aaa 315 # @if [[ $($(SIZE) --target=$(FORMAT) $(TARGET).hex | $(AWK) 'NR==2 {print "0x"$5}') -gt 0x200 ]]; then $(SECHO) "File is too big!"; fi
a074364c 316
317# Display compiler version information.
e175b8d5 318gccversion :
d9e4dad0 319 @$(SILENT) || $(CC) --version
a074364c 320
a074364c 321# Create final output files (.hex, .eep) from ELF output file.
322%.hex: %.elf
d9e4dad0 323 @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD)
4d4f7684 324 $(eval CMD=$(HEX) $< $@)
d9e4dad0 325 @$(BUILD_CMD)
215c2119
JH
326 @if $(AUTOGEN); then \
327 $(SILENT) || printf "Copying $(TARGET).hex to keymaps/$(KEYMAP)/$(KEYBOARD)_$(KEYMAP).hex\n"; \
328 $(COPY) $@ $(KEYMAP_PATH)/$(KEYBOARD)_$(KEYMAP).hex; \
329 else \
330 $(COPY) $@ $(TARGET).hex; \
331 fi
a074364c 332
333%.eep: %.elf
d9e4dad0 334 @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD)
4d4f7684 335 $(eval CMD=$(EEP) $< $@ || exit 0)
d9e4dad0 336 @$(BUILD_CMD)
a074364c 337
338# Create extended listing file from ELF output file.
339%.lss: %.elf
d9e4dad0
JH
340 @$(SILENT) || printf "$(MSG_EXTENDED_LISTING) $@" | $(AWK_CMD)
341 $(eval CMD=$(OBJDUMP) -h -S -z $< > $@)
342 @$(BUILD_CMD)
a074364c 343
344# Create a symbol table from ELF output file.
345%.sym: %.elf
d9e4dad0
JH
346 @$(SILENT) || printf "$(MSG_SYMBOL_TABLE) $@" | $(AWK_CMD)
347 $(eval CMD=$(NM) -n $< > $@ )
348 @$(BUILD_CMD)
a074364c 349
f9a6e34c
FS
350%.bin: %.elf
351 @$(SILENT) || printf "$(MSG_BIN) $@" | $(AWK_CMD)
352 $(eval CMD=$(BIN) $< $@ || exit 0)
353 @$(BUILD_CMD)
354
a074364c 355# Create library from object files.
d9e4dad0 356.SECONDARY : $(BUILD_DIR)/$(TARGET).a
a074364c 357.PRECIOUS : $(OBJ)
358%.a: $(OBJ)
d9e4dad0
JH
359 @$(SILENT) || printf "$(MSG_CREATING_LIBRARY) $@" | $(AWK_CMD)
360 $(eval CMD=$(AR) $@ $(OBJ) )
361 @$(BUILD_CMD)
a074364c 362
6911ead0
FS
363BEGIN = gccversion check_submodule sizebefore
364
a074364c 365# Link: create ELF output file from object files.
d9e4dad0 366.SECONDARY : $(BUILD_DIR)/$(TARGET).elf
a074364c 367.PRECIOUS : $(OBJ)
6911ead0 368%.elf: $(OBJ) | $(BEGIN)
d9e4dad0 369 @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD)
6911ead0 370 $(eval CMD=$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS))
d9e4dad0 371 @$(BUILD_CMD)
a074364c 372
373# Compile: create object files from C source files.
6911ead0 374$(OBJDIR)/%.o : %.c | $(BEGIN)
d9e4dad0
JH
375 @mkdir -p $(@D)
376 @$(SILENT) || printf "$(MSG_COMPILING) $<" | $(AWK_CMD)
377 $(eval CMD=$(CC) -c $(ALL_CFLAGS) $< -o $@)
378 @$(BUILD_CMD)
a074364c 379
380# Compile: create object files from C++ source files.
6911ead0 381$(OBJDIR)/%.o : %.cpp | $(BEGIN)
d9e4dad0
JH
382 @mkdir -p $(@D)
383 @$(SILENT) || printf "$(MSG_COMPILING_CPP) $<" | $(AWK_CMD)
215c2119 384 $(eval CMD=$(CC) -c $(ALL_CPPFLAGS) $< -o $@)
d9e4dad0 385 @$(BUILD_CMD)
a074364c 386
387# Compile: create assembler files from C source files.
6911ead0 388%.s : %.c | $(BEGIN)
d9e4dad0
JH
389 @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
390 $(eval CMD=$(CC) -S $(ALL_CFLAGS) $< -o $@)
391 @$(BUILD_CMD)
a074364c 392
393# Compile: create assembler files from C++ source files.
6911ead0 394%.s : %.cpp | $(BEGIN)
d9e4dad0
JH
395 @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
396 $(eval CMD=$(CC) -S $(ALL_CPPFLAGS) $< -o $@)
397 @$(BUILD_CMD)
a074364c 398
399# Assemble: create object files from assembler source files.
6911ead0 400$(OBJDIR)/%.o : %.S | $(BEGIN)
d9e4dad0
JH
401 @mkdir -p $(@D)
402 @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
403 $(eval CMD=$(CC) -c $(ALL_ASFLAGS) $< -o $@)
404 @$(BUILD_CMD)
a074364c 405
406# Create preprocessed source for use in sending a bug report.
6911ead0 407%.i : %.c | $(BEGIN)
e175b8d5 408 $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@
a074364c 409
a074364c 410# Target: clean project.
b86b0480 411clean:
a074364c 412
413show_path:
414 @echo VPATH=$(VPATH)
415 @echo SRC=$(SRC)
416
4d4f7684 417SUBDIRS := $(filter-out %/util/ %/doc/ %/keymaps/ %/old_keymap_files/,$(dir $(wildcard $(TOP_DIR)/keyboards/**/*/Makefile)))
a8b55f8c
JH
418SUBDIRS := $(SUBDIRS) $(dir $(wildcard $(TOP_DIR)/keyboards/*/.))
419SUBDIRS := $(sort $(SUBDIRS))
420# $(error $(SUBDIRS))
3f6fac47 421all-keyboards-defaults-%:
d9e4dad0
JH
422 @for x in $(SUBDIRS) ; do \
423 printf "Compiling with default: $$x" | $(AWK_CMD); \
3f6fac47 424 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; \
d9e4dad0
JH
425 done
426
3f6fac47 427all-keyboards-defaults: all-keyboards-defaults-all
428
649b33d7 429KEYBOARDS := $(SUBDIRS:$(TOP_DIR)/keyboards/%/=/keyboards/%)
a69d0025 430all-keyboards-all: $(addsuffix -all,$(KEYBOARDS))
431all-keyboards-quick: $(addsuffix -quick,$(KEYBOARDS))
432all-keyboards-clean: $(addsuffix -clean,$(KEYBOARDS))
3f6fac47 433all-keyboards: all-keyboards-all
434
a69d0025 435define make_keyboard
649b33d7 436$(eval KEYBOARD=$(patsubst /keyboards/%,%,$1))
a8b55f8c
JH
437$(eval SUBPROJECT=$(lastword $(subst /, ,$(KEYBOARD))))
438$(eval KEYBOARD=$(firstword $(subst /, ,$(KEYBOARD))))
439$(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/keymaps/*/.))))
440$(eval KEYMAPS+=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/*/.))))
a69d0025 441@for x in $(KEYMAPS) ; do \
a8b55f8c 442 printf "Compiling $(BOLD)$(KEYBOARD)/$(SUBPROJECT)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-118s", $$0; }'; \
a69d0025 443 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; \
444done
445endef
446
447define make_keyboard_helper
448# Just remove the -quick, -all and so on from the first argument and pass it forward
449$(call make_keyboard,$(subst -$2,,$1),$2)
450endef
451
649b33d7 452/keyboards/%-quick:
a69d0025 453 $(call make_keyboard_helper,$@,quick)
649b33d7 454/keyboards/%-all:
a69d0025 455 $(call make_keyboard_helper,$@,all)
649b33d7 456/keyboards/%-clean:
a69d0025 457 $(call make_keyboard_helper,$@,clean)
649b33d7 458/keyboards/%:
a69d0025 459 $(call make_keyboard_helper,$@,all)
460
3f6fac47 461all-keymaps-%:
462 $(eval MAKECONFIG=$(call get_target,all-keymaps,$@))
649b33d7 463 $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/keymaps/*/.))))
d9e4dad0 464 @for x in $(KEYMAPS) ; do \
2d80eee6 465 printf "Compiling $(BOLD)$(KEYBOARD)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-118s", $$0; }'; \
3f6fac47 466 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; \
d9e4dad0
JH
467 done
468
3f6fac47 469all-keymaps: all-keymaps-all
470
b86b0480
FS
471GOAL=$(MAKECMDGOALS)
472ifeq ($(MAKECMDGOALS),)
473GOAL = all
474endif
475CLEANING_GOALS=clean clean_list all
476ifneq ($(findstring $(GOAL),$(CLEANING_GOALS)),)
477$(shell $(REMOVE) -r $(BUILD_DIR) 2>/dev/null)
478$(shell $(REMOVE) -r $(TOP_DIR)/$(BUILD_DIR))
479$(shell $(REMOVE) -r $(KEYBOARD_PATH)/$(BUILD_DIR))
480$(shell if $$SUBPROJECT; then $(REMOVE) -r $(SUBPROJECT_PATH)/$(BUILD_DIR); fi)
481$(shell $(REMOVE) -r $(KEYMAP_PATH)/$(BUILD_DIR))
482endif
483
d9e4dad0
JH
484# Create build directory
485$(shell mkdir $(BUILD_DIR) 2>/dev/null)
a074364c 486
487# Create object files directory
488$(shell mkdir $(OBJDIR) 2>/dev/null)
489
490
491# Include the dependency files.
d9e4dad0 492-include $(shell mkdir $(BUILD_DIR)/.dep 2>/dev/null) $(wildcard $(BUILD_DIR)/.dep/*)
a074364c 493
494
495# Listing of phony targets.
b86b0480 496.PHONY : all quick finish sizebefore sizeafter gccversion \
6911ead0 497build elf hex eep lss sym coff extcoff check_submodule \
a074364c 498clean clean_list debug gdb-config show_path \
d9e4dad0 499program teensy dfu flip dfu-ee flip-ee dfu-start \
3f6fac47 500all-keyboards-defaults all-keyboards all-keymaps \
501all-keyboards-defaults-% all-keyboards-% all-keymaps-%