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 AVRDUDE_BL_PROGRAMMER
= arduino
16 AVRDUDE_BL_PORT
= COM3
17 AVRDUDE_BL_SPEED
= 115200
19 # Target name and MCU setup -------------------------------------------------
25 # Processor frequency.
26 # This will define a symbol, F_CPU, in all source code files equal to the
27 # processor frequency. You can then use this symbol in your source code to
28 # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
29 # automatically to create a 32-bit value in your source code.
46 # Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
51 # Fancy 20MHz settings:
53 ## Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
64 # Source files to compile ---------------------------------------------------
66 # List C source files here. (C dependencies are automatically generated.)
67 SRC
= $(TARGET
).c render.c draw.c
69 # List Assembler source files here.
70 # Make them always end in a capital .S.
73 # Optimization level, can be [0, 1, 2, 3, s].
74 # 0 = turn off optimization. s = optimize for size.
75 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
78 # Output formats and debug format -------------------------------------------
80 # Output format. (can be srec, ihex, binary)
84 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
85 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
88 # Command names (and paths/parameters to them...) ---------------------------
99 # Compiler flag to set the C Standard level.
101 # gnu89 - c89 plus GCC extensions
102 # c99 - ISO C99 standard (not yet fully implemented)
103 # gnu99 - c99 plus GCC extensions
104 CSTANDARD
= -std
=gnu99
106 # Place -D or -U options here
107 CDEFS
= -DF_CPU
=$(F_CPU
)UL
109 # Place -I options here
112 CFLAGS
= -g
$(CDEBUG
) $(CDEFS
) $(CINCS
) -O
$(OPT
) $(CSTANDARD
)
113 CFLAGS
+= -funsigned-char
114 CFLAGS
+= -funsigned-bitfields
115 CFLAGS
+= -fpack-struct
116 CFLAGS
+= -fshort-enums
118 CFLAGS
+= -Wstrict-prototypes
119 #CFLAGS += -mshort-calls
120 #CFLAGS += -fno-unit-at-a-time
122 #CFLAGS += -Wunreachable-code
123 #CFLAGS += -Wsign-compare
125 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
128 #Additional libraries.
132 # Minimalistic printf version
133 PRINTF_LIB_MIN
= -Wl
,-u
,vfprintf
-lprintf_min
135 # Floating point printf version (requires MATH_LIB = -lm)
136 PRINTF_LIB_FLOAT
= -Wl
,-u
,vfprintf
-lprintf_flt
138 # If this is left blank, then it will use the Standard printf version.
140 #PRINTF_LIB = $(PRINTF_LIB_MIN)
141 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
144 # Minimalistic scanf version
145 SCANF_LIB_MIN
= -Wl
,-u
,vfscanf
-lscanf_min
147 # Floating point + %[ scanf version (requires MATH_LIB = -lm)
148 SCANF_LIB_FLOAT
= -Wl
,-u
,vfscanf
-lscanf_flt
150 # If this is left blank, then it will use the Standard scanf version.
152 #SCANF_LIB = $(SCANF_LIB_MIN)
153 #SCANF_LIB = $(SCANF_LIB_FLOAT)
156 # External memory options
158 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
159 # used for variables (.data/.bss) and heap (malloc()).
160 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
162 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
163 # only used for heap (malloc()).
164 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
169 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
170 LDFLAGS
= $(EXTMEMOPTS
) $(LDMAP
) $(PRINTF_LIB
) $(SCANF_LIB
) $(MATH_LIB
)
173 # Programming support using avrdude. Settings and variables.
175 AVRDUDE_WRITE_FLASH
= -U flash
:w
:$(TARGET
).hex
176 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
179 # Uncomment the following if you want avrdude's erase cycle counter.
180 # Note that this counter needs to be initialized first using -Yn,
181 # see avrdude manual.
182 #AVRDUDE_ERASE_COUNTER = -y
184 # Uncomment the following if you do /not/ wish a verification to be
185 # performed after programming the device.
186 #AVRDUDE_NO_VERIFY = -V
188 # Increase verbosity level. Please use this when submitting bug
189 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
190 # to submit bug reports.
191 #AVRDUDE_VERBOSE = -v -v
193 AVRDUDE_PROG
= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
194 AVRDUDE_FLAGS
= $(AVRDUDE_NO_VERIFY
) $(AVRDUDE_VERBOSE
) $(AVRDUDE_ERASE_COUNTER
)
197 # Define all object files.
198 OBJ
= $(SRC
:.c
=.o
) $(ASRC
:.S
=.o
)
200 # Define all listing files.
201 LST
= $(ASRC
:.S
=.lst
) $(SRC
:.c
=.lst
)
203 # Combine all necessary flags and optional flags.
204 # Add target processor to flags.
205 ALL_CFLAGS
= -mmcu
=$(MCU
) -I.
$(CFLAGS
)
206 ALL_ASFLAGS
= -mmcu
=$(MCU
) -I.
-x assembler-with-cpp
$(ASFLAGS
)
212 build
: elf hex eep size
220 # Display size of file.
221 HEXSIZE
= $(SIZE
) --target
=$(FORMAT
) $(TARGET
).hex
222 ELFSIZE
= $(SIZE
) --mcu
=$(MCU
) --format
=avr
$(TARGET
).elf
226 $(SIZE
) --mcu
=$(MCU
) --format
=avr
$(TARGET
).elf
227 $(SIZE
) --target
=$(FORMAT
) $(TARGET
).hex
229 # Program the device.
230 program
: $(TARGET
).hex
$(TARGET
).eep
231 $(AVRDUDE
) -p
$(MCU
) $(AVRDUDE_PROG
) $(AVRDUDE_FLAGS
) $(AVRDUDE_WRITE_FLASH
) $(AVRDUDE_WRITE_EEPROM
)
233 bl_program
: $(TARGET
).hex
$(TARGET
).eep
234 $(AVRDUDE
) -p
$(MCU
) -c
$(AVRDUDE_BL_PROGRAMMER
) -P
$(AVRDUDE_BL_PORT
) -b
$(AVRDUDE_BL_SPEED
) $(AVRDUDE_NO_VERIFY
) $(AVRDUDE_VERBOSE
) $(AVRDUDE_ERASE_COUNTER
) $(AVRDUDE_WRITE_FLASH
)
236 # make fuseread can be used to test programmer connectivity, and naturally to verify fuses..
238 $(AVRDUDE
) -p
$(MCU
) $(AVRDUDE_PROG
) -q
-U lfuse
:r
:-:h
-U hfuse
:r
:-:h
-U efuse
:r
:-:h
242 FUSES
+= -U efuse
:w
:$(FUSE_EXT
):m
244 FUSES
+= -U efuse
:w
:$(FUSE_EXT
):m
245 FUSES
+= -U lfuse
:w
:$(FUSE_LOW
):m
247 fusebits
: $(TARGET
).hex
248 $(AVRDUDE
) -p
$(MCU
) $(AVRDUDE_PROG
) $(FUSES
)
250 lockbits
: $(TARGET
).hex
251 $(AVRDUDE
) -p
$(MCU
) $(AVRDUDE_PROG
) -e
-u
-U lock
:w
:$(FUSE_LOCK
):m
253 bl_fusebits
: $(TARGET
).hex
254 $(AVRDUDE
) -p
$(MCU
) $(AVRDUDE_PROG
) -U efuse
:w
:$(BL_FUSE_EXT
):m
-U efuse
:w
:$(BL_FUSE_EXT
):m
-U lfuse
:w
:$(BL_FUSE_LOW
):m
256 bl_lockbits
: $(TARGET
).hex
257 $(AVRDUDE
)-p
$(MCU
) $(AVRDUDE_PROG
) -e
-u
-U lock
:w
:$(BL_FUSE_LOCK
):m
259 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
260 COFFCONVERT
=$(OBJCOPY
) --debugging \
261 --change-section-address .data-0x800000 \
262 --change-section-address .bss-0x800000 \
263 --change-section-address .noinit-0x800000 \
264 --change-section-address .eeprom-0x810000
267 $(COFFCONVERT
) -O coff-avr
$(TARGET
).elf
$(TARGET
).cof
270 extcoff
: $(TARGET
).elf
271 $(COFFCONVERT
) -O coff-ext-avr
$(TARGET
).elf
$(TARGET
).cof
274 .SUFFIXES
: .elf .hex .eep .lss .sym
277 $(OBJCOPY
) -O
$(FORMAT
) -R .eeprom
$< $@
280 -$(OBJCOPY
) -j .eeprom
--set-section-flags
=.eeprom
="alloc,load" \
281 --change-section-lma .eeprom
=0 -O
$(FORMAT
) $< $@
283 # Create extended listing file from ELF output file.
285 $(OBJDUMP
) -h
-S
$< > $@
287 # Create a symbol table from ELF output file.
293 # Link: create ELF output file from object files.
294 $(TARGET
).elf
: $(OBJ
)
295 $(CC
) $(ALL_CFLAGS
) $(OBJ
) --output
$@
$(LDFLAGS
)
298 # Compile: create object files from C source files.
300 $(CC
) -c
$(ALL_CFLAGS
) $< -o
$@
303 # Compile: create assembler files from C source files.
305 $(CC
) -S
$(ALL_CFLAGS
) $< -o
$@
308 # Assemble: create object files from assembler source files.
310 $(CC
) -c
$(ALL_ASFLAGS
) $< -o
$@
314 # Target: clean project.
316 $(REMOVE
) $(TARGET
).hex
$(TARGET
).eep
$(TARGET
).cof
$(TARGET
).elf \
317 $(TARGET
).map
$(TARGET
).sym
$(TARGET
).lss \
318 $(OBJ
) $(LST
) $(SRC
:.c
=.s
) $(SRC
:.c
=.d
)
320 # Name of this Makefile (used for "make depend").
324 if grep
'^# DO NOT DELETE' $(MAKEFILE
) >/dev
/null
; \
326 sed
-e
'/^# DO NOT DELETE/,$$d' $(MAKEFILE
) > \
327 $(MAKEFILE
).
$$$$ && \
328 $(MV
) $(MAKEFILE
).
$$$$ $(MAKEFILE
); \
330 echo
'# DO NOT DELETE THIS LINE -- make depend depends on it.' \
332 $(CC
) -M
-mmcu
=$(MCU
) $(CDEFS
) $(CINCS
) $(SRC
) $(ASRC
) >> $(MAKEFILE
)
334 .PHONY
: all build elf hex eep lss sym program coff extcoff
clean depend