Subversion Repositories HomeAutomation

Rev

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