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)
14 SRC
= $(BASEDIR
)/$(TARGET
).c \
15 $(BASEDIR
)/lib
/fifo.c \
16 $(BASEDIR
)/lib
/usart.c
20 # Name of this Makefile (used for "make depend").
24 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
25 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
28 # Compiler flag to set the C Standard level.
30 # gnu89 - c89 plus GCC extensions
31 # c99 - ISO C99 standard (not yet fully implemented)
32 # gnu99 - c99 plus GCC extensions
33 CSTANDARD
= -std
=gnu99
35 # Place -D or -U options here
38 # Place -I options here
42 CWARN
= -Wall
-Wstrict-prototypes
43 CTUNING
= -funsigned-char
-funsigned-bitfields \
44 -fpack-struct
-fshort-enums
-ffreestanding \
45 -ffunction-sections
-fdata-sections
47 CEXTRA
= -Wa
,-adhlns
=$(<:.c
=.lst
)
48 CFLAGS
= $(CDEBUG
) $(CDEFS
) $(CINCS
) -O
$(OPT
) $(CWARN
) $(CSTANDARD
) $(CEXTRA
)
50 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
52 #Additional libraries.
54 # Minimalistic printf version
55 PRINTF_LIB_MIN
= -Wl
,-u
,vfprintf
-lprintf_min
57 # Floating point printf version (requires MATH_LIB = -lm below)
58 PRINTF_LIB_FLOAT
= -Wl
,-u
,vfprintf
-lprintf_flt
62 # Minimalistic scanf version
63 SCANF_LIB_MIN
= -Wl
,-u
,vfscanf
-lscanf_min
65 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
66 SCANF_LIB_FLOAT
= -Wl
,-u
,vfscanf
-lscanf_flt
72 # External memory options
74 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
75 # used for variables (.data/.bss) and heap (malloc()).
76 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
78 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
79 # only used for heap (malloc()).
80 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
84 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
85 LDFLAGS
= $(EXTMEMOPTS
) $(LDMAP
) $(PRINTF_LIB
) $(SCANF_LIB
) $(MATH_LIB
)
88 # Programming support using avrdude. Settings and variables.
90 AVRDUDE_PROGRAMMER
= avrispmkII
93 AVRDUDE_WRITE_FLASH
= -U flash
:w
:$(TARGET
).hex
94 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
97 # Uncomment the following if you want avrdude's erase cycle counter.
98 # Note that this counter needs to be initialized first using -Yn,
100 #AVRDUDE_ERASE_COUNTER = -y
102 # Uncomment the following if you do /not/ wish a verification to be
103 # performed after programming the device.
104 #AVRDUDE_NO_VERIFY = -V
106 # Increase verbosity level. Please use this when submitting bug
107 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
108 # to submit bug reports.
109 #AVRDUDE_VERBOSE = -v -v
111 AVRDUDE_BASIC
= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
112 AVRDUDE_FLAGS
= $(AVRDUDE_BASIC
) $(AVRDUDE_NO_VERIFY
) $(AVRDUDE_VERBOSE
) $(AVRDUDE_ERASE_COUNTER
)
116 OBJCOPY
= avr-objcopy
117 OBJDUMP
= avr-objdump
124 # Define all object files.
125 OBJ
= $(SRC
:.c
=.o
) $(ASRC
:.S
=.o
)
127 # Define all listing files.
128 LST
= $(ASRC
:.S
=.lst
) $(SRC
:.c
=.lst
)
130 # Combine all necessary flags and optional flags.
131 # Add target processor to flags.
132 ALL_CFLAGS
= -mmcu
=$(MCU
) -I.
$(CFLAGS
) -DF_CPU
=$(F_CPU
) -Wl
,--relax
,--gc-sections
133 ALL_ASFLAGS
= -mmcu
=$(MCU
) -I.
-x assembler-with-cpp
$(ASFLAGS
) -DF_CPU
=$(F_CPU
)
147 # Program the device.
148 program
: $(TARGET
).hex
$(TARGET
).eep
149 $(AVRDUDE
) $(AVRDUDE_FLAGS
) $(AVRDUDE_WRITE_FLASH
) $(AVRDUDE_WRITE_EEPROM
)
151 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
152 COFFCONVERT
=$(OBJCOPY
) --debugging \
153 --change-section-address .data-0x800000 \
154 --change-section-address .bss-0x800000 \
155 --change-section-address .noinit-0x800000 \
156 --change-section-address .eeprom-0x810000
159 $(COFFCONVERT
) -O coff-avr
$(TARGET
).elf
$(TARGET
).cof
162 extcoff
: $(TARGET
).elf
163 $(COFFCONVERT
) -O coff-ext-avr
$(TARGET
).elf
$(TARGET
).cof
165 .SUFFIXES
: .elf .hex .eep .lss .sym
168 $(OBJCOPY
) -O
$(FORMAT
) -R .eeprom
$< $@
171 -$(OBJCOPY
) -j .eeprom
--set-section-flags
=.eeprom
="alloc,load" \
172 --change-section-lma .eeprom
=0 -O
$(FORMAT
) $< $@
174 # Create extended listing file from ELF output file.
176 $(OBJDUMP
) -h
-S
$< > $@
178 # Create a symbol table from ELF output file.
183 # Link: create ELF output file from object files.
184 $(TARGET
).elf
: $(OBJ
)
185 $(CC
) $(ALL_CFLAGS
) $(OBJ
) --output
$@
$(LDFLAGS
)
188 # Compile: create object files from C source files.
190 $(CC
) -c
$(ALL_CFLAGS
) $< -o
$@
192 # Compile: create assembler files from C source files.
194 $(CC
) -S
$(ALL_CFLAGS
) $< -o
$@
196 # Assemble: create object files from assembler source files.
198 $(CC
) -c
$(ALL_ASFLAGS
) $< -o
$@
200 # XXX: Determine free flash
204 # XXX: Flash consumption details
205 size-detail
: $(TARGET
).elf
206 tools
/space-detail.sh
$^
208 # Target: clean project.
210 $(REMOVE
) $(TARGET
).hex
$(TARGET
).eep
$(TARGET
).cof
$(TARGET
).elf \
211 $(TARGET
).map
$(TARGET
).sym
$(TARGET
).lss \
212 $(OBJ
) $(LST
) $(SRC
:.c
=.s
) $(SRC
:.c
=.d
)
215 if grep
'^# DO NOT DELETE' $(MAKEFILE
) >/dev
/null
; \
217 sed
-e
'/^# DO NOT DELETE/,$$d' $(MAKEFILE
) > \
218 $(MAKEFILE
).
$$$$ && \
219 $(MV
) $(MAKEFILE
).
$$$$ $(MAKEFILE
); \
221 echo
'# DO NOT DELETE THIS LINE -- make depend depends on it.' \
223 $(CC
) -M
-mmcu
=$(MCU
) $(CDEFS
) $(CINCS
) $(SRC
) $(ASRC
) >> $(MAKEFILE
)
225 .PHONY
: all build elf hex eep lss sym program coff extcoff
clean depend size size-detail