Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
151 kaklik 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
# Retrofitted for the AVRcam project by John Orlando  6/30/2004
6
#
7
#
8
# On command line:
9
#
10
# make all = Make software.
11
#
12
# make clean = Clean out built project files.
13
#
14
# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
15
#
16
# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
17
#                4.07 or greater).
18
#
19
# make program = Download the hex file to the device, using avrdude.  Please
20
#                customize the avrdude settings below first!
21
#
22
# make filename.s = Just compile filename.c into the assembler code only
23
#
24
# To rebuild project do "make clean" then "make all".
25
#
26
#    Revision History:
27
#    Date        Rel Ver.    Notes
28
#    4/10/2004      0.1     Module created
29
#    6/30/2004      1.0     Initial release for Circuit Cellar
30
#                           contest.
31
#    1/15/2005      1.4     Removed the UartInterfaceAsm file from 
32
#                           file list, since the routine in that
33
#                           file was added to UartInterface.c.
34
 
35
 
36
# MCU name
37
MCU = atmega8
38
 
39
# Output format. (can be srec, ihex, binary)
40
FORMAT = ihex
41
 
42
# Target file name (without extension).
43
TARGET = AVRcam
44
 
45
# Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
46
# (Note 3 is not always the best optimization level. See avr-libc FAQ.)
47
OPT = 1
48
 
49
 
50
# List C source files here. (C dependencies are automatically generated.)
51
#SRC = $(TARGET).c
52
 
53
# If there is more than one source file, append them above, or adjust and
54
# uncomment the following:
55
# NOTE: The order of the files here is important...CamInterface.c MUST be
56
# the first file, due to the declaration of an array that needs to be 
57
# located at the very beginning of the .noinit section in on-board RAM.
58
SRC = CamInterface.c Main.c Executive.c FrameMgr.c UIMgr.c UartInterface.c I2CInterface.c CamConfig.c Utility.c DebugInterface.c
59
 
60
 
61
# List Assembler source files here.
62
# Make them always end in a capital .S.  Files ending in a lowercase .s
63
# will not be considered source files but generated files (assembler
64
# output from the compiler), and will be deleted upon "make clean"!
65
# Even though the DOS/Win* filesystem matches both .s and .S the same,
66
# it will preserve the spelling of the filenames, and gcc itself does
67
# care about how the name is spelled on its command-line.
68
ASRC = CamInterfaceAsm.S
69
 
70
 
71
 
72
# Optional compiler flags.
73
#  -g:        generate debugging information (for GDB, or for COFF conversion)
74
#  -O*:       optimization level
75
#  -f...:     tuning, see gcc manual and avr-libc documentation
76
#  -Wall...:  warning level
77
#  -Wa,...:   tell GCC to pass this to the assembler.
78
#    -ahlms:  create assembler listing
79
CFLAGS = -g -O$(OPT) \
80
	-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
81
	-Wall -Wstrict-prototypes \
82
	-Wa,-ahlms=$(<:.c=.lst) 
83
 
84
 
85
 
86
# Optional assembler flags.
87
#  -Wa,...:   tell GCC to pass this to the assembler.
88
#  -ahlms:    create listing
89
#  -gstabs:   have the assembler create line number information; note that
90
#             for use in COFF files, additional information about filenames
91
#             and function names needs to be present in the assembler source
92
#             files -- see avr-libc docs [FIXME: not yet described there]
93
ASFLAGS = -Wa,-ahlms=$(<:.S=.lst),-gstabs
94
 
95
 
96
 
97
# Optional linker flags.
98
#  -Wl,...:   tell GCC to pass this to linker.
99
#  -Map:      create map file
100
#  --cref:    add cross reference to  map file
101
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref,--section-start=.noinit=0x800300
102
#LDFLAGS = -Wl,-Map=$(TARGET).map,--cref,--section-start=.john=0x800200
103
 
104
 
105
 
106
# Additional libraries
107
#
108
# Minimalistic printf version
109
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
110
#
111
# Floating point printf version (requires -lm below)
112
#LDFLAGS +=  -Wl,-u,vfprintf -lprintf_flt
113
#
114
# -lm = math library
115
LDFLAGS += -lm
116
 
117
 
118
 
119
 
120
# Programming support using avrdude. Settings and variables.
121
 
122
# Programming hardware: avrisp stk500 avr910 pavr stk200 pony-stk200
123
#                       dt006 bascom alf
124
# Type: avrdude -c ?
125
# to get a full listing.
126
#
127
AVRDUDE_PROGRAMMER = dapa
128
 
129
 
130
#AVRDUDE_PORT = com1	   	# programmer connected to serial device
131
AVRDUDE_PORT = /dev/parport0			# programmer connected to parallel port
132
 
133
AVRDUDE_ERASE = -e
134
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
135
 
136
 
137
# Uncomment the following if you want avrdude's erase cycle counter.
138
# Note that this counter needs to be initialized first using -Yn,
139
# see avrdude manual.
140
#AVRDUDE_ERASE += -y
141
#
142
# Uncomment the following if you do /not/ wish a verification to be
143
# performed after programming the device.
144
#AVRDUDE_FLAGS += -V
145
#
146
# Increase verbosity level.  Please use this when submitting bug
147
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
148
# to submit bug reports.
149
#AVRDUDE_FLAGS += -v -v
150
 
151
 
152
 
153
 
154
# ---------------------------------------------------------------------------
155
 
156
# Define directories, if needed.
157
DIRAVR = c:/winavr
158
DIRAVRBIN = $(DIRAVR)/bin
159
DIRAVRUTILS = $(DIRAVR)/utils/bin
160
DIRINC = .
161
DIRLIB = $(DIRAVR)/avr/lib
162
 
163
 
164
# Define programs and commands.
165
SHELL = sh
166
 
167
CC = avr-gcc
168
 
169
OBJCOPY = avr-objcopy
170
OBJDUMP = avr-objdump
171
SIZE = avr-size
172
 
173
 
174
# Programming support using avrdude.
175
AVRDUDE = avrdude
176
 
177
 
178
REMOVE = rm -f
179
COPY = cp
180
 
181
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
182
ELFSIZE = $(SIZE) -A $(TARGET).elf
183
 
184
FINISH = echo Errors: none
185
BEGIN = echo -------- begin --------
186
END = echo --------  end  --------
187
 
188
 
189
 
190
 
191
# Define all object files.
192
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
193
 
194
# Define all listing files.
195
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
196
 
197
# Combine all necessary flags and optional flags.
198
# Add target processor to flags.
199
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
200
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
201
 
202
 
203
 
204
# Default target.
205
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
206
	$(TARGET).lss coff sizeafter finished end
207
 
208
 
209
# Eye candy.
210
# AVR Studio 3.x does not check make's exit code but relies on
211
# the following magic strings to be generated by the compile job.
212
begin:
213
	@$(BEGIN)
214
 
215
finished:
216
	@$(FINISH)
217
 
218
end:
219
	@$(END)
220
 
221
 
222
# Display size of file.
223
sizebefore:
224
	@if [ -f $(TARGET).elf ]; then echo Size before:; $(ELFSIZE);fi
225
 
226
sizeafter:
227
	@if [ -f $(TARGET).elf ]; then echo Size after:; $(ELFSIZE);fi
228
 
229
 
230
 
231
# Display compiler version information.
232
gccversion :
233
	$(CC) --version
234
 
235
 
236
 
237
 
238
# Convert ELF to COFF for use in debugging / simulating in
239
# AVR Studio or VMLAB.
240
COFFCONVERT=$(OBJCOPY) --debugging \
241
	--change-section-address .data-0x800000 \
242
	--change-section-address .bss-0x800000 \
243
	--change-section-address .noinit-0x800000 \
244
	--change-section-address .eeprom-0x810000
245
 
246
 
247
coff: $(TARGET).elf
248
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
249
 
250
 
251
extcoff: $(TARGET).elf
252
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
253
 
254
 
255
 
256
 
257
# Program the device.  The magic trickery below examines the .eep hex
258
# file whether the size is > 0, and if so, reprograms the EEPROM as
259
# well.  Just delete these lines if you don't want this feature (like
260
# on the ATmegas with the EESAVE fuse bit set).
261
program: $(TARGET).hex $(TARGET).eep
262
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_ERASE)
263
	$(AVRDUDE) $(AVRDUDE_FLAGS) -i $(TARGET).hex
264
	@$(SIZE) --target=$(FORMAT) $(TARGET).eep | while read line; \
265
	do \
266
		set -- $$line; \
267
		if [ "x$$1" != "x0" ] ; then continue; fi; \
268
		if [ "$$2" -ne 0 ] ; then \
269
			echo $(AVRDUDE) $(AVRDUDE_FLAGS) -m eeprom -i $(TARGET).eep; \
270
			$(AVRDUDE) $(AVRDUDE_FLAGS) -m eeprom -i $(TARGET).eep; \
271
			break; \
272
		fi; \
273
	done
274
 
275
 
276
# Create final output files (.hex, .eep) from ELF output file.
277
%.hex: %.elf
278
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
279
 
280
%.eep: %.elf
281
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
282
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
283
 
284
# Create extended listing file from ELF output file.
285
%.lss: %.elf
286
	$(OBJDUMP) -h -S $< > $@
287
 
288
 
289
 
290
# Link: create ELF output file from object files.
291
.SECONDARY : $(TARGET).elf
292
.PRECIOUS : $(OBJ)
293
%.elf: $(OBJ)
294
	$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
295
 
296
 
297
# Compile: create object files from C source files.
298
%.o : %.c
299
	$(CC) -c $(ALL_CFLAGS) $< -o $@
300
 
301
 
302
# Compile: create assembler files from C source files.
303
%.s : %.c
304
	$(CC) -S $(ALL_CFLAGS) $< -o $@
305
 
306
 
307
# Assemble: create object files from assembler source files.
308
%.o : %.S
309
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
310
 
311
 
312
 
313
 
314
 
315
 
316
# Target: clean project.
317
clean: begin clean_list finished end
318
 
319
clean_list :
320
	$(REMOVE) $(TARGET).hex
321
	$(REMOVE) $(TARGET).eep
322
	$(REMOVE) $(TARGET).obj
323
	$(REMOVE) $(TARGET).cof
324
	$(REMOVE) $(TARGET).elf
325
	$(REMOVE) $(TARGET).map
326
	$(REMOVE) $(TARGET).obj
327
	$(REMOVE) $(TARGET).a90
328
	$(REMOVE) $(TARGET).sym
329
	$(REMOVE) $(TARGET).lnk
330
	$(REMOVE) $(TARGET).lss
331
	$(REMOVE) $(OBJ)
332
	$(REMOVE) $(LST)
333
	$(REMOVE) $(SRC:.c=.s)
334
	$(REMOVE) $(SRC:.c=.d)
335
 
336
 
337
# Automatically generate C source code dependencies.
338
# (Code originally taken from the GNU make user manual and modified
339
# (See README.txt Credits).)
340
#
341
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
342
# (see the SHELL variable defined above).
343
# This may not work with other shells or other seds.
344
#
345
%.d: %.c
346
	set -e; $(CC) -MM $(ALL_CFLAGS) $< \
347
	| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
348
	[ -s $@ ] || rm -f $@
349
 
350
 
351
# Remove the '-' if you want to see the dependency files generated.
352
-include $(SRC:.c=.d)
353
 
354
 
355
 
356
# Listing of phony targets.
357
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
358
	clean clean_list program
359
 
360
 
361
 
362