]> git.defcon.no Git - avrfbosd/blob - syncgen/Makefile
e68a3273029bbf66fde59c11d3364cbdab2b0a39
[avrfbosd] / syncgen / 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 = syncgen
15
16 MCU = attiny85
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 F_CPU = 20000000
37
38 # Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
39 FUSE_LOW = 0xCF
40 FUSE_HIGH = 0xDF
41 FUSE_EXT = 0xFF
42 # Have had problems with efuse suggested by fusecalc, must check :P
43
44 # Source files to compile ---------------------------------------------------
45
46 # List C source files here. (C dependencies are automatically generated.)
47 SRC = main.c
48
49 # List Assembler source files here.
50 # Make them always end in a capital .S.
51 ASRC =
52
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.)
56 OPT = 1
57
58 # Output formats and debug format -------------------------------------------
59
60 # Output format. (can be srec, ihex, binary)
61 FORMAT = ihex
62
63 # Debugging format.
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.
66 DEBUG = dwarf-2
67
68 # Command names (and paths/parameters to them...) ---------------------------
69
70 CC = avr-gcc
71 OBJCOPY = avr-objcopy
72 OBJDUMP = avr-objdump
73 SIZE = avr-size
74 NM = avr-nm
75 AVRDUDE = avrdude
76 REMOVE = rm -f
77 MV = mv -f
78
79 # Compiler flag to set the C Standard level.
80 # c89 - "ANSI" C
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
85
86 # Place -D or -U options here
87 CDEFS = -DF_CPU=$(F_CPU)UL
88
89 # Place -I options here
90 CINCS =
91
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
97 CFLAGS += -Wall
98 CFLAGS += -Wstrict-prototypes
99 #CFLAGS += -mshort-calls
100 #CFLAGS += -fno-unit-at-a-time
101 #CFLAGS += -Wundef
102 #CFLAGS += -Wunreachable-code
103 #CFLAGS += -Wsign-compare
104
105 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
106
107
108 #Additional libraries.
109
110 MATH_LIB = -lm
111
112 # Minimalistic printf version
113 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
114
115 # Floating point printf version (requires MATH_LIB = -lm)
116 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
117
118 # If this is left blank, then it will use the Standard printf version.
119 PRINTF_LIB =
120 #PRINTF_LIB = $(PRINTF_LIB_MIN)
121 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
122
123
124 # Minimalistic scanf version
125 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
126
127 # Floating point + %[ scanf version (requires MATH_LIB = -lm)
128 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
129
130 # If this is left blank, then it will use the Standard scanf version.
131 SCANF_LIB =
132 #SCANF_LIB = $(SCANF_LIB_MIN)
133 #SCANF_LIB = $(SCANF_LIB_FLOAT)
134
135
136 # External memory options
137
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
141
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
145
146 EXTMEMOPTS =
147
148
149 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
150 LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
151
152
153 # Programming support using avrdude. Settings and variables.
154
155 AVRDUDE_PROGRAMMER = usbtiny
156 AVRDUDE_PORT = usb
157
158 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
159 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
160
161
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
166
167 # Uncomment the following if you do /not/ wish a verification to be
168 # performed after programming the device.
169 #AVRDUDE_NO_VERIFY = -V
170
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
175
176 AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
177 AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) $(AVRDUDE_ERASE_COUNTER)
178
179
180 # Define all object files.
181 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
182
183 # Define all listing files.
184 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
185
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)
190
191
192 # Default target.
193 all: build
194
195 build: elf hex eep size
196
197 elf: $(TARGET).elf
198 hex: $(TARGET).hex
199 eep: $(TARGET).eep
200 lss: $(TARGET).lss
201 sym: $(TARGET).sym
202
203 # Display size of file.
204 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
205 ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
206
207 size:
208 @echo
209 $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
210 $(SIZE) --target=$(FORMAT) $(TARGET).hex
211
212 # Program the device.
213 program: $(TARGET).hex $(TARGET).eep
214 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
215
216
217 # make fuseread can be used to test programmer connectivity, and naturally to verify fuses..
218 fuseread:
219 $(AVRDUDE) $(AVRDUDE_BASIC) -q -U lfuse:r:-:h -U hfuse:r:-:h -U efuse:r:-:h
220
221 FUSES =
222 ifdef FUSE_EXT
223 FUSES += -U efuse:w:$(FUSE_EXT):m
224 endif
225 FUSES += -U hfuse:w:$(FUSE_HIGH):m
226 FUSES += -U lfuse:w:$(FUSE_LOW):m
227
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
236
237
238 coff: $(TARGET).elf
239 $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
240
241
242 extcoff: $(TARGET).elf
243 $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
244
245
246 .SUFFIXES: .elf .hex .eep .lss .sym
247
248 .elf.hex:
249 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
250
251 .elf.eep:
252 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
253 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
254
255 # Create extended listing file from ELF output file.
256 .elf.lss:
257 $(OBJDUMP) -h -S $< > $@
258
259 # Create a symbol table from ELF output file.
260 .elf.sym:
261 $(NM) -n $< > $@
262
263
264
265 # Link: create ELF output file from object files.
266 $(TARGET).elf: $(OBJ)
267 $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
268
269
270 # Compile: create object files from C source files.
271 .c.o:
272 $(CC) -c $(ALL_CFLAGS) $< -o $@
273
274
275 # Compile: create assembler files from C source files.
276 .c.s:
277 $(CC) -S $(ALL_CFLAGS) $< -o $@
278
279
280 # Assemble: create object files from assembler source files.
281 .S.o:
282 $(CC) -c $(ALL_ASFLAGS) $< -o $@
283
284
285
286 # Target: clean project.
287 clean:
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)
291
292 # Name of this Makefile (used for "make depend").
293 MAKEFILE = Makefile
294
295 depend:
296 if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
297 then \
298 sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
299 $(MAKEFILE).$$$$ && \
300 $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
301 fi
302 echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
303 >> $(MAKEFILE); \
304 $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
305
306 .PHONY: all build elf hex eep lss sym program coff extcoff clean depend
307