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