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