Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

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