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