Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
336 andfri 1
# Hey Emacs, this is a -*- makefile -*-
2
#
3
# WinAVR makefile written by Eric B. Weddington, J�rg Wunsch, et al.
4
# Released to the Public Domain
5
# Please read the make user manual!
6
#
7
# Additional material for this makefile was submitted by:
8
#  Tim Henigan
9
#  Peter Fleury
10
#  Reiner Patommel
11
#  Sander Pool
12
#  Frederik Rouleau
13
#  Markus Pfaff
14
#
15
# On command line:
16
#
17
# make all = Make software.
18
#
19
# make clean = Clean out built project files.
20
#
21
# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
22
#
23
# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
24
#                4.07 or greater).
25
#
26
# make program = Download the hex file to the device, using avrdude.  Please
27
#                customize the avrdude settings below first!
28
#
29
# make filename.s = Just compile filename.c into the assembler code only
30
#
31
# To rebuild project do "make clean" then "make all".
32
#
33
 
34
########
35
# Differences from WinAVR 20040720 sample:
36
# - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum)
37
# - F_OSC Define in CFLAGS and AFLAGS
38
 
39
 
40
# MCU name
41
#MCU = atmega32
42
MCU = atmega8
43
#MCU = atmega16
44
 
45
 
46
# Main Oscillator Frequency
47
F_CPU = 8000000
48
##F_OSC = 1000000
49
##F_OSC = 1843200
50
##F_OSC = 2000000
51
##F_OSC = 3686400
52
##F_OSC = 4000000
53
##F_OSC = 8000000
54
##F_OSC = 11059200
55
##F_OSC = 16000000
56
 
57
# Output format. (can be srec, ihex, binary)
58
FORMAT = ihex
59
 
60
 
61
# Target file name (without extension).
62
TARGET = main
63
 
64
BIOSDIR = ../AVR-Bios
65
LIBDIR = ../lib/src
66
 
67
 
68
# List C source files here. (C dependencies are automatically generated.)
69
SRC =	$(TARGET).c
70
 
71
# List Assembler source files here.
72
# Make them always end in a capital .S.  Files ending in a lowercase .s
73
# will not be considered source files but generated files (assembler
74
# output from the compiler), and will be deleted upon "make clean"!
75
# Even though the DOS/Win* filesystem matches both .s and .S the same,
76
# it will preserve the spelling of the filenames, and gcc itself does
77
# care about how the name is spelled on its command-line.
78
ASRC = 
79
 
80
 
81
# Optimization level, can be [0, 1, 2, 3, s]. 
82
# 0 = turn off optimization. s = optimize for size.
83
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
84
OPT = s
85
#OPT = 3
86
 
87
# Debugging format.
88
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
89
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
90
#DEBUG = stabs
91
DEBUG = dwarf-2
92
 
93
# List any extra directories to look for include files here.
94
#     Each directory must be seperated by a space.
95
EXTRAINCDIRS = $(BIOSDIR) $(LIBDIR)/can $(LIBDIR)/can/mcp2515 $(LIBDIR)/mcu
96
 
97
# Compiler flag to set the C Standard level.
98
# c89   - "ANSI" C
99
# gnu89 - c89 plus GCC extensions
100
# c99   - ISO C99 standard (not yet fully implemented)
101
# gnu99 - c99 plus GCC extensions
102
CSTANDARD = -std=gnu99
103
 
104
# Place -D or -U options here
105
CDEFS =
106
 
107
# Place -I options here
108
CINCS =
109
 
110
 
111
# Compiler flags.
112
#  -g*:          generate debugging information
113
#  -O*:          optimization level
114
#  -f...:        tuning, see GCC manual and avr-libc documentation
115
#  -Wall...:     warning level
116
#  -Wa,...:      tell GCC to pass this to the assembler.
117
#    -adhlns...: create assembler listing
118
CFLAGS = 
119
#CFLAGS += -g$(DEBUG)
120
CFLAGS += $(CDEFS) $(CINCS)
121
CFLAGS += -O$(OPT)
122
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
123
CFLAGS += -Wall -Wstrict-prototypes
124
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
125
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
126
CFLAGS += $(CSTANDARD)
127
CFLAGS += -DF_CPU=$(F_CPU)
128
 
129
 
130
 
131
# Assembler flags.
132
#  -Wa,...:   tell GCC to pass this to the assembler.
133
#  -ahlms:    create listing
134
#  -gstabs:   have the assembler create line number information; note that
135
#             for use in COFF files, additional information about filenames
136
#             and function names needs to be present in the assembler source
137
#             files -- see avr-libc docs [FIXME: not yet described there]
138
##ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
139
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-g$(DEBUG)
140
ASFLAGS += -DF_OSC=$(F_OSC)
141
 
142
 
143
#Additional libraries.
144
 
145
# Minimalistic printf version
146
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
147
 
148
# Floating point printf version (requires MATH_LIB = -lm below)
149
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
150
 
151
PRINTF_LIB = 
152
 
153
# Minimalistic scanf version
154
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
155
 
156
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
157
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
158
 
159
SCANF_LIB = 
160
 
161
MATH_LIB = -lm
162
 
163
# External memory options
164
 
165
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
166
# used for variables (.data/.bss) and heap (malloc()).
167
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
168
 
169
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
170
# only used for heap (malloc()).
171
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
172
 
173
EXTMEMOPTS =
174
 
175
BIOS_RAM_END   = 0x0080008c
176
BIOSOPTS = -Wl,-L$(BIOSDIR),--defsym,__bios_ram_end=$(BIOS_RAM_END),-T$(MCU)_app.ld
177
 
178
# Linker flags.
179
#  -Wl,...:     tell GCC to pass this to linker.
180
#    -Map:      create map file
181
#    --cref:    add cross reference to  map file
182
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
183
LDFLAGS += $(EXTMEMOPTS)
184
LDFLAGS += $(BIOSOPTS)
185
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
186
 
187
 
188
 
189
 
190
# Programming support using avrdude. Settings and variables.
191
 
192
# Programming hardware: alf avr910 avrisp bascom bsd 
193
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
194
#
195
# Type: avrdude -c ?
196
# to get a full listing.
197
#
198
AVRDUDE_PROGRAMMER = avr910
199
 
200
# com1 = serial port. Use lpt1 to connect to parallel port.
201
AVRDUDE_PORT = /dev/ttyS0    # programmer connected to serial device
202
AVRDUDE_BAUD = 115200
203
 
204
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
205
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
206
 
207
 
208
# Uncomment the following if you want avrdude's erase cycle counter.
209
# Note that this counter needs to be initialized first using -Yn,
210
# see avrdude manual.
211
#AVRDUDE_ERASE_COUNTER = -y
212
 
213
# Uncomment the following if you do /not/ wish a verification to be
214
# performed after programming the device.
215
#AVRDUDE_NO_VERIFY = -V
216
 
217
# Increase verbosity level.  Please use this when submitting bug
218
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
219
# to submit bug reports.
220
#AVRDUDE_VERBOSE = -v -v
221
 
222
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -b $(AVRDUDE_BAUD)
223
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
224
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
225
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
226
 
227
 
228
 
229
# ---------------------------------------------------------------------------
230
 
231
# Define directories, if needed.
232
DIRAVR = c:/progra~1/winavr
233
DIRAVRBIN = $(DIRAVR)/bin
234
DIRAVRUTILS = $(DIRAVR)/utils/bin
235
DIRINC = .
236
DIRLIB = $(DIRAVR)/avr/lib
237
 
238
 
239
# Define programs and commands.
240
SHELL = sh
241
CC = avr-gcc
242
OBJCOPY = avr-objcopy
243
OBJDUMP = avr-objdump
244
SIZE = avr-size
245
NM = avr-nm
246
AVRDUDE = avrdude
247
REMOVE = rm -f
248
COPY = cp
249
 
250
 
251
 
252
 
253
# Define Messages
254
# English
255
MSG_ERRORS_NONE = Errors: none
256
MSG_BEGIN = -------- begin --------
257
MSG_END = --------  end  --------
258
MSG_SIZE_BEFORE = Size before: 
259
MSG_SIZE_AFTER = Size after:
260
MSG_COFF = Converting to AVR COFF:
261
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
262
MSG_FLASH = Creating load file for Flash:
263
MSG_EEPROM = Creating load file for EEPROM:
264
MSG_EXTENDED_LISTING = Creating Extended Listing:
265
MSG_SYMBOL_TABLE = Creating Symbol Table:
266
MSG_LINKING = Linking:
267
MSG_COMPILING = Compiling:
268
MSG_ASSEMBLING = Assembling:
269
MSG_CLEANING = Cleaning project:
270
 
271
 
272
 
273
 
274
# Define all object files.
275
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
276
 
277
# Define all listing files.
278
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
279
 
280
 
281
# Compiler flags to generate dependency files.
282
### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
283
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
284
 
285
# Combine all necessary flags and optional flags.
286
# Add target processor to flags.
287
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
288
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
289
 
290
 
291
 
292
 
293
 
294
# Default target.
295
all: begin gccversion sizebefore build sizeafter finished end
296
 
297
build: elf hex eep lss sym
298
 
299
elf: $(TARGET).elf
300
hex: $(TARGET).hex
301
eep: $(TARGET).eep
302
lss: $(TARGET).lss 
303
sym: $(TARGET).sym
304
 
305
 
306
 
307
# Eye candy.
308
# AVR Studio 3.x does not check make's exit code but relies on
309
# the following magic strings to be generated by the compile job.
310
begin:
311
	@echo
312
	@echo $(MSG_BEGIN)
313
 
314
finished:
315
	@echo $(MSG_ERRORS_NONE)
316
 
317
end:
318
	@echo $(MSG_END)
319
	@echo
320
 
321
 
322
# Display size of file.
323
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
324
ELFSIZE = $(SIZE) -A $(TARGET).elf
325
sizebefore:
326
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
327
 
328
sizeafter:
329
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
330
 
331
 
332
 
333
# Display compiler version information.
334
gccversion : 
335
	@$(CC) --version
336
 
337
 
338
 
339
# Program the device.  
340
program: $(TARGET).hex $(TARGET).eep
341
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
342
 
343
#programlock: 
344
#	$(AVRDUDE) $(AVRDUDE_FLAGS) -U lock:w:0x00:m
345
 
346
#programinit: 
347
#	$(AVRDUDE) $(AVRDUDE_FLAGS) -U hfuse:w:0xd9:m -U lfuse:w:0xe4:m
348
 
349
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
350
COFFCONVERT=$(OBJCOPY) --debugging \
351
--change-section-address .data-0x800000 \
352
--change-section-address .bss-0x800000 \
353
--change-section-address .noinit-0x800000 \
354
--change-section-address .eeprom-0x810000 
355
 
356
 
357
coff: $(TARGET).elf
358
	@echo
359
	@echo $(MSG_COFF) $(TARGET).cof
360
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
361
 
362
 
363
extcoff: $(TARGET).elf
364
	@echo
365
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
366
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
367
 
368
 
369
 
370
# Create final output files (.hex, .eep) from ELF output file.
371
%.hex: %.elf
372
	@echo
373
	@echo $(MSG_FLASH) $@
374
	$(OBJCOPY) -j .text -j .data -O $(FORMAT) $< $@
375
 
376
%.eep: %.elf
377
	@echo
378
	@echo $(MSG_EEPROM) $@
379
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
380
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
381
 
382
# Create extended listing file from ELF output file.
383
%.lss: %.elf
384
	@echo
385
	@echo $(MSG_EXTENDED_LISTING) $@
386
	$(OBJDUMP) -h -S $< > $@
387
 
388
# Create a symbol table from ELF output file.
389
%.sym: %.elf
390
	@echo
391
	@echo $(MSG_SYMBOL_TABLE) $@
392
	$(NM) -n $< > $@
393
 
394
 
395
 
396
# Link: create ELF output file from object files.
397
.SECONDARY : $(TARGET).elf
398
.PRECIOUS : $(OBJ)
399
%.elf: $(OBJ)
400
	@echo
401
	@echo $(MSG_LINKING) $@
402
	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $^
403
 
404
# Compile: create object files from C source files.
405
%.o : %.c
406
	@echo
407
	@echo $(MSG_COMPILING) $<
408
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
409
 
410
 
411
# Compile: create assembler files from C source files.
412
%.s : %.c
413
	$(CC) -S $(ALL_CFLAGS) $< -o $@
414
 
415
 
416
# Assemble: create object files from assembler source files.
417
%.o : %.S
418
	@echo
419
	@echo $(MSG_ASSEMBLING) $<
420
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
421
 
422
 
423
 
424
# Target: clean project.
425
clean: begin clean_list finished end
426
 
427
clean_list :
428
	@echo
429
	@echo $(MSG_CLEANING)
430
	$(REMOVE) $(TARGET).hex
431
	$(REMOVE) $(TARGET).eep
432
	$(REMOVE) $(TARGET).obj
433
	$(REMOVE) $(TARGET).cof
434
	$(REMOVE) $(TARGET).elf
435
	$(REMOVE) $(TARGET).map
436
	$(REMOVE) $(TARGET).obj
437
	$(REMOVE) $(TARGET).a90
438
	$(REMOVE) $(TARGET).sym
439
	$(REMOVE) $(TARGET).lnk
440
	$(REMOVE) $(TARGET).lss
441
	$(REMOVE) $(OBJ)
442
	$(REMOVE) $(LST)
443
	$(REMOVE) $(SRC:.c=.s)
444
	$(REMOVE) $(SRC:.c=.d)
445
	$(REMOVE) .dep/*
446
 
447
 
448
 
449
# Include the dependency files.
450
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
451
 
452
 
453
# Listing of phony targets.
454
.PHONY : all begin finish end sizebefore sizeafter gccversion \
455
build elf hex eep lss sym coff extcoff \
456
clean clean_list program programlock programinit
457