Subversion Repositories HomeAutomation

Rev

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

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