1 # Hey Emacs, this is a -*- makefile -*-
3 # WinAVR Sample 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".
38 # Output format. (can be srec, ihex, binary)
41 # Target file name (without extension).
45 # List C source files here. (C dependencies are automatically generated.)
46 SRC = $(TARGET).c lcd.c
49 # List Assembler source files here.
50 # Make them always end in a capital .S. Files ending in a lowercase .s
51 # will not be considered source files but generated files (assembler
52 # output from the compiler), and will be deleted upon "make clean"!
53 # Even though the DOS/Win* filesystem matches both .s and .S the same,
54 # it will preserve the spelling of the filenames, and gcc itself does
55 # care about how the name is spelled on its command-line.
60 # Optimization level, can be [0, 1, 2, 3, s].
61 # 0 = turn off optimization. s = optimize for size.
62 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
66 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
67 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
70 # List any extra directories to look for include files here.
71 # Each directory must be seperated by a space.
75 # Compiler flag to set the C Standard level.
77 # gnu89 - c89 plus GCC extensions
78 # c99 - ISO C99 standard (not yet fully implemented)
79 # gnu99 - c99 plus GCC extensions
80 CSTANDARD = -std=gnu99
82 # Place -D or -U options here
85 # Place -I options here
90 # -g*: generate debugging information
91 # -O*: optimization level
92 # -f...: tuning, see GCC manual and avr-libc documentation
93 # -Wall...: warning level
94 # -Wa,...: tell GCC to pass this to the assembler.
95 # -adhlns...: create assembler listing
97 CFLAGS += $(CDEFS) $(CINCS)
99 CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
100 CFLAGS += -Wall -Wstrict-prototypes
101 CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
102 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
103 CFLAGS += $(CSTANDARD)
108 # -Wa,...: tell GCC to pass this to the assembler.
109 # -ahlms: create listing
110 # -gstabs: have the assembler create line number information; note that
111 # for use in COFF files, additional information about filenames
112 # and function names needs to be present in the assembler source
113 # files -- see avr-libc docs [FIXME: not yet described there]
114 ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
118 #Additional libraries.
120 # Minimalistic printf version
121 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
123 # Floating point printf version (requires MATH_LIB = -lm below)
124 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
128 # Minimalistic scanf version
129 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
131 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
132 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
138 # External memory options
140 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
141 # used for variables (.data/.bss) and heap (malloc()).
142 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
144 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
145 # only used for heap (malloc()).
146 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
151 # -Wl,...: tell GCC to pass this to linker.
152 # -Map: create map file
153 # --cref: add cross reference to map file
154 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
155 LDFLAGS += $(EXTMEMOPTS)
156 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
161 # Programming support using avrdude. Settings and variables.
163 # Programming hardware: alf avr910 avrisp bascom bsd
164 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
167 # to get a full listing.
169 AVRDUDE_PROGRAMMER = usbtiny
171 # com1 = serial port. Use lpt1 to connect to parallel port.
172 #AVRDUDE_PORT = com1 # programmer connected to serial device
174 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
175 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
178 # Uncomment the following if you want avrdude's erase cycle counter.
179 # Note that this counter needs to be initialized first using -Yn,
180 # see avrdude manual.
181 #AVRDUDE_ERASE_COUNTER = -y
183 # Uncomment the following if you do /not/ wish a verification to be
184 # performed after programming the device.
185 #AVRDUDE_NO_VERIFY = -V
187 # Increase verbosity level. Please use this when submitting bug
188 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
189 # to submit bug reports.
190 #AVRDUDE_VERBOSE = -v -v
192 AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER)
193 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
194 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
195 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
199 # ---------------------------------------------------------------------------
201 # Define directories, if needed.
203 #DIRAVRBIN = $(DIRAVR)/bin
204 #DIRAVRUTILS = $(DIRAVR)/utils/bin
206 #DIRLIB = $(DIRAVR)/avr/lib
209 # Define programs and commands.
212 OBJCOPY = avr-objcopy
213 OBJDUMP = avr-objdump
225 MSG_ERRORS_NONE = Errors: none
226 MSG_BEGIN = -------- begin --------
227 MSG_END = -------- end --------
228 MSG_SIZE_BEFORE = Size before:
229 MSG_SIZE_AFTER = Size after:
230 MSG_COFF = Converting to AVR COFF:
231 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
232 MSG_FLASH = Creating load file for Flash:
233 MSG_EEPROM = Creating load file for EEPROM:
234 MSG_EXTENDED_LISTING = Creating Extended Listing:
235 MSG_SYMBOL_TABLE = Creating Symbol Table:
236 MSG_LINKING = Linking:
237 MSG_COMPILING = Compiling:
238 MSG_ASSEMBLING = Assembling:
239 MSG_CLEANING = Cleaning project:
244 # Define all object files.
245 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
247 # Define all listing files.
248 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
251 # Compiler flags to generate dependency files.
252 GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
255 # Combine all necessary flags and optional flags.
256 # Add target processor to flags.
257 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
258 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
265 all: begin gccversion sizebefore build sizeafter finished end
267 build: elf hex eep lss sym
278 # AVR Studio 3.x does not check make's exit code but relies on
279 # the following magic strings to be generated by the compile job.
285 @echo $(MSG_ERRORS_NONE)
292 # Display size of file.
293 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
294 ELFSIZE = $(SIZE) -A $(TARGET).elf
296 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
299 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
303 # Display compiler version information.
309 # Program the device.
310 program: $(TARGET).hex $(TARGET).eep
311 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
316 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
317 COFFCONVERT=$(OBJCOPY) --debugging \
318 --change-section-address .data-0x800000 \
319 --change-section-address .bss-0x800000 \
320 --change-section-address .noinit-0x800000 \
321 --change-section-address .eeprom-0x810000
326 @echo $(MSG_COFF) $(TARGET).cof
327 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
330 extcoff: $(TARGET).elf
332 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
333 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
337 # Create final output files (.hex, .eep) from ELF output file.
340 @echo $(MSG_FLASH) $@
341 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
345 @echo $(MSG_EEPROM) $@
346 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
347 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
349 # Create extended listing file from ELF output file.
352 @echo $(MSG_EXTENDED_LISTING) $@
353 $(OBJDUMP) -h -S $< > $@
355 # Create a symbol table from ELF output file.
358 @echo $(MSG_SYMBOL_TABLE) $@
363 # Link: create ELF output file from object files.
364 .SECONDARY : $(TARGET).elf
368 @echo $(MSG_LINKING) $@
369 $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
372 # Compile: create object files from C source files.
375 @echo $(MSG_COMPILING) $<
376 $(CC) -c $(ALL_CFLAGS) $< -o $@
379 # Compile: create assembler files from C source files.
381 $(CC) -S $(ALL_CFLAGS) $< -o $@
384 # Assemble: create object files from assembler source files.
387 @echo $(MSG_ASSEMBLING) $<
388 $(CC) -c $(ALL_ASFLAGS) $< -o $@
392 # Target: clean project.
393 clean: begin clean_list finished end
397 @echo $(MSG_CLEANING)
398 $(REMOVE) $(TARGET).hex
399 $(REMOVE) $(TARGET).eep
400 $(REMOVE) $(TARGET).obj
401 $(REMOVE) $(TARGET).cof
402 $(REMOVE) $(TARGET).elf
403 $(REMOVE) $(TARGET).map
404 $(REMOVE) $(TARGET).obj
405 $(REMOVE) $(TARGET).a90
406 $(REMOVE) $(TARGET).sym
407 $(REMOVE) $(TARGET).lnk
408 $(REMOVE) $(TARGET).lss
411 $(REMOVE) $(SRC:.c=.s)
412 $(REMOVE) $(SRC:.c=.d)
417 # Include the dependency files.
418 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
421 # Listing of phony targets.
422 .PHONY : all begin finish end sizebefore sizeafter gccversion \
423 build elf hex eep lss sym coff extcoff \
424 clean clean_list program