Subversion Repositories HomeAutomation

Rev

Rev 673 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

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