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