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.
38 # Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
42 # Have had problems with efuse suggested by fusecalc, must check :P
44 # Source files to compile ---------------------------------------------------
46 # List C source files here. (C dependencies are automatically generated.)
49 # List Assembler source files here.
50 # Make them always end in a capital .S.
53 # Optimization level, can be [0, 1, 2, 3, s].
54 # 0 = turn off optimization. s = optimize for size.
55 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
58 # Output formats and debug format -------------------------------------------
60 # Output format. (can be srec, ihex, binary)
64 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
65 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
68 # Command names (and paths/parameters to them...) ---------------------------
79 # Compiler flag to set the C Standard level.
81 # gnu89 - c89 plus GCC extensions
82 # c99 - ISO C99 standard (not yet fully implemented)
83 # gnu99 - c99 plus GCC extensions
84 CSTANDARD
= -std
=gnu99
86 # Place -D or -U options here
87 CDEFS
= -DF_CPU
=$(F_CPU
)UL
89 # Place -I options here
92 CFLAGS
= -g
$(CDEBUG
) $(CDEFS
) $(CINCS
) -O
$(OPT
) $(CSTANDARD
)
93 CFLAGS
+= -funsigned-char
94 CFLAGS
+= -funsigned-bitfields
95 CFLAGS
+= -fpack-struct
96 CFLAGS
+= -fshort-enums
98 CFLAGS
+= -Wstrict-prototypes
99 #CFLAGS += -mshort-calls
100 #CFLAGS += -fno-unit-at-a-time
102 #CFLAGS += -Wunreachable-code
103 #CFLAGS += -Wsign-compare
105 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
108 #Additional libraries.
112 # Minimalistic printf version
113 PRINTF_LIB_MIN
= -Wl
,-u
,vfprintf
-lprintf_min
115 # Floating point printf version (requires MATH_LIB = -lm)
116 PRINTF_LIB_FLOAT
= -Wl
,-u
,vfprintf
-lprintf_flt
118 # If this is left blank, then it will use the Standard printf version.
120 #PRINTF_LIB = $(PRINTF_LIB_MIN)
121 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
124 # Minimalistic scanf version
125 SCANF_LIB_MIN
= -Wl
,-u
,vfscanf
-lscanf_min
127 # Floating point + %[ scanf version (requires MATH_LIB = -lm)
128 SCANF_LIB_FLOAT
= -Wl
,-u
,vfscanf
-lscanf_flt
130 # If this is left blank, then it will use the Standard scanf version.
132 #SCANF_LIB = $(SCANF_LIB_MIN)
133 #SCANF_LIB = $(SCANF_LIB_FLOAT)
136 # External memory options
138 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
139 # used for variables (.data/.bss) and heap (malloc()).
140 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
142 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
143 # only used for heap (malloc()).
144 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
149 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
150 LDFLAGS
= $(EXTMEMOPTS
) $(LDMAP
) $(PRINTF_LIB
) $(SCANF_LIB
) $(MATH_LIB
)
153 # Programming support using avrdude. Settings and variables.
155 AVRDUDE_PROGRAMMER
= usbtiny
158 AVRDUDE_WRITE_FLASH
= -U flash
:w
:$(TARGET
).hex
159 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
162 # Uncomment the following if you want avrdude's erase cycle counter.
163 # Note that this counter needs to be initialized first using -Yn,
164 # see avrdude manual.
165 #AVRDUDE_ERASE_COUNTER = -y
167 # Uncomment the following if you do /not/ wish a verification to be
168 # performed after programming the device.
169 #AVRDUDE_NO_VERIFY = -V
171 # Increase verbosity level. Please use this when submitting bug
172 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
173 # to submit bug reports.
174 #AVRDUDE_VERBOSE = -v -v
176 AVRDUDE_BASIC
= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
177 AVRDUDE_FLAGS
= $(AVRDUDE_BASIC
) $(AVRDUDE_NO_VERIFY
) $(AVRDUDE_VERBOSE
) $(AVRDUDE_ERASE_COUNTER
)
180 # Define all object files.
181 OBJ
= $(SRC
:.c
=.o
) $(ASRC
:.S
=.o
)
183 # Define all listing files.
184 LST
= $(ASRC
:.S
=.lst
) $(SRC
:.c
=.lst
)
186 # Combine all necessary flags and optional flags.
187 # Add target processor to flags.
188 ALL_CFLAGS
= -mmcu
=$(MCU
) -I.
$(CFLAGS
)
189 ALL_ASFLAGS
= -mmcu
=$(MCU
) -I.
-x assembler-with-cpp
$(ASFLAGS
)
195 build
: elf hex eep size
203 # Display size of file.
204 HEXSIZE
= $(SIZE
) --target
=$(FORMAT
) $(TARGET
).hex
205 ELFSIZE
= $(SIZE
) --mcu
=$(MCU
) --format
=avr
$(TARGET
).elf
209 $(SIZE
) --mcu
=$(MCU
) --format
=avr
$(TARGET
).elf
210 $(SIZE
) --target
=$(FORMAT
) $(TARGET
).hex
212 # Program the device.
213 program
: $(TARGET
).hex
$(TARGET
).eep
214 $(AVRDUDE
) $(AVRDUDE_FLAGS
) $(AVRDUDE_WRITE_FLASH
) $(AVRDUDE_WRITE_EEPROM
)
217 # make fuseread can be used to test programmer connectivity, and naturally to verify fuses..
219 $(AVRDUDE
) $(AVRDUDE_BASIC
) -q
-U lfuse
:r
:-:h
-U hfuse
:r
:-:h
-U efuse
:r
:-:h
223 FUSES
+= -U efuse
:w
:$(FUSE_EXT
):m
225 FUSES
+= -U hfuse
:w
:$(FUSE_HIGH
):m
226 FUSES
+= -U lfuse
:w
:$(FUSE_LOW
):m
228 fusebits
: $(TARGET
).hex
229 $(AVRDUDE
) $(AVRDUDE_BASIC
) $(FUSES
)
230 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
231 COFFCONVERT
=$(OBJCOPY
) --debugging \
232 --change-section-address .data-0x800000 \
233 --change-section-address .bss-0x800000 \
234 --change-section-address .noinit-0x800000 \
235 --change-section-address .eeprom-0x810000
239 $(COFFCONVERT
) -O coff-avr
$(TARGET
).elf
$(TARGET
).cof
242 extcoff
: $(TARGET
).elf
243 $(COFFCONVERT
) -O coff-ext-avr
$(TARGET
).elf
$(TARGET
).cof
246 .SUFFIXES
: .elf .hex .eep .lss .sym
249 $(OBJCOPY
) -O
$(FORMAT
) -R .eeprom
$< $@
252 -$(OBJCOPY
) -j .eeprom
--set-section-flags
=.eeprom
="alloc,load" \
253 --change-section-lma .eeprom
=0 -O
$(FORMAT
) $< $@
255 # Create extended listing file from ELF output file.
257 $(OBJDUMP
) -h
-S
$< > $@
259 # Create a symbol table from ELF output file.
265 # Link: create ELF output file from object files.
266 $(TARGET
).elf
: $(OBJ
)
267 $(CC
) $(ALL_CFLAGS
) $(OBJ
) --output
$@
$(LDFLAGS
)
270 # Compile: create object files from C source files.
272 $(CC
) -c
$(ALL_CFLAGS
) $< -o
$@
275 # Compile: create assembler files from C source files.
277 $(CC
) -S
$(ALL_CFLAGS
) $< -o
$@
280 # Assemble: create object files from assembler source files.
282 $(CC
) -c
$(ALL_ASFLAGS
) $< -o
$@
286 # Target: clean project.
288 $(REMOVE
) $(TARGET
).hex
$(TARGET
).eep
$(TARGET
).cof
$(TARGET
).elf \
289 $(TARGET
).map
$(TARGET
).sym
$(TARGET
).lss \
290 $(OBJ
) $(LST
) $(SRC
:.c
=.s
) $(SRC
:.c
=.d
)
292 # Name of this Makefile (used for "make depend").
296 if grep
'^# DO NOT DELETE' $(MAKEFILE
) >/dev
/null
; \
298 sed
-e
'/^# DO NOT DELETE/,$$d' $(MAKEFILE
) > \
299 $(MAKEFILE
).
$$$$ && \
300 $(MV
) $(MAKEFILE
).
$$$$ $(MAKEFILE
); \
302 echo
'# DO NOT DELETE THIS LINE -- make depend depends on it.' \
304 $(CC
) -M
-mmcu
=$(MCU
) $(CDEFS
) $(CINCS
) $(SRC
) $(ASRC
) >> $(MAKEFILE
)
306 .PHONY
: all build elf hex eep lss sym program coff extcoff
clean depend