]> git.gir.st - tmk_keyboard.git/blob - Makefile.vusb
added PS/2 to USB converter use V-USB as protocol stack
[tmk_keyboard.git] / Makefile.vusb
1 #----------------------------------------------------------------------------
2 # On command line:
3 #
4 # make all = Make software.
5 #
6 # make clean = Clean out built project files.
7 #
8 # make coff = Convert ELF to AVR COFF.
9 #
10 # make extcoff = Convert ELF to AVR Extended COFF.
11 #
12 # make program = Download the hex file to the device, using avrdude.
13 # Please customize the avrdude settings below first!
14 #
15 # make debug = Start either simulavr or avarice as specified for debugging,
16 # with avr-gdb or avr-insight as the front end for debugging.
17 #
18 # make filename.s = Just compile filename.c into the assembler code only.
19 #
20 # make filename.i = Create a preprocessed source file for use in submitting
21 # bug reports to the GCC project.
22 #
23 # To rebuild project do "make clean" then "make all".
24 #----------------------------------------------------------------------------
25
26 # Following variables need to be set in <target>/Makefile:
27 # TARGET
28 # COMMON_DIR
29 # TARGET_DIR
30 # TARGET_SRC
31 # MCU
32 # F_CPU
33
34
35 # List C source files here. (C dependencies are automatically generated.)
36 SRC = usbdrv.c \
37 usbdrvasm.S \
38 oddebug.c
39 SRC += $(TARGET_SRC)
40
41 # Option modules
42 ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE)
43 SRC += usb_mouse.c
44 endif
45 ifdef MOUSEKEY_ENABLE
46 SRC += mousekey.c
47 endif
48 ifdef PS2_MOUSE_ENABLE
49 SRC += ps2.c \
50 ps2_mouse.c
51 endif
52 ifdef USB_EXTRA_ENABLE
53 SRC += usb_extra.c
54 endif
55
56
57 # C source file search path
58 VPATH = $(TARGET_DIR):$(COMMON_DIR):$(COMMON_DIR)/usbdrv
59
60
61 # Output format. (can be srec, ihex, binary)
62 FORMAT = ihex
63
64
65 # Object files directory
66 # To put object files in current directory, use a dot (.), do NOT make
67 # this an empty or blank macro!
68 OBJDIR = .
69
70
71 # Optimization level, can be [0, 1, 2, 3, s].
72 # 0 = turn off optimization. s = optimize for size.
73 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
74 OPT = s
75
76
77 # Debugging format.
78 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
79 # AVR Studio 4.10 requires dwarf-2.
80 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
81 DEBUG = dwarf-2
82
83
84 # List any extra directories to look for include files here.
85 # Each directory must be seperated by a space.
86 # Use forward slashes for directory separators.
87 # For a directory that has spaces, enclose it in quotes.
88 #EXTRAINCDIRS = $(TARGET_DIR) $(COMMON_DIR)
89 EXTRAINCDIRS = $(subst :, ,$(VPATH))
90
91
92 # Compiler flag to set the C Standard level.
93 # c89 = "ANSI" C
94 # gnu89 = c89 plus GCC extensions
95 # c99 = ISO C99 standard (not yet fully implemented)
96 # gnu99 = c99 plus GCC extensions
97 CSTANDARD = -std=gnu99
98
99
100 #OPT_DEFS =
101 ifdef MOUSEKEY_ENABLE
102 OPT_DEFS += -DMOUSEKEY_ENABLE
103 endif
104 ifdef PS2_MOUSE_ENABLE
105 OPT_DEFS += -DPS2_MOUSE_ENABLE
106 endif
107 ifdef USB_EXTRA_ENABLE
108 OPT_DEFS += -DUSB_EXTRA_ENABLE
109 endif
110 ifdef USB_NKRO_ENABLE
111 OPT_DEFS += -DUSB_NKRO_ENABLE
112 endif
113 ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE)
114 OPT_DEFS += -DUSB_MOUSE_ENABLE
115 endif
116
117 # Place -D or -U options here for C sources
118 CDEFS = -DF_CPU=$(F_CPU)UL
119 CDEFS += $(OPT_DEFS)
120
121
122 # Place -D or -U options here for ASM sources
123 ADEFS = -DF_CPU=$(F_CPU)
124 ADEFS += $(OPT_DEFS)
125
126
127 # Place -D or -U options here for C++ sources
128 CPPDEFS = -DF_CPU=$(F_CPU)UL
129 #CPPDEFS += -D__STDC_LIMIT_MACROS
130 #CPPDEFS += -D__STDC_CONSTANT_MACROS
131 CPPDEFS += $(OPT_DEFS)
132
133
134
135 #---------------- Compiler Options C ----------------
136 # -g*: generate debugging information
137 # -O*: optimization level
138 # -f...: tuning, see GCC manual and avr-libc documentation
139 # -Wall...: warning level
140 # -Wa,...: tell GCC to pass this to the assembler.
141 # -adhlns...: create assembler listing
142 CFLAGS = -g$(DEBUG)
143 CFLAGS += $(CDEFS)
144 CFLAGS += -O$(OPT)
145 CFLAGS += -funsigned-char
146 CFLAGS += -funsigned-bitfields
147 CFLAGS += -ffunction-sections
148 CFLAGS += -fpack-struct
149 CFLAGS += -fshort-enums
150 CFLAGS += -Wall
151 CFLAGS += -Wstrict-prototypes
152 #CFLAGS += -mshort-calls
153 #CFLAGS += -fno-unit-at-a-time
154 #CFLAGS += -Wundef
155 #CFLAGS += -Wunreachable-code
156 #CFLAGS += -Wsign-compare
157 CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
158 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
159 CFLAGS += $(CSTANDARD)
160 CFLAGS += -include config.h
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=$(@:%.o=%.lst)
186 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
187 #CPPFLAGS += $(CSTANDARD)
188 CPPFLAGS += -include config.h
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=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
201 ASFLAGS += -include config.h
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 #
259 # Comennt out "--relax" option to avoid a error such:
260 # (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12'
261 #
262 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
263 LDFLAGS += -Wl,--relax
264 LDFLAGS += -Wl,--gc-sections
265 LDFLAGS += $(EXTMEMOPTS)
266 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
267 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
268 #LDFLAGS += -T linker_script.x
269
270
271
272 #---------------- Programming Options (avrdude) ----------------
273
274 # Programming hardware
275 # Type: avrdude -c ?
276 # to get a full listing.
277 #
278 AVRDUDE_PROGRAMMER = stk500v2
279
280 # com1 = serial port. Use lpt1 to connect to parallel port.
281 AVRDUDE_PORT = com1 # programmer connected to serial device
282
283 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
284 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
285
286
287 # Uncomment the following if you want avrdude's erase cycle counter.
288 # Note that this counter needs to be initialized first using -Yn,
289 # see avrdude manual.
290 #AVRDUDE_ERASE_COUNTER = -y
291
292 # Uncomment the following if you do /not/ wish a verification to be
293 # performed after programming the device.
294 #AVRDUDE_NO_VERIFY = -V
295
296 # Increase verbosity level. Please use this when submitting bug
297 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
298 # to submit bug reports.
299 #AVRDUDE_VERBOSE = -v -v
300
301 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
302 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
303 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
304 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
305
306
307
308 #---------------- Debugging Options ----------------
309
310 # For simulavr only - target MCU frequency.
311 DEBUG_MFREQ = $(F_CPU)
312
313 # Set the DEBUG_UI to either gdb or insight.
314 # DEBUG_UI = gdb
315 DEBUG_UI = insight
316
317 # Set the debugging back-end to either avarice, simulavr.
318 DEBUG_BACKEND = avarice
319 #DEBUG_BACKEND = simulavr
320
321 # GDB Init Filename.
322 GDBINIT_FILE = __avr_gdbinit
323
324 # When using avarice settings for the JTAG
325 JTAG_DEV = /dev/com1
326
327 # Debugging port used to communicate between GDB / avarice / simulavr.
328 DEBUG_PORT = 4242
329
330 # Debugging host used to communicate between GDB / avarice / simulavr, normally
331 # just set to localhost unless doing some sort of crazy debugging when
332 # avarice is running on a different computer.
333 DEBUG_HOST = localhost
334
335
336
337 #============================================================================
338
339
340 # Define programs and commands.
341 SHELL = sh
342 CC = avr-gcc
343 OBJCOPY = avr-objcopy
344 OBJDUMP = avr-objdump
345 SIZE = avr-size
346 AR = avr-ar rcs
347 NM = avr-nm
348 AVRDUDE = avrdude
349 REMOVE = rm -f
350 REMOVEDIR = rm -rf
351 COPY = cp
352 WINSHELL = cmd
353
354
355 # Define Messages
356 # English
357 MSG_ERRORS_NONE = Errors: none
358 MSG_BEGIN = -------- begin --------
359 MSG_END = -------- end --------
360 MSG_SIZE_BEFORE = Size before:
361 MSG_SIZE_AFTER = Size after:
362 MSG_COFF = Converting to AVR COFF:
363 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
364 MSG_FLASH = Creating load file for Flash:
365 MSG_EEPROM = Creating load file for EEPROM:
366 MSG_EXTENDED_LISTING = Creating Extended Listing:
367 MSG_SYMBOL_TABLE = Creating Symbol Table:
368 MSG_LINKING = Linking:
369 MSG_COMPILING = Compiling C:
370 MSG_COMPILING_CPP = Compiling C++:
371 MSG_ASSEMBLING = Assembling:
372 MSG_CLEANING = Cleaning project:
373 MSG_CREATING_LIBRARY = Creating library:
374
375
376
377
378 # Define all object files.
379 OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC))))
380
381 # Define all listing files.
382 LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst %.S,$(OBJDIR)/%.lst,$(SRC))))
383
384
385 # Compiler flags to generate dependency files.
386 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
387
388
389 # Combine all necessary flags and optional flags.
390 # Add target processor to flags.
391 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
392 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
393 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
394
395
396
397
398
399 # Default target.
400 all: begin gccversion sizebefore build sizeafter end
401
402 # Change the build target to build a HEX file or a library.
403 build: elf hex eep lss sym
404 #build: lib
405
406
407 elf: $(TARGET).elf
408 hex: $(TARGET).hex
409 eep: $(TARGET).eep
410 lss: $(TARGET).lss
411 sym: $(TARGET).sym
412 LIBNAME=lib$(TARGET).a
413 lib: $(LIBNAME)
414
415
416
417 # Eye candy.
418 # AVR Studio 3.x does not check make's exit code but relies on
419 # the following magic strings to be generated by the compile job.
420 begin:
421 @echo
422 @echo $(MSG_BEGIN)
423
424 end:
425 @echo $(MSG_END)
426 @echo
427
428
429 # Display size of file.
430 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
431 #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
432 ELFSIZE = $(SIZE) $(TARGET).elf
433
434 sizebefore:
435 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
436 2>/dev/null; echo; fi
437
438 sizeafter:
439 @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
440 2>/dev/null; echo; fi
441
442
443
444 # Display compiler version information.
445 gccversion :
446 @$(CC) --version
447
448
449
450 # Program the device.
451 program: $(TARGET).hex $(TARGET).eep
452 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
453
454
455 # Generate avr-gdb config/init file which does the following:
456 # define the reset signal, load the target file, connect to target, and set
457 # a breakpoint at main().
458 gdb-config:
459 @$(REMOVE) $(GDBINIT_FILE)
460 @echo define reset >> $(GDBINIT_FILE)
461 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
462 @echo end >> $(GDBINIT_FILE)
463 @echo file $(TARGET).elf >> $(GDBINIT_FILE)
464 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
465 ifeq ($(DEBUG_BACKEND),simulavr)
466 @echo load >> $(GDBINIT_FILE)
467 endif
468 @echo break main >> $(GDBINIT_FILE)
469
470 debug: gdb-config $(TARGET).elf
471 ifeq ($(DEBUG_BACKEND), avarice)
472 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
473 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
474 $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
475 @$(WINSHELL) /c pause
476
477 else
478 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
479 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
480 endif
481 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
482
483
484
485
486 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
487 COFFCONVERT = $(OBJCOPY) --debugging
488 COFFCONVERT += --change-section-address .data-0x800000
489 COFFCONVERT += --change-section-address .bss-0x800000
490 COFFCONVERT += --change-section-address .noinit-0x800000
491 COFFCONVERT += --change-section-address .eeprom-0x810000
492
493
494
495 coff: $(TARGET).elf
496 @echo
497 @echo $(MSG_COFF) $(TARGET).cof
498 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
499
500
501 extcoff: $(TARGET).elf
502 @echo
503 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
504 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
505
506
507
508 # Create final output files (.hex, .eep) from ELF output file.
509 %.hex: %.elf
510 @echo
511 @echo $(MSG_FLASH) $@
512 $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
513
514 %.eep: %.elf
515 @echo
516 @echo $(MSG_EEPROM) $@
517 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
518 --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
519
520 # Create extended listing file from ELF output file.
521 %.lss: %.elf
522 @echo
523 @echo $(MSG_EXTENDED_LISTING) $@
524 $(OBJDUMP) -h -S -z $< > $@
525
526 # Create a symbol table from ELF output file.
527 %.sym: %.elf
528 @echo
529 @echo $(MSG_SYMBOL_TABLE) $@
530 $(NM) -n $< > $@
531
532
533
534 # Create library from object files.
535 .SECONDARY : $(TARGET).a
536 .PRECIOUS : $(OBJ)
537 %.a: $(OBJ)
538 @echo
539 @echo $(MSG_CREATING_LIBRARY) $@
540 $(AR) $@ $(OBJ)
541
542
543 # Link: create ELF output file from object files.
544 .SECONDARY : $(TARGET).elf
545 .PRECIOUS : $(OBJ)
546 %.elf: $(OBJ)
547 @echo
548 @echo $(MSG_LINKING) $@
549 $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
550
551
552 # Compile: create object files from C source files.
553 $(OBJDIR)/%.o : %.c
554 @echo
555 @echo $(MSG_COMPILING) $<
556 $(CC) -c $(ALL_CFLAGS) $< -o $@
557
558
559 # Compile: create object files from C++ source files.
560 $(OBJDIR)/%.o : %.cpp
561 @echo
562 @echo $(MSG_COMPILING_CPP) $<
563 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
564
565
566 # Compile: create assembler files from C source files.
567 %.s : %.c
568 $(CC) -S $(ALL_CFLAGS) $< -o $@
569
570
571 # Compile: create assembler files from C++ source files.
572 %.s : %.cpp
573 $(CC) -S $(ALL_CPPFLAGS) $< -o $@
574
575
576 # Assemble: create object files from assembler source files.
577 $(OBJDIR)/%.o : %.S
578 @echo
579 @echo $(MSG_ASSEMBLING) $<
580 $(CC) -c $(ALL_ASFLAGS) $< -o $@
581
582
583 # Create preprocessed source for use in sending a bug report.
584 %.i : %.c
585 $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
586
587
588 # Target: clean project.
589 clean: begin clean_list end
590
591 clean_list :
592 @echo
593 $(REMOVE) $(TARGET).hex
594 $(REMOVE) $(TARGET).eep
595 $(REMOVE) $(TARGET).cof
596 $(REMOVE) $(TARGET).elf
597 $(REMOVE) $(TARGET).map
598 $(REMOVE) $(TARGET).sym
599 $(REMOVE) $(TARGET).lss
600 $(REMOVE) $(OBJ)
601 $(REMOVE) $(LST)
602 $(REMOVE) $(OBJ:.o=.s)
603 $(REMOVE) $(OBJ:.o=.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