]> git.defcon.no Git - avrfbosd/blob - Makefile
Changed syncgen to allow disabling of background image. By defining DRAW_LOGO the...
[avrfbosd] / Makefile
1 # Hey Emacs, this is a -*- makefile -*-
2
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)
6 #
7 # Adaptations by Jon Langseth <jon.langseth AT lilug.no>
8 # This modified template is placed in the public domain like the original.
9 #
10
11
12 # Target name and MCU setup -------------------------------------------------
13
14 TARGET = fbosd
15
16 MCU = atmega328p
17
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.
23 # Typical values are:
24 # F_CPU = 1000000
25 # F_CPU = 1843200
26 # F_CPU = 2000000
27 # F_CPU = 3686400
28 # F_CPU = 4000000
29 # F_CPU = 7372800
30 # F_CPU = 8000000
31 # F_CPU = 11059200
32 # F_CPU = 14745600
33 # F_CPU = 16000000
34 # F_CPU = 18432000
35 # F_CPU = 20000000
36
37 # Default settings:
38 #F_CPU = 1000000
39 # Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
40 #FUSE_LOW = 0x62
41 #FUSE_HIGH = 0xD9
42 #FUSE_EXT = 0x7
43
44 # Fancy 20MHz settings:
45 F_CPU = 20000000
46 ## Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
47 FUSE_LOW = 0xAF
48 FUSE_HIGH = 0xD9
49 FUSE_EXT = 0x7
50
51 # Source files to compile ---------------------------------------------------
52
53 # List C source files here. (C dependencies are automatically generated.)
54 SRC = $(TARGET).c render.c draw.c
55
56 # List Assembler source files here.
57 # Make them always end in a capital .S.
58 ASRC =
59
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.)
63 OPT = 1
64
65 # Output formats and debug format -------------------------------------------
66
67 # Output format. (can be srec, ihex, binary)
68 FORMAT = ihex
69
70 # Debugging format.
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.
73 DEBUG = dwarf-2
74
75 # Command names (and paths/parameters to them...) ---------------------------
76
77 CC = avr-gcc
78 OBJCOPY = avr-objcopy
79 OBJDUMP = avr-objdump
80 SIZE = avr-size
81 NM = avr-nm
82 AVRDUDE = avrdude
83 REMOVE = rm -f
84 MV = mv -f
85
86 # Compiler flag to set the C Standard level.
87 # c89 - "ANSI" C
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
92
93 # Place -D or -U options here
94 CDEFS = -DF_CPU=$(F_CPU)UL
95
96 # Place -I options here
97 CINCS =
98
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
104 CFLAGS += -Wall
105 CFLAGS += -Wstrict-prototypes
106 #CFLAGS += -mshort-calls
107 #CFLAGS += -fno-unit-at-a-time
108 #CFLAGS += -Wundef
109 #CFLAGS += -Wunreachable-code
110 #CFLAGS += -Wsign-compare
111
112 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
113
114
115 #Additional libraries.
116
117 MATH_LIB = -lm
118
119 # Minimalistic printf version
120 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
121
122 # Floating point printf version (requires MATH_LIB = -lm)
123 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
124
125 # If this is left blank, then it will use the Standard printf version.
126 PRINTF_LIB =
127 #PRINTF_LIB = $(PRINTF_LIB_MIN)
128 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
129
130
131 # Minimalistic scanf version
132 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
133
134 # Floating point + %[ scanf version (requires MATH_LIB = -lm)
135 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
136
137 # If this is left blank, then it will use the Standard scanf version.
138 SCANF_LIB =
139 #SCANF_LIB = $(SCANF_LIB_MIN)
140 #SCANF_LIB = $(SCANF_LIB_FLOAT)
141
142
143 # External memory options
144
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
148
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
152
153 EXTMEMOPTS =
154
155
156 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
157 LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
158
159
160 # Programming support using avrdude. Settings and variables.
161
162 AVRDUDE_PROGRAMMER = usbtiny
163 AVRDUDE_PORT = usb
164
165 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
166 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
167
168
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
173
174 # Uncomment the following if you do /not/ wish a verification to be
175 # performed after programming the device.
176 #AVRDUDE_NO_VERIFY = -V
177
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
182
183 AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
184 AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) $(AVRDUDE_ERASE_COUNTER)
185
186
187 # Define all object files.
188 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
189
190 # Define all listing files.
191 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
192
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)
197
198
199 # Default target.
200 all: build
201
202 build: elf hex eep size
203
204 elf: $(TARGET).elf
205 hex: $(TARGET).hex
206 eep: $(TARGET).eep
207 lss: $(TARGET).lss
208 sym: $(TARGET).sym
209
210 # Display size of file.
211 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
212 ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
213
214 size:
215 @echo
216 $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
217 $(SIZE) --target=$(FORMAT) $(TARGET).hex
218
219 # Program the device.
220 program: $(TARGET).hex $(TARGET).eep
221 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
222
223
224 # make fuseread can be used to test programmer connectivity, and naturally to verify fuses..
225 fuseread:
226 $(AVRDUDE) $(AVRDUDE_BASIC) -q -U lfuse:r:-:h -U hfuse:r:-:h -U efuse:r:-:h
227
228 FUSES =
229 ifdef FUSE_EXT
230 FUSES += -U efuse:w:$(FUSE_EXT):m
231 endif
232 FUSES += -U hfuse:w:$(FUSE_HIGH):m
233 FUSES += -U lfuse:w:$(FUSE_LOW):m
234
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
243
244
245 coff: $(TARGET).elf
246 $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
247
248
249 extcoff: $(TARGET).elf
250 $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
251
252
253 .SUFFIXES: .elf .hex .eep .lss .sym
254
255 .elf.hex:
256 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
257
258 .elf.eep:
259 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
260 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
261
262 # Create extended listing file from ELF output file.
263 .elf.lss:
264 $(OBJDUMP) -h -S $< > $@
265
266 # Create a symbol table from ELF output file.
267 .elf.sym:
268 $(NM) -n $< > $@
269
270
271
272 # Link: create ELF output file from object files.
273 $(TARGET).elf: $(OBJ)
274 $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
275
276
277 # Compile: create object files from C source files.
278 .c.o:
279 $(CC) -c $(ALL_CFLAGS) $< -o $@
280
281
282 # Compile: create assembler files from C source files.
283 .c.s:
284 $(CC) -S $(ALL_CFLAGS) $< -o $@
285
286
287 # Assemble: create object files from assembler source files.
288 .S.o:
289 $(CC) -c $(ALL_ASFLAGS) $< -o $@
290
291
292
293 # Target: clean project.
294 clean:
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)
298
299 # Name of this Makefile (used for "make depend").
300 MAKEFILE = Makefile
301
302 depend:
303 if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
304 then \
305 sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
306 $(MAKEFILE).$$$$ && \
307 $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
308 fi
309 echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
310 >> $(MAKEFILE); \
311 $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
312
313 .PHONY: all build elf hex eep lss sym program coff extcoff clean depend
314