Subversion Repositories svnkaklik

Rev

Rev 182 | Go to most recent revision | Details | Compare with Previous | 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
 
174 kaklik 117
 
118
PROGRAMMER_DEVICE = dapa
151 kaklik 119
 
174 kaklik 120
PORT = /dev/parport0			# programmer connected to parallel port
151 kaklik 121
 
122
# Programming support using avrdude. Settings and variables.
123
 
124
# Programming hardware: avrisp stk500 avr910 pavr stk200 pony-stk200
125
#                       dt006 bascom alf
126
# Type: avrdude -c ?
127
# to get a full listing.
128
#
129
# Uncomment the following if you want avrdude's erase cycle counter.
130
# Note that this counter needs to be initialized first using -Yn,
131
# see avrdude manual.
132
#AVRDUDE_ERASE += -y
133
#
134
# Uncomment the following if you do /not/ wish a verification to be
135
# performed after programming the device.
136
#AVRDUDE_FLAGS += -V
137
#
138
# Increase verbosity level.  Please use this when submitting bug
139
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
140
# to submit bug reports.
141
#AVRDUDE_FLAGS += -v -v
174 kaklik 142
 
151 kaklik 143
 
144
# ---------------------------------------------------------------------------
145
 
146
# Define directories, if needed.
147
DIRAVR = c:/winavr
148
DIRAVRBIN = $(DIRAVR)/bin
149
DIRAVRUTILS = $(DIRAVR)/utils/bin
150
DIRINC = .
151
DIRLIB = $(DIRAVR)/avr/lib
152
 
153
 
154
# Define programs and commands.
155
SHELL = sh
156
 
157
CC = avr-gcc
158
 
159
OBJCOPY = avr-objcopy
160
OBJDUMP = avr-objdump
161
SIZE = avr-size
162
 
163
 
164
# Programming support using avrdude.
174 kaklik 165
#PROGRAMMER = avrdude
166
# Programming support using uisp.
167
PROGRAMMER = uisp
151 kaklik 168
 
169
 
170
REMOVE = rm -f
171
COPY = cp
172
 
173
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
174
ELFSIZE = $(SIZE) -A $(TARGET).elf
175
 
176
FINISH = echo Errors: none
177
BEGIN = echo -------- begin --------
178
END = echo --------  end  --------
179
 
180
 
181
 
182
 
183
# Define all object files.
184
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
185
 
186
# Define all listing files.
187
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
188
 
189
# Combine all necessary flags and optional flags.
190
# Add target processor to flags.
191
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
192
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
193
 
194
 
195
 
196
# Default target.
197
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
198
	$(TARGET).lss coff sizeafter finished end
199
 
200
 
201
# Eye candy.
202
# AVR Studio 3.x does not check make's exit code but relies on
203
# the following magic strings to be generated by the compile job.
204
begin:
205
	@$(BEGIN)
206
 
207
finished:
208
	@$(FINISH)
209
 
210
end:
211
	@$(END)
212
 
213
 
214
# Display size of file.
215
sizebefore:
216
	@if [ -f $(TARGET).elf ]; then echo Size before:; $(ELFSIZE);fi
217
 
218
sizeafter:
219
	@if [ -f $(TARGET).elf ]; then echo Size after:; $(ELFSIZE);fi
220
 
221
 
222
 
223
# Display compiler version information.
224
gccversion :
225
	$(CC) --version
226
 
227
 
228
 
229
 
230
# Convert ELF to COFF for use in debugging / simulating in
231
# AVR Studio or VMLAB.
232
COFFCONVERT=$(OBJCOPY) --debugging \
233
	--change-section-address .data-0x800000 \
234
	--change-section-address .bss-0x800000 \
235
	--change-section-address .noinit-0x800000 \
236
	--change-section-address .eeprom-0x810000
237
 
238
 
239
coff: $(TARGET).elf
240
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
241
 
242
 
243
extcoff: $(TARGET).elf
244
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
245
 
246
 
247
 
248
 
249
# Program the device.  The magic trickery below examines the .eep hex
250
# file whether the size is > 0, and if so, reprograms the EEPROM as
251
# well.  Just delete these lines if you don't want this feature (like
252
# on the ATmegas with the EESAVE fuse bit set).
174 kaklik 253
program: $(TARGET).hex $(TARGET).eep
254
#	if[ "$(PROGRAMMER)" == "avrdude"]; then \
255
#	  avrdude -p $(MCU) -P $(PORT) -c $(PROGRAMMER_DEVICE) -e # erase AVR device
256
#	  avrdude -p $(MCU) -P $(PORT) -c $(PROGRAMMER_DEVICE) -i $(TARGET).hex # program AVR device
257
#	fi; \
258
#	@$(SIZE) --target=$(FORMAT) $(TARGET).eep | while read line; \
259
#	do \
260
#		set -- $$line; \
261
#		if [ "x$$1" != "x0" ] ; then continue; fi; \
262
#		if [ "$$2" -ne 0 ] ; then \
263
#			echo $(AVRDUDE) $(AVRDUDE_FLAGS) -m eeprom -i $(TARGET).eep; \
264
#			$(AVRDUDE) $(AVRDUDE_FLAGS) -m eeprom -i $(TARGET).eep; \
265
#			break; \
266
#		fi; \
267
#	done
268
 
269
#	if[$PROGRAMMER == "uisp"]; then 
182 kaklik 270
	   uisp -dlpt=$(PORT) -dpart=$(MCU) -dprog=$(PROGRAMMER_DEVICE) --erase
174 kaklik 271
	   uisp -dlpt=$(PORT) -dpart=$(MCU) -dprog=$(PROGRAMMER_DEVICE) if=$(TARGET).hex --upload
182 kaklik 272
	   uisp -dlpt=$(PORT) -dpart=$(MCU) -dprog=$(PROGRAMMER_DEVICE) if=$(TARGET).hex --verify
174 kaklik 273
#	fi;
151 kaklik 274
 
275
# Create final output files (.hex, .eep) from ELF output file.
276
%.hex: %.elf
277
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
278
 
279
%.eep: %.elf
280
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
281
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
282
 
283
# Create extended listing file from ELF output file.
284
%.lss: %.elf
285
	$(OBJDUMP) -h -S $< > $@
286
 
287
 
288
 
289
# Link: create ELF output file from object files.
290
.SECONDARY : $(TARGET).elf
291
.PRECIOUS : $(OBJ)
292
%.elf: $(OBJ)
293
	$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
294
 
295
 
296
# Compile: create object files from C source files.
297
%.o : %.c
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
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
309
 
310
 
311
 
312
 
313
 
314
 
315
# Target: clean project.
316
clean: begin clean_list finished end
317
 
318
clean_list :
319
	$(REMOVE) $(TARGET).hex
320
	$(REMOVE) $(TARGET).eep
321
	$(REMOVE) $(TARGET).obj
322
	$(REMOVE) $(TARGET).cof
323
	$(REMOVE) $(TARGET).elf
324
	$(REMOVE) $(TARGET).map
325
	$(REMOVE) $(TARGET).obj
326
	$(REMOVE) $(TARGET).a90
327
	$(REMOVE) $(TARGET).sym
328
	$(REMOVE) $(TARGET).lnk
329
	$(REMOVE) $(TARGET).lss
330
	$(REMOVE) $(OBJ)
331
	$(REMOVE) $(LST)
332
	$(REMOVE) $(SRC:.c=.s)
333
	$(REMOVE) $(SRC:.c=.d)
334
 
335
 
336
# Automatically generate C source code dependencies.
337
# (Code originally taken from the GNU make user manual and modified
338
# (See README.txt Credits).)
339
#
340
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
341
# (see the SHELL variable defined above).
342
# This may not work with other shells or other seds.
343
#
344
%.d: %.c
345
	set -e; $(CC) -MM $(ALL_CFLAGS) $< \
346
	| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
347
	[ -s $@ ] || rm -f $@
348
 
349
 
350
# Remove the '-' if you want to see the dependency files generated.
351
-include $(SRC:.c=.d)
352
 
353
 
354
 
355
# Listing of phony targets.
356
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
357
	clean clean_list program
358
 
359
 
360
 
361