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