root/trunk/RingBuffAdv/makefile

Revision 16, 16.5 kB (checked in by charlie, 3 years ago)

Added serial communications (transmit only).

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