1 # Hey Emacs, this is a -*- makefile -*-
3 # AVR-GCC Makefile template, derived from the WinAVR template (which
4 # is public domain), believed to be neutral to any flavor of "make"
5 # (GNU make, BSD make, SysV make)
7 # Adaptations by Jon Langseth <jon.langseth AT lilug.no>
8 # This modified template is placed in the public domain like the original.
11 #AVRDUDE_PROGRAMMER = usbasp
12 AVRDUDE_PROGRAMMER
= usbtiny
15 # Target name and MCU setup -------------------------------------------------
21 # Processor frequency.
22 # This will define a symbol, F_CPU, in all source code files equal to the
23 # processor frequency. You can then use this symbol in your source code to
24 # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
25 # automatically to create a 32-bit value in your source code.
42 # Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
47 # Fancy 20MHz settings:
49 ## Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
54 # Source files to compile ---------------------------------------------------
56 # List C source files here. (C dependencies are automatically generated.)
57 SRC
= $(TARGET
).c render.c draw.c
59 # List Assembler source files here.
60 # Make them always end in a capital .S.
63 # Optimization level, can be [0, 1, 2, 3, s].
64 # 0 = turn off optimization. s = optimize for size.
65 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
68 # Output formats and debug format -------------------------------------------
70 # Output format. (can be srec, ihex, binary)
74 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
75 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
78 # Command names (and paths/parameters to them...) ---------------------------
89 # Compiler flag to set the C Standard level.
91 # gnu89 - c89 plus GCC extensions
92 # c99 - ISO C99 standard (not yet fully implemented)
93 # gnu99 - c99 plus GCC extensions
94 CSTANDARD
= -std
=gnu99
96 # Place -D or -U options here
97 CDEFS
= -DF_CPU
=$(F_CPU
)UL
99 # Place -I options here
102 CFLAGS
= -g
$(CDEBUG
) $(CDEFS
) $(CINCS
) -O
$(OPT
) $(CSTANDARD
)
103 CFLAGS
+= -funsigned-char
104 CFLAGS
+= -funsigned-bitfields
105 CFLAGS
+= -fpack-struct
106 CFLAGS
+= -fshort-enums
108 CFLAGS
+= -Wstrict-prototypes
109 #CFLAGS += -mshort-calls
110 #CFLAGS += -fno-unit-at-a-time
112 #CFLAGS += -Wunreachable-code
113 #CFLAGS += -Wsign-compare
115 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
118 #Additional libraries.
122 # Minimalistic printf version
123 PRINTF_LIB_MIN
= -Wl
,-u
,vfprintf
-lprintf_min
125 # Floating point printf version (requires MATH_LIB = -lm)
126 PRINTF_LIB_FLOAT
= -Wl
,-u
,vfprintf
-lprintf_flt
128 # If this is left blank, then it will use the Standard printf version.
130 #PRINTF_LIB = $(PRINTF_LIB_MIN)
131 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
134 # Minimalistic scanf version
135 SCANF_LIB_MIN
= -Wl
,-u
,vfscanf
-lscanf_min
137 # Floating point + %[ scanf version (requires MATH_LIB = -lm)
138 SCANF_LIB_FLOAT
= -Wl
,-u
,vfscanf
-lscanf_flt
140 # If this is left blank, then it will use the Standard scanf version.
142 #SCANF_LIB = $(SCANF_LIB_MIN)
143 #SCANF_LIB = $(SCANF_LIB_FLOAT)
146 # External memory options
148 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
149 # used for variables (.data/.bss) and heap (malloc()).
150 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
152 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
153 # only used for heap (malloc()).
154 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
159 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
160 LDFLAGS
= $(EXTMEMOPTS
) $(LDMAP
) $(PRINTF_LIB
) $(SCANF_LIB
) $(MATH_LIB
)
163 # Programming support using avrdude. Settings and variables.
165 AVRDUDE_WRITE_FLASH
= -U flash
:w
:$(TARGET
).hex
166 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
169 # Uncomment the following if you want avrdude's erase cycle counter.
170 # Note that this counter needs to be initialized first using -Yn,
171 # see avrdude manual.
172 #AVRDUDE_ERASE_COUNTER = -y
174 # Uncomment the following if you do /not/ wish a verification to be
175 # performed after programming the device.
176 #AVRDUDE_NO_VERIFY = -V
178 # Increase verbosity level. Please use this when submitting bug
179 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
180 # to submit bug reports.
181 #AVRDUDE_VERBOSE = -v -v
183 AVRDUDE_BASIC
= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
184 AVRDUDE_FLAGS
= $(AVRDUDE_BASIC
) $(AVRDUDE_NO_VERIFY
) $(AVRDUDE_VERBOSE
) $(AVRDUDE_ERASE_COUNTER
)
187 # Define all object files.
188 OBJ
= $(SRC
:.c
=.o
) $(ASRC
:.S
=.o
)
190 # Define all listing files.
191 LST
= $(ASRC
:.S
=.lst
) $(SRC
:.c
=.lst
)
193 # Combine all necessary flags and optional flags.
194 # Add target processor to flags.
195 ALL_CFLAGS
= -mmcu
=$(MCU
) -I.
$(CFLAGS
)
196 ALL_ASFLAGS
= -mmcu
=$(MCU
) -I.
-x assembler-with-cpp
$(ASFLAGS
)
202 build
: elf hex eep size
210 # Display size of file.
211 HEXSIZE
= $(SIZE
) --target
=$(FORMAT
) $(TARGET
).hex
212 ELFSIZE
= $(SIZE
) --mcu
=$(MCU
) --format
=avr
$(TARGET
).elf
216 $(SIZE
) --mcu
=$(MCU
) --format
=avr
$(TARGET
).elf
217 $(SIZE
) --target
=$(FORMAT
) $(TARGET
).hex
219 # Program the device.
220 program
: $(TARGET
).hex
$(TARGET
).eep
221 $(AVRDUDE
) $(AVRDUDE_FLAGS
) $(AVRDUDE_WRITE_FLASH
) $(AVRDUDE_WRITE_EEPROM
)
224 # make fuseread can be used to test programmer connectivity, and naturally to verify fuses..
226 $(AVRDUDE
) $(AVRDUDE_BASIC
) -q
-U lfuse
:r
:-:h
-U hfuse
:r
:-:h
-U efuse
:r
:-:h
230 FUSES
+= -U efuse
:w
:$(FUSE_EXT
):m
232 FUSES
+= -U hfuse
:w
:$(FUSE_HIGH
):m
233 FUSES
+= -U lfuse
:w
:$(FUSE_LOW
):m
235 fusebits
: $(TARGET
).hex
236 $(AVRDUDE
) $(AVRDUDE_BASIC
) $(FUSES
)
237 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
238 COFFCONVERT
=$(OBJCOPY
) --debugging \
239 --change-section-address .data-0x800000 \
240 --change-section-address .bss-0x800000 \
241 --change-section-address .noinit-0x800000 \
242 --change-section-address .eeprom-0x810000
246 $(COFFCONVERT
) -O coff-avr
$(TARGET
).elf
$(TARGET
).cof
249 extcoff
: $(TARGET
).elf
250 $(COFFCONVERT
) -O coff-ext-avr
$(TARGET
).elf
$(TARGET
).cof
253 .SUFFIXES
: .elf .hex .eep .lss .sym
256 $(OBJCOPY
) -O
$(FORMAT
) -R .eeprom
$< $@
259 -$(OBJCOPY
) -j .eeprom
--set-section-flags
=.eeprom
="alloc,load" \
260 --change-section-lma .eeprom
=0 -O
$(FORMAT
) $< $@
262 # Create extended listing file from ELF output file.
264 $(OBJDUMP
) -h
-S
$< > $@
266 # Create a symbol table from ELF output file.
272 # Link: create ELF output file from object files.
273 $(TARGET
).elf
: $(OBJ
)
274 $(CC
) $(ALL_CFLAGS
) $(OBJ
) --output
$@
$(LDFLAGS
)
277 # Compile: create object files from C source files.
279 $(CC
) -c
$(ALL_CFLAGS
) $< -o
$@
282 # Compile: create assembler files from C source files.
284 $(CC
) -S
$(ALL_CFLAGS
) $< -o
$@
287 # Assemble: create object files from assembler source files.
289 $(CC
) -c
$(ALL_ASFLAGS
) $< -o
$@
293 # Target: clean project.
295 $(REMOVE
) $(TARGET
).hex
$(TARGET
).eep
$(TARGET
).cof
$(TARGET
).elf \
296 $(TARGET
).map
$(TARGET
).sym
$(TARGET
).lss \
297 $(OBJ
) $(LST
) $(SRC
:.c
=.s
) $(SRC
:.c
=.d
)
299 # Name of this Makefile (used for "make depend").
303 if grep
'^# DO NOT DELETE' $(MAKEFILE
) >/dev
/null
; \
305 sed
-e
'/^# DO NOT DELETE/,$$d' $(MAKEFILE
) > \
306 $(MAKEFILE
).
$$$$ && \
307 $(MV
) $(MAKEFILE
).
$$$$ $(MAKEFILE
); \
309 echo
'# DO NOT DELETE THIS LINE -- make depend depends on it.' \
311 $(CC
) -M
-mmcu
=$(MCU
) $(CDEFS
) $(CINCS
) $(SRC
) $(ASRC
) >> $(MAKEFILE
)
313 .PHONY
: all build elf hex eep lss sym program coff extcoff
clean depend