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