Subversion Repositories HomeAutomation

Rev

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

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