root / branches / encoders / code / projects / template / Makefile @ 546
History | View | Annotate | Download (13.6 KB)
1 | 63 | emarinel | ########Update This Section######## |
---|---|---|---|
2 | # |
||
3 | # |
||
4 | |||
5 | # Relative path to the root directory (containing lib directory) |
||
6 | ifndef COLONYROOT |
||
7 | COLONYROOT = ../../.. |
||
8 | endif |
||
9 | |||
10 | # Target file name (without extension). |
||
11 | TARGET = template |
||
12 | |||
13 | # Uncomment this to use the wireless library |
||
14 | # USE_WIRELESS = 1 |
||
15 | |||
16 | # com1 = serial port. Use lpt1 to connect to parallel port. |
||
17 | 546 | kwoo | AVRDUDE_PORT = /dev/ttyUSB0 |
18 | 63 | emarinel | # |
19 | ################################### |
||
20 | |||
21 | # Hey Emacs, this is a -*- makefile -*- |
||
22 | #---------------------------------------------------------------------------- |
||
23 | # WinAVR Makefile Template written by Eric B. Weddington, J?rg Wunsch, et al. |
||
24 | # |
||
25 | # Released to the Public Domain |
||
26 | # |
||
27 | # Additional material for this makefile was written by: |
||
28 | # Peter Fleury |
||
29 | # Tim Henigan |
||
30 | # Colin O'Flynn |
||
31 | # Reiner Patommel |
||
32 | # Markus Pfaff |
||
33 | # Sander Pool |
||
34 | # Frederik Rouleau |
||
35 | # |
||
36 | #---------------------------------------------------------------------------- |
||
37 | # On command line: |
||
38 | # |
||
39 | # make all = Make software. |
||
40 | # |
||
41 | # make clean = Clean out built project files. |
||
42 | # |
||
43 | # make coff = Convert ELF to AVR COFF. |
||
44 | # |
||
45 | # make extcoff = Convert ELF to AVR Extended COFF. |
||
46 | # |
||
47 | # make program = Download the hex file to the device, using avrdude. |
||
48 | # Please customize the avrdude settings below first! |
||
49 | # |
||
50 | # make debug = Start either simulavr or avarice as specified for debugging, |
||
51 | # with avr-gdb or avr-insight as the front end for debugging. |
||
52 | # |
||
53 | # make filename.s = Just compile filename.c into the assembler code only. |
||
54 | # |
||
55 | # make filename.i = Create a preprocessed source file for use in submitting |
||
56 | # bug reports to the GCC project. |
||
57 | # |
||
58 | # To rebuild project do "make clean" then "make all". |
||
59 | #---------------------------------------------------------------------------- |
||
60 | |||
61 | #if you want your code to work on the Firefly++ and not Firefly+ |
||
62 | #then add the -DFFPP line to CDEFS |
||
63 | CDEFS = |
||
64 | #-DFFPP |
||
65 | |||
66 | # MCU name |
||
67 | MCU = atmega128 |
||
68 | |||
69 | # Processor frequency. |
||
70 | # This will define a symbol, F_CPU, in all source code files equal to the |
||
71 | # processor frequency. You can then use this symbol in your source code to |
||
72 | # calculate timings. Do NOT tack on a 'UL' at the end, this will be done |
||
73 | # automatically to create a 32-bit value in your source code. |
||
74 | F_CPU = 8000000 |
||
75 | |||
76 | # Output format. (can be srec, ihex, binary) |
||
77 | FORMAT = ihex |
||
78 | |||
79 | # List C source files here. (C dependencies are automatically generated.) |
||
80 | SRC = $(wildcard *.c) |
||
81 | |||
82 | # List Assembler source files here. |
||
83 | # Make them always end in a capital .S. Files ending in a lowercase .s |
||
84 | # will not be considered source files but generated files (assembler |
||
85 | # output from the compiler), and will be deleted upon "make clean"! |
||
86 | # Even though the DOS/Win* filesystem matches both .s and .S the same, |
||
87 | # it will preserve the spelling of the filenames, and gcc itself does |
||
88 | # care about how the name is spelled on its command-line. |
||
89 | ASRC = |
||
90 | |||
91 | # Optimization level, can be [0, 1, 2, 3, s]. |
||
92 | # 0 = turn off optimization. s = optimize for size. |
||
93 | # (Note: 3 is not always the best optimization level. See avr-libc FAQ.) |
||
94 | OPT = s |
||
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 = |
||
101 | |||
102 | # Compiler flag to set the C Standard level. |
||
103 | # c89 = "ANSI" C |
||
104 | # gnu89 = c89 plus GCC extensions |
||
105 | # c99 = ISO C99 standard (not yet fully implemented) |
||
106 | # gnu99 = c99 plus GCC extensions |
||
107 | CSTANDARD = -std=gnu99 |
||
108 | |||
109 | # Place -D or -U options here |
||
110 | CDEFS += -DF_CPU=$(F_CPU)UL |
||
111 | CDEFS += -DFFP |
||
112 | # for wireless library |
||
113 | ifdef USE_WIRELESS |
||
114 | CDEFS += -DROBOT |
||
115 | endif |
||
116 | |||
117 | # Place -I, -L options here |
||
118 | 367 | kwoo | CINCS = -I../libdragonfly |
119 | CINCS += -L../libdragonfly |
||
120 | 63 | emarinel | |
121 | #---------------- Compiler Options ---------------- |
||
122 | # -g*: generate debugging information |
||
123 | # -O*: optimization level |
||
124 | # -f...: tuning, see GCC manual and avr-libc documentation |
||
125 | # -Wall...: warning level |
||
126 | # -Wa,...: tell GCC to pass this to the assembler. |
||
127 | # -adhlns...: create assembler listing |
||
128 | CFLAGS = |
||
129 | # CFLAGS = -g$(DEBUG) |
||
130 | CFLAGS += $(CDEFS) $(CINCS) |
||
131 | CFLAGS += -O$(OPT) |
||
132 | CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums |
||
133 | CFLAGS += -Wall -Wstrict-prototypes |
||
134 | CFLAGS += -Wa,-adhlns=$(<:.c=.lst) |
||
135 | CFLAGS += $(CSTANDARD) |
||
136 | |||
137 | #---------------- Assembler Options ---------------- |
||
138 | # -Wa,...: tell GCC to pass this to the assembler. |
||
139 | # -ahlms: create listing |
||
140 | # -gstabs: have the assembler create line number information; note that |
||
141 | # for use in COFF files, additional information about filenames |
||
142 | # and function names needs to be present in the assembler source |
||
143 | # files -- see avr-libc docs [FIXME: not yet described there] |
||
144 | ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs |
||
145 | |||
146 | |||
147 | #---------------- Library Options ---------------- |
||
148 | # Minimalistic printf version |
||
149 | PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min |
||
150 | |||
151 | # Floating point printf version (requires MATH_LIB = -lm below) |
||
152 | PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt |
||
153 | |||
154 | # If this is left blank, then it will use the Standard printf version. |
||
155 | PRINTF_LIB = |
||
156 | #PRINTF_LIB = $(PRINTF_LIB_MIN) |
||
157 | #PRINTF_LIB = $(PRINTF_LIB_FLOAT) |
||
158 | |||
159 | |||
160 | # Minimalistic scanf version |
||
161 | SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min |
||
162 | |||
163 | # Floating point + %[ scanf version (requires MATH_LIB = -lm below) |
||
164 | SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt |
||
165 | |||
166 | # If this is left blank, then it will use the Standard scanf version. |
||
167 | SCANF_LIB = |
||
168 | #SCANF_LIB = $(SCANF_LIB_MIN) |
||
169 | #SCANF_LIB = $(SCANF_LIB_FLOAT) |
||
170 | |||
171 | MATH_LIB = -lm |
||
172 | |||
173 | #---------------- External Memory Options ---------------- |
||
174 | |||
175 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), |
||
176 | # used for variables (.data/.bss) and heap (malloc()). |
||
177 | #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff |
||
178 | |||
179 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), |
||
180 | # only used for heap (malloc()). |
||
181 | #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff |
||
182 | |||
183 | EXTMEMOPTS = |
||
184 | |||
185 | #---------------- Linker Options ---------------- |
||
186 | # -Wl,...: tell GCC to pass this to linker. |
||
187 | # -Map: create map file |
||
188 | # --cref: add cross reference to map file |
||
189 | LDFLAGS = -Wl,-Map=$(TARGET).map,--cref |
||
190 | LDFLAGS += $(EXTMEMOPTS) |
||
191 | LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) |
||
192 | ifdef USE_WIRELESS |
||
193 | LDFLAGS += -lwireless |
||
194 | endif |
||
195 | LDFLAGS += -ldragonfly |
||
196 | |||
197 | |||
198 | |||
199 | #---------------- Programming Options (avrdude) ---------------- |
||
200 | |||
201 | # Programming hardware: alf avr910 avrisp bascom bsd |
||
202 | # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 |
||
203 | # |
||
204 | # Type: avrdude -c ? |
||
205 | # to get a full listing. |
||
206 | # |
||
207 | AVRDUDE_PROGRAMMER = avrisp |
||
208 | |||
209 | # programmer connected to serial device |
||
210 | |||
211 | AVRDUDE_WRITE_FLASH = -b 57600 -U flash:w:$(TARGET).hex |
||
212 | #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep |
||
213 | |||
214 | |||
215 | # Uncomment the following if you want avrdude's erase cycle counter. |
||
216 | # Note that this counter needs to be initialized first using -Yn, |
||
217 | # see avrdude manual. |
||
218 | #AVRDUDE_ERASE_COUNTER = -y |
||
219 | |||
220 | # Uncomment the following if you do /not/ wish a verification to be |
||
221 | # performed after programming the device. |
||
222 | #AVRDUDE_NO_VERIFY = -V |
||
223 | |||
224 | # Increase verbosity level. Please use this when submitting bug |
||
225 | # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> |
||
226 | # to submit bug reports. |
||
227 | #AVRDUDE_VERBOSE = -v -v |
||
228 | |||
229 | AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) |
||
230 | AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) |
||
231 | AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) |
||
232 | AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) |
||
233 | |||
234 | #don't check for device signature |
||
235 | AVRDUDE_FLAGS += -F |
||
236 | |||
237 | |||
238 | |||
239 | #---------------- Debugging Options ---------------- |
||
240 | |||
241 | # For simulavr only - target MCU frequency. |
||
242 | DEBUG_MFREQ = $(F_CPU) |
||
243 | |||
244 | # Set the DEBUG_UI to either gdb or insight. |
||
245 | # DEBUG_UI = gdb |
||
246 | DEBUG_UI = insight |
||
247 | |||
248 | # Set the debugging back-end to either avarice, simulavr. |
||
249 | DEBUG_BACKEND = avarice |
||
250 | #DEBUG_BACKEND = simulavr |
||
251 | |||
252 | # GDB Init Filename. |
||
253 | GDBINIT_FILE = __avr_gdbinit |
||
254 | |||
255 | # When using avarice settings for the JTAG |
||
256 | JTAG_DEV = /dev/com1 |
||
257 | |||
258 | # Debugging port used to communicate between GDB / avarice / simulavr. |
||
259 | DEBUG_PORT = 4242 |
||
260 | |||
261 | # Debugging host used to communicate between GDB / avarice / simulavr, normally |
||
262 | # just set to localhost unless doing some sort of crazy debugging when |
||
263 | # avarice is running on a different computer. |
||
264 | DEBUG_HOST = localhost |
||
265 | |||
266 | |||
267 | |||
268 | #============================================================================ |
||
269 | |||
270 | |||
271 | # Define programs and commands. |
||
272 | SHELL = sh |
||
273 | CC = avr-gcc |
||
274 | OBJCOPY = avr-objcopy |
||
275 | OBJDUMP = avr-objdump |
||
276 | SIZE = avr-size |
||
277 | NM = avr-nm |
||
278 | AVRDUDE = avrdude |
||
279 | REMOVE = rm -f |
||
280 | REMOVEDIR = rm -rf |
||
281 | COPY = cp |
||
282 | WINSHELL = cmd |
||
283 | |||
284 | |||
285 | # Define Messages |
||
286 | # English |
||
287 | MSG_ERRORS_NONE = Errors: none |
||
288 | MSG_BEGIN = -------- begin -------- |
||
289 | MSG_END = -------- end -------- |
||
290 | MSG_SIZE_BEFORE = Size before: |
||
291 | MSG_SIZE_AFTER = Size after: |
||
292 | MSG_COFF = Converting to AVR COFF: |
||
293 | MSG_EXTENDED_COFF = Converting to AVR Extended COFF: |
||
294 | MSG_FLASH = Creating load file for Flash: |
||
295 | MSG_EEPROM = Creating load file for EEPROM: |
||
296 | MSG_EXTENDED_LISTING = Creating Extended Listing: |
||
297 | MSG_SYMBOL_TABLE = Creating Symbol Table: |
||
298 | MSG_LINKING = Linking: |
||
299 | MSG_COMPILING = Compiling: |
||
300 | MSG_ASSEMBLING = Assembling: |
||
301 | MSG_CLEANING = Cleaning project: |
||
302 | |||
303 | |||
304 | |||
305 | |||
306 | # Define all object files. |
||
307 | OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) |
||
308 | |||
309 | # Define all listing files. |
||
310 | LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) |
||
311 | |||
312 | |||
313 | # Compiler flags to generate dependency files. |
||
314 | GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d |
||
315 | |||
316 | |||
317 | # Combine all necessary flags and optional flags. |
||
318 | # Add target processor to flags. |
||
319 | ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) |
||
320 | ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) |
||
321 | |||
322 | |||
323 | |||
324 | |||
325 | |||
326 | # Default target. |
||
327 | all: begin gccversion sizebefore build sizeafter end |
||
328 | |||
329 | build: elf hex eep lss sym |
||
330 | |||
331 | elf: $(TARGET).elf |
||
332 | hex: $(TARGET).hex |
||
333 | eep: $(TARGET).eep |
||
334 | lss: $(TARGET).lss |
||
335 | sym: $(TARGET).sym |
||
336 | |||
337 | |||
338 | |||
339 | # Eye candy. |
||
340 | # AVR Studio 3.x does not check make's exit code but relies on |
||
341 | # the following magic strings to be generated by the compile job. |
||
342 | begin: |
||
343 | @echo |
||
344 | @echo $(MSG_BEGIN) |
||
345 | |||
346 | end: |
||
347 | @echo $(MSG_END) |
||
348 | @echo |
||
349 | |||
350 | |||
351 | # Display size of file. |
||
352 | HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex |
||
353 | ELFSIZE = $(SIZE) -A $(TARGET).elf |
||
354 | AVRMEM = avr-mem.sh $(TARGET).elf $(MCU) |
||
355 | |||
356 | sizebefore: |
||
357 | @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \ |
||
358 | $(AVRMEM) 2>/dev/null; echo; fi |
||
359 | |||
360 | sizeafter: |
||
361 | @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \ |
||
362 | $(AVRMEM) 2>/dev/null; echo; fi |
||
363 | |||
364 | |||
365 | |||
366 | # Display compiler version information. |
||
367 | gccversion : |
||
368 | @$(CC) --version |
||
369 | |||
370 | |||
371 | |||
372 | # Program the device. |
||
373 | program: $(TARGET).hex $(TARGET).eep |
||
374 | $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) |
||
375 | |||
376 | |||
377 | # Generate avr-gdb config/init file which does the following: |
||
378 | # define the reset signal, load the target file, connect to target, and set |
||
379 | # a breakpoint at main(). |
||
380 | gdb-config: |
||
381 | @$(REMOVE) $(GDBINIT_FILE) |
||
382 | @echo define reset >> $(GDBINIT_FILE) |
||
383 | @echo SIGNAL SIGHUP >> $(GDBINIT_FILE) |
||
384 | @echo end >> $(GDBINIT_FILE) |
||
385 | @echo file $(TARGET).elf >> $(GDBINIT_FILE) |
||
386 | @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE) |
||
387 | ifeq ($(DEBUG_BACKEND),simulavr) |
||
388 | @echo load >> $(GDBINIT_FILE) |
||
389 | endif |
||
390 | @echo break main >> $(GDBINIT_FILE) |
||
391 | |||
392 | debug: gdb-config $(TARGET).elf |
||
393 | ifeq ($(DEBUG_BACKEND), avarice) |
||
394 | @echo Starting AVaRICE - Press enter when "waiting to connect" message displays. |
||
395 | @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \ |
||
396 | $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT) |
||
397 | @$(WINSHELL) /c pause |
||
398 | |||
399 | else |
||
400 | @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \ |
||
401 | $(DEBUG_MFREQ) --port $(DEBUG_PORT) |
||
402 | endif |
||
403 | @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE) |
||
404 | |||
405 | |||
406 | |||
407 | |||
408 | # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. |
||
409 | COFFCONVERT=$(OBJCOPY) --debugging \ |
||
410 | --change-section-address .data-0x800000 \ |
||
411 | --change-section-address .bss-0x800000 \ |
||
412 | --change-section-address .noinit-0x800000 \ |
||
413 | --change-section-address .eeprom-0x810000 |
||
414 | |||
415 | |||
416 | coff: $(TARGET).elf |
||
417 | @echo |
||
418 | @echo $(MSG_COFF) $(TARGET).cof |
||
419 | $(COFFCONVERT) -O coff-avr $< $(TARGET).cof |
||
420 | |||
421 | |||
422 | extcoff: $(TARGET).elf |
||
423 | @echo |
||
424 | @echo $(MSG_EXTENDED_COFF) $(TARGET).cof |
||
425 | $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof |
||
426 | |||
427 | |||
428 | |||
429 | # Create final output files (.hex, .eep) from ELF output file. |
||
430 | %.hex: %.elf |
||
431 | @echo |
||
432 | @echo $(MSG_FLASH) $@ |
||
433 | $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ |
||
434 | |||
435 | %.eep: %.elf |
||
436 | @echo |
||
437 | @echo $(MSG_EEPROM) $@ |
||
438 | -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ |
||
439 | --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ |
||
440 | |||
441 | # Create extended listing file from ELF output file. |
||
442 | %.lss: %.elf |
||
443 | @echo |
||
444 | @echo $(MSG_EXTENDED_LISTING) $@ |
||
445 | $(OBJDUMP) -h -S $< > $@ |
||
446 | |||
447 | # Create a symbol table from ELF output file. |
||
448 | %.sym: %.elf |
||
449 | @echo |
||
450 | @echo $(MSG_SYMBOL_TABLE) $@ |
||
451 | $(NM) -n $< > $@ |
||
452 | |||
453 | |||
454 | |||
455 | # Link: create ELF output file from object files. |
||
456 | .SECONDARY : $(TARGET).elf |
||
457 | .PRECIOUS : $(OBJ) |
||
458 | %.elf: $(OBJ) |
||
459 | @echo |
||
460 | @echo $(MSG_LINKING) $@ |
||
461 | $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) |
||
462 | |||
463 | |||
464 | # Compile: create object files from C source files. |
||
465 | %.o : %.c |
||
466 | @echo |
||
467 | @echo $(MSG_COMPILING) $< |
||
468 | $(CC) -c $(ALL_CFLAGS) $< -o $@ |
||
469 | |||
470 | |||
471 | # Compile: create assembler files from C source files. |
||
472 | %.s : %.c |
||
473 | $(CC) -S $(ALL_CFLAGS) $< -o $@ |
||
474 | |||
475 | |||
476 | # Assemble: create object files from assembler source files. |
||
477 | %.o : %.S |
||
478 | @echo |
||
479 | @echo $(MSG_ASSEMBLING) $< |
||
480 | $(CC) -c $(ALL_ASFLAGS) $< -o $@ |
||
481 | |||
482 | # Create preprocessed source for use in sending a bug report. |
||
483 | %.i : %.c |
||
484 | $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ |
||
485 | |||
486 | |||
487 | # Target: clean project. |
||
488 | clean: begin clean_list end |
||
489 | |||
490 | clean_list : |
||
491 | @echo |
||
492 | @echo $(MSG_CLEANING) |
||
493 | $(REMOVE) $(TARGET).hex |
||
494 | $(REMOVE) $(TARGET).eep |
||
495 | $(REMOVE) $(TARGET).cof |
||
496 | $(REMOVE) $(TARGET).elf |
||
497 | $(REMOVE) $(TARGET).map |
||
498 | $(REMOVE) $(TARGET).sym |
||
499 | $(REMOVE) $(TARGET).lss |
||
500 | $(REMOVE) $(OBJ) |
||
501 | $(REMOVE) $(LST) |
||
502 | $(REMOVE) $(SRC:.c=.s) |
||
503 | $(REMOVE) $(SRC:.c=.d) |
||
504 | $(REMOVEDIR) .dep |
||
505 | |||
506 | |||
507 | |||
508 | # Include the dependency files. |
||
509 | -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) |
||
510 | |||
511 | |||
512 | # Listing of phony targets. |
||
513 | .PHONY : all begin finish end sizebefore sizeafter gccversion \ |
||
514 | build elf hex eep lss sym coff extcoff \ |
||
515 | clean clean_list program debug gdb-config |