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