1 # Hey Emacs, this is a -*- makefile -*-
\r
3 # WinAVR makefile written by Eric B. Weddington, Jörg Wunsch, et al.
\r
4 # Released to the Public Domain
\r
5 # Please read the make user manual!
\r
7 # Additional material for this makefile was submitted by:
\r
17 # make all = Make software.
\r
19 # make clean = Clean out built project files.
\r
21 # make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
\r
23 # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
\r
26 # make program = Download the hex file to the device, using avrdude. Please
\r
27 # customize the avrdude settings below first!
\r
29 # make filename.s = Just compile filename.c into the assembler code only
\r
31 # To rebuild project do "make clean" then "make all".
\r
35 # Differences from WinAVR 20040720 sample:
\r
36 # - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum)
\r
37 # - F_OSC Define in CFLAGS and AFLAGS
\r
43 # Main Oscillator Frequency
\r
44 # This is only used to define F_OSC in all assembler and c-sources.
\r
47 # Output format. (can be srec, ihex, binary)
\r
50 # Target file name (without extension).
\r
54 # List C source files here. (C dependencies are automatically generated.)
\r
55 SRC = $(TARGET).c uart.c
\r
58 # List Assembler source files here.
\r
59 # Make them always end in a capital .S. Files ending in a lowercase .s
\r
60 # will not be considered source files but generated files (assembler
\r
61 # output from the compiler), and will be deleted upon "make clean"!
\r
62 # Even though the DOS/Win* filesystem matches both .s and .S the same,
\r
63 # it will preserve the spelling of the filenames, and gcc itself does
\r
64 # care about how the name is spelled on its command-line.
\r
69 # Optimization level, can be [0, 1, 2, 3, s].
\r
70 # 0 = turn off optimization. s = optimize for size.
\r
71 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
\r
75 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
\r
76 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
\r
80 # List any extra directories to look for include files here.
\r
81 # Each directory must be seperated by a space.
\r
85 # Compiler flag to set the C Standard level.
\r
87 # gnu89 - c89 plus GCC extensions
\r
88 # c99 - ISO C99 standard (not yet fully implemented)
\r
89 # gnu99 - c99 plus GCC extensions
\r
90 CSTANDARD = -std=gnu99
\r
92 # Place -D or -U options here
\r
93 CDEFS = -DF_CPU=16000000
\r
95 # Place -I options here
\r
100 # -g*: generate debugging information
\r
101 # -O*: optimization level
\r
102 # -f...: tuning, see GCC manual and avr-libc documentation
\r
103 # -Wall...: warning level
\r
104 # -Wa,...: tell GCC to pass this to the assembler.
\r
105 # -adhlns...: create assembler listing
\r
106 CFLAGS = -g$(DEBUG)
\r
107 CFLAGS += $(CDEFS) $(CINCS)
\r
109 CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
\r
110 CFLAGS += -Wall -Wstrict-prototypes
\r
111 CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
\r
112 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
\r
113 CFLAGS += $(CSTANDARD)
\r
114 CFLAGS += -DF_OSC=$(F_OSC)
\r
119 # -Wa,...: tell GCC to pass this to the assembler.
\r
120 # -ahlms: create listing
\r
121 # -gstabs: have the assembler create line number information; note that
\r
122 # for use in COFF files, additional information about filenames
\r
123 # and function names needs to be present in the assembler source
\r
124 # files -- see avr-libc docs [FIXME: not yet described there]
\r
125 ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
\r
126 ASFLAGS += -DF_OSC=$(F_OSC)
\r
129 #Additional libraries.
\r
131 # Minimalistic printf version
\r
132 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
\r
134 # Floating point printf version (requires MATH_LIB = -lm below)
\r
135 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt -lm
\r
139 # Minimalistic scanf version
\r
140 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
\r
142 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
\r
143 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
\r
149 # External memory options
\r
151 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
\r
152 # used for variables (.data/.bss) and heap (malloc()).
\r
153 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
\r
155 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
\r
156 # only used for heap (malloc()).
\r
157 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
\r
162 # -Wl,...: tell GCC to pass this to linker.
\r
163 # -Map: create map file
\r
164 # --cref: add cross reference to map file
\r
165 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
\r
166 LDFLAGS += $(EXTMEMOPTS)
\r
167 LDFLAGS += $(PRINTF_LIB_MIN) $(SCANF_LIB) $(MATH_LIB)
\r
172 # Programming support using avrdude. Settings and variables.
\r
174 # Programming hardware: alf avr910 avrisp bascom bsd
\r
175 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
\r
177 # Type: avrdude -c ?
\r
178 # to get a full listing.
\r
180 #AVRDUDE_PROGRAMMER = avr911
\r
181 AVRDUDE_PROGRAMMER = avrisp2
\r
183 # com1 = serial port. Use lpt1 to connect to parallel port.
\r
184 #AVRDUDE_PORT = /dev/ttyUSB0 # programmer connected to serial device
\r
185 AVRDUDE_PORT = usb # programmer connected to serial device
\r
187 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
\r
188 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
\r
191 # Uncomment the following if you want avrdude's erase cycle counter.
\r
192 # Note that this counter needs to be initialized first using -Yn,
\r
193 # see avrdude manual.
\r
194 #AVRDUDE_ERASE_COUNTER = -y
\r
196 # Uncomment the following if you do /not/ wish a verification to be
\r
197 # performed after programming the device.
\r
198 #AVRDUDE_NO_VERIFY = -V
\r
200 # Increase verbosity level. Please use this when submitting bug
\r
201 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
\r
202 # to submit bug reports.
\r
203 #AVRDUDE_VERBOSE = -v -v
\r
205 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
\r
206 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
\r
207 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
\r
208 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
\r
212 # ---------------------------------------------------------------------------
\r
214 # Define directories, if needed.
\r
216 DIRAVRBIN = $(DIRAVR)/bin
\r
217 DIRAVRUTILS = $(DIRAVR)/utils/bin
\r
219 DIRLIB = $(DIRAVR)/avr/lib
\r
222 # Define programs and commands.
\r
225 OBJCOPY = avr-objcopy
\r
226 OBJDUMP = avr-objdump
\r
238 MSG_ERRORS_NONE = Errors: none
\r
239 MSG_BEGIN = -------- begin --------
\r
240 MSG_END = -------- end --------
\r
241 MSG_SIZE_BEFORE = Size before:
\r
242 MSG_SIZE_AFTER = Size after:
\r
243 MSG_COFF = Converting to AVR COFF:
\r
244 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
\r
245 MSG_FLASH = Creating load file for Flash:
\r
246 MSG_EEPROM = Creating load file for EEPROM:
\r
247 MSG_EXTENDED_LISTING = Creating Extended Listing:
\r
248 MSG_SYMBOL_TABLE = Creating Symbol Table:
\r
249 MSG_LINKING = Linking:
\r
250 MSG_COMPILING = Compiling:
\r
251 MSG_ASSEMBLING = Assembling:
\r
252 MSG_CLEANING = Cleaning project:
\r
257 # Define all object files.
\r
258 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
\r
260 # Define all listing files.
\r
261 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
\r
264 # Compiler flags to generate dependency files.
\r
265 ### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
\r
266 GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
\r
268 # Combine all necessary flags and optional flags.
\r
269 # Add target processor to flags.
\r
270 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
\r
271 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
\r
278 all: begin gccversion sizebefore build sizeafter finished end
\r
280 build: elf hex eep lss sym
\r
285 lss: $(TARGET).lss
\r
291 # AVR Studio 3.x does not check make's exit code but relies on
\r
292 # the following magic strings to be generated by the compile job.
\r
298 @echo $(MSG_ERRORS_NONE)
\r
305 # Display size of file.
\r
306 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
\r
307 ELFSIZE = $(SIZE) -A $(TARGET).elf
\r
309 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
\r
312 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
\r
316 # Display compiler version information.
\r
322 # Program the device.
\r
323 program: $(TARGET).hex $(TARGET).eep
\r
324 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
\r
329 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
\r
330 COFFCONVERT=$(OBJCOPY) --debugging \
\r
331 --change-section-address .data-0x800000 \
\r
332 --change-section-address .bss-0x800000 \
\r
333 --change-section-address .noinit-0x800000 \
\r
334 --change-section-address .eeprom-0x810000
\r
337 coff: $(TARGET).elf
\r
339 @echo $(MSG_COFF) $(TARGET).cof
\r
340 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
\r
343 extcoff: $(TARGET).elf
\r
345 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
\r
346 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
\r
350 # Create final output files (.hex, .eep) from ELF output file.
\r
353 @echo $(MSG_FLASH) $@
\r
354 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
\r
358 @echo $(MSG_EEPROM) $@
\r
359 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
\r
360 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
\r
362 # Create extended listing file from ELF output file.
\r
365 @echo $(MSG_EXTENDED_LISTING) $@
\r
366 $(OBJDUMP) -h -S $< > $@
\r
368 # Create a symbol table from ELF output file.
\r
371 @echo $(MSG_SYMBOL_TABLE) $@
\r
376 # Link: create ELF output file from object files.
\r
377 .SECONDARY : $(TARGET).elf
\r
381 @echo $(MSG_LINKING) $@
\r
382 $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
\r
385 # Compile: create object files from C source files.
\r
388 @echo $(MSG_COMPILING) $<
\r
389 $(CC) -c $(ALL_CFLAGS) $< -o $@
\r
392 # Compile: create assembler files from C source files.
\r
394 $(CC) -S $(ALL_CFLAGS) $< -o $@
\r
397 # Assemble: create object files from assembler source files.
\r
400 @echo $(MSG_ASSEMBLING) $<
\r
401 $(CC) -c $(ALL_ASFLAGS) $< -o $@
\r
405 # Target: clean project.
\r
406 clean: begin clean_list finished end
\r
410 @echo $(MSG_CLEANING)
\r
411 $(REMOVE) $(TARGET).hex
\r
412 $(REMOVE) $(TARGET).eep
\r
413 $(REMOVE) $(TARGET).obj
\r
414 $(REMOVE) $(TARGET).cof
\r
415 $(REMOVE) $(TARGET).elf
\r
416 $(REMOVE) $(TARGET).map
\r
417 $(REMOVE) $(TARGET).obj
\r
418 $(REMOVE) $(TARGET).a90
\r
419 $(REMOVE) $(TARGET).sym
\r
420 $(REMOVE) $(TARGET).lnk
\r
421 $(REMOVE) $(TARGET).lss
\r
424 $(REMOVE) $(SRC:.c=.s)
\r
425 $(REMOVE) $(SRC:.c=.d)
\r
430 # Include the dependency files.
\r
431 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
\r
434 # Listing of phony targets.
\r
435 .PHONY : all begin finish end sizebefore sizeafter gccversion \
\r
436 build elf hex eep lss sym coff extcoff \
\r
437 clean clean_list program
\r