Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
282 grottenfli 1
# WinAVR Sample makefile written by Eric B. Weddington, Jörg Wunsch, et al.
2
# Released to the Public Domain
3
# Please read the make user manual!
4
#
5
# Additional material for this makefile was submitted by:
6
#  Tim Henigan
7
#  Peter Fleury
8
#  Reiner Patommel
9
#  Sander Pool
10
#  Frederik Rouleau
11
#  Markus Pfaff
12
#
13
# On command line:
14
#
15
# make all = Make software.
16
#
17
# make clean = Clean out built project files.
18
#
19
# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
20
#
21
# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
22
#                4.07 or greater).
23
#
24
# make program = Download the hex file to the device, using avrdude.  Please
25
#                customize the avrdude settings below first!
26
#
27
# make filename.s = Just compile filename.c into the assembler code only
28
#
29
# To rebuild project do "make clean" then "make all".
30
#
31
 
32
# MCU name
33
 
34
MCU = atmega8
35
#F_CPU = 1000000UL
36
 
37
#Fuse settings for ATmega644
38
ifeq ($(MCU), atmega644)
39
	FUSE_BITS = -u -U lfuse:w:0xff:m -U hfuse:w:0xdf:m
40
	HEX_FILE_NAME = MEGA8
41
endif
42
 
43
 
44
 
45
 
46
 
47
 
48
 
49
 
50
# Output format. (can be srec, ihex, binary)
51
FORMAT = ihex
52
 
53
# Target file name (without extension).
54
TARGET = Hexfiles/MikroBlink_$(HEX_FILE_NAME)
55
 
56
# Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
57
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
58
OPT = s
59
 
60
# If there is more than one source file, append them above, or modify and
61
# uncomment the following:
62
SRC =  main.c
63
 
64
 
65
 
66
# List Assembler source files here.
67
# Make them always end in a capital .S.  Files ending in a lowercase .s
68
# will not be considered source files but generated files (assembler
69
# output from the compiler), and will be deleted upon "make clean"!
70
# Even though the DOS/Win* filesystem matches both .s and .S the same,
71
# it will preserve the spelling of the filenames, and gcc itself does
72
# care about how the name is spelled on its command-line.
73
ASRC =
74
 
75
 
76
# List any extra directories to look for include files here.
77
#     Each directory must be seperated by a space.
78
EXTRAINCDIRS =
79
 
80
 
81
# Optional compiler flags.
82
#  -g:        generate debugging information (for GDB, or for COFF conversion)
83
#  -O*:       optimization level
84
#  -f...:     tuning, see gcc manual and avr-libc documentation
85
#  -Wall...:  warning level
86
#  -Wa,...:   tell GCC to pass this to the assembler.
87
#    -ahlms:  create assembler listing
88
CFLAGS = -g -O$(OPT) \
89
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
90
-Wall -Wstrict-prototypes \
91
-Wa,-adhlns=$(<:.c=.lst) \
92
$(patsubst %,-I%,$(EXTRAINCDIRS))
93
 
94
 
95
# Set a "language standard" compiler flag.
96
#   Unremark just one line below to set the language standard to use.
97
#   gnu99 = C99 + GNU extensions. See GCC manual for more information.
98
#CFLAGS += -std=c89
99
#CFLAGS += -std=gnu89
100
#CFLAGS += -std=c99
101
CFLAGS += -std=gnu99
102
 
103
 
104
 
105
# Optional assembler flags.
106
#  -Wa,...:   tell GCC to pass this to the assembler.
107
#  -ahlms:    create listing
108
#  -gstabs:   have the assembler create line number information; note that
109
#             for use in COFF files, additional information about filenames
110
#             and function names needs to be present in the assembler source
111
#             files -- see avr-libc docs [FIXME: not yet described there]
112
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
113
 
114
 
115
 
116
# Optional linker flags.
117
#  -Wl,...:   tell GCC to pass this to linker.
118
#  -Map:      create map file
119
#  --cref:    add cross reference to  map file
120
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
121
 
122
 
123
 
124
# Additional libraries
125
 
126
# Minimalistic printf version
127
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
128
 
129
# Floating point printf version (requires -lm below)
130
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
131
 
132
# -lm = math library
133
LDFLAGS += -lm
134
 
135
 
136
 
137
 
138
# Programming support using avrdude. Settings and variables.
139
 
140
# Programming hardware: alf avr910 avrisp bascom bsd
141
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
142
#
143
# Type: avrdude -c ?
144
# to get a full listing.
145
#
146
 
147
#AVRDUDE_PROGRAMMER = AVR910
148
#AVRDUDE_PROGRAMMER = stk300
149
#AVRDUDE_PROGRAMMER = USBasp
150
#AVRDUDE_PROGRAMMER = dt006
151
#AVRDUDE_PROGRAMMER = bascom
152
AVRDUDE_PROGRAMMER = siprog
153
#AVRDUDE_PROGRAMMER = avrisp2
154
#AVRDUDE_PROGRAMMER = AVRISPMKII
155
 
156
 
157
 
158
#AVRDUDE_PORT = usb        # programmer connected to USB port
159
AVRDUDE_PORT = com2	   # programmer connected to serial device
160
#AVRDUDE_PORT = lpt1	       # programmer connected to parallel port
161
 
162
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex $(FUSE_BITS)
163
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
164
 
165
#AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -b 115200 -c $(AVRDUDE_PROGRAMMER)
166
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
167
 
168
# Uncomment the following if you want avrdude's erase cycle counter.
169
# Note that this counter needs to be initialized first using -Yn,
170
# see avrdude manual.
171
#AVRDUDE_ERASE += -y
172
 
173
# Uncomment the following if you do /not/ wish a verification to be
174
# performed after programming the device.
175
#AVRDUDE_FLAGS += -V
176
 
177
# Increase verbosity level.  Please use this when submitting bug
178
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
179
# to submit bug reports.
180
#AVRDUDE_FLAGS += -v -v
181
 
182
 
183
 
184
 
185
# ---------------------------------------------------------------------------
186
 
187
# Define directories, if needed.
188
DIRAVR = c:/winavr
189
DIRAVRBIN = $(DIRAVR)/bin
190
DIRAVRUTILS = $(DIRAVR)/utils/bin
191
DIRINC = .
192
DIRLIB = $(DIRAVR)/avr/lib
193
 
194
 
195
# Define programs and commands.
196
SHELL = sh
197
 
198
CC = avr-gcc
199
 
200
OBJCOPY = avr-objcopy
201
OBJDUMP = avr-objdump
202
SIZE = avr-size
203
 
204
 
205
# Programming support using avrdude.
206
AVRDUDE = avrdude
207
 
208
 
209
REMOVE = rm -f
210
COPY = cp
211
 
212
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
213
ELFSIZE = $(SIZE) -A $(TARGET).elf
214
 
215
 
216
 
217
# Define Messages
218
# English
219
MSG_ERRORS_NONE = Errors: none
220
MSG_BEGIN = -------- begin --------
221
MSG_END = --------  end  --------
222
MSG_SIZE_BEFORE = Size before:
223
MSG_SIZE_AFTER = Size after:
224
MSG_COFF = Converting to AVR COFF:
225
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
226
MSG_FLASH = Creating load file for Flash:
227
MSG_EEPROM = Creating load file for EEPROM:
228
MSG_EXTENDED_LISTING = Creating Extended Listing:
229
MSG_SYMBOL_TABLE = Creating Symbol Table:
230
MSG_LINKING = Linking:
231
MSG_COMPILING = Compiling:
232
MSG_ASSEMBLING = Assembling:
233
MSG_CLEANING = Cleaning project:
234
 
235
 
236
 
237
 
238
# Define all object files.
239
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
240
 
241
# Define all listing files.
242
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
243
 
244
# Combine all necessary flags and optional flags.
245
# Add target processor to flags.
246
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
247
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
248
 
249
 
250
 
251
# Default target.
252
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
253
	$(TARGET).lss $(TARGET).sym sizeafter finished end
254
 
255
 
256
# Eye candy.
257
# AVR Studio 3.x does not check make's exit code but relies on
258
# the following magic strings to be generated by the compile job.
259
begin:
260
	@echo
261
	@echo $(MSG_BEGIN)
262
 
263
finished:
264
	@echo $(MSG_ERRORS_NONE)
265
 
266
end:
267
	@echo $(MSG_END)
268
	@echo
269
 
270
 
271
# Display size of file.
272
sizebefore:
273
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
274
 
275
sizeafter:
276
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
277
 
278
 
279
 
280
# Display compiler version information.
281
gccversion :
282
	@$(CC) --version
283
 
284
 
285
 
286
 
287
# Convert ELF to COFF for use in debugging / simulating in
288
# AVR Studio or VMLAB.
289
COFFCONVERT=$(OBJCOPY) --debugging \
290
	--change-section-address .data-0x800000 \
291
	--change-section-address .bss-0x800000 \
292
	--change-section-address .noinit-0x800000 \
293
	--change-section-address .eeprom-0x810000
294
 
295
 
296
coff: $(TARGET).elf
297
	@echo
298
	@echo $(MSG_COFF) $(TARGET).cof
299
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
300
 
301
 
302
extcoff: $(TARGET).elf
303
	@echo
304
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
305
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
306
 
307
 
308
 
309
 
310
# Program the device.
311
program: $(TARGET).hex $(TARGET).eep
312
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
313
 
314
 
315
 
316
 
317
# Create final output files (.hex, .eep) from ELF output file.
318
%.hex: %.elf
319
	@echo
320
	@echo $(MSG_FLASH) $@
321
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
322
 
323
%.eep: %.elf
324
	@echo
325
	@echo $(MSG_EEPROM) $@
326
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
327
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
328
 
329
# Create extended listing file from ELF output file.
330
%.lss: %.elf
331
	@echo
332
	@echo $(MSG_EXTENDED_LISTING) $@
333
	$(OBJDUMP) -h -S $< > $@
334
 
335
# Create a symbol table from ELF output file.
336
%.sym: %.elf
337
	@echo
338
	@echo $(MSG_SYMBOL_TABLE) $@
339
	avr-nm -n $< > $@
340
 
341
 
342
 
343
# Link: create ELF output file from object files.
344
.SECONDARY : $(TARGET).elf
345
.PRECIOUS : $(OBJ)
346
%.elf: $(OBJ)
347
	@echo
348
	@echo $(MSG_LINKING) $@
349
	$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
350
 
351
 
352
# Compile: create object files from C source files.
353
%.o : %.c
354
	@echo
355
	@echo $(MSG_COMPILING) $<
356
	$(CC) -c $(ALL_CFLAGS) $< -o $@
357
 
358
 
359
# Compile: create assembler files from C source files.
360
%.s : %.c
361
	$(CC) -S $(ALL_CFLAGS) $< -o $@
362
 
363
 
364
# Assemble: create object files from assembler source files.
365
%.o : %.S
366
	@echo
367
	@echo $(MSG_ASSEMBLING) $<
368
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
369
 
370
 
371
 
372
 
373
 
374
 
375
# Target: clean project.
376
clean: begin clean_list finished end
377
 
378
clean_list :
379
	@echo
380
	@echo $(MSG_CLEANING)
381
#	$(REMOVE) $(TARGET).hex
382
	$(REMOVE) $(TARGET).eep
383
	$(REMOVE) $(TARGET).obj
384
	$(REMOVE) $(TARGET).cof
385
	$(REMOVE) $(TARGET).elf
386
	$(REMOVE) $(TARGET).map
387
	$(REMOVE) $(TARGET).obj
388
	$(REMOVE) $(TARGET).a90
389
	$(REMOVE) $(TARGET).sym
390
	$(REMOVE) $(TARGET).lnk
391
	$(REMOVE) $(TARGET).lss
392
	$(REMOVE) $(OBJ)
393
	$(REMOVE) $(LST)
394
	$(REMOVE) $(SRC:.c=.s)
395
	$(REMOVE) $(SRC:.c=.d)
396
 
397
 
398
# Automatically generate C source code dependencies.
399
# (Code originally taken from the GNU make user manual and modified
400
# (See README.txt Credits).)
401
#
402
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
403
# (see the SHELL variable defined above).
404
# This may not work with other shells or other seds.
405
#
406
%.d: %.c
407
	set -e; $(CC) -MM $(ALL_CFLAGS) $< \
408
	| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
409
	[ -s $@ ] || rm -f $@
410
 
411
 
412
# Remove the '-' if you want to see the dependency files generated.
413
-include $(SRC:.c=.d)
414
 
415
 
416
 
417
# Listing of phony targets.
418
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
419
	clean clean_list program
420