Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

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