1 # Hey Emacs, this is a -*- makefile -*-
2 #----------------------------------------------------------------------------
3 # WinAVR Makefile Template written by Eric B. Weddington, Jg Wunsch, et al.
5 # Released to the Public Domain
7 # Additional material for this makefile was written by:
18 # Enable vpath seraching for source files only
19 # Without this, output files, could be read from the wrong .build directories
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)
29 # Output format. (can be srec, ihex, binary)
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.)
42 ERROR_COLOR=\033[31;01m
43 WARN_COLOR=\033[33;01m
50 ifneq ($(shell awk --version 2>/dev/null),)
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
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;
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))
82 # Compiler flag to set the C Standard level.
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
90 # Place -D or -U options here for C sources
94 # Place -D or -U options here for ASM sources
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)
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
117 ifeq ("$(shell echo "int main(){}" | $(CC) -fdiagnostics-color -x c - -o /dev/null 2>&1)", "")
118 CFLAGS+= -fdiagnostics-color
122 CFLAGS += -Wstrict-prototypes
123 #CFLAGS += -mshort-calls
124 #CFLAGS += -fno-unit-at-a-time
126 #CFLAGS += -Wunreachable-code
127 #CFLAGS += -Wsign-compare
128 CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
129 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
130 CFLAGS += $(CSTANDARD)
132 CFLAGS += -include $(CONFIG_H)
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)
146 # to supress "warning: only initialized variables can be placed into program memory area"
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)
159 CPPFLAGS += -include $(CONFIG_H)
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))
175 ASFLAGS += -include $(CONFIG_H)
178 #---------------- Library Options ----------------
179 # Minimalistic printf version
180 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
182 # Floating point printf version (requires MATH_LIB = -lm below)
183 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
185 # If this is left blank, then it will use the Standard printf version.
187 #PRINTF_LIB = $(PRINTF_LIB_MIN)
188 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
191 # Minimalistic scanf version
192 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
194 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
195 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
197 # If this is left blank, then it will use the Standard scanf version.
199 #SCANF_LIB = $(SCANF_LIB_MIN)
200 #SCANF_LIB = $(SCANF_LIB_FLOAT)
206 # List any extra directories to look for libraries here.
207 # Each directory must be seperated by a space.
208 # Use forward slashes for directory separators.
209 # For a directory that has spaces, enclose it in quotes.
214 #---------------- External Memory Options ----------------
216 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
217 # used for variables (.data/.bss) and heap (malloc()).
218 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
220 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
221 # only used for heap (malloc()).
222 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
228 #---------------- Linker Options ----------------
229 # -Wl,...: tell GCC to pass this to linker.
230 # -Map: create map file
231 # --cref: add cross reference to map file
233 # Comennt out "--relax" option to avoid a error such:
234 # (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12'
236 LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref
237 #LDFLAGS += -Wl,--relax
238 LDFLAGS += $(EXTMEMOPTS)
239 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
240 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
241 #LDFLAGS += -T linker_script.x
242 # You can give EXTRALDFLAGS at 'make' command line.
243 LDFLAGS += $(EXTRALDFLAGS)
247 #---------------- Debugging Options ----------------
249 # For simulavr only - target MCU frequency.
250 DEBUG_MFREQ = $(F_CPU)
252 # Set the DEBUG_UI to either gdb or insight.
256 # Set the debugging back-end to either avarice, simulavr.
257 DEBUG_BACKEND = avarice
258 #DEBUG_BACKEND = simulavr
261 GDBINIT_FILE = __avr_gdbinit
263 # When using avarice settings for the JTAG
266 # Debugging port used to communicate between GDB / avarice / simulavr.
269 # Debugging host used to communicate between GDB / avarice / simulavr, normally
270 # just set to localhost unless doing some sort of crazy debugging when
271 # avarice is running on a different computer.
272 DEBUG_HOST = localhost
276 #============================================================================
279 # Define programs and commands.
285 SECHO = $(SILENT) || echo
289 MSG_ERRORS_NONE = Errors: none
290 MSG_BEGIN = -------- begin --------
291 MSG_END = -------- end --------
292 MSG_SIZE_BEFORE = Size before:
293 MSG_SIZE_AFTER = Size after:
294 MSG_COFF = Converting to AVR COFF:
295 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
296 MSG_FLASH = Creating load file for Flash:
297 MSG_EEPROM = Creating load file for EEPROM:
298 MSG_BIN = Creating binary load file for Flash:
299 MSG_EXTENDED_LISTING = Creating Extended Listing:
300 MSG_SYMBOL_TABLE = Creating Symbol Table:
301 MSG_LINKING = Linking:
302 MSG_COMPILING = Compiling:
303 MSG_COMPILING_CPP = Compiling:
304 MSG_ASSEMBLING = Assembling:
305 MSG_CLEANING = Cleaning project:
306 MSG_CREATING_LIBRARY = Creating library:
307 MSG_SUBMODULE_DIRTY = $(WARN_COLOR)WARNING:$(NO_COLOR)\n \
308 Some git sub-modules are out of date or modified, please consider runnning:$(BOLD)\n\
309 git submodule sync --recursive\n\
310 git submodule update --init --recursive$(NO_COLOR)\n\n\
311 You can ignore this warning if you are not compiling any ChibiOS keyboards,\n\
312 or if you have modified the ChibiOS libraries yourself. \n\n
315 # Define all object files.
316 OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC))))
317 # The files in the lib folder are shared between all keymaps, so generate that folder name by removing
318 # the keymap from the name
319 KBOBJDIR=$(subst _$(KEYMAP),,$(OBJDIR))
320 # And fixup the object files to match
321 LIBOBJ = $(foreach v,$(OBJ),$(if $(findstring /lib/,$v),$v))
322 NONLIBOBJ := $(filter-out $(LIBOBJ),$(OBJ))
323 LIBOBJ := $(subst _$(KEYMAP)/,/,$(LIBOBJ))
324 OBJ := $(LIBOBJ) $(NONLIBOBJ)
326 # Define all listing files.
327 LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst %.S,$(OBJDIR)/%.lst,$(SRC))))
330 # Compiler flags to generate dependency files.
331 #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
332 GENDEPFLAGS = -MMD -MP -MF $(patsubst %.o,%.td,$@)
335 # Combine all necessary flags and optional flags.
336 # Add target processor to flags.
337 # You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar
338 ALL_CFLAGS = $(MCUFLAGS) $(CFLAGS) $(EXTRAFLAGS)
339 ALL_CPPFLAGS = $(MCUFLAGS) -x c++ $(CPPFLAGS) $(EXTRAFLAGS)
340 ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
342 MOVE_DEP = mv -f $(patsubst %.o,%.td,$@) $(patsubst %.o,%.d,$@)
347 # Change the build target to build a HEX file or a library.
349 #build: elf hex eep lss sym
353 elf: $(BUILD_DIR)/$(TARGET).elf
354 hex: $(BUILD_DIR)/$(TARGET).hex
355 eep: $(BUILD_DIR)/$(TARGET).eep
356 lss: $(BUILD_DIR)/$(TARGET).lss
357 sym: $(BUILD_DIR)/$(TARGET).sym
358 LIBNAME=lib$(TARGET).a
362 git submodule status --recursive | \
363 while IFS= read -r x; do \
366 *) printf "$(MSG_SUBMODULE_DIRTY)";break;; \
370 # Display size of file.
371 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
372 #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
373 ELFSIZE = $(SIZE) $(BUILD_DIR)/$(TARGET).elf
376 @if test -f $(TARGET).hex; then $(SECHO) $(MSG_SIZE_BEFORE); $(SILENT) || $(HEXSIZE); \
377 2>/dev/null; $(SECHO); fi
379 sizeafter: $(BUILD_DIR)/$(TARGET).hex
380 @if test -f $(TARGET).hex; then $(SECHO); $(SECHO) $(MSG_SIZE_AFTER); $(SILENT) || $(HEXSIZE); \
381 2>/dev/null; $(SECHO); fi
382 # test file sizes eventually
383 # @if [[ $($(SIZE) --target=$(FORMAT) $(TARGET).hex | $(AWK) 'NR==2 {print "0x"$5}') -gt 0x200 ]]; then $(SECHO) "File is too big!"; fi
385 # Display compiler version information.
387 @$(SILENT) || $(CC) --version
391 # Program the device.
392 program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
395 teensy: $(BUILD_DIR)/$(TARGET).hex
396 $(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
398 flip: $(BUILD_DIR)/$(TARGET).hex
399 batchisp -hardware usb -device $(MCU) -operation erase f
400 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(BUILD_DIR)/$(TARGET).hex program
401 batchisp -hardware usb -device $(MCU) -operation start reset 0
403 dfu: $(BUILD_DIR)/$(TARGET).hex sizeafter
404 ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
405 dfu-programmer $(MCU) erase --force
407 dfu-programmer $(MCU) erase
409 dfu-programmer $(MCU) erase
410 dfu-programmer $(MCU) flash $(BUILD_DIR)/$(TARGET).hex
411 dfu-programmer $(MCU) reset
414 ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
415 dfu-programmer $(MCU) erase --force
417 dfu-programmer $(MCU) erase
419 dfu-programmer $(MCU) erase
420 dfu-programmer $(MCU) flash $(KEYMAP_PATH)/compiled.hex
421 dfu-programmer $(MCU) reset
424 dfu-programmer $(MCU) reset
425 dfu-programmer $(MCU) start
427 flip-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
428 $(COPY) $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET)eep.hex
429 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
430 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(BUILD_DIR)/$(TARGET)eep.hex program
431 batchisp -hardware usb -device $(MCU) -operation start reset 0
432 $(REMOVE) $(BUILD_DIR)/$(TARGET)eep.hex
434 dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
435 ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
436 dfu-programmer $(MCU) flash --eeprom $(BUILD_DIR)/$(TARGET).eep
438 dfu-programmer $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep
440 dfu-programmer $(MCU) reset
443 # Generate avr-gdb config/init file which does the following:
444 # define the reset signal, load the target file, connect to target, and set
445 # a breakpoint at main().
447 @$(REMOVE) $(GDBINIT_FILE)
448 @echo define reset >> $(GDBINIT_FILE)
449 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
450 @echo end >> $(GDBINIT_FILE)
451 @echo file $(BUILD_DIR)/$(TARGET).elf >> $(GDBINIT_FILE)
452 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
453 ifeq ($(DEBUG_BACKEND),simulavr)
454 @echo load >> $(GDBINIT_FILE)
456 @echo break main >> $(GDBINIT_FILE)
458 debug: gdb-config $(BUILD_DIR)/$(TARGET).elf
459 ifeq ($(DEBUG_BACKEND), avarice)
460 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
461 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
462 $(BUILD_DIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
463 @$(WINSHELL) /c pause
466 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
467 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
469 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
474 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
475 COFFCONVERT = $(OBJCOPY) --debugging
476 COFFCONVERT += --change-section-address .data-0x800000
477 COFFCONVERT += --change-section-address .bss-0x800000
478 COFFCONVERT += --change-section-address .noinit-0x800000
479 COFFCONVERT += --change-section-address .eeprom-0x810000
483 coff: $(BUILD_DIR)/$(TARGET).elf
484 @$(SECHO) $(MSG_COFF) $(BUILD_DIR)/$(TARGET).cof
485 $(COFFCONVERT) -O coff-avr $< $(BUILD_DIR)/$(TARGET).cof
488 extcoff: $(BUILD_DIR)/$(TARGET).elf
489 @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof
490 $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof
494 # Create final output files (.hex, .eep) from ELF output file.
496 @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD)
497 $(eval CMD=$(HEX) $< $@)
499 @if $(AUTOGEN); then \
500 $(SILENT) || printf "Copying $(TARGET).hex to keymaps/$(KEYMAP)/$(KEYBOARD)_$(KEYMAP).hex\n"; \
501 $(COPY) $@ $(KEYMAP_PATH)/$(KEYBOARD)_$(KEYMAP).hex; \
503 $(COPY) $@ $(TARGET).hex; \
507 @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD)
508 $(eval CMD=$(EEP) $< $@ || exit 0)
511 # Create extended listing file from ELF output file.
513 @$(SILENT) || printf "$(MSG_EXTENDED_LISTING) $@" | $(AWK_CMD)
514 $(eval CMD=$(OBJDUMP) -h -S -z $< > $@)
517 # Create a symbol table from ELF output file.
519 @$(SILENT) || printf "$(MSG_SYMBOL_TABLE) $@" | $(AWK_CMD)
520 $(eval CMD=$(NM) -n $< > $@ )
524 @$(SILENT) || printf "$(MSG_BIN) $@" | $(AWK_CMD)
525 $(eval CMD=$(BIN) $< $@ || exit 0)
528 # Create library from object files.
529 .SECONDARY : $(BUILD_DIR)/$(TARGET).a
532 @$(SILENT) || printf "$(MSG_CREATING_LIBRARY) $@" | $(AWK_CMD)
533 $(eval CMD=$(AR) $@ $(OBJ) )
536 BEGIN = gccversion check_submodule sizebefore
538 # Link: create ELF output file from object files.
539 .SECONDARY : $(BUILD_DIR)/$(TARGET).elf
541 # Note the obj.txt depeendency is there to force linking if a source file is deleted
542 %.elf: $(OBJ) $(OBJDIR)/cflags.txt $(OBJDIR)/ldflags.txt $(OBJDIR)/obj.txt | $(BEGIN)
543 @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD)
544 $(eval CMD=$(CC) $(ALL_CFLAGS) $(filter-out %.txt,$^) --output $@ $(LDFLAGS))
548 # Compile: create object files from C source files.
549 $1/%.o : %.c $1/%.d $1/cflags.txt $1/compiler.txt | $(BEGIN)
551 @$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD)
552 $$(eval CMD=$$(CC) -c $$(ALL_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP))
555 # Compile: create object files from C++ source files.
556 $1/%.o : %.cpp $1/%.d $1/cppflags.txt $1/compiler.txt | $(BEGIN)
558 @$$(SILENT) || printf "$$(MSG_COMPILING_CPP) $$<" | $$(AWK_CMD)
559 $$(eval CMD=$$(CC) -c $$(ALL_CPPFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP))
562 # Assemble: create object files from assembler source files.
563 $1/%.o : %.S $1/asflags.txt $1/compiler.txt | $(BEGIN)
565 @$(SILENT) || printf "$$(MSG_ASSEMBLING) $$<" | $$(AWK_CMD)
566 $$(eval CMD=$$(CC) -c $$(ALL_ASFLAGS) $$< -o $$@)
571 $1/cflags.txt: $1/force
572 echo '$$(ALL_CFLAGS)' | cmp -s - $$@ || echo '$$(ALL_CFLAGS)' > $$@
574 $1/cppflags.txt: $1/force
575 echo '$$(ALL_CPPFLAGS)' | cmp -s - $$@ || echo '$$(ALL_CPPFLAGS)' > $$@
577 $1/asflags.txt: $1/force
578 echo '$$(ALL_ASFLAGS)' | cmp -s - $$@ || echo '$$(ALL_ASFLAGS)' > $$@
580 $1/ldflags.txt: $1/force
581 echo '$$(LDFLAGS)' | cmp -s - $$@ || echo '$$(LDFLAGS)' > $$@
584 echo '$$(OBJ)' | cmp -s - $$@ || echo '$$(OBJ)' > $$@
586 $1/compiler.txt: $1/force
587 $$(CC) --version | cmp -s - $$@ || $$(CC) --version > $$@
590 # We have to use static rules for the .d files for some reason
591 DEPS = $(patsubst %.o,%.d,$(OBJ))
594 # Empty rule to force recompilation if the .d file is missing
597 # Since the object files could be in two different folders, generate
598 # separate rules for them, rather than having too generic rules
599 $(eval $(call GEN_OBJRULE,$(OBJDIR)))
600 $(eval $(call GEN_OBJRULE,$(KBOBJDIR)))
602 # Compile: create assembler files from C source files.
604 @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
605 $(eval CMD=$(CC) -S $(ALL_CFLAGS) $< -o $@)
608 # Compile: create assembler files from C++ source files.
609 %.s : %.cpp | $(BEGIN)
610 @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
611 $(eval CMD=$(CC) -S $(ALL_CPPFLAGS) $< -o $@)
614 # Create preprocessed source for use in sending a bug report.
616 $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@
618 # Target: clean project.
620 $(REMOVE) -r $(OBJDIR) 2>/dev/null
621 $(REMOVE) -r $(KBOBJDIR) 2>/dev/null
622 $(REMOVE) $(BUILD_DIR)/$(TARGET).*
628 SUBDIRS := $(filter-out %/util/ %/doc/ %/keymaps/ %/old_keymap_files/,$(dir $(wildcard $(TOP_DIR)/keyboards/**/*/Makefile)))
629 SUBDIRS := $(SUBDIRS) $(dir $(wildcard $(TOP_DIR)/keyboards/*/.))
630 SUBDIRS := $(sort $(SUBDIRS))
631 # $(error $(SUBDIRS))
632 all-keyboards-defaults-%:
633 @for x in $(SUBDIRS) ; do \
634 printf "Compiling with default: $$x" | $(AWK_CMD); \
635 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; \
638 all-keyboards-defaults: all-keyboards-defaults-all
640 KEYBOARDS := $(SUBDIRS:$(TOP_DIR)/keyboards/%/=/keyboards/%)
641 all-keyboards-all: $(addsuffix -all,$(KEYBOARDS))
642 all-keyboards-clean: $(addsuffix -clean,$(KEYBOARDS))
643 all-keyboards: all-keyboards-all
646 $(eval KEYBOARD=$(patsubst /keyboards/%,%,$1))
647 $(eval SUBPROJECT=$(lastword $(subst /, ,$(KEYBOARD))))
648 $(eval KEYBOARD=$(firstword $(subst /, ,$(KEYBOARD))))
649 $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/keymaps/*/.))))
650 $(eval KEYMAPS+=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/*/.))))
651 @for x in $(KEYMAPS) ; do \
652 printf "Compiling $(BOLD)$(KEYBOARD)/$(SUBPROJECT)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-118s", $$0; }'; \
653 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; \
657 define make_keyboard_helper
658 # Just remove the -all and so on from the first argument and pass it forward
659 $(call make_keyboard,$(subst -$2,,$1),$2)
663 $(call make_keyboard_helper,$@,all)
665 $(call make_keyboard_helper,$@,clean)
667 $(call make_keyboard_helper,$@,all)
670 $(eval MAKECONFIG=$(call get_target,all-keymaps,$@))
671 $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/keymaps/*/.))))
672 @for x in $(KEYMAPS) ; do \
673 printf "Compiling $(BOLD)$(KEYBOARD)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-118s", $$0; }'; \
674 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; \
677 all-keymaps: all-keymaps-all
679 # Create build directory
680 $(shell mkdir $(BUILD_DIR) 2>/dev/null)
682 # Create object files directory
683 $(shell mkdir $(OBJDIR) 2>/dev/null)
684 $(shell mkdir $(KBOBJDIR) 2>/dev/null)
686 # Include the dependency files.
687 -include $(patsubst %.o,%.d,$(OBJ))
690 # Listing of phony targets.
691 .PHONY : all finish sizebefore sizeafter gccversion \
692 build elf hex eep lss sym coff extcoff check_submodule \
693 clean clean_list debug gdb-config show_path \
694 program teensy dfu flip dfu-ee flip-ee dfu-start \
695 all-keyboards-defaults all-keyboards all-keymaps \
696 all-keyboards-defaults-% all-keyboards-% all-keymaps-%