Subversion Repositories HomeAutomation

Rev

Rev 664 | Rev 1115 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

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