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