]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/rules.mk
Merge pull request #438 from tkuichooseyou/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
19
20 # Output format. (can be srec, ihex, binary)
21 FORMAT = ihex
22
23 BUILD_DIR = .build
24
25 # Object files directory
26 #     To put object files in current directory, use a dot (.), do NOT make
27 #     this an empty or blank macro!
28 OBJDIR = $(BUILD_DIR)/obj_$(TARGET)
29
30
31 # Optimization level, can be [0, 1, 2, 3, s].
32 #     0 = turn off optimization. s = optimize for size.
33 #     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
34 OPT = s
35
36
37 # Debugging format.
38 #     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
39 #     AVR Studio 4.10 requires dwarf-2.
40 #     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
41 DEBUG = dwarf-2
42
43 COLOR ?= true
44
45 ifeq ($(COLOR),true)
46         NO_COLOR=\033[0m
47         OK_COLOR=\033[32;01m
48         ERROR_COLOR=\033[31;01m
49         WARN_COLOR=\033[33;01m
50         BLUE=\033[0;34m
51         BOLD=\033[1m
52 endif
53
54 ifneq ($(shell awk --version 2>/dev/null),)
55         AWK=awk
56 else
57         AWK=cat && test
58 endif
59
60 OK_STRING=$(OK_COLOR)[OK]$(NO_COLOR)\n
61 ERROR_STRING=$(ERROR_COLOR)[ERRORS]$(NO_COLOR)\n
62 WARN_STRING=$(WARN_COLOR)[WARNINGS]$(NO_COLOR)\n
63
64 ifndef $(SILENT)
65         SILENT = false
66 endif
67
68 TAB_LOG = printf "\n$$LOG\n\n" | $(AWK) '{ sub(/^/," | "); print }'
69 TAB_LOG_PLAIN = printf "$$LOG\n"
70 AWK_STATUS = $(AWK) '{ printf " %-10s\n", $$1; }'
71 AWK_CMD = $(AWK) '{ printf "%-69s", $$0; }'
72 PRINT_ERROR = ($(SILENT) ||printf " $(ERROR_STRING)" | $(AWK_STATUS)) && $(TAB_LOG) && false
73 PRINT_WARNING = ($(SILENT) || printf " $(WARN_STRING)" | $(AWK_STATUS)) && $(TAB_LOG)
74 PRINT_ERROR_PLAIN = ($(SILENT) ||printf " $(ERROR_STRING)" | $(AWK_STATUS)) && $(TAB_LOG_PLAIN) && false
75 PRINT_WARNING_PLAIN = ($(SILENT) || printf " $(WARN_STRING)" | $(AWK_STATUS)) && $(TAB_LOG_PLAIN)
76 PRINT_OK = $(SILENT) || printf " $(OK_STRING)" | $(AWK_STATUS)
77 BUILD_CMD = LOG=$$($(CMD) 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING); else $(PRINT_OK); fi;
78
79 # List any extra directories to look for include files here.
80 #     Each directory must be seperated by a space.
81 #     Use forward slashes for directory separators.
82 #     For a directory that has spaces, enclose it in quotes.
83 EXTRAINCDIRS = $(subst :, ,$(VPATH))
84
85
86 # Compiler flag to set the C Standard level.
87 #     c89   = "ANSI" C
88 #     gnu89 = c89 plus GCC extensions
89 #     c99   = ISO C99 standard (not yet fully implemented)
90 #     gnu99 = c99 plus GCC extensions
91 CSTANDARD = -std=gnu99
92
93
94 # Place -D or -U options here for C sources
95 CDEFS = -DF_CPU=$(F_CPU)UL
96 CDEFS += $(OPT_DEFS)
97
98
99 # Place -D or -U options here for ASM sources
100 ADEFS = -DF_CPU=$(F_CPU)
101 ADEFS += $(OPT_DEFS)
102
103
104 # Place -D or -U options here for C++ sources
105 CPPDEFS = -DF_CPU=$(F_CPU)UL
106 #CPPDEFS += -D__STDC_LIMIT_MACROS
107 #CPPDEFS += -D__STDC_CONSTANT_MACROS
108 CPPDEFS += $(OPT_DEFS)
109
110
111
112 #---------------- Compiler Options C ----------------
113 #  -g*:          generate debugging information
114 #  -O*:          optimization level
115 #  -f...:        tuning, see GCC manual and avr-libc documentation
116 #  -Wall...:     warning level
117 #  -Wa,...:      tell GCC to pass this to the assembler.
118 #    -adhlns...: create assembler listing
119 CFLAGS = -g$(DEBUG)
120 CFLAGS += $(CDEFS)
121 CFLAGS += -O$(OPT)
122 CFLAGS += -funsigned-char
123 CFLAGS += -funsigned-bitfields
124 CFLAGS += -ffunction-sections
125 CFLAGS += -fdata-sections
126 CFLAGS += -fno-inline-small-functions
127 CFLAGS += -fpack-struct
128 CFLAGS += -fshort-enums
129 CFLAGS += -fno-strict-aliasing
130 # add color
131 ifeq ($(COLOR),true)
132 ifeq ("$(shell echo "int main(){}" | $(CC) -fdiagnostics-color -x c - -o /dev/null 2>&1)", "")
133         CFLAGS+= -fdiagnostics-color
134 endif
135 endif
136 CFLAGS += -Wall
137 CFLAGS += -Wstrict-prototypes
138 #CFLAGS += -mshort-calls
139 #CFLAGS += -fno-unit-at-a-time
140 #CFLAGS += -Wundef
141 #CFLAGS += -Wunreachable-code
142 #CFLAGS += -Wsign-compare
143 CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
144 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
145 CFLAGS += $(CSTANDARD)
146 ifdef CONFIG_H
147     CFLAGS += -include $(CONFIG_H)
148 endif
149
150
151 #---------------- Compiler Options C++ ----------------
152 #  -g*:          generate debugging information
153 #  -O*:          optimization level
154 #  -f...:        tuning, see GCC manual and avr-libc documentation
155 #  -Wall...:     warning level
156 #  -Wa,...:      tell GCC to pass this to the assembler.
157 #    -adhlns...: create assembler listing
158 CPPFLAGS = -g$(DEBUG)
159 CPPFLAGS += $(CPPDEFS)
160 CPPFLAGS += -O$(OPT)
161 CPPFLAGS += -funsigned-char
162 CPPFLAGS += -funsigned-bitfields
163 CPPFLAGS += -fpack-struct
164 CPPFLAGS += -fshort-enums
165 CPPFLAGS += -fno-exceptions
166 CPPFLAGS += -ffunction-sections
167 CPPFLAGS += -fdata-sections
168 # to supress "warning: only initialized variables can be placed into program memory area"
169 CPPFLAGS += -w
170 CPPFLAGS += -Wall
171 CPPFLAGS += -Wundef
172 #CPPFLAGS += -mshort-calls
173 #CPPFLAGS += -fno-unit-at-a-time
174 #CPPFLAGS += -Wstrict-prototypes
175 #CPPFLAGS += -Wunreachable-code
176 #CPPFLAGS += -Wsign-compare
177 CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
178 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
179 #CPPFLAGS += $(CSTANDARD)
180 ifdef CONFIG_H
181     CPPFLAGS += -include $(CONFIG_H)
182 endif
183
184
185 #---------------- Assembler Options ----------------
186 #  -Wa,...:   tell GCC to pass this to the assembler.
187 #  -adhlns:   create listing
188 #  -gstabs:   have the assembler create line number information; note that
189 #             for use in COFF files, additional information about filenames
190 #             and function names needs to be present in the assembler source
191 #             files -- see avr-libc docs [FIXME: not yet described there]
192 #  -listing-cont-lines: Sets the maximum number of continuation lines of hex
193 #       dump that will be displayed for a given single line of source input.
194 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
195 ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
196 ifdef CONFIG_H
197     ASFLAGS += -include $(CONFIG_H)
198 endif
199
200 #---------------- Library Options ----------------
201 # Minimalistic printf version
202 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
203
204 # Floating point printf version (requires MATH_LIB = -lm below)
205 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
206
207 # If this is left blank, then it will use the Standard printf version.
208 PRINTF_LIB =
209 #PRINTF_LIB = $(PRINTF_LIB_MIN)
210 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
211
212
213 # Minimalistic scanf version
214 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
215
216 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
217 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
218
219 # If this is left blank, then it will use the Standard scanf version.
220 SCANF_LIB =
221 #SCANF_LIB = $(SCANF_LIB_MIN)
222 #SCANF_LIB = $(SCANF_LIB_FLOAT)
223
224
225 MATH_LIB = -lm
226
227
228 # List any extra directories to look for libraries here.
229 #     Each directory must be seperated by a space.
230 #     Use forward slashes for directory separators.
231 #     For a directory that has spaces, enclose it in quotes.
232 EXTRALIBDIRS =
233
234
235
236 #---------------- External Memory Options ----------------
237
238 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
239 # used for variables (.data/.bss) and heap (malloc()).
240 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
241
242 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
243 # only used for heap (malloc()).
244 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
245
246 EXTMEMOPTS =
247
248
249
250 #---------------- Linker Options ----------------
251 #  -Wl,...:     tell GCC to pass this to linker.
252 #    -Map:      create map file
253 #    --cref:    add cross reference to  map file
254 #
255 # Comennt out "--relax" option to avoid a error such:
256 #       (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12'
257 #
258 LDFLAGS = -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref
259 #LDFLAGS += -Wl,--relax
260 LDFLAGS += -Wl,--gc-sections
261 LDFLAGS += $(EXTMEMOPTS)
262 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
263 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
264 #LDFLAGS += -T linker_script.x
265 # You can give EXTRALDFLAGS at 'make' command line.
266 LDFLAGS += $(EXTRALDFLAGS)
267
268
269
270 #---------------- Debugging Options ----------------
271
272 # For simulavr only - target MCU frequency.
273 DEBUG_MFREQ = $(F_CPU)
274
275 # Set the DEBUG_UI to either gdb or insight.
276 # DEBUG_UI = gdb
277 DEBUG_UI = insight
278
279 # Set the debugging back-end to either avarice, simulavr.
280 DEBUG_BACKEND = avarice
281 #DEBUG_BACKEND = simulavr
282
283 # GDB Init Filename.
284 GDBINIT_FILE = __avr_gdbinit
285
286 # When using avarice settings for the JTAG
287 JTAG_DEV = /dev/com1
288
289 # Debugging port used to communicate between GDB / avarice / simulavr.
290 DEBUG_PORT = 4242
291
292 # Debugging host used to communicate between GDB / avarice / simulavr, normally
293 #     just set to localhost unless doing some sort of crazy debugging when
294 #     avarice is running on a different computer.
295 DEBUG_HOST = localhost
296
297
298
299 #============================================================================
300
301
302 # Define programs and commands.
303 SHELL = sh
304 CC = avr-gcc
305 OBJCOPY = avr-objcopy
306 OBJDUMP = avr-objdump
307 SIZE = avr-size
308 AR = avr-ar rcs
309 NM = avr-nm
310 REMOVE = rm -f
311 REMOVEDIR = rmdir
312 COPY = cp
313 WINSHELL = cmd
314 SECHO = $(SILENT) || echo
315 # Autodecct teensy loader
316 ifneq (, $(shell which teensy-loader-cli 2>/dev/null))
317   TEENSY_LOADER_CLI = teensy-loader-cli
318 else
319   TEENSY_LOADER_CLI = teensy_loader_cli
320 endif
321
322 # Define Messages
323 # English
324 MSG_ERRORS_NONE = Errors: none
325 MSG_BEGIN = -------- begin --------
326 MSG_END = --------  end  --------
327 MSG_SIZE_BEFORE = Size before:
328 MSG_SIZE_AFTER = Size after:
329 MSG_COFF = Converting to AVR COFF:
330 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
331 MSG_FLASH = Creating load file for Flash:
332 MSG_EEPROM = Creating load file for EEPROM:
333 MSG_EXTENDED_LISTING = Creating Extended Listing:
334 MSG_SYMBOL_TABLE = Creating Symbol Table:
335 MSG_LINKING = Linking:
336 MSG_COMPILING = Compiling:
337 MSG_COMPILING_CPP = Compiling:
338 MSG_ASSEMBLING = Assembling:
339 MSG_CLEANING = Cleaning project:
340 MSG_CREATING_LIBRARY = Creating library:
341
342
343
344
345 # Define all object files.
346 OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC))))
347
348 # Define all listing files.
349 LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst %.S,$(OBJDIR)/%.lst,$(SRC))))
350
351
352 # Compiler flags to generate dependency files.
353 #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
354 GENDEPFLAGS = -MMD -MP -MF $(BUILD_DIR)/.dep/$(subst /,_,$@).d
355
356
357 # Combine all necessary flags and optional flags.
358 # Add target processor to flags.
359 # You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar
360 ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
361 ALL_CPPFLAGS = -mmcu=$(MCU) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
362 ALL_ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
363
364 # Default target.
365 all:
366         @$(MAKE) begin
367         @$(MAKE) gccversion
368         @$(MAKE) sizebefore
369         @$(MAKE) clean_list # force clean each time
370         @$(MAKE) build
371         @$(MAKE) sizeafter
372         @$(MAKE) end
373
374 # Quick make that doesn't clean
375 quick:
376         @$(MAKE) begin
377         @$(MAKE) gccversion
378         @$(MAKE) sizebefore
379         @$(MAKE) build
380         @$(MAKE) sizeafter
381         @$(MAKE) end
382
383 # Change the build target to build a HEX file or a library.
384 build: elf hex
385 #build: elf hex eep lss sym
386 #build: lib
387
388
389 elf: $(BUILD_DIR)/$(TARGET).elf
390 hex: $(BUILD_DIR)/$(TARGET).hex
391 eep: $(BUILD_DIR)/$(TARGET).eep
392 lss: $(BUILD_DIR)/$(TARGET).lss
393 sym: $(BUILD_DIR)/$(TARGET).sym
394 LIBNAME=lib$(TARGET).a
395 lib: $(LIBNAME)
396
397
398
399 # Eye candy.
400 # AVR Studio 3.x does not check make's exit code but relies on
401 # the following magic strings to be generated by the compile job.
402 begin:
403         @$(SECHO) $(MSG_BEGIN)
404
405 end:
406         @$(SECHO) $(MSG_END)
407
408
409 # Display size of file.
410 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
411 #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
412 ELFSIZE = $(SIZE) $(BUILD_DIR)/$(TARGET).elf
413
414 sizebefore:
415         @if test -f $(TARGET).hex; then $(SECHO) $(MSG_SIZE_BEFORE); $(SILENT) || $(HEXSIZE); \
416         2>/dev/null; $(SECHO); fi
417
418 sizeafter:
419         @if test -f $(TARGET).hex; then $(SECHO); $(SECHO) $(MSG_SIZE_AFTER); $(SILENT) || $(HEXSIZE); \
420         2>/dev/null; $(SECHO); fi
421         # test file sizes eventually
422         # @if [[ $($(SIZE) --target=$(FORMAT) $(TARGET).hex | $(AWK) 'NR==2 {print "0x"$5}') -gt 0x200 ]]; then $(SECHO) "File is too big!"; fi
423
424 # Display compiler version information.
425 gccversion :
426         @$(SILENT) || $(CC) --version
427
428
429
430 # Program the device.
431 program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
432         $(PROGRAM_CMD)
433
434 teensy: $(BUILD_DIR)/$(TARGET).hex
435         $(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
436
437 flip: $(BUILD_DIR)/$(TARGET).hex
438         batchisp -hardware usb -device $(MCU) -operation erase f
439         batchisp -hardware usb -device $(MCU) -operation loadbuffer $(BUILD_DIR)/$(TARGET).hex program
440         batchisp -hardware usb -device $(MCU) -operation start reset 0
441
442 dfu: $(BUILD_DIR)/$(TARGET).hex sizeafter
443 ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
444         dfu-programmer $(MCU) erase --force
445 else
446         dfu-programmer $(MCU) erase
447 endif
448         dfu-programmer $(MCU) flash $(BUILD_DIR)/$(TARGET).hex
449         dfu-programmer $(MCU) reset
450
451 dfu-start:
452         dfu-programmer $(MCU) reset
453         dfu-programmer $(MCU) start
454
455 flip-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
456         $(COPY) $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET)eep.hex
457         batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
458         batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(BUILD_DIR)/$(TARGET)eep.hex program
459         batchisp -hardware usb -device $(MCU) -operation start reset 0
460         $(REMOVE) $(BUILD_DIR)/$(TARGET)eep.hex
461
462 dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
463 ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
464         dfu-programmer $(MCU) flash --eeprom $(BUILD_DIR)/$(TARGET).eep
465 else
466         dfu-programmer $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep
467 endif
468         dfu-programmer $(MCU) reset
469
470
471 # Generate avr-gdb config/init file which does the following:
472 #     define the reset signal, load the target file, connect to target, and set
473 #     a breakpoint at main().
474 gdb-config:
475         @$(REMOVE) $(GDBINIT_FILE)
476         @echo define reset >> $(GDBINIT_FILE)
477         @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
478         @echo end >> $(GDBINIT_FILE)
479         @echo file $(BUILD_DIR)/$(TARGET).elf >> $(GDBINIT_FILE)
480         @echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
481 ifeq ($(DEBUG_BACKEND),simulavr)
482         @echo load  >> $(GDBINIT_FILE)
483 endif
484         @echo break main >> $(GDBINIT_FILE)
485
486 debug: gdb-config $(BUILD_DIR)/$(TARGET).elf
487 ifeq ($(DEBUG_BACKEND), avarice)
488         @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
489         @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
490         $(BUILD_DIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
491         @$(WINSHELL) /c pause
492
493 else
494         @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
495         $(DEBUG_MFREQ) --port $(DEBUG_PORT)
496 endif
497         @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
498
499
500
501
502 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
503 COFFCONVERT = $(OBJCOPY) --debugging
504 COFFCONVERT += --change-section-address .data-0x800000
505 COFFCONVERT += --change-section-address .bss-0x800000
506 COFFCONVERT += --change-section-address .noinit-0x800000
507 COFFCONVERT += --change-section-address .eeprom-0x810000
508
509
510
511 coff: $(BUILD_DIR)/$(TARGET).elf
512         @$(SECHO) $(MSG_COFF) $(BUILD_DIR)/$(TARGET).cof
513         $(COFFCONVERT) -O coff-avr $< $(BUILD_DIR)/$(TARGET).cof
514
515
516 extcoff: $(BUILD_DIR)/$(TARGET).elf
517         @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof
518         $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof
519
520
521
522 # Create final output files (.hex, .eep) from ELF output file.
523 %.hex: %.elf
524         @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD)
525         $(eval CMD=$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@)
526         @$(BUILD_CMD)
527         @$(COPY) $@ $(TARGET).hex
528
529 %.eep: %.elf
530         @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD)
531         $(eval CMD=$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0)
532         @$(BUILD_CMD)
533
534 # Create extended listing file from ELF output file.
535 %.lss: %.elf
536         @$(SILENT) || printf "$(MSG_EXTENDED_LISTING) $@" | $(AWK_CMD)
537         $(eval CMD=$(OBJDUMP) -h -S -z $< > $@)
538         @$(BUILD_CMD)
539
540 # Create a symbol table from ELF output file.
541 %.sym: %.elf
542         @$(SILENT) || printf "$(MSG_SYMBOL_TABLE) $@" | $(AWK_CMD)
543         $(eval CMD=$(NM) -n $< > $@ )
544         @$(BUILD_CMD)
545
546 # Create library from object files.
547 .SECONDARY : $(BUILD_DIR)/$(TARGET).a
548 .PRECIOUS : $(OBJ)
549 %.a: $(OBJ)
550         @$(SILENT) || printf "$(MSG_CREATING_LIBRARY) $@" | $(AWK_CMD)
551         $(eval CMD=$(AR) $@ $(OBJ) )
552         @$(BUILD_CMD)
553
554 # Link: create ELF output file from object files.
555 .SECONDARY : $(BUILD_DIR)/$(TARGET).elf
556 .PRECIOUS : $(OBJ)
557 %.elf: $(OBJ)
558         @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD)
559         $(eval CMD=$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS))
560         @$(BUILD_CMD)
561
562 # Compile: create object files from C source files.
563 $(OBJDIR)/%.o : %.c
564         @mkdir -p $(@D)
565         @$(SILENT) || printf "$(MSG_COMPILING) $<" | $(AWK_CMD)
566         $(eval CMD=$(CC) -c $(ALL_CFLAGS) $< -o $@)
567         @$(BUILD_CMD)
568
569 # Compile: create object files from C++ source files.
570 $(OBJDIR)/%.o : %.cpp
571         @mkdir -p $(@D)
572         @$(SILENT) || printf "$(MSG_COMPILING_CPP) $<" | $(AWK_CMD)
573         $(CC) -c $(ALL_CPPFLAGS) $< -o $@
574         @$(BUILD_CMD)
575
576 # Compile: create assembler files from C source files.
577 %.s : %.c
578         @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
579         $(eval CMD=$(CC) -S $(ALL_CFLAGS) $< -o $@)
580         @$(BUILD_CMD)
581
582 # Compile: create assembler files from C++ source files.
583 %.s : %.cpp
584         @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
585         $(eval CMD=$(CC) -S $(ALL_CPPFLAGS) $< -o $@)
586         @$(BUILD_CMD)
587
588 # Assemble: create object files from assembler source files.
589 $(OBJDIR)/%.o : %.S
590         @mkdir -p $(@D)
591         @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
592         $(eval CMD=$(CC) -c $(ALL_ASFLAGS) $< -o $@)
593         @$(BUILD_CMD)
594
595 # Create preprocessed source for use in sending a bug report.
596 %.i : %.c
597         $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@
598
599 # Target: clean project.
600 clean: begin clean_list end
601
602 clean_list :
603         $(REMOVE) -r $(TOP_DIR)/$(BUILD_DIR)
604         $(REMOVE) -r $(KEYBOARD_PATH)/$(BUILD_DIR)
605         $(REMOVE) -r $(KEYMAP_PATH)/$(BUILD_DIR)
606
607 show_path:
608         @echo VPATH=$(VPATH)
609         @echo SRC=$(SRC)
610
611 SUBDIRS := $(sort $(dir $(wildcard $(TOP_DIR)/keyboards/*/.)))
612 all-keyboards-defaults-%:
613         @for x in $(SUBDIRS) ; do \
614                 printf "Compiling with default: $$x" | $(AWK_CMD); \
615                 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; \
616         done
617
618 all-keyboards-defaults: all-keyboards-defaults-all
619
620 KEYBOARDS := $(SUBDIRS:$(TOP_DIR)/keyboards/%/=/keyboards/%)
621 all-keyboards-all: $(addsuffix -all,$(KEYBOARDS))
622 all-keyboards-quick: $(addsuffix -quick,$(KEYBOARDS))
623 all-keyboards-clean: $(addsuffix -clean,$(KEYBOARDS))
624 all-keyboards: all-keyboards-all
625
626 define make_keyboard
627 $(eval KEYBOARD=$(patsubst /keyboards/%,%,$1))
628 $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)$1/keymaps/*/.))))
629 @for x in $(KEYMAPS) ; do \
630         printf "Compiling $(BOLD)$(KEYBOARD)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-88s", $$0; }'; \
631         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; \
632 done
633 endef
634
635 define make_keyboard_helper
636 # Just remove the -quick, -all and so on from the first argument and pass it forward
637 $(call make_keyboard,$(subst -$2,,$1),$2)
638 endef
639
640 /keyboards/%-quick:
641         $(call make_keyboard_helper,$@,quick)
642 /keyboards/%-all:
643         $(call make_keyboard_helper,$@,all)
644 /keyboards/%-clean:
645         $(call make_keyboard_helper,$@,clean)
646 /keyboards/%:
647         $(call make_keyboard_helper,$@,all)
648
649 all-keymaps-%:
650         $(eval MAKECONFIG=$(call get_target,all-keymaps,$@))
651         $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/keymaps/*/.))))
652         @for x in $(KEYMAPS) ; do \
653                 printf "Compiling $(BOLD)$(KEYBOARD)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-88s", $$0; }'; \
654                 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; \
655         done
656
657 all-keymaps: all-keymaps-all
658
659 # Create build directory
660 $(shell mkdir $(BUILD_DIR) 2>/dev/null)
661
662 # Create object files directory
663 $(shell mkdir $(OBJDIR) 2>/dev/null)
664
665
666 # Include the dependency files.
667 -include $(shell mkdir $(BUILD_DIR)/.dep 2>/dev/null) $(wildcard $(BUILD_DIR)/.dep/*)
668
669
670 # Listing of phony targets.
671 .PHONY : all quick begin finish end sizebefore sizeafter gccversion \
672 build elf hex eep lss sym coff extcoff \
673 clean clean_list debug gdb-config show_path \
674 program teensy dfu flip dfu-ee flip-ee dfu-start \
675 all-keyboards-defaults all-keyboards all-keymaps \
676 all-keyboards-defaults-% all-keyboards-% all-keymaps-%