]> git.defcon.no Git - avrfbosd/blob - Makefile
oops
[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 #AVRDUDE_PROGRAMMER = usbasp
12 AVRDUDE_PROGRAMMER = usbtiny
13 AVRDUDE_PORT = usb
14
15 # Target name and MCU setup -------------------------------------------------
16
17 TARGET = fbosd
18
19 MCU = atmega328p
20
21 # Processor frequency.
22 # This will define a symbol, F_CPU, in all source code files equal to the
23 # processor frequency. You can then use this symbol in your source code to
24 # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
25 # automatically to create a 32-bit value in your source code.
26 # Typical values are:
27 # F_CPU = 1000000
28 # F_CPU = 1843200
29 # F_CPU = 2000000
30 # F_CPU = 3686400
31 # F_CPU = 4000000
32 # F_CPU = 7372800
33 # F_CPU = 8000000
34 # F_CPU = 11059200
35 # F_CPU = 14745600
36 # F_CPU = 16000000
37 # F_CPU = 18432000
38 # F_CPU = 20000000
39
40 # Default settings:
41 #F_CPU = 1000000
42 # Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
43 #FUSE_LOW = 0x62
44 #FUSE_HIGH = 0xD9
45 #FUSE_EXT = 0x7
46
47 # Fancy 20MHz settings:
48 F_CPU = 20000000
49 ## Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
50 FUSE_LOW = 0xAF
51 FUSE_HIGH = 0xD9
52 FUSE_EXT = 0x7
53
54 # Source files to compile ---------------------------------------------------
55
56 # List C source files here. (C dependencies are automatically generated.)
57 SRC = $(TARGET).c render.c draw.c
58
59 # List Assembler source files here.
60 # Make them always end in a capital .S.
61 ASRC =
62
63 # Optimization level, can be [0, 1, 2, 3, s].
64 # 0 = turn off optimization. s = optimize for size.
65 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
66 OPT = 1
67
68 # Output formats and debug format -------------------------------------------
69
70 # Output format. (can be srec, ihex, binary)
71 FORMAT = ihex
72
73 # Debugging format.
74 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
75 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
76 DEBUG = dwarf-2
77
78 # Command names (and paths/parameters to them...) ---------------------------
79
80 CC = avr-gcc
81 OBJCOPY = avr-objcopy
82 OBJDUMP = avr-objdump
83 SIZE = avr-size
84 NM = avr-nm
85 AVRDUDE = avrdude
86 REMOVE = rm -f
87 MV = mv -f
88
89 # Compiler flag to set the C Standard level.
90 # c89 - "ANSI" C
91 # gnu89 - c89 plus GCC extensions
92 # c99 - ISO C99 standard (not yet fully implemented)
93 # gnu99 - c99 plus GCC extensions
94 CSTANDARD = -std=gnu99
95
96 # Place -D or -U options here
97 CDEFS = -DF_CPU=$(F_CPU)UL
98
99 # Place -I options here
100 CINCS =
101
102 CFLAGS = -g$(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CSTANDARD)
103 CFLAGS += -funsigned-char
104 CFLAGS += -funsigned-bitfields
105 CFLAGS += -fpack-struct
106 CFLAGS += -fshort-enums
107 CFLAGS += -Wall
108 CFLAGS += -Wstrict-prototypes
109 #CFLAGS += -mshort-calls
110 #CFLAGS += -fno-unit-at-a-time
111 #CFLAGS += -Wundef
112 #CFLAGS += -Wunreachable-code
113 #CFLAGS += -Wsign-compare
114
115 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
116
117
118 #Additional libraries.
119
120 MATH_LIB = -lm
121
122 # Minimalistic printf version
123 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
124
125 # Floating point printf version (requires MATH_LIB = -lm)
126 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
127
128 # If this is left blank, then it will use the Standard printf version.
129 PRINTF_LIB =
130 #PRINTF_LIB = $(PRINTF_LIB_MIN)
131 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
132
133
134 # Minimalistic scanf version
135 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
136
137 # Floating point + %[ scanf version (requires MATH_LIB = -lm)
138 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
139
140 # If this is left blank, then it will use the Standard scanf version.
141 SCANF_LIB =
142 #SCANF_LIB = $(SCANF_LIB_MIN)
143 #SCANF_LIB = $(SCANF_LIB_FLOAT)
144
145
146 # External memory options
147
148 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
149 # used for variables (.data/.bss) and heap (malloc()).
150 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
151
152 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
153 # only used for heap (malloc()).
154 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
155
156 EXTMEMOPTS =
157
158
159 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
160 LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
161
162
163 # Programming support using avrdude. Settings and variables.
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