]> git.gir.st - tmk_keyboard.git/blob - Makefile
matrix scan & default keymap
[tmk_keyboard.git] / Makefile
1 # Hey Emacs, this is a -*- makefile -*-
2 #----------------------------------------------------------------------------
3 # WinAVR Makefile Template written by Eric B. Weddington, Jörg 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 # On command line:
19 #
20 # make all = Make software.
21 #
22 # make clean = Clean out built project files.
23 #
24 # make coff = Convert ELF to AVR COFF.
25 #
26 # make extcoff = Convert ELF to AVR Extended COFF.
27 #
28 # make program = Download the hex file to the device, using avrdude.
29 # Please customize the avrdude settings below first!
30 #
31 # make debug = Start either simulavr or avarice as specified for debugging,
32 # with avr-gdb or avr-insight as the front end for debugging.
33 #
34 # make filename.s = Just compile filename.c into the assembler code only.
35 #
36 # make filename.i = Create a preprocessed source file for use in submitting
37 # bug reports to the GCC project.
38 #
39 # To rebuild project do "make clean" then "make all".
40 #----------------------------------------------------------------------------
41
42
43 # Target file name (without extension).
44 TARGET = mykey
45
46
47 # List C source files here. (C dependencies are automatically generated.)
48 SRC = $(TARGET).c \
49 keymap.c \
50 usb_keyboard_debug.c \
51 print.c
52
53
54 # MCU name, you MUST set this to match the board you are using
55 # type "make clean" after changing this, so all files will be rebuilt
56 #MCU = at90usb162 # Teensy 1.0
57 MCU = atmega32u4 # Teensy 2.0
58 #MCU = at90usb646 # Teensy++ 1.0
59 #MCU = at90usb1286 # Teensy++ 2.0
60
61
62 # Processor frequency.
63 # Normally the first thing your program should do is set the clock prescaler,
64 # so your program will run at the correct speed. You should also set this
65 # variable to same clock speed. The _delay_ms() macro uses this, and many
66 # examples use this variable to calculate timings. Do not add a "UL" here.
67 F_CPU = 16000000
68
69
70 # Output format. (can be srec, ihex, binary)
71 FORMAT = ihex
72
73
74 # Object files directory
75 # To put object files in current directory, use a dot (.), do NOT make
76 # this an empty or blank macro!
77 OBJDIR = .
78
79
80 # List C++ source files here. (C dependencies are automatically generated.)
81 CPPSRC =
82
83
84 # List Assembler source files here.
85 # Make them always end in a capital .S. Files ending in a lowercase .s
86 # will not be considered source files but generated files (assembler
87 # output from the compiler), and will be deleted upon "make clean"!
88 # Even though the DOS/Win* filesystem matches both .s and .S the same,
89 # it will preserve the spelling of the filenames, and gcc itself does
90 # care about how the name is spelled on its command-line.
91 ASRC =
92
93
94 # Optimization level, can be [0, 1, 2, 3, s].
95 # 0 = turn off optimization. s = optimize for size.
96 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
97 OPT = s
98
99
100 # Debugging format.
101 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
102 # AVR Studio 4.10 requires dwarf-2.
103 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
104 DEBUG = dwarf-2
105
106
107 # List any extra directories to look for include files here.
108 # Each directory must be seperated by a space.
109 # Use forward slashes for directory separators.
110 # For a directory that has spaces, enclose it in quotes.
111 EXTRAINCDIRS =
112
113
114 # Compiler flag to set the C Standard level.
115 # c89 = "ANSI" C
116 # gnu89 = c89 plus GCC extensions
117 # c99 = ISO C99 standard (not yet fully implemented)
118 # gnu99 = c99 plus GCC extensions
119 CSTANDARD = -std=gnu99
120
121
122 # Place -D or -U options here for C sources
123 CDEFS = -DF_CPU=$(F_CPU)UL
124
125
126 # Place -D or -U options here for ASM sources
127 ADEFS = -DF_CPU=$(F_CPU)
128
129
130 # Place -D or -U options here for C++ sources
131 CPPDEFS = -DF_CPU=$(F_CPU)UL
132 #CPPDEFS += -D__STDC_LIMIT_MACROS
133 #CPPDEFS += -D__STDC_CONSTANT_MACROS
134
135
136
137 #---------------- Compiler Options C ----------------
138 # -g*: generate debugging information
139 # -O*: optimization level
140 # -f...: tuning, see GCC manual and avr-libc documentation
141 # -Wall...: warning level
142 # -Wa,...: tell GCC to pass this to the assembler.
143 # -adhlns...: create assembler listing
144 CFLAGS = -g$(DEBUG)
145 CFLAGS += $(CDEFS)
146 CFLAGS += -O$(OPT)
147 CFLAGS += -funsigned-char
148 CFLAGS += -funsigned-bitfields
149 CFLAGS += -ffunction-sections
150 CFLAGS += -fpack-struct
151 CFLAGS += -fshort-enums
152 CFLAGS += -Wall
153 CFLAGS += -Wstrict-prototypes
154 #CFLAGS += -mshort-calls
155 #CFLAGS += -fno-unit-at-a-time
156 #CFLAGS += -Wundef
157 #CFLAGS += -Wunreachable-code
158 #CFLAGS += -Wsign-compare
159 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
160 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
161 CFLAGS += $(CSTANDARD)
162
163
164 #---------------- Compiler Options C++ ----------------
165 # -g*: generate debugging information
166 # -O*: optimization level
167 # -f...: tuning, see GCC manual and avr-libc documentation
168 # -Wall...: warning level
169 # -Wa,...: tell GCC to pass this to the assembler.
170 # -adhlns...: create assembler listing
171 CPPFLAGS = -g$(DEBUG)
172 CPPFLAGS += $(CPPDEFS)
173 CPPFLAGS += -O$(OPT)
174 CPPFLAGS += -funsigned-char
175 CPPFLAGS += -funsigned-bitfields
176 CPPFLAGS += -fpack-struct
177 CPPFLAGS += -fshort-enums
178 CPPFLAGS += -fno-exceptions
179 CPPFLAGS += -Wall
180 CPPFLAGS += -Wundef
181 #CPPFLAGS += -mshort-calls
182 #CPPFLAGS += -fno-unit-at-a-time
183 #CPPFLAGS += -Wstrict-prototypes
184 #CPPFLAGS += -Wunreachable-code
185 #CPPFLAGS += -Wsign-compare
186 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
187 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
188 #CPPFLAGS += $(CSTANDARD)
189
190
191 #---------------- Assembler Options ----------------
192 # -Wa,...: tell GCC to pass this to the assembler.
193 # -adhlns: create listing
194 # -gstabs: have the assembler create line number information; note that
195 # for use in COFF files, additional information about filenames
196 # and function names needs to be present in the assembler source
197 # files -- see avr-libc docs [FIXME: not yet described there]
198 # -listing-cont-lines: Sets the maximum number of continuation lines of hex
199 # dump that will be displayed for a given single line of source input.
200 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
201
202
203 #---------------- Library Options ----------------
204 # Minimalistic printf version
205 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
206
207 # Floating point printf version (requires MATH_LIB = -lm below)
208 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
209
210 # If this is left blank, then it will use the Standard printf version.
211 PRINTF_LIB =
212 #PRINTF_LIB = $(PRINTF_LIB_MIN)
213 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
214
215
216 # Minimalistic scanf version
217 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
218
219 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
220 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
221
222 # If this is left blank, then it will use the Standard scanf version.
223 SCANF_LIB =
224 #SCANF_LIB = $(SCANF_LIB_MIN)
225 #SCANF_LIB = $(SCANF_LIB_FLOAT)
226
227
228 MATH_LIB = -lm
229
230
231 # List any extra directories to look for libraries here.
232 # Each directory must be seperated by a space.
233 # Use forward slashes for directory separators.
234 # For a directory that has spaces, enclose it in quotes.
235 EXTRALIBDIRS =
236
237
238
239 #---------------- External Memory Options ----------------
240
241 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
242 # used for variables (.data/.bss) and heap (malloc()).
243 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
244
245 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
246 # only used for heap (malloc()).
247 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
248
249 EXTMEMOPTS =
250
251
252
253 #---------------- Linker Options ----------------
254 # -Wl,...: tell GCC to pass this to linker.
255 # -Map: create map file
256 # --cref: add cross reference to map file
257 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
258 LDFLAGS += -Wl,--relax
259 LDFLAGS += -Wl,--gc-sections
260 LDFLAGS += $(EXTMEMOPTS)
261 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
262 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
263 #LDFLAGS += -T linker_script.x
264
265
266
267 #---------------- Programming Options (avrdude) ----------------
268
269 # Programming hardware
270 # Type: avrdude -c ?
271 # to get a full listing.
272 #
273 AVRDUDE_PROGRAMMER = stk500v2
274
275 # com1 = serial port. Use lpt1 to connect to parallel port.
276 AVRDUDE_PORT = com1 # programmer connected to serial device
277
278 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
279 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
280
281
282 # Uncomment the following if you want avrdude's erase cycle counter.
283 # Note that this counter needs to be initialized first using -Yn,
284 # see avrdude manual.
285 #AVRDUDE_ERASE_COUNTER = -y
286
287 # Uncomment the following if you do /not/ wish a verification to be
288 # performed after programming the device.
289 #AVRDUDE_NO_VERIFY = -V
290
291 # Increase verbosity level. Please use this when submitting bug
292 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
293 # to submit bug reports.
294 #AVRDUDE_VERBOSE = -v -v
295
296 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
297 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
298 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
299 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
300
301
302
303 #---------------- Debugging Options ----------------
304
305 # For simulavr only - target MCU frequency.
306 DEBUG_MFREQ = $(F_CPU)
307
308 # Set the DEBUG_UI to either gdb or insight.
309 # DEBUG_UI = gdb
310 DEBUG_UI = insight
311
312 # Set the debugging back-end to either avarice, simulavr.
313 DEBUG_BACKEND = avarice
314 #DEBUG_BACKEND = simulavr
315
316 # GDB Init Filename.
317 GDBINIT_FILE = __avr_gdbinit
318
319 # When using avarice settings for the JTAG
320 JTAG_DEV = /dev/com1
321
322 # Debugging port used to communicate between GDB / avarice / simulavr.
323 DEBUG_PORT = 4242
324
325 # Debugging host used to communicate between GDB / avarice / simulavr, normally
326 # just set to localhost unless doing some sort of crazy debugging when
327 # avarice is running on a different computer.
328 DEBUG_HOST = localhost
329
330
331
332 #============================================================================
333
334
335 # Define programs and commands.
336 SHELL = sh
337 CC = avr-gcc
338 OBJCOPY = avr-objcopy
339 OBJDUMP = avr-objdump
340 SIZE = avr-size
341 AR = avr-ar rcs
342 NM = avr-nm
343 AVRDUDE = avrdude
344 REMOVE = rm -f
345 REMOVEDIR = rm -rf
346 COPY = cp
347 WINSHELL = cmd
348
349
350 # Define Messages
351 # English
352 MSG_ERRORS_NONE = Errors: none
353 MSG_BEGIN = -------- begin --------
354 MSG_END = -------- end --------
355 MSG_SIZE_BEFORE = Size before:
356 MSG_SIZE_AFTER = Size after:
357 MSG_COFF = Converting to AVR COFF:
358 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
359 MSG_FLASH = Creating load file for Flash:
360 MSG_EEPROM = Creating load file for EEPROM:
361 MSG_EXTENDED_LISTING = Creating Extended Listing:
362 MSG_SYMBOL_TABLE = Creating Symbol Table:
363 MSG_LINKING = Linking:
364 MSG_COMPILING = Compiling C:
365 MSG_COMPILING_CPP = Compiling C++:
366 MSG_ASSEMBLING = Assembling:
367 MSG_CLEANING = Cleaning project:
368 MSG_CREATING_LIBRARY = Creating library:
369
370
371
372
373 # Define all object files.
374 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
375
376 # Define all listing files.
377 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
378
379
380 # Compiler flags to generate dependency files.
381 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
382
383
384 # Combine all necessary flags and optional flags.
385 # Add target processor to flags.
386 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
387 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
388 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
389
390
391
392
393
394 # Default target.
395 all: begin gccversion sizebefore build sizeafter end
396
397 # Change the build target to build a HEX file or a library.
398 build: elf hex eep lss sym
399 #build: lib
400
401
402 elf: $(TARGET).elf
403 hex: $(TARGET).hex
404 eep: $(TARGET).eep
405 lss: $(TARGET).lss
406 sym: $(TARGET).sym
407 LIBNAME=lib$(TARGET).a
408 lib: $(LIBNAME)
409
410
411
412 # Eye candy.
413 # AVR Studio 3.x does not check make's exit code but relies on
414 # the following magic strings to be generated by the compile job.
415 begin:
416 @echo
417 @echo $(MSG_BEGIN)
418
419 end:
420 @echo $(MSG_END)
421 @echo
422
423
424 # Display size of file.
425 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
426 #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
427 ELFSIZE = $(SIZE) $(TARGET).elf
428
429 sizebefore:
430 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
431 2>/dev/null; echo; fi
432
433 sizeafter:
434 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
435 2>/dev/null; echo; fi
436
437
438
439 # Display compiler version information.
440 gccversion :
441 @$(CC) --version
442
443
444
445 # Program the device.
446 program: $(TARGET).hex $(TARGET).eep
447 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
448
449
450 # Generate avr-gdb config/init file which does the following:
451 # define the reset signal, load the target file, connect to target, and set
452 # a breakpoint at main().
453 gdb-config:
454 @$(REMOVE) $(GDBINIT_FILE)
455 @echo define reset >> $(GDBINIT_FILE)
456 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
457 @echo end >> $(GDBINIT_FILE)
458 @echo file $(TARGET).elf >> $(GDBINIT_FILE)
459 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
460 ifeq ($(DEBUG_BACKEND),simulavr)
461 @echo load >> $(GDBINIT_FILE)
462 endif
463 @echo break main >> $(GDBINIT_FILE)
464
465 debug: gdb-config $(TARGET).elf
466 ifeq ($(DEBUG_BACKEND), avarice)
467 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
468 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
469 $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
470 @$(WINSHELL) /c pause
471
472 else
473 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
474 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
475 endif
476 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
477
478
479
480
481 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
482 COFFCONVERT = $(OBJCOPY) --debugging
483 COFFCONVERT += --change-section-address .data-0x800000
484 COFFCONVERT += --change-section-address .bss-0x800000
485 COFFCONVERT += --change-section-address .noinit-0x800000
486 COFFCONVERT += --change-section-address .eeprom-0x810000
487
488
489
490 coff: $(TARGET).elf
491 @echo
492 @echo $(MSG_COFF) $(TARGET).cof
493 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
494
495
496 extcoff: $(TARGET).elf
497 @echo
498 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
499 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
500
501
502
503 # Create final output files (.hex, .eep) from ELF output file.
504 %.hex: %.elf
505 @echo
506 @echo $(MSG_FLASH) $@
507 $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
508
509 %.eep: %.elf
510 @echo
511 @echo $(MSG_EEPROM) $@
512 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
513 --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
514
515 # Create extended listing file from ELF output file.
516 %.lss: %.elf
517 @echo
518 @echo $(MSG_EXTENDED_LISTING) $@
519 $(OBJDUMP) -h -S -z $< > $@
520
521 # Create a symbol table from ELF output file.
522 %.sym: %.elf
523 @echo
524 @echo $(MSG_SYMBOL_TABLE) $@
525 $(NM) -n $< > $@
526
527
528
529 # Create library from object files.
530 .SECONDARY : $(TARGET).a
531 .PRECIOUS : $(OBJ)
532 %.a: $(OBJ)
533 @echo
534 @echo $(MSG_CREATING_LIBRARY) $@
535 $(AR) $@ $(OBJ)
536
537
538 # Link: create ELF output file from object files.
539 .SECONDARY : $(TARGET).elf
540 .PRECIOUS : $(OBJ)
541 %.elf: $(OBJ)
542 @echo
543 @echo $(MSG_LINKING) $@
544 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
545
546
547 # Compile: create object files from C source files.
548 $(OBJDIR)/%.o : %.c
549 @echo
550 @echo $(MSG_COMPILING) $<
551 $(CC) -c $(ALL_CFLAGS) $< -o $@
552
553
554 # Compile: create object files from C++ source files.
555 $(OBJDIR)/%.o : %.cpp
556 @echo
557 @echo $(MSG_COMPILING_CPP) $<
558 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
559
560
561 # Compile: create assembler files from C source files.
562 %.s : %.c
563 $(CC) -S $(ALL_CFLAGS) $< -o $@
564
565
566 # Compile: create assembler files from C++ source files.
567 %.s : %.cpp
568 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
569
570
571 # Assemble: create object files from assembler source files.
572 $(OBJDIR)/%.o : %.S
573 @echo
574 @echo $(MSG_ASSEMBLING) $<
575 $(CC) -c $(ALL_ASFLAGS) $< -o $@
576
577
578 # Create preprocessed source for use in sending a bug report.
579 %.i : %.c
580 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
581
582
583 # Target: clean project.
584 clean: begin clean_list end
585
586 clean_list :
587 @echo
588 @echo $(MSG_CLEANING)
589 $(REMOVE) $(TARGET).hex
590 $(REMOVE) $(TARGET).eep
591 $(REMOVE) $(TARGET).cof
592 $(REMOVE) $(TARGET).elf
593 $(REMOVE) $(TARGET).map
594 $(REMOVE) $(TARGET).sym
595 $(REMOVE) $(TARGET).lss
596 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
597 $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
598 $(REMOVE) $(SRC:.c=.s)
599 $(REMOVE) $(SRC:.c=.d)
600 $(REMOVE) $(SRC:.c=.i)
601 $(REMOVEDIR) .dep
602
603
604 # Create object files directory
605 $(shell mkdir $(OBJDIR) 2>/dev/null)
606
607
608 # Include the dependency files.
609 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
610
611
612 # Listing of phony targets.
613 .PHONY : all begin finish end sizebefore sizeafter gccversion \
614 build elf hex eep lss sym coff extcoff \
615 clean clean_list program debug gdb-config
Imprint / Impressum