Statistics
| Branch: | Revision:

root / Makefile @ master

History | View | Annotate | Download (8.21 KB)

1 b3338b32 imp
# Hey Emacs, this is a -*- makefile -*-
2
#
3
# WinAVR makefile written by Eric B. Weddington, J�rg Wunsch, et al.
4
# Released to the Public Domain
5
# Please read the make user manual!
6
#
7
# Additional material for this makefile was submitted by:
8
#  Tim Henigan
9
#  Peter Fleury
10
#  Reiner Patommel
11
#  Sander Pool
12
#  Frederik Rouleau
13
#  Markus Pfaff
14
#
15
# abused by
16
# psycorama
17
#
18
# On command line:
19
#
20
# make all = Make software.
21
#
22
# make clean = Clean out built project files.
23
#
24
25
# MCU name
26
MCU = atmega168
27
28
# Main Oscillator Frequency
29
# This is only used to define F_OSC in all assembler and c-sources.
30
F_OSC = 16000000
31
32
# Output format. (can be srec, ihex, binary)
33
FORMAT = ihex
34
35
# Target file name (without extension).
36
TARGET = main
37
38
# List C source files here. (C dependencies are automatically generated.)
39
SRC = $(TARGET).c
40
41
42
# Optimization level, can be [0, 1, 2, 3, s]. 
43
# 0 = turn off optimization. s = optimize for size.
44
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
45 08a88852 imp
OPT = s
46 b3338b32 imp
47
# Compiler flag to set the C Standard level.
48
# c89   - "ANSI" C
49
# gnu89 - c89 plus GCC extensions
50
# c99   - ISO C99 standard (not yet fully implemented)
51
# gnu99 - c99 plus GCC extensions
52
CSTANDARD = -std=gnu99
53
54
# Compiler flags.
55
#  -g*:          generate debugging information
56
#  -O*:          optimization level
57
#  -f...:        tuning, see GCC manual and avr-libc documentation
58
#  -Wall...:     warning level
59
#  -Wa,...:      tell GCC to pass this to the assembler.
60
#    -adhlns...: create assembler listing
61
CFLAGS += -O$(OPT)
62
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
63
CFLAGS += -Wall -Wstrict-prototypes
64
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
65
CFLAGS += $(CSTANDARD)
66
CFLAGS += -DF_OSC=$(F_OSC)
67
68
69
# Assembler flags.
70
#  -Wa,...:   tell GCC to pass this to the assembler.
71
#  -ahlms:    create listing
72
#  -gstabs:   have the assembler create line number information; note that
73
#             for use in COFF files, additional information about filenames
74
#             and function names needs to be present in the assembler source
75
#             files -- see avr-libc docs [FIXME: not yet described there]
76
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
77
ASFLAGS += -DF_OSC=$(F_OSC)
78
79
80
#Additional libraries.
81
82
# Minimalistic printf version
83
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
84
85
# Floating point printf version (requires MATH_LIB = -lm below)
86
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
87
88
PRINTF_LIB = 
89
90
# Minimalistic scanf version
91
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
92
93
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
94
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
95
96
MATH_LIB = -lm
97
98
# Linker flags.
99
#  -Wl,...:     tell GCC to pass this to linker.
100
#    -Map:      create map file
101
#    --cref:    add cross reference to  map file
102
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
103
LDFLAGS += $(EXTMEMOPTS)
104
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
105
106
# Programming support using avrdude. Settings and variables.
107
108
# Programming hardware: alf avr910 avrisp bascom bsd 
109
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
110
#
111
# Type: avrdude -c ?
112
# to get a full listing.
113
#
114
AVRDUDE_PROGRAMMER = usbasp
115
116
# com1 = serial port. Use lpt1 to connect to parallel port.
117
AVRDUDE_PORT = usb    # programmer connected to serial device
118
119
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
120
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
121
122
123
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -V
124
125
# ---------------------------------------------------------------------------
126
127
# Define programs and commands.
128
SHELL = sh
129
CC = avr-gcc
130
OBJCOPY = avr-objcopy
131
OBJDUMP = avr-objdump
132
SIZE = avr-size
133
NM = avr-nm
134
AVRDUDE = avrdude
135
REMOVE = rm -f
136
COPY = cp
137
138
139
140
141
# Define Messages
142
# English
143
MSG_ERRORS_NONE = Errors: none
144
MSG_BEGIN = -------- begin --------
145
MSG_END = --------  end  --------
146
MSG_SIZE_BEFORE = Size before: 
147
MSG_SIZE_AFTER = Size after:
148
MSG_COFF = Converting to AVR COFF:
149
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
150
MSG_FLASH = Creating load file for Flash:
151
MSG_EEPROM = Creating load file for EEPROM:
152
MSG_EXTENDED_LISTING = Creating Extended Listing:
153
MSG_SYMBOL_TABLE = Creating Symbol Table:
154
MSG_LINKING = Linking:
155
MSG_COMPILING = Compiling:
156
MSG_ASSEMBLING = Assembling:
157
MSG_CLEANING = Cleaning project:
158
159
160
161
162
# Define all object files.
163
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
164
165
# Define all listing files.
166
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
167
168
169
# Compiler flags to generate dependency files.
170
### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
171
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
172
173
# Combine all necessary flags and optional flags.
174
# Add target processor to flags.
175
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
176
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
177
178
# Default target.
179
all: begin gccversion sizebefore build sizeafter finished end
180
181
build: elf hex eep
182
183
#lss sym
184
185
elf: $(TARGET).elf
186
hex: $(TARGET).hex
187
eep: $(TARGET).eep
188
lss: $(TARGET).lss
189
sym: $(TARGET).sym
190
191
192
# Eye candy.
193
# AVR Studio 3.x does not check make's exit code but relies on
194
# the following magic strings to be generated by the compile job.
195
begin:
196
	@echo
197
	@echo $(MSG_BEGIN)
198
199
finished:
200
	@echo $(MSG_ERRORS_NONE)
201
202
end:
203
	@echo $(MSG_END)
204
	@echo
205
206
207
# Display size of file.
208
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
209
ELFSIZE = $(SIZE) -A $(TARGET).elf
210
sizebefore:
211
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
212
213
sizeafter:
214
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
215
216
217
218
# Display compiler version information.
219
gccversion : 
220
	@$(CC) --version
221
222
223
224
# Program the device.  
225
program: $(TARGET).hex $(TARGET).eep
226
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
227
228
erase: 
229
	$(AVRDUDE) -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -e
230
231
232
233
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
234
COFFCONVERT=$(OBJCOPY) --debugging \
235
--change-section-address .data-0x800000 \
236
--change-section-address .bss-0x800000 \
237
--change-section-address .noinit-0x800000 \
238
--change-section-address .eeprom-0x810000 
239
240
241
coff: $(TARGET).elf
242
	@echo
243
	@echo $(MSG_COFF) $(TARGET).cof
244
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
245
246
247
extcoff: $(TARGET).elf
248
	@echo
249
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
250
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
251
252
253
254
# Create final output files (.hex, .eep) from ELF output file.
255
%.bin: %.elf
256
	@echo
257
	@echo $(MSG_FLASH) $@
258
	$(OBJCOPY) -O binary -R .eeprom $< $@
259
260
%.hex: %.elf
261
	@echo
262
	@echo $(MSG_FLASH) $@
263
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
264
265
%.eep: %.elf
266
	@echo
267
	@echo $(MSG_EEPROM) $@
268
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
269
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
270
271
# Create extended listing file from ELF output file.
272
%.lss: %.elf
273
	@echo
274
	@echo $(MSG_EXTENDED_LISTING) $@
275
	$(OBJDUMP) -h -S $< > $@
276
277
# Create a symbol table from ELF output file.
278
%.sym: %.elf
279
	@echo
280
	@echo $(MSG_SYMBOL_TABLE) $@
281
	$(NM) -n $< > $@
282
283
284
285
# Link: create ELF output file from object files.
286
.SECONDARY : $(TARGET).elf
287
.PRECIOUS : $(OBJ)
288
%.elf: $(OBJ)
289
	@echo
290
	@echo $(MSG_LINKING) $@
291
	$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
292
293
294
# Compile: create object files from C source files.
295
%.o : %.c
296
	@echo
297
	@echo $(MSG_COMPILING) $<
298
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
299
300
301
# Compile: create assembler files from C source files.
302
%.s : %.c
303
	$(CC) -S $(ALL_CFLAGS) $< -o $@
304
305
306
# Assemble: create object files from assembler source files.
307
%.o : %.S
308
	@echo
309
	@echo $(MSG_ASSEMBLING) $<
310
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
311
312
313
314
# Target: clean project.
315
clean: begin clean_list finished end
316
317
clean_list :
318
	@echo
319
	@echo $(MSG_CLEANING)
320
	$(REMOVE) $(TARGET).bin
321
	$(REMOVE) $(TARGET).hex
322
	$(REMOVE) $(TARGET).eep
323
	$(REMOVE) $(TARGET).obj
324
	$(REMOVE) $(TARGET).cof
325
	$(REMOVE) $(TARGET).elf
326
	$(REMOVE) $(TARGET).map
327
	$(REMOVE) $(TARGET).obj
328
	$(REMOVE) $(TARGET).a90
329
	$(REMOVE) $(TARGET).sym
330
	$(REMOVE) $(TARGET).lnk
331
	$(REMOVE) $(TARGET).lss
332
	$(REMOVE) $(OBJ)
333
	$(REMOVE) $(LST)
334
	$(REMOVE) $(SRC:.c=.s)
335
	$(REMOVE) $(SRC:.c=.d)
336
	$(REMOVE) .dep/* 
337
	rmdir .dep
338
339
340
341
# Include the dependency files.
342
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
343
344
345
# Listing of phony targets.
346
.PHONY : all begin finish end sizebefore sizeafter gccversion \
347
build elf hex eep lss sym coff extcoff \
348
clean clean_list program
349
350
flash:
351
	avrdude -c usbasp -p m168 -U flash:w:main.hex:i
352
353
354
read:
355
	avrdude -c usbasp -p m168 -v