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
+= spi_io.c ..
/common
/queue.c
21 # Name of this Makefile (used for "make depend").
25 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
26 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
29 # Compiler flag to set the C Standard level.
31 # gnu89 - c89 plus GCC extensions
32 # c99 - ISO C99 standard (not yet fully implemented)
33 # gnu99 - c99 plus GCC extensions
34 CSTANDARD
= -std
=gnu99
36 # Place -D or -U options here
39 # Place -I options here
44 CWARN
= -Wall
-Wstrict-prototypes
-Wextra
-Wno-main
45 CWARN
+= -Wunknown-pragmas
-Wfloat-equal
-Wundef
-Wbad-function-cast
46 CWARN
+= -Wstrict-overflow
-Wmissing-format-attribute
47 CWARN
+= -Wunsafe-loop-optimizations
-Wstrict-prototypes
48 CWARN
+= -Wcast-qual
-Wcast-align
-Wwrite-strings
-Wconversion
50 CTUNING
= -funsigned-char
-funsigned-bitfields
-fshort-enums
51 CTUNING
+= -fmerge-all-constants
-funsafe-loop-optimizations
52 CTUNING
+= -fstrict-overflow
53 #CTUNING += -fpack-struct
55 #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
56 CFLAGS
= $(CDEBUG
) $(CDEFS
) $(CINCS
) -O
$(OPT
) $(CWARN
) $(CSTANDARD
) $(CEXTRA
) $(CLINK
) $(CTUNING
)
59 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
62 #Additional libraries.
64 # Minimalistic printf version
65 PRINTF_LIB_MIN
= -Wl
,-u
,vfprintf
-lprintf_min
67 # Floating point printf version (requires MATH_LIB = -lm below)
68 PRINTF_LIB_FLOAT
= -Wl
,-u
,vfprintf
-lprintf_flt
70 #PRINTF_LIB = $(PRINTF_LIB_MIN)
74 # Minimalistic scanf version
75 SCANF_LIB_MIN
= -Wl
,-u
,vfscanf
-lscanf_min
77 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
78 SCANF_LIB_FLOAT
= -Wl
,-u
,vfscanf
-lscanf_flt
81 #SCANF_LIB = $(SCANF_LIB_MIN)
86 # External memory options
88 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
89 # used for variables (.data/.bss) and heap (malloc()).
90 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
92 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
93 # only used for heap (malloc()).
94 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
98 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
99 LDFLAGS
= $(EXTMEMOPTS
) $(LDMAP
) $(PRINTF_LIB
) $(SCANF_LIB
) $(MATH_LIB
)
102 # Programming support using avrdude. Settings and variables.
104 AVRDUDE_PROGRAMMER
= usbtiny
105 #AVRDUDE_PORT = "-P /dev/ttyUSB0"
107 AVRDUDE_WRITE_FLASH
= -U flash
:w
:$(TARGET
).hex
108 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
111 # Uncomment the following if you want avrdude's erase cycle counter.
112 # Note that this counter needs to be initialized first using -Yn,
113 # see avrdude manual.
114 #AVRDUDE_ERASE_COUNTER = -y
116 # Uncomment the following if you do /not/ wish a verification to be
117 # performed after programming the device.
118 #AVRDUDE_NO_VERIFY = -V
120 # Increase verbosity level. Please use this when submitting bug
121 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
122 # to submit bug reports.
123 #AVRDUDE_VERBOSE = -v -v
125 AVRDUDE_BASIC
= -p
$(ADMCU
) $(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
126 AVRDUDE_FLAGS
= $(AVRDUDE_BASIC
) $(AVRDUDE_NO_VERIFY
) $(AVRDUDE_VERBOSE
) $(AVRDUDE_ERASE_COUNTER
)
127 AVRDUDE_POWER
= -t
-p
$(ADMCU
) -c
$(AVRDUDE_PROGRAMMER
)
130 OBJCOPY
= avr-objcopy
131 OBJDUMP
= avr-objdump
138 # Define all object files.
139 OBJ
= $(SRC
:.c
=.o
) $(ASRC
:.S
=.o
)
141 # Define all listing files.
142 LST
= $(ASRC
:.S
=.lst
) $(SRC
:.c
=.lst
)
144 # Combine all necessary flags and optional flags.
145 # Add target processor to flags.
146 ALL_CFLAGS
= -mmcu
=$(MCU
) -I.
$(CFLAGS
)
147 ALL_ASFLAGS
= -mmcu
=$(MCU
) -I.
-x assembler-with-cpp
$(ASFLAGS
)
148 ALL_CFLAGS
+= -DF_CPU
=$(F_CPU
)
149 ALL_ASFLAGS
+= -DF_CPU
=$(F_CPU
)
156 $(SIZE
) -C
--mcu
=$(MCU
) $(TARGET
).elf
168 # Program the device.
169 program
: $(TARGET
).hex
$(TARGET
).eep
170 $(AVRDUDE
) $(AVRDUDE_FLAGS
) $(AVRDUDE_WRITE_FLASH
) $(AVRDUDE_WRITE_EEPROM
)
174 $(AVRDUDE
) $(AVRDUDE_POWER
)
176 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
177 COFFCONVERT
=$(OBJCOPY
) --debugging \
178 --change-section-address .data-0x800000 \
179 --change-section-address .bss-0x800000 \
180 --change-section-address .noinit-0x800000 \
181 --change-section-address .eeprom-0x810000
185 $(COFFCONVERT
) -O coff-avr
$(TARGET
).elf
$(TARGET
).cof
188 extcoff
: $(TARGET
).elf
189 $(COFFCONVERT
) -O coff-ext-avr
$(TARGET
).elf
$(TARGET
).cof
192 .SUFFIXES
: .elf .hex .eep .lss .sym
195 $(OBJCOPY
) -O
$(FORMAT
) -R .eeprom
$< $@
198 -$(OBJCOPY
) -j .eeprom
--set-section-flags
=.eeprom
="alloc,load" \
199 --change-section-lma .eeprom
=0 -O
$(FORMAT
) $< $@
201 # Create extended listing file from ELF output file.
203 $(OBJDUMP
) -h
-S
$< > $@
205 # Create a symbol table from ELF output file.
211 # Link: create ELF output file from object files.
212 $(TARGET
).elf
: $(OBJ
)
213 $(CC
) $(ALL_CFLAGS
) $(OBJ
) --output
$@
$(LDFLAGS
)
214 #$(CC) $(ALL_CFLAGS) $(SRC) --combine -fwhole-program --output $@ $(LDFLAGS)
216 # Compile: create object files from C source files.
218 $(CC
) -c
$(ALL_CFLAGS
) $< -o
$@
221 # Compile: create assembler files from C source files.
223 $(CC
) -S
$(ALL_CFLAGS
) $< -o
$@
226 # Assemble: create object files from assembler source files.
228 $(CC
) -c
$(ALL_ASFLAGS
) $< -o
$@
232 # Target: clean project.
234 $(REMOVE
) $(TARGET
).hex
$(TARGET
).eep
$(TARGET
).cof
$(TARGET
).elf \
235 $(TARGET
).map
$(TARGET
).sym
$(TARGET
).lss \
236 $(OBJ
) $(LST
) $(SRC
:.c
=.s
) $(SRC
:.c
=.d
)
239 if grep
'^# DO NOT DELETE' $(MAKEFILE
) >/dev
/null
; \
241 sed
-e
'/^# DO NOT DELETE/,$$d' $(MAKEFILE
) > \
242 $(MAKEFILE
).
$$$$ && \
243 $(MV
) $(MAKEFILE
).
$$$$ $(MAKEFILE
); \
245 echo
'# DO NOT DELETE THIS LINE -- make depend depends on it.' \
247 $(CC
) -M
-mmcu
=$(MCU
) $(CDEFS
) $(CINCS
) $(SRC
) $(ASRC
) >> $(MAKEFILE
)
249 .PHONY
: all build elf hex eep lss sym program coff extcoff
clean depend
250 # DO NOT DELETE THIS LINE -- make depend depends on it.