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.
12 # Target name and MCU setup -------------------------------------------------
18 # Processor frequency.
19 # This will define a symbol, F_CPU, in all source code files equal to the
20 # processor frequency. You can then use this symbol in your source code to
21 # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
22 # automatically to create a 32-bit value in your source code.
39 # Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
44 # Fancy 20MHz settings:
46 ## Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
51 # Source files to compile ---------------------------------------------------
53 # List C source files here. (C dependencies are automatically generated.)
54 SRC
= $(TARGET
).c render.c draw.c
56 # List Assembler source files here.
57 # Make them always end in a capital .S.
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.)
65 # Output formats and debug format -------------------------------------------
67 # Output format. (can be srec, ihex, binary)
71 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
72 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
75 # Command names (and paths/parameters to them...) ---------------------------
86 # Compiler flag to set the C Standard level.
88 # gnu89 - c89 plus GCC extensions
89 # c99 - ISO C99 standard (not yet fully implemented)
90 # gnu99 - c99 plus GCC extensions
91 CSTANDARD
= -std
=gnu99
93 # Place -D or -U options here
94 CDEFS
= -DF_CPU
=$(F_CPU
)UL
96 # Place -I options here
99 CFLAGS
= -g
$(CDEBUG
) $(CDEFS
) $(CINCS
) -O
$(OPT
) $(CSTANDARD
)
100 CFLAGS
+= -funsigned-char
101 CFLAGS
+= -funsigned-bitfields
102 CFLAGS
+= -fpack-struct
103 CFLAGS
+= -fshort-enums
105 CFLAGS
+= -Wstrict-prototypes
106 #CFLAGS += -mshort-calls
107 #CFLAGS += -fno-unit-at-a-time
109 #CFLAGS += -Wunreachable-code
110 #CFLAGS += -Wsign-compare
112 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
115 #Additional libraries.
119 # Minimalistic printf version
120 PRINTF_LIB_MIN
= -Wl
,-u
,vfprintf
-lprintf_min
122 # Floating point printf version (requires MATH_LIB = -lm)
123 PRINTF_LIB_FLOAT
= -Wl
,-u
,vfprintf
-lprintf_flt
125 # If this is left blank, then it will use the Standard printf version.
127 #PRINTF_LIB = $(PRINTF_LIB_MIN)
128 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
131 # Minimalistic scanf version
132 SCANF_LIB_MIN
= -Wl
,-u
,vfscanf
-lscanf_min
134 # Floating point + %[ scanf version (requires MATH_LIB = -lm)
135 SCANF_LIB_FLOAT
= -Wl
,-u
,vfscanf
-lscanf_flt
137 # If this is left blank, then it will use the Standard scanf version.
139 #SCANF_LIB = $(SCANF_LIB_MIN)
140 #SCANF_LIB = $(SCANF_LIB_FLOAT)
143 # External memory options
145 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
146 # used for variables (.data/.bss) and heap (malloc()).
147 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
149 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
150 # only used for heap (malloc()).
151 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
156 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
157 LDFLAGS
= $(EXTMEMOPTS
) $(LDMAP
) $(PRINTF_LIB
) $(SCANF_LIB
) $(MATH_LIB
)
160 # Programming support using avrdude. Settings and variables.
162 AVRDUDE_PROGRAMMER
= usbtiny
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